public override void LoadDisplayData() { if (Collector != null) { WMIQueryCollectorConfig wmiConfig = (WMIQueryCollectorConfig)Collector.AgentConfig; lvwResults.Items.Clear(); foreach (WMIQueryEntry wmiConfigEntry in wmiConfig.Entries) { ListViewItem lvi = new ListViewItem(wmiConfigEntry.Name); lvi.SubItems.Add(""); lvi.Tag = wmiConfigEntry; lvwResults.Items.Add(lvi); } } base.LoadDisplayData(); }
public override void LoadList() { if (SelectedConfig != null) { WMIQueryCollectorConfig currentConfig = (WMIQueryCollectorConfig)SelectedConfig; lvwEntries.Items.Clear(); foreach (WMIQueryEntry wmiConfigEntry in currentConfig.Entries) { ListViewItem lvi = new ListViewItem(wmiConfigEntry.Name); lvi.SubItems.Add(wmiConfigEntry.Machinename); lvi.SubItems.Add(wmiConfigEntry.Namespace); lvi.SubItems.Add(wmiConfigEntry.StateQuery); lvi.Tag = wmiConfigEntry; lvwEntries.Items.Add(lvi); } CheckOKEnabled(); } base.LoadList(); }
public override void OKClicked() { if (CheckOKEnabled()) { if (SelectedConfig == null) { SelectedConfig = new WMIQueryCollectorConfig(); } WMIQueryCollectorConfig currentConfig = (WMIQueryCollectorConfig)SelectedConfig; currentConfig.Entries.Clear(); foreach (ListViewItem lvi in lvwEntries.Items) { WMIQueryEntry eventLogEntry = (WMIQueryEntry)lvi.Tag; currentConfig.Entries.Add(eventLogEntry); } DialogResult = System.Windows.Forms.DialogResult.OK; Close(); } }
public override List <System.Data.DataTable> GetDetailDataTables() { List <System.Data.DataTable> tables = new List <System.Data.DataTable>(); try { WMIQueryCollectorConfig currentConfig = (WMIQueryCollectorConfig)AgentConfig; foreach (WMIQueryCollectorConfigEntry entry in currentConfig.Entries) { System.Data.DataTable dt = entry.GetDetailDataTable(); dt.TableName = Name + " (" + entry.Name + ")"; tables.Add(dt); } } catch (Exception ex) { System.Data.DataTable dt = new System.Data.DataTable("Exception"); dt.Columns.Add(new System.Data.DataColumn("Text", typeof(string))); dt.Rows.Add(ex.ToString()); tables.Add(dt); } return(tables); }
public override MonitorState RefreshState() { MonitorState returnState = new MonitorState(); string lastAction = ""; int errors = 0; int warnings = 0; int success = 0; double totalValue = 0; try { WMIQueryCollectorConfig currentConfig = (WMIQueryCollectorConfig)AgentConfig; returnState.RawDetails = string.Format("Running {0} WMI queries", currentConfig.Entries.Count); returnState.HtmlDetails = string.Format("<b>Running {0} WMI queries</b>", currentConfig.Entries.Count); foreach (WMIQueryCollectorConfigEntry wmiConfigEntry in currentConfig.Entries) { lastAction = string.Format("Running WMI query for {0} - ", wmiConfigEntry.Name); object val = wmiConfigEntry.RunQuery(); CollectorState currentState = wmiConfigEntry.GetState(val); if (currentState == CollectorState.Error) { errors++; returnState.ChildStates.Add( new MonitorState() { ForAgent = wmiConfigEntry.Name, State = CollectorState.Error, CurrentValue = val, RawDetails = string.Format("(Trigger '{0}')", wmiConfigEntry.ErrorValue) //RawDetails = string.Format("Machine '{0}' - value '{1}' - Error (trigger {2})", wmiConfigEntry.Machinename, FormatUtils.N(val, "[null]"), wmiConfigEntry.ErrorValue), //HtmlDetails = string.Format("Machine '{0}' - Value '{1}' - <b>Error</b> (trigger {2})", wmiConfigEntry.Machinename, FormatUtils.N(val, "[null]"), wmiConfigEntry.ErrorValue) }); } else if (currentState == CollectorState.Warning) { warnings++; returnState.ChildStates.Add( new MonitorState() { ForAgent = wmiConfigEntry.Name, State = CollectorState.Warning, CurrentValue = val, RawDetails = string.Format("(Trigger '{0}')", wmiConfigEntry.WarningValue) //RawDetails = string.Format("Machine '{0}' - value '{1}' - Warning (trigger {2})", wmiConfigEntry.Machinename, FormatUtils.N(val, "[null]"), wmiConfigEntry.WarningValue), //HtmlDetails = string.Format("Machine '{0}' - Value '{1}' - <b>Warning</b> (trigger {2})", wmiConfigEntry.Machinename, FormatUtils.N(val, "[null]"), wmiConfigEntry.WarningValue) }); } else { success++; returnState.ChildStates.Add( new MonitorState() { ForAgent = wmiConfigEntry.Name, State = CollectorState.Good, CurrentValue = val //, //RawDetails = string.Format("Machine '{0}' - value '{1}'", wmiConfigEntry.Machinename, FormatUtils.N(val, "[null]")), //HtmlDetails = string.Format("Machine '{0}' - Value '{1}'", wmiConfigEntry.Machinename, FormatUtils.N(val, "[null]")) }); } if (val != null && val.IsNumber()) { totalValue += double.Parse(val.ToString()); } } returnState.CurrentValue = totalValue; if (errors > 0 && warnings == 0) { returnState.State = CollectorState.Error; } else if (warnings > 0) { returnState.State = CollectorState.Warning; } else { returnState.State = CollectorState.Good; } } catch (Exception ex) { returnState.RawDetails = ex.Message; returnState.HtmlDetails = string.Format("<p><b>Last action:</b> {0}</p><blockquote>{1}</blockquote>", lastAction, ex.Message); returnState.State = CollectorState.Error; } return(returnState); }
public WMIQueryCollector() { AgentConfig = new WMIQueryCollectorConfig(); }
public override MonitorState GetState() { MonitorState returnState = new MonitorState(); StringBuilder plainTextDetails = new StringBuilder(); StringBuilder htmlTextTextDetails = new StringBuilder(); string lastAction = ""; int errors = 0; int warnings = 0; int success = 0; double totalValue = 0; try { WMIQueryCollectorConfig WmiIConfig = (WMIQueryCollectorConfig)AgentConfig; plainTextDetails.AppendLine(string.Format("Running {0} WMI queries", WmiIConfig.Entries.Count)); htmlTextTextDetails.AppendLine(string.Format("<i>Running {0} WMI queries'</i>", WmiIConfig.Entries.Count)); htmlTextTextDetails.AppendLine("<ul>"); foreach (WMIQueryEntry wmiConfigEntry in WmiIConfig.Entries) { lastAction = string.Format("Running WMI query for {0} - ", wmiConfigEntry.Name); plainTextDetails.Append(string.Format("\t\t{0} - ", wmiConfigEntry.Name)); htmlTextTextDetails.Append(string.Format("<li>{0} - ", wmiConfigEntry.Name)); object val = wmiConfigEntry.RunQuery(); CollectorState currentState = wmiConfigEntry.GetState(val); if (currentState == CollectorState.Error) { errors++; plainTextDetails.AppendLine(string.Format("Machine '{0}' - value '{1}' - Error (trigger {2})", wmiConfigEntry.Machinename, FormatUtils.N(val, "[null]"), wmiConfigEntry.ErrorValue)); htmlTextTextDetails.AppendLine(string.Format("<li>Machine '{0}' - Value '{1}' - <b>Error</b> (trigger {2})</li>", wmiConfigEntry.Machinename, FormatUtils.N(val, "[null]"), wmiConfigEntry.ErrorValue)); } else if (currentState == CollectorState.Warning) { warnings++; plainTextDetails.AppendLine(string.Format("Machine '{0}' - value '{1}' - Warning (trigger {2})", wmiConfigEntry.Machinename, FormatUtils.N(val, "[null]"), wmiConfigEntry.WarningValue)); htmlTextTextDetails.AppendLine(string.Format("<li>Machine '{0}' - Value '{1}' - <b>Warning</b> (trigger {2})</li>", wmiConfigEntry.Machinename, FormatUtils.N(val, "[null]"), wmiConfigEntry.WarningValue)); } else { success++; plainTextDetails.AppendLine(string.Format("Machine '{0}' - value '{1}'", wmiConfigEntry.Machinename, val)); htmlTextTextDetails.AppendLine(string.Format("<li>Machine '{0}' - Value '{1}'</li>", wmiConfigEntry.Machinename, val)); } if (val != null && val.IsNumber()) { totalValue += double.Parse(val.ToString()); } } htmlTextTextDetails.AppendLine("</ul>"); returnState.RawDetails = plainTextDetails.ToString().TrimEnd('\r', '\n'); returnState.HtmlDetails = htmlTextTextDetails.ToString(); returnState.CurrentValue = totalValue; if (errors > 0 && warnings == 0) { returnState.State = CollectorState.Error; } else if (warnings > 0) { returnState.State = CollectorState.Warning; } else { returnState.State = CollectorState.Good; } } catch (Exception ex) { returnState.RawDetails = ex.Message; returnState.HtmlDetails = string.Format("<p><b>Last action:</b> {0}</p><blockquote>{1}</blockquote>", lastAction, ex.Message); returnState.State = CollectorState.Error; } return(returnState); }