private IEnumerable <Message> Probe(TaskTimerElapsed arg) { if (!Enabled) { return(JanelObserver.Success()); } try { using (var authentication = new WindowsLogin(UserName, Domain, Password)) { var failedServices = new List <string>(); WindowsIdentity.RunImpersonated(authentication.Identity.AccessToken, () => { foreach (var service in Services) { var windowsService = new ServiceController(service, MachineName); if (windowsService.Status != ServiceControllerStatus.Running) { failedServices.Add(service); } } }); if (Enabled && failedServices.Any() && Retries++ >= RetriesBeforeFailure) { _alertManager.LogAlert($"Alert !\n\nServices not running : \n{string.Join("\n- ", failedServices)}", "Windows Services", MachineName, "", SeverityType.Critical); } else if (!Enabled || !failedServices.Any()) { Retries = 0; } } } catch (Exception exc) { _alertManager.LogAlert($"Unable to probe services of {MachineName}. {exc.Message}", MachineName, "", "", SeverityType.Moderate); } return(JanelObserver.Success()); }
public static IList<DataTable> ExecuteSqlScript(string providerType, string connectionString, string sqlCommand, string environment = "Default", WindowsLogin impersonation = null) { switch (providerType) { case "System.Data.SqlClient": return ExecuteSqlScript<SqlConnection, SqlCommand>(connectionString, sqlCommand, environment); case "System.Data.SQLite": return ExecuteSqlScript<SQLiteConnection, SQLiteCommand>(connectionString, sqlCommand, environment); default: return null; } }