예제 #1
0
 protected void OnArtifactStatusChanged(ArtifactMonitoringEventArgs e)
 {
     if (ArtifactStatusChanged != null)
     {
         ArtifactStatusChanged(this, e);
     }
 }
예제 #2
0
        /// <summary>
        /// Event handler for WMI events
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void monitor_ArtifactStatusChanged(object sender, ArtifactMonitoringEventArgs e)
        {
            try
            {
                int smtp_email_port = 25;
                bool smtp_email_ssl = false;
                string smtp_email_host = string.Empty;
                string smtp_email_username = string.Empty;
                string smtp_email_userpwd = string.Empty;
                string smtp_email_subject = string.Empty;
                string smtp_email_rcpnt = string.Empty;
                string smtp_email_title = "BizTalk Control Center (BCC) - Alert Notification";
                string mailSubject = "BCC Agent notification [" + Environment.MachineName + "]";

                string mailMessage = HtmlEmailHelper.FormatContent(e, smtp_email_title);

                if (!IsLocalEmailFlag)
                {
                    try
                    {
                        // Read monitoring list
                        BCCMonitoringDataAccess da = new BCCMonitoringDataAccess();

                        // Receive Port
                        if (e.ArtifactType == ArtifactType.ReceivePort)
                        {
                            da.LogMonitoringData(e.ArtifactType, e.ReceiveLocationName, e.ArtifactStatus);
                        }
                        // Host Instance
                        else if (e.ArtifactType == ArtifactType.HostInstance)
                        {
                            da.LogMonitoringData(e.ArtifactType, e.HostName, e.ArtifactStatus);
                        }
                        // Service Instance
                        else if (e.ArtifactType == ArtifactType.ServiceInstance)
                        {
                            da.LogMonitoringData(e.ArtifactType, e.ServerName, e.ArtifactStatus);
                        }
                        // Send Port
                        else
                        {
                            da.LogMonitoringData(e.ArtifactType, e.ArtifactName, e.ArtifactStatus);
                        }
                    }
                    catch (Exception exception)
                    {
                        WriteToEventLog(exception.Message + exception.StackTrace);
                    }

                    // Send email
                    EmailHelper helper = new EmailHelper(BCC_AGENT_CONFIG_SPEEDCODE);

                    mailMessage = HtmlEmailHelper.FormatContent(e, helper.EmailTitle);
                    mailSubject = helper.EmailSubject.Replace("$machineName", Environment.MachineName);

                    helper.SendMail(mailSubject, mailMessage, false);

                    WriteToEventLog("Mail message:" + mailMessage);
                }
                else // Use local SMTP settings
                {
                    SmtpSection smtpSection = ConfigurationManager.GetSection("system.net/mailSettings/smtp") as SmtpSection;

                    // Get the from email of the config file
                    smtp_email_username = smtpSection.From;
                    // Get the to address from the app settings
                    smtp_email_rcpnt = ConfigurationManager.AppSettings["EmailRecipients"].ToString();
                    // Get the host name from the smtp section
                    smtp_email_host = smtpSection.Network.Host;

                    EmailHelper helper = new EmailHelper(smtp_email_port, smtp_email_ssl, smtp_email_host, smtp_email_username, smtp_email_userpwd, smtp_email_rcpnt, smtp_email_title, false);
                    helper.SendMail(mailSubject, mailMessage, true);
                }
            }
            catch (Exception exception)
            {
                WriteToEventLog(exception.Message + exception.StackTrace);
            }
        }
예제 #3
0
 static void x_PortStatusChanged(object sender, ArtifactMonitoringEventArgs e)
 {
     Console.WriteLine("ArtifactName:" + e.ArtifactName);
     Console.WriteLine("ArtifactURL:" + e.ArtifactURL);
     Console.WriteLine("ArtifactStatus:" + e.ArtifactStatus);
     Console.WriteLine("ReceiveLocationName:" + e.ReceiveLocationName);
     Console.WriteLine("HostName:" + e.HostName);
     Console.WriteLine("ServerName:" + e.ServerName);
 }
예제 #4
0
 protected void x_PortStatusChanged(object sender, ArtifactMonitoringEventArgs e)
 {
     lblInfo.Text = "Artifact Name: " + e.ArtifactName + " Status:" + e.ArtifactStatus;
     System.Diagnostics.Debug.Write(lblInfo.Text, "ASP.NET");
 }
        public static string FormatContent(ArtifactMonitoringEventArgs e, string tableHeaderTitle)
        {
            StringBuilder htmlBody = new StringBuilder(
            "<html xmlns=\"http://www.w3.org/1999/xhtml\">"
            + "<head><title></title>"
            + "<style type=\"text/css\">"
            + ".itemStyle { color:#FDD017;background-color:#525252;width:35%;}"
            + "</style>"
            + "</head>"
            + "<body style=\"font-family: Verdana; font-size: x-small; background-color: #C0C0C0;\">"
            + "<table cellspacing=\"0\" cellpadding=\"4\" border=\"1\" style=\"font-family:Verdana;font-size:x-small;color:#333333;width:100%;border-collapse:collapse;\" bgcolor=\"#FFFFCC\">"
            + "<thead><tr class=\"itemStyle\"><th colspan=\"2\">" + tableHeaderTitle + "</th></tr></thead>");

            // BizTalk Artifact type
            htmlBody.Append("<tr><td class=\"itemStyle\">BizTalk Artifact Type</td><td>" + Enum.GetName(typeof(ArtifactType), e.ArtifactType) + "</td></tr>");

            if (e.ArtifactType != ArtifactType.EventLog)
            {
                if (e.ArtifactName != string.Empty)
                {
                    htmlBody.Append("<tr><td class=\"itemStyle\">BizTalk Artifact Name</td><td style='word-break:break-all;'>" + e.ArtifactName + "</td></tr>");
                }

                if (e.ArtifactStatus != string.Empty)
                {
                    string markup = string.Empty;

                    if ((e.ArtifactStatus.Equals("Bound")
                        || e.ArtifactStatus.Equals("Enlisted")
                        || e.ArtifactStatus.Equals("Unenlisted")
                        || e.ArtifactStatus.Equals("Disabled")
                        || e.ArtifactStatus.Equals("Stopped")
                        || e.ArtifactStatus.Contains("Suspended")
                        || e.ArtifactStatus.Equals("Unknown")))
                    {
                        markup = "<b><font color=\"Red\">" + e.ArtifactStatus + "</font></b>";
                    }
                    else
                    {
                        markup = "<b><font color=\"Green\">" + e.ArtifactStatus + "</font></b>";
                    }

                    htmlBody.Append("<tr><td class=\"itemStyle\">BizTalk Artifact Status</td><td>" + markup + "</td></tr>");
                }

                if (e.ArtifactURL != string.Empty)
                {
                    htmlBody.Append("<tr><td class=\"itemStyle\">BizTalk Artifact URL</td><td>" + e.ArtifactURL + "</td></tr>");
                }

                if (e.HostName != string.Empty)
                {
                    htmlBody.Append("<tr><td class=\"itemStyle\">BizTalk Host Name</td><td>" + e.HostName + "</td></tr>");
                }

                if (e.ServerName != string.Empty)
                {
                    htmlBody.Append("<tr><td class=\"itemStyle\">BizTalk Server Name</td><td>" + e.ServerName + "</td></tr>");
                }

                if (e.ReceiveLocationName != string.Empty)
                {
                    htmlBody.Append("<tr><td class=\"itemStyle\">BizTalk Receive location name</td><td>" + e.ReceiveLocationName + "</td></tr>");
                }
            }
            else
            {
                if (e.ArtifactName != string.Empty)
                {
                    htmlBody.Append("<tr><td class=\"itemStyle\">NT Eventlog logfile</td><td>" + e.ArtifactName + "</td></tr>");
                }

                if (e.ArtifactStatus != string.Empty)
                {
                    string markup = string.Empty;

                    if (e.ArtifactStatus.Equals("Error"))
                    {
                        markup = "<b><font color=\"Red\">" + e.ArtifactStatus + "</font></b>";
                    }
                    else
                    {
                        markup = "<b><font color=\"Orange\">" + e.ArtifactStatus + "</font></b>";
                    }

                    htmlBody.Append("<tr><td class=\"itemStyle\">NT Event Type</td><td>" + markup + "</td></tr>");
                }

                if (e.ArtifactURL != string.Empty)
                {
                    htmlBody.Append("<tr><td class=\"itemStyle\">Event Message</td><td>" + e.ArtifactURL + "</td></tr>");
                }

                if (e.HostName != string.Empty)
                {
                    htmlBody.Append("<tr><td class=\"itemStyle\">Computer Name</td><td>" + e.HostName + "</td></tr>");
                }

                if (e.ServerName != string.Empty)
                {
                    htmlBody.Append("<tr><td class=\"itemStyle\">Server Name</td><td>" + e.ServerName + "</td></tr>");
                }
            }

            htmlBody.Append("<tr><td class=\"itemStyle\">Event timestamp</td><td>" + e.EventTimestamp.ToString("MMM-dd-yyyy hh:mm:ss tt") + "</td></tr>");

            htmlBody.Append("</table><ul><li>To enable/disable alert notifications, use speedcode '103'.</li><li>To manage BCC Alert service, use speedcode '604'.</li></ul></body></html>");

            return htmlBody.ToString();
        }