You can check the status of any private build agent configured under agent pools in Azure DevOps.

But if you want to monitor it using Azure Automation then you can create a PowerShell Runbook and use the WebRequest explained here to setup scheduled monitoring and alerting  (via email).


>>First you have to get the Pool details under which the build agent is registered/configured. Run the below request to get the results{replace organisation}/_apis/distributedtask/pools?api-version=5.1

It will show output as shown

Note the ‘id’ value which is actually PoolId.

>> Now using this Pool Id we will find all the build agent Ids registered under this Pool. Run the request{organisation}/_apis/distributedtask/pools/{PoolId}/agents?api-version=5.1

The results will  be

Now ‘id’ value is agentid. You can see the status value is also shown here. But we will run request specifically for the AgentId to get the details.

>> Now using the AgentId you can get the status of the agent. Run the below request{organisation}/_apis/distributedtask/pools/{PoolId}/agents?agentid={AgentId}api-version=5.1


This way you can get the status of the build agent which can be monitored by scheduling a PowerShell Runbook using Azure Automation.

The PowerShell script will look like


[Parameter(Mandatory=$true][string]$user = <provide DevOps user name>

[Parameter(Mandatory=$true)][string]$PATtoken = <PAT value for the user>

$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$token)))

$agentStatusReq =Invoke-WebRequest -Uri '{organisation}/_apis/distributedtask/pools/{PoolId}/agents?agentid={AgentId}api-version=5.1' -UseBasicParsing -Method Get -ContentType "application/json" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}

$agentStatus = ConvertFrom-Json InputObject $agentStatusReq.Content

Write-Output "The name of build agent is : " $

Write-Output "The Status of build agent is : " $agentStatus.status