public void AgentCheckSequenceTest() { string configXml = "<collectorHosts>\r\n" + "<collectorHost uniqueId=\"123\" name=\"Ping test\" enabled=\"True\" " + "agentCheckSequence=\"All\" childCheckBehaviour=\"OnlyRunOnSuccess\" >\r\n" + "<collectorAgents>\r\n" + "<collectorAgent type=\"PingCollector\">\r\n" + "<config>\r\n" + "<entries>\r\n" + "<entry pingMethod=\"Ping\" address=\"localhost\" />\r\n" + "</entries>\r\n" + "</config>\r\n" + "</collectorAgent>\r\n" + "<collectorAgent type=\"PingCollector\">\r\n" + "<config>\r\n" + "<entries>\r\n" + "<entry pingMethod=\"Ping\" address=\"localhostInvalid\" />\r\n" + "</entries>\r\n" + "</config>\r\n" + "</collectorAgent>\r\n" + "<collectorAgent type=\"PingCollector\">\r\n" + "<config>\r\n" + "<entries>\r\n" + "<entry pingMethod=\"Ping\" address=\"localhost\" />\r\n" + "</entries>\r\n" + "</config>\r\n" + "</collectorAgent>\r\n" + "</collectorAgents>\r\n" + "</collectorHost>\r\n" + "</collectorHosts>"; List <CollectorHost> chList = CollectorHost.GetCollectorHostsFromString(configXml); Assert.IsNotNull(chList, "CollectorHost list is null"); if (chList != null && chList.Count == 1) { MonitorState ms = chList[0].RefreshCurrentState(); Assert.AreEqual(3, ms.ChildStates.Count, "All agents expected to execute"); chList[0].AgentCheckSequence = AgentCheckSequence.FirstSuccess; ms = chList[0].RefreshCurrentState(); Assert.AreEqual(1, ms.ChildStates.Count, "Only first agent expected to execute"); chList[0].AgentCheckSequence = AgentCheckSequence.FirstError; ms = chList[0].RefreshCurrentState(); Assert.AreEqual(2, ms.ChildStates.Count, "Second agent expected to execute"); } }
public void CreateCollectorHostTest() { string configXml = "<collectorHosts>\r\n" + "<collectorHost uniqueId=\"123\" name=\"Ping test\" enabled=\"True\" expandOnStart=\"True\" dependOnParentId=\"\" " + "agentCheckSequence=\"All\" childCheckBehaviour=\"OnlyRunOnSuccess\" " + "repeatAlertInXMin=\"0\" alertOnceInXMin=\"0\" delayErrWarnAlertForXSec=\"0\" " + "repeatAlertInXPolls=\"0\" alertOnceInXPolls=\"0\" delayErrWarnAlertForXPolls=\"0\" " + "correctiveScriptDisabled=\"False\" correctiveScriptOnWarningPath=\"\" correctiveScriptOnErrorPath=\"\" " + "restorationScriptPath=\"\" correctiveScriptsOnlyOnStateChange=\"True\" enableRemoteExecute=\"False\" " + "forceRemoteExcuteOnChildCollectors=\"True\" remoteAgentHostAddress=\"\" remoteAgentHostPort=\"48181\" " + "blockParentRemoteAgentHostSettings=\"False\" runLocalOnRemoteHostConnectionFailure=\"False\" " + "enabledPollingOverride=\"False\" onlyAllowUpdateOncePerXSec=\"1\" enablePollFrequencySliding=\"False\" " + "pollSlideFrequencyAfterFirstRepeatSec=\"2\" pollSlideFrequencyAfterSecondRepeatSec=\"5\" " + "pollSlideFrequencyAfterThirdRepeatSec=\"30\">\r\n" + "<collectorAgents>\r\n" + "<collectorAgent type=\"PingCollector\">\r\n" + "<config>\r\n" + "<entries>\r\n" + "<entry pingMethod=\"Ping\" address=\"localhost\" />\r\n" + "</entries>\r\n" + "</config>\r\n" + "</collectorAgent>\r\n" + "</collectorAgents>\r\n" + "</collectorHost>\r\n" + "</collectorHosts>"; List <CollectorHost> chList = CollectorHost.GetCollectorHostsFromString(configXml); Assert.IsNotNull(chList, "CollectorHost list is null"); if (chList != null) { Assert.IsNotNull(chList[0].ToXml(), "CollectorHost[0].ToXml is null"); string chXml = chList[0].ToXml(); Assert.AreNotEqual("", chXml, "CollectorHost[0].ToXml is empty"); StringBuilder rebuildXml = new StringBuilder(); rebuildXml.AppendLine("<collectorHosts>"); foreach (CollectorHost ch in chList) { rebuildXml.AppendLine(ch.ToXml()); } rebuildXml.AppendLine("</collectorHosts>"); chList = CollectorHost.GetCollectorHostsFromString(configXml); Assert.IsNotNull(chList, "CollectorHost list is null (test 2)"); } }
public void CallCollectorHostThroughRemoteHost() { //For this test to work the Remote host service (QuickMon 4 Service) must be started on the local machine string configXml = "<collectorHosts>\r\n" + "<collectorHost uniqueId=\"1234\" name=\"Ping test\" enabled=\"True\" expandOnStart=\"True\" dependOnParentId=\"\" " + "agentCheckSequence=\"All\" childCheckBehaviour=\"OnlyRunOnSuccess\" " + "repeatAlertInXMin=\"0\" alertOnceInXMin=\"0\" delayErrWarnAlertForXSec=\"0\" " + "repeatAlertInXPolls=\"0\" alertOnceInXPolls=\"0\" delayErrWarnAlertForXPolls=\"0\" " + "correctiveScriptDisabled=\"False\" correctiveScriptOnWarningPath=\"\" correctiveScriptOnErrorPath=\"\" " + "restorationScriptPath=\"\" correctiveScriptsOnlyOnStateChange=\"True\" enableRemoteExecute=\"True\" " + "forceRemoteExcuteOnChildCollectors=\"True\" remoteAgentHostAddress=\"localhost\" remoteAgentHostPort=\"48181\" " + "blockParentRemoteAgentHostSettings=\"False\" runLocalOnRemoteHostConnectionFailure=\"False\" " + "enabledPollingOverride=\"False\" onlyAllowUpdateOncePerXSec=\"1\" enablePollFrequencySliding=\"False\" " + "pollSlideFrequencyAfterFirstRepeatSec=\"2\" pollSlideFrequencyAfterSecondRepeatSec=\"5\" " + "pollSlideFrequencyAfterThirdRepeatSec=\"30\">\r\n" + "<collectorAgents>\r\n" + "<collectorAgent type=\"PingCollector\">\r\n" + "<config>\r\n" + "<entries>\r\n" + "<entry pingMethod=\"Ping\" address=\"localhost\" />\r\n" + "</entries>\r\n" + "</config>\r\n" + "</collectorAgent>\r\n" + "</collectorAgents>\r\n" + "</collectorHost>\r\n" + "</collectorHosts>"; List <CollectorHost> chList = CollectorHost.GetCollectorHostsFromString(configXml); Assert.IsNotNull(chList, "CollectorHost list is null"); if (chList != null) { Assert.AreEqual(true, chList[0].EnableRemoteExecute, "Remote execute not enabled"); Assert.AreEqual(false, chList[0].RunLocalOnRemoteHostConnectionFailure, "RunLocalOnRemoteHostConnectionFailure should not be set"); MonitorState ms = chList[0].RefreshCurrentState(); Assert.AreEqual(false, ms.ReadAllRawDetails().Contains("There was no endpoint"), "Remote host service not started!"); Assert.IsNotNull(ms.ChildStates, "No Child states"); Assert.AreEqual(1, ms.ChildStates.Count, "One child state expected"); Assert.AreEqual(CollectorState.Good, ms.ChildStates[0].State, "Child state should be good"); Assert.AreEqual(CollectorState.Good, ms.State, "Global state should be good"); Assert.AreEqual(System.Net.Dns.GetHostName(), ms.ExecutedOnHostComputer, "Should run on localhost"); } }
public void CollectorHostToRemoteCollectorHostConversionTest() { string configXml = "<collectorHosts>\r\n" + "<collectorHost uniqueId=\"1234\" name=\"Ping test\" enabled=\"True\" expandOnStart=\"True\" dependOnParentId=\"\" " + "agentCheckSequence=\"All\" childCheckBehaviour=\"OnlyRunOnSuccess\" " + "repeatAlertInXMin=\"0\" alertOnceInXMin=\"0\" delayErrWarnAlertForXSec=\"0\" " + "repeatAlertInXPolls=\"0\" alertOnceInXPolls=\"0\" delayErrWarnAlertForXPolls=\"0\" " + "correctiveScriptDisabled=\"False\" correctiveScriptOnWarningPath=\"\" correctiveScriptOnErrorPath=\"\" " + "restorationScriptPath=\"\" correctiveScriptsOnlyOnStateChange=\"True\" enableRemoteExecute=\"False\" " + "forceRemoteExcuteOnChildCollectors=\"True\" remoteAgentHostAddress=\"\" remoteAgentHostPort=\"48181\" " + "blockParentRemoteAgentHostSettings=\"False\" runLocalOnRemoteHostConnectionFailure=\"False\" " + "enabledPollingOverride=\"False\" onlyAllowUpdateOncePerXSec=\"1\" enablePollFrequencySliding=\"False\" " + "pollSlideFrequencyAfterFirstRepeatSec=\"2\" pollSlideFrequencyAfterSecondRepeatSec=\"5\" " + "pollSlideFrequencyAfterThirdRepeatSec=\"30\">\r\n" + "<collectorAgents>\r\n" + "<collectorAgent type=\"PingCollector\">\r\n" + "<config>\r\n" + "<entries>\r\n" + "<entry pingMethod=\"Ping\" address=\"localhost\" />\r\n" + "</entries>\r\n" + "</config>\r\n" + "</collectorAgent>\r\n" + "</collectorAgents>\r\n" + "</collectorHost>\r\n" + "</collectorHosts>"; List <CollectorHost> chList = CollectorHost.GetCollectorHostsFromString(configXml); Assert.IsNotNull(chList, "CollectorHost list is null"); if (chList != null) { RemoteCollectorHost rch = new RemoteCollectorHost(); rch.FromCollectorHost(chList[0]); Assert.AreEqual(1, rch.Agents.Count, "Expected 1 Agent - " + rch.ToCollectorHostXml()); Assert.AreNotEqual("", rch.ToCollectorHostXml(), "RemoteCollectorHost.FromCollectorHost is empty"); if (rch.Agents.Count == 1) { Assert.AreEqual("PingCollector", rch.Agents[0].TypeName, "Type should be PingCollector"); Assert.AreNotEqual(0, rch.Agents[0].ConfigString.Length, "Agent config must not be blank"); } } }
public void LoadXml(string xmlConfig) { Stopwatch sw = new Stopwatch(); XmlDocument configurationXml = new XmlDocument(); sw.Start(); configurationXml.LoadXml(xmlConfig); sw.Stop(); System.Diagnostics.Trace.WriteLine(string.Format("MonitorPack Loading XML time:{0}ms", sw.ElapsedMilliseconds)); sw.Reset(); sw.Start(); XmlElement root = configurationXml.DocumentElement; Name = root.Attributes.GetNamedItem("name").Value; TypeName = root.ReadXmlElementAttr("typeName", ""); this.Version = root.ReadXmlElementAttr("version", "4.0.0.0"); Enabled = root.ReadXmlElementAttr("enabled", true); CollectorStateHistorySize = root.ReadXmlElementAttr("stateHistorySize", 1); PollingFrequencyOverrideSec = root.ReadXmlElementAttr("pollingFreqSecOverride", 0); string defaultNotifierName = root.ReadXmlElementAttr("defaultNotifier"); RunCorrectiveScripts = root.ReadXmlElementAttr("runCorrectiveScripts", true); LoggingEnabled = root.ReadXmlElementAttr("loggingEnabled", false); /***************** Load config variables ****************/ #region Load config variables XmlNode configVarsNode = root.SelectSingleNode("configVars"); ConfigVariables = new List <ConfigVariable>(); if (configVarsNode != null) { foreach (XmlElement configVarNodeEntry in configVarsNode.SelectNodes("configVar")) { ConfigVariables.Add(ConfigVariable.FromXml(configVarNodeEntry.OuterXml)); } } #endregion /***************** Load Collectors ****************/ #region Load Collectors XmlNode collectorHostsNode = root.SelectSingleNode("collectorHosts"); if (collectorHostsNode != null) { CollectorHosts = CollectorHost.GetCollectorHostsFromString(collectorHostsNode.OuterXml, ConfigVariables); foreach (CollectorHost collectorHost in CollectorHosts) { SetCollectorHostEvents(collectorHost); } } #endregion /***************** Load Notifiers ****************/ #region Load Notifiers XmlNode notifierHostsNode = root.SelectSingleNode("notifierHosts"); if (notifierHostsNode != null) { NotifierHosts = NotifierHost.GetNotifierHostsFromString(notifierHostsNode.OuterXml, ConfigVariables); } #endregion #region security UserNameCacheMasterKey = root.ReadXmlElementAttr("usernameCacheMasterKey", ""); UserNameCacheFilePath = root.ReadXmlElementAttr("usernameCacheFilePath", ""); #endregion #region Logging LoggingCollectorCategories = new List <string>(); XmlNode loggingNode = root.SelectSingleNode("logging"); if (loggingNode != null) { LoggingPath = loggingNode.ReadXmlElementAttr("loggingPath", ""); LoggingCollectorEvents = loggingNode.ReadXmlElementAttr("loggingCollectorEvents", false); LoggingNotifierEvents = loggingNode.ReadXmlElementAttr("loggingNotifierEvents", false); LoggingAlertsRaised = loggingNode.ReadXmlElementAttr("loggingAlertsRaised", false); LoggingCorrectiveScriptRun = loggingNode.ReadXmlElementAttr("loggingCorrectiveScriptRun", false); LoggingPollingOverridesTriggered = loggingNode.ReadXmlElementAttr("loggingPollingOverridesTriggered", false); LoggingServiceWindowEvents = loggingNode.ReadXmlElementAttr("loggingServiceWindowEvents", false); LoggingKeepLogFilesXDays = loggingNode.ReadXmlElementAttr("loggingKeepLogFilesXDays", 180); XmlNode loggingCollectorCategoriesNode = loggingNode.SelectSingleNode("collectorCategories"); if (loggingCollectorCategoriesNode != null) { foreach (XmlNode categoryNode in loggingCollectorCategoriesNode.SelectNodes("category")) { LoggingCollectorCategories.Add(categoryNode.InnerText.UnEscapeXml()); } } } else { LoggingEnabled = false; } #endregion sw.Stop(); System.Diagnostics.Trace.WriteLine(string.Format("MonitorPack Parsing XML time:{0}ms", sw.ElapsedMilliseconds)); InitializeGlobalPerformanceCounters(); }