DX Unified Infrastructure Management

 View Only
Expand all | Collapse all

How to programmatically monitor the Hub Subscribers/Queues using REST WEB API in a PowerShell Script

  • 1.  How to programmatically monitor the Hub Subscribers/Queues using REST WEB API in a PowerShell Script

    Posted Mar 30, 2023 10:10 AM

    I've had cases where the NAS queue (or any other Queue) was backlogged and there is no way to monitor the Queues within UIM.

    I was able to write a PowerShell script to call the WEB API on the Primary Hub and get the results, then parse through them to get the Queue Information.

    If it's any queue but NAS, you could set this up in Logmon and execute the PowerShell script & setup a watch for the "Queued" number going higher than a certain Number. If you're monitoring the NAS Queue, then you're probably best off by making a Scheduled Task & setting up an email to notify yourself.

    I'm giving you 99% of the code & you just need to customize it for your environment.

    PowerShell Code:

    function Rest-POST ($URI, $Content, $Body, $Credentials, $Timeout)

    {

        if ($Timeout -lt 0 -or $Timeout -eq "") {$Timeout = 60}

        $Results = Invoke-RestMethod -Uri $URI -ContentType $Content -Method Post -Body ($Body) -Credential $Credentials -TimeoutSec $Timeout

        return $Results

    }

    function UIM-GetListSubscribers ($List)

    {

        $URL = "https://UIM_Server/uimapi/probes/UIM_domain/UIM_hub/HubServer/hub/callback2/list_subscribers/30"

        $Body = '{"timeout":30,"arguments":[]}'

        $N = Rest-POST $URL "application/json" $Body $mycreds

        for ($i = 0; $i -lt $n.nimPds.nimPdsTable.key.Count; $i++)

        {

            #Find Array Item for SUBSCRIBERS

            if ($n.nimPds.nimPdsTable.key[$i] -eq "subscribers")

            {

                for ($j = 0; $j -lt $n.nimPds.nimPdsTable[$i].nimPds.Count; $j++)

                {

                    # Find POSTROUTE Array AND Specific Subscribers Queue named in $LIST.

                    if ($n.nimPds.nimPdsTable[$i].nimPds[$j].nimString[0].'#text' -eq $List -and $n.nimPds.nimPdsTable[$i].nimPds[$j].nimString[0].key -eq "postroute")

                    {

                        for ($k = 1; $k -lt $n.nimPds.nimPdsTable[$i].nimPds[$j].nimInt.Count; $k++)

                        {

                            # Find QUEUE Count (INQ).

                            if ($n.nimPds.nimPdsTable[$i].nimPds[$j].nimInt.key[$k] -eq "inq")

                            {

                                $Queued = $n.nimPds.nimPdsTable[$i].nimPds[$j].nimInt.'#text'[$k]

                            }

                            # Find Total SENT Count (COUNT).

                            if ($n.nimPds.nimPdsTable[$i].nimPds[$j].nimInt.key[$k] -eq "count")

                            {

                                $Count = $n.nimPds.nimPdsTable[$i].nimPds[$j].nimInt.'#text'[$k]

                            }

                        }

                    }

                }

            }

        }

        #return "$List = $Queued / $Count"

        return $List,$Queued,$Count

    }

    ########################## MAIN ##########################

    $ListSubscriber = "nas"    #Could check any queue, such as: $ListSubscriber = "alarm_enrichment"

    $List,$Queued,$Count = UIM-GetListSubscribers $ListSubscriber

    Write-Host "UIM Queued=$Queued in ""$List"" Queue with Sent=$Count"

    The output will look like this:
    UIM Queued=33 in "nas" Queue with Sent=1273694

    I hope you find this code helpful...



  • 2.  RE: How to programmatically monitor the Hub Subscribers/Queues using REST WEB API in a PowerShell Script

    Posted Mar 30, 2023 05:45 PM

    Thank you for sharing.

    Always nice to see things like this implemented in a new language. There are Lua and Perl versions of this that have been posted in the past but using the nimsoft callback methodology. Nice to see something using the REST API for comparison. This also has the advantage that it should work from any windows box that has network connectivity as opposed to the others' limitations of needing to be able to reach the central hub directly using a nimbus call.