コード例 #1
0
 public override void LoadDisplayData()
 {
     if (Collector != null)
     {
         DirectoryServicesQueryCollectorConfig wmiConfig = (DirectoryServicesQueryCollectorConfig)Collector.AgentConfig;
         lvwResults.Items.Clear();
         foreach (DirectoryServicesQueryCollectorConfigEntry dsQueryEntry in wmiConfig.Entries)
         {
             ListViewItem lvi = new ListViewItem(dsQueryEntry.Name);
             lvi.SubItems.Add("");
             lvi.Tag = dsQueryEntry;
             lvwResults.Items.Add(lvi);
         }
         lvwResults.AutoResizeColumnIndex   = 1;
         lvwResults.AutoResizeColumnEnabled = true;
     }
     base.LoadDisplayData();
 }
コード例 #2
0
        public override List <System.Data.DataTable> GetDetailDataTables()
        {
            List <System.Data.DataTable> tables = new List <System.Data.DataTable>();

            System.Data.DataTable dt = new System.Data.DataTable();
            try
            {
                //dt.Columns.Add(new System.Data.DataColumn("Query name", typeof(string)));
                //dt.Columns.Add(new System.Data.DataColumn("Response", typeof(string)));

                DirectoryServicesQueryCollectorConfig currentConfig = (DirectoryServicesQueryCollectorConfig)AgentConfig;
                foreach (DirectoryServicesQueryCollectorConfigEntry entry in currentConfig.Entries)
                {
                    tables.Add(entry.GetQueryDataTable());

                    //object output = "N/A";
                    //try
                    //{
                    //    //entry.UseRowCountAsValue
                    //    output = entry.RunQuery();
                    //}
                    //catch (Exception ex)
                    //{
                    //    output = ex.Message;
                    //}
                    //dt.Rows.Add(entry.Name, output);
                }
            }
            catch (Exception ex)
            {
                dt = new System.Data.DataTable("Exception");
                dt.Columns.Add(new System.Data.DataColumn("Text", typeof(string)));
                dt.Rows.Add(ex.ToString());
                tables.Add(dt);
            }

            return(tables);
        }
コード例 #3
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
            {
                DirectoryServicesQueryCollectorConfig dsQueryConfig = (DirectoryServicesQueryCollectorConfig)AgentConfig;
                plainTextDetails.AppendLine(string.Format("Running {0} Directory Services queries", dsQueryConfig.Entries.Count));
                htmlTextTextDetails.AppendLine(string.Format("<i>Running {0} Directory Services queries'</i>", dsQueryConfig.Entries.Count));
                htmlTextTextDetails.AppendLine("<ul>");
                StringBuilder sbTotalResults = new StringBuilder();
                foreach (DirectoryServicesQueryCollectorConfigEntry dsQueryEntry in dsQueryConfig.Entries)
                {
                    lastAction = string.Format("Running Directory Services query for {0} - ", dsQueryEntry.Name);
                    sbTotalResults.AppendLine(dsQueryEntry.Name);
                    plainTextDetails.Append(string.Format("\t{0} - ", dsQueryEntry.Name));
                    htmlTextTextDetails.Append(string.Format("<li>{0} - ", dsQueryEntry.Name));

                    object         queryResult  = dsQueryEntry.RunQuery();
                    CollectorState currentState = dsQueryEntry.GetState(queryResult);
                    if (currentState == CollectorState.Error)
                    {
                        errors++;
                        plainTextDetails.AppendLine(string.Format("\t\tQuery '{0}' - Error\r\n\t\t Result: '{1}'", dsQueryEntry.Name, FormatUtils.N(queryResult, "[null]")));
                        htmlTextTextDetails.AppendLine(string.Format("<li>Query '{0}' - <b>Error</b><br>Result: <blockquote>{1}</blockquote></li>", dsQueryEntry.Name, FormatUtils.N(queryResult, "[null]")));
                    }
                    else if (currentState == CollectorState.Warning)
                    {
                        warnings++;
                        plainTextDetails.AppendLine(string.Format("\t\tQuery '{0}' - Warning\r\n\t\t Result: '{1}'", dsQueryEntry.Name, FormatUtils.N(queryResult, "[null]")));
                        htmlTextTextDetails.AppendLine(string.Format("<li>Query '{0}' - <b>Warning</b><br>Result: <blockquote>{1}</blockquote></li>", dsQueryEntry.Name, FormatUtils.N(queryResult, "[null]")));
                    }
                    else
                    {
                        success++;
                        plainTextDetails.AppendLine(string.Format("\t\tQuery '{0}'\r\n\t\t Result: '{1}'", dsQueryEntry.Name, FormatUtils.N(queryResult, "[null]")));
                        htmlTextTextDetails.AppendLine(string.Format("<li>Query '{0}'<br>Result: <blockquote>{1}</blockquote></li>", dsQueryEntry.Name, FormatUtils.N(queryResult, "[null]")));
                    }
                    if (queryResult != null)
                    {
                        sbTotalResults.AppendLine(queryResult.ToString());
                    }
                    else
                    {
                        sbTotalResults.AppendLine("[null]");
                    }
                }

                htmlTextTextDetails.AppendLine("</ul>");
                returnState.RawDetails   = plainTextDetails.ToString().TrimEnd('\r', '\n');
                returnState.HtmlDetails  = htmlTextTextDetails.ToString();
                returnState.CurrentValue = sbTotalResults.ToString();
                if (errors > 0 && warnings == 0 && success == 0)
                {
                    returnState.State = CollectorState.Error;
                }
                else if (errors > 0 || warnings > 0)
                {
                    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);
        }
コード例 #4
0
 public DirectoryServicesQueryCollector()
 {
     AgentConfig = new DirectoryServicesQueryCollectorConfig();
 }
コード例 #5
0
        public override MonitorState RefreshState()
        {
            MonitorState returnState = new MonitorState();
            string       lastAction  = "";
            int          errors      = 0;
            int          warnings    = 0;
            int          success     = 0;

            try
            {
                DirectoryServicesQueryCollectorConfig currentConfig = (DirectoryServicesQueryCollectorConfig)AgentConfig;
                returnState.RawDetails  = string.Format("Running {0} queries", currentConfig.Entries.Count);
                returnState.HtmlDetails = string.Format("<b>Running {0} queries</b>", currentConfig.Entries.Count);
                foreach (DirectoryServicesQueryCollectorConfigEntry entry in currentConfig.Entries)
                {
                    CollectorState currentState = CollectorState.NotAvailable;
                    object         output       = "N/A";
                    try
                    {
                        lastAction   = "Running query " + entry.Name;
                        output       = entry.RunQuery();
                        lastAction   = "Checking states of " + entry.Name;
                        currentState = entry.GetState(output);
                        lastAction   = output.ToString();
                    }
                    catch (Exception wsException)
                    {
                        currentState = CollectorState.Error;
                        lastAction   = wsException.Message;
                        output       = wsException.Message;
                    }
                    if (output == null)
                    {
                        output = "N/A";
                    }
                    if (currentState == CollectorState.Error)
                    {
                        errors++;
                        returnState.ChildStates.Add(
                            new MonitorState()
                        {
                            ForAgent     = entry.Name,
                            State        = CollectorState.Error,
                            CurrentValue = output //,
                                                  //RawDetails = string.Format("'{0}' (Error)", output),
                                                  //HtmlDetails = string.Format("'{0}' (<b>Error</b>)", output)
                        });
                    }
                    else if (currentState == CollectorState.Warning)
                    {
                        warnings++;
                        returnState.ChildStates.Add(
                            new MonitorState()
                        {
                            ForAgent     = entry.Name,
                            State        = CollectorState.Warning,
                            CurrentValue = output //,
                                                  //RawDetails = string.Format("'{0}' (Warning)", output),
                                                  //HtmlDetails = string.Format("'{0}' (<b>Warning</b>)", output)
                        });
                    }
                    else
                    {
                        success++;
                        returnState.ChildStates.Add(
                            new MonitorState()
                        {
                            ForAgent     = entry.Name,
                            State        = CollectorState.Good,
                            CurrentValue = output //,
                                                  //RawDetails = string.Format("'{0}'", output),
                                                  //HtmlDetails = string.Format("'{0}'", output)
                        });
                    }
                }
                //returnState.CurrentValue = pingTotalTime;

                if (errors > 0 && warnings == 0 && success == 0) // any errors
                {
                    returnState.State = CollectorState.Error;
                }
                else if (errors > 0 || warnings > 0) //any 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);
        }