//public override MonitorState RefreshState() //{ // MonitorState returnState = new MonitorState(); // string lastAction = ""; // int errors = 0; // int warnings = 0; // int success = 0; // try // { // SqlQueryCollectorConfig currentConfig = (SqlQueryCollectorConfig)AgentConfig; // returnState.RawDetails = string.Format("Running {0} queries", currentConfig.Entries.Count); // returnState.HtmlDetails = string.Format("<b>Running {0} queries</b>", currentConfig.Entries.Count); // returnState.CurrentValue = 0; // foreach (SqlQueryCollectorEntry entry in currentConfig.Entries) // { // object value = entry.GetStateQueryValue(); // CollectorState currentState = CollectorAgentReturnValueCompareEngine.GetState(entry.ValueReturnCheckSequence, entry.SuccessMatchType, entry.SuccessValueOrMacro, // entry.WarningMatchType, entry.WarningValueOrMacro, entry.ErrorMatchType, entry.ErrorValueOrMacro, value); // if (value.IsNumber()) // { // returnState.CurrentValue = Double.Parse(returnState.CurrentValue.ToString()) + Double.Parse(value.ToString()); // } // if (currentState == CollectorState.Error) // { // errors++; // returnState.ChildStates.Add( // new MonitorState() // { // State = CollectorState.Error, // ForAgent = entry.Name, // CurrentValue = value//, // //RawDetails = string.Format("(Trigger '{0}')", entry.TriggerSummary) // }); // } // else if (currentState == CollectorState.Warning) // { // warnings++; // returnState.ChildStates.Add( // new MonitorState() // { // State = CollectorState.Warning, // ForAgent = entry.Name, // CurrentValue = value//, // //RawDetails = string.Format("(Trigger '{0}')", entry.TriggerSummary) // }); // } // else // { // success++; // returnState.ChildStates.Add( // new MonitorState() // { // State = CollectorState.Good, // ForAgent = entry.Name, // CurrentValue = value // }); // } // } // if (errors > 0 && warnings == 0 && success == 0) // any errors // returnState.State = CollectorState.Error; // else if (errors > 0 || warnings > 0) //any warnings // 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 override List <System.Data.DataTable> GetDetailDataTables() { List <System.Data.DataTable> tables = new List <System.Data.DataTable>(); SqlQueryCollectorConfig currentConfig = (SqlQueryCollectorConfig)AgentConfig; int tableNo = 1; foreach (SqlQueryCollectorEntry entry in currentConfig.Entries) { System.Data.DataTable dt = entry.GetDetailQueryDataTable(); if (entry.Name.Length > 0) { dt.TableName = entry.Name; } else { dt.TableName = "Table " + tableNo.ToString(); } while ((from t in tables where t.TableName == dt.TableName select t).Count() > 0) { dt.TableName = "Table " + tableNo.ToString(); tableNo++; } tables.Add(dt); tableNo++; } return(tables); }
public override void LoadDisplayData() { if (Collector != null && Collector.AgentConfig != null) { SqlQueryCollectorConfig sqlQueryConfig = (SqlQueryCollectorConfig)Collector.AgentConfig; lvwResults.Items.Clear(); foreach (QueryInstance queryInstance in sqlQueryConfig.Entries) { ListViewItem lvi = new ListViewItem(queryInstance.Name); lvi.SubItems.Add(GetQIValue(lvi, queryInstance)); lvi.Tag = queryInstance; lvwResults.Items.Add(lvi); } } ExportButtonVisible = lvwResults.Items.Count > 0; base.LoadDisplayData(); }
public override void OKClicked() { if (SelectedConfig == null) { SelectedConfig = new SqlQueryCollectorConfig(); } SqlQueryCollectorConfig sqlQueryConfig = (SqlQueryCollectorConfig)SelectedConfig; sqlQueryConfig.Entries.Clear(); foreach (ListViewItem lvi in lvwEntries.Items) { QueryInstance queryInstance = (QueryInstance)lvi.Tag; sqlQueryConfig.Entries.Add(queryInstance); } DialogResult = System.Windows.Forms.DialogResult.OK; Close(); }
public override void LoadList() { if (SelectedConfig != null) { SqlQueryCollectorConfig sqlQueryConfig = (SqlQueryCollectorConfig)SelectedConfig; lvwEntries.Items.Clear(); foreach (QueryInstance queryInstance in sqlQueryConfig.Entries) { ListViewItem lvi = new ListViewItem(queryInstance.Name); lvi.SubItems.Add(queryInstance.ToServerDBName()); lvi.SubItems.Add(queryInstance.WarningValue); lvi.SubItems.Add(queryInstance.ErrorValue); lvi.Tag = queryInstance; lvwEntries.Items.Add(lvi); } } base.LoadList(); }
public SqlQueryCollector() { AgentConfig = new SqlQueryCollectorConfig(); }
public override MonitorState GetState() { MonitorState returnState = new MonitorState() { State = CollectorState.Good }; StringBuilder plainTextDetails = new StringBuilder(); StringBuilder htmlTextTextDetails = new StringBuilder(); string lastAction = ""; int errors = 0; int warnings = 0; int success = 0; double totalValue = 0; try { SqlQueryCollectorConfig sqlQueryConfig = (SqlQueryCollectorConfig)AgentConfig; plainTextDetails.AppendLine(string.Format("SQL Queries")); htmlTextTextDetails.AppendLine(string.Format("SQL Queries")); htmlTextTextDetails.AppendLine("<ul>"); foreach (QueryInstance queryInstance in sqlQueryConfig.Entries) { object value = null; lastAction = string.Format("Running SQL query '{0}' on '{1}\\{2}'", queryInstance.Name, queryInstance.SqlServer, queryInstance.Database); value = queryInstance.RunQuery(); CollectorState currentstate = queryInstance.GetState(value); if (value != DBNull.Value && value.IsNumber()) { totalValue += double.Parse(value.ToString()); } if (currentstate == CollectorState.Error) { errors++; plainTextDetails.AppendLine(string.Format("\t'{0}' - value '{1}' - Error (trigger {2})", queryInstance.Name, FormatUtils.N(value, "[null]"), queryInstance.ErrorValue)); htmlTextTextDetails.AppendLine(string.Format("<li>'{0}' - Value '{1}' - <b>Error</b> (trigger {2})</li>", queryInstance.Name, FormatUtils.N(value, "[null]"), queryInstance.ErrorValue)); } else if (currentstate == CollectorState.Warning) { warnings++; plainTextDetails.AppendLine(string.Format("\t'{0}' - value '{1}' - Warning (trigger {2})", queryInstance.Name, FormatUtils.N(value, "[null]"), queryInstance.WarningValue)); htmlTextTextDetails.AppendLine(string.Format("<li>'{0}' - Value '{1}' - <b>Warning</b> (trigger {2})</li>", queryInstance.Name, FormatUtils.N(value, "[null]"), queryInstance.WarningValue)); } else { success++; plainTextDetails.AppendLine(string.Format("\t'{0}' - value '{1}'", queryInstance.Name, value)); htmlTextTextDetails.AppendLine(string.Format("<li>'{0}' - Value '{1}'</li>", queryInstance.Name, value)); } } htmlTextTextDetails.AppendLine("</ul>"); if (errors > 0 && warnings == 0) { returnState.State = CollectorState.Error; } else if (warnings > 0) { returnState.State = CollectorState.Warning; } returnState.RawDetails = plainTextDetails.ToString().TrimEnd('\r', '\n'); returnState.HtmlDetails = htmlTextTextDetails.ToString(); returnState.CurrentValue = totalValue; } catch (Exception ex) { returnState.RawDetails = string.Format("Last step: '{0}\r\n{1}", lastAction, ex.Message); returnState.HtmlDetails = string.Format("<blockquote>Last step: '{0}<br />{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 warnings = 0; int success = 0; try { SqlQueryCollectorConfig currentConfig = (SqlQueryCollectorConfig)AgentConfig; returnState.RawDetails = string.Format("Running {0} queries", currentConfig.Entries.Count); returnState.HtmlDetails = string.Format("<b>Running {0} queries</b>", currentConfig.Entries.Count); returnState.CurrentValue = 0; foreach (SqlQueryCollectorEntry entry in currentConfig.Entries) { object value = entry.GetStateQueryValue(); CollectorState currentState = CollectorAgentReturnValueCompareEngine.GetState(entry.ValueReturnCheckSequence, entry.SuccessMatchType, entry.SuccessValueOrMacro, entry.WarningMatchType, entry.WarningValueOrMacro, entry.ErrorMatchType, entry.ErrorValueOrMacro, value); if (value.IsNumber()) { returnState.CurrentValue = Double.Parse(returnState.CurrentValue.ToString()) + Double.Parse(value.ToString()); } if (currentState == CollectorState.Error) { errors++; returnState.ChildStates.Add( new MonitorState() { State = CollectorState.Error, ForAgent = entry.Name, CurrentValue = value //, //RawDetails = string.Format("(Trigger '{0}')", entry.TriggerSummary) }); } else if (currentState == CollectorState.Warning) { warnings++; returnState.ChildStates.Add( new MonitorState() { State = CollectorState.Warning, ForAgent = entry.Name, CurrentValue = value //, //RawDetails = string.Format("(Trigger '{0}')", entry.TriggerSummary) }); } else { success++; returnState.ChildStates.Add( new MonitorState() { State = CollectorState.Good, ForAgent = entry.Name, CurrentValue = value }); } } if (errors > 0 && warnings == 0 && success == 0) // any errors { returnState.State = CollectorState.Error; } else if (errors > 0 || warnings > 0) //any warnings { 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); }