Esempio n. 1
0
        private static IWarden ConfigureWarden()
        {
            var wardenConfiguration = WardenConfiguration
                                      .Create()
                                      .AddDiskWatcher(cfg =>
            {
                cfg.WithFilesToCheck(@"D:\Test\File1.txt", @"D:\Test\File2.txt")
                .WithPartitionsToCheck("D", @"E:\")
                .WithDirectoriesToCheck(@"D:\Test");
            })
                                      .AddMongoDbWatcher("mongodb://*****:*****@"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"));
            })
                                      .AddPerformanceWatcher(cfg => cfg.EnsureThat(usage => usage.Cpu < 50 && usage.Ram < 5000),
                                                             hooks =>
                                                             hooks.OnCompleted(result => System.Console.WriteLine(result.WatcherCheckResult.Description)))
                                      .AddRedisWatcher("localhost", 1, cfg =>
            {
                cfg.WithQuery("get test")
                .EnsureThat(results => results.Any(x => x == "test-value"));
            })
                                      .AddWebWatcher("http://httpstat.us/200", hooks =>
            {
                hooks.OnStartAsync(check => WebsiteHookOnStartAsync(check))
                .OnSuccessAsync(check => WebsiteHookOnSuccessAsync(check))
                .OnCompletedAsync(check => WebsiteHookOnCompletedAsync(check))
                .OnFailureAsync(check => WebsiteHookOnFailureAsync(check));
            })
                                      .AddWebWatcher("API watcher", "http://httpstat.us/200", HttpRequest.Post("users", new { name = "test" },
                                                                                                               headers: new Dictionary <string, string>
            {
                ["User-Agent"]    = "Warden",
                ["Authorization"] = "Token MyBase64EncodedString"
            }), cfg => cfg.EnsureThat(response => response.Headers.Any())
                                                     )
                                      //Set proper API key or credentials.
                                      //.IntegrateWithSendGrid("api-key", "*****@*****.**", cfg =>
                                      //{
                                      //    cfg.WithDefaultSubject("Monitoring status")
                                      //        .WithDefaultReceivers("*****@*****.**");
                                      //})
                                      //.SetAggregatedWatcherHooks((hooks, integrations) =>
                                      //{
                                      //    hooks.OnFirstFailureAsync(result =>
                                      //        integrations.SendGrid().SendEmailAsync("Monitoring errors have occured."))
                                      //        .OnFirstSuccessAsync(results =>
                                      //            integrations.SendGrid().SendEmailAsync("Everything is up and running again!"));
                                      //})
                                      //Set proper URL of the Warden Web API
                                      .IntegrateWithHttpApi("http://localhost:11223/api",
                                                            "1pi0Tp9/n2wdLSRsUBAKXwHGPXoFU/58wV8Dc+vIL+k2/fWF14VXPiuK",
                                                            "0b8351f1-dc93-4137-90b9-e3a7d7e12054")
                                      .SetGlobalWatcherHooks(hooks =>
            {
                hooks.OnStart(check => GlobalHookOnStart(check))
                .OnFailure(result => GlobalHookOnFailure(result))
                .OnSuccess(result => GlobalHookOnSuccess(result))
                .OnCompleted(result => GlobalHookOnCompleted(result));
            })
                                      .SetHooks((hooks, integrations) =>
            {
                hooks.OnIterationCompleted(iteration => OnIterationCompleted(iteration))
                .OnIterationCompletedAsync(iteration => integrations.HttpApi()
                                           .PostIterationToWardenPanelAsync(iteration))
                .OnError(exception => System.Console.WriteLine(exception));
            })
                                      .Build();

            return(Warden.Create(wardenConfiguration));
        }