Hi everyone,

I am currently testing a REST Custom Sensor JSON Sensor where I would like to monitor a REST API that should give a state about different services.

For that I created a custom template for this specific page :

{ "prtg": { "result": [ { "channel": "Incident", "value": lookup($.service.current_incident_type, "minor", "scheduled", "major"), "LimitMode": 1 } ] } }

My issue : The state of the service communicated on this REST API is a string "major", "minor", "scheduled" OR null

PRTG does display following on the sensor : " Could no evaluate channel value of Incident: expected type string for parameter 0 but got <nil>."

Is there a way to handle null value in a lookup file ?

Thank you in advance for your support !

Best regards


Article Comments

Hello Kevin,

Thank your for your message and best wishes for this year.

Regarding your question, can you please provide us the JSON response you get from your API, please make sure to remove all confidential information if necessary.

Regards.


Jan, 2021 - Permalink

Hi Florian,

Thank you for your answer and wishes, I also wish you all the best for this new year.

Yeah sure !

Bellow two possible answer coming from the API with the first responding a string ("major") and the second a null value. What i want to read is the "current_incident_type" value.

{ "incidents": [], "maintenances": [], "service": { "children": null, "current_incident_type": "major", "id": 16102, "name": "Service 1", "parent_id": 16095 } }

{ "incidents": [], "maintenances": [], "service": { "children": null, "current_incident_type": null, "id": 16104, "name": "Service 2", "parent_id": 16095 } }

Possible values are ("major", "minor" , "scheduled" , null) I would like to set my sensor to error for "major" and "minor" and OK for "scheduled" and null

I hope this help you understand my issue.

Best regards, Kevin


Jan, 2021 - Permalink

Thank you very much for the information.

As the result returns no value (null) and not "null" as a string, I'm afraid that the REST Custom sensor can't be used. However, you have the possibility to use a custom script and handle the values (including null) as you want.

Here is the manual of the EXE/Script Advanced sensor you can use to monitor the services: https://www.paessler.com/manuals/prtg/exe_script_advanced_sensor

I also invite you to have a look to the manual about custom sensor to see how to return information in PRTG with a script: https://www.paessler.com/manuals/prtg/custom_sensors#advanced_sensors

If you have further questions, let me know.


Jan, 2021 - Permalink

Hi Florian,

Thanks a lot for your answer. I followed your advice and finally create a script with a 'Python Script Advanced' Sensor in order to also handle null values.

I have been able to solve my problem so and monitor this status page.

Best regards, Kevin


Jan, 2021 - Permalink

Hi Kevin,

Thank you for the update, I'm glad to ear that you make it through. Have an excellent day.

Best regards.


Jan, 2021 - Permalink