What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general.

Learn more

PRTG Network Monitor

Intuitive to Use. Easy to manage.
More than 500,000 users rely on Paessler PRTG every day. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free Download

Top Tags


View all Tags

custom PowerShell sensor returns System Error: (code: PE022)

Votes:

0

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?

powershell prtg sensor

Created on Apr 14, 2023 12:08:17 AM



1 Reply

Votes:

0

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 [email protected] after changing Debug options to store results for this sensor and collect a support bundle for further review

Created on Apr 21, 2023 4:27:59 PM by  Mitzi Rodriguez [Paessler support]




Disclaimer: The information in the Paessler Knowledge Base comes without warranty of any kind. Use at your own risk. Before applying any instructions please exercise proper system administrator housekeeping. You must make sure that a proper backup of all your data is available.