private void timerUpdate_Tick(object sender, EventArgs e) { //BulkStatusCheck(tbServicesToMonitor.Lines); lvServiceStatus.Items.Clear(); //Clear the status list //Update the status list foreach (string service in WinServices.CheckServices(Services).ToArray()) //Iterate through the services { lvServiceStatus.Items.Add(service); //Add each result to the listview } for (int i = 0; i < lvServiceStatus.Items.Count; i++) //Color the status list { if (lvServiceStatus.Items[i].ToString().Contains("RUNNING")) //If the service is running, color it green, else white text with a red background { lvServiceStatus.Items[i].BackColor = Color.White; lvServiceStatus.Items[i].ForeColor = Color.Green; } else { lvServiceStatus.Items[i].BackColor = Color.Red; lvServiceStatus.Items[i].ForeColor = Color.White; } } }
public void LoadConfig() { try { if (_cfg.AppSettings.Settings.AllKeys.Contains(ConfigConstants.Services) == true) { _services.Clear(); WinServices cc = WinServices.Load(_cfg.AppSettings.Settings[ConfigConstants.Services].Value); if (cc != null) { cc.Services.ForEach(x => _services.Add(x)); } } this.servicesGrid.ItemsSource = this.Services; this.servicesGrid.SelectedIndex = 0; this.nagiosServiceStartPause.Text = "60"; if (_cfg.AppSettings.Settings.AllKeys.Contains(ConfigConstants.NagiosServiceStartPause) == true) { this.nagiosServiceStartPause.Text = _cfg.AppSettings.Settings[ConfigConstants.NagiosServiceStartPause].Value; } } catch (Exception ex) { Nagios.Net.Client.Log.WriteLog(string.Format("{0}\n{1}", ex.Message, ex.StackTrace), true); } }
private void Save() { WinServices pc = new WinServices(); pc.Services = Services.ToList(); if (_cfg.AppSettings.Settings.AllKeys.Contains(ConfigConstants.Services) == true) { _cfg.AppSettings.Settings[ConfigConstants.Services].Value = pc.GetSerialized(); } else { _cfg.AppSettings.Settings.Add(ConfigConstants.Services, pc.GetSerialized()); } int duration; if (int.TryParse(this.nagiosServiceStartPause.Text, out duration) == true) { _cfg.AppSettings.Settings[ConfigConstants.NagiosServiceStartPause].Value = this.nagiosServiceStartPause.Text; } else { _cfg.AppSettings.Settings[ConfigConstants.NagiosServiceStartPause].Value = "60"; } _cfg.Save(ConfigurationSaveMode.Modified); ConfigurationManager.RefreshSection("appSettings"); }
private void btnStartStop_Click(object sender, EventArgs e) { if (timerUpdate.Enabled) { //If running stop everything and enable editing tbServicesToMonitor.Enabled = true; //Enable editing btnStartStop.Text = "Start"; //Change the button text to start timerUpdate.Enabled = false; //Stop the update timer } else { //If not running start everything and prevent editing Services = WinServices.EnumerateServices(tbServicesToMonitor.Lines); //Enumerate the services tbServicesToMonitor.Enabled = false; //Disable editing btnStartStop.Text = "Stop"; //Change the button text to stop timerUpdate.Enabled = true; //Start the update timer } }
private void btnLoadFromFile_Click(object sender, EventArgs e) { tbServicesToMonitor.Text = ""; if (File.Exists(tbFileName.Text)) { Services = WinServices.LoadServicesFromFile(tbFileName.Text); foreach (Service service in Services) { tbServicesToMonitor.AppendText(service.MACHINENAME + "," + service.SERVICENAME + Environment.NewLine); } } else { MessageBox.Show("Error Loading File..."); } }
private void timerAlert_Tick(object sender, EventArgs e) { WinServices.GenerateAlerts(Services); //Send alerts as necessary }
private void Save() { WinServices pc = new WinServices(); pc.Services = Services.ToList(); if (_cfg.AppSettings.Settings.AllKeys.Contains(ConfigConstants.Services) == true) _cfg.AppSettings.Settings[ConfigConstants.Services].Value = pc.GetSerialized(); else _cfg.AppSettings.Settings.Add(ConfigConstants.Services, pc.GetSerialized()); int duration; if (int.TryParse(this.nagiosServiceStartPause.Text, out duration) == true) { _cfg.AppSettings.Settings[ConfigConstants.NagiosServiceStartPause].Value = this.nagiosServiceStartPause.Text; } else _cfg.AppSettings.Settings[ConfigConstants.NagiosServiceStartPause].Value = "60"; _cfg.Save(ConfigurationSaveMode.Modified); ConfigurationManager.RefreshSection("appSettings"); }