Checking the Status of an Azure WebJob
17 May 2017As we migrate more and more of our infrastructure to Azure, we've begun to make use of WebJobs. Now that we have started to reply more and more on WebJobs rather than Windows Services, I wanted to add a status check to our dashboard to make sure that the WebJob was run successfully.
After some digging, it was actually quite easy:
Dim Url As [String] = "https://APPSERVICENAME.scm.azurewebsites.net/api/triggeredwebjobs/JOBNAME"
Dim request As WebRequest = WebRequest.Create(Url)
request.ContentType = "application/json"
request.Method = "GET"
Dim userName As [String] = "$username"
Dim passWord As [String] = "password"
Dim credentials As String = Convert.ToBase64String(Encoding.ASCII.GetBytes(userName + ":" + passWord))
request.Headers(HttpRequestHeader.Authorization) = String.Format("Basic {0}", credentials)
request.ContentType = "application/json; charset=utf-8"
Dim response As HttpWebResponse = request.GetResponse()
Using sr = New StreamReader(response.GetResponseStream())
Dim data = sr.ReadToEnd()
'This will be a JSON string
End Using
The hardest part of this was figuring out what credentials to use. In the Azure Portal, if you go to the properties of your WebJob, the username and password can be seen: