Hello guys.
What is the output structure of a JSON for a Python script sensor? I tried to orient myself by the example sensor and could not. Below is the JSON part of my code, it will only have 1 channel, called level, test3 is the variable of my script that has the value I want to show in the sensor.
data = json.loads(sys.argv[1]) csr = CustomSensorResult(text="This sensor runs on %s" % data["host"]) csr.add_primary_channel(name="Level", value=test3, unit=ValueUnit.PERCENT, is_float=False, is_limit_mode=True, limit_min_error=30, limit_error_msg="Percentage too high") print(csr.json_result) except Exception as e: csr = CustomSensorResult(text="Python Script execution error") csr.error = "Python Script execution error: %s" % str(e) print(csr.json_result)
I also noticed that in the example sensor, there is this structure:
if __name__ == "__main__": try:
What does she mean? Should I put it at the beginning or end of my code?
I imported the json, sys, from paesslerag_prtg_sensor_api.sensor.result import CustomSensorResult and from paesslerag_prtg_sensor_api.sensor.units import ValueUnit. But still it doesn't work.
Add comment