Пример #1
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);
        }
Пример #2
0
        private MonitorState FormatMonitorState(CollectorHost ch, MonitorState ms)
        {
            MonitorState displayMS     = ms.Clone();
            string       collectorPath = GetCollectorPath(ch);

            //foreach (CollectorHost pch in HostingMonitorPack.GetParentCollectorHostTree(ch))
            //{
            //    collectorPath = pch.Name + "/" + collectorPath;
            //}
            //displayMS.ForAgent = collectorPath + ch.Name;
            displayMS.ForAgent     = collectorPath; // ch.ApplyConfigVarsOnString(collectorPath);
            displayMS.CurrentValue = ms.ReadPrimaryOrFirstUIValue();
            displayMS.RawDetails   = ms.ReadAllRawDetails();
            return(displayMS);
        }
Пример #3
0
        public void CallCollectorHostThroughRemoteHost()
        {
            //For this test to work the Remote host service (QuickMon 4 Service) must be started on the local machine
            string configXml = "<collectorHosts>\r\n" +
                               "<collectorHost uniqueId=\"1234\" 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=\"True\" " +
                               "forceRemoteExcuteOnChildCollectors=\"True\" remoteAgentHostAddress=\"localhost\" 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>";
            List <CollectorHost> chList = CollectorHost.GetCollectorHostsFromString(configXml);

            Assert.IsNotNull(chList, "CollectorHost list is null");
            if (chList != null)
            {
                Assert.AreEqual(true, chList[0].EnableRemoteExecute, "Remote execute not enabled");
                Assert.AreEqual(false, chList[0].RunLocalOnRemoteHostConnectionFailure, "RunLocalOnRemoteHostConnectionFailure should not be set");
                MonitorState ms = chList[0].RefreshCurrentState();
                Assert.AreEqual(false, ms.ReadAllRawDetails().Contains("There was no endpoint"), "Remote host service not started!");
                Assert.IsNotNull(ms.ChildStates, "No Child states");
                Assert.AreEqual(1, ms.ChildStates.Count, "One child state expected");
                Assert.AreEqual(CollectorState.Good, ms.ChildStates[0].State, "Child state should be good");
                Assert.AreEqual(CollectorState.Good, ms.State, "Global state should be good");
                Assert.AreEqual(System.Net.Dns.GetHostName(), ms.ExecutedOnHostComputer, "Should run on localhost");
            }
        }
Пример #4
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')));
                }
            });
        }
Пример #5
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);
        }
Пример #6
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;
                }
            }
        }