public override void LoadDisplayData()
 {
     if (Collector != null && Collector.AgentConfig != null && ((ServiceStateCollectorConfig)Collector.AgentConfig).Entries != null)
     {
         ServiceStateCollectorConfig ssc = (ServiceStateCollectorConfig)Collector.AgentConfig;
         lvwEntries.Items.Clear();
         foreach (ServiceStateDefinition serviceDefinition in (from ServiceStateDefinition s in ssc.Entries
                                                               orderby s.MachineName
                                                               select s))
         {
             ListViewGroup group = new ListViewGroup(serviceDefinition.MachineName);
             lvwEntries.Groups.Add(group);
             foreach (ServiceStateServiceEntry serviceEntry in (from s in serviceDefinition.SubItems
                                                                orderby s.Description
                                                                select s))
             {
                 ListViewItem lvi = new ListViewItem(serviceEntry.Description);
                 lvi.Group      = group;
                 lvi.ImageIndex = 3;
                 lvi.Tag        = serviceEntry;
                 lvwEntries.Items.Add(lvi);
             }
         }
     }
 }
        private void LoadTree()
        {
            if (SelectedConfig != null)
            {
                try
                {
                    ServiceStateCollectorConfig currentConfig = (ServiceStateCollectorConfig)SelectedConfig;
                    foreach (ServiceStateDefinition entry in currentConfig.Entries)
                    {
                        TreeNode machineTreeNode = treeConfig.Nodes.Add(entry.MachineName, entry.MachineName);
                        machineTreeNode.ImageIndex = 0;

                        foreach (ServiceStateServiceEntry serviceEntry in entry.SubItems)
                        {
                            TreeNode serviceTreeNode = machineTreeNode.Nodes.Add(entry.MachineName + "\\" + serviceEntry.Description, serviceEntry.Description);
                            serviceTreeNode.ImageIndex         = 1;
                            serviceTreeNode.SelectedImageIndex = 1;
                            serviceTreeNode.Tag = serviceEntry;
                        }
                        machineTreeNode.Expand();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
        private void cmdOK_Click(object sender, EventArgs e)
        {
            if (SelectedConfig == null)
            {
                SelectedConfig = new ServiceStateCollectorConfig();
            }
            ((ServiceStateCollectorConfig)SelectedConfig).Entries.Clear();
            foreach (TreeNode machineTreeNode in treeConfig.Nodes)
            {
                ServiceStateDefinition ssd = new ServiceStateDefinition();
                ssd.MachineName = machineTreeNode.Text;
                ssd.SubItems    = new List <ICollectorConfigSubEntry>();

                foreach (TreeNode serviceTreeNode in machineTreeNode.Nodes)
                {
                    ssd.SubItems.Add(new ServiceStateServiceEntry()
                    {
                        Description = serviceTreeNode.Text
                    });
                }
                ((ServiceStateCollectorConfig)SelectedConfig).Entries.Add(ssd);
            }
            DialogResult = DialogResult.OK;
            Close();
        }
Пример #4
0
        public override MonitorState GetState()
        {
            MonitorState  returnState         = new MonitorState();
            StringBuilder plainTextDetails    = new StringBuilder();
            StringBuilder htmlTextTextDetails = new StringBuilder();
            string        lastAction          = "";
            int           errors   = 0;
            int           warnings = 0;
            int           success  = 0;

            try
            {
                ServiceStateCollectorConfig currentConfig = (ServiceStateCollectorConfig)AgentConfig;
                foreach (ServiceStateDefinition ssd in currentConfig.Entries)
                {
                    lastAction = "Checking services on " + ssd.MachineName;
                    var serviceStates = ssd.GetServiceStates();
                    lastAction = "Checking service states of " + ssd.MachineName;
                    CollectorState currentState = ssd.GetState(serviceStates);


                    if (currentState == CollectorState.Error)
                    {
                        errors++;
                        plainTextDetails.AppendLine(string.Format("Error: {0}", ssd.MachineName));
                        htmlTextTextDetails.AppendLine(string.Format("<b>Error</b>: {0}", ssd.MachineName));
                    }
                    else if (currentState == CollectorState.Warning)
                    {
                        warnings++;
                        plainTextDetails.AppendLine(string.Format("Warning: {0}", ssd.MachineName));
                        htmlTextTextDetails.AppendLine(string.Format("<i>Warning</i>: {0}", ssd.MachineName));
                    }
                    else
                    {
                        success++;
                        plainTextDetails.AppendLine(string.Format("Success: {0}", ssd.MachineName));
                        htmlTextTextDetails.AppendLine(string.Format("Success: {0}", ssd.MachineName));
                    }
                    foreach (ServiceStateInfo serviceEntry in serviceStates)
                    {
                        plainTextDetails.AppendLine(string.Format("\t{0}: {1}", serviceEntry.DisplayName, serviceEntry.Status));
                        htmlTextTextDetails.AppendLine("<ul>");
                        if (serviceEntry.Status != System.ServiceProcess.ServiceControllerStatus.Running)
                        {
                            htmlTextTextDetails.AppendLine(string.Format("<li>{0}: <b>{1}</b></li>", serviceEntry.DisplayName, serviceEntry.Status));
                        }
                        else
                        {
                            htmlTextTextDetails.AppendLine(string.Format("<li>{0}: {1}</li>", serviceEntry.DisplayName, serviceEntry.Status));
                        }
                        htmlTextTextDetails.AppendLine("</ul>");
                    }
                }
                returnState.RawDetails  = plainTextDetails.ToString().TrimEnd('\r', '\n');
                returnState.HtmlDetails = htmlTextTextDetails.ToString();

                if (errors > 0 && warnings == 0 && success == 0) // all errors
                {
                    returnState.State = CollectorState.Error;
                }
                else if (errors > 0 || warnings > 0) //any error or warnings
                {
                    returnState.State = CollectorState.Warning;
                }
                else
                {
                    returnState.State = CollectorState.Good;
                }
            }
            catch (Exception ex)
            {
                returnState.RawDetails  = ex.Message;
                returnState.HtmlDetails = string.Format("<p><b>Last action:</b> {0}</p><blockquote>{1}</blockquote>", lastAction, ex.Message);
                returnState.State       = CollectorState.Error;
            }

            return(returnState);
        }
Пример #5
0
 public ServiceStateCollector()
 {
     AgentConfig = new ServiceStateCollectorConfig();
 }