Пример #1
0
        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");
                    }
                }
            }
        }
Пример #2
0
        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);
        }
Пример #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);
        }
Пример #4
0
        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);
        }
Пример #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();
                }
            }
        }
Пример #6
0
 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);
     }
 }
Пример #7
0
        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");
                }
            }
        }
Пример #8
0
        private void cmdRunTest_Click(object sender, EventArgs e)
        {
            if (!chkRemoteHost.Checked || txtHostName.Text.Trim().Length > 0)
            {
                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";
                string[] hostnames = txtHostName.Text.Split(',', ' ');
                foreach (string hostname in hostnames)
                {
                    configXml += "<collectorHost uniqueId=\"Ping" + hostname.EscapeXml() + "\" name=\"Ping " + hostname.EscapeXml() + " tests\" enabled=\"True\" expandOnStart=\"True\" dependOnParentId=\"\" " +
                                 "agentCheckSequence=\"" + (opt1stSuccess.Checked ? "FirstSuccess" : opt1stError.Checked ? "FirstError" : "All") + "\" childCheckBehaviour=\"OnlyRunOnSuccess\" " +
                                 "enableRemoteExecute=\"" + (chkRemoteHost.Checked ? "True" : "False") + "\" " +
                                 "forceRemoteExcuteOnChildCollectors=\"False\" remoteAgentHostAddress=\"" + txtRemoteHost.Text.EscapeXml() + "\" 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=\"" + hostname.EscapeXml() + "\" />\r\n" +
                                 "</entries>\r\n" +
                                 "</config>\r\n" +
                                 "</collectorAgent>\r\n" +
                                 "</collectorAgents>\r\n" +
                                 "</collectorHost>\r\n";

                    if (chkServices.Checked)
                    {
                        configXml += "<collectorHost uniqueId=\"Services" + hostname.EscapeXml() + "\" name=\"Services " + hostname.EscapeXml() + " tests\" enabled=\"True\" expandOnStart=\"True\" dependOnParentId=\"Ping" + hostname.EscapeXml() + "\" " +
                                     "agentCheckSequence=\"" + (opt1stSuccess.Checked ? "FirstSuccess" : opt1stError.Checked ? "FirstError" : "All") + "\" childCheckBehaviour=\"OnlyRunOnSuccess\" " +
                                     "enableRemoteExecute=\"" + (chkRemoteHost.Checked ? "True" : "False") + "\" " +
                                     "forceRemoteExcuteOnChildCollectors=\"True\" remoteAgentHostAddress=\"" + txtRemoteHost.Text.EscapeXml() + "\" remoteAgentHostPort=\"48181\" " +
                                     "blockParentRemoteAgentHostSettings=\"False\" runLocalOnRemoteHostConnectionFailure=\"True\" >\r\n" +
                                     "<collectorAgents>\r\n" +
                                     "<collectorAgent type=\"WindowsServiceStateCollector\">\r\n" +
                                     "<config>\r\n" +
                                     "<machine name=\"" + hostname.EscapeXml() + "\">\r\n" +
                                     "<service name=\"QuickMon 3 Service\" />\r\n" +
                                     "</machine>\r\n" +
                                     "</config>\r\n" +
                                     "</collectorAgent>\r\n" +
                                     "</collectorAgents>\r\n" +
                                     "</collectorHost>\r\n";
                    }

                    if (chkPerfCounters.Checked)
                    {
                        configXml += "<collectorHost uniqueId=\"Perf" + hostname.EscapeXml() + "\" name=\"Perfs " + hostname.EscapeXml() + " tests\" enabled=\"True\" expandOnStart=\"True\" dependOnParentId=\"Ping" + hostname.EscapeXml() + "\" " +
                                     "agentCheckSequence=\"" + (opt1stSuccess.Checked ? "FirstSuccess" : opt1stError.Checked ? "FirstError" : "All") + "\" childCheckBehaviour=\"OnlyRunOnSuccess\" " +
                                     "enableRemoteExecute=\"" + (chkRemoteHost.Checked ? "True" : "False") + "\" " +
                                     "forceRemoteExcuteOnChildCollectors=\"True\" remoteAgentHostAddress=\"" + txtRemoteHost.Text.EscapeXml() + "\" remoteAgentHostPort=\"48181\" " +
                                     "blockParentRemoteAgentHostSettings=\"False\" runLocalOnRemoteHostConnectionFailure=\"True\" >\r\n" +
                                     "<collectorAgents>\r\n" +
                                     "<collectorAgent name=\"CPU\" type=\"PerfCounterCollector\" enabled=\"True\">\r\n" +
                                     "<config>\r\n" +
                                     "<performanceCounters>\r\n" +
                                     "<performanceCounter computer=\"" + hostname.EscapeXml() + "\" category=\"Processor\" counter=\"% Processor Time\" instance=\"_Total\" returnValueInverted=\"False\" warningValue=\"90\" errorValue=\"99\" />\r\n" +
                                     "</performanceCounters>\r\n" +
                                     "</config>\r\n" +
                                     "</collectorAgent>\r\n" +
                                     "<collectorAgent name=\"Memory\" type=\"PerfCounterCollector\" enabled=\"False\">\r\n" +
                                     "<config>\r\n" +
                                     "<performanceCounters>\r\n" +
                                     "<performanceCounter computer=\"" + hostname.EscapeXml() + "\" category=\"Memory\" counter=\"% Committed Bytes In Use\" instance=\"\" returnValueInverted=\"False\" warningValue=\"80\" errorValue=\"90\" />\r\n" +
                                     "</performanceCounters>\r\n" +
                                     "</config>\r\n" +
                                     "</collectorAgent>\r\n" +
                                     "</collectorAgents>\r\n" +
                                     "</collectorHost>\r\n";
                    }

                    if (chkFileFolder.Checked)
                    {
                        configXml += "<collectorHost uniqueId=\"Folder" + hostname.EscapeXml() + "\" name=\"C drive " + hostname.EscapeXml() + " tests\" enabled=\"True\" expandOnStart=\"True\" dependOnParentId=\"Ping" + hostname.EscapeXml() + "\" " +
                                     "agentCheckSequence=\"" + (opt1stSuccess.Checked ? "FirstSuccess" : opt1stError.Checked ? "FirstError" : "All") + "\" childCheckBehaviour=\"OnlyRunOnSuccess\" " +
                                     "enableRemoteExecute=\"" + (chkRemoteHost.Checked ? "True" : "False") + "\" " +
                                     "forceRemoteExcuteOnChildCollectors=\"True\" remoteAgentHostAddress=\"" + txtRemoteHost.Text.EscapeXml() + "\" remoteAgentHostPort=\"48181\" " +
                                     "blockParentRemoteAgentHostSettings=\"False\" runLocalOnRemoteHostConnectionFailure=\"True\" >\r\n" +
                                     "<collectorAgents>\r\n" +
                                     "<collectorAgent name=\"Does C drive exist\" type=\"FileSystemCollector\" enabled=\"True\">\r\n" +
                                     "<config>\r\n" +
                                     "<directoryList>\r\n" +
                                     "<directory directoryPathFilter=\"\\\\" + hostname.EscapeXml() + "\\c$\\Test\\Test.txt\" testDirectoryExistOnly=\"False\" testFilesExistOnly=\"False\" " +
                                     "errorOnFilesExist=\"True\" warningFileCountMax=\"2\" errorFileCountMax=\"3\" warningFileSizeMaxKB=\"0\" errorFileSizeMaxKB=\"0\" " +
                                     "fileMinAgeMin=\"0\" fileMaxAgeMin=\"86400\" fileMinSizeKB=\"0\" fileMaxSizeKB=\"0\" />\r\n" +
                                     "</directoryList>\r\n" +
                                     "</config>\r\n" +
                                     "</collectorAgent>\r\n" +
                                     "</collectorAgents>\r\n" +
                                     "</collectorHost>\r\n";
                    }

                    if (chkEventLog.Checked)
                    {
                        configXml += "<collectorHost uniqueId=\"EventLog" + hostname.EscapeXml() + "\" name=\"Application Eventlog " + hostname.EscapeXml() + " tests\" enabled=\"True\" expandOnStart=\"True\" dependOnParentId=\"Ping" + hostname.EscapeXml() + "\" " +
                                     "agentCheckSequence=\"" + (opt1stSuccess.Checked ? "FirstSuccess" : opt1stError.Checked ? "FirstError" : "All") + "\" childCheckBehaviour=\"OnlyRunOnSuccess\" " +
                                     "enableRemoteExecute=\"" + (chkRemoteHost.Checked ? "True" : "False") + "\" " +
                                     "forceRemoteExcuteOnChildCollectors=\"True\" remoteAgentHostAddress=\"" + txtRemoteHost.Text.EscapeXml() + "\" remoteAgentHostPort=\"48181\" " +
                                     "blockParentRemoteAgentHostSettings=\"False\" runLocalOnRemoteHostConnectionFailure=\"True\" >\r\n" +
                                     "<collectorAgents>\r\n" +
                                     "<collectorAgent name=\"Errors in Evewntlog\" type=\"EventLogCollector\" enabled=\"True\">\r\n" +
                                     "<config>\r\n" +
                                     "<eventlogs>\r\n" +
                                     "<log computer=\"" + hostname.EscapeXml() + "\" eventLog=\"Application\" typeInfo=\"False\" typeWarn=\"True\" typeErr=\"True\" containsText=\"False\" textFilter=\"\" " +
                                     "withInLastXEntries=\"100\" withInLastXMinutes=\"1440\" warningValue=\"1\" errorValue=\"50\">\r\n" +
                                     "<sources />\r\n" +
                                     "<eventIds />\r\n" +
                                     "</log>\r\n" +
                                     "</eventlogs>\r\n" +
                                     "</config>\r\n" +
                                     "</collectorAgent>\r\n" +
                                     "</collectorAgents>\r\n" +
                                     "</collectorHost>\r\n";
                    }
                }
                configXml += "</collectorHosts>" +
                             "<notifierHosts>\r\n" +
                             "<notifierHost name=\"Default notifiers\" enabled=\"True\" alertLevel=\"Info\" detailLevel=\"Detail\" " +
                             "attendedOptionOverride=\"OnlyAttended\">\r\n" +
                             "<notifierAgents>\r\n" +
                             "<notifierAgent type=\"InMemoryNotifier\">\r\n" +
                             "<config><inMemory maxEntryCount=\"99999\" /></config>\r\n" +
                             "</notifierAgent>\r\n" +
                             "</notifierAgents>\r\n" +
                             "</notifierHost>\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=\"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" +

                             "</notifierHosts>\r\n" +
                             "</monitorPack>";

                WaitingPictureBox.BringToFront();
                Application.DoEvents();
                //this.WaitingPictureBox.Image = global::QuickMon.Properties.Resources.animated;
                //Application.DoEvents();
                txtAlerts.Text = "";

                MonitorPack m = new MonitorPack();
                m.ConcurrencyLevel = (int)nudConcurency.Value;
                m.LoadXml(configXml);
                System.Threading.ThreadPool.QueueUserWorkItem(RefreshMonitorPack, m);


                //ParallelOptions po = new ParallelOptions()
                //{
                //    MaxDegreeOfParallelism = 10
                //};
                //List<MonitorPack> mList = new List<MonitorPack>();
                //MonitorPack m = new MonitorPack();
                //m.ConcurrencyLevel = (int)nudConcurency.Value;
                //m.LoadXml(configXml);
                //mList.Add(m);
                //ParallelLoopResult parResult = Parallel.ForEach(mList, po, mEntry => RefreshPack(mEntry));

                //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')));
                //}

                ////WaitingPictureBox.Visible = false;
                //WaitingPictureBox.SendToBack();
                //Application.DoEvents();
            }
        }
Пример #9
0
        public MonitorState GetState(QuickMon.RemoteCollectorHost entry)
        {
            StringBuilder consoleOutPut = new StringBuilder();
            MonitorState  monitorState  = new MonitorState();

            /*** For Console debugging **/
            consoleOutPut.AppendFormat("{0}: Running collector host: {1}\r\n", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), entry.Name);
            try
            {
                OperationContext context = OperationContext.Current;
                System.ServiceModel.Channels.MessageProperties             messageProperties = context.IncomingMessageProperties;
                System.ServiceModel.Channels.RemoteEndpointMessageProperty endpointProperty  =
                    messageProperties[System.ServiceModel.Channels.RemoteEndpointMessageProperty.Name] as System.ServiceModel.Channels.RemoteEndpointMessageProperty;

                consoleOutPut.AppendFormat(" Requested from {0}:{1}\r\n", endpointProperty.Address, endpointProperty.Port);
            }
            catch (Exception ex)
            {
                consoleOutPut.AppendFormat(" Error getting caller info: {0}\r\n", ex.Message);
            }
            consoleOutPut.AppendFormat("{0}\r\n", new string('*', 79));
            Console.WriteLine(consoleOutPut.ToString());
            consoleOutPut = new StringBuilder();
            /*** For Console debugging **/

            try
            {
                string collectorHostConfig = entry.ToCollectorHostXml();
                string tempMonitorPack     = "<monitorPack version=\"5.0.0.0\" name=\"\" typeName=\"\" enabled=\"True\" defaultNotifier=\"\" runCorrectiveScripts=\"False\" collectorStateHistorySize=\"1\" pollingFreqSecOverride=\"0\">" +
                                             "<collectorHosts>" +
                                             collectorHostConfig +
                                             "</collectorHosts>\r\n" +
                                             "<notifierHosts>\r\n" +
                                             "</notifierHosts>\r\n" +
                                             "</monitorPack>";
                MonitorPack m = new MonitorPack();
                m.LoadXml(tempMonitorPack);
                m.ApplicationUserNameCacheMasterKey = ApplicationUserNameCacheMasterKey;
                m.ApplicationUserNameCacheFilePath  = ApplicationUserNameCacheFilePath;
                m.BlockedCollectorAgentTypes.AddRange(BlockedCollectorAgentTypes.ToArray());
                m.ScriptsRepositoryDirectory = ScriptsRepositoryDirectory;
                if (m.CollectorHosts.Count == 1)
                {
                    m.RefreshStates();
                    //Since there is only one CollectorHost
                    CollectorHost ch = m.CollectorHosts[0];
                    monitorState       = ch.CurrentState;
                    monitorState.RanAs = ch.CurrentState.RanAs;
                }
                else
                {
                    monitorState.CurrentValue = "There was a problem loading the Collector Host config on the remote host!";
                    monitorState.RawDetails   = collectorHostConfig;
                    monitorState.HtmlDetails  = collectorHostConfig.EscapeXml();
                    monitorState.State        = CollectorState.Error;
                }
                //If hosted in console test app
                consoleOutPut.AppendFormat("{0}: Results for collector host: {1}\r\n", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), entry.Name);
                consoleOutPut.AppendFormat(" State   : {0}\r\n", monitorState.State);
                consoleOutPut.AppendFormat(" Ran as  : {0}\r\n", monitorState.RanAs);
                consoleOutPut.AppendFormat(" Details : {0}\r\n", monitorState.ReadAllRawDetails());
            }
            catch (Exception ex)
            {
                consoleOutPut.AppendFormat(" Error: {0}\r\n", ex);
                monitorState.CurrentValue = ex.Message;
                monitorState.State        = CollectorState.Error;
                monitorState.RawDetails   = ex.ToString();
                monitorState.HtmlDetails  = ex.ToString().EscapeXml();
            }

            consoleOutPut.AppendLine(new string('*', 79));
            Console.WriteLine(consoleOutPut.ToString());

            monitorState.ExecutedOnHostComputer = System.Net.Dns.GetHostName();
            return(monitorState);
        }
Пример #10
0
        public void SaveAndLoadBlankMonitorPack()
        {
            MonitorPack m       = new MonitorPack();
            string      mconfig = "<monitorPack version=\"4.0.0\" name=\"Test\" typeName=\"TestType\" enabled=\"True\" " +
                                  "defaultNotifier=\"In Memory\" runCorrectiveScripts=\"True\" " +
                                  "stateHistorySize=\"101\" pollingFreqSecOverride=\"12\">\r\n" +
                                  "<configVars />" +
                                  "<collectorHosts />" +
                                  "<notifierHosts />" +
                                  "</monitorPack>";

            m.LoadXml(mconfig);
            Assert.IsNotNull(m, "Monitor pack is null");
            if (m != null)
            {
                string outputFileName = System.IO.Path.Combine(System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "QuickMon4SaveTest.qmp");
                if (System.IO.File.Exists(outputFileName))
                {
                    System.IO.File.Delete(outputFileName);
                }
                m.Save(outputFileName);
                Assert.AreEqual("Test", m.Name, "Name is not set");
                Assert.AreEqual(true, System.IO.File.Exists(outputFileName));
                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, "Enabled is not set");
                Assert.AreEqual(true, m.RunCorrectiveScripts, "runCorrectiveScripts is not set");
                Assert.AreEqual(101, 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");
                }

                m.Name = "Deliberately change name";
                m.Load(outputFileName);
                Assert.AreEqual("Test", m.Name, "Name is not set (2nd test)");
                Assert.AreEqual(true, System.IO.File.Exists(outputFileName));
                //Assert.AreEqual("4.0.0.0", m.Version, "Version is not set (2nd test)");
                Assert.AreEqual("TestType", m.TypeName, "Type is not set (2nd test)");
                Assert.AreEqual(true, m.Enabled, "Enabled is not set (2nd test)");
                Assert.AreEqual(true, m.RunCorrectiveScripts, "runCorrectiveScripts is not set (2nd test)");
                Assert.AreEqual(101, m.CollectorStateHistorySize, string.Format("CollectorStateHistorySize is not set: {0} (2nd test)", m.CollectorStateHistorySize));
                Assert.AreEqual(12, m.PollingFrequencyOverrideSec, string.Format("PollingFrequencyOverrideSec is not set: {0} (2nd test)", m.PollingFrequencyOverrideSec));
                Assert.IsNotNull(m.ConfigVariables, "ConfigVariables is null (2nd test)");
                if (m.ConfigVariables != null)
                {
                    Assert.AreEqual(0, m.ConfigVariables.Count, "ConfigVariables count should be 0 (2nd test)");
                }
                Assert.IsNotNull(m.CollectorHosts, "CollectorHosts is null (2nd test)");
                if (m.CollectorHosts != null)
                {
                    Assert.AreEqual(0, m.CollectorHosts.Count, "CollectorHosts count should be 0 (2nd test)");
                }
                Assert.IsNotNull(m.NotifierHosts, "NotifierHosts is null (2nd test)");
                if (m.NotifierHosts != null)
                {
                    Assert.AreEqual(0, m.NotifierHosts.Count, "NotifierHosts count should be 0 (2nd test)");
                }
            }
        }
Пример #11
0
        public void LoadPingCollectorTest()
        {
            string mconfig = "<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" +
                             "<collectorHost uniqueId=\"123\" name=\"Ping test\" enabled=\"True\" expandOnStart=\"True\" dependOnParentId=\"\" " +
                             "agentCheckSequence=\"All\" childCheckBehaviour=\"OnlyRunOnSuccess\" " +
                             "repeatAlertInXMin=\"0\" alertOnceInXMin=\"0\" delayErrWarnAlertForXSec=\"0\" " +
                             "repeatAlertInXPolls=\"0\" alertOnceInXPolls=\"0\" delayErrWarnAlertForXPolls=\"0\" " +
                             "correctiveScriptDisabled=\"False\" correctiveScriptOnWarningPath=\"\" correctiveScriptOnErrorPath=\"\" " +
                             "restorationScriptPath=\"\" correctiveScriptsOnlyOnStateChange=\"True\" enableRemoteExecute=\"False\" " +
                             "forceRemoteExcuteOnChildCollectors=\"True\" remoteAgentHostAddress=\"\" remoteAgentHostPort=\"48181\" " +
                             "blockParentRemoteAgentHostSettings=\"False\" runLocalOnRemoteHostConnectionFailure=\"False\" " +
                             "enabledPollingOverride=\"False\" onlyAllowUpdateOncePerXSec=\"1\" enablePollFrequencySliding=\"False\" " +
                             "pollSlideFrequencyAfterFirstRepeatSec=\"2\" pollSlideFrequencyAfterSecondRepeatSec=\"5\" " +
                             "pollSlideFrequencyAfterThirdRepeatSec=\"30\">\r\n" +
                             "<collectorAgents>\r\n" +
                             "<collectorAgent type=\"PingCollector\">\r\n" +
                             "<config>\r\n" +
                             "<entries>\r\n" +
                             "<entry pingMethod=\"Ping\" address=\"localhost\" />\r\n" +
                             "</entries>\r\n" +
                             "</config>\r\n" +
                             "</collectorAgent>\r\n" +
                             "</collectorAgents>\r\n" +
                             "</collectorHost>\r\n" +
                             "</collectorHosts>\r\n" +
                             "<notifierHosts>\r\n" +
                             "<notifierHost name=\"Default notifiers\" enabled=\"True\" alertLevel=\"Warning\" detailLevel=\"Detail\" " +
                             "attendedOptionOverride=\"OnlyAttended\">\r\n" +
                             "<notifierAgents>\r\n" +
                             "<notifierAgent type=\"InMemoryNotifier\">\r\n" +
                             "<config><inMemory maxEntryCount=\"99999\" /></config>\r\n" +
                             "</notifierAgent>\r\n" +
                             "</notifierAgents>\r\n" +
                             "</notifierHost>\r\n" +
                             "</notifierHosts>\r\n" +
                             "</monitorPack>";
            MonitorPack m = new MonitorPack();

            m.LoadXml(mconfig);
            Assert.IsNotNull(m, "Monitor pack is null");
            if (m != null)
            {
                string outputFileName = System.IO.Path.Combine(System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "QuickMon4SaveTest.qmp");
                if (System.IO.File.Exists(outputFileName))
                {
                    System.IO.File.Delete(outputFileName);
                }
                m.Save(outputFileName);
                m.Load(outputFileName);

                Assert.AreEqual(1, m.CollectorHosts.Count, "1 Collector host is expected");
                if (m.CollectorHosts.Count == 1)
                {
                    Assert.AreEqual(1, m.CollectorHosts[0].CollectorAgents.Count, "1 Collector agent is expected");
                    Assert.AreEqual(m.CollectorHosts[0].CollectorAgents[0].InitialConfiguration, m.CollectorHosts[0].CollectorAgents[0].ActiveConfiguration, "Initial and active config should match");
                }
            }
        }
Пример #12
0
        public void LoadBlankCollectorHost()
        {
            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 />\r\n" +
                             "<collectorHosts>\r\n" +
                             "<collectorHost uniqueId=\"123\" name=\"Test name\" enabled=\"True\" expandOnStart=\"Auto\" dependOnParentId=\"\" " +
                             "agentCheckSequence=\"All\" childCheckBehaviour=\"OnlyRunOnSuccess\" " +
                             "repeatAlertInXMin=\"1\" alertOnceInXMin=\"1\" delayErrWarnAlertForXSec=\"1\" " +
                             "repeatAlertInXPolls=\"1\" alertOnceInXPolls=\"1\" delayErrWarnAlertForXPolls=\"1\" " +
                             "correctiveScriptDisabled=\"True\" correctiveScriptOnWarningPath=\"test\" correctiveScriptOnErrorPath=\"test\" " +
                             "restorationScriptPath=\"test\" correctiveScriptsOnlyOnStateChange=\"True\" enableRemoteExecute=\"True\" " +
                             "forceRemoteExcuteOnChildCollectors=\"True\" remoteAgentHostAddress=\"test\" remoteAgentHostPort=\"48182\" " +
                             "blockParentRemoteAgentHostSettings=\"True\" runLocalOnRemoteHostConnectionFailure=\"True\" " +
                             "enabledPollingOverride=\"True\" onlyAllowUpdateOncePerXSec=\"2\" enablePollFrequencySliding=\"True\" " +
                             "pollSlideFrequencyAfterFirstRepeatSec=\"3\" pollSlideFrequencyAfterSecondRepeatSec=\"6\" " +
                             "pollSlideFrequencyAfterThirdRepeatSec=\"31\">\r\n" +
                             "</collectorHost>\r\n" +
                             "</collectorHosts>\r\n" +
                             "<notifierHosts />\r\n" +
                             "</monitorPack>";

            MonitorPack m = new MonitorPack();

            m.LoadXml(mconfig);
            Assert.IsNotNull(m, "Monitor pack is null");
            if (m != null)
            {
                Assert.AreEqual(1, m.CollectorHosts.Count, "1 Collector host is expected");
                if (m.CollectorHosts.Count == 1)
                {
                    Assert.AreEqual("Test name", m.CollectorHosts[0].Name, "Collector host name not set");
                    Assert.AreEqual("123", m.CollectorHosts[0].UniqueId, "Collector host UniqueId not set");
                    Assert.AreEqual(true, m.CollectorHosts[0].Enabled, "Collector host Enabled property not set");
                    Assert.AreEqual(ExpandOnStartOption.Auto, m.CollectorHosts[0].ExpandOnStartOption, "Collector host ExpandOnStart property not set");
                    Assert.AreEqual("", m.CollectorHosts[0].ParentCollectorId, "Collector host ParentCollectorId property not set");
                    Assert.AreEqual(AgentCheckSequence.All, m.CollectorHosts[0].AgentCheckSequence, "Collector host AgentCheckSequence property not set");
                    Assert.AreEqual(ChildCheckBehaviour.OnlyRunOnSuccess, m.CollectorHosts[0].ChildCheckBehaviour, "Collector host ChildCheckBehaviour property not set");
                    Assert.AreEqual(1, m.CollectorHosts[0].RepeatAlertInXMin, "Collector host RepeatAlertInXMin property not set");
                    Assert.AreEqual(1, m.CollectorHosts[0].AlertOnceInXMin, "Collector host AlertOnceInXMin property not set");
                    Assert.AreEqual(1, m.CollectorHosts[0].DelayErrWarnAlertForXSec, "Collector host DelayErrWarnAlertForXSec property not set");
                    Assert.AreEqual(1, m.CollectorHosts[0].RepeatAlertInXPolls, "Collector host RepeatAlertInXPolls property not set");
                    Assert.AreEqual(1, m.CollectorHosts[0].AlertOnceInXPolls, "Collector host AlertOnceInXPolls property not set");
                    Assert.AreEqual(1, m.CollectorHosts[0].DelayErrWarnAlertForXPolls, "Collector host DelayErrWarnAlertForXPolls property not set");
                    Assert.AreEqual(true, m.CollectorHosts[0].CorrectiveScriptDisabled, "Collector host CorrectiveScriptDisabled property not set");
                    Assert.AreEqual("test", m.CollectorHosts[0].CorrectiveScriptOnWarningPath, "Collector host CorrectiveScriptOnWarningPath property not set");
                    Assert.AreEqual("test", m.CollectorHosts[0].CorrectiveScriptOnErrorPath, "Collector host CorrectiveScriptOnErrorPath property not set");
                    Assert.AreEqual("test", m.CollectorHosts[0].RestorationScriptPath, "Collector host RestorationScriptPath property not set");
                    Assert.AreEqual(true, m.CollectorHosts[0].CorrectiveScriptsOnlyOnStateChange, "Collector host CorrectiveScriptsOnlyOnStateChange property not set");
                    Assert.AreEqual(true, m.CollectorHosts[0].EnableRemoteExecute, "Collector host EnableRemoteExecute property not set");
                    Assert.AreEqual(true, m.CollectorHosts[0].ForceRemoteExcuteOnChildCollectors, "Collector host ForceRemoteExcuteOnChildCollectors property not set");
                    Assert.AreEqual("test", m.CollectorHosts[0].RemoteAgentHostAddress, "Collector host RemoteAgentHostAddress property not set");
                    Assert.AreEqual(48182, m.CollectorHosts[0].RemoteAgentHostPort, "Collector host RemoteAgentHostPort property not set");
                    Assert.AreEqual(true, m.CollectorHosts[0].BlockParentOverrideRemoteAgentHostSettings, "Collector host BlockParentOverrideRemoteAgentHostSettings property not set");
                    Assert.AreEqual(true, m.CollectorHosts[0].RunLocalOnRemoteHostConnectionFailure, "Collector host RunLocalOnRemoteHostConnectionFailure property not set");
                    Assert.AreEqual(true, m.CollectorHosts[0].EnabledPollingOverride, "Collector host EnabledPollingOverride property not set");
                    Assert.AreEqual(2, m.CollectorHosts[0].OnlyAllowUpdateOncePerXSec, "Collector host OnlyAllowUpdateOncePerXSec property not set");
                    Assert.AreEqual(true, m.CollectorHosts[0].EnablePollFrequencySliding, "Collector host EnablePollFrequencySliding property not set");
                    Assert.AreEqual(3, m.CollectorHosts[0].PollSlideFrequencyAfterFirstRepeatSec, "Collector host PollSlideFrequencyAfterFirstRepeatSec property not set");
                    Assert.AreEqual(6, m.CollectorHosts[0].PollSlideFrequencyAfterSecondRepeatSec, "Collector host PollSlideFrequencyAfterSecondRepeatSec property not set");
                    Assert.AreEqual(31, m.CollectorHosts[0].PollSlideFrequencyAfterThirdRepeatSec, "Collector host PollSlideFrequencyAfterThirdRepeatSec property not set");

                    string outputFileName = System.IO.Path.Combine(System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "QuickMon4SaveTest.qmp");
                    if (System.IO.File.Exists(outputFileName))
                    {
                        System.IO.File.Delete(outputFileName);
                    }
                    m.Save(outputFileName);
                    Assert.AreEqual(true, System.IO.File.Exists(outputFileName));

                    m.Load(outputFileName);
                    Assert.AreEqual(1, m.CollectorHosts.Count, "1 Collector host is expected (2nd test)");
                    if (m.CollectorHosts.Count == 1)
                    {
                        Assert.AreEqual("Test name", m.CollectorHosts[0].Name, "Collector host name not set (2nd test)");
                        Assert.AreEqual("123", m.CollectorHosts[0].UniqueId, "Collector host UniqueId not set (2nd test)");
                        Assert.AreEqual(true, m.CollectorHosts[0].Enabled, "Collector host Enabled property not set (2nd test)");
                        Assert.AreEqual(ExpandOnStartOption.Auto, m.CollectorHosts[0].ExpandOnStartOption, "Collector host ExpandOnStart property not set (2nd test)");
                        Assert.AreEqual("", m.CollectorHosts[0].ParentCollectorId, "Collector host ParentCollectorId property not set (2nd test)");
                        Assert.AreEqual(AgentCheckSequence.All, m.CollectorHosts[0].AgentCheckSequence, "Collector host AgentCheckSequence property not set (2nd test)");
                        Assert.AreEqual(ChildCheckBehaviour.OnlyRunOnSuccess, m.CollectorHosts[0].ChildCheckBehaviour, "Collector host ChildCheckBehaviour property not set (2nd test)");
                        Assert.AreEqual(1, m.CollectorHosts[0].RepeatAlertInXMin, "Collector host RepeatAlertInXMin property not set (2nd test)");
                        Assert.AreEqual(1, m.CollectorHosts[0].AlertOnceInXMin, "Collector host AlertOnceInXMin property not set (2nd test)");
                        Assert.AreEqual(1, m.CollectorHosts[0].DelayErrWarnAlertForXSec, "Collector host DelayErrWarnAlertForXSec property not set (2nd test)");
                        Assert.AreEqual(1, m.CollectorHosts[0].RepeatAlertInXPolls, "Collector host RepeatAlertInXPolls property not set (2nd test)");
                        Assert.AreEqual(1, m.CollectorHosts[0].AlertOnceInXPolls, "Collector host AlertOnceInXPolls property not set (2nd test)");
                        Assert.AreEqual(1, m.CollectorHosts[0].DelayErrWarnAlertForXPolls, "Collector host DelayErrWarnAlertForXPolls property not set (2nd test)");
                        Assert.AreEqual(true, m.CollectorHosts[0].CorrectiveScriptDisabled, "Collector host CorrectiveScriptDisabled property not set (2nd test)");
                        Assert.AreEqual("test", m.CollectorHosts[0].CorrectiveScriptOnWarningPath, "Collector host CorrectiveScriptOnWarningPath property not set (2nd test)");
                        Assert.AreEqual("test", m.CollectorHosts[0].CorrectiveScriptOnErrorPath, "Collector host CorrectiveScriptOnErrorPath property not set (2nd test)");
                        Assert.AreEqual("test", m.CollectorHosts[0].RestorationScriptPath, "Collector host RestorationScriptPath property not set (2nd test)");
                        Assert.AreEqual(true, m.CollectorHosts[0].CorrectiveScriptsOnlyOnStateChange, "Collector host CorrectiveScriptsOnlyOnStateChange property not set (2nd test)");
                        Assert.AreEqual(true, m.CollectorHosts[0].EnableRemoteExecute, "Collector host EnableRemoteExecute property not set (2nd test)");
                        Assert.AreEqual(true, m.CollectorHosts[0].ForceRemoteExcuteOnChildCollectors, "Collector host ForceRemoteExcuteOnChildCollectors property not set (2nd test)");
                        Assert.AreEqual("test", m.CollectorHosts[0].RemoteAgentHostAddress, "Collector host RemoteAgentHostAddress property not set (2nd test)");
                        Assert.AreEqual(48182, m.CollectorHosts[0].RemoteAgentHostPort, "Collector host RemoteAgentHostPort property not set (2nd test)");
                        Assert.AreEqual(true, m.CollectorHosts[0].BlockParentOverrideRemoteAgentHostSettings, "Collector host BlockParentOverrideRemoteAgentHostSettings property not set (2nd test)");
                        Assert.AreEqual(true, m.CollectorHosts[0].RunLocalOnRemoteHostConnectionFailure, "Collector host RunLocalOnRemoteHostConnectionFailure property not set (2nd test)");
                        Assert.AreEqual(true, m.CollectorHosts[0].EnabledPollingOverride, "Collector host EnabledPollingOverride property not set (2nd test)");
                        Assert.AreEqual(2, m.CollectorHosts[0].OnlyAllowUpdateOncePerXSec, "Collector host OnlyAllowUpdateOncePerXSec property not set (2nd test)");
                        Assert.AreEqual(true, m.CollectorHosts[0].EnablePollFrequencySliding, "Collector host EnablePollFrequencySliding property not set (2nd test)");
                        Assert.AreEqual(3, m.CollectorHosts[0].PollSlideFrequencyAfterFirstRepeatSec, "Collector host PollSlideFrequencyAfterFirstRepeatSec property not set (2nd test)");
                        Assert.AreEqual(6, m.CollectorHosts[0].PollSlideFrequencyAfterSecondRepeatSec, "Collector host PollSlideFrequencyAfterSecondRepeatSec property not set (2nd test)");
                        Assert.AreEqual(31, m.CollectorHosts[0].PollSlideFrequencyAfterThirdRepeatSec, "Collector host PollSlideFrequencyAfterThirdRepeatSec property not set (2nd test)");
                    }
                }
            }
        }
Пример #13
0
        private void ReadCallback(IAsyncResult result)
        {
            try
            {
                using (NetworkStream networkStream = clientSocket.GetStream())
                {
                    int          read       = networkStream.EndRead(result);
                    MonitorState packResult = new MonitorState()
                    {
                        State = CollectorState.NotAvailable, RawDetails = "", HtmlDetails = ""
                    };

                    string data = "";
                    if (read > 0)
                    {
                        byte[] buffer = result.AsyncState as byte[];
                        data = Encoding.UTF8.GetString(buffer, 0, read);

                        //do the job with the data here
                        if (data.StartsWith("<monitorPack") && data.EndsWith("</monitorPack>"))
                        {
                            MonitorPack   m = new MonitorPack();
                            StringBuilder plainTextDetails    = new StringBuilder();
                            StringBuilder htmlTextTextDetails = new StringBuilder();

                            m.RaiseMonitorPackError += m_RaiseMonitorPackError;
                            m.LoadXml(data);
                            RaiseDisplayMonitorPackName(m.Name);
                            packResult.State = m.RefreshStates();
                            htmlTextTextDetails.AppendLine("<ul>");
                            foreach (CollectorEntry ce in (from c in m.Collectors
                                                           where c.CurrentState != null
                                                           select c))
                            {
                                if (ce.CurrentState == null)
                                {
                                    plainTextDetails.AppendLine(string.Format("\tCollector: {0}, State: N/A", ce.Name));
                                    htmlTextTextDetails.AppendLine(string.Format("<li>Collector: {0}, State: N/A</li>", ce.Name));
                                }
                                else if (ce.CurrentState.State == CollectorState.Good)
                                {
                                    plainTextDetails.AppendLine(string.Format("\tCollector: {0}, State: {1}", ce.Name, ce.CurrentState.State));
                                    htmlTextTextDetails.AppendLine(string.Format("<li>Collector: {0}, State: {1}</li>", ce.Name, ce.CurrentState.State));
                                }
                                else
                                {
                                    plainTextDetails.AppendLine(string.Format("\tCollector: {0}, State: {1}", ce.Name, ce.CurrentState.State));
                                    if (ce.CurrentState.RawDetails != null && ce.CurrentState.RawDetails.Length > 0)
                                    {
                                        plainTextDetails.AppendLine(string.Format("\t\tDetails: {0}", ce.CurrentState.RawDetails.Replace("\r\n", "\r\n\t\t\t")));
                                    }
                                    htmlTextTextDetails.AppendLine(string.Format("<li>Collector: {0}, State: {1}</li>", ce.Name, ce.CurrentState.State));
                                    if (ce.CurrentState.HtmlDetails != null && ce.CurrentState.HtmlDetails.Length > 0)
                                    {
                                        htmlTextTextDetails.AppendLine(string.Format("<br/>Details: {0}", ce.CurrentState.HtmlDetails));
                                    }
                                }
                            }
                            htmlTextTextDetails.AppendLine("</ul>");
                            packResult.RawDetails  = plainTextDetails.ToString();
                            packResult.HtmlDetails = htmlTextTextDetails.ToString();

                            RaiseInfoMessage(string.Format("MonitorPack: '{0}' - state: {1}", m.Name, packResult.State));
                            m = null;
                        }
                        else
                        {
                            RaiseErrorMessage("Input request data invalid!\r\n" + summarizeErrData(data));
                            packResult.State       = CollectorState.Error;
                            packResult.RawDetails  = "Input request data invalid!\r\n" + summarizeErrData(data);
                            packResult.HtmlDetails = "Input request data invalid!\r\n" + summarizeErrData(data.Replace("<", "&lt;").Replace(">", "&gt;"));
                        }

                        //send the data back to client.
                        Byte[] sendBytes = Encoding.UTF8.GetBytes(packResult.ToXml());
                        networkStream.Write(sendBytes, 0, sendBytes.Length);
                        networkStream.Flush();
                    }
                }
            }
            catch (Exception ex)
            {
                if ((ex is System.IO.IOException && ex.Message.Contains("Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host")) ||
                    ex is System.InvalidOperationException && ex.Message.Contains("The operation is not allowed on non-connected sockets"))
                {
                    RaiseInfoMessage(string.Format("Client {0} disconnecting.", clientNo));
                }
                else
                {
                    if (clientSocket != null && clientSocket.Client != null && clientSocket.Client.RemoteEndPoint is System.Net.IPEndPoint)
                    {
                        RaiseErrorMessage(string.Format("Error processing request from {0}\r\nError: {1}", ((System.Net.IPEndPoint)clientSocket.Client.RemoteEndPoint).Address.ToString(), ex));
                    }
                    else
                    {
                        RaiseErrorMessage(string.Format("Error from unknown client: {0}", ex));
                    }
                }
            }
        }
Пример #14
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;
                }
            }
        }