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.
The problem is that the sensor returns the error: System Error: (code: PE022)
What I'm I doing wrong here?
Add comment