public ActionResult <MonitorState> GetMonitor([FromServices] IMonitoringLogic monitoringLogic, MonitorState monitorState) { monitoringLogic.EnableMonitoring(monitorState.Enabled); return(Ok(monitorState)); }
public SafeguardDevOpsService() { CheckGenerateUniqueIdentifier(); var webSslCert = CheckDefaultCertificate(); if (webSslCert == null) { Log.Logger.Error("Failed to find or change the default SSL certificate."); Environment.Exit(1); } if (bool.Parse(Environment.GetEnvironmentVariable("DOCKER_RUNNING") ?? "false")) { Log.Logger.Information("Running in Docker container"); if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("DOCKER_HOST_IP"))) { var hostEntry = Dns.GetHostEntry("host.docker.internal"); Log.Logger.Information($"Using host.docker.internal IP: {hostEntry.AddressList[0]}"); Environment.SetEnvironmentVariable("DOCKER_HOST_IP", hostEntry.AddressList[0].ToString()); } Log.Logger.Information($"Docker host IP: {Environment.GetEnvironmentVariable("DOCKER_HOST_IP")}"); } Log.Logger.Information($"Thumbprint for {webSslCert.Subject}: {webSslCert.Thumbprint}"); Log.Logger.Information(webSslCert.ToPemFormat()); Log.Logger.Information($"Configuration file location: {Path.Combine(WellKnownData.ServiceDirPath, WellKnownData.AppSettings)}.json"); var configuration = new ConfigurationBuilder() .AddJsonFile($"{Path.Combine(WellKnownData.ServiceDirPath, WellKnownData.AppSettings)}.json", optional: true, reloadOnChange: true) .AddEnvironmentVariables() .Build(); var httpsPort = configuration["HttpsPort"] ?? "443"; var logLevel = configuration["LogLevel"]; if (logLevel != null) { if (Enum.TryParse(logLevel, out DevOpsLogLevel level)) { var logLevelSwitch = LogLevelSwitcher.Instance.LogLevelSwitch; switch (level) { case DevOpsLogLevel.Information: logLevelSwitch.MinimumLevel = LogEventLevel.Information; break; case DevOpsLogLevel.Debug: logLevelSwitch.MinimumLevel = LogEventLevel.Debug; break; case DevOpsLogLevel.Error: logLevelSwitch.MinimumLevel = LogEventLevel.Error; break; case DevOpsLogLevel.Warning: logLevelSwitch.MinimumLevel = LogEventLevel.Warning; break; case DevOpsLogLevel.Fatal: logLevelSwitch.MinimumLevel = LogEventLevel.Fatal; break; case DevOpsLogLevel.Verbose: logLevelSwitch.MinimumLevel = LogEventLevel.Verbose; break; } } else { Log.Logger.Error($"{logLevel} is not not a recognized log level. Continuing to use the default log level."); } } _host = new WebHostBuilder() .UseSerilog() .UseKestrel(options => { if (int.TryParse(httpsPort, out var port) == false) { port = 443; } Log.Logger.Information($"Binding web server to port: {port}."); options.ListenAnyIP(port, listenOptions => { listenOptions.UseHttps(webSslCert); }); }) .ConfigureServices(services => services.AddAutofac()) .UseContentRoot(Directory.GetCurrentDirectory()) .UseStartup <Startup>() .Build(); _monitoringLogic = (IMonitoringLogic)_host.Services.GetService(typeof(IMonitoringLogic)); _pluginManager = (IPluginManager)_host.Services.GetService(typeof(IPluginManager)); }
public ActionResult <MonitorState> GetMonitor([FromServices] IMonitoringLogic monitoringLogic) { var monitoring = monitoringLogic.GetMonitorState(); return(Ok(monitoring)); }
public ActionResult <IEnumerable <MonitorEvent> > GetMonitorEvents([FromServices] IMonitoringLogic monitoringLogic, [FromQuery] int size = 25) { var monitorEvents = monitoringLogic.GetMonitorEvents(size); return(Ok(monitorEvents)); }