Example #1
0
        private void LoadCollectorHostItems()
        {
            lvwAgentType.Items.Clear();
            lvwAgentType.Groups.Clear();

            ListViewGroup generalGroup = new ListViewGroup("General");

            lvwAgentType.Groups.Add(generalGroup);
            ListViewItem lviEmptyCollector = new ListViewItem("Folder/Blank collector");

            //lviEmptyCollector.SubItems.Add("Creates a blank collector with no agents");
            //lviEmptyCollector.Group = generalGroup;
            //lviEmptyCollector.Tag = new CollectorHost() { Name = "Folder" };
            //lvwAgentType.Items.Add(lviEmptyCollector);

            //lviEmptyCollector = new ListViewItem("Folder/Blank Collector");
            lviEmptyCollector.SubItems.Add("Creates a blank collector with no agents");
            lviEmptyCollector.Group = generalGroup;
            lviEmptyCollector.Tag   = CollectorHost.FromXml("<collectorHost uniqueId=\"\" dependOnParentId=\"\" name=\"[[FolderName:]]\"><collectorAgents agentCheckSequence=\"All\"></collectorAgents></collectorHost>").Clone(true);
            lvwAgentType.Items.Add(lviEmptyCollector);

            //<collectorHost uniqueId=\"\" dependOnParentId=\"\" name=\"[[FolderName:]]\"><collectorAgents agentCheckSequence="All"></collectorAgents></collectorHost>

            ListViewItem lviPingCollector = new ListViewItem("Ping (ICMP)");

            lviPingCollector.SubItems.Add("Creates a collector with a Ping (ICMP) agent");
            lviPingCollector.Group = generalGroup;
            lviPingCollector.Tag   = CollectorHost.FromXml("<collectorHost uniqueId=\"\" dependOnParentId=\"\" name=\"Ping [[MachineName:localhost]]\"><collectorAgents agentCheckSequence=\"All\"><collectorAgent name=\"Ping [[MachineName:localhost]]\" type=\"QuickMon.Collectors.PingCollector\" enabled=\"True\"><config><entries><entry pingMethod=\"Ping\" address=\"[[MachineName:localhost]]\" maxTimeMS=\"[[maxTimeMS:1000]]\" timeOutMS=\"[[timeOutMS:5000]]\" /></entries></config></collectorAgent></collectorAgents></collectorHost>").Clone(true);
            lvwAgentType.Items.Add(lviPingCollector);

            lviPingCollector = new ListViewItem("Ping (http)");
            lviPingCollector.SubItems.Add("Creates a collector with a Ping (http) agent");
            lviPingCollector.Group = generalGroup;
            lviPingCollector.Tag   = CollectorHost.FromXml("<collectorHost uniqueId=\"\" dependOnParentId=\"\" name=\"Ping [[MachineName:localhost]]\"><collectorAgents agentCheckSequence=\"All\"><collectorAgent name=\"Ping [[MachineName:localhost]]\" type=\"QuickMon.Collectors.PingCollector\" enabled=\"True\"><config><entries><entry pingMethod=\"Http\" address=\"http://[[MachineName:localhost]]\" maxTimeMS=\"[[maxTimeMS:1000]]\" timeOutMS=\"[[timeOutMS:5000]]\" /></entries></config></collectorAgent></collectorAgents></collectorHost>").Clone(true);
            lvwAgentType.Items.Add(lviPingCollector);

            ListViewGroup templatesGroup = new ListViewGroup("Templates");

            lvwAgentType.Groups.Add(templatesGroup);

            foreach (QuickMonTemplate qt in QuickMonTemplate.GetAllTemplates().Where(t => t.TemplateType == TemplateType.CollectorHost))
            {
                ListViewItem lviTemplateCollector = new ListViewItem(qt.Name);
                lviTemplateCollector.SubItems.Add(qt.Description);
                lviTemplateCollector.Group = templatesGroup;
                lviTemplateCollector.Tag   = qt;
                lvwAgentType.Items.Add(lviTemplateCollector);
            }
        }
Example #2
0
        private void RefreshItem(object o)
        {
            ListViewItem lvi = (ListViewItem)o;

            try
            {
                try
                {
                    bool            hostExists = false;
                    RemoteAgentInfo ri         = (RemoteAgentInfo)lvi.Tag;
                    string          configXml  = "<collectorHost uniqueId=\"Ping" + ri.Computer.EscapeXml() + "\" name=\"Ping " + ri.Computer.EscapeXml() + " tests\" enabled=\"True\" expandOnStart=\"True\" dependOnParentId=\"\" " +
                                                 "agentCheckSequence=\"All\" childCheckBehaviour=\"OnlyRunOnSuccess\" " +
                                                 "enableRemoteExecute=\"True\" " +
                                                 "forceRemoteExcuteOnChildCollectors=\"False\" remoteAgentHostAddress=\"" + ri.Computer.EscapeXml() + "\" remoteAgentHostPort=\"48191\" " +
                                                 "blockParentRemoteAgentHostSettings=\"False\" runLocalOnRemoteHostConnectionFailure=\"True\" >\r\n" +
                                                 "<collectorAgents>\r\n" +
                                                 "<collectorAgent type=\"PingCollector\">\r\n" +
                                                 "<config>\r\n" +
                                                 "<entries>\r\n" +
                                                 "<entry pingMethod=\"Ping\" address=\"" + ri.Computer.EscapeXml() + "\" />\r\n" +
                                                 "</entries>\r\n" +
                                                 "</config>\r\n" +
                                                 "</collectorAgent>\r\n" +
                                                 "</collectorAgents>\r\n" +
                                                 "</collectorHost>\r\n";
                    CollectorHost ce = CollectorHost.FromXml(configXml);

                    ce.EnableRemoteExecute    = true;
                    ce.RemoteAgentHostAddress = ri.Computer;
                    ce.RemoteAgentHostPort    = ri.PortNumber;
                    try
                    {
                        hostExists = System.Net.Dns.GetHostAddresses(ri.Computer).Count() != 0;
                    }
                    catch { }
                    if (!hostExists)
                    {
                        UpdateListViewItem(lvi, 4, "", "Host not found");
                    }
                    else if (!CanPingHost(ri.Computer))
                    {
                        UpdateListViewItem(lvi, 4, "", "Host not pingable");
                    }
                    else
                    {
                        MonitorState testState = RemoteCollectorHostService.GetCollectorHostState(ce);
                        if (testState.State == CollectorState.Good)
                        {
                            try
                            {
                                string versionInfo = RemoteCollectorHostService.GetRemoteAgentHostVersion(ri.Computer, ri.PortNumber);
                                string packs       = "0";

                                //Pack count
                                try
                                {
                                    packs = RemoteCollectorHostService.GetCurrentMonitorPacks(ri.Computer, ri.PortNumber).Count().ToString();
                                }
                                catch (Exception packsEx)
                                {
                                    packs = packsEx.Message;
                                    if (packsEx.Message.Contains("ContractFilter mismatch"))
                                    {
                                        packs = "Check version!";
                                    }
                                    else
                                    {
                                        packs = packsEx.Message;
                                    }
                                }

                                UpdateListViewItem(lvi, 1, versionInfo, packs);
                            }
                            catch (Exception ex)
                            {
                                if (ex.Message.Contains("ContractFilter"))
                                {
                                    UpdateListViewItem(lvi, 2, "", "Remote host does not support version info query! Check that QuickMon 4.x or later is installed.");
                                }
                                else
                                {
                                    UpdateListViewItem(lvi, 2, "", ex.Message);
                                }
                            }
                        }
                        else
                        {
                            UpdateListViewItem(lvi, 3, "N/A", "N/A");
                        }
                    }
                }
                catch (Exception delegateEx)
                {
                    if (delegateEx.Message.StartsWith("There was no endpoint listening"))
                    {
                        UpdateListViewItem(lvi, 3, "", "Service not running or inaccessible");
                    }
                    else if (delegateEx.Message.Contains("The formatter threw an exception while trying to deserialize the message"))
                    {
                        UpdateListViewItem(lvi, 3, "", "Old version of Remote agent host does not support query or format does not match! Please update remote agent host version.");
                    }
                    else
                    {
                        UpdateListViewItem(lvi, 3, "", delegateEx.Message);
                    }
                }
            }
            catch (Exception riEx)
            {
                UpdateListViewItem(lvi, 1, "", riEx.ToString());
            }
        }
Example #3
0
        private void cmdOK_Click(object sender, EventArgs e)
        {
            if (lvwAgentType.SelectedItems.Count == 1)
            {
                string configToUse = "";
                if (selectingMonitorPacks)
                {
                    #region Monitor pack
                    if (lvwAgentType.SelectedItems[0].Tag is string)
                    {
                        configToUse = lvwAgentType.SelectedItems[0].Tag.ToString();
                    }
                    else if (lvwAgentType.SelectedItems[0].Tag is QuickMonTemplate)
                    {
                        QuickMonTemplate selectedTemplate = (QuickMonTemplate)(lvwAgentType.SelectedItems[0].Tag);
                        configToUse = selectedTemplate.Config;
                    }
                    if (chkShowCustomConfig.Checked)
                    {
                        RAWXmlEditor editor = new RAWXmlEditor();
                        editor.SelectedMarkup = configToUse;
                        if (editor.ShowDialog() == DialogResult.OK)
                        {
                            configToUse = editor.SelectedMarkup;
                        }
                    }
                    configToUse = FormatTemplateVariables(configToUse);
                    if (configToUse.Length == 0)
                    {
                        return;
                    }

                    MonitorPack mp = new MonitorPack();
                    mp.LoadXml(configToUse);
                    SelectedMonitorPack = mp;
                    #endregion
                }
                else if (selectingCollectorHosts)
                {
                    #region Collector hosts
                    if (lvwAgentType.SelectedItems[0].Tag is CollectorHost)
                    {
                        CollectorHost newCH = (CollectorHost)lvwAgentType.SelectedItems[0].Tag;
                        newCH.UniqueId = "";
                        configToUse    = newCH.ToXml();
                    }
                    else if (lvwAgentType.SelectedItems[0].Tag is QuickMonTemplate)
                    {
                        QuickMonTemplate selectedTemplate = (QuickMonTemplate)(lvwAgentType.SelectedItems[0].Tag);
                        configToUse = selectedTemplate.Config;
                    }
                    if (chkShowCustomConfig.Checked)
                    {
                        RAWXmlEditor editor = new RAWXmlEditor();
                        editor.SelectedMarkup = configToUse;
                        if (editor.ShowDialog() == DialogResult.OK)
                        {
                            configToUse = editor.SelectedMarkup;
                        }
                    }

                    configToUse = FormatTemplateVariables(configToUse);
                    if (configToUse.Length == 0)
                    {
                        return;
                    }

                    CollectorHost cls = CollectorHost.FromXml(configToUse);
                    if (cls != null)
                    {
                        SelectedCollectorHost = cls;
                    }
                    else
                    {
                        MessageBox.Show("The configuration for this template is invalid! Please correct and try again.", "Template", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        return;
                    }
                    #endregion
                }
                else if (selectingCollectorAgents || selectingNotifierAgents)
                {
                    #region Collector agents
                    RegisteredAgent ra = null;
                    if (lvwAgentType.SelectedItems[0].Tag is RegisteredAgent)
                    {
                        ra = (RegisteredAgent)lvwAgentType.SelectedItems[0].Tag;
                    }
                    else if (lvwAgentType.SelectedItems[0].Tag is QuickMonTemplate)
                    {
                        QuickMonTemplate template = (QuickMonTemplate)lvwAgentType.SelectedItems[0].Tag;
                        ra          = RegisteredAgentCache.GetRegisteredAgentByClassName(template.ForClass, selectingCollectorAgents);
                        configToUse = template.Config;
                    }
                    if (ra != null)
                    {
                        if (System.IO.File.Exists(ra.AssemblyPath))
                        {
                            Assembly collectorEntryAssembly = Assembly.LoadFile(ra.AssemblyPath);
                            SelectedAgent = (IAgent)collectorEntryAssembly.CreateInstance(ra.ClassName);
                            SelectedAgent.AgentClassName        = ra.ClassName;
                            SelectedAgent.AgentClassDisplayName = ra.DisplayName;
                            if (configToUse.Length == 0)
                            {
                                configToUse = SelectedAgent.AgentConfig.GetDefaultOrEmptyXml();
                            }
                            if (chkShowCustomConfig.Checked)
                            {
                                RAWXmlEditor editor = new RAWXmlEditor();
                                editor.SelectedMarkup = configToUse;
                                if (editor.ShowDialog() == DialogResult.OK)
                                {
                                    configToUse = editor.SelectedMarkup;
                                }
                            }
                            try
                            {
                                if ((selectingCollectorAgents && configToUse.StartsWith("<collectorAgent")) || (selectingNotifierAgents && configToUse.StartsWith("<notifierAgent")))
                                {
                                    System.Xml.XmlDocument collectorAgentDoc = new System.Xml.XmlDocument();
                                    collectorAgentDoc.LoadXml(configToUse);
                                    System.Xml.XmlNode configNode = collectorAgentDoc.DocumentElement.SelectSingleNode("config");
                                    if (configNode != null)
                                    {
                                        configToUse = configNode.OuterXml;
                                    }
                                }

                                configToUse = FormatTemplateVariables(configToUse);
                                if (configToUse.Length == 0)
                                {
                                    return;
                                }

                                SelectedAgent.AgentConfig.FromXml(configToUse);
                                DialogResult = DialogResult.OK;
                                Close();
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show("An error occured while processing the config!\r\n" + ex.Message, "Edit config", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            }
                        }
                    }
                    #endregion
                }
                else if (selectingNotifierHosts)
                {
                    #region Notifier hosts
                    if (lvwAgentType.SelectedItems[0].Tag is NotifierHost)
                    {
                        configToUse = ((NotifierHost)lvwAgentType.SelectedItems[0].Tag).ToXml();
                    }
                    else if (lvwAgentType.SelectedItems[0].Tag is QuickMonTemplate)
                    {
                        QuickMonTemplate selectedTemplate = (QuickMonTemplate)(lvwAgentType.SelectedItems[0].Tag);
                        configToUse = selectedTemplate.Config;
                    }

                    if (chkShowCustomConfig.Checked)
                    {
                        RAWXmlEditor editor = new RAWXmlEditor();
                        editor.SelectedMarkup = configToUse;
                        if (editor.ShowDialog() == DialogResult.OK)
                        {
                            configToUse = editor.SelectedMarkup;
                        }
                    }

                    configToUse = FormatTemplateVariables(configToUse);
                    if (configToUse.Length == 0)
                    {
                        return;
                    }

                    NotifierHost cls = NotifierHost.FromXml(configToUse);
                    if (cls != null)
                    {
                        SelectedNotifierHost = cls;
                    }
                    else
                    {
                        MessageBox.Show("The configuration for this template is invalid! Please correct and try again.", "Template", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        return;
                    }
                    #endregion
                }
                EditAfterCreation = chkEditAfterCreate.Checked;
                DialogResult      = DialogResult.OK;
                Close();
            }
        }