Exemplo n.º 1
0
        static void Main(string[] args)
        {
            //var testWatcher = new TestWatcher();
            //var configuration = WardenConfiguration
            //	.Create()
            //	.AddWatcher(testWatcher, hooks =>
            //	{
            //		hooks.OnCompleted(result => Console.WriteLine($"Completed {DateTime.Now:s}"));

            //	})
            //	.WithInterval(TimeSpan.FromSeconds(10))
            //	.Build();
            //var warden = WardenInstance.Create(configuration);


            var mssqlconfiguration = MsSqlWatcherConfiguration
                                     .Create(@"Data Source=localhost;Initial Catalog=AtomicScope;Integrated Security=True")
                                     .WithQuery("select * from Config_BusinessProcess", new Dictionary <string, object> {
                ["id"] = 1
            })
                                     .EnsureThat(users => users.Any(user => user.ProcessName == "Kovai.Sales"))
                                     .Build();
            var mssqlWatcher = MsSqlWatcher.Create("My MSSQL watcher", mssqlconfiguration);

            var configuration = WardenConfiguration
                                .Create()
                                .AddWatcher(mssqlWatcher, hooks => { hooks.OnCompleted(result => PrintResult(result)); })
                                .Build();

            var warden = WardenInstance.Create(configuration);

            Task.WaitAll(warden.StartAsync());

            Read();
        }
Exemplo n.º 2
0
        public async Task <List <IWardenCheckResult> > DoHealthChecks(IEnumerable <SingleHealthCheckSettings> settings)
        {
            var results       = new List <IWardenCheckResult>();
            var configuration = Configure(settings, results);
            var warden        = WardenInstance.Create(configuration);

            await warden.StartAsync();

            return(results);
        }
        public IWarden Create(string name)
        {
            var wardenConfiguration = WardenConfiguration
                                      .Create()
                                      .AddWebWatcher("http://httpstat.us/200", cfg =>
            {
                cfg.EnsureThat(response => response.StatusCode == HttpStatusCode.Accepted);
            })
                                      .SetGlobalWatcherHooks((hooks, integrations) =>
            {
            })
                                      .WithConsoleLogger()
                                      .Build();

            return(WardenInstance.Create(name, wardenConfiguration));
        }
Exemplo n.º 4
0
        private static IWarden CreateWarden(string name, int interval = 5)
        {
            var wardenConfiguration = WardenConfiguration
                                      .Create()
                                      .AddWebWatcher("http://httpstat.us/200", cfg =>
            {
                cfg.EnsureThat(response => response.StatusCode == HttpStatusCode.Accepted);
            })
                                      .SetGlobalWatcherHooks((hooks, integrations) =>
            {
                Console.WriteLine($"Hello!");
            })
                                      .WithInterval(TimeSpan.FromSeconds(interval))
                                      .WithConsoleLogger()
                                      .Build();

            return(WardenInstance.Create(name, wardenConfiguration));
        }
Exemplo n.º 5
0
        private static IWardenManager ConfigureWardenManager()
        {
            var wardenConfiguration = WardenConfiguration
                                      .Create()
                                      .AddWebWatcher("http://httpstat.us/200",
                                                     interval: TimeSpan.FromMilliseconds(1000), group: "websites")
                                      .AddServerWatcher("www.google.pl", 80)
                                      .WithConsoleLogger(minLevel: WardenLoggerLevel.All, useColors: true)
                                      .Build();

            var warden = WardenInstance.Create(wardenConfiguration);

            return(WardenManager.Create(warden, cfg =>
            {
                cfg.SetCommandSource(() => CommandSource)
                .SetEventHandler(() => _eventHandler)
                .WithConsoleLogger(minLevel: WardenLoggerLevel.All, useColors: true);
            }));
        }
Exemplo n.º 6
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)))
                                      .AddProcessWatcher("mongod")
                                      .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));
            }, interval: TimeSpan.FromMilliseconds(1000), group: "websites")
                                      .AddServerWatcher("www.google.pl", 80)
                                      .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()), interval: TimeSpan.FromSeconds(3)
                                                     )
                                      .IntegrateWithMsSql(@"Data Source=.\sqlexpress;Initial Catalog=MyDatabase;Integrated Security=True")
                                      //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("https://panel.getwarden.net/api",
                                                            "pMBXwekquqlfvGPXTNT1k32RHisgguAV2yv3tJq1Wq0d2eqMsx2HuR97Lfc=",
                                                            "150bd13b-ef0d-41e7-8817-e52c3831b319")
                                      //Set proper Slack webhook URL
                                      //.IntegrateWithSlack("https://hooks.slack.com/services/XXX/YYY/ZZZ")
                                      //Set proper URL of Cachet API and access token or username & password
                                      //.IntegrateWithCachet("http://localhost/api/v1", "XYZ")
                                      .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 => OnIterationCompletedCachetAsync(iteration, integrations.Cachet()))
                .OnIterationCompletedAsync(iteration => integrations.MsSql()
                                           .QueryAsync <int>("select * from users where id = @id", GetSqlQueryParams()))
                .OnIterationCompletedAsync(iteration => integrations.MsSql()
                                           .ExecuteAsync("insert into messages values(@message)", GetSqlCommandParams()));
            })
                                      .Build();

            return(WardenInstance.Create(wardenConfiguration));
        }
Exemplo n.º 7
0
        private static IWarden ConfigureWarden()
        {
            var wardenConfiguration = WardenConfiguration
                                      .Create();

            if (SCWardenConfigurationManager.IsDiskWatcherEnabled)
            {
                wardenConfiguration.AddDiskWatcher(cfg =>
                {
                    // Disk Watcher
                    //cfg.WithFilesToCheck(@"D:\Test\File1.txt", @"D:\Test\File2.txt")
                    cfg.WithPartitionsToCheck("D", @"E:\")
                    .WithDirectoriesToCheck(@"D:\Test");
                });
            }
            if (SCWardenConfigurationManager.IsMongoDBWatcherEnabled)
            {
                // "mongodb://*****:*****@id", new Dictionary <string, object> {
                        ["id"] = "11111111-1111-1111-1111-111111111111"
                    })
                    .EnsureThat(items => items.Any(item => item.Name == "sitecore"));
                });
            }
            if (SCWardenConfigurationManager.IsPerformanceWatcherEnabled)
            {
                wardenConfiguration.AddPerformanceWatcher(cfg =>
                                                          cfg.EnsureThat(usage => usage.Cpu < SCWardenConfigurationManager.CPUThreshold &&
                                                                         usage.Ram < SCWardenConfigurationManager.RAMThreshold),
                                                          hooks =>
                                                          hooks.OnCompleted(result => LogMessage(result.WatcherCheckResult.Description, MessageType.Info)));
            }
            //.AddProcessWatcher("mongod")
            //.AddRedisWatcher("localhost", 1, cfg =>
            //{
            //    cfg.WithQuery("get test")
            //        .EnsureThat(results => results.Any(x => x == "test-value"));
            //})
            if (SCWardenConfigurationManager.IsWebWatcherEnabled)
            {
                // TODO : Make it configurable
                wardenConfiguration.AddWebWatcher("http://sc82rev160617/sitecore/service/heartbeat.aspx", hooks =>
                {
                    hooks.OnStartAsync(check => WebsiteHookOnStartAsync(check))
                    .OnSuccessAsync(check => WebsiteHookOnSuccessAsync(check))
                    .OnCompletedAsync(check => WebsiteHookOnCompletedAsync(check))
                    .OnFailureAsync(check => WebsiteHookOnFailureAsync(check));
                }, interval: TimeSpan.FromMinutes(10));  // TODO : Configurable
            }
            //.AddServerWatcher("www.google.pl", 80)
            //.AddWebWatcher("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())
            //)
            //.IntegrateWithMsSql(@"Data Source=.\sqlexpress;Initial Catalog=MyDatabase;Integrated Security=True")
            //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

            if (SCWardenConfigurationManager.IsWebPanelIntegrationEnabled)
            {
                wardenConfiguration.IntegrateWithHttpApi(SCWardenConfigurationManager.WebPanelURL,
                                                         SCWardenConfigurationManager.WebPanelAPIKey,
                                                         SCWardenConfigurationManager.WebPanelOrganizationId);
            }

            wardenConfiguration.SetGlobalWatcherHooks(hooks =>
            {
                hooks.OnStart(check => GlobalHookOnStart(check))
                .OnFailure(result => GlobalHookOnFailure(result))
                .OnSuccess(result => GlobalHookOnSuccess(result))
                .OnCompleted(result => GlobalHookOnCompleted(result));
            });
            wardenConfiguration.SetHooks((hooks, integrations) =>
            {
                hooks.OnIterationCompleted(iteration => OnIterationCompleted(iteration))
                //.OnIterationCompletedAsync(iteration => OnIterationCompletedCachetAsync(iteration, integrations.Cachet()))
                //.OnIterationCompletedAsync(iteration =>
                //    integrations.Slack().SendMessageAsync($"Iteration {iteration.Ordinal} has completed."))
                .OnIterationCompletedAsync(iteration => integrations.HttpApi()
                                           .PostIterationToWardenPanelAsync(iteration))
                .OnError(exception => LogMessage(exception.ToString(), MessageType.Error));
                //.OnIterationCompletedAsync(
                //    iteration => OnIterationCompletedMsSqlAsync(iteration, integrations.MsSql()));
            });

            return(WardenInstance.Create(wardenConfiguration.Build()));
        }
Exemplo n.º 8
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 => Console.WriteLine(result.WatcherCheckResult.Description)))
                                      .AddProcessWatcher("mongod")
                                      .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));
            }, interval: TimeSpan.FromMilliseconds(1000))
                                      .AddServerWatcher("www.google.pl", 80)
                                      .AddWebWatcher("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())
                                                     )
                                      .IntegrateWithMsSql(@"Data Source=.\sqlexpress;Initial Catalog=MyDatabase;Integrated Security=True")
                                      //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",
                                                            "yroWbGkozycDLMI7+Jkyw0FzJv/O6xHzhR8+DcKTNEQECZHFBFmBbYCKJ2wiHYI=",
                                                            "20afbd7c-f803-4a2d-be64-640776930930")
                                      //Set proper Slack webhook URL
                                      //.IntegrateWithSlack("https://hooks.slack.com/services/XXX/YYY/ZZZ")
                                      //Set proper URL of Cachet API and access token or username & password
                                      //.IntegrateWithCachet("http://localhost/api/v1", "XYZ")
                                      .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 => OnIterationCompletedCachetAsync(iteration, integrations.Cachet()))
                //.OnIterationCompletedAsync(iteration =>
                //    integrations.Slack().SendMessageAsync($"Iteration {iteration.Ordinal} has completed."))
                .OnIterationCompletedAsync(iteration => integrations.HttpApi()
                                           .PostIterationToWardenPanelAsync(iteration))
                .OnError(exception => Console.WriteLine(exception))
                .OnIterationCompletedAsync(
                    iteration => OnIterationCompletedMsSqlAsync(iteration, integrations.MsSql()));
            })
                                      .Build();

            return(WardenInstance.Create(wardenConfiguration));
        }