none
Email Alert in case of any message gets suspended in Group Hub BizTalk Server

    Question

  • Hi friends,

    I am  using below scripts in PowerShell to get email alert in case of any message gets suspended in Group Hub.It's working fine.

    Now I don't want email alert if the no. of suspended messages  in group Hub is 0. How to apply in below scripts.

    # Import external assembly and create a new object
    [void] [System.reflection.Assembly]::LoadWithPartialName("Microsoft.BizTalk.ExplorerOM")
    [void] [System.reflection.Assembly]::LoadWithPartialName("Microsoft.BizTalk.Operations")
    $Catalog = New-Object Microsoft.BizTalk.ExplorerOM.BtsCatalogExplorer 
    #BizTalk Config
    $Catalog.ConnectionString = "SERVER=.;DATABASE=BizTalkMgmtDb;Integrated Security=SSPI" 
    #Email Config
    $emailFrom = ""
    $emailTo = ""
    $emailSubject = "Suspended Messages in BizTalk Admin Console " + $(Get-WmiObject Win32_Computersystem).name
    $emailServer =""
    function getSuspendedMessages()
    {
     $bo = New-Object Microsoft.BizTalk.Operations.BizTalkOperations
     $serviceInstances = $bo.GetServiceInstances()
       
      
     foreach ($instance in $serviceInstances)
     {
     $msgApp = "Application :" + $instance.Application + [Environment]::NewLine
     $msgApp = $msgApp + "Service Name :" + $instance.ServiceType + [Environment]::NewLine + [Environment]::NewLine
      foreach ($mesg in $instance.Messages)
       {
         $AppMsgs = "MessageID : " + $mesg.MessageID + [Environment]::NewLine
         $AppMsgs = $AppMsgs + "Instance ID: " + $mesg.InstanceID + [Environment]::NewLine
         $AppMsgs = $AppMsgs + "Instance Status :" + $mesg.InstanceStatus + [Environment]::NewLine
         $AppMsgs = $AppMsgs + "Adapter Name :" + $mesg.AdapterName + [Environment]::NewLine
         $AppMsgs = $AppMsgs + "Creation Time :" + $mesg.CreationTime + [Environment]::NewLine
         $AppMsgs = $AppMsgs + "Error Description:" + $mesg.ErrorDescription + [Environment]::NewLine
       }
     $msgApp = $msgApp + $AppMsgs + [Environment]::NewLine   
     $FullMsg = $FullMsg + $msgApp
     }
        return $FullMsg;
    }
    #echo $message
    $SuspendedMessages = getSuspendedMessages
    $SuspendedMessages = "Following are the Suspended Messages : " + [Environment]::NewLine + $SuspendedMessages
    $message = $message + [Environment]::NewLine + [Environment]::NewLine + $SuspendedMessages
    echo $message
    sendEmail($message)

    Regards,

    Ritesh

    Monday, July 24, 2017 7:05 AM

All replies

  • Hi Ritesh,

    First of all, $bo.GetServiceInstances() will get all the service instances running, suspended (resumable, non resumable) as well as the active, scheduled etc. Hence you need to filter out the results only on the suspended instances. You need to do something on below lines

     foreach ($instance in $serviceInstances)
     {
    if(($instance.InstanceStatus -eq 'Suspended') -or ($instance.InstanceStatus -eq 'SuspendedAll') -or ($instance.InstanceStatus -eq 'SuspendedNotResumable'))
    {
     $msgApp = "Application :" + $instance.Application + [Environment]::NewLine
     $msgApp = $msgApp + "Service Name :" + $instance.ServiceType + [Environment]::NewLine + [Environment]::NewLine
      foreach ($mesg in $instance.Messages)
       {
         $AppMsgs = "MessageID : " + $mesg.MessageID + [Environment]::NewLine
         $AppMsgs = $AppMsgs + "Instance ID: " + $mesg.InstanceID + [Environment]::NewLine
         $AppMsgs = $AppMsgs + "Instance Status :" + $mesg.InstanceStatus + [Environment]::NewLine
         $AppMsgs = $AppMsgs + "Adapter Name :" + $mesg.AdapterName + [Environment]::NewLine
         $AppMsgs = $AppMsgs + "Creation Time :" + $mesg.CreationTime + [Environment]::NewLine
         $AppMsgs = $AppMsgs + "Error Description:" + $mesg.ErrorDescription + [Environment]::NewLine
       }
     $msgApp = $msgApp + $AppMsgs + [Environment]::NewLine   
     $FullMsg = $FullMsg + $msgApp
     }
        return $FullMsg;
    }
    }
    
    Just put a check of Instance Status and then you will have messages only if there are suspended instances


    Mandar Dharmadhikari


    Monday, July 24, 2017 7:29 AM
    Moderator
  • Hi Mandar,

    I have added below codes in above script.It's not working .

     If (($serviceInstances.Count -eq 0))
    {
        exit
    }

    Regards,

    Ritesh

    Monday, July 24, 2017 9:00 AM
  • HOLD ON!

    Before you go any further, ask your network or Windows teams if they have a management or monitoring app already running, specifically one that can watch the Windows Event Log.

    Examples would be Microsoft System Center, Splunk or others.

    This is the most correct way to accomplish this.

    Monday, July 24, 2017 1:51 PM
    Moderator
  • Hi Ritesh,

    GetServiceInstances() method always queries and brings back ALL the service instances in the Biztalk environment. So at a given point of time it is not possible that the Biztalk environment is not processing any service instances. Hence 

    $Instances.Count

    will never give you 0 because it will contain not only suspended but also other service instances. In case you need only suspended service instances, then implement the check I have mentioned in my previous reply, that will ensure that you filter out only the SUSPENDED instances at a given point of time when you run the query. 

    AS Johns has mentioned, this utility is pretty common and Production support team generally has tools set up to monitor these issues. So it is also advisable to connect with them and see if they alread have something to monitor the suspended service instances, that will save your time to write a script.


    Mandar Dharmadhikari

    Tuesday, July 25, 2017 12:23 AM
    Moderator
  • Hi Ritesh,

    Any update for us on the issue?


    Mandar Dharmadhikari

    Monday, July 31, 2017 1:10 AM
    Moderator