Beispiel #1
0
 private bool IsCollectorInLoggingCategory(string category, CollectorHost collectorHost)
 {
     if (category == "*") //don't bother further testing
     {
         return(true);
     }
     else if (category.StartsWith("*"))
     {
         string endsWith = category.Substring(1);
         if ((from s in collectorHost.Categories
              where s.EndsWith(endsWith, StringComparison.InvariantCultureIgnoreCase)
              select s).Count() > 0)
         {
             return(true);
         }
     }
     else if (category.EndsWith("*"))
     {
         string startsWith = category.Substring(0, category.Length - 1);
         if ((from s in collectorHost.Categories
              where s.StartsWith(startsWith, StringComparison.InvariantCultureIgnoreCase)
              select s).Count() > 0)
         {
             return(true);
         }
     }
     else if (collectorHost.Categories.Contains(category))
     {
         return(true);
     }
     return(false);
 }
Beispiel #2
0
        private void LoggingCollectorEvent(string message, CollectorHost collectorHost)
        {
            bool allCollectors   = LoggingCollectorCategories == null || LoggingCollectorCategories.Count == 0;
            bool matchCategories = false;

            if (!allCollectors)
            {
                foreach (string category in LoggingCollectorCategories)
                {
                    if (IsCollectorInLoggingCategory(category, collectorHost))
                    {
                        matchCategories = true;
                        break;
                    }
                }

                //if (collectorHost.Categories != null && collectorHost.Categories.Count > 0)
                //{

                //    foreach(string cat in collectorHost.Categories)
                //        if (LoggingCollectorCategories.Contains(cat))
                //        {
                //            matchCategories = true;
                //            break;
                //        }
                //}
            }
            if (LoggingCollectorEvents && (allCollectors || matchCategories))
            {
                WriteLogging(message);
            }
        }
Beispiel #3
0
 private void LoggingPollingOverridesTriggeredEvent(string message, CollectorHost collectorHost)
 {
     if (LoggingPollingOverridesTriggered)
     {
         WriteLogging(string.Format("Collector '{0}' encoutered polling override event: {1}", collectorHost.Name, message));
     }
 }
Beispiel #4
0
        private void ResetAllOverrides(CollectorHost parentCollector = null)
        {
            List <CollectorHost> collectors = null;

            if (parentCollector == null)
            {
                collectors = (from c in CollectorHosts
                              where c.ParentCollectorId.Length == 0
                              select c).ToList();
            }
            else
            {
                collectors = (from c in CollectorHosts
                              where c.ParentCollectorId == parentCollector.UniqueId
                              select c).ToList();
            }
            foreach (CollectorHost childCollector in collectors)
            {
                childCollector.MaxStateHistorySize = CollectorStateHistorySize;
                //Remote agent host
                childCollector.OverrideForceRemoteExcuteOnChildCollectors = false;
                childCollector.OverrideRemoteAgentHost        = false;
                childCollector.OverrideRemoteAgentHostAddress = "";
                childCollector.OverrideRemoteAgentHostPort    = GlobalConstants.DefaultRemoteHostPort;
                ResetAllOverrides(childCollector);
            }
        }
Beispiel #5
0
 private void collectorHost_AllAgentsExecutionTime(CollectorHost collectorHost, long msTime)
 {
     if (CollectorHostAllAgentsExecutionTime != null)
     {
         CollectorHostAllAgentsExecutionTime(collectorHost, msTime);
     }
 }
Beispiel #6
0
        private void SetChildCollectorHostPollingOverrides(CollectorHost parentCollectorHost)
        {
            foreach (CollectorHost childCollector in (from c in CollectorHosts
                                                      where c.ParentCollectorId == parentCollectorHost.UniqueId
                                                      select c))
            {
                if (!childCollector.EnabledPollingOverride) //check that child does not have its own
                {
                    childCollector.OnlyAllowUpdateOncePerXSec = parentCollectorHost.OnlyAllowUpdateOncePerXSec;
                    //to make sure child collector does not miss the poll event
                    childCollector.LastStateUpdate = parentCollectorHost.LastStateUpdate;
                }
                else
                {
                    if (childCollector.OnlyAllowUpdateOncePerXSec < parentCollectorHost.OnlyAllowUpdateOncePerXSec)
                    {
                        childCollector.OnlyAllowUpdateOncePerXSec = parentCollectorHost.OnlyAllowUpdateOncePerXSec;
                        //to make sure child collector does not miss the poll event
                        childCollector.LastStateUpdate = parentCollectorHost.LastStateUpdate;
                    }
                }
                //force child settings permanently
                childCollector.EnabledPollingOverride = true;

                //Set grand children
                SetChildCollectorHostPollingOverrides(childCollector);
            }
        }
Beispiel #7
0
 private void RaiseCollectorHostCalled(CollectorHost collectorHost)
 {
     if (CollectorHostCalled != null)
     {
         CollectorHostCalled(collectorHost);
     }
 }
Beispiel #8
0
        private int GetItemIcon(CollectorHost collector)
        {
            int imageIndex = collectorNAstateImage;

            if (collector.CollectorAgents.Count == 0 || collector.CurrentState.State == CollectorState.None)
            {
                imageIndex = collectorFolderImage;
            }
            else if (!collector.Enabled || collector.CurrentState.State == CollectorState.Disabled)
            {
                imageIndex = collectorDisabled;
            }
            else if (collector.CurrentState.State == CollectorState.Error || collector.CurrentState.State == CollectorState.ConfigurationError)
            {
                imageIndex = collectorErrorStateImage1;
            }
            else if (collector.CurrentState.State == CollectorState.Warning)
            {
                imageIndex = collectorWarningStateImage1;
            }
            else if (collector.CurrentState.State == CollectorState.Good)
            {
                imageIndex = collectorGoodStateImage1;
            }
            else if (collector.CurrentState.State == CollectorState.NotInServiceWindow)
            {
                imageIndex = collectorOutOfServiceWindowstateImage;
            }
            return(imageIndex);
        }
Beispiel #9
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);
 }
Beispiel #10
0
        private void CollectorHostEditor_Load(object sender, EventArgs e)
        {
            panelGeneralSettingsHeight = panelGeneralSettings.Height;
            panelAgentsHeight          = panelAgents.Height;
            panelPollingHeight         = panelPolling.Height;
            panelRemoteAgentHeight     = panelRemoteAgent.Height;
            panelRunAsHeight           = panelRunAs.Height;
            panelServiceWindowsHeight  = panelServiceWindows.Height;
            panelAlertingHeight        = panelAlerting.Height;
            panelVariablesHeight       = panelVariables.Height;
            panelActionScriptsHeight   = panelActionScripts.Height;

            cmdAgentsToggle_Click(null, null);
            cmdPollingToggle_Click(null, null);
            cmdRemoteAgentToggle_Click(null, null);
            cmdRunAsToggle_Click(null, null);
            cmdServiceWindowsToggle_Click(null, null);
            cmdAlertingToggle_Click(null, null);
            cmdVariablesToggle_Click(null, null);
            cmdActionScriptsToggle_Click(null, null);

            if (SelectedCollectorHost == null)
            {
                SelectedCollectorHost = new CollectorHost();
            }
        }
Beispiel #11
0
 private void collectorHost_NoStateChanged(CollectorHost collectorHost)
 {
     if (CollectorHost_AlertRaised_NoStateChanged != null)
     {
         CollectorHost_AlertRaised_NoStateChanged(collectorHost);
     }
     SendNotifierAlert(AlertLevel.Debug, DetailLevel.Detail, collectorHost);
 }
Beispiel #12
0
 private void collectorHost_AlertWarningState(CollectorHost collectorHost)
 {
     if (CollectorHost_AlertRaised_Warning != null)
     {
         CollectorHost_AlertRaised_Warning(collectorHost);
     }
     SendNotifierAlert(AlertLevel.Warning, DetailLevel.Detail, collectorHost);
 }
Beispiel #13
0
 private void collectorHost_AlertGoodState(CollectorHost collectorHost)
 {
     if (CollectorHost_AlertRaised_Good != null)
     {
         CollectorHost_AlertRaised_Good(collectorHost);
     }
     SendNotifierAlert(AlertLevel.Info, DetailLevel.Detail, collectorHost);
 }
Beispiel #14
0
        private void collectorHost_AlertErrorState(CollectorHost collectorHost)
        {
            if (CollectorHost_AlertRaised_Error != null)
            {
                CollectorHost_AlertRaised_Error(collectorHost);
            }

            SendNotifierAlert(AlertLevel.Error, DetailLevel.Detail, collectorHost);
        }
Beispiel #15
0
        private string GetCollectorPath(CollectorHost ch)
        {
            string collectorPath = "";

            foreach (CollectorHost pch in HostingMonitorPack.GetParentCollectorHostTree(ch))
            {
                collectorPath = pch.NameFormatted + "/" + collectorPath;
            }
            return(collectorPath + ch.NameFormatted);
        }
Beispiel #16
0
 private void RaiseCollectorError(CollectorHost collector, string errorMessage)
 {
     try
     {
         OnCollectorError?.Invoke(collector, errorMessage);
     }
     catch (Exception ex)
     {
         System.Diagnostics.Trace.WriteLine(string.Format("Error in RaiseCollectorError: {0}", ex.Message));
     }
 }
Beispiel #17
0
 private void removeCollectorToolStripMenuItem_Click(object sender, EventArgs e)
 {
     //List<CollectorHost> collectorsToBeRemoved = new List<CollectorHost>();
     foreach (ListViewItem lvi in lvwCollectorStates.SelectedItems)
     {
         CollectorHost collector = (CollectorHost)lvi.Tag;
         SelectedCollectors.Remove(collector);
         //collectorsToBeRemoved.Add(collector);
         LoadControls(true);
     }
 }
Beispiel #18
0
        public static MonitorState GetCollectorHostState(CollectorHost entry, string hostAddressOverride, int portNumberOverride)
        {
            BasicHttpBinding myBinding  = new BasicHttpBinding();
            EndpointAddress  myEndpoint = new EndpointAddress(string.Format("http://{0}:{1}/QuickMonRemoteHost", hostAddressOverride, portNumberOverride));
            ChannelFactory <IRemoteCollectorHostService> myChannelFactory = new ChannelFactory <IRemoteCollectorHostService>(myBinding, myEndpoint);
            IRemoteCollectorHostService relay = myChannelFactory.CreateChannel();

            RemoteCollectorHost colReq = new RemoteCollectorHost();

            colReq.FromCollectorHost(entry);
            return(relay.GetState(colReq));
        }
Beispiel #19
0
        public List <CollectorHost> GetParentCollectorHostTree(CollectorHost child)
        {
            List <CollectorHost> list          = new List <CollectorHost>();
            CollectorHost        currentParent = GetParentCollectorHost(child);

            while (currentParent != null)
            {
                list.Add(currentParent);
                currentParent = GetParentCollectorHost(currentParent);
            }
            return(list);
        }
Beispiel #20
0
        public void ExportCollectorMetricsToCSV()
        {
            string outputPath     = CollectorMetricsExportPath;
            string outputFileName = Name.StringToSaveFileName() + DateTime.Now.Date.ToString("yyyyMMdd") + ".csv";

            if (outputPath.Length == 0)
            {
                if (MonitorPackPath != null && MonitorPackPath.Length > 0)
                {
                    outputPath = System.IO.Path.GetDirectoryName(MonitorPackPath);
                }
                else
                {
                    outputPath = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                }
                outputPath = System.IO.Path.Combine(outputPath, outputFileName);
            }
            else if (System.IO.Directory.Exists(outputPath))
            {
                outputPath = System.IO.Path.Combine(outputPath, outputFileName);
            }

            ////Get output directory
            //if (outputPath.Length == 0 || (!System.IO.Directory.Exists(outputPath) && !System.IO.File.Exists(outputPath)))
            //{
            //    if (MonitorPackPath != null && MonitorPackPath.Length > 0)
            //    {
            //        outputPath = System.IO.Path.GetDirectoryName(MonitorPackPath);
            //    }
            //    else
            //    {
            //        outputPath = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            //    }
            //}
            //outputPath = System.IO.Path.Combine(outputPath, outputFileName);
            try
            {
                lock (collectorMetricsSyncLock)
                {
                    if (!System.IO.File.Exists(outputPath))
                    {
                        System.IO.File.WriteAllText(outputPath, CollectorHost.ExportHistoryToCSVHeaders());
                    }

                    System.IO.File.AppendAllText(outputPath, ExportCurrentCollectorMetricsToCSV());
                }
            }
            catch (Exception ex)
            {
                WriteLogging(string.Format("Error performing ExportCollectorMetricsToCSV: {0}", ex.Message));
                RaiseMonitorPackError(string.Format("Error performing ExportCollectorMetricsToCSV: {0}", ex.Message));
            }
        }
Beispiel #21
0
        private GraphSeries SeriesFromCollector(CollectorHost collector, Color seriesColor, int lastXEntries)
        {
            GraphSeries series = null;

            if (txtTextFilter.Text.Trim().Length < 2 || collector.PathWithoutMP.ContainEx(txtTextFilter.Text))
            //if (txtTextFilter.Text.Trim().Length < 2 || collector.PathWithoutMP.ToLower().Contains(txtTextFilter.Text.ToLower()))
            {
                string stateValue = "";
                float  v          = 0;
                if (lastXEntries == 0)
                {
                    lastXEntries = collector.StateHistory.Count;
                }
                series = new GraphSeries(collector.PathWithoutMP, seriesColor);
                foreach (MonitorState agentState in (from hsm in collector.StateHistory
                                                     orderby hsm.Timestamp descending
                                                     select hsm).Take(lastXEntries))
                {
                    v          = 0;
                    stateValue = agentState.ReadFirstValue(false);
                    if (stateValue != null && float.TryParse(stateValue, out v))
                    {
                        series.Values.Add(new TimeValue()
                        {
                            Time = agentState.Timestamp, Value = v
                        });
                    }
                }
                v          = 0;
                stateValue = collector.CurrentState.ReadFirstValue(false);
                if (stateValue != null && float.TryParse(stateValue, out v))
                {
                    series.Values.Add(new TimeValue()
                    {
                        Time = collector.CurrentState.Timestamp, Value = v
                    });
                }
            }
            if (series != null && series.Values != null && series.Values.Count > 0)
            {
                return(series);
            }
            //else if (series.Values.Count ==1)
            //{
            //    series.Name += " (Not enough data)";
            //    return series;
            //}
            else
            {
                return(null);
            }
        }
Beispiel #22
0
        public List <CollectorHost> GetAllChildCollectorHosts(CollectorHost parentCE)
        {
            List <CollectorHost> list         = new List <CollectorHost>();
            List <CollectorHost> listChildren = new List <CollectorHost>();

            listChildren = GetChildCollectorHosts(parentCE);
            foreach (CollectorHost child in listChildren)
            {
                list.Add(child);
                list.AddRange(GetAllChildCollectorHosts(child));
            }
            return(list);
        }
Beispiel #23
0
 private void LogCorrectiveScriptAction(CollectorHost collectorEntry, bool error)
 {
     collectorEntry.CurrentState.RawDetails += "\r\n" + string.Format("Due to an alert raised on the collector '{0}' the following corrective script was executed: '{1}'",
                                                                      collectorEntry.Name, error ? collectorEntry.CorrectiveScriptOnErrorPath : collectorEntry.CorrectiveScriptOnWarningPath);
     SendNotifierAlert(new AlertRaised()
     {
         Level       = error ? AlertLevel.Error : AlertLevel.Warning,
         DetailLevel = DetailLevel.Detail,
         RaisedFor   = collectorEntry
     });
     LoggingCorrectiveScriptRunEvent(string.Format("Due to an alert raised on the collector '{0}' the following corrective script was executed: '{1}'",
                                                   collectorEntry.Name, error ? collectorEntry.CorrectiveScriptOnErrorPath : collectorEntry.CorrectiveScriptOnWarningPath));
 }
Beispiel #24
0
 private void LogRestorationScriptAction(CollectorHost collectorEntry)
 {
     collectorEntry.CurrentState.RawDetails += "\r\n" + string.Format("Due to an earlier alert raised on the collector '{0}' the following restoration script was executed: '{1}'",
                                                                      collectorEntry.Name, collectorEntry.RestorationScriptPath);
     SendNotifierAlert(new AlertRaised()
     {
         Level       = collectorEntry.PreviousState.State == CollectorState.Warning ? AlertLevel.Warning : AlertLevel.Error,
         DetailLevel = DetailLevel.Detail,
         RaisedFor   = collectorEntry
     });
     LoggingCorrectiveScriptRunEvent(string.Format("Due to an earlier alert raised on the collector '{0}' the following restoration script was executed: '{1}'",
                                                   collectorEntry.Name, collectorEntry.RestorationScriptPath));
 }
Beispiel #25
0
        public string ToCollectorHostXml()
        {
            string collectorAgentsXml = CollectorHost.GetRemoteCollectorAgentsConfigXml(Agents, AgentCheckSequence);

            return(CollectorHost.ToXml(UniqueId,
                                       Name,
                                       Enabled,
                                       ChildCheckBehaviour.OnlyRunOnSuccess,
                                       RunAsEnabled,
                                       RunAs,
                                       collectorAgentsXml
                                       ));
        }
Beispiel #26
0
        /// <summary>
        /// When Initializing/reinitializing the scripts
        /// </summary>
        //public void InitializeCollectorActionScripts()
        //{
        //    foreach (CollectorHost collectorHost in CollectorHosts)
        //    {
        //        InitializeCollectorActionScripts(collectorHost);
        //    }
        //}
        //public void InitializeCollectorActionScripts(CollectorHost collectorHost)
        //{
        //    if (collectorHost != null && collectorHost.ActionScripts != null)
        //    {
        //        foreach(var collectorActionScript in collectorHost.ActionScripts)
        //        {
        //            ActionScript currentActionScript = (from acs in ActionScripts
        //                                                where acs.Id == collectorActionScript.MPId
        //                                                select acs).FirstOrDefault();
        //            if (currentActionScript != null)
        //                collectorActionScript.InitializeScript(currentActionScript);
        //        }
        //    }
        //}
        public CollectorHost GetParentCollectorHost(CollectorHost child)
        {
            CollectorHost selectedCH = null;

            if (CollectorHosts != null && child != null && child.ParentCollectorId != null && child.ParentCollectorId.Length > 0)
            {
                selectedCH = (from CollectorHost c in CollectorHosts
                              where c.UniqueId == child.ParentCollectorId
                              select c).FirstOrDefault();
            }

            return(selectedCH);
        }
Beispiel #27
0
        private void monitorPack_RaiseCollectorError(CollectorHost collectorHost, string errorMessage)
        {
            string lastCollectorDetails = "N/A";

            if (collectorHost != null && collectorHost.CurrentState != null)
            {
                lastCollectorDetails = collectorHost.CurrentState.ReadAllRawDetails();
            }

            EventLog.WriteEntry(Globals.ServiceEventSourceName, string.Format("Collector error\r\n" +
                                                                              "Collector name: {0}\r\n" +
                                                                              "Last details: {1}\r\n" +
                                                                              "Error details: {2}", collectorHost.Name, lastCollectorDetails, errorMessage), EventLogEntryType.Error, 2);
        }
Beispiel #28
0
        public string ExportCollectorHistoryToCSV(bool addheader = true)
        {
            StringBuilder sb = new StringBuilder();

            if (addheader)
            {
                sb.Append(CollectorHost.ExportHistoryToCSVHeaders());
            }
            foreach (CollectorHost ch in CollectorHosts)
            {
                sb.Append(ch.ExportHistoryToCSV());
            }
            return(sb.ToString());
        }
Beispiel #29
0
 private void LoggingServiceWindowEvent(CollectorHost collectorHost, bool entered)
 {
     if (LoggingServiceWindowEvents)
     {
         if (entered)
         {
             WriteLogging(string.Format("Collector '{0}' entered a service window.", collectorHost.Name));
         }
         else
         {
             WriteLogging(string.Format("Collector '{0}' exited a service window.", collectorHost.Name));
         }
     }
 }
Beispiel #30
0
        public static System.Data.DataSet GetRemoteHostAllAgentDetails(CollectorHost entry, string hostAddressOverride, int portNumberOverride)
        {
            BasicHttpBinding myBinding = new BasicHttpBinding();

            myBinding.MaxReceivedMessageSize = 2147483647;
            EndpointAddress myEndpoint = new EndpointAddress(string.Format("http://{0}:{1}/QuickMonRemoteHost", hostAddressOverride, portNumberOverride));
            ChannelFactory <IRemoteCollectorHostService> myChannelFactory = new ChannelFactory <IRemoteCollectorHostService>(myBinding, myEndpoint);
            IRemoteCollectorHostService relay = myChannelFactory.CreateChannel();

            RemoteCollectorHost colReq = new RemoteCollectorHost();

            colReq.FromCollectorHost(entry);
            return(relay.GetCollectorHostDetails(colReq));
        }