Beispiel #1
0
 public bool IsEnabledNow()
 {
     if (Enabled)
     {
         if (ServiceWindows.IsInTimeWindow())
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     else
     {
         return(false);
     }
 }
Beispiel #2
0
 public bool IsEnabledNow()
 {
     if (Enabled)
     {
         InServiceWindow = !ServiceWindows.IsInTimeWindow();
         if (!InServiceWindow)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     else
     {
         return(false);
     }
 }
Beispiel #3
0
        public MonitorStates GetCurrentState()
        {
            if (LastMonitorState != MonitorStates.ConfigurationError)
            {
                if (IsFolder)
                {
                    if (Enabled && ServiceWindows.IsInTimeWindow())
                    {
                        CurrentState = MonitorStates.Folder;
                    }
                    else
                    {
                        CurrentState = MonitorStates.Disabled;
                    }
                }
                else
                {
                    if (Enabled && ServiceWindows.IsInTimeWindow())
                    {
                        //*********** Call actual collector GetState **********
                        CurrentState       = Collector.GetState();
                        LastMonitorDetails = Collector.LastDetailMsg;
                        if (CurrentState == MonitorStates.Good)
                        {
                            LastGoodState = DateTime.Now;
                        }
                    }
                    else
                    {
                        CurrentState = MonitorStates.Disabled;
                    }
                }
            }
            else
            {
                CurrentState = MonitorStates.ConfigurationError;
            }

            return(CurrentState);
        }
        public MonitorState RefreshCurrentState(bool forceRefreshNow = false)
        {
            MonitorState resultMonitorState = new MonitorState()
            {
                State = CollectorState.NotAvailable, RepeatCount = 0
            };

            if (AlertHeaderText != null && AlertHeaderText.Trim().Length > 0)
            {
                resultMonitorState.AlertHeader = AlertHeaderText;
            }
            if (AlertFooterText != null && AlertFooterText.Trim().Length > 0)
            {
                resultMonitorState.AlertFooter = AlertFooterText;
            }

            RefreshCount++;
            //CurrentPollAborted = false;
            PollingOverrideActive = false;
            if (CurrentState.State != CollectorState.ConfigurationError)
            {
                if (InServiceWindow)                     //currently in Service window
                {
                    if (ServiceWindows.IsInTimeWindow()) //Service window expired
                    {
                        InServiceWindow = false;
                        RaiseEntereringServiceWindow();
                    }
                }
                else if (!ServiceWindows.IsInTimeWindow())
                {
                    InServiceWindow = true;
                    RaiseExitingServiceWindow();
                }

                if (!Enabled)
                {
                    resultMonitorState.State      = CollectorState.Disabled;
                    StagnantStateFirstRepeat      = false;
                    StagnantStateSecondRepeat     = false;
                    StagnantStateThirdRepeat      = false;
                    resultMonitorState.RawDetails = "Collector host is disabled.";
                }
                else if (InServiceWindow)
                {
                    resultMonitorState.State      = CollectorState.NotInServiceWindow;
                    StagnantStateFirstRepeat      = false;
                    StagnantStateSecondRepeat     = false;
                    StagnantStateThirdRepeat      = false;
                    resultMonitorState.RawDetails = "Disabled due to 'out of service window' event.";
                }
                else if (CollectorAgents == null || CollectorAgents.Count == 0) //like old folder type collector
                {
                    resultMonitorState.State      = CollectorState.None;
                    StagnantStateFirstRepeat      = false;
                    StagnantStateSecondRepeat     = false;
                    StagnantStateThirdRepeat      = false;
                    resultMonitorState.RawDetails = "There are no agents.";
                }
                else if (CollectorAgents != null && CollectorAgents.Count == CollectorAgents.Count(ca => !ca.Enabled))
                {
                    resultMonitorState.State      = CollectorState.Disabled;
                    StagnantStateFirstRepeat      = false;
                    StagnantStateSecondRepeat     = false;
                    StagnantStateThirdRepeat      = false;
                    resultMonitorState.RawDetails = "Disabled because all agents are disabled.";
                }
                else if (CurrentState.State != CollectorState.NotAvailable && !forceRefreshNow && EnabledPollingOverride && !EnablePollFrequencySliding &&
                         (LastStateUpdate.AddSeconds(OnlyAllowUpdateOncePerXSec) > DateTime.Now))
                {
                    //Not time yet for update
                    PollingOverrideActive = true;
                    //CurrentPollAborted = true;
                    //repeat same State
                    resultMonitorState = null;
                    resultMonitorState = CurrentState;
                    //resultMonitorState.Timestamp = DateTime.Now;

                    //if (resultMonitorState.RawDetails == null)
                    //    resultMonitorState.RawDetails = "";
                    //if (resultMonitorState.RawDetails.Length > 0)
                    //    resultMonitorState.RawDetails += "\r\n";
                    //resultMonitorState.RawDetails += "Due to polling override (OnlyAllowUpdateOncePerXSec) the previous state is repeated.";

                    //resultMonitorState.State = CurrentState.State;
                    //resultMonitorState.CurrentValue = CurrentState.ReadValues();
                    //resultMonitorState.RawDetails = "Due to polling override (OnlyAllowUpdateOncePerXSec) the previous state is repeated.";
                    RaiseLoggingPollingOverridesTriggeredEvent(string.Format("Polling override of {0} seconds not reached yet", OnlyAllowUpdateOncePerXSec));
                }
                else if (CurrentState.State != CollectorState.NotAvailable && !forceRefreshNow && EnabledPollingOverride && EnablePollFrequencySliding &&
                         !StagnantStateFirstRepeat && !StagnantStateThirdRepeat && !StagnantStateSecondRepeat &&
                         LastStateUpdate.AddSeconds(OnlyAllowUpdateOncePerXSec - 1) > DateTime.Now)
                {
                    PollingOverrideActive    = true;
                    resultMonitorState       = null;
                    resultMonitorState       = CurrentState;
                    StagnantStateFirstRepeat = true;
                    LastStateUpdate          = DateTime.Now;
                }
                else if (CurrentState.State != CollectorState.NotAvailable && !forceRefreshNow && EnabledPollingOverride && EnablePollFrequencySliding &&
                         StagnantStateFirstRepeat && !StagnantStateThirdRepeat && !StagnantStateSecondRepeat &&
                         LastStateUpdate.AddSeconds(PollSlideFrequencyAfterFirstRepeatSec - 1) > DateTime.Now)
                {
                    PollingOverrideActive     = true;
                    resultMonitorState        = null;
                    resultMonitorState        = CurrentState;
                    StagnantStateFirstRepeat  = true;
                    StagnantStateSecondRepeat = true;
                    LastStateUpdate           = DateTime.Now;
                }
                else if (CurrentState.State != CollectorState.NotAvailable && !forceRefreshNow && EnabledPollingOverride && EnablePollFrequencySliding &&
                         StagnantStateFirstRepeat && StagnantStateThirdRepeat && !StagnantStateSecondRepeat &&
                         LastStateUpdate.AddSeconds(PollSlideFrequencyAfterSecondRepeatSec - 1) > DateTime.Now)
                {
                    PollingOverrideActive     = true;
                    resultMonitorState        = null;
                    resultMonitorState        = CurrentState;
                    StagnantStateFirstRepeat  = true;
                    StagnantStateSecondRepeat = true;
                    StagnantStateThirdRepeat  = true;
                    LastStateUpdate           = DateTime.Now;
                }
                else if (CurrentState.State != CollectorState.NotAvailable && !forceRefreshNow && EnabledPollingOverride && EnablePollFrequencySliding &&
                         StagnantStateFirstRepeat && StagnantStateThirdRepeat && StagnantStateSecondRepeat &&
                         LastStateUpdate.AddSeconds(PollSlideFrequencyAfterThirdRepeatSec - 1) > DateTime.Now)
                {
                    PollingOverrideActive     = true;
                    resultMonitorState        = null;
                    resultMonitorState        = CurrentState;
                    StagnantStateFirstRepeat  = true;
                    StagnantStateSecondRepeat = true;
                    StagnantStateThirdRepeat  = true;
                    if (!stagnantStateMaxReached)
                    {
                        LastStateUpdate         = DateTime.Now;
                        stagnantStateMaxReached = true;
                    }
                }



                //else if (CurrentState.State != CollectorState.NotAvailable && !forceRefreshNow && 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;
                //    //repeat same State
                //    resultMonitorState = null;
                //    resultMonitorState = CurrentState.Clone();
                //    resultMonitorState.Timestamp = DateTime.Now;

                //    //if (resultMonitorState.RawDetails == null)
                //    //    resultMonitorState.RawDetails = "";
                //    //if (resultMonitorState.RawDetails.Length > 0)
                //    //    resultMonitorState.RawDetails += "\r\n";

                //    //resultMonitorState.State = CurrentState.State;
                //    //resultMonitorState.CurrentValue = CurrentState.ReadValues();
                //    //if (StagnantStateThirdRepeat)
                //    //    resultMonitorState.RawDetails += "Due to polling override (StagnantStateThirdRepeat) the previous state is repeated.";
                //    //else if (StagnantStateSecondRepeat)
                //    //    resultMonitorState.RawDetails += "Due to polling override (StagnantStateSecondRepeat) the previous state is repeated.";
                //    //else if (StagnantStateFirstRepeat)
                //    //    resultMonitorState.RawDetails += "Due to polling override (StagnantStateFirstRepeat) the previous state is repeated.";
                //    //else
                //    //    resultMonitorState.RawDetails += "Due to polling override (EnablePollFrequencySliding) the previous state is repeated.";
                //}
                else
                {
                    stagnantStateMaxReached = false;
                    //*********** Call actual collector GetState **********
                    LastStateCheckAttemptBegin = DateTime.Now;
                    System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
                    //Applies config vars to Initial configs of agents (on the run)
                    ApplyConfigVarsNow();
                    sw.Start();

                    //first check if remote host exection is required
                    if (EnableRemoteExecute || (OverrideRemoteAgentHost && !BlockParentOverrideRemoteAgentHostSettings))
                    {
                        resultMonitorState = GetRemoteState();
                    }
                    else if (!RunAsEnabled || RunAs == null || RunAs.Length == 0 || RunTimeUserNameCacheFile == null || RunTimeUserNameCacheFile.Length == 0 || RunTimeMasterKey == null || RunTimeMasterKey.Length == 0)
                    {
                        resultMonitorState = GetStateFromLocalCurrentUser();
                    }
                    else
                    {
                        resultMonitorState = GetStateFromLocal();
                    }
                    sw.Stop();
                    resultMonitorState.CallDurationMS = (int)sw.ElapsedMilliseconds;
                    RaiseAllAgentsExecutionTime(sw.ElapsedMilliseconds);

                    #region Calculate summarized state
                    if (resultMonitorState.ChildStates != null && resultMonitorState.ChildStates.Count > 0)
                    {
                        int allCount      = resultMonitorState.ChildStates.Count;
                        int disabledCount = (from cs in resultMonitorState.ChildStates
                                             where cs.State == CollectorState.Disabled
                                             select cs).Count();
                        int goodCount = (from cs in resultMonitorState.ChildStates
                                         where cs.State == CollectorState.Good
                                         select cs).Count();
                        int warningCount = (from cs in resultMonitorState.ChildStates
                                            where cs.State == CollectorState.Warning
                                            select cs).Count();
                        int errorCount = (from cs in resultMonitorState.ChildStates
                                          where cs.State == CollectorState.Error
                                          select cs).Count();

                        if (allCount == disabledCount)
                        {
                            resultMonitorState.State = CollectorState.Disabled;
                        }
                        else if (AgentCheckSequence == QuickMon.AgentCheckSequence.All)
                        {
                            if (allCount - disabledCount == goodCount)
                            {
                                resultMonitorState.State = CollectorState.Good;
                            }
                            else if (allCount - disabledCount == errorCount)
                            {
                                resultMonitorState.State = CollectorState.Error;
                            }
                            else
                            {
                                resultMonitorState.State = CollectorState.Warning;
                            }
                        }
                        else if (AgentCheckSequence == QuickMon.AgentCheckSequence.FirstSuccess)
                        {
                            if (goodCount > 0)
                            {
                                resultMonitorState.State = CollectorState.Good;
                            }
                            else if (warningCount > 0)
                            {
                                resultMonitorState.State = CollectorState.Warning;
                            }
                            else
                            {
                                resultMonitorState.State = CollectorState.Error;
                            }
                        }
                        else
                        {
                            if (errorCount > 0)
                            {
                                resultMonitorState.State = CollectorState.Error;
                            }
                            else if (warningCount > 0)
                            {
                                resultMonitorState.State = CollectorState.Warning;
                            }
                            else
                            {
                                resultMonitorState.State = CollectorState.Good;
                            }
                        }
                    }
                    #endregion
                }
            }
            else
            {
                resultMonitorState.State = CollectorState.ConfigurationError;
            }

            //Set current CH state plus raise any alerts if required
            // if (!PollingOverrideActive)
            SetCurrentState(resultMonitorState);
            return(resultMonitorState);
        }