Exemple #1
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("Web service", typeof(string)));
                dt.Columns.Add(new System.Data.DataColumn("Response", typeof(string)));

                WSCollectorConfig currentConfig = (WSCollectorConfig)AgentConfig;
                foreach (WSCollectorConfigEntry entry in currentConfig.Entries)
                {
                    object wsData = "N/A";
                    try
                    {
                        wsData = entry.RunMethod();
                    }
                    catch (Exception ex)
                    {
                        wsData = ex.Message;
                    }
                    dt.Rows.Add(entry.Description, wsData.ToString());
                }
            }
            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);
        }
Exemple #2
0
 public WSCollector()
 {
     AgentConfig = new WSCollectorConfig();
 }
Exemple #3
0
        public override MonitorState RefreshState()
        {
            MonitorState returnState = new MonitorState();
            string       lastAction  = "";
            int          errors      = 0;
            int          warnings    = 0;
            int          success     = 0;

            try
            {
                WSCollectorConfig currentConfig = (WSCollectorConfig)AgentConfig;
                returnState.RawDetails  = string.Format("Calling {0} services", currentConfig.Entries.Count);
                returnState.HtmlDetails = string.Format("<b>Calling {0} services</b>", currentConfig.Entries.Count);
                foreach (WSCollectorConfigEntry entry in currentConfig.Entries)
                {
                    CollectorState currentState = CollectorState.NotAvailable;
                    object         wsData       = "N/A";
                    try
                    {
                        lastAction   = "Running Web Service " + entry.Description;
                        wsData       = entry.RunMethod();
                        lastAction   = "Checking states of " + entry.Description;
                        currentState = entry.GetState(wsData);
                        lastAction   = entry.LastFormattedValue;
                    }
                    catch (Exception wsException)
                    {
                        currentState = CollectorState.Error;
                        lastAction   = wsException.Message;
                        wsData       = wsException.Message;
                    }
                    if (wsData == null)
                    {
                        wsData = "N/A";
                    }
                    if (currentState == CollectorState.Error)
                    {
                        errors++;
                        returnState.ChildStates.Add(
                            new MonitorState()
                        {
                            ForAgent     = entry.Description,
                            State        = CollectorState.Error,
                            CurrentValue = wsData.ToString() //,
                                                             //RawDetails = string.Format("'{0}' (Error)", wsData.ToString()),
                                                             //HtmlDetails = string.Format("'{0}' (<b>Error</b>)", wsData.ToString())
                        });
                    }
                    else if (currentState == CollectorState.Warning)
                    {
                        warnings++;
                        returnState.ChildStates.Add(
                            new MonitorState()
                        {
                            ForAgent     = entry.Description,
                            State        = CollectorState.Warning,
                            CurrentValue = wsData.ToString() //,
                                                             //RawDetails = string.Format("'{0}' (Warning)", wsData.ToString()),
                                                             //HtmlDetails = string.Format("'{0}' (<b>Warning</b>)", wsData.ToString())
                        });
                    }
                    else
                    {
                        success++;
                        returnState.ChildStates.Add(
                            new MonitorState()
                        {
                            ForAgent     = entry.Description,
                            State        = CollectorState.Good,
                            CurrentValue = wsData.ToString() //,
                                                             //RawDetails = string.Format("'{0}'", wsData.ToString()),
                                                             //HtmlDetails = string.Format("'{0}'", wsData.ToString())
                        });
                    }
                }
                //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);
        }