Home

Awesome

Warden MSSQL Watcher

Warden

OPEN SOURCE & CROSS-PLATFORM TOOL FOR SIMPLIFIED MONITORING

getwarden.net

BranchBuild status
mastermaster branch build status
developdevelop branch build status

MsSqlWatcher can be used either for simple database monitoring (e.g. checking if a connection can be made) or more advanced one which may include running a specialized query.

Installation:

Available as a NuGet package.

dotnet add package Warden.Watchers.MsSql

Configuration:

MsSqlWatcher can be configured by using the MsSqlWatcherWatcherConfiguration class or via the lambda expression passed to a specialized constructor.

Example of configuring the watcher via provided configuration class:

var configuration = MsSqlWatcherConfiguration
    .Create(@"Data Source=.\sqlexpress;Initial Catalog=MyDatabase;Integrated Security=True")
    .WithQuery("select * from users where id = @id", new Dictionary<string, object> {["id"] = 1 })
    .EnsureThat(users => users.Any(user => user.Name == "admin"))
    .Build();
var mssqlWatcher = MsSqlWatcher.Create("My MSSQL watcher", configuration);

var wardenConfiguration = WardenConfiguration
    .Create()
    .AddWatcher(mssqlWatcher)
    //Configure other watchers, hooks etc.

Example of adding the watcher directly to the Warden via one of the extension methods:

var wardenConfiguration  = WardenConfiguration
    .Create()
    .AddMsSqlWatcher(@"Data Source=.\sqlexpress;Initial Catalog=MyDatabase;Integrated Security=True", cfg =>
    {
        cfg.WithQuery("select * from users where id = @id", new Dictionary<string, object> {["id"] = 1})
           .EnsureThat(users => users.Any(user => user.Name == "admin"));
    })
    //Configure other watchers, hooks etc.

Please note that you may either use the lambda expression for configuring the watcher or pass the configuration instance directly. You may also configure the hooks by using another lambda expression available in the extension methods.

Check result type:

MsSqlWatcher provides a custom **MsSqlWatcherCheckResult ** type which contains additional values.

public class MsSqlWatcherCheckResult : WatcherCheckResult
{
    public string ConnectionString { get; }
    public string Query { get; }
    public IEnumerable<dynamic> QueryResult { get; }
}

Custom interfaces:

public interface IMsSql
{
    Task<IEnumerable<dynamic>> QueryAsync(IDbConnection connection, string query,
        IDictionary<string, object> parameters, TimeSpan? timeout = null);
}

IMsSql is responsible for executing the query on a database. It can be configured via the WithMsSqlProvider() method. By default it is based on the Dapper.