public void CollectorAgentTestPing() { string mconfig = "<collectorHost uniqueId=\"123\" dependOnParentId=\"\" name=\"Ping\" enabled=\"True\" expandOnStart=\"Auto\" " + " childCheckBehaviour=\"OnlyRunOnSuccess\" runAsEnabled=\"False\" runAs=\"\">" + " <collectorAgents agentCheckSequence=\"All\">" + " <collectorAgent name=\"Ping localhost\" type=\"QuickMon.Collectors.PingCollector\" enabled=\"True\">" + " <config>" + " <entries>" + " <entry pingMethod=\"Ping\" address=\"localhost\" description=\"\" maxTimeMS=\"1000\" timeOutMS=\"5000\" httpHeaderUser=\"\" httpHeaderPwd=\"\" httpProxyServer=\"\" httpProxyUser=\"\" httpProxyPwd=\"\" socketPort=\"23\" receiveTimeoutMS=\"30000\" sendTimeoutMS=\"30000\" useTelnetLogin=\"False\" userName=\"\" password=\"\" ignoreInvalidHTTPSCerts=\"False\" />" + " <entry pingMethod=\"HTTP\" address=\"http://localhost\" description=\"\" maxTimeMS=\"1000\" timeOutMS=\"5000\" httpHeaderUser=\"\" httpHeaderPwd=\"\" httpProxyServer=\"\" httpProxyUser=\"\" httpProxyPwd=\"\" socketPort=\"23\" receiveTimeoutMS=\"30000\" sendTimeoutMS=\"30000\" useTelnetLogin=\"False\" userName=\"\" password=\"\" ignoreInvalidHTTPSCerts=\"False\" />" + " <entry pingMethod=\"SOCKET\" address=\"127.0.0.1\" description=\"\" maxTimeMS=\"1000\" timeOutMS=\"5000\" httpHeaderUser=\"\" httpHeaderPwd=\"\" httpProxyServer=\"\" httpProxyUser=\"\" httpProxyPwd=\"\" socketPort=\"80\" receiveTimeoutMS=\"30000\" sendTimeoutMS=\"30000\" useTelnetLogin=\"False\" userName=\"\" password=\"\" ignoreInvalidHTTPSCerts=\"False\" />" + " </entries>" + " </config>" + " </collectorAgent>" + " </collectorAgents>" + " </collectorHost>"; CollectorHost ch = CollectorHost.FromXml(mconfig); Assert.IsNotNull(ch, "Monitor pack is null"); Assert.AreEqual("Ping", ch.Name, "Collector host name not set"); Assert.AreEqual("123", ch.UniqueId, "Collector host UniqueId not set"); Assert.AreEqual(true, ch.Enabled, "Collector host Enabled property not set"); Assert.AreEqual(false, ch.RunAsEnabled, "Run As enabled!"); Assert.AreEqual("", ch.RunAs, "Run As set up incorrectly!"); Assert.AreEqual("", ch.ParentCollectorId, "Collector host ParentCollectorId property not set"); Assert.AreEqual(AgentCheckSequence.All, ch.AgentCheckSequence, "Collector host AgentCheckSequence property not set"); Assert.AreEqual(ChildCheckBehaviour.OnlyRunOnSuccess, ch.ChildCheckBehaviour, "Collector host ChildCheckBehaviour property not set"); Assert.AreEqual(1, ch.CollectorAgents.Count, "1 Collector agent expected"); Assert.AreEqual(0, ch.ConfigVariables.Count, "No config variables expected"); Assert.AreEqual(0, ch.RefreshCount, "No refreshes expected yet"); MonitorState testState = ch.RefreshCurrentState(); Assert.AreEqual(1, ch.RefreshCount, "1 refresh expected"); Assert.AreEqual(CollectorState.Good, testState.State, "Cannot ping self"); }
private void CollectorHostRefreshCurrentState(CollectorHost collectorHost, bool disablePollingOverrides = false) { if (!AbortPolling) { RaiseCollectorHostCalled(collectorHost); try { MonitorState chms = null; collectorHost.RunTimeMasterKey = ""; collectorHost.RunTimeUserNameCacheFile = ""; collectorHost.BlockedCollectorAgentTypes = new List <string>(); collectorHost.BlockedCollectorAgentTypes.AddRange(BlockedCollectorAgentTypes.ToArray()); if (collectorHost.RunAsEnabled && collectorHost.RunAs != null && collectorHost.RunAs.Length > 0) { if (UserNameCacheMasterKey.Length > 0 && System.IO.File.Exists(UserNameCacheFilePath) && QuickMon.Security.CredentialManager.IsAccountPersisted(UserNameCacheFilePath, UserNameCacheMasterKey, collectorHost.RunAs) && QuickMon.Security.CredentialManager.IsAccountDecryptable(UserNameCacheFilePath, UserNameCacheMasterKey, collectorHost.RunAs)) { collectorHost.RunTimeMasterKey = UserNameCacheMasterKey; collectorHost.RunTimeUserNameCacheFile = UserNameCacheFilePath; } else if (ApplicationUserNameCacheMasterKey != null && ApplicationUserNameCacheFilePath != null && ApplicationUserNameCacheMasterKey.Length > 0 && System.IO.File.Exists(ApplicationUserNameCacheFilePath) && QuickMon.Security.CredentialManager.IsAccountPersisted(ApplicationUserNameCacheFilePath, ApplicationUserNameCacheMasterKey, collectorHost.RunAs) && QuickMon.Security.CredentialManager.IsAccountDecryptable(ApplicationUserNameCacheFilePath, ApplicationUserNameCacheMasterKey, collectorHost.RunAs)) { collectorHost.RunTimeMasterKey = ApplicationUserNameCacheMasterKey; collectorHost.RunTimeUserNameCacheFile = ApplicationUserNameCacheFilePath; } } //collectorHost.ApplyConfigVarsNow(ConfigVariables); chms = collectorHost.RefreshCurrentState(disablePollingOverrides); #region Do/Check/Set dependant CollectorHosts if (chms.State == CollectorState.Error && collectorHost.ChildCheckBehaviour != ChildCheckBehaviour.ContinueOnWarningOrError) { SetDependantCollectorHostStates(collectorHost, CollectorState.NotAvailable); } else if (chms.State == CollectorState.Warning && collectorHost.ChildCheckBehaviour == ChildCheckBehaviour.OnlyRunOnSuccess) { SetDependantCollectorHostStates(collectorHost, CollectorState.NotAvailable); } else if (chms.State == CollectorState.Disabled || chms.State == CollectorState.ConfigurationError || !collectorHost.IsEnabledNow()) { SetDependantCollectorHostStates(collectorHost, CollectorState.Disabled); } else { //Remote execute and dependant Collector Hosts if (collectorHost.ForceRemoteExcuteOnChildCollectors) { collectorHost.OverrideForceRemoteExcuteOnChildCollectors = true; SetChildCollectorHostRemoteExecuteDetails(collectorHost, collectorHost.RemoteAgentHostAddress, collectorHost.RemoteAgentHostPort); } //Polling overrides and dependant Collector Hosts if (collectorHost.EnabledPollingOverride) { SetChildCollectorHostPollingOverrides(collectorHost); } #region Loop through dependant CollectorHosts if (ConcurrencyLevel > 1) { ParallelOptions po = new ParallelOptions() { MaxDegreeOfParallelism = ConcurrencyLevel }; ParallelLoopResult parResult = Parallel.ForEach((from c in CollectorHosts where c.ParentCollectorId == collectorHost.UniqueId select c), po, dependentCollectorHost => CollectorHostRefreshCurrentState(dependentCollectorHost, disablePollingOverrides)); if (!parResult.IsCompleted) { SendNotifierAlert(AlertLevel.Error, DetailLevel.All, "Error querying collectors in parralel"); } } else //use old single threaded way { //Refresh states foreach (CollectorHost dependentCollectorHost in (from c in CollectorHosts where c.ParentCollectorId == collectorHost.UniqueId select c)) { CollectorHostRefreshCurrentState(dependentCollectorHost, disablePollingOverrides); } } #endregion } #endregion LoggingCollectorEvent(string.Format("Collector '{0}' return state '{1}'", collectorHost.Name, collectorHost.CurrentState), collectorHost); } catch (Exception ex) { WriteLogging(string.Format("CollectorHostRefreshCurrentState error: {0}", ex.Message)); if (!ex.Message.Contains("Collection was modified; enumeration operation may not execute")) { RaiseMonitorPackError("Internal error. Collector config was modified while in use!"); } else { RaiseCollectorError(collectorHost, ex.Message); } } } }