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("Host name", typeof(string))); dt.Columns.Add(new System.Data.DataColumn("Success", typeof(bool))); dt.Columns.Add(new System.Data.DataColumn("Ping time", typeof(int))); dt.Columns.Add(new System.Data.DataColumn("Response", typeof(string))); PingCollectorConfig currentConfig = (PingCollectorConfig)AgentConfig; foreach (PingCollectorHostEntry host in currentConfig.Entries) //.OrderBy(h => ((PingCollectorHostEntry)h).Address)) { PingCollectorResult pingResult = host.Ping(); dt.Rows.Add(host.Address, pingResult.Success, pingResult.PingTime, pingResult.ResponseDetails); } } 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 LoadDisplayData() { if (Collector != null && Collector.AgentConfig != null) { PingCollectorConfig pc = (PingCollectorConfig)Collector.AgentConfig; lvwEntries.Items.Clear(); foreach (PingCollectorHostEntry hostEntry in pc.Entries) { ListViewItem lvi = new ListViewItem(hostEntry.ToString()); lvi.ImageIndex = 0; lvi.SubItems.Add("-"); lvi.SubItems.Add("-"); lvi.Tag = hostEntry; lvwEntries.Items.Add(lvi); } } }
public override void LoadList() { if (SelectedConfig != null) { PingCollectorConfig pingCollectorConfig = (PingCollectorConfig)SelectedConfig; foreach (PingCollectorHostEntry hostEntry in pingCollectorConfig.Entries) { ListViewItem lvi = new ListViewItem(hostEntry.ToString()); lvi.SubItems.Add(hostEntry.MaxTimeMS.ToString()); lvi.SubItems.Add(hostEntry.TimeOutMS.ToString()); lvi.SubItems.Add(hostEntry.DescriptionLocal); lvi.Tag = hostEntry; lvwEntries.Items.Add(lvi); } } base.LoadList(); }
public override void OKClicked() { if (CheckOKEnabled()) { if (SelectedConfig == null) { SelectedConfig = new PingCollectorConfig(); } PingCollectorConfig pingCollectorConfig = (PingCollectorConfig)SelectedConfig; pingCollectorConfig.Entries.Clear(); foreach (ListViewItem lvi in lvwEntries.Items) { PingCollectorHostEntry hostEntry = (PingCollectorHostEntry)lvi.Tag; pingCollectorConfig.Entries.Add(hostEntry); } DialogResult = DialogResult.OK; Close(); } }
public PingCollector() { AgentConfig = new PingCollectorConfig(); }
public override MonitorState RefreshState() { MonitorState returnState = new MonitorState(); string lastAction = ""; long pingTotalTime = 0; int errors = 0; int warnings = 0; int success = 0; try { PingCollectorConfig currentConfig = (PingCollectorConfig)AgentConfig; returnState.RawDetails = string.Format("Pinging {0} entries", currentConfig.Entries.Count); returnState.HtmlDetails = string.Format("<b>Pinging {0} entries</b>", currentConfig.Entries.Count); foreach (PingCollectorHostEntry host in currentConfig.Entries) { PingCollectorResult pingResult = host.Ping(); CollectorState currentState = host.GetState(pingResult); if (pingResult.Success) { pingTotalTime += pingResult.PingTime; if (currentState == CollectorState.Error) { errors++; returnState.ChildStates.Add( new MonitorState() { ForAgent = host.Address, State = CollectorState.Error, CurrentValue = pingResult.PingTime, RawDetails = string.Format("Response details : '{0}'", pingResult.ResponseDetails) }); } else if (currentState == CollectorState.Warning) { warnings++; returnState.ChildStates.Add( new MonitorState() { ForAgent = host.Address, State = CollectorState.Warning, CurrentValue = pingResult.PingTime, RawDetails = string.Format("Response details : '{0}'", pingResult.ResponseDetails) }); } else { success++; returnState.ChildStates.Add( new MonitorState() { ForAgent = host.Address, State = CollectorState.Good, CurrentValue = pingResult.PingTime, RawDetails = string.Format("Response details : '{0}'", pingResult.ResponseDetails) }); } } else { errors++; returnState.ChildStates.Add( new MonitorState() { ForAgent = host.Address, State = CollectorState.Error, CurrentValue = "", RawDetails = string.Format("Response details : '{0}'", pingResult.ResponseDetails) }); } } returnState.CurrentValue = pingTotalTime; 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 MonitorState GetState() { MonitorState returnState = new MonitorState(); StringBuilder plainTextDetails = new StringBuilder(); StringBuilder htmlTextTextDetails = new StringBuilder(); string lastAction = ""; long pingTotalTime = 0; int errors = 0; int warnings = 0; int success = 0; try { PingCollectorConfig currentConfig = (PingCollectorConfig)AgentConfig; plainTextDetails.AppendLine(string.Format("Pinging {0} entries", currentConfig.Entries.Count)); htmlTextTextDetails.AppendLine(string.Format("<b>Pinging {0} entries</b>", currentConfig.Entries.Count)); htmlTextTextDetails.AppendLine("<ul>"); foreach (PingCollectorHostEntry host in currentConfig.Entries) { PingCollectorResult pingResult = host.Ping(); CollectorState currentState = host.GetState(pingResult); if (pingResult.Success) { pingTotalTime += pingResult.PingTime; if (currentState == CollectorState.Error) { errors++; plainTextDetails.AppendLine(string.Format("\t{0} (Error) - {1} ", host.Address, pingResult.ResponseDetails)); htmlTextTextDetails.AppendLine(string.Format("<li>{0} (<b>Error</b>) - {1}</li>", host.Address, pingResult.ResponseDetails)); } else if (currentState == CollectorState.Warning) { warnings++; plainTextDetails.AppendLine(string.Format("\t{0} (Warning) - {1}ms - {2}", host.Address, pingResult.PingTime, pingResult.ResponseDetails)); htmlTextTextDetails.AppendLine(string.Format("<li>{0} (<b>Warning</b>) - {1}ms - {2}</li>", host.Address, pingResult.PingTime, pingResult.ResponseDetails)); } else { success++; plainTextDetails.AppendLine(string.Format("\t{0} (Success) - {1}ms - {2}", host.Address, pingResult.PingTime, pingResult.ResponseDetails)); htmlTextTextDetails.AppendLine(string.Format("<li>{0} (<b>Success</b>) - {1}ms - {2}</li>", host.Address, pingResult.PingTime, pingResult.ResponseDetails)); } } else { errors++; plainTextDetails.AppendLine(string.Format("\t{0} (Error)- {1}", host.Address, pingResult.ResponseDetails)); htmlTextTextDetails.AppendLine(string.Format("<li>{0} (<b>Error</b>) - {1}</li>", host.Address, pingResult.ResponseDetails)); } } htmlTextTextDetails.AppendLine("</ul>"); returnState.RawDetails = plainTextDetails.ToString().TrimEnd('\r', '\n'); returnState.HtmlDetails = htmlTextTextDetails.ToString(); returnState.CurrentValue = pingTotalTime; if (errors > 0) // any errors returnState.State = CollectorState.Error; else if (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; }