Using PowerShell, I created a custom sensor that will invoke an API query on a server running Rundeck. The response will be either "0" for no running jobs, or "1" if there is a running job. I read that PRTG needs to have a "value:message" returned, so I wrote an if statement to format the response and meet this requirement.

This is the script.

$projectName = "ESXi"
$authToken = "authtokenhere"

$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Accept", "application/json")
$headers.Add("X-Rundeck-Auth-Token", $authToken)
$headers.Add("Content-Type", "application/json")

$responce = (Invoke-RestMethod "http://192.168.1.26:4440/api/21/project/$projectName/executions/running" -Method 'GET' -Headers $headers)
$result = $responce.paging.count

if ($result -eq '0') {
    Write-Output 0:OK
}
else {
    Write-Output 1:WARNING
}

I tested this PowerShell script by running it on the PRTG server, and indeed, if a job on Rundeck is running, it gives me 1:WARNING and if no jobs are running, it returns 0:OK

I then put the PowerShell script in C:\Program Files (x86)\PRTG Network Monitor\Custom Sensors\EXE and created a new Custom EXE/Script Sensor. I selected my PowerShell script and left all the other settings at their default values.

Image

The problem is that the sensor returns the error: System Error: (code: PE022)

What I'm I doing wrong here?


Article Comments

Hello,

Can you try adding quotes to the results as follow ?

if ($result -eq '0') { Write-Output "0:OK"; Exit 0 } else { Write-Output "1:WARNING"; Exit 1 }

To better assist you in this issue in case the issue persists, please open a case to our support@paessler.com after changing Debug options to store results for this sensor and collect a support bundle for further review


Apr, 2023 - Permalink