BizTalk: Monitoring Host Instances using PowerShell script

Configure alerts when host instance stopped
If you ever faced a situation when your BizTalk server is down and you don’t have any clue about that before you got a call from client and asking why a system is down.In this article covers how to configure the alerts when BizTalk host instances stopped, and the same techniques can be applied to receive locations and send ports.

First question will come to your mind, why host instances has been stopped?

  • Loss of network connectivity with the SQL Server
  • Out Of Memory exception
  • Access Violation

Some times if database and BizTalk have configured on different servers then it loses connectivity for even a very brief interval, host instances will shut down. The SQL Server goes down unexpectedly, In this situation, the First Failure property will apply.(Host Instance Service Properties) With the default First Failure and Restart service after settings, a single restart attempt is made after 1 minute. If the SQL Server is still not available after 1 minute, no additional restart attempts will be made. The host instance will remain stopped.

Dependencies, All the listed components must be started before the BizTalk host instance will start. This includes Enterprise Single Sign-On.

I have developed a script that can run as a scheduled Task in Windows and this can be scheduled frequently every 10 or 30 minutes. When it runs, it will look at your host instances, and alert a email to configured receipts if instance are not running.

Building the PowerShell Script

function FuncCheckService{
param($ServiceName)
$arrService = Get-Service -Name $ServiceName
if ($arrService.Status -ne “Running”){
# Start-alert notification for $ServiceName
# I have used Gmail SMTP server configuration, you can use your own.
$EmailFrom = “Your Gmail email ID”
$EmailTo = “Your Gmail email ID”
$EmailBody = $ServiceName + “Service is not running”
$EmailSubject = $ServiceName + “Service is not running”
$SMTPServer = “smtp.gmail.com”
$Username = “Your Gmail email ID”
$Password = “Your Gmail Password”
$Message = New-Object Net.Mail.MailMessage($EmailFrom, $EmailTo, $EmailSubject,$EmailBody)
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)
$SMTPClient.EnableSsl = $true
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential($Username, $Password);
$SMTPClient.Send($Message)
}
}
FuncCheckService -ServiceName ‘BTSSvc$BizTalkServerApplication’

Note: new modified HostInstanceFailureNotification.PS1 file can be downloaded form Here.

Schedule PowerShell script on Task Scheduler

First of all I suggest you to do all activity with admin privileges.

Open Task scheduler, either you can Run Task Scheduler using the Windows interface
  • Click the Start button.
  • Click Control Panel .
  • Click System and Maintenance .
  • Click Administrative Tools .
  • Double-click Task Scheduler .

Or, Run Task Scheduler from the Command Line

  • Open Run window (Windows button + R)
  • Type Taskschd.msc
  1. Create new task from right panel of Task scheduler window.
  2. Put the name, Description in General tab and select radio button Run whether user is logged on or not from Security options.
  3. Select Triggers tab and click on New, In settings panel select Daily radio button, In Advance settings panel check box tick on Repeat Task every 30 min or select according your requirement. select for s duration of Indefinitely. Select check box tick for option Stop task if it runs longer than 1 hours. and click OK.
  4. Select Action tab and click on New, Action should be Start a program. In Settings panel Brows the file path of PowerShell script. and click OK.
  5. Select Conditions tab, and unchecked the option in POWER panel.
  6. Select Settings tab, select all check box to tick. and click OK.
Now your Powershell script is placed at Task scheduler and it will execute every 30 minutes, If BizTalk host instance has been stopped then will trigger a alert mail to configured receipts.

Leave a Reply

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