Exemplo n.º 1
0
        private void llblRawEdit_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            if (SetEditingNotifierHost())
            {
                RAWXmlEditor editor    = new RAWXmlEditor();
                string       oldMarkUp = editingNotifierHost.ToXml();
                editor.SelectedMarkup = oldMarkUp;
                if (editor.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    try
                    {
                        editingNotifierHost = NotifierHost.FromXml(editor.SelectedMarkup, null, false);

                        if (editor.SelectedMarkup == null || editor.SelectedMarkup.Length == 0)
                        {
                            if (MessageBox.Show("Editing the raw config resulted in a configuration error!\r\nDo you want to accept this?", "Configuration error", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == System.Windows.Forms.DialogResult.No)
                            {
                                editingNotifierHost = NotifierHost.FromXml(oldMarkUp, null, false);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("An error occured while processing the config!\r\n" + ex.Message, "Edit config", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                    LoadControlData();
                }
            }
        }
Exemplo n.º 2
0
 private void RaiseNotifierError(NotifierHost notifier, string errorMessage)
 {
     try
     {
         OnNotifierError?.Invoke(notifier, errorMessage);
     }
     catch (Exception ex)
     {
         System.Diagnostics.Trace.WriteLine(string.Format("Error in RaiseNotifierError: {0}", ex.Message));
     }
 }
Exemplo n.º 3
0
        public static List <NotifierHost> GetNotifierHosts(XmlNode notifierHostsNode, MonitorPack parentMonitorPack = null) //, List<ConfigVariable> monitorPackVars = null)
        {
            List <NotifierHost> notifierHosts = new List <NotifierHost>();

            foreach (XmlElement xmlNotifierHost in notifierHostsNode.SelectNodes("notifierHost"))
            {
                NotifierHost newNotifierHost = NotifierHost.FromConfig(null, xmlNotifierHost); //, monitorPackVars);
                newNotifierHost.ParentMonitorPack = parentMonitorPack;
                notifierHosts.Add(newNotifierHost);
            }
            return(notifierHosts);
        }
Exemplo n.º 4
0
        internal void SwapNotifierEntries(NotifierHost n1, NotifierHost n2)
        {
            int index1 = NotifierHosts.FindIndex(c => c.Name == n1.Name);
            int index2 = NotifierHosts.FindIndex(c => c.Name == n2.Name);

            if (index1 > -1 && index2 > -1 && index1 != index2)
            {
                NotifierHosts.RemoveAt(index1);
                NotifierHosts.RemoveAt(index2);
                NotifierHosts.Insert(index2, n1);
                NotifierHosts.Insert(index1, n2);
            }
        }
Exemplo n.º 5
0
        //private bool loading = false;

        public DialogResult ShowDialog(NotifierHost nh, MonitorPack hostingMonitorPack = null)
        {
            if (nh != null)
            {
                SelectedConfig     = nh.ToXml();
                HostingMonitorPack = hostingMonitorPack;
                return(ShowDialog());
            }
            else
            {
                return(System.Windows.Forms.DialogResult.Cancel);
            }
        }
Exemplo n.º 6
0
        public static List <NotifierHost> GetNotifierHostsFromString(string xmlString, List <ConfigVariable> monitorPackVars = null)
        {
            List <NotifierHost> notifierHosts    = new List <NotifierHost>();
            XmlDocument         notifierHostsXml = new XmlDocument();

            notifierHostsXml.LoadXml(xmlString);
            XmlElement root = notifierHostsXml.DocumentElement;

            foreach (XmlElement xmlNotifierHost in root.SelectNodes("notifierHost"))
            {
                NotifierHost newNotifierHost = NotifierHost.FromConfig(null, xmlNotifierHost, monitorPackVars);
                notifierHosts.Add(newNotifierHost);
            }
            return(notifierHosts);
        }
Exemplo n.º 7
0
 private void SetAlertForCollectors(NotifierHost editingNotifierHost, TreeNode parent = null)
 {
     if (parent == null)
     {
         parent = tvwCollectors.Nodes[0];
     }
     foreach (TreeNode child in parent.Nodes)
     {
         if (child.Checked && child.Tag is CollectorHost)
         {
             CollectorHost ch = (CollectorHost)child.Tag;
             editingNotifierHost.AlertForCollectors.Add(ch.Name);
         }
         SetAlertForCollectors(editingNotifierHost, child);
     }
 }
Exemplo n.º 8
0
 private void EditNotifierHost_Load(object sender, EventArgs e)
 {
     try
     {
         if (SelectedConfig != null && SelectedConfig.Length > 0 && SelectedConfig.StartsWith("<notifierHost", StringComparison.CurrentCultureIgnoreCase))
         {
             editingNotifierHost = NotifierHost.FromXml(SelectedConfig, null, false);
         }
         else
         {
             editingNotifierHost = new NotifierHost();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Loading error: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Exemplo n.º 9
0
 private void monitorPack_NotifierError(NotifierHost notifier, string errorMessage)
 {
     EventLog.WriteEntry(Globals.ServiceEventSourceName, string.Format("There was a problem recording an alert with notifier {0}\r\n{1}", notifier.Name, errorMessage), EventLogEntryType.Error, 1);
 }
Exemplo n.º 10
0
        public void LoadXml(string xmlConfig)
        {
            try
            {
                LastMPLoadError = "";
                Stopwatch   sw = new Stopwatch();
                XmlDocument configurationXml = new XmlDocument();
                sw.Start();
                configurationXml.LoadXml(xmlConfig);
                sw.Stop();
                System.Diagnostics.Trace.WriteLine(string.Format("MonitorPack Loading XML time:{0}ms", sw.ElapsedMilliseconds));

                sw.Reset();
                sw.Start();
                XmlElement root = configurationXml.DocumentElement;
                Name                        = root.ReadXmlElementAttr("name", "");
                LastChangeDate              = root.ReadXmlElementAttr("lastChanged", DateTime.Now);
                TypeName                    = root.ReadXmlElementAttr("typeName", "");
                this.Version                = root.ReadXmlElementAttr("version", "5.0.0.0");
                Enabled                     = root.ReadXmlElementAttr("enabled", true);
                CollectorStateHistorySize   = root.ReadXmlElementAttr("stateHistorySize", 100);      //Depricated
                PollingFrequencyOverrideSec = root.ReadXmlElementAttr("pollingFreqSecOverride", 0);  //Depricated
                CorrectiveScriptsEnabled    = root.ReadXmlElementAttr("runCorrectiveScripts", true); //Depricated
                LoggingEnabled              = root.ReadXmlElementAttr("loggingEnabled", false);      //Deprecated

                /***************** Load config variables ****************/
                #region Load config variables
                LoadConfigVars(root);
                #endregion
                /***************** Load Collectors ****************/
                #region Load Collectors
                XmlNode collectorHostsNode = root.SelectSingleNode("collectorHosts");
                if (collectorHostsNode != null)
                {
                    CorrectiveScriptsEnabled    = collectorHostsNode.ReadXmlElementAttr("correctiveScriptsEnabled", CorrectiveScriptsEnabled);
                    CollectorStateHistorySize   = collectorHostsNode.ReadXmlElementAttr("stateHistorySize", CollectorStateHistorySize);
                    PollingFrequencyOverrideSec = collectorHostsNode.ReadXmlElementAttr("pollingFreqSecOverride", PollingFrequencyOverrideSec);

                    //XmlNode actionScriptsNode = collectorHostsNode.SelectSingleNode("actionScripts");
                    //if (actionScriptsNode != null)
                    //{
                    //    ActionScripts = ActionScript.FromXml(actionScriptsNode);
                    //}

                    CollectorHosts = CollectorHost.GetCollectorHosts(collectorHostsNode, this);// , ConfigVariables);
                    foreach (CollectorHost collectorHost in CollectorHosts)
                    {
                        SetCollectorHostEvents(collectorHost);
                    }
                    //InitializeCollectorActionScripts();
                }
                #endregion
                /***************** Load Notifiers ****************/
                #region Load Notifiers
                XmlNode notifierHostsNode = root.SelectSingleNode("notifierHosts");
                if (notifierHostsNode != null)
                {
                    NotifierHosts = NotifierHost.GetNotifierHosts(notifierHostsNode, this); //, ConfigVariables);
                }
                #endregion

                #region security
                UserNameCacheMasterKey = root.ReadXmlElementAttr("usernameCacheMasterKey", "");
                UserNameCacheFilePath  = root.ReadXmlElementAttr("usernameCacheFilePath", "");
                #endregion

                #region Logging
                LoggingCollectorCategories = new List <string>();
                XmlNode loggingNode = root.SelectSingleNode("logging");
                if (loggingNode != null)
                {
                    LoggingEnabled                   = loggingNode.ReadXmlElementAttr("enabled", LoggingEnabled);
                    LoggingPath                      = loggingNode.ReadXmlElementAttr("loggingPath", "");
                    LoggingCollectorEvents           = loggingNode.ReadXmlElementAttr("loggingCollectorEvents", false);
                    LoggingNotifierEvents            = loggingNode.ReadXmlElementAttr("loggingNotifierEvents", false);
                    LoggingAlertsRaised              = loggingNode.ReadXmlElementAttr("loggingAlertsRaised", false);
                    LoggingCorrectiveScriptRun       = loggingNode.ReadXmlElementAttr("loggingCorrectiveScriptRun", false);
                    LoggingPollingOverridesTriggered = loggingNode.ReadXmlElementAttr("loggingPollingOverridesTriggered", false);
                    LoggingServiceWindowEvents       = loggingNode.ReadXmlElementAttr("loggingServiceWindowEvents", false);
                    LoggingKeepLogFilesXDays         = loggingNode.ReadXmlElementAttr("loggingKeepLogFilesXDays", 180);

                    XmlNode loggingCollectorCategoriesNode = loggingNode.SelectSingleNode("collectorCategories");
                    if (loggingCollectorCategoriesNode != null)
                    {
                        foreach (XmlNode categoryNode in loggingCollectorCategoriesNode.SelectNodes("category"))
                        {
                            LoggingCollectorCategories.Add(categoryNode.InnerText.UnEscapeXml());
                        }
                    }
                }
                else
                {
                    LoggingEnabled = false;
                }
                #endregion

                sw.Stop();
                System.Diagnostics.Trace.WriteLine(string.Format("MonitorPack Parsing XML time:{0}ms", sw.ElapsedMilliseconds));
                InitializeGlobalPerformanceCounters();
            }
            catch (Exception ex)
            {
                LastMPLoadError = ex.ToString();
            }
            if (LastMPLoadError.Length == 0)
            {
                WriteLogging("Monitor config loaded with no errors");
            }
            else
            {
                WriteLogging("Monitor config loaded with errors - " + LastMPLoadError);
            }
        }
Exemplo n.º 11
0
 /// <summary>
 /// When adding a new notifier host manually or by editing it needs to be initialized for events, config vars etc.
 /// </summary>
 /// <param name="notifierHost"></param>
 public void AddNotifierHost(NotifierHost notifierHost)
 {
     notifierHost.ParentMonitorPack = this;
     NotifierHosts.Add(notifierHost);
 }
Exemplo n.º 12
0
        private static NotifierHost FromConfig(NotifierHost newNotifierHost, XmlElement xmlNotifierHost, List <ConfigVariable> monitorPackVars, bool applyConfigVars = true)
        {
            if (newNotifierHost == null)
            {
                newNotifierHost = new NotifierHost();
            }
            newNotifierHost.Name                   = xmlNotifierHost.ReadXmlElementAttr("name", "").Trim();
            newNotifierHost.Enabled                = xmlNotifierHost.ReadXmlElementAttr("enabled", true);
            newNotifierHost.AlertLevel             = (AlertLevel)Enum.Parse(typeof(AlertLevel), xmlNotifierHost.ReadXmlElementAttr("alertLevel", "Warning"));
            newNotifierHost.DetailLevel            = (DetailLevel)Enum.Parse(typeof(DetailLevel), xmlNotifierHost.ReadXmlElementAttr("detailLevel", "Detail"));
            newNotifierHost.AttendedOptionOverride = (AttendedOption)Enum.Parse(typeof(AttendedOption), xmlNotifierHost.ReadXmlElementAttr("attendedOptionOverride", "AttendedAndUnAttended"));

            //Service windows config
            newNotifierHost.ServiceWindows = new ServiceWindows();
            XmlNode serviceWindowsNode = xmlNotifierHost.SelectSingleNode("serviceWindows");

            if (serviceWindowsNode != null) //Load service windows info
            {
                newNotifierHost.ServiceWindows.CreateFromConfig(serviceWindowsNode.OuterXml);
            }
            else
            {
                newNotifierHost.ServiceWindows.CreateFromConfig("<serviceWindows />");
            }
            //Categories
            XmlNode categoriesNode = xmlNotifierHost.SelectSingleNode("categories");

            if (categoriesNode != null)
            {
                newNotifierHost.CategoriesCreateFromConfig(categoriesNode.OuterXml);
            }
            else
            {
                newNotifierHost.Categories = new List <string>();
            }

            XmlNode collectorsNode = xmlNotifierHost.SelectSingleNode("collectorHosts");

            if (collectorsNode != null)
            {
                newNotifierHost.AlertForCollectors = new List <string>();
                foreach (XmlElement colNode in collectorsNode.SelectNodes("collectorHost"))
                {
                    string collectorName = colNode.ReadXmlElementAttr("name", "");
                    if (collectorName.Length > 0)
                    {
                        newNotifierHost.AlertForCollectors.Add(collectorName);
                    }
                }
            }
            XmlNode configVarsNode = xmlNotifierHost.SelectSingleNode("configVars");

            if (configVarsNode != null)
            {
                newNotifierHost.ConfigVariables = new List <ConfigVariable>();
                foreach (XmlNode configVarNode in configVarsNode.SelectNodes("configVar"))
                {
                    newNotifierHost.ConfigVariables.Add(ConfigVariable.FromXml(configVarNode.OuterXml));
                }
            }

            //OnlyRecordAlertOnHosts
            XmlNode recordOnHostsNode = xmlNotifierHost.SelectSingleNode("recordOnHosts");

            if (recordOnHostsNode != null)
            {
                newNotifierHost.OnlyRecordAlertOnHosts = new List <string>();
                foreach (XmlElement hostNode in recordOnHostsNode.SelectNodes("host"))
                {
                    newNotifierHost.OnlyRecordAlertOnHosts.Add(hostNode.ReadXmlElementAttr("name", ""));
                }
            }

            #region notifierAgents
            XmlNode notifierAgentsNode = xmlNotifierHost.SelectSingleNode("notifierAgents");
            if (notifierAgentsNode != null)
            {
                newNotifierHost.NotifierAgents = new List <INotifier>();
                foreach (XmlElement notifierAgentNode in notifierAgentsNode.SelectNodes("notifierAgent"))
                {
                    string  name       = notifierAgentNode.ReadXmlElementAttr("name", "");
                    string  typeName   = notifierAgentNode.ReadXmlElementAttr("type", "");
                    bool    enabled    = notifierAgentNode.ReadXmlElementAttr("enabled", true);
                    string  configXml  = "";
                    XmlNode configNode = notifierAgentNode.SelectSingleNode("config");
                    if (configNode != null)
                    {
                        configXml = configNode.OuterXml;
                    }
                    INotifier newAgent = CreateNotifierFromClassName(typeName);
                    if (newAgent != null)
                    {
                        try
                        {
                            newAgent.Name    = name;
                            newAgent.Enabled = enabled;
                            if (configXml.Length > 0)
                            {
                                newAgent.InitialConfiguration = configXml;
                            }
                            else
                            {
                                if (newAgent.AgentConfig != null)
                                {
                                    newAgent.InitialConfiguration = newAgent.AgentConfig.GetDefaultOrEmptyXml();
                                }
                                else
                                {
                                    newNotifierHost.Enabled = false;
                                }
                            }
                            string appliedConfig = newAgent.InitialConfiguration;
                            if (applyConfigVars)
                            {
                                appliedConfig = monitorPackVars.ApplyOn(appliedConfig);
                                appliedConfig = newNotifierHost.ConfigVariables.ApplyOn(appliedConfig);
                            }
                            newAgent.ActiveConfiguration = appliedConfig;
                            newNotifierHost.NotifierAgents.Add(newAgent);

                            newAgent.AgentConfig.FromXml(appliedConfig);
                        }
                        catch (Exception ex)
                        {
                            System.Diagnostics.Trace.WriteLine(ex.ToString());
                            newNotifierHost.Enabled = false;
                        }
                    }
                }
            }
            #endregion

            return(newNotifierHost);
        }
Exemplo n.º 13
0
        public void LoadXml(string xmlConfig)
        {
            Stopwatch   sw = new Stopwatch();
            XmlDocument configurationXml = new XmlDocument();

            sw.Start();
            configurationXml.LoadXml(xmlConfig);
            sw.Stop();
            System.Diagnostics.Trace.WriteLine(string.Format("MonitorPack Loading XML time:{0}ms", sw.ElapsedMilliseconds));

            sw.Reset();
            sw.Start();
            XmlElement root = configurationXml.DocumentElement;

            Name         = root.Attributes.GetNamedItem("name").Value;
            TypeName     = root.ReadXmlElementAttr("typeName", "");
            this.Version = root.ReadXmlElementAttr("version", "4.0.0.0");
            Enabled      = root.ReadXmlElementAttr("enabled", true);
            CollectorStateHistorySize   = root.ReadXmlElementAttr("stateHistorySize", 1);
            PollingFrequencyOverrideSec = root.ReadXmlElementAttr("pollingFreqSecOverride", 0);
            string defaultNotifierName = root.ReadXmlElementAttr("defaultNotifier");

            RunCorrectiveScripts = root.ReadXmlElementAttr("runCorrectiveScripts", true);
            LoggingEnabled       = root.ReadXmlElementAttr("loggingEnabled", false);

            /***************** Load config variables ****************/
            #region Load config variables
            XmlNode configVarsNode = root.SelectSingleNode("configVars");
            ConfigVariables = new List <ConfigVariable>();
            if (configVarsNode != null)
            {
                foreach (XmlElement configVarNodeEntry in configVarsNode.SelectNodes("configVar"))
                {
                    ConfigVariables.Add(ConfigVariable.FromXml(configVarNodeEntry.OuterXml));
                }
            }
            #endregion
            /***************** Load Collectors ****************/
            #region Load Collectors
            XmlNode collectorHostsNode = root.SelectSingleNode("collectorHosts");
            if (collectorHostsNode != null)
            {
                CollectorHosts = CollectorHost.GetCollectorHostsFromString(collectorHostsNode.OuterXml, ConfigVariables);
                foreach (CollectorHost collectorHost in CollectorHosts)
                {
                    SetCollectorHostEvents(collectorHost);
                }
            }
            #endregion
            /***************** Load Notifiers ****************/
            #region Load Notifiers
            XmlNode notifierHostsNode = root.SelectSingleNode("notifierHosts");
            if (notifierHostsNode != null)
            {
                NotifierHosts = NotifierHost.GetNotifierHostsFromString(notifierHostsNode.OuterXml, ConfigVariables);
            }
            #endregion

            #region security
            UserNameCacheMasterKey = root.ReadXmlElementAttr("usernameCacheMasterKey", "");
            UserNameCacheFilePath  = root.ReadXmlElementAttr("usernameCacheFilePath", "");
            #endregion

            #region Logging
            LoggingCollectorCategories = new List <string>();
            XmlNode loggingNode = root.SelectSingleNode("logging");
            if (loggingNode != null)
            {
                LoggingPath                      = loggingNode.ReadXmlElementAttr("loggingPath", "");
                LoggingCollectorEvents           = loggingNode.ReadXmlElementAttr("loggingCollectorEvents", false);
                LoggingNotifierEvents            = loggingNode.ReadXmlElementAttr("loggingNotifierEvents", false);
                LoggingAlertsRaised              = loggingNode.ReadXmlElementAttr("loggingAlertsRaised", false);
                LoggingCorrectiveScriptRun       = loggingNode.ReadXmlElementAttr("loggingCorrectiveScriptRun", false);
                LoggingPollingOverridesTriggered = loggingNode.ReadXmlElementAttr("loggingPollingOverridesTriggered", false);
                LoggingServiceWindowEvents       = loggingNode.ReadXmlElementAttr("loggingServiceWindowEvents", false);
                LoggingKeepLogFilesXDays         = loggingNode.ReadXmlElementAttr("loggingKeepLogFilesXDays", 180);

                XmlNode loggingCollectorCategoriesNode = loggingNode.SelectSingleNode("collectorCategories");
                if (loggingCollectorCategoriesNode != null)
                {
                    foreach (XmlNode categoryNode in loggingCollectorCategoriesNode.SelectNodes("category"))
                    {
                        LoggingCollectorCategories.Add(categoryNode.InnerText.UnEscapeXml());
                    }
                }
            }
            else
            {
                LoggingEnabled = false;
            }
            #endregion

            sw.Stop();
            System.Diagnostics.Trace.WriteLine(string.Format("MonitorPack Parsing XML time:{0}ms", sw.ElapsedMilliseconds));
            InitializeGlobalPerformanceCounters();
        }
Exemplo n.º 14
0
 public void AddNotifierHost(NotifierHost notifierHost)
 {
     NotifierHosts.Add(notifierHost);
 }