public override void RefreshDisplayData() { try { System.Windows.Forms.Cursor.Current = Cursors.WaitCursor; lvwEntries.BeginUpdate(); foreach (ListViewItem itmX in lvwEntries.Items) { PingCollectorHostEntry host = (PingCollectorHostEntry)itmX.Tag; try { PingCollectorResult pingResult = host.Ping(); CollectorState result = host.GetState(pingResult); if (pingResult.Success) { itmX.SubItems[1].Text = pingResult.PingTime.ToString() + " ms"; itmX.SubItems[2].Text = pingResult.ResponseDetails; if (result == CollectorState.Good) { itmX.ImageIndex = 0; itmX.BackColor = SystemColors.Window; } else if (result == CollectorState.Warning) { itmX.ImageIndex = 1; itmX.BackColor = Color.SandyBrown; } else { itmX.ImageIndex = 2; itmX.BackColor = Color.Salmon; } } else { itmX.ImageIndex = 2; itmX.BackColor = Color.Salmon; if (pingResult.PingTime < 0) { itmX.SubItems[1].Text = "Err"; } itmX.SubItems[2].Text = pingResult.ResponseDetails; } } catch (Exception ex) { itmX.ImageIndex = 2; itmX.SubItems[1].Text = "Err"; itmX.SubItems[2].Text = ex.Message; itmX.BackColor = Color.Salmon; } } lvwEntries.EndUpdate(); System.Windows.Forms.Cursor.Current = Cursors.Default; toolStripStatusLabelDetails.Text = "Last updated " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); } finally { } }
private PingCollectorResult RunPingTest() { PingCollectorResult result; PingCollectorHostEntry tmpPingCollectorHostEntry = new PingCollectorHostEntry(); if (cboPingType.SelectedIndex == 1) { tmpPingCollectorHostEntry.PingType = PingCollectorType.HTTP; if (!txtAddress.Text.ToUpper().StartsWith("HTTP")) { txtAddress.Text = "http://" + txtAddress.Text; } } else if (cboPingType.SelectedIndex == 2) { tmpPingCollectorHostEntry.PingType = PingCollectorType.Socket; } else { tmpPingCollectorHostEntry.PingType = PingCollectorType.Ping; } tmpPingCollectorHostEntry.Address = txtAddress.Text; tmpPingCollectorHostEntry.DescriptionLocal = txtDescription.Text; tmpPingCollectorHostEntry.MaxTimeMS = Convert.ToInt32(nudExpextedTime.Value); tmpPingCollectorHostEntry.TimeOutMS = Convert.ToInt32(nudTimeOut.Value); tmpPingCollectorHostEntry.HttpHeaderUserName = txtHTTPHeaderUsername.Text; tmpPingCollectorHostEntry.HttpHeaderPassword = txtHTTPHeaderPassword.Text; tmpPingCollectorHostEntry.HttpProxyServer = txtHttpProxy.Text; tmpPingCollectorHostEntry.HttpProxyUserName = txtProxyUsername.Text; tmpPingCollectorHostEntry.HttpProxyPassword = txtProxyPassword.Text; tmpPingCollectorHostEntry.HTMLContentContain = txtHTMLContent.Text; tmpPingCollectorHostEntry.IgnoreInvalidHTTPSCerts = chkIgnoreInvalidHTTPSCerts.Checked; tmpPingCollectorHostEntry.SocketPort = (int)nudPortNumber.Value; tmpPingCollectorHostEntry.ReceiveTimeOutMS = (int)nudReceiveTimeout.Value; tmpPingCollectorHostEntry.SendTimeOutMS = (int)nudSendTimeout.Value; tmpPingCollectorHostEntry.UseTelnetLogin = chkUseTelNetLogin.Checked; tmpPingCollectorHostEntry.TelnetUserName = txtUserName.Text; tmpPingCollectorHostEntry.TelnetPassword = txtPassword.Text; result = tmpPingCollectorHostEntry.Ping(); result.Success = tmpPingCollectorHostEntry.GetState(result) == CollectorState.Good; return(result); }
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 void FromXml(string configurationString) { XmlDocument config = new XmlDocument(); config.LoadXml(configurationString); Entries.Clear(); XmlElement root = config.DocumentElement; foreach (XmlElement host in root.SelectNodes("entries/entry")) { PingCollectorHostEntry hostEntry = new PingCollectorHostEntry(); hostEntry.PingType = PingCollectorTypeHelper.FromText(host.ReadXmlElementAttr("pingMethod", "Ping")); hostEntry.Address = host.ReadXmlElementAttr("address"); hostEntry.DescriptionLocal = host.ReadXmlElementAttr("description"); int tmp = 0; if (int.TryParse(host.ReadXmlElementAttr("maxTimeMS", "1000"), out tmp)) { hostEntry.MaxTimeMS = tmp; } if (int.TryParse(host.ReadXmlElementAttr("timeOutMS", "5000"), out tmp)) { hostEntry.TimeOutMS = tmp; } hostEntry.HttpHeaderUserName = host.ReadXmlElementAttr("httpHeaderUser"); hostEntry.HttpHeaderPassword = host.ReadXmlElementAttr("httpHeaderPwd"); hostEntry.HttpProxyServer = host.ReadXmlElementAttr("httpProxyServer"); hostEntry.HttpProxyUserName = host.ReadXmlElementAttr("httpProxyUser"); hostEntry.HttpProxyPassword = host.ReadXmlElementAttr("httpProxyPwd"); if (hostEntry.PingType == PingCollectorType.HTTP) { XmlNode htmlContentMatchNode = host.SelectSingleNode("htmlContentMatch"); if (htmlContentMatchNode != null) { hostEntry.HTMLContentContain = htmlContentMatchNode.InnerText; } } if (int.TryParse(host.ReadXmlElementAttr("socketPort", "23"), out tmp)) { hostEntry.SocketPort = tmp; } if (int.TryParse(host.ReadXmlElementAttr("receiveTimeoutMS", "30000"), out tmp)) { hostEntry.ReceiveTimeOutMS = tmp; } if (int.TryParse(host.ReadXmlElementAttr("sendTimeoutMS", "30000"), out tmp)) { hostEntry.SendTimeOutMS = tmp; } bool btmp; if (bool.TryParse(host.ReadXmlElementAttr("useTelnetLogin", "false"), out btmp)) { hostEntry.UseTelnetLogin = btmp; } hostEntry.TelnetUserName = host.ReadXmlElementAttr("userName"); hostEntry.TelnetPassword = host.ReadXmlElementAttr("password"); hostEntry.IgnoreInvalidHTTPSCerts = host.ReadXmlElementAttr("ignoreInvalidHTTPSCerts", false); hostEntry.HttpsSecurityProtocol = host.ReadXmlElementAttr("httpsSecurityProtocol"); hostEntry.SocketPingMsgBody = host.ReadXmlElementAttr("socketPingMsgBody", "QuickMon Ping Test"); hostEntry.PrimaryUIValue = host.ReadXmlElementAttr("primaryUIValue", false); Entries.Add(hostEntry); } }
//public List<PingCollectorHostEntry> HostEntries = new List<PingCollectorHostEntry>(); #region IAgentConfig Members public void ReadConfiguration(string configurationString) { XmlDocument config = new XmlDocument(); config.LoadXml(configurationString); Entries.Clear(); XmlElement root = config.DocumentElement; foreach (XmlElement host in root.SelectNodes("hostAddress/entry")) { PingCollectorHostEntry hostEntry = new PingCollectorHostEntry(); hostEntry.PingType = PingCollectorTypeHelper.FromText(host.ReadXmlElementAttr("pingMethod", "Ping")); hostEntry.Address = host.ReadXmlElementAttr("address"); hostEntry.DescriptionLocal = host.ReadXmlElementAttr("description"); int tmp = 0; if (int.TryParse(host.ReadXmlElementAttr("maxTimeMS", "1000"), out tmp)) { hostEntry.MaxTimeMS = tmp; } if (int.TryParse(host.ReadXmlElementAttr("timeOutMS", "5000"), out tmp)) { hostEntry.TimeOutMS = tmp; } hostEntry.HttpProxyServer = host.ReadXmlElementAttr("httpProxyServer"); if (int.TryParse(host.ReadXmlElementAttr("socketPort", "23"), out tmp)) { hostEntry.SocketPort = tmp; } if (int.TryParse(host.ReadXmlElementAttr("receiveTimeoutMS", "30000"), out tmp)) { hostEntry.ReceiveTimeOutMS = tmp; } if (int.TryParse(host.ReadXmlElementAttr("sendTimeoutMS", "30000"), out tmp)) { hostEntry.SendTimeOutMS = tmp; } bool btmp; if (bool.TryParse(host.ReadXmlElementAttr("useTelnetLogin", "false"), out btmp)) { hostEntry.UseTelnetLogin = btmp; } hostEntry.TelnetUserName = host.ReadXmlElementAttr("userName"); hostEntry.TelnetPassword = host.ReadXmlElementAttr("password"); hostEntry.IgnoreInvalidHTTPSCerts = host.ReadXmlElementAttr("ignoreInvalidHTTPSCerts", false); Entries.Add(hostEntry); } //for backwards compatibility try old Ping config foreach (XmlElement host in root.SelectNodes("hosts/host")) { PingCollectorHostEntry hostEntry = new PingCollectorHostEntry(); hostEntry.Address = host.Attributes.GetNamedItem("hostName").Value; hostEntry.DescriptionLocal = host.Attributes.GetNamedItem("description").Value; int tmp = 0; if (int.TryParse(host.Attributes.GetNamedItem("maxTime").Value, out tmp)) { hostEntry.MaxTimeMS = tmp; } if (int.TryParse(host.Attributes.GetNamedItem("timeOut").Value, out tmp)) { hostEntry.TimeOutMS = tmp; } Entries.Add(hostEntry); } }