Windows Azure

Windows Azure

The place for things I find whilst learning about windows azure.

Windows Azure servicebus queue and relay REST calls for monitoring


Windows Azure servicebus queue and relay REST calls for monitoring

Whilst deploying a new application to Windows Azure Cloud services, one of the components that was being used was both Servicebus relays and queues.

Traditional cloud or web services are relatively easy to monitor, usually a web or api type call, but as Servicebus doesn’t have a directly callable endpoint as such monitoring is a little more tricky.

Because its new, currently there isn’t much help on the web with regard to the REST api for servicebus, especially if its secured using ACS, so I have knocked together some scripts using powershell which call to ACS for your authorization token, then present that in a http REST call which will get in the case of a servicebus queue, the details of that queue – if there are messages in there, and in the case of relays, the name and whether there are any listeners connected.

PowerShell scripts below for Relays – it probably needs some tidying up but it does the main bits..

function Execute-HTTPPostCommand() {
param(
[string] $target = $null, [string] $Post
)

$url = $target

$parameters = $Post # your POST parameters

$http_request = New-Object -ComObject Msxml2.XMLHTTP
$http_request.open(‘POST’, $url, $false)
$http_request.setRequestHeader(“Content-type”,”application/x-www-form-urlencoded”)
$http_request.setRequestHeader(“Content-length”, $parameters.length)
$http_request.setRequestHeader(“Connection”, “close”)
$http_request.send($parameters)
$http_request.statusText

$results = $http_request.ResponseText
return $results;

}

function Execute-HTTPGetCommand() {
param(
[string] $target = $null, [string] $authstring
)

$authnew = $authstring.Split(“=”,2)

#Write-Host “authnew”,$authnew[1]
$authnospace = $authnew[1]
$strippedauth = $authnospace -replace ‘ ‘, ”

$encmsg = [System.Web.HttpUtility]::UrlDecode($strippedauth)
$encmsg1 = [System.Web.HttpUtility]::UrlDecode($encmsg)

write-host $encmsg
$encmsg2 = $encmsg -replace ‘&wrap_access_token_expires_in=10799’, ”
$encmsg2 = $encmsg -replace ‘&wrap_access_token_expires_in=10800’, ”

write-host $encmsg2

$authfull = “WRAP access_token=`”” + $encmsg2 + “`””
$url = $target

$parameters = $Post # your POST parameters

$http_request = New-Object -ComObject Msxml2.XMLHTTP
$http_request.open(‘GET’, $url, $false)

$http_request.setRequestHeader(“Authorization”, $authfull)
$http_request.setRequestHeader(“Connection”, “close”)
$http_request.send($parameters)
$http_request.statusText

$results = $http_request.ResponseText
return $results;

}

$post = “wrap_name=owner&wrap_password=[URIEncodedpassword]&wrap_scope=http%3A%2F%2F[namespace].servicebus.windows.net”
$URL = “https://[namespace]-sb.accesscontrol.windows.net/WRAPv0.9/”

$authstring = Execute-HTTPPostCommand $URL $post

$URL2 = “https://[namespace].servicebus.windows.net/`$Resources/Relays”

Execute-HTTPGetCommand $URL2 $authstring

 

———————- Powershell Script for querying Servicebus queues this returns if the queue is greater than 0

function Execute-HTTPPostCommand() {
param(
[string] $target = $null, [string] $Post
)

$url = $target

$parameters = $Post # your POST parameters

$http_request = New-Object -ComObject Msxml2.XMLHTTP
$http_request.open(‘POST’, $url, $false)
$http_request.setRequestHeader(“Content-type”,”application/x-www-form-urlencoded”)
$http_request.setRequestHeader(“Content-length”, $parameters.length)
$http_request.setRequestHeader(“Connection”, “close”)
$http_request.send($parameters)
$http_request.statusText

$results = $http_request.ResponseText
return $results;

}

function Execute-HTTPGetCommand() {
param(
[string] $target = $null, [string] $authstring
)

$authnew = $authstring.Split(“=”,2)

#Write-Host “authnew”,$authnew[1]
$authnospace = $authnew[1]
$strippedauth = $authnospace -replace ‘ ‘, ”

$encmsg = [System.Web.HttpUtility]::UrlDecode($strippedauth)
$encmsg1 = [System.Web.HttpUtility]::UrlDecode($encmsg)

write-host $encmsg
$encmsg2 = $encmsg -replace ‘&wrap_access_token_expires_in=10799’, ”
$encmsg2 = $encmsg -replace ‘&wrap_access_token_expires_in=10800’, ”

write-host $encmsg2

$authfull = “WRAP access_token=`”” + $encmsg2 + “`””
$url = $target

$parameters = $Post # your POST parameters

$http_request = New-Object -ComObject Msxml2.XMLHTTP
$http_request.open(‘GET’, $url, $false)

$http_request.setRequestHeader(“Authorization”, $authfull)
$http_request.setRequestHeader(“Connection”, “close”)
$http_request.send($parameters)
$http_request.statusText

$results = $http_request.ResponseText
return $results;

}

$post = “wrap_name=owner&wrap_password=[URIEncodedpassword]&wrap_scope=http%3A%2F%2F[namespace].servicebus.windows.net”
$URL = “https://[namespace]-sb.accesscontrol.windows.net/WRAPv0.9/”

$authstring = Execute-HTTPPostCommand $URL $post

$URL2 = “https://[namespace].servicebus.windows.net/`$Resources/Queues?`$filter=MessageCount%20Gt%200”

Execute-HTTPGetCommand $URL2 $authstring