//#region Dynamic Config Variables //public List<ConfigVariable> ConfigVariables { get; set; } //#endregion #endregion #region Refreshing state and getting alerts /// <summary> /// Queries the agent to get the latest state. /// </summary> /// <returns>True or False but not both I hope</returns> public MonitorState GetCurrentState(bool disablePollingOverrides = false) { RefreshCount++; CurrentPollAborted = false; if (LastMonitorState == null) { LastMonitorState = new MonitorState() { State = CollectorState.NotAvailable } } ; if (CurrentState == null) { CurrentState = new MonitorState() { State = CollectorState.NotAvailable }; LastStateUpdate = DateTime.Now; } if (LastMonitorState.State != CollectorState.ConfigurationError) { if (!IsEnabledNow()) { LastMonitorState = CurrentState.Clone(); CurrentState.State = CollectorState.Disabled; StagnantStateFirstRepeat = false; StagnantStateSecondRepeat = false; StagnantStateThirdRepeat = false; } //if (!Enabled) //{ // CurrentState.State = CollectorState.Disabled; // StagnantStateFirstRepeat = false; // StagnantStateSecondRepeat = false; // StagnantStateThirdRepeat = false; //} //else if (!ServiceWindows.IsInTimeWindow()) //{ // LastMonitorState = CurrentState.Clone(); // CurrentState.State = CollectorState.Disabled; // StagnantStateFirstRepeat = false; // StagnantStateSecondRepeat = false; // StagnantStateThirdRepeat = false; //} else if (IsFolder) { LastMonitorState = CurrentState.Clone(); CurrentState.State = CollectorState.Folder; StagnantStateFirstRepeat = false; StagnantStateSecondRepeat = false; StagnantStateThirdRepeat = false; } else if (CurrentState.State != CollectorState.NotAvailable && !disablePollingOverrides && EnabledPollingOverride && !EnablePollFrequencySliding && (LastStateUpdate.AddSeconds(OnlyAllowUpdateOncePerXSec) > DateTime.Now)) { //Not time yet for update CurrentPollAborted = true; } else if (CurrentState.State != CollectorState.NotAvailable && !disablePollingOverrides && EnabledPollingOverride && EnablePollFrequencySliding && ( (StagnantStateThirdRepeat && (LastStateUpdate.AddSeconds(PollSlideFrequencyAfterThirdRepeatSec) > DateTime.Now)) || (!StagnantStateThirdRepeat && StagnantStateSecondRepeat && (LastStateUpdate.AddSeconds(PollSlideFrequencyAfterSecondRepeatSec) > DateTime.Now)) || (!StagnantStateThirdRepeat && !StagnantStateSecondRepeat && StagnantStateFirstRepeat && (LastStateUpdate.AddSeconds(PollSlideFrequencyAfterFirstRepeatSec) > DateTime.Now)) || (!StagnantStateFirstRepeat && !StagnantStateThirdRepeat && !StagnantStateSecondRepeat && (LastStateUpdate.AddSeconds(OnlyAllowUpdateOncePerXSec) > DateTime.Now)) ) ) { //Not time yet for update CurrentPollAborted = true; } else { //*********** Call actual collector GetState ********** LastStateCheckAttemptBegin = DateTime.Now; LastMonitorState = CurrentState.Clone(); System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); sw.Start(); if (EnableRemoteExecute || (OverrideRemoteAgentHost && !BlockParentOverrideRemoteAgentHostSettings)) { string currentHostAddress = EnableRemoteExecute ? this.RemoteAgentHostAddress : OverrideRemoteAgentHostAddress; int currentHostPort = EnableRemoteExecute ? this.RemoteAgentHostPort : OverrideRemoteAgentHostPort; try { CurrentState = CollectorEntryRelay.GetRemoteAgentState(this, currentHostAddress, currentHostPort); } catch (Exception ex) { CurrentState.Timestamp = DateTime.Now; if (RunLocalOnRemoteHostConnectionFailure && ex.Message.Contains("There was no endpoint listening")) { //attempting to run locally try { CurrentState = Collector.GetState(); } catch (Exception exLocal) { CurrentState.State = CollectorState.Error; CurrentState.RawDetails = exLocal.ToString(); } CurrentState.RawDetails = "Remote excution failed. Attempting to run locally\r\n" + CurrentState.RawDetails; } else { CurrentState.State = CollectorState.Error; CurrentState.RawDetails = ex.ToString(); } CurrentState.ExecutedOnHostComputer = System.Net.Dns.GetHostName(); } } //if (EnableRemoteExecute) //{ // try // { // CurrentState = CollectorEntryRelay.GetRemoteAgentState(this); // } // catch (Exception ex) // { // CurrentState.Timestamp = DateTime.Now; // if (ex.Message.Contains("There was no endpoint listening")) // { // //attempting to run locally // try // { // CurrentState = Collector.GetState(); // } // catch (Exception exLocal) // { // CurrentState.State = CollectorState.Error; // CurrentState.RawDetails = exLocal.ToString(); // } // CurrentState.RawDetails = "Remote excution failed. Attempting to run locally\r\n" + CurrentState.RawDetails; // } // else // { // CurrentState.State = CollectorState.Error; // CurrentState.RawDetails = ex.ToString(); // } // CurrentState.ExecutedOnHostComputer = System.Net.Dns.GetHostName(); // } //} //else if (OverrideRemoteAgentHost && !BlockParentOverrideRemoteAgentHostSettings) //{ // try // { // CurrentState = CollectorEntryRelay.GetRemoteAgentState(this, OverrideRemoteAgentHostAddress, OverrideRemoteAgentHostPort); // } // catch (Exception ex) // { // CurrentState.Timestamp = DateTime.Now; // if (ex.Message.Contains("There was no endpoint listening")) // { // //attempting to run locally // try // { // CurrentState = Collector.GetState(); // } // catch (Exception exLocal) // { // CurrentState.State = CollectorState.Error; // CurrentState.RawDetails = exLocal.ToString(); // } // CurrentState.RawDetails = "Remote excution failed. Attempting to run locally\r\n" + CurrentState.RawDetails; // } // else // { // CurrentState.State = CollectorState.Error; // CurrentState.RawDetails = ex.ToString(); // } // CurrentState.ExecutedOnHostComputer = System.Net.Dns.GetHostName(); // } //} else //Use LOCAL execution { CurrentState = Collector.GetState(); CurrentState.ExecutedOnHostComputer = System.Net.Dns.GetHostName(); } sw.Stop(); if (LastMonitorState.State != CurrentState.State) { StagnantStateFirstRepeat = false; StagnantStateSecondRepeat = false; StagnantStateThirdRepeat = false; } else if (!StagnantStateFirstRepeat) { StagnantStateFirstRepeat = true; StagnantStateSecondRepeat = false; StagnantStateThirdRepeat = false; } else if (!StagnantStateSecondRepeat) { StagnantStateSecondRepeat = true; StagnantStateThirdRepeat = false; } else if (!StagnantStateThirdRepeat) { StagnantStateThirdRepeat = true; } //Updating stats CurrentState.CallDurationMS = (int)sw.ElapsedMilliseconds; LastStateUpdate = DateTime.Now; if (FirstStateUpdate < (new DateTime(2000, 1, 1))) { FirstStateUpdate = DateTime.Now; } PollCount++; if (CurrentState.State == CollectorState.Good) { LastGoodState = CurrentState.Clone(); LastGoodStateTime = DateTime.Now; GoodStateCount++; } else if (CurrentState.State == CollectorState.Warning) { LastWarningState = CurrentState.Clone(); LastWarningStateTime = DateTime.Now; WarningStateCount++; } else if (CurrentState.State == CollectorState.Error) { LastErrorState = CurrentState.Clone(); LastErrorStateTime = DateTime.Now; ErrorStateCount++; } AddStateToHistory(CurrentState.Clone()); //add details for historic details - still missing alert details though....hmmm } } else { CurrentState.State = CollectorState.ConfigurationError; } return(CurrentState); }
private void RefreshItem(object o) { ListViewItem lvi = (ListViewItem)o; try { try { bool hostExists = false; RemoteAgentInfo ri = (RemoteAgentInfo)lvi.Tag; CollectorEntry ce = new CollectorEntry(); ce.EnableRemoteExecute = true; ce.RemoteAgentHostAddress = ri.Computer; ce.RemoteAgentHostPort = ri.PortNumber; ce.CollectorRegistrationName = "PingCollector"; ce.CollectorRegistrationDisplayName = "Ping Collector"; ce.InitialConfiguration = "<config><hostAddress><entry pingMethod=\"Ping\" address=\"localhost\" description=\"\" maxTimeMS=\"1000\" timeOutMS=\"5000\" httpProxyServer=\"\" socketPort=\"23\" receiveTimeoutMS=\"30000\" sendTimeoutMS=\"30000\" useTelnetLogin=\"False\" userName=\"\" password=\"\" /></hostAddress></config>"; hostExists = System.Net.Dns.GetHostAddresses(ri.Computer).Count() != 0; if (!hostExists) { UpdateListViewItem(lvi, 3, "N/A"); } else { MonitorState testState = CollectorEntryRelay.GetRemoteAgentState(ce); if (testState.State == CollectorState.Good) { try { string versionInfo = CollectorEntryRelay.GetRemoteAgentHostVersion(ri.Computer, ri.PortNumber); UpdateListViewItem(lvi, 0, versionInfo); } catch (Exception ex) { if (ex.Message.Contains("ContractFilter")) { UpdateListViewItem(lvi, 2, "Remote host does not support version info query! Check that QuickMon 3.13 or later is installed."); } else { UpdateListViewItem(lvi, 2, ex.Message); } } } else { UpdateListViewItem(lvi, 2, "N/A"); } } } catch (Exception delegateEx) { if (delegateEx.Message.Contains("The formatter threw an exception while trying to deserialize the message")) { UpdateListViewItem(lvi, 3, "Old version of Remote agent host does not support query or format does not match! Please update remote agent host version."); } else { UpdateListViewItem(lvi, 3, delegateEx.Message); } } } catch (Exception riEx) { UpdateListViewItem(lvi, 1, riEx.ToString()); } }