Exemple #1
0
        public string ToConfig()
        {
            XmlDocument config = new XmlDocument();

            config.LoadXml("<config><hostAddress></hostAddress></config>");
            XmlNode hostsListNode = config.SelectSingleNode("config/hostAddress");

            foreach (PingCollectorHostEntry hostEntry in Entries)
            {
                XmlNode hostXmlNode = config.CreateElement("entry");
                hostXmlNode.SetAttributeValue("pingMethod", PingCollectorTypeHelper.ToString(hostEntry.PingType));
                hostXmlNode.SetAttributeValue("address", hostEntry.Address);
                hostXmlNode.SetAttributeValue("description", hostEntry.DescriptionLocal);
                hostXmlNode.SetAttributeValue("maxTimeMS", hostEntry.MaxTimeMS);
                hostXmlNode.SetAttributeValue("timeOutMS", hostEntry.TimeOutMS);
                hostXmlNode.SetAttributeValue("httpProxyServer", hostEntry.HttpProxyServer);
                hostXmlNode.SetAttributeValue("socketPort", hostEntry.SocketPort);
                hostXmlNode.SetAttributeValue("receiveTimeoutMS", hostEntry.ReceiveTimeOutMS);
                hostXmlNode.SetAttributeValue("sendTimeoutMS", hostEntry.SendTimeOutMS);
                hostXmlNode.SetAttributeValue("useTelnetLogin", hostEntry.UseTelnetLogin);
                hostXmlNode.SetAttributeValue("userName", hostEntry.TelnetUserName);
                hostXmlNode.SetAttributeValue("password", hostEntry.TelnetPassword);
                hostXmlNode.SetAttributeValue("ignoreInvalidHTTPSCerts", hostEntry.IgnoreInvalidHTTPSCerts);
                hostsListNode.AppendChild(hostXmlNode);
            }
            return(config.OuterXml);
        }
Exemple #2
0
        public string ToXml()
        {
            XmlDocument config = new XmlDocument();

            config.LoadXml(GetDefaultOrEmptyXml());
            XmlNode hostsListNode = config.SelectSingleNode("config/entries");

            foreach (PingCollectorHostEntry hostEntry in Entries)
            {
                XmlNode hostXmlNode = config.CreateElement("entry");
                hostXmlNode.SetAttributeValue("pingMethod", PingCollectorTypeHelper.ToString(hostEntry.PingType));
                hostXmlNode.SetAttributeValue("address", hostEntry.Address);
                hostXmlNode.SetAttributeValue("description", hostEntry.DescriptionLocal);
                hostXmlNode.SetAttributeValue("maxTimeMS", hostEntry.MaxTimeMS);
                hostXmlNode.SetAttributeValue("timeOutMS", hostEntry.TimeOutMS);
                hostXmlNode.SetAttributeValue("httpHeaderUser", hostEntry.HttpHeaderUserName);
                hostXmlNode.SetAttributeValue("httpHeaderPwd", hostEntry.HttpHeaderPassword);
                hostXmlNode.SetAttributeValue("httpProxyServer", hostEntry.HttpProxyServer);
                hostXmlNode.SetAttributeValue("httpProxyUser", hostEntry.HttpProxyUserName);
                hostXmlNode.SetAttributeValue("httpProxyPwd", hostEntry.HttpProxyPassword);
                hostXmlNode.SetAttributeValue("socketPort", hostEntry.SocketPort);
                hostXmlNode.SetAttributeValue("receiveTimeoutMS", hostEntry.ReceiveTimeOutMS);
                hostXmlNode.SetAttributeValue("sendTimeoutMS", hostEntry.SendTimeOutMS);
                hostXmlNode.SetAttributeValue("useTelnetLogin", hostEntry.UseTelnetLogin);
                hostXmlNode.SetAttributeValue("userName", hostEntry.TelnetUserName);
                hostXmlNode.SetAttributeValue("password", hostEntry.TelnetPassword);
                hostXmlNode.SetAttributeValue("ignoreInvalidHTTPSCerts", hostEntry.IgnoreInvalidHTTPSCerts);
                hostXmlNode.SetAttributeValue("httpsSecurityProtocol", hostEntry.HttpsSecurityProtocol);
                hostXmlNode.SetAttributeValue("socketPingMsgBody", hostEntry.SocketPingMsgBody);
                hostXmlNode.SetAttributeValue("primaryUIValue", hostEntry.PrimaryUIValue);

                if (hostEntry.PingType == PingCollectorType.HTTP && hostEntry.HTMLContentContain.Trim().Length > 0)
                {
                    XmlNode htmlContentMatchNode = config.CreateElement("htmlContentMatch");
                    htmlContentMatchNode.InnerText = hostEntry.HTMLContentContain;
                    hostXmlNode.AppendChild(htmlContentMatchNode);
                }
                hostsListNode.AppendChild(hostXmlNode);
            }
            return(config.OuterXml);
        }
Exemple #3
0
        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);
            }
        }
Exemple #4
0
        //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);
            }
        }
 public override string ToString()
 {
     return(string.Format("[{0}] {1}", PingCollectorTypeHelper.ToString(pingType), address + (pingType == PingCollectorType.Socket ? (":" + socketPort.ToString()) : "")));
 }