Ejemplo n.º 1
0
 /// <summary>
 /// When adding a new collector host manually or by editing it needs to be initialized for events, config vars, scripts etc.
 /// </summary>
 /// <param name="collectorHost"></param>
 public void AddCollectorHost(CollectorHost collectorHost)
 {
     collectorHost.ParentMonitorPack = this;
     SetCollectorHostEvents(collectorHost);
     //InitializeCollectorActionScripts(collectorHost);
     CollectorHosts.Add(collectorHost);
 }
Ejemplo n.º 2
0
        internal void SwapCollectorEntries(CollectorHost c1, CollectorHost c2)
        {
            int index1 = CollectorHosts.FindIndex(c => c.UniqueId == c1.UniqueId);
            int index2 = CollectorHosts.FindIndex(c => c.UniqueId == c2.UniqueId);

            if (index1 < index2)
            {
                int tmp = index1;
                index1 = index2;
                index2 = tmp;
            }

            if (index1 > -1 && index2 > -1 && index1 != index2)
            {
                CollectorHosts.RemoveAt(index1);
                CollectorHosts.RemoveAt(index2);
                CollectorHosts.Insert(index2, c1);
                CollectorHosts.Insert(index1, c2);
            }
        }
Ejemplo n.º 3
0
        public CollectorState RefreshStates(bool disablePollingOverrides = false)
        {
            AbortPolling  = false;
            IsBusyPolling = true;
            CollectorState globalState = CollectorState.Good;

            ResetAllOverrides();
            Stopwatch sw = new Stopwatch();

            sw.Start();
            //First get collectors with no dependancies
            List <CollectorHost> rootCollectorHosts = (from c in CollectorHosts
                                                       where c.ParentCollectorId.Length == 0
                                                       select c).ToList();

            if (ConcurrencyLevel > 1)
            {
                ParallelOptions po = new ParallelOptions()
                {
                    MaxDegreeOfParallelism = ConcurrencyLevel
                };
                ParallelLoopResult parResult = Parallel.ForEach(rootCollectorHosts, po, collectorHost =>
                                                                CollectorHostRefreshCurrentState(collectorHost, disablePollingOverrides));
                if (!parResult.IsCompleted)
                {
                    SendNotifierAlert(AlertLevel.Error, DetailLevel.All, "Error querying collectors in parralel");
                }
            }
            else //use old single threaded way
            {
                //Refresh states
                foreach (CollectorHost collectorHost in rootCollectorHosts)
                {
                    CollectorHostRefreshCurrentState(collectorHost, disablePollingOverrides);
                }
            }
            sw.Stop();
            PCSetCollectorsQueryTime(sw.ElapsedMilliseconds);
            LastRefreshDurationMS = sw.ElapsedMilliseconds;
#if DEBUG
            Trace.WriteLine(string.Format("RefreshStates - Global time: {0}ms", sw.ElapsedMilliseconds));
#endif

            #region Get Global state
            //All disabled
            if (CollectorHosts.Count == CollectorHosts.Count(c => c.CurrentState.State == CollectorState.Disabled || c.CurrentState.State == CollectorState.NotInServiceWindow))
            {
                globalState = CollectorState.Disabled;
            }
            //All NotAvailable
            else if (CollectorHosts.Count == CollectorHosts.Count(c => c.CurrentState.State == CollectorState.NotAvailable))
            {
                globalState = CollectorState.NotAvailable;
            }
            //All good
            else if (CollectorHosts.Count == CollectorHosts.Count(c => c.CurrentState.State == CollectorState.Good ||
                                                                  c.CurrentState.State == CollectorState.None ||
                                                                  c.CurrentState.State == CollectorState.Disabled ||
                                                                  c.CurrentState.State == CollectorState.NotInServiceWindow))
            {
                globalState = CollectorState.Good;
            }
            //Error state
            else if (CollectorHosts.Count == CollectorHosts.Count(c => c.CurrentState.State == CollectorState.Error ||
                                                                  c.CurrentState.State == CollectorState.ConfigurationError ||
                                                                  c.CurrentState.State == CollectorState.Disabled ||
                                                                  c.CurrentState.State == CollectorState.NotInServiceWindow))
            {
                globalState = CollectorState.Error;
            }
            else
            {
                globalState = CollectorState.Warning;
            }

            AlertLevel globalAlertLevel = AlertLevel.Info;
            if (globalState == CollectorState.Error)
            {
                globalAlertLevel = AlertLevel.Error;
            }
            else if (globalState == CollectorState.Warning)
            {
                globalAlertLevel = AlertLevel.Warning;
            }
            #endregion

            sw.Restart();
            SendNotifierAlert(globalAlertLevel, DetailLevel.Summary, "GlobalState");
            sw.Stop();
            PCSetNotifiersSendTime(sw.ElapsedMilliseconds);
            IsBusyPolling = false;
            CurrentState  = globalState;
            return(globalState);
        }
Ejemplo n.º 4
0
 public void AddCollectorHost(CollectorHost collectorHost)
 {
     SetCollectorHostEvents(collectorHost);
     CollectorHosts.Add(collectorHost);
 }