Example #1
0
        public override MonitorState GetState()
        {
            MonitorState  returnState         = new MonitorState();
            StringBuilder plainTextDetails    = new StringBuilder();
            StringBuilder htmlTextTextDetails = new StringBuilder();
            string        lastAction          = "Getting Suspended counts";
            int           instancesSuspended  = 0;

            try
            {
                BizTalkSuspendedCountCollectorConfigEntry currentConfig = (BizTalkSuspendedCountCollectorConfigEntry)((ICollectorConfig)AgentConfig).Entries[0];
                lastAction         = string.Format("Getting BizTalk Ports and Orchestration Details for {0}.{1}", currentConfig.SqlServer, currentConfig.MgmtDBName);
                instancesSuspended = currentConfig.GetSuspendedMsgsCount();

                if (instancesSuspended < currentConfig.InstancesWarning)
                {
                    returnState.State = CollectorState.Good;
                }
                else if (instancesSuspended >= currentConfig.InstancesError)
                {
                    returnState.State = CollectorState.Error;
                }
                else
                {
                    returnState.State = CollectorState.Warning;
                }

                if (instancesSuspended > 0)
                {
                    plainTextDetails.AppendLine(string.Format("Total suspended count: {0}\r\n", instancesSuspended));
                    htmlTextTextDetails.AppendLine(string.Format("<b>Total suspended count:</b> {0}<hr />\r\n", instancesSuspended));

                    if (returnState.State != CollectorState.Good && currentConfig.ShowLastXDetails > 0)
                    {
                        AgentMultiFormatInfoMsg info = currentConfig.GetLastXDetails();
                        plainTextDetails.AppendLine(info.RawText);
                        htmlTextTextDetails.AppendLine(info.HTMLText);
                    }
                }
                else
                {
                    plainTextDetails.AppendLine("No suspended instances");
                    htmlTextTextDetails.AppendLine("No suspended instances");
                }
                returnState.RawDetails   = plainTextDetails.ToString().TrimEnd('\r', '\n');
                returnState.HtmlDetails  = htmlTextTextDetails.ToString();
                returnState.CurrentValue = instancesSuspended;
            }
            catch (Exception ex)
            {
                returnState.RawDetails  = string.Format("Last step: '{0}\r\n{1}", lastAction, ex.Message);
                returnState.HtmlDetails = string.Format("<blockquote>Last step: '{0}<br />{1}</blockquote>", lastAction, ex.Message);
                returnState.State       = CollectorState.Error;
            }
            return(returnState);
        }
Example #2
0
        public override MonitorState RefreshState()
        {
            MonitorState returnState        = new MonitorState();
            string       lastAction         = "";
            int          instancesSuspended = 0;

            try
            {
                BizTalkSuspendedCountCollectorConfig currentConfig = (BizTalkSuspendedCountCollectorConfig)AgentConfig;
                if (currentConfig.Entries.Count == 1)
                {
                    BizTalkSuspendedCountCollectorConfigEntry entry = (BizTalkSuspendedCountCollectorConfigEntry)currentConfig.Entries[0];

                    returnState.RawDetails   = string.Format("BizTalk Managament DB: {0}", entry.Description);
                    returnState.HtmlDetails  = string.Format("<b>BizTalk Managament DB: {0}</b>", entry.Description);
                    returnState.CurrentValue = "None";

                    instancesSuspended = entry.GetSuspendedMsgsCount();
                    if (instancesSuspended < entry.InstancesWarning)
                    {
                        returnState.State = CollectorState.Good;
                    }
                    else if (instancesSuspended >= entry.InstancesError)
                    {
                        returnState.State = CollectorState.Error;
                    }
                    else
                    {
                        returnState.State = CollectorState.Warning;
                    }
                    if (instancesSuspended > 0)
                    {
                        returnState.ForAgent     = entry.Description;
                        returnState.CurrentValue = instancesSuspended;
                        MonitorState suspendedIstancesState = new MonitorState()
                        {
                            RawDetails  = "Suspended instances",
                            HtmlDetails = "<b>Suspended instances</b>"
                        };
                        foreach (SuspendedInstance si in entry.GetTopXSuspendedInstanced())
                        {
                            suspendedIstancesState.ChildStates.Add(
                                new MonitorState()
                            {
                                RawDetails  = si.ToString(),
                                HtmlDetails = si.ToString(true)
                            });
                        }
                        returnState.ChildStates.Add(suspendedIstancesState);
                    }
                }
                else
                {
                    returnState.State       = CollectorState.Error;
                    returnState.RawDetails  = "Configuration not set";
                    returnState.HtmlDetails = "Configuration not set";
                }
            }
            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);
        }