But we already have periodic health checks scheduled in Octopus, so it’d be more efficient to specify the target name / id & grab the result of the last health check.
Thanks for reaching out. Just to confirm, you are wanting to RUN a health check on a specific target, not just check the current health of that target (Is it healthy/not) and return that value, correct?
It will return a JSON and I believe the values you will want to utilize will be IsDisabled, HealthStatus, and StatusSummary.
So a quick powershell query could be:
# Define working variables
$OctopusURL = "https://" #for example https://local.octopus.com
$OctopusAPIKey = "" #for example API-############
$Header = @{ "X-Octopus-ApiKey" = $OctopusAPIKey }
$SpaceName = "" #input space name that has the machines here
$MachineIDs = @("Machines-501","Machines-991") #put 1 or more machine IDs here separated by commas
$Space = (Invoke-RestMethod -Method Get -Uri "$OctopusURL/api/spaces/all" -Headers $Header) | Where-Object { $_.Name -eq $SpaceName }
foreach ($machineID in $MachineIDs){
$Machine = (Invoke-RestMethod -Method Get -Uri "$OctopusURL/api/$($Space.id)/machines/$($machineID)" -Headers $Header)
Write-Host $machine.IsDisabled
Write-Host $machine.HealthStatus
Write-Host $machine.StatusSummary
}
Please test that thoroughly as I quickly wrote and tested it and can’t guarantee it will work in your scenario.
Octopus is API driven so anything you can do in the portal you should be able to do with scripting. The method that I got the above Endpoint and the JSON format in the response was to open Developer tools in Firefox/Chrome by pressing F12, going to the network tab, then clicking the Connectivity page within a target. You can then see all of the calls on any given page in the Network tab and click into them to get more information. Following this method while doing most things in the Octopus portal will show you the endpoints involved in the call as well as the required data and resulting data.
Please let me know if that helps or if you have any questions.