Example #1
0
 private void RAWXmlEditor_Load(object sender, EventArgs e)
 {
     if (SelectedMarkup != null && SelectedMarkup.Length > 0)
     {
         txtConfig.Text = XmlFormattingUtils.NormalizeXML(SelectedMarkup);
     }
 }
Example #2
0
        public static void SavePresetsToFile(string filePath, List <AgentPresetConfig> list)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
            sb.AppendLine("<qmpresets>");
            foreach (AgentPresetConfig preset in list)
            {
                try
                {
                    sb.Append("<preset ");
                    sb.Append("class=\"" + XmlFormattingUtils.EscapeXml(preset.AgentClassName) + "\" ");
                    sb.Append("description=\"" + XmlFormattingUtils.EscapeXml(preset.Description) + "\"");
                    sb.AppendLine(">");

                    //assumption is made that <config> is valid xml
                    sb.AppendLine(preset.Config);

                    sb.AppendLine("</preset>");
                }
                catch (Exception nodeEx)
                {
                    System.Diagnostics.Trace.WriteLine("Error write preset: " + preset.ToString() + "\r\n" + nodeEx.ToString());
                }
            }
            sb.AppendLine("</qmpresets>");

            System.IO.File.WriteAllText(filePath, sb.ToString(), Encoding.UTF8);
        }
Example #3
0
        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);
        }
Example #4
0
        public string ToXml()
        {
            XmlDocument outDoc = new XmlDocument();

            outDoc.LoadXml(emptyConfig);
            XmlElement root = outDoc.DocumentElement;

            root.SetAttributeValue("version", System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString());
            root.SetAttributeValue("name", Name);
            root.SetAttributeValue("typeName", TypeName);
            root.SetAttributeValue("enabled", Enabled);
            root.SetAttributeValue("runCorrectiveScripts", RunCorrectiveScripts);
            root.SetAttributeValue("stateHistorySize", CollectorStateHistorySize);
            root.SetAttributeValue("pollingFreqSecOverride", PollingFrequencyOverrideSec);

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

            root.SelectSingleNode("configVars").InnerXml     = GetConfigVarXml();
            root.SelectSingleNode("collectorHosts").InnerXml = GetConfigForCollectors();
            root.SelectSingleNode("notifierHosts").InnerXml  = GetConfigForNotifiers();

            #region Logging
            XmlNode loggingNode = root.SelectSingleNode("logging");
            loggingNode.SetAttributeValue("loggingPath", LoggingPath);
            loggingNode.SetAttributeValue("loggingCollectorEvents", LoggingCollectorEvents);
            loggingNode.SetAttributeValue("loggingNotifierEvents", LoggingNotifierEvents);
            loggingNode.SetAttributeValue("loggingAlertsRaised", LoggingAlertsRaised);
            loggingNode.SetAttributeValue("loggingCorrectiveScriptRun", LoggingCorrectiveScriptRun);
            loggingNode.SetAttributeValue("loggingPollingOverridesTriggered", LoggingPollingOverridesTriggered);
            loggingNode.SetAttributeValue("loggingServiceWindowEvents", LoggingServiceWindowEvents);
            loggingNode.SetAttributeValue("loggingKeepLogFilesXDays", LoggingKeepLogFilesXDays);
            XmlNode loggingCollectorCategoriesNode = loggingNode.SelectSingleNode("collectorCategories");
            foreach (string s in LoggingCollectorCategories)
            {
                XmlNode category = outDoc.CreateElement("category");
                category.InnerText = s;
                loggingCollectorCategoriesNode.AppendChild(category);
            }
            #endregion

            //outDoc.PreserveWhitespace = false;
            //outDoc.Normalize();
            return(XmlFormattingUtils.NormalizeXML(outDoc.OuterXml));
        }
Example #5
0
        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();
                }
            }
        }
Example #6
0
        public string ToXml()
        {
            XmlDocument outDoc = new XmlDocument();

            outDoc.LoadXml(emptyConfig);
            XmlElement root = outDoc.DocumentElement;

            root.SetAttributeValue("version", System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString());
            root.SetAttributeValue("name", Name);
            LastChangeDate = DateTime.Now;
            root.SetAttributeValue("lastChanged", LastChangeDate.ToString("yyyy-MM-dd HH:mm:ss"));
            root.SetAttributeValue("typeName", TypeName);
            root.SetAttributeValue("enabled", Enabled);

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

            root.SelectSingleNode("configVars").InnerXml = GetConfigVarXml();

            XmlNode collectorHostsNode = root.SelectSingleNode("collectorHosts");
            collectorHostsNode.SetAttributeValue("runCorrectiveScripts", CorrectiveScriptsEnabled);
            collectorHostsNode.SetAttributeValue("stateHistorySize", CollectorStateHistorySize);
            collectorHostsNode.SetAttributeValue("pollingFreqSecOverride", PollingFrequencyOverrideSec);
            XmlNode actionScriptsNode = collectorHostsNode.SelectSingleNode("actionScripts");

            //foreach (ActionScript ascr in ActionScripts)
            //{
            //    XmlNode scriptParameterNode = outDoc.ImportNode(ascr.ToXmlNode(), true);
            //    actionScriptsNode.AppendChild(scriptParameterNode);
            //}

            foreach (CollectorHost collectorHost in CollectorHosts)
            {
                XmlNode collectorHostNode = outDoc.ImportNode(collectorHost.ToXmlNode(), true);
                collectorHostsNode.AppendChild(collectorHostNode);
            }
            XmlNode notifierHostsNode = root.SelectSingleNode("notifierHosts");

            foreach (NotifierHost notifierHost in NotifierHosts)
            {
                XmlNode notifierHostNode = outDoc.ImportNode(notifierHost.ToXmlNode(), true);
                notifierHostsNode.AppendChild(notifierHostNode);
            }

            #region Logging
            XmlNode loggingNode = root.SelectSingleNode("logging");
            loggingNode.SetAttributeValue("enabled", LoggingEnabled);
            loggingNode.SetAttributeValue("loggingPath", LoggingPath);
            loggingNode.SetAttributeValue("loggingCollectorEvents", LoggingCollectorEvents);
            loggingNode.SetAttributeValue("loggingNotifierEvents", LoggingNotifierEvents);
            loggingNode.SetAttributeValue("loggingAlertsRaised", LoggingAlertsRaised);
            loggingNode.SetAttributeValue("loggingCorrectiveScriptRun", LoggingCorrectiveScriptRun);
            loggingNode.SetAttributeValue("loggingPollingOverridesTriggered", LoggingPollingOverridesTriggered);
            loggingNode.SetAttributeValue("loggingServiceWindowEvents", LoggingServiceWindowEvents);
            loggingNode.SetAttributeValue("loggingKeepLogFilesXDays", LoggingKeepLogFilesXDays);
            XmlNode loggingCollectorCategoriesNode = loggingNode.SelectSingleNode("collectorCategories");
            foreach (string s in LoggingCollectorCategories)
            {
                XmlNode category = outDoc.CreateElement("category");
                category.InnerText = s;
                loggingCollectorCategoriesNode.AppendChild(category);
            }
            #endregion

            return(XmlFormattingUtils.NormalizeXML(outDoc.OuterXml));
        }
Example #7
0
 private void formatToolStripMenuItem_Click(object sender, EventArgs e)
 {
     txtConfig.Text = XmlFormattingUtils.NormalizeXML(txtConfig.Text);
 }
Example #8
0
 private void cmdFormat_Click(object sender, EventArgs e)
 {
     txtConfig.Text = XmlFormattingUtils.NormalizeXML(txtConfig.Text);
 }
Example #9
0
        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')));
                }
            });
        }
Example #10
0
        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(), XmlFormattingUtils.NormalizeXML(sb.ToString()));
        }
Example #11
0
        private void cmdRunTest_Click(object sender, EventArgs e)
        {
            string configXml = "<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 += "<collectorHost uniqueId=\"PingNowhere\" name=\"Ping Nowhere\" enabled=\"True\" expandOnStart=\"True\" dependOnParentId=\"\" " +
                         "agentCheckSequence=\"All\" childCheckBehaviour=\"OnlyRunOnSuccess\" " +
                         "enableRemoteExecute=\"False\" " +
                         "forceRemoteExcuteOnChildCollectors=\"False\" remoteAgentHostAddress=\"\" remoteAgentHostPort=\"48181\" " +
                         "blockParentRemoteAgentHostSettings=\"False\" runLocalOnRemoteHostConnectionFailure=\"True\" >\r\n" +
                         "<collectorAgents>\r\n" +
                         "<collectorAgent type=\"PingCollector\">\r\n" +
                         "<config>\r\n" +
                         "<entries>\r\n" +
                         "<entry pingMethod=\"Ping\" address=\"NowhereSpecific\" />\r\n" +
                         (chkLocalhost.Checked ? "<entry pingMethod=\"Ping\" address=\"localhost\" />\r\n" : "") +
                         "</entries>\r\n" +
                         "</config>\r\n" +
                         "</collectorAgent>\r\n" +
                         "</collectorAgents>\r\n" +
                         "</collectorHost>\r\n";

            configXml += "</collectorHosts>" +
                         "<notifierHosts>\r\n";

            if (chkEventLog.Checked)
            {
                configXml += "<notifierHost name=\"EventLogNotifier\" enabled=\"True\" alertLevel=\"Warning\" detailLevel=\"Detail\" " +
                             "attendedOptionOverride=\"OnlyAttended\">\r\n" +
                             "<notifierAgents>\r\n" +
                             "<notifierAgent type=\"EventLogNotifier\">\r\n" +
                             "<config><eventLog computer=\".\" eventSource=\"QuickMon4\" successEventID=\"0\" warningEventID=\"1\" errorEventID=\"2\" /></config>\r\n" +
                             "</notifierAgent>\r\n" +
                             "</notifierAgents>\r\n" +
                             "</notifierHost>\r\n";
            }
            if (chkLogFile.Checked)
            {
                configXml += "<notifierHost name=\"Log file\" enabled=\"True\" alertLevel=\"Info\" detailLevel=\"Detail\" " +
                             "attendedOptionOverride=\"OnlyAttended\">\r\n" +
                             "<notifierAgents>\r\n" +
                             "<notifierAgent type=\"LogFileNotifier\">\r\n" +
                             "<config><logFile path=\"" + txtLogFile.Text + "\" createNewFileSizeKB=\"0\" /></config>\r\n" +
                             "</notifierAgent>\r\n" +
                             "</notifierAgents>\r\n" +
                             "</notifierHost>\r\n";
            }
            if (chkSMTP.Checked)
            {
                configXml += "<notifierHost name=\"Email\" enabled=\"True\" alertLevel=\"Info\" detailLevel=\"Detail\" " +
                             "attendedOptionOverride=\"OnlyAttended\">\r\n" +
                             "<notifierAgents>\r\n" +
                             "<notifierAgent name=\"Email\" type=\"SMTPNotifier\">\r\n" +
                             "<config>\r\n" +
                             "<smtp hostServer=\"" + txtSMTPServer.Text + "\" useDefaultCredentials=\"True\" domain=\"\" userName=\"\" password=\"\" " +
                             "fromAddress=\"" + txtEmailAddress.Text + "\" toAddress=\"" + txtEmailAddress.Text + "\" senderAddress=\"" + txtEmailAddress.Text + "\" replyToAddress=\"" + txtEmailAddress.Text + "\" mailPriority=\"0\" useTLS=\"False\" isBodyHtml=\"True\" port=\"25\" subject=\"QuickMon %AlertLevel% - %CollectorName%\" body=\"QuickMon alert raised for &lt;b&gt;'%CollectorName%'&lt;/b&gt;&lt;br /&gt;&#xD;&#xA;&lt;b&gt;Date Time:&lt;/b&gt; %DateTime%&lt;br /&gt;&#xD;&#xA;&lt;b&gt;Current state:&lt;/b&gt; %CurrentState%&lt;br /&gt;&#xD;&#xA;&lt;b&gt;Agents:&lt;/b&gt; %CollectorAgents%&lt;br /&gt;&#xD;&#xA;&lt;b&gt;Details&lt;/b&gt;&lt;blockquote&gt;%Details%&lt;/blockquote&gt;\" />\r\n" +
                             "</config>\r\n" +
                             "</notifierAgent>\r\n" +
                             "</notifierAgents>\r\n" +
                             "</notifierHost>\r\n";
            }
            if (chkAudio.Checked)
            {
                configXml += "<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=\"2\" soundRepeatCount=\"1\" soundVolumePerc=\"-1\" />\r\n" +
                             "<errorState enabled=\"true\" useSystemSounds=\"true\" soundPath=\"\" systemSound=\"3\" soundRepeatCount=\"1\" soundVolumePerc=\"-1\" />\r\n" +
                             "</audioConfig>\r\n" +
                             "</config>\r\n" +
                             "</notifierAgent>\r\n" +
                             "</notifierAgents>\r\n" +
                             "</notifierHost>\r\n";
            }
            configXml += "</notifierHosts>\r\n" +
                         "</monitorPack>";
            MonitorPack m = new MonitorPack();

            m.ConcurrencyLevel = (int)nudConcurency.Value;
            m.LoadXml(configXml);
            m.RefreshStates();
            txtAlerts.Text = "";
            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')));
                txtAlerts.Text += "Alerts\r\n";
                foreach (string alert in ms.AlertsRaised)
                {
                    txtAlerts.Text += "\t" + alert;
                }
            }
        }