Exemple #1
0
        public override bool EditAgent()
        {
            ICollector agent = CollectorHost.CreateCollectorFromClassName(AgentType);

            if (agent != null)
            {
                agent.Name    = AgentName;
                agent.Enabled = AgentEnabled;
                EditCollectorAgentEntries editCollectorAgentEntries = new EditCollectorAgentEntries();
                agent.InitialConfiguration = SelectedAgentConfig;
                agent.AgentConfig.FromXml(SelectedAgentConfig);

                editCollectorAgentEntries.SelectedEntry = agent;
                editCollectorAgentEntries.DetailEditor  = DetailEditor;
                if (editCollectorAgentEntries.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    agent               = editCollectorAgentEntries.SelectedEntry;
                    AgentName           = agent.Name;
                    AgentEnabled        = agent.Enabled;
                    SelectedAgentConfig = agent.AgentConfig.ToXml();
                    return(true);
                }
            }
            return(false);
        }
        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);
            }
        }
Exemple #3
0
 private void SetAlertForCollectors(NotifierHost editingNotifierHost, TreeNode parent = null)
 {
     if (parent == null)
     {
         parent = tvwCollectors.Nodes[0];
     }
     foreach (TreeNode child in parent.Nodes)
     {
         if (child.Checked && child.Tag is CollectorHost)
         {
             CollectorHost ch = (CollectorHost)child.Tag;
             editingNotifierHost.AlertForCollectors.Add(ch.Name);
         }
         SetAlertForCollectors(editingNotifierHost, child);
     }
 }
Exemple #4
0
        private void cboClass_SelectedIndexChanged(object sender, EventArgs e)
        {
            //if (txtConfig.Text.Length == 0)
            if (cboType.SelectedIndex == 2 || cboType.SelectedIndex == 4)
            {
                RegisteredAgent ra = (from r in RegisteredAgentCache.Agents
                                      where r.ClassName.EndsWith(cboClass.Text)
                                      select r).FirstOrDefault();
                if (ra != null)
                {
                    IAgent a;

                    if (ra.IsCollector)
                    {
                        a = CollectorHost.CreateCollectorFromClassName(ra.ClassName.Replace("QuickMon.Collectors.", ""));
                    }
                    else
                    {
                        a = NotifierHost.CreateNotifierFromClassName(ra.ClassName.Replace("QuickMon.Notifiers.", ""));
                    }
                    if (a != null)
                    {
                        string agentConfig = a.AgentConfig.GetDefaultOrEmptyXml();
                        if (cboType.SelectedIndex == 2)
                        {
                            txtConfig.Text = Properties.Resources.BlankTemplateCollectorAgent.Replace("{0}", agentConfig);
                        }
                        else if (cboType.SelectedIndex == 4)
                        {
                            txtConfig.Text = Properties.Resources.BlankTemplateNotifierAgent.Replace("{0}", agentConfig);
                        }
                        //txtConfig.Text = XmlFormattingUtils.NormalizeXML(txtConfig.Text);
                        try
                        {
                            txtConfig.Text = txtConfig.Text.BeautifyXML(); // XmlFormattingUtils.NormalizeXML(txtConfig.Text);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(string.Format("Error formatting xml\r\n{0}", ex.Message), "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        }
                    }
                }
            }
            IsSaveEnabled();
        }
Exemple #5
0
 private void LoadCollectors(TreeNode parent, CollectorHost collector, string indentation)
 {
     foreach (CollectorHost childCollector in (from c in HostingMonitorPack.CollectorHosts
                                               where c.ParentCollectorId == collector.UniqueId
                                               select c))
     {
         TreeNode tnode = new TreeNode(indentation + childCollector.Name);
         tnode.Tag = childCollector;
         if (editingNotifierHost.AlertForCollectors.Contains(childCollector.Name))
         {
             tnode.Checked = true;
         }
         //if (childCollector.CollectorAgents.Count() == 0)
         //    lvi.ImageIndex = folderImgIndex;
         //else
         tnode.ImageIndex = collectorImgIndex;
         parent.Nodes.Add(tnode);
         LoadCollectors(tnode, childCollector, indentation + indentationChars);
     }
 }
Exemple #6
0
        //Form initialize
        public Form1()
        {
            conf = new XmlConfigurator(Settings.Default.ConfigurationFilePath);
            conf.Load();              // TODO: показать информацию о том что сейчас идет загрузка конфигурации

            // TODO: Сгенерировать элементы GUI в зависимости от конфигурации
            // напр.: перечислить в списке доступных устройств, только те для которых
            // налични данные в конфигурации

            InitializeComponent();

            host = new CollectorHost(conf);

            // событие которое оповещает о наличие информация для
            // запис в текстовое поле вывода
            host.OutputPending += HandleOutputPending;

            host.Started += HandleStarted;
            host.Stopped += HandleStopped;

            // При закрывание формы удаляем хост и конфигурацию
            this.FormClosing += HandleFormClosing;
        }
Exemple #7
0
        private void cboClass_SelectedIndexChanged(object sender, EventArgs e)
        {
            //if (txtConfig.Text.Length == 0)
            if (cboType.SelectedIndex == 2 || cboType.SelectedIndex == 4)
            {
                RegisteredAgent ra = (from r in RegisteredAgentCache.Agents
                                      where r.ClassName.EndsWith(cboClass.Text)
                                      select r).FirstOrDefault();
                if (ra != null)
                {
                    IAgent a;

                    if (ra.IsCollector)
                    {
                        a = CollectorHost.CreateCollectorFromClassName(ra.ClassName.Replace("QuickMon.Collectors.", ""));
                    }
                    else
                    {
                        a = NotifierHost.CreateNotifierFromClassName(ra.ClassName.Replace("QuickMon.Notifiers.", ""));
                    }
                    if (a != null)
                    {
                        string agentConfig = a.AgentConfig.GetDefaultOrEmptyXml();
                        if (cboType.SelectedIndex == 2)
                        {
                            txtConfig.Text = Properties.Resources.BlankTemplateCollectorAgent.Replace("{0}", agentConfig);
                        }
                        else if (cboType.SelectedIndex == 4)
                        {
                            txtConfig.Text = Properties.Resources.BlankTemplateNotifierAgent.Replace("{0}", agentConfig);
                        }
                        txtConfig.Text = XmlFormattingUtils.NormalizeXML(txtConfig.Text);
                    }
                }
            }
            IsSaveEnabled();
        }
Exemple #8
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());
            }
        }
        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();
            }
        }
Exemple #10
0
 private void cmdOK_Click(object sender, EventArgs e)
 {
     if (lvwAgentType.SelectedItems.Count == 1)
     {
         RegisteredAgent ra          = null;
         string          configToUse = "";
         if (lvwAgentType.SelectedItems[0].Tag is RegisteredAgent)
         {
             ra           = (RegisteredAgent)lvwAgentType.SelectedItems[0].Tag;
             TemplateUsed = false;
         }
         else if (lvwAgentType.SelectedItems[0].Tag is QuickMonTemplate)
         {
             QuickMonTemplate template = (QuickMonTemplate)lvwAgentType.SelectedItems[0].Tag;
             ra           = RegisteredAgentCache.GetRegisteredAgentByClassName(template.ForClass, selectingCollectors);
             configToUse  = template.Config;
             TemplateUsed = true;
         }
         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.Replace("QuickMon.Collectors.", "").Replace("QuickMon.Notifiers.", "");
                 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() == System.Windows.Forms.DialogResult.OK)
                     {
                         configToUse = editor.SelectedMarkup;
                     }
                 }
                 try
                 {
                     if (selectingCollectors && configToUse.StartsWith("<collectorAgent"))
                     {
                         SelectedAgent = CollectorHost.GetCollectorAgentFromString(configToUse);
                     }
                     else if (!selectingCollectors && configToUse.StartsWith("<notifierAgent"))
                     {
                         SelectedAgent = NotifierHost.GetNotifierAgentFromString(configToUse);
                     }
                     else
                     {
                         SelectedAgent.AgentConfig.FromXml(configToUse);
                     }
                     DialogResult = System.Windows.Forms.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);
                 }
             }
         }
     }
 }