private void AddAndStartMonitorPack(string monitorPackPath) { try { StringBuilder sbNotifiers = new StringBuilder(); MonitorPack monitorPack = new MonitorPack(); EventLog.WriteEntry(serviceEventSource, string.Format("Starting QuickMon MonitorPack '{0}'", monitorPackPath), EventLogEntryType.Information, 0); monitorPack.Load(monitorPackPath); if (monitorPack.Notifiers != null && monitorPack.Notifiers.Count > 0) { foreach (var notifier in monitorPack.Notifiers) { sbNotifiers.AppendLine("\t" + notifier.Name); } } EventLog.WriteEntry(serviceEventSource, string.Format("MonitorPack '{0}' has the following notifiers\r\n{1}", monitorPack.Name, sbNotifiers.ToString()), EventLogEntryType.Information, 0); monitorPack.RaiseNotifierError += new RaiseNotifierErrorDelegare(monitorPack_RaiseNotifierError); monitorPack.RaiseCollectorError += new RaiseCollectorErrorDelegare(monitorPack_RaiseCollectorError); monitorPack.CollectorExecutionTimeEvent += new CollectorExecutionTimeDelegate(monitorPack_CollectorExecutionTimeEvent); monitorPack.RunCollectorCorrectiveWarningScript += new RaiseCollectorCalledDelegate(monitorPack_RunCollectorCorrectiveWarningScript); monitorPack.RunCollectorCorrectiveErrorScript += new RaiseCollectorCalledDelegate(monitorPack_RunCollectorCorrectiveErrorScript); monitorPack.PollingFreq = Properties.Settings.Default.PollingFreqSec * 1000; monitorPack.ConcurrencyLevel = concurrencyLevel; packs.Add(monitorPack); monitorPack.StartPolling(); PCSetMonitorPacksLoaded(packs.Count); } catch (Exception ex) { EventLog.WriteEntry(serviceEventSource, string.Format("Error loading/starting MonitorPack '{0}'\r\n{1}", monitorPackPath, ex.Message), EventLogEntryType.Error, 11); } }
private bool ParseTest(bool prompt = false) { //first check it it is valid XML string xmlText = @"<monitorPack version=""3.x.x.x"" name=""Test"" enabled=""False"" defaultViewerNotifier="""" runCorrectiveScripts=""False"">\r\n" + "<collectorEntries>\r\n" + txtConfig.Text + "\r\n</collectorEntries></monitorPack>"; try { XmlDocument textDoc = new XmlDocument(); textDoc.LoadXml(xmlText); } catch (Exception ex) { MessageBox.Show("XML not formatted properly!\r\n" + ex.Message, "XML format", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(false); } try { monitorPack = null; monitorPack = new MonitorPack(); monitorPack.LoadXml(xmlText); if (prompt) { MessageBox.Show("Collector config seems to be ok!", "Collector config", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { MessageBox.Show("Error parsing collector config!\r\n" + ex.Message, "Collector config", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(false); } return(true); }
private void EditMonitorPackConfig_Load(object sender, EventArgs e) { if (SelectedMonitorPack == null) { SelectedMonitorPack = new MonitorPack(); } if (SelectedMonitorPack.MonitorPackPath != null) { string pathString = SelectedMonitorPack.MonitorPackPath; if (TextRenderer.MeasureText(pathString + "........", lblMonitorPackPath.Font).Width > lblMonitorPackPath.Width) { string ellipseText = pathString.Substring(0, 20) + "...."; string tmpStr = pathString.Substring(4); while (TextRenderer.MeasureText(ellipseText + tmpStr, lblMonitorPackPath.Font).Width > lblMonitorPackPath.Width) { tmpStr = tmpStr.Substring(1); } pathString = ellipseText + tmpStr; } lblMonitorPackPath.Text = pathString; } txtName.Text = SelectedMonitorPack.Name; txtType.Text = SelectedMonitorPack.TypeName; chkCorrectiveScripts.Checked = SelectedMonitorPack.RunCorrectiveScripts; chkEnabled.Checked = SelectedMonitorPack.Enabled; collectorStateHistorySizeNumericUpDown.Value = SelectedMonitorPack.CollectorStateHistorySize; SetFrequency(SelectedMonitorPack.PollingFrequencyOverrideSec); LoadNotifiers(); }
public static List <AgentPresetConfig> GetAllPresets() { List <AgentPresetConfig> presets = new List <AgentPresetConfig>(); return(ReadPresetsFromFile(MonitorPack.GetQuickMonUserDataTemplatesFile())); //string progDataPath = MonitorPack.GetQuickMonUserDataDirectory();// System.IO.Path.Combine(System.Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Hen IT\\QuickMon 3"); //foreach (AgentPresetConfig apc in ReadPresetsFromDirectory(progDataPath)) //{ // if ((from p in presets // where p.Description == apc.Description && p.AgentClassName == apc.AgentClassName // select p).FirstOrDefault() == null) // presets.Add(apc); //} ////search current directory as well //string presetPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); //foreach (AgentPresetConfig apc in ReadPresetsFromDirectory(presetPath)) //{ // if ((from p in presets // where p.Description == apc.Description && p.AgentClassName == apc.AgentClassName // select p).FirstOrDefault() == null) // presets.Add(apc); //} //return presets; }
public void ConfigVarsLoadTest() { MonitorPack m = new MonitorPack(); string mconfig = "<monitorPack version=\"4.0.0\" name=\"Test\" typeName=\"TestType\" enabled=\"True\" " + "defaultNotifier=\"In Memory\" runCorrectiveScripts=\"True\" " + "stateHistorySize=\"100\" pollingFreqSecOverride=\"12\">\r\n" + "<configVars>" + "<configVar find=\"One value\" replace=\"Another value\" />" + "</configVars>" + "<collectorHosts />" + "<notifierHosts />" + "</monitorPack>"; m.LoadXml(mconfig); Assert.IsNotNull(m, "Monitor pack is null"); if (m != null) { Assert.IsNotNull(m.ConfigVariables, "ConfigVariables is null"); if (m.ConfigVariables != null) { Assert.AreEqual(1, m.ConfigVariables.Count, "ConfigVariables count should be 1"); if (m.ConfigVariables.Count == 1) { Assert.AreEqual("One value", m.ConfigVariables[0].FindValue, "ConfigVariable name not set"); Assert.AreEqual("Another value", m.ConfigVariables[0].ReplaceValue, "ConfigVariable value not set"); } } } }
public static List <QuickMonTemplate> GetAllTemplates() { List <QuickMonTemplate> list = new List <QuickMonTemplate>(); string fileContents = System.IO.File.ReadAllText(MonitorPack.GetQuickMonUserDataTemplatesFile()); if (fileContents.Contains("<quickMonTemplate>") && fileContents.Contains("</quickMonTemplate>")) { try { XmlDocument xdoc = new XmlDocument(); xdoc.LoadXml(fileContents); XmlElement root = xdoc.DocumentElement; foreach (XmlNode templateNode in root.SelectNodes("template")) { try { QuickMonTemplate newTemplate = new QuickMonTemplate(); newTemplate.Name = templateNode.ReadXmlElementAttr("name", ""); newTemplate.TemplateType = TemplateTypeConverter.FromText(templateNode.ReadXmlElementAttr("type", "MonitorPack")); newTemplate.ForClass = templateNode.ReadXmlElementAttr("class", ""); newTemplate.Description = templateNode.ReadXmlElementAttr("description", ""); newTemplate.Config = templateNode.InnerXml; list.Add(newTemplate); } catch { } } } catch (Exception ex) { LastError = ex.Message; } } return(list); }
private void EditMonitorPackConfig_Load(object sender, EventArgs e) { if (SelectedMonitorPack == null) { SelectedMonitorPack = new MonitorPack(); } LoadFormControls(); }
public static void SaveTemplates(List <QuickMonTemplate> list) { StringBuilder sb = new StringBuilder(); sb.AppendLine("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); sb.AppendLine("<quickMonTemplate>"); //MonitorPacks foreach (QuickMonTemplate template in (from t in list where t.TemplateType == TemplateType.MonitorPack orderby t.Name select t)) { sb.AppendLine(GetTemplateXmlString(template.Name, "MonitorPack", "MonitorPack", template.Description, template.Config)); } //CollectorHosts foreach (QuickMonTemplate template in (from t in list where t.TemplateType == TemplateType.CollectorHost orderby t.Name select t)) { sb.AppendLine(GetTemplateXmlString(template.Name, "CollectorHost", "CollectorHost", template.Description, template.Config)); } //CollectorAgent foreach (QuickMonTemplate template in (from t in list where t.TemplateType == TemplateType.CollectorAgent orderby t.Name select t)) { sb.AppendLine(GetTemplateXmlString(template.Name, "CollectorAgent", template.ForClass, template.Description, template.Config)); } //NotifierHosts foreach (QuickMonTemplate template in (from t in list where t.TemplateType == TemplateType.NotifierHost orderby t.Name select t)) { sb.AppendLine(GetTemplateXmlString(template.Name, "NotifierHost", "NotifierHost", template.Description, template.Config)); } //NotifierAgents foreach (QuickMonTemplate template in (from t in list where t.TemplateType == TemplateType.NotifierAgent orderby t.Name select t)) { sb.AppendLine(GetTemplateXmlString(template.Name, "NotifierAgent", template.ForClass, template.Description, template.Config)); } sb.AppendLine("</quickMonTemplate>"); if (System.IO.File.Exists(MonitorPack.GetQuickMonUserDataTemplatesFile() + ".bak")) { System.IO.File.SetAttributes(MonitorPack.GetQuickMonUserDataTemplatesFile() + ".bak", System.IO.FileAttributes.Normal); System.IO.File.Delete(MonitorPack.GetQuickMonUserDataTemplatesFile() + ".bak"); } if (System.IO.File.Exists(MonitorPack.GetQuickMonUserDataTemplatesFile())) { System.IO.File.Move(MonitorPack.GetQuickMonUserDataTemplatesFile(), MonitorPack.GetQuickMonUserDataTemplatesFile() + ".bak"); } System.IO.File.WriteAllText(MonitorPack.GetQuickMonUserDataTemplatesFile(), sb.ToString().BeautifyXML()); }
public static void ResetTemplates() { string path = MonitorPack.GetQuickMonUserDataTemplatesFile(); if (!System.IO.Directory.Exists(System.IO.Path.GetDirectoryName(path))) { System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(path)); } System.IO.File.WriteAllText(path, Properties.Resources.QuickMon5DefaultTemplate); }
private void cmdTest_Click(object sender, EventArgs e) { string configXml = txtConfig.Text; //"<monitorPack version=\"4.0.0\" name=\"Test\" typeName=\"TestType\" enabled=\"True\" " + // "defaultNotifier=\"Default notifiers\" runCorrectiveScripts=\"True\" " + // "stateHistorySize=\"100\" pollingFreqSecOverride=\"12\">\r\n" + // "<configVars />\r\n" + // "<collectorHosts>\r\n"; //configXml += txtConfig.Text; //configXml += "</collectorHosts>" + // "<notifierHosts>\r\n" + // "<notifierHost name=\"AudioNotifier\" enabled=\"True\" alertLevel=\"Warning\" detailLevel=\"Detail\" " + // "attendedOptionOverride=\"OnlyAttended\">\r\n" + // "<notifierAgents>\r\n" + // "<notifierAgent type=\"AudioNotifier\">\r\n" + // "<config>\r\n" + // "<audioConfig>\r\n" + // "<goodState enabled=\"false\" useSystemSounds=\"true\" soundPath=\"\" systemSound=\"1\" soundRepeatCount=\"1\" soundVolumePerc=\"-1\" />\r\n" + // "<warningState enabled=\"true\" useSystemSounds=\"true\" soundPath=\"\" systemSound=\"3\" soundRepeatCount=\"1\" soundVolumePerc=\"-1\" />\r\n" + // "<errorState enabled=\"true\" useSystemSounds=\"true\" soundPath=\"\" systemSound=\"2\" soundRepeatCount=\"1\" soundVolumePerc=\"-1\" />\r\n" + // "</audioConfig>\r\n" + // "</config>\r\n" + // "</notifierAgent>\r\n" + // "</notifierAgents>\r\n" + // "</notifierHost>\r\n" + // "</notifierHosts>\r\n" + // "</monitorPack>"; MonitorPack m = new MonitorPack(); m.LoadXml(configXml); m.RefreshStates(); StringBuilder sb = new StringBuilder(); sb.AppendLine(string.Format("Global state: {0}", m.CurrentState)); sb.AppendLine(new string('*', 30)); foreach (CollectorHost ch in m.CollectorHosts) { MonitorState ms = ch.CurrentState; sb.AppendLine(string.Format("Collector host: {0}", ch.Name)); sb.AppendLine(string.Format("Time: {0}", ms.Timestamp.ToString("yyyy-MM-dd HH:mm:ss"))); sb.AppendLine(string.Format("Duration: {0}ms", ms.CallDurationMS)); sb.AppendLine(string.Format("Run on host: {0}", ms.ExecutedOnHostComputer)); sb.AppendLine(string.Format("State: {0}", ms.State)); sb.AppendLine("DETAILS (agents)"); sb.AppendLine(string.Format("{0}", XmlFormattingUtils.NormalizeXML(ms.ReadAllRawDetails()))); //sb.AppendLine(string.Format("\t\tState: {0}\r\n{1}", ms.State, XmlFormattingUtils.NormalizeXML(ms.ReadAllRawDetails('\t', 3)))); sb.AppendLine(new string('*', 30)); } MessageBox.Show(sb.ToString(), "Result", MessageBoxButtons.OK, MessageBoxIcon.Information); }
public void CreateBlankMonitorPack() { try { MonitorPack m = new MonitorPack(); Assert.IsNotNull(m, "Success"); } catch (Exception ex) { Assert.Fail("Could not create monitorpack:" + ex.ToString()); } }
//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); } }
public MonitorState GetState(CollectorEntryRequest entry) { MonitorState monitorState = new MonitorState(); StringBuilder plainTextDetails = new StringBuilder(); StringBuilder htmlTextTextDetails = new StringBuilder(); Console.WriteLine("{0}: Running collector: {1}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), entry.Name); try { string tempMonitorPack = "<monitorPack version=\"3.0.0.0\" name=\"\" enabled=\"True\" defaultViewerNotifier=\"\" runCorrectiveScripts=\"False\"><collectorEntries>" + entry.ToConfig() + "</collectorEntries><notifierEntries></notifierEntries></monitorPack>"; MonitorPack m = new MonitorPack(); m.LoadXml(tempMonitorPack); monitorState.State = m.RefreshStates(); //there is only one...Collector CollectorEntry ce = (from c in m.Collectors select c).FirstOrDefault(); if (ce != null) //Just is case it is null { plainTextDetails.AppendLine(string.Format("Collector: {0}, State: {1}", ce.Name, ce.CurrentState.State)); htmlTextTextDetails.AppendLine(string.Format("<p>Collector: {0}, State: {1}</p>", ce.Name, ce.CurrentState.State)); if (ce.CurrentState.RawDetails != null && ce.CurrentState.RawDetails.Length > 0) { plainTextDetails.AppendLine(string.Format(" Details: {0}", ce.CurrentState.RawDetails.Trim('\r', '\n').Replace("\t", " "))); } if (ce.CurrentState.HtmlDetails != null && ce.CurrentState.HtmlDetails.Length > 0) { htmlTextTextDetails.AppendLine(string.Format("<blockquote>Details: {0}</blockquote>", ce.CurrentState.HtmlDetails)); } } else { plainTextDetails.AppendLine(string.Format("Collector: {0}, State: N/A", ce.Name)); htmlTextTextDetails.AppendLine(string.Format("<p><b>Collector</b>: {0}, State: N/A</p>", ce.Name)); } monitorState.ExecutedOnHostComputer = System.Net.Dns.GetHostName(); monitorState.RawDetails = plainTextDetails.ToString(); monitorState.HtmlDetails = htmlTextTextDetails.ToString(); Console.WriteLine(" State : {0}", monitorState.State); Console.WriteLine(" Details : {0}", monitorState.RawDetails); } catch (Exception ex) { Console.WriteLine(" Error: {0}", ex); monitorState.State = CollectorState.Error; monitorState.RawDetails = ex.ToString(); } return(monitorState); }
private void MonitorPackEditor_Load(object sender, EventArgs e) { panelGeneralSettingsHeight = panelGeneralSettings.Height; panelAgentSettingsHeight = panelAgentSettings.Height; panelVariablesHeight = panelVariables.Height; panelSecuritySettingsHeight = panelSecuritySettings.Height; panelLoggingSettingsHeight = panelLoggingSettings.Height; if (SelectedMonitorPack == null) { SelectedMonitorPack = new MonitorPack(); } LoadFormControls(); this.Size = new Size(600, 450); }
public static void SaveAllPresetsToFile(List <AgentPresetConfig> list) { SavePresetsToFile(MonitorPack.GetQuickMonUserDataTemplatesFile(), list); //string progDataPath = MonitorPack.GetQuickMonUserDataDirectory(); // System.IO.Path.Combine(System.Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Hen IT\\QuickMon 3"); //foreach(string agentClass in (from ps in list // group ps by ps.AgentClassName.ToLower() into g // select g.Key)) //{ // string presetFilePath = System.IO.Path.Combine(progDataPath, agentClass + ".qps"); // SavePresetsToFile(presetFilePath, (from presetsByAgentType in list // where presetsByAgentType.AgentClassName.ToLower() == agentClass.ToLower() // select presetsByAgentType).ToList()); //} }
private void button1_Click(object sender, EventArgs e) { string configXml = txtConfig.Text; MonitorPack m = new MonitorPack(); m.LoadXml(configXml); if (m.CollectorHosts.Count > 0) { EditCollectorHost editCollectorHost = new EditCollectorHost(); editCollectorHost.SelectedConfig = m.CollectorHosts[0].ToXml(); if (editCollectorHost.ShowDialog() == System.Windows.Forms.DialogResult.OK) { m.CollectorHosts[0] = CollectorHost.FromXml(XmlFormattingUtils.NormalizeXML(editCollectorHost.SelectedConfig), null, false); txtConfig.Text = m.ToXml(); } } }
private void MonitorPackEditor_Load(object sender, EventArgs e) { panelGeneralSettingsHeight = panelGeneralSettings.Height; panelAgentSettingsHeight = panelAgentSettings.Height; panelVariablesHeight = panelVariables.Height; panelSecuritySettingsHeight = panelSecuritySettings.Height; panelLoggingSettingsHeight = panelLoggingSettings.Height; if (SelectedMonitorPack == null) { SelectedMonitorPack = new MonitorPack(); } LoadFormControls(); lvwConfigVars.AutoResizeColumnEnabled = true; llblRawEdit.Visible = Properties.Settings.Default.EnableRawEditing; this.Size = new Size(600, 450); }
public static NotifierEntry CreateAndEditNewNotifier(MonitorPack monitorPack) { NotifierEntry newNotifierEntry = CreateNewNotifier(); if (newNotifierEntry != null) { Management.EditNotifierEntry editNotifierEntry = new Management.EditNotifierEntry(); editNotifierEntry.SelectedEntry = newNotifierEntry; editNotifierEntry.LaunchAddEntry = LastLaunchAddEntryOption; editNotifierEntry.ShowRawEditOnStart = LastShowRawEditOnStartOption; if (editNotifierEntry.ShowDialog(monitorPack) != System.Windows.Forms.DialogResult.OK) { newNotifierEntry = null; } } return(newNotifierEntry); }
public static CollectorEntry CreateAndEditNewCollector(MonitorPack monitorPack, CollectorEntry parentCollectorEntry = null) { CollectorEntry newCollectorEntry = CreateNewCollector(parentCollectorEntry); if (newCollectorEntry != null) { QuickMon.Forms.EditCollectorConfig editCollectorEntry = new Forms.EditCollectorConfig(); editCollectorEntry.SelectedEntry = newCollectorEntry; editCollectorEntry.KnownRemoteHosts = KnownRemoteHosts; editCollectorEntry.LaunchAddEntry = LastLaunchAddEntryOption; editCollectorEntry.ShowRawEditOnStart = LastShowRawEditOnStartOption; if (editCollectorEntry.ShowDialog(monitorPack) != System.Windows.Forms.DialogResult.OK) { newCollectorEntry = null; } } return(newCollectorEntry); }
static void Main(string[] args) { if (Properties.Settings.Default.NewVersion) { Properties.Settings.Default.Upgrade(); Properties.Settings.Default.NewVersion = false; Properties.Settings.Default.Save(); } if (Properties.Settings.Default.RecentQMConfigFiles == null) { Properties.Settings.Default.RecentQMConfigFiles = new System.Collections.Specialized.StringCollection(); } if (Properties.Settings.Default.KnownRemoteHosts == null) { Properties.Settings.Default.KnownRemoteHosts = new System.Collections.Specialized.StringCollection(); } Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); //Copy installed presets to user's application data directory try { if (!System.IO.File.Exists(MonitorPack.GetQuickMonUserDataTemplatesFile())) { string commonAppData = System.IO.Path.Combine(System.Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Hen IT\\QuickMon 3"); List <AgentPresetConfig> presets = AgentPresetConfig.ReadPresetsFromDirectory(commonAppData); AgentPresetConfig.SaveAllPresetsToFile(presets); } } catch { } //if application is launched with qmconfig file set it as last Monitor pack if (args.Length > 0 && System.IO.File.Exists(args[0]) && (args[0].ToLower().EndsWith(".qmconfig") || args[0].ToLower().EndsWith(".qmp"))) { Properties.Settings.Default.LastMonitorPack = args[0]; } Application.Run(new MainForm()); }
private void RefreshMonitorPack(object o) { MonitorPack m = (MonitorPack)o; m.RefreshStates(); this.Invoke((MethodInvoker) delegate { WaitingPictureBox.SendToBack(); foreach (CollectorHost ch in m.CollectorHosts) { MonitorState ms = ch.CurrentState; txtAlerts.Text += string.Format("Collector host: {0}\r\n", ch.Name); txtAlerts.Text += string.Format("Time: {0}\r\n", ms.Timestamp.ToString("yyyy-MM-dd HH:mm:ss")); txtAlerts.Text += string.Format("Duration: {0}ms\r\n", ms.CallDurationMS); txtAlerts.Text += string.Format("Run on host: {0}\r\n", ms.ExecutedOnHostComputer); txtAlerts.Text += string.Format("State: {0}\r\n{1}\r\n", ms.State, XmlFormattingUtils.NormalizeXML(ms.ReadAllRawDetails('\t'))); } }); }
private void AddAndStartMonitorPack(string monitorPackPath) { try { StringBuilder sbNotifiers = new StringBuilder(); MonitorPack monitorPack = new MonitorPack(); EventLog.WriteEntry(Globals.ServiceEventSourceName, string.Format("Starting QuickMon MonitorPack '{0}'", monitorPackPath), EventLogEntryType.Information, (int)QuickMonServiceEventIDs.MonitorPack); monitorPack.Load(monitorPackPath); monitorPack.ApplicationUserNameCacheMasterKey = Properties.Settings.Default.ApplicationMasterKey; monitorPack.ApplicationUserNameCacheFilePath = Properties.Settings.Default.ApplicationUserNameCacheFilePath; monitorPack.CollectorStateHistorySize = 0; //For service history is always disabled!! if (monitorPack.NotifierHosts != null && monitorPack.NotifierHosts.Count > 0) { foreach (var notifier in monitorPack.NotifierHosts) { sbNotifiers.AppendLine("\t" + notifier.Name); } } EventLog.WriteEntry(Globals.ServiceEventSourceName, string.Format("MonitorPack '{0}' has the following notifiers\r\n{1}", monitorPack.Name, sbNotifiers.ToString()), EventLogEntryType.Information, (int)QuickMonServiceEventIDs.MonitorPack); monitorPack.OnNotifierError += new NotifierHostWithMessageDelegate(monitorPack_NotifierError); monitorPack.OnCollectorError += new CollectorHostWithMessageDelegate(monitorPack_RaiseCollectorError); monitorPack.CollectorHostAllAgentsExecutionTime += new CollectorHostExecutionTimeDelegate(monitorPack_CollectorHostAllAgentsExecutionTime); monitorPack.CollectorHostRestorationScriptExecuted += MonitorPack_CollectorHostRestorationScriptExecuted; monitorPack.CollectorHostRestorationScriptFailed += MonitorPack_CollectorHostRestorationScriptFailed; monitorPack.CollectorHostWarningCorrectiveScriptExecuted += MonitorPack_CollectorHostWarningCorrectiveScriptExecuted; monitorPack.CollectorHostWarningCorrectiveScriptFailed += MonitorPack_CollectorHostWarningCorrectiveScriptFailed; monitorPack.CollectorHostErrorCorrectiveScriptExecuted += MonitorPack_CollectorHostErrorCorrectiveScriptExecuted; monitorPack.CollectorHostErrorCorrectiveScriptFailed += MonitorPack_CollectorHostErrorCorrectiveScriptFailed; monitorPack.MonitorPackEventReported += monitorPack_MonitorPackEventReported; monitorPack.PollingFreq = Properties.Settings.Default.PollingFreqSec * 1000; monitorPack.ConcurrencyLevel = concurrencyLevel; monitorPack.RunningAttended = AttendedOption.OnlyUnAttended; packs.Add(monitorPack); monitorPack.StartPolling(); PCSetMonitorPacksLoaded(packs.Count); } catch (Exception ex) { EventLog.WriteEntry(Globals.ServiceEventSourceName, string.Format("Error loading/starting MonitorPack '{0}'\r\n{1}", monitorPackPath, ex.Message), EventLogEntryType.Error, (int)QuickMonServiceEventIDs.MonitorPack); } }
private void llblRawEdit_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { try { if (ValidateInput()) { SelectedMonitorPack.Name = txtName.Text; SelectedMonitorPack.TypeName = txtType.Text; SelectedMonitorPack.RunCorrectiveScripts = chkCorrectiveScripts.Checked; SelectedMonitorPack.Enabled = chkEnabled.Checked; SelectedMonitorPack.CollectorStateHistorySize = (int)collectorStateHistorySizeNumericUpDown.Value; SelectedMonitorPack.PollingFrequencyOverrideSec = (int)freqSecNumericUpDown.Value; //if (cboDefaultNotifier.SelectedIndex > -1) // SelectedMonitorPack.DefaultViewerNotifier = (NotifierHost)cboDefaultNotifier.SelectedItem; //else // SelectedMonitorPack.DefaultViewerNotifier = null; SelectedMonitorPack.ConfigVariables = new List <ConfigVariable>(); foreach (ListViewItem lvi in lvwConfigVars.Items) { SelectedMonitorPack.ConfigVariables.Add(((ConfigVariable)lvi.Tag).Clone()); } RAWXmlEditor editor = new RAWXmlEditor(); string oldMarkUp = SelectedMonitorPack.ToXml(); editor.SelectedMarkup = oldMarkUp; if (editor.ShowDialog() == System.Windows.Forms.DialogResult.OK) { TriggerMonitorPackReload = true; MonitorPack newMP = new MonitorPack(); newMP.LoadXml(editor.SelectedMarkup); newMP.MonitorPackPath = SelectedMonitorPack.MonitorPackPath; SelectedMonitorPack = null; SelectedMonitorPack = newMP; LoadFormControls(); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public void LoadBlankMonitorPack() { MonitorPack m = new MonitorPack(); string mconfig = "<monitorPack version=\"4.0.0\" name=\"Test\" typeName=\"TestType\" enabled=\"True\" " + "defaultNotifier=\"In Memory\" runCorrectiveScripts=\"True\" " + "stateHistorySize=\"100\" pollingFreqSecOverride=\"12\">\r\n" + "<configVars />" + "<collectorHosts />" + "<notifierHosts />" + "</monitorPack>"; m.LoadXml(mconfig); Assert.IsNotNull(m, "Monitor pack is null"); if (m != null) { Assert.AreEqual("Test", m.Name, "Name is not set"); Assert.AreEqual("4.0.0", m.Version, "Version is not set"); Assert.AreEqual("TestType", m.TypeName, "Type is not set"); Assert.AreEqual("true", m.Enabled.ToString().ToLower(), "Enabled is not set"); Assert.AreEqual("true", m.RunCorrectiveScripts.ToString().ToLower(), "runCorrectiveScripts is not set"); Assert.AreEqual(100, m.CollectorStateHistorySize, string.Format("CollectorStateHistorySize is not set: {0}", m.CollectorStateHistorySize)); Assert.AreEqual(12, m.PollingFrequencyOverrideSec, string.Format("PollingFrequencyOverrideSec is not set: {0}", m.PollingFrequencyOverrideSec)); Assert.IsNotNull(m.ConfigVariables, "ConfigVariables is null"); if (m.ConfigVariables != null) { Assert.AreEqual(0, m.ConfigVariables.Count, "ConfigVariables count should be 0"); } Assert.IsNotNull(m.CollectorHosts, "CollectorHosts is null"); if (m.CollectorHosts != null) { Assert.AreEqual(0, m.CollectorHosts.Count, "CollectorHosts count should be 0"); } Assert.IsNotNull(m.NotifierHosts, "NotifierHosts is null"); if (m.NotifierHosts != null) { Assert.AreEqual(0, m.NotifierHosts.Count, "NotifierHosts count should be 0"); } } }
static void Main(string[] args) { if (Properties.Settings.Default.NewVersion) { Properties.Settings.Default.Upgrade(); Properties.Settings.Default.NewVersion = false; Properties.Settings.Default.Save(); } MonitorPack monitorPack = new MonitorPack(); if (args.Length > 0 && args[0].ToLower().EndsWith(".qmconfig")) { if (File.Exists(args[0])) { monitorPack.Load(args[0]); } } else { if (Properties.Settings.Default.LastMonitorPackPath != null && File.Exists(Properties.Settings.Default.LastMonitorPackPath)) { monitorPack.Load(Properties.Settings.Default.LastMonitorPackPath); } } Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Management.MonitorPackManagement monitorPackManagement = new Management.MonitorPackManagement(); if (monitorPackManagement.ShowMonitorPack(monitorPack) == DialogResult.OK) { Properties.Settings.Default.LastMonitorPackPath = monitorPackManagement.MonitorPackPath; Properties.Settings.Default.Save(); } }
static void Main(string[] args) { Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException); AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; if (Properties.Settings.Default.NewVersion) { Properties.Settings.Default.Upgrade(); Properties.Settings.Default.NewVersion = false; Properties.Settings.Default.Save(); } if (Properties.Settings.Default.ApplicationMasterKey == null || Properties.Settings.Default.ApplicationMasterKey == "") { Properties.Settings.Default.ApplicationMasterKey = "QuickMon-" + System.Net.Dns.GetHostName(); } if (Properties.Settings.Default.ApplicationUserNameCacheFilePath == null || Properties.Settings.Default.ApplicationUserNameCacheFilePath == "") { Properties.Settings.Default.ApplicationUserNameCacheFilePath = System.IO.Path.Combine(MonitorPack.GetQuickMonUserDataDirectory(), "QM5MasterKeys.qmmxml"); } if (Properties.Settings.Default.ApplicationUserNameCache == null) { Properties.Settings.Default.ApplicationUserNameCache = new System.Collections.Specialized.StringCollection(); } if (Properties.Settings.Default.RecentQMConfigFiles == null) { Properties.Settings.Default.RecentQMConfigFiles = new System.Collections.Specialized.StringCollection(); } if (Properties.Settings.Default.KnownRemoteHosts == null) { Properties.Settings.Default.KnownRemoteHosts = new System.Collections.Specialized.StringCollection(); } try { if (HenIT.Security.AdminModeTools.IsInAdminMode()) { if (Properties.Settings.Default.DisableAutoAdminMode) { HenIT.Security.AdminModeTools.DeleteAdminLaunchTask(AppGlobals.AppTaskId); } else { HenIT.Security.AdminModeTools.CreateAdminLaunchTask(AppGlobals.AppTaskId); } } } catch { } Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); if (args.Length > 0 && args[0].ToLower().Contains(".qmp")) { string qmpFile = args[0]; if (System.IO.File.Exists(qmpFile)) { Properties.Settings.Default.LastMonitorPack = qmpFile; } } try { if (!System.IO.File.Exists(MonitorPack.GetQuickMonUserDataTemplatesFile())) { try { QuickMonTemplate.ResetTemplates(); } catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex.ToString()); } } } catch (Exception ex) { System.Windows.Forms.MessageBox.Show(ex.Message, "Templates", MessageBoxButtons.OK, MessageBoxIcon.Error); } if (!System.IO.Directory.Exists(Properties.Settings.Default.ScriptRepositoryDirectory)) { try { System.IO.Directory.CreateDirectory(Properties.Settings.Default.ScriptRepositoryDirectory); } catch { } } MainForm mainForm = new MainForm(); Application.Run(mainForm); }
public static string GetQuickMonUserDataTemplatesFile() { return(System.IO.Path.Combine(MonitorPack.GetQuickMonUserDataDirectory(), "Templates", "QuickMon5Templates.qmtemplate")); }
private void LoadMonitorPack(string monitorPackPath) { if (System.IO.File.Exists(monitorPackPath)) { mainRefreshTimer.Enabled = false; try { monitorPack.RaiseCurrentState -= new RaiseCurrentStateDelegate(monitorPack_RaiseCurrentState); monitorPack.RaiseNotifierError -= new RaiseNotifierErrorDelegare(monitorPack_RaiseNotifierError); monitorPack.CollectorCalled -= new RaiseCollectorCalledDelegate(monitorPack_CollectorCalled); monitorPack.CollectorExecutionTimeEvent -= new CollectorExecutionTimeDelegate(monitorPack_CollectorExecutionTimeEvent); monitorPack.ClosePerformanceCounters(); monitorPack = null; } catch { } TreeNode root = tvwCollectors.Nodes[0]; root.Nodes.Clear(); monitorPack = new MonitorPack(); monitorPack.Load(monitorPackPath); monitorPack.ConcurrencyLevel = Properties.Settings.Default.ConcurrencyLevel; if (monitorPack.AgentLoadingErrors != null && monitorPack.AgentLoadingErrors.Length > 0) { MessageBox.Show(monitorPack.AgentLoadingErrors, "Loading errors", MessageBoxButtons.OK, MessageBoxIcon.Error); } SetEnableDisablePolling(); List <CollectorEntry> noDependantCollectors = (from c in monitorPack.Collectors where c.ParentCollectorId.Length == 0 select c).ToList(); foreach (CollectorEntry collector in noDependantCollectors) { LoadCollectorNode(root, collector); } root.Expand(); monitorPack.RaiseCurrentState += new RaiseCurrentStateDelegate(monitorPack_RaiseCurrentState); monitorPack.RaiseNotifierError += new RaiseNotifierErrorDelegare(monitorPack_RaiseNotifierError); monitorPack.CollectorCalled += new RaiseCollectorCalledDelegate(monitorPack_CollectorCalled); monitorPack.CollectorExecutionTimeEvent += new CollectorExecutionTimeDelegate(monitorPack_CollectorExecutionTimeEvent); monitorPack.RunCollectorCorrectiveWarningScript += new RaiseCollectorCalledDelegate(monitorPack_RunCollectorCorrectiveWarningScript); monitorPack.RunCollectorCorrectiveErrorScript += new RaiseCollectorCalledDelegate(monitorPack_RunCollectorCorrectiveErrorScript); monitorPack.MonitorPackPathChanged += new MonitorPackPathChangedDelegate(monitorPack_MonitorPackPathChanged); globalState = MonitorStates.NotAvailable; UpdateAppTitle(); try { defaultNotifierViewerToolStripMenuItem.Enabled = false; if (monitorPack != null) { toolStripStatusLabelStatus.Text = string.Format("{0} collectors, {1} notifiers", monitorPack.Collectors.Count, monitorPack.Notifiers.Count); defaultNotifierViewerToolStripMenuItem.Enabled = monitorPack.DefaultViewerNotifier != null; } } catch { } tvwCollectors.SelectedNode = root; root.EnsureVisible(); AddMonitorPackFileToRecentList(monitorPackPath); mainRefreshTimer.Enabled = true; } }
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); }
static void Main(string[] args) { bool useBackgroundPolling = false; bool showManagement = false; bool reportOnlyStates = true; string currentPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); string registeredAgentsPath = currentPath;// +@"\RegisteredAgents.qmral"; string pingAgentAssembly = currentPath + @"\QMPing.dll"; string fileCountAgentAssembly = currentPath + @"\QMFileCount.dll"; string serviceStateAgentAssembly = currentPath + @"\QMServiceState.dll"; string bizTalkSuspendedCountAgentAssembly = currentPath + @"\QMBizTalkSuspendedCount.dll"; string logFileAgentAssembly = currentPath + @"\QMLogFile.dll"; string configurationFile = currentPath + @"\workConfig.qmconfig"; MonitorPack monitorPack = new MonitorPack(); #region Agent registrations try { monitorPack.AgentsAssemblyPath = registeredAgentsPath; } catch { monitorPack.AgentRegistrations = new List <AgentRegistration>(); monitorPack.AgentRegistrations.AddRange(new AgentRegistration[] { new AgentRegistration() { Name = "Ping", AssemblyPath = pingAgentAssembly, ClassName = "QuickMon.Ping", IsCollector = true, IsNotifier = false }, new AgentRegistration() { Name = "FileCount", AssemblyPath = fileCountAgentAssembly, ClassName = "QuickMon.FileCount", IsCollector = true, IsNotifier = false }, new AgentRegistration() { Name = "ServiceState", AssemblyPath = serviceStateAgentAssembly, ClassName = "QuickMon.ServiceState", IsCollector = true, IsNotifier = false }, new AgentRegistration() { Name = "BizTalkSuspendedCount", AssemblyPath = bizTalkSuspendedCountAgentAssembly, ClassName = "QuickMon.BizTalkSuspendedCount", IsCollector = true, IsNotifier = false }, new AgentRegistration() { Name = "LogFile", AssemblyPath = logFileAgentAssembly, ClassName = "QuickMon.LogFile", IsCollector = false, IsNotifier = true } } ); //SerializationUtils.SerializeXMLToFile<List<AgentRegistration>>(registeredAgentsFile, monitorPack.AgentRegistrations); } #endregion monitorPack.Load(configurationFile); if (useBackgroundPolling) { //monitorPack.RaiseAlert += new RaiseAlertDelegate(monitorPack_RaiseAlert); monitorPack.PollingFreq = 10000; monitorPack.StartPolling(); Console.WriteLine("Press any key to stop polling"); Console.ReadKey(); monitorPack.IsPolling = false; Console.WriteLine("Done"); } else if (showManagement) { Management.MonitorPackManagement monitorPackManagement = new Management.MonitorPackManagement(); monitorPackManagement.ShowMonitorPack(monitorPack); } else if (reportOnlyStates) { ConsoleKeyInfo cki = new ConsoleKeyInfo(' ', ConsoleKey.Spacebar, false, false, false); monitorPack.RaiseCurrentState += new RaiseCurrentStateDelegate(monitorPack_RaiseCurrentState); while (cki.Key != ConsoleKey.Escape) { Console.WriteLine(new string('-', 79)); MonitorStates globalState = monitorPack.RefreshStates(); Console.WriteLine("Global state: {0}", globalState); Console.WriteLine("Last time: {0}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); Console.WriteLine(new string('-', 79)); Console.WriteLine("Press ESC to end"); cki = ConsoleHelper.ReadKeyWithTimeOut(20000); } } else { //monitorPack.RaiseAlert += new RaiseAlertDelegate(monitorPack_RaiseAlert); MonitorStates globalState = monitorPack.RefreshStates(); Console.WriteLine(new string('-', 79)); Console.WriteLine(string.Format("Current global state: {0}", globalState)); string level = " "; foreach (CollectorEntry ce in (from c in monitorPack.Collectors where c.ParentCollectorId.Length == 0 select c)) { ShowCollectorEntryStatus(monitorPack.Collectors, ce, level); } Console.WriteLine("Press any key to continue or wait 30 seconds"); ConsoleKeyInfo cki = ConsoleHelper.ReadKeyWithTimeOut(30000); if (cki.Key == ConsoleKey.S) { monitorPack.Save(currentPath + @"\Test.qmconfig"); } } }