This post was originally published here

BizTalk360 has introduced notification channels from its major version release V8.0. One of the most greeted features from our customers. With the introduction of this capability, it’s easy to send alerts to any external systems like your ticketing system, internal databases, calling REST endpoints or executing PowerShell scripts.

One of the most powerful capabilities is to use an API, to enable you to create notification channels for connecting to your own systems. The PowerShell notification channel allows you to execute a PowerShell script, each time an alarm is triggered when the threshold is crossed.

During business transactions in mission-critical BizTalk Server environments, if any of the service instances are waiting for response messages, they will be turned to the dehydrated state. There might be valid reasons why such service instances are not needed anymore. So, as a BizTalk administrator, you should keep an eye on these instances in their environments to avoid further critical business consequences.

BizTalk360 provides Monitoring capabilities for dehydrated service instances and it sends periodic alerts via different notification channels. One such channel is the PowerShell Notification channel.

This blog post will give you an insight about how to terminate the dehydrated service instances through the PowerShell notification channel in BizTalk360, just by configuring it with the Alarms.

Steps to implement the PowerShell Notification Channel

1. Create the PowerShell script
2. Configure the PowerShell notification channel
3. Configure the PowerShell notification channel with the Alarm

Creating the PowerShell script

To develop the PowerShell script, it is essential to identify the API’s which will take care of these actions.

Step 1:

Retrieve the dehydrated service instances from the Message Box using the below API.
http://localhost/BizTalk360/Services.REST/BizTalkQueryService.svc/ExecuteServiceInstanceQuery

Code Snippet


import-Module Microsoft.PowerShell.Management
$username = "DomainUserName"
$password = "ABC1236890"
$password_base64 = ConvertTo-SecureString $password -AsPlainText -Force
$creds = New-Object System.Management.Automation.PSCredential ($username, $password_base64)
$body_ExecuteServiceInstanceQuery='{
"context":{
"callerReference":"REST-SAMPLE",
"environmentSettings":{
"id":"3beb9328-c435-47ed-8c51-a406117e632b",
"licenseEdition":0
}
},
"query":{
"compositeFilter":{
"filterDescriptorCollection":[
{
"member":"Instance Status",
"filterAvailableMember":[
{
"name":"Application",
"alias":"Application Name",
"dataType": 1,
"isList":true,
"isAutoComplete":false
},
{
"name":"CreationTime",
"alias":"Creation Time",
"dataType":0,
"isList":false,
"isAutoComplete":false
},
{
"name":"GroupResultsBy",
"alias": "Group Results By",
"dataType": 1,
"isList": true,
"isAutoComplete": false
},
{
"name": "HostName",
"alias": "Host Name",
"dataType": 1,
"isList": true,
"isAutoComplete": false
},
{
"name": "InstanceStatus",
"alias": "Instance Status",
"dataType": 1,
"isList": true,
"isAutoComplete": false
},
{
"name": "ServiceClass",
"alias": "Service Class",
"dataType": 1,
"isList": true,
"isAutoComplete": false
},
{
"name": "ServiceInstanceID",
"alias": "Service Instance ID",
"dataType": 1,
"isList": false,
"isAutoComplete": false
},
{
"name": "ServiceName",
"alias": "Service Name",
"dataType": 1,
"isList": true,
"isAutoComplete": false
},
{
"name": "ServiceTypeID",
"alias": "ServiceType ID",
"dataType": 1,
"isList": false,
"isAutoComplete": false
}
],
"memberType": 1,
"filterOperator": 2,
"value": "Dehydrated",
"progressIndicator": false,
"validationError": "",
"isValid": true,
"tempValue": ""
}
]
},
"maxMatches": "10",
"queryType": 0
},
"maxMatches": "10"
}'
$headers=@{"Content-Type"="application/json"}
$uri="http://BT360SUP03/BizTalk360/Services.REST/BizTalkQueryService.svc/ExecuteServiceInstanceQuery"
$response = Invoke-WebRequest -Uri $uri -Headers $headers -Method Post -Body $body_ExecuteServiceInstanceQuery -Credential $creds

Step 2:

Pass the retrieved dehydrated service instances for the termination process to the below API.

http://localhost/BizTalk360//Services.REST/BizTalkQueryService.svc/ExecuteServiceInstanceOperation

Code Snippet


$ExecuteServiceInstanceQueryobj = ConvertFrom-Json $response
if (!$ExecuteServiceInstanceQueryobj.serviceInstances) {write-Host "There are no dehydrated service instances for termination"}

foreach ($serviceinstance in $ExecuteServiceInstanceQueryobj.serviceInstances)
{
$body_ExecuteServiceInstanceOperation='{
"context":{
"callerReference":"REST-SAMPLE",
"environmentSettings":{
"id":"3beb9328-c435-47ed-8c51-a406117e632b",
"licenseEdition":0
}
},
"serviceInstances":[
{
"ServiceName": "'+$($serviceinstance.ServiceName)+'",
"ServiceClass": "Orchestration",
"StatusDisplayText": "Dehydrated",
"Application":"'+$($serviceinstance.application)+'",
"ServiceInstanceID":"'+$($serviceinstance.serviceInstanceID)+'"
}
],
"operation": 1
}'
$headers1=@{"Content-Type"="application/json"}
$uri1="http://localhost/BizTalk360//Services.REST/BizTalkQueryService.svc/ExecuteServiceInstanceOperation"
$response1 = Invoke-WebRequest -Uri $uri1 -Headers $headers1 -Method Post -Body $body_ExecuteServiceInstanceOperation -Credential $creds
$ExecuteServiceInstanceQueryobj = ConvertFrom-Json $response
}

Points to Remember

Following are the parameters need to be changed as per your environment configuration.

  1. Service Account credentials for UserName
  2. Password
  3. Environment Id
  4. URI

As mentioned in the introduction section, BizTalk360 exposes its APIs and can be found in the section Settings -> API documentation.

Terminating Dehydrated Service instances - API Documentation screen

Configuring the PowerShell Notification channel

Once the PowerShell script has been created, the next step is to configure it with the notification channel in BizTalk360.The PowerShell notification channel can be found in Settings -> Monitoring Notification Channels ->B360.Notifier.PowerShellNotification.

Terminating Dehydrated Service instances - Configure PowerShell Notification channel

Select the notification channel and click on the “Configure” button on the top menu bar. In the Configuration Notification Channel section, enter the location of the script which has been created for terminating the dehydrated service instances and click on the Configure button. Now, the PowerShell script has been configured with the BizTalk360 notification channel.

Terminating Dehydrated Service instances - Associate the Powershell Script Path

Associating the PowerShell Notification Channel with Alarms

The next primary step is to Map the notification channel with the Alarms for further execution and configure the Threshold violation settings, as how frequent you want to terminate the dehydrated service instances from your environment. Based on the settings, BizTalk360 will terminate the dehydrated service instances in your BizTalk Server environment.

Terminating Dehydrated Service instances - Alarm Configuration with PowerShell Notification Channel

Terminating Dehydrated Service instances - Threshold Alarm Settings

Conclusion

We strongly believe BizTalk360 has transformed the way you do your work. It is a very common situation where administrators depend on various tools like BizTalk admin console, SQL queries and other custom build tools to monitor their BizTalk Environment. But with this capability “PowerShell Notification Channel”, administrators can create their own scripts and automate their daily activities. In this blog post, we have explained one such scenario we can accommodate with BizTalk360. This capability is not restricted for some functionalities, the component is generically implemented in the product where our customers can achieve a lot more business scenarios by using this powerful capability.

Do try BizTalk360 one-stop monitoring tool for your BizTalk Server.

Author: Mekala Ramesh

Lead QA & Product Support at BizTalk360 – Having around 8 years of experience in software testing & customer support field with the strong knowledge in SDLC and STLC phases. Specialized in various types of testing methodologies. Passionate tester, who always want to deliver the software product with the best quality to the end customers. Possess strong knowledge, to establish the testing process from scratch. Playing a pivotal role in BizTalk360 is making me deliver the product to every customer in a delicious way. View all posts by Mekala Ramesh