BizTalk DevOps: Monitor your BizTalk environment using PowerShell – How to schedule Message Box Viewer or BizTalk Health Monitor and customize notification alerts with PowerShell

There are several ways that you can integrate and schedule Message Box Viewer or BizTalk Health Monitor, since Message Box Viewer (aka MBV) is deprecated, and it is now replaced by BizTalk Health Monitor (aka BHM).

The first option is to use BHM itself, for that, if you have BHM integrated with BizTalk Administration Console (see how-to here):

  • Open BizTalk Administration Console, expand BizTalk Health Monitor
  • And then right-click on “Default” profile (or your custom profile) and select “Settings…”
  • On the Monitoring Profile Settings – [Profile name] windows
    • Select “Schedule” panel and define your schedule
BizTalk Healt Monitor Scheduler options
  • And then select “Notifications” panel to “customize” the desired notifications and email settings. For example:
    • Mail notification or/and Eventlog Notifications
    • Send a mail only when critical warnings are raised
    • And the option to attach the complete report (compressed)
BizTalk-Healt-Monitor-Notification-options

Of course, by using the BHM, you can customize also the types of queries that you want to run and so on.

The second option is, for example, to use BizTalk360 by:

  • Click the “Settings” icon at the top of the page and then selecting “Message Box Viewer” option from the left menu bar.
  • On “Config and Schedule Message Box Viewer Integration” panel you need to:
    • In the “Message Box Viewer Download Directory” property: Enter the path to the MBV directory in the
    • In the “Schedule Execution” panel:
      • In the “Environment” property: leave the default or select your BTS environment for which the MBV execution has to be scheduled
      • In the “Days” and “Time” properties – Select the day and time when the MBV should run automatically.
      • And finally, click “Save” to save the configuration settings.
MessageBox Viewer BizTalk360 integration

However, I was trying to fully customize my notification warnings! And I want to receive an email notification if Warnings and Critical Warnings are raised but in some environments, special in small or test environments, I know that BizTalk machines are not fully configured as High Availability or according to all the best practices… sometimes these are limitations that you need to live with it. For example:

  • SSO DB: “Not Clustered (this DB is critical as it keeps encrypted ports properties)!” – for small environments sometimes I only have one BizTalk Machine so in this case, I don’t need, and I can’t, cluster the SSO. So, for me sometimes this is a false warning.
  • “MDF Db Growth for BizTalkMgmtDb” or “LOG Db Growth for BizTalkMgmtDb”: “Current =102400 KB (Def=1024 KB) – Recommended for this Db=1024 KB?!” – I have the MDF and LOG grow setting defined correctly but not according to the recommended setting of this tool, again, for me sometimes this is a false warning.
  • “LDF and MDF files Location for …”: “Same Drive (Can cause disk contention)!” – Again, sometimes the tool raises these warnings even if the location is different, so in certain cases, if I’m sure of the configurations I can consider this a false warning.
  • And so on…

Don’t get me wrong I love this tool but each time the report is generated, we need to make a review of the report and analyze what is real and what is “false” warnings, special the non-critical warnings. I want to be smarter and automate this task, just for fun, I decide to give it a try with PowerShell script.

So how can PowerShell help us?

With this script, you can be able to easily monitor the health of your BizTalk environment (engine and architecture) by scheduling Message Box Viewer(MBV) or BizTalk Health Monitor (BHM) and customize alerts using PowerShell.

Only if the script finds any critical warning (there are no conditions in critical warnings) or any non-critical warning that is not expected (what I may consider a “false” or expected warning) a mail notification will be sent.

Additional, if a notification mail is sent, I will also want to send the completed report (compressed) attached to the email.

This script allows you to set:

  • Set your email notification settings
 Set mail variables
 [STRING]$PSEmailServer = "mySMTPServer" #SMTP Server.
 [STRING]$SubjectPrefix = "MBV Notification Report -  "
 [STRING]$From = "biztalksupport@mail.pt"
 $EmailTo = ("sandro.pereira@devscope.net")
 
  • Set location settings – the location of the tool and where the reports are saved can be different
 Option to execute MBV
 $mbvPath = "C:\Users\Administrator\Desktop\powerShell\MBV\"
 Option to execute BHM
 $mbvPath = "C:\Program Files (x86)\BizTalk Support Tools\BHMv3.1\"
 $mbvReportSaveLocation = "C:\Users\Administrator\Desktop\powerShell\MBV\"
 
  • Critical errors we want to be notified (in this case all of them)
# Critical errors we want to be notified (in this case all of them)
if($xml.MSGBOXVIEWER.WARNINGSREPORT_RED.Count -gt 0)
{
    $mailBodyMsb += "<h3>Critical Warnings</h3> `n`n"

    Foreach ($criticalReport in $xml.MSGBOXVIEWER.WARNINGSREPORT_RED)
    {
        $countCriticalAlerts++;

        #Add mail content
        $mailBodyMsb += "<th><b>Critical Warning: " + $countCriticalAlerts + "</font></b></th>"
        $mailBodyMsb += "<table style='boder:0px 0px 0px 0px;'>"

        $mailBodyMsb += "<TR style='background-color:rgb(245,245,245);';><TD>Category</TD>"
        $mailBodyMsb += "<TD><b><font color='red'>" + $warningReport.Category + "</font><b></TD></TR>"
        
        $mailBodyMsb += "<TR style='background-color:white;'><TD>Item Caption</TD>"
        $mailBodyMsb += "<TD><b><font color='red'>" + $warningReport.ItemCaption + "</font><b></TD></TR>"
        
        $mailBodyMsb += "<TR style='background-color:rgb(245,245,245);';><TD>Details</TD>"
        $mailBodyMsb += "<TD>" + $warningReport.ItemValue + "</TD></TR>"

        $mailBodyMsb += "</table>"
        $mailBodyMsb += "<BR><BR>"
    }
}
  • Non-Critical errors we want to be notified – REPORT FILTER EXCLUSIONS
# Non-Critical errors we want to be notified - REPORT FILTER EXCLUSIONS
if($xml.MSGBOXVIEWER.WARNINGSREPORT_YELLOW.Count -gt 0)
{
    $mailBodyMsb += "<h3>Non Critical Warnings</h3> `n`n"

    Foreach ($warningReport in $xml.MSGBOXVIEWER.WARNINGSREPORT_YELLOW)
    {
        #####################################################################################
        # REPORT FILTER EXCLUSIONS
        #
        #Exclude from the report "false" warnings (like MDF Db Growth for) 
        #or warnings that you already know that you have and need to deal with it (like LDF and MDF files Location for)
        #or others that you want to exclude
        #####################################################################################
        if($warningReport.ItemCaption -eq "Errors during Collect")
        {
            continue;
        }

        if($warningReport.ItemCaption -eq "Class Settings Changed")
        {
            continue;
        }

        if(($warningReport.ItemCaption -Match "MDF Db Growth for") -or ($warningReport.ItemCaption -Match "LOG Db Growth for") -or ($warningReport.ItemCaption -Match "LDF and MDF files Location for"))
        {
            continue;
        }

        if(($warningReport.ItemCaption -Match "LDF files Location for BizTalkDTADb and BizTalkMsgBoxDb") -or ($warningReport.ItemCaption -Match "MDF files Location for BizTalkDTADb and BizTalkMsgBoxDb"))
        {
            continue;
        }

        if(($warningReport.ItemCaption -Match 'BizTalkServerApplication') -and ($warningReport.ItemValue -Match "Run Receive Location+Orchestration"))
        {
            continue;
        }

        if($warningReport.ItemCaption -Match 'SMS agent is running')
        {
            continue;
        }

        if($warningReport.ItemCaption -eq "Non WCF SQL adapter used in some Receive Locations")
        {
            continue;
        }

        if(($warningReport.ItemCaption -Match 'Server WH0') -and ($warningReport.ItemValue -Match "Running in VMware Virtual Platform "))
        {
            continue;
        }

        if($warningReport.ItemValue -eq "Custom or Third-party adapter !")
        {
            continue;
        }

        if($warningReport.ItemCaption -eq "'maxconnection' property")
        {
            continue;
        }
        #####################################################################################
        # Report Filter exclusions
        #####################################################################################

        $countWarningAlerts++;
        #Add mail content
        $mailBodyMsb += "<th><b>Warning: " + $countWarningAlerts + "</b></th>"
        $mailBodyMsb += "<table style='boder:0px 0px 0px 0px;'>"
        $mailBodyMsb += "<TR style='background-color:rgb(245,245,245);';><TD>Category</TD>"
        $mailBodyMsb += "<TD><b><font color='Orange'>" + $warningReport.Category + "</font><b></TD></TR>"
        
        $mailBodyMsb += "<TR style='background-color:white;'><TD>Item Caption</TD>"
        $mailBodyMsb += "<TD><b><font color='Orange'>" + $warningReport.ItemCaption + "</font><b></TD></TR>"
        
        $mailBodyMsb += "<TR style='background-color:rgb(245,245,245);';><TD>Details</TD>"
        $mailBodyMsb += "<TD>" + $warningReport.ItemValue + "</TD></TR>"

        $mailBodyMsb += "</table>"
        $mailBodyMsb += "<BR><BR>"
    }
}
  • Delete the report’s history from “Save Report” folder (I can have the last day’s executions as history) and remove compressed files.
#remote the rip report file
Remove-Item $zipFile
#remote report folder older then X days
get-childitem $mbvReportSaveLocation |? {$_.psiscontainer -and $_.lastwritetime -le (get-date).adddays(-3)} |% {remove-item $_ -Force -Recurse}

Again, only if the script finds any Critical or non-critical warning (that is not expected) a mail notification will be sent.

Report sample:

MessageBox Viewer BHM Notification report powershell

Note: This type of script must be viewed as a complement to the tools mentioned above or used in the absence of them.

Download

THIS POWERSHELL IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND.

You can download How to schedule MBV or BHM and customize notification alerts with PowerShell from GitHub here:

Author: Sandro Pereira

Sandro Pereira lives in Portugal and works as a consultant at DevScope. In the past years, he has been working on implementing Integration scenarios both on-premises and cloud for various clients, each with different scenarios from a technical point of view, size, and criticality, using Microsoft Azure, Microsoft BizTalk Server and different technologies like AS2, EDI, RosettaNet, SAP, TIBCO etc. He is a regular blogger, international speaker, and technical reviewer of several BizTalk books all focused on Integration. He is also the author of the book “BizTalk Mapping Patterns & Best Practices”. He has been awarded MVP since 2011 for his contributions to the integration community.

Leave a Reply

Your email address will not be published. Required fields are marked *

turbo360

Back to Top