private List <ConfigVariable> GetConfigVarsNow() { List <ConfigVariable> allConfigVars = new List <ConfigVariable>(); //applying its own first foreach (ConfigVariable cv in ConfigVariables) { ConfigVariable existingCV = (from ConfigVariable c in allConfigVars where c.FindValue == cv.FindValue select c).FirstOrDefault(); if (existingCV == null) { allConfigVars.Add(cv.Clone()); } } //then applying parent Collector Host variables if (ParentMonitorPack != null) { foreach (ConfigVariable cv in GetAllParentConfigVars()) { ConfigVariable existingCV = (from ConfigVariable c in allConfigVars where c.FindValue == cv.FindValue select c).FirstOrDefault(); if (existingCV == null) { allConfigVars.Add(cv.Clone()); } } } return(allConfigVars); }
private void moveDownConfigVarToolStripButton_Click(object sender, EventArgs e) { if (lvwConfigVars.SelectedItems.Count == 1) { int index = lvwConfigVars.SelectedItems[0].Index; if (index < lvwConfigVars.Items.Count - 1) { loadConfigVarEntry = true; ConfigVariable tmpBottom = (ConfigVariable)lvwConfigVars.Items[index + 1].Tag; ConfigVariable tmpTop = (ConfigVariable)lvwConfigVars.Items[index].Tag; lvwConfigVars.Items[index + 1].Tag = tmpTop; lvwConfigVars.Items[index + 1].Text = tmpTop.FindValue; lvwConfigVars.Items[index + 1].SubItems[1].Text = tmpTop.ReplaceValue; lvwConfigVars.Items[index].Tag = tmpBottom; lvwConfigVars.Items[index].Text = tmpBottom.FindValue; lvwConfigVars.Items[index].SubItems[1].Text = tmpBottom.ReplaceValue; lvwConfigVars.Items[index].Selected = false; lvwConfigVars.Items[index].Focused = false; lvwConfigVars.Items[index + 1].Selected = true; lvwConfigVars.Items[index + 1].Focused = true; lvwConfigVars.Items[index].EnsureVisible(); loadConfigVarEntry = false; } } }
public static ConfigVariable FromXml(XmlNode configVarNode) { ConfigVariable newConfigVariable = new ConfigVariable(); newConfigVariable.FindValue = configVarNode.ReadXmlElementAttr("find", ""); newConfigVariable.ReplaceValue = configVarNode.ReadXmlElementAttr("replace", ""); return(newConfigVariable); }
public static ConfigVariable FromXml(string xmlStr) { ConfigVariable newConfigVariable = new ConfigVariable(); XmlDocument config = new XmlDocument(); config.LoadXml(xmlStr); newConfigVariable = FromXml(config.DocumentElement); return(newConfigVariable); }
public static ConfigVariable FromXml(string xmlStr) { ConfigVariable newConfigVariable = new ConfigVariable(); XmlDocument config = new XmlDocument(); config.LoadXml(xmlStr); XmlElement root = config.DocumentElement; newConfigVariable.Name = root.ReadXmlElementAttr("name", ""); newConfigVariable.Value = root.ReadXmlElementAttr("value", ""); return(newConfigVariable); }
public static ConfigVariable FromXml(string xmlStr) { ConfigVariable newConfigVariable = new ConfigVariable(); XmlDocument config = new XmlDocument(); config.LoadXml(xmlStr); XmlElement root = config.DocumentElement; newConfigVariable.FindValue = root.ReadXmlElementAttr("find", ""); newConfigVariable.ReplaceValue = root.ReadXmlElementAttr("replace", ""); return(newConfigVariable); }
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)); } } }
public void ConfigVarsFindReplaceTest() { try { ConfigVariable cv = new ConfigVariable(); cv.FindValue = "123"; cv.ReplaceValue = "abc"; string someText = "This is a 123 test"; string changedText = cv.ApplyOn(someText); Assert.AreEqual("This is a abc test", changedText, "Find/Replace failed"); } catch (Exception ex) { Assert.Fail("ConfigVariable exception: " + ex.ToString()); } }
public List <ConfigVariable> GetAllParentConfigVars() { List <ConfigVariable> allConfigVars = new List <ConfigVariable>(); if (ParentMonitorPack != null) { //apply static/hardcoded monitor pack variables allConfigVars.Add(new ConfigVariable() { FindValue = "$QMScripts", ReplaceValue = ParentMonitorPack.ScriptsRepositoryDirectory }); allConfigVars.Add(new ConfigVariable() { FindValue = "$QMVersion", ReplaceValue = ParentMonitorPack.Version }); allConfigVars.Add(new ConfigVariable() { FindValue = "$QMCoreVersion", ReplaceValue = System.Reflection.Assembly.GetAssembly(typeof(MonitorPack)).GetName().Version.ToString() }); foreach (CollectorHost parentCollector in ParentMonitorPack.GetParentCollectorHostTree(this)) { foreach (ConfigVariable cv in parentCollector.ConfigVariables) { ConfigVariable existingCV = (from ConfigVariable c in allConfigVars where c.FindValue == cv.FindValue select c).FirstOrDefault(); if (existingCV == null) { allConfigVars.Add(cv.Clone()); } } } //then applying parent monitor pack variables foreach (ConfigVariable cv in ParentMonitorPack.ConfigVariables) { ConfigVariable existingCV = (from ConfigVariable c in allConfigVars where c.FindValue == cv.FindValue select c).FirstOrDefault(); if (existingCV == null) { allConfigVars.Add(cv.Clone()); } } } return(allConfigVars); }
public static string ApplyOn(this List <ConfigVariable> configVars, string configStr) { string appliedConfig = configStr; List <ConfigVariable> uniqueConfigVars = new List <ConfigVariable>(); if (configVars == null) { configVars = new List <ConfigVariable>(); } foreach (ConfigVariable cv in configVars) { ConfigVariable existingCV = (from ConfigVariable c in uniqueConfigVars where c.FindValue == cv.FindValue select c).FirstOrDefault(); if (existingCV == null) { uniqueConfigVars.Add(cv.Clone()); } } if (uniqueConfigVars.Count == 0) //adds dummy entry so internal vars also get applied { uniqueConfigVars.Add(new ConfigVariable() { FindValue = DateTime.Now.Millisecond.ToString(), ReplaceValue = DateTime.Now.Millisecond.ToString() }); } foreach (ConfigVariable cv in uniqueConfigVars) { appliedConfig = cv.ApplyOn(appliedConfig); } //if (configVars != null) //{ // if (configVars.Count == 0) //adds dummy entry so internal vars also get applied // { // configVars.Add(new ConfigVariable() { FindValue = DateTime.Now.Millisecond.ToString(), ReplaceValue = DateTime.Now.Millisecond.ToString() }); // } // foreach (ConfigVariable cv in configVars) // appliedConfig = cv.ApplyOn(appliedConfig); //} //if (appliedConfig.IndexOf("%LocalHost%", StringComparison.CurrentCultureIgnoreCase) > -1) // appliedConfig = appliedConfig.Replace("%LocalHost%", System.Net.Dns.GetHostName()); return(appliedConfig); }
public static ConfigVariable FromXml(XmlNode configVarNode) { ConfigVariable newConfigVariable = new ConfigVariable(); XmlNode findNode = configVarNode.SelectSingleNode("find"); XmlNode replaceNode = configVarNode.SelectSingleNode("replace"); if (findNode == null || replaceNode == null) { newConfigVariable.FindValue = configVarNode.ReadXmlElementAttr("find", ""); newConfigVariable.ReplaceValue = configVarNode.ReadXmlElementAttr("replace", ""); } else { newConfigVariable.FindValue = findNode.InnerText; newConfigVariable.ReplaceValue = replaceNode.InnerText; } return(newConfigVariable); }
public void ApplyConfigVarsNow() { List <ConfigVariable> allConfigVars = new List <ConfigVariable>(); //applying its own first foreach (ConfigVariable cv in ConfigVariables) { ConfigVariable existingCV = (from ConfigVariable c in allConfigVars where c.FindValue == cv.FindValue select c).FirstOrDefault(); if (existingCV == null) { allConfigVars.Add(cv.Clone()); } } if (ParentMonitorPack != null) { //then applying parent monitor pack variables foreach (ConfigVariable cv in ParentMonitorPack.ConfigVariables) { ConfigVariable existingCV = (from ConfigVariable c in allConfigVars where c.FindValue == cv.FindValue select c).FirstOrDefault(); if (existingCV == null) { allConfigVars.Add(cv.Clone()); } } } foreach (IAgent agent in NotifierAgents) { string appliedConfig = agent.InitialConfiguration; appliedConfig = allConfigVars.ApplyOn(appliedConfig); //only reapply if it is different from existing if (agent.ActiveConfiguration != appliedConfig) { agent.ActiveConfiguration = appliedConfig; agent.AgentConfig.FromXml(appliedConfig); } } }
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(); }
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); }
/// <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) { 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); } }