public static NotifierEntry FromConfig(XmlElement xmlNotifierEntry) { NotifierEntry notifierEntry = new NotifierEntry(); notifierEntry.Name = xmlNotifierEntry.ReadXmlElementAttr("name"); notifierEntry.NotifierRegistrationName = xmlNotifierEntry.ReadXmlElementAttr("notifier"); notifierEntry.Enabled = xmlNotifierEntry.ReadXmlElementAttr("enabled", false); notifierEntry.AlertLevel = (AlertLevel)Enum.Parse(typeof(AlertLevel), xmlNotifierEntry.ReadXmlElementAttr("alertLevel", "Warning")); notifierEntry.DetailLevel = (DetailLevel)Enum.Parse(typeof(DetailLevel), xmlNotifierEntry.ReadXmlElementAttr("detailLevel", "Detail")); notifierEntry.AttendedOptionOverride = (AttendedOption)Enum.Parse(typeof(AttendedOption), xmlNotifierEntry.ReadXmlElementAttr("attendedOptionOverride", "AttendedAndUnAttended")); if (xmlNotifierEntry.SelectSingleNode("config") != null) { notifierEntry.InitialConfiguration = xmlNotifierEntry.SelectSingleNode("config").OuterXml; } //Service windows config notifierEntry.ServiceWindows = new ServiceWindows(); XmlNode serviceWindowsNode = xmlNotifierEntry.SelectSingleNode("serviceWindows"); if (serviceWindowsNode != null) //Load service windows info { notifierEntry.ServiceWindows.CreateFromConfig(serviceWindowsNode.OuterXml); } else { notifierEntry.ServiceWindows.CreateFromConfig("<serviceWindows />"); } XmlNode collectorsNode = xmlNotifierEntry.SelectSingleNode("collectors"); if (collectorsNode != null) { foreach (XmlElement colNode in collectorsNode.SelectNodes("collector")) { string collectorName = colNode.ReadXmlElementAttr("name", ""); if (collectorName.Length > 0) { notifierEntry.AlertForCollectors.Add(collectorName); } } } XmlNode configVarsNode = xmlNotifierEntry.SelectSingleNode("configVars"); if (configVarsNode != null) { foreach (XmlNode configVarNode in configVarsNode.SelectNodes("configVar")) { notifierEntry.ConfigVariables.Add(ConfigVariable.FromXml(configVarNode.OuterXml)); } } return(notifierEntry); }
private void LoadConfigVars(XmlElement root) { XmlNode configVarsNode = root.SelectSingleNode("configVars"); ConfigVariables = new List <ConfigVariable>(); if (configVarsNode != null) { foreach (XmlElement configVarNode in configVarsNode.SelectNodes("configVar")) { ConfigVariables.Add(ConfigVariable.FromXml(configVarNode)); } } }
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); }
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 XmlNode configVarsNode = root.SelectSingleNode("configVars"); ConfigVariables = new List <ConfigVariable>(); if (configVarsNode != null) { foreach (XmlElement configVarNode in configVarsNode.SelectNodes("configVar")) { ConfigVariables.Add(ConfigVariable.FromXml(configVarNode)); } } #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); } }
/// <summary> /// Create CollectorEntry instance based on configuration string /// </summary> /// <param name="xmlCollectorEntry">configuration XmlElement instance</param> /// <returns>CollectorEntry instance</returns> public static CollectorEntry FromConfig(XmlElement xmlCollectorEntry) { CollectorEntry collectorEntry = new CollectorEntry(); collectorEntry.LastStateChange = DateTime.Now; collectorEntry.Name = xmlCollectorEntry.ReadXmlElementAttr("name", "").Trim(); collectorEntry.UniqueId = xmlCollectorEntry.ReadXmlElementAttr("uniqueID", DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss")); collectorEntry.Enabled = bool.Parse(xmlCollectorEntry.ReadXmlElementAttr("enabled", "True")); collectorEntry.ExpandOnStart = xmlCollectorEntry.ReadXmlElementAttr("expandOnStart", true); collectorEntry.IsFolder = bool.Parse(xmlCollectorEntry.ReadXmlElementAttr("isFolder", "False")); collectorEntry.ParentCollectorId = xmlCollectorEntry.ReadXmlElementAttr("dependOnParent"); collectorEntry.CorrectiveScriptDisabled = bool.Parse(xmlCollectorEntry.ReadXmlElementAttr("correctiveScriptDisabled", "False")); collectorEntry.CorrectiveScriptOnWarningPath = xmlCollectorEntry.ReadXmlElementAttr("correctiveScriptOnWarningPath"); collectorEntry.CorrectiveScriptOnErrorPath = xmlCollectorEntry.ReadXmlElementAttr("correctiveScriptOnErrorPath"); collectorEntry.RestorationScriptPath = xmlCollectorEntry.ReadXmlElementAttr("restorationScriptPath"); collectorEntry.CorrectiveScriptsOnlyOnStateChange = bool.Parse(xmlCollectorEntry.ReadXmlElementAttr("correctiveScriptsOnlyOnStateChange", "False")); collectorEntry.EnableRemoteExecute = bool.Parse(xmlCollectorEntry.ReadXmlElementAttr("enableRemoteExecute", "False")); collectorEntry.ForceRemoteExcuteOnChildCollectors = bool.Parse(xmlCollectorEntry.ReadXmlElementAttr("forceRemoteExcuteOnChildCollectors", "False")); collectorEntry.RemoteAgentHostAddress = xmlCollectorEntry.ReadXmlElementAttr("remoteAgentHostAddress"); collectorEntry.RemoteAgentHostPort = xmlCollectorEntry.ReadXmlElementAttr("remoteAgentHostPort", 8181); collectorEntry.BlockParentOverrideRemoteAgentHostSettings = xmlCollectorEntry.ReadXmlElementAttr("blockParentRemoteAgentHostSettings", false); collectorEntry.RunLocalOnRemoteHostConnectionFailure = xmlCollectorEntry.ReadXmlElementAttr("runLocalOnRemoteHostConnectionFailure", false); collectorEntry.AlertsPaused = bool.Parse(xmlCollectorEntry.ReadXmlElementAttr("alertsPaused", "False")); //Polling overrides collectorEntry.EnabledPollingOverride = xmlCollectorEntry.ReadXmlElementAttr("enabledPollingOverride", false); collectorEntry.OnlyAllowUpdateOncePerXSec = xmlCollectorEntry.ReadXmlElementAttr("onlyAllowUpdateOncePerXSec", 1); collectorEntry.EnablePollFrequencySliding = xmlCollectorEntry.ReadXmlElementAttr("enablePollFrequencySliding", false); collectorEntry.PollSlideFrequencyAfterFirstRepeatSec = xmlCollectorEntry.ReadXmlElementAttr("pollSlideFrequencyAfterFirstRepeatSec", 2); collectorEntry.PollSlideFrequencyAfterSecondRepeatSec = xmlCollectorEntry.ReadXmlElementAttr("pollSlideFrequencyAfterSecondRepeatSec", 5); collectorEntry.PollSlideFrequencyAfterThirdRepeatSec = xmlCollectorEntry.ReadXmlElementAttr("pollSlideFrequencyAfterThirdRepeatSec", 30); //Service windows config collectorEntry.ServiceWindows = new ServiceWindows(); XmlNode serviceWindowsNode = xmlCollectorEntry.SelectSingleNode("serviceWindows"); if (serviceWindowsNode != null) //Load service windows info { collectorEntry.ServiceWindows.CreateFromConfig(serviceWindowsNode.OuterXml); } else { collectorEntry.ServiceWindows.CreateFromConfig("<serviceWindows />"); } if (!collectorEntry.IsFolder) { collectorEntry.CollectorRegistrationName = xmlCollectorEntry.ReadXmlElementAttr("collector", "No collector"); collectorEntry.CollectOnParentWarning = bool.Parse(xmlCollectorEntry.ReadXmlElementAttr("collectOnParentWarning", "False")); collectorEntry.RepeatAlertInXMin = int.Parse(xmlCollectorEntry.ReadXmlElementAttr("repeatAlertInXMin", "0")); collectorEntry.AlertOnceInXMin = int.Parse(xmlCollectorEntry.ReadXmlElementAttr("alertOnceInXMin", "0")); collectorEntry.DelayErrWarnAlertForXSec = int.Parse(xmlCollectorEntry.ReadXmlElementAttr("delayErrWarnAlertForXSec", "0")); collectorEntry.RepeatAlertInXPolls = int.Parse(xmlCollectorEntry.ReadXmlElementAttr("repeatAlertInXPolls", "0")); collectorEntry.AlertOnceInXPolls = int.Parse(xmlCollectorEntry.ReadXmlElementAttr("alertOnceInXPolls", "0")); collectorEntry.DelayErrWarnAlertForXPolls = int.Parse(xmlCollectorEntry.ReadXmlElementAttr("delayErrWarnAlertForXPolls", "0")); collectorEntry.LastAlertTime = new DateTime(2000, 1, 1); //long ago collectorEntry.LastGoodStateTime = new DateTime(2000, 1, 1); //long ago collectorEntry.LastMonitorState = new MonitorState() { State = CollectorState.NotAvailable, CurrentValue = null, RawDetails = "", HtmlDetails = "" }; XmlNode configNode = xmlCollectorEntry.SelectSingleNode("config"); if (configNode != null) { collectorEntry.InitialConfiguration = configNode.OuterXml; } else { collectorEntry.LastMonitorState.State = CollectorState.ConfigurationError; collectorEntry.InitialConfiguration = ""; } XmlNode configVarsNode = xmlCollectorEntry.SelectSingleNode("configVars"); if (configVarsNode != null) { foreach (XmlNode configVarNode in configVarsNode.SelectNodes("configVar")) { collectorEntry.ConfigVariables.Add(ConfigVariable.FromXml(configVarNode.OuterXml)); } } } else { collectorEntry.CollectorRegistrationName = "Folder"; collectorEntry.CollectorRegistrationDisplayName = "Folder"; collectorEntry.InitialConfiguration = ""; collectorEntry.LastMonitorState.State = CollectorState.Folder; } return(collectorEntry); }
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(); }