//public override MonitorState RefreshState() //{ // MonitorState returnState = new MonitorState(); // string lastAction = ""; // int errors = 0; // int success = 0; // int warnings = 0; // double totalValue = 0; // try // { // RegistryQueryCollectorConfig currentConfig = (RegistryQueryCollectorConfig)AgentConfig; // returnState.RawDetails = string.Format("Running {0} registry query(s)", currentConfig.Entries.Count); // returnState.HtmlDetails = string.Format("<b>Running {0} registry query(s)</b>", currentConfig.Entries.Count); // foreach (RegistryQueryCollectorConfigEntry queryInstance in currentConfig.Entries) // { // object value = null; // if (queryInstance.UseRemoteServer) // lastAction = string.Format("Running Registry query '{0}' on '{1}'", queryInstance.Name, queryInstance.Server); // else // lastAction = string.Format("Running Registry query '{0}'", queryInstance.Name); // value = queryInstance.GetValue(); // if (!queryInstance.ReturnValueIsNumber && value.IsNumber()) // totalValue += double.Parse(value.ToString()); // CollectorState instanceState = queryInstance.EvaluateValue(value); // if (instanceState == CollectorState.Error) // { // errors++; // returnState.ChildStates.Add( // new MonitorState() // { // ForAgent = queryInstance.Name, // State = CollectorState.Error, // CurrentValue = value, // RawDetails = string.Format("'{0}' - value '{1}' - Error (trigger {2})", queryInstance.Name, FormatUtils.FormatArrayToString(value, "[null]"), queryInstance.ErrorValue), // HtmlDetails = string.Format("'{0}' - value '{1}' - <b>Error</b> (trigger {2})", queryInstance.Name, FormatUtils.FormatArrayToString(value, "[null]"), queryInstance.ErrorValue), // }); // } // else if (instanceState == CollectorState.Warning) // { // warnings++; // returnState.ChildStates.Add( // new MonitorState() // { // ForAgent = queryInstance.Name, // State = CollectorState.Warning, // CurrentValue = value, // RawDetails = string.Format("'{0}' - value '{1}' - Warning (trigger {2})", queryInstance.Name, FormatUtils.FormatArrayToString(value, "[null]"), queryInstance.WarningValue), // HtmlDetails = string.Format("'{0}' - value '{1}' - <b>Warning</b> (trigger {2})", queryInstance.Name, FormatUtils.FormatArrayToString(value, "[null]"), queryInstance.WarningValue), // }); // } // else // { // success++; // returnState.ChildStates.Add( // new MonitorState() // { // ForAgent = queryInstance.Name, // State = CollectorState.Good, // CurrentValue = value, // RawDetails = string.Format("'{0}' - value '{1}'", queryInstance.Name, FormatUtils.FormatArrayToString(value, "[null]")), // HtmlDetails = string.Format("'{0}' - value '{1}'", queryInstance.Name, FormatUtils.FormatArrayToString(value, "[null]")), // }); // } // } // if (errors > 0 && warnings == 0) // returnState.State = CollectorState.Error; // else if (warnings > 0) // returnState.State = CollectorState.Warning; // else // returnState.State = CollectorState.Good; // returnState.CurrentValue = totalValue; // } // 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 override List <System.Data.DataTable> GetDetailDataTables() { List <System.Data.DataTable> tables = new List <System.Data.DataTable>(); System.Data.DataTable dt = new System.Data.DataTable(); try { dt.Columns.Add(new System.Data.DataColumn("Path", typeof(string))); dt.Columns.Add(new System.Data.DataColumn("Value", typeof(string))); RegistryQueryCollectorConfig currentConfig = (RegistryQueryCollectorConfig)AgentConfig; foreach (RegistryQueryCollectorConfigEntry entry in currentConfig.Entries) { object value = entry.GetValue(); if (value.GetType().IsArray) { value = FormatUtils.FormatArrayToString(value); } dt.Rows.Add(entry.Description, value); } } catch (Exception ex) { 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 void OKClicked() { if (CheckOKEnabled()) { if (SelectedConfig == null) { SelectedConfig = new RegistryQueryCollectorConfig(); } RegistryQueryCollectorConfig currentConfig = (RegistryQueryCollectorConfig)SelectedConfig; currentConfig.Entries.Clear(); foreach (ListViewItem lvi in lvwEntries.Items) { RegistryQueryInstance registryQueryInstance = (RegistryQueryInstance)lvi.Tag; currentConfig.Entries.Add(registryQueryInstance); } DialogResult = System.Windows.Forms.DialogResult.OK; Close(); } }
public override void LoadList() { if (SelectedConfig != null) { RegistryQueryCollectorConfig currentConfig = (RegistryQueryCollectorConfig)SelectedConfig; lvwEntries.Items.Clear(); foreach (RegistryQueryInstance entry in currentConfig.Entries) { ListViewItem lvi = new ListViewItem(entry.Name); lvi.SubItems.Add(entry.ToString()); //(entry.UseRemoteServer ? entry.Server + "\\" : "") + RegistryQueryInstance.GetRegistryHiveFromString(entry.RegistryHive.ToString()).ToString() + "\\" + entry.Path); lvi.SubItems.Add(entry.KeyName); lvi.SubItems.Add(entry.SuccessValue); lvi.SubItems.Add(entry.WarningValue); lvi.SubItems.Add(entry.ErrorValue); lvi.Tag = entry; lvwEntries.Items.Add(lvi); } } base.LoadList(); }
public RegistryQueryCollector() { AgentConfig = new RegistryQueryCollectorConfig(); }
public override MonitorState GetState() { MonitorState returnState = new MonitorState(); StringBuilder plainTextDetails = new StringBuilder(); StringBuilder htmlTextTextDetails = new StringBuilder(); string lastAction = ""; int errors = 0; int success = 0; int warnings = 0; double totalValue = 0; try { RegistryQueryCollectorConfig config = (RegistryQueryCollectorConfig)AgentConfig; plainTextDetails.AppendLine(string.Format("Running {0} registry query(s)", config.Entries.Count)); htmlTextTextDetails.AppendLine(string.Format("<b>Running {0} registry query(s)</b>", config.Entries.Count)); htmlTextTextDetails.AppendLine("<ul>"); foreach (RegistryQueryInstance queryInstance in config.Entries) { object value = null; if (queryInstance.UseRemoteServer) { lastAction = string.Format("Running Registry query '{0}' on '{1}'", queryInstance.Name, queryInstance.Server); } else { lastAction = string.Format("Running Registry query '{0}'", queryInstance.Name); } value = queryInstance.GetValue(); if (!queryInstance.ReturnValueIsNumber && value.IsNumber()) { totalValue += double.Parse(value.ToString()); } CollectorState instanceState = queryInstance.EvaluateValue(value); if (instanceState == CollectorState.Error) { errors++; plainTextDetails.AppendLine(string.Format("\t'{0}' - value '{1}' - Error (trigger {2})", queryInstance.Name, FormatUtils.FormatArrayToString(value, "[null]"), queryInstance.ErrorValue)); htmlTextTextDetails.AppendLine(string.Format("<li>Machine '{0}' - Value '{1}' - <b>Error</b> (trigger {2})</li>", queryInstance.Name, FormatUtils.FormatArrayToString(value, "[null]"), queryInstance.ErrorValue)); } else if (instanceState == CollectorState.Warning) { warnings++; plainTextDetails.AppendLine(string.Format("\t'{0}' - value '{1}' - Warning (trigger {2})", queryInstance.Name, FormatUtils.FormatArrayToString(value, "[null]"), queryInstance.WarningValue)); htmlTextTextDetails.AppendLine(string.Format("<li>Machine '{0}' - Value '{1}' - <b>Warning</b> (trigger {2})</li>", queryInstance.Name, FormatUtils.FormatArrayToString(value, "[null]"), queryInstance.WarningValue)); } else { success++; plainTextDetails.AppendLine(string.Format("\t'{0}' - value '{1}'", queryInstance.Name, FormatUtils.FormatArrayToString(value))); htmlTextTextDetails.AppendLine(string.Format("<li>Machine '{0}' - Value '{1}'</li>", queryInstance.Name, FormatUtils.FormatArrayToString(value))); } } htmlTextTextDetails.AppendLine("</ul>"); if (errors > 0 && warnings == 0) { returnState.State = CollectorState.Error; } else if (warnings > 0) { returnState.State = CollectorState.Warning; } else { returnState.State = CollectorState.Good; } returnState.RawDetails = plainTextDetails.ToString().TrimEnd('\r', '\n'); returnState.HtmlDetails = htmlTextTextDetails.ToString(); returnState.CurrentValue = totalValue; } 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 override MonitorState RefreshState() { MonitorState returnState = new MonitorState(); string lastAction = ""; int errors = 0; int success = 0; int warnings = 0; double totalValue = 0; try { RegistryQueryCollectorConfig currentConfig = (RegistryQueryCollectorConfig)AgentConfig; returnState.RawDetails = string.Format("Running {0} registry query(s)", currentConfig.Entries.Count); returnState.HtmlDetails = string.Format("<b>Running {0} registry query(s)</b>", currentConfig.Entries.Count); foreach (RegistryQueryCollectorConfigEntry queryInstance in currentConfig.Entries) { object value = null; if (queryInstance.UseRemoteServer) { lastAction = string.Format("Running Registry query '{0}' on '{1}'", queryInstance.Name, queryInstance.Server); } else { lastAction = string.Format("Running Registry query '{0}'", queryInstance.Name); } value = queryInstance.GetValue(); if (!queryInstance.ReturnValueIsNumber && value.IsNumber()) { totalValue += double.Parse(value.ToString()); } CollectorState instanceState = queryInstance.EvaluateValue(value); if (instanceState == CollectorState.Error) { errors++; returnState.ChildStates.Add( new MonitorState() { ForAgent = queryInstance.Name, State = CollectorState.Error, CurrentValue = value, RawDetails = string.Format("'{0}' - value '{1}' - Error (trigger {2})", queryInstance.Name, FormatUtils.FormatArrayToString(value, "[null]"), queryInstance.ErrorValue), HtmlDetails = string.Format("'{0}' - value '{1}' - <b>Error</b> (trigger {2})", queryInstance.Name, FormatUtils.FormatArrayToString(value, "[null]"), queryInstance.ErrorValue), }); } else if (instanceState == CollectorState.Warning) { warnings++; returnState.ChildStates.Add( new MonitorState() { ForAgent = queryInstance.Name, State = CollectorState.Warning, CurrentValue = value, RawDetails = string.Format("'{0}' - value '{1}' - Warning (trigger {2})", queryInstance.Name, FormatUtils.FormatArrayToString(value, "[null]"), queryInstance.WarningValue), HtmlDetails = string.Format("'{0}' - value '{1}' - <b>Warning</b> (trigger {2})", queryInstance.Name, FormatUtils.FormatArrayToString(value, "[null]"), queryInstance.WarningValue), }); } else { success++; returnState.ChildStates.Add( new MonitorState() { ForAgent = queryInstance.Name, State = CollectorState.Good, CurrentValue = value, RawDetails = string.Format("'{0}' - value '{1}'", queryInstance.Name, FormatUtils.FormatArrayToString(value, "[null]")), HtmlDetails = string.Format("'{0}' - value '{1}'", queryInstance.Name, FormatUtils.FormatArrayToString(value, "[null]")), }); } } if (errors > 0 && warnings == 0) { returnState.State = CollectorState.Error; } else if (warnings > 0) { returnState.State = CollectorState.Warning; } else { returnState.State = CollectorState.Good; } returnState.CurrentValue = totalValue; } 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); }