API Returns 500 when updating HOST exit_status: 2, but returns normally when HOST exit_status: 0

I have written my own check plugin that passively checks a device (the plugin runs on cron due to the nature of the device).

I run the script, and pass expected thresholds to set the status_code to 0 to indicate all is good. When I do this, the Icinga2 API returns normally and updates the host output in Icingaweb2.

Status successfully updated for 96.5.193.179. Payload:
{ "type": "Host", "filter": "host.name==\"96.5.193.179\"", "exit_status": 0, "plugin_output":"OK - Total of 16 APs is equal to expected number of APs (16). Model: SZ104 Serial: 222038000092", "pretty": true }

However, when I pass in bogus information to trigger a CRITICAL status_code 2, I get a 500 error returned from the API:

{'results': [{'code': 400.0, 'status': "Invalid 'exit_status' for Host 96.5.193.179."}]}
Status not updated! API returned HTTP 500 for 96.5.193.179. Payload:
{ "type": "Host", "filter": "host.name==\"96.5.193.179\"", "exit_status": 2, "plugin_output":"CRITICAL - Total of 16 APs not equal to expected number of APs (15). Model: SZ104 Serial: 222038000092", "pretty": true }

I then check Icingaweb2 and the host status information is still stuck on OK.

Any idea what’s going on here? I am passing in the same parameters and the payloads looks the same, except for the exit_status and the plugin_output.

I am using Python 3.8. It’s worth noting that I am passing in an integer and using its str method to concatenate it to the payload string. If I do not use the str(exit_status) then I get a TypeError.

Per the documentation https://icinga.com/docs/icinga-2/latest/doc/12-icinga2-api/#process-check-result
2 should be a valid exit_status

Hello @steaksauce , If you’re performing passive checks for a host via the REST API, then you only have 2 states, 0=OK, 1=CRITICAL, it’s also mentioned in the documentation you linked above. You get this error because the status value 2=CRITICAL is not a valid status value for a host but only for services.

Hope this helps you!
Yonas

1 Like

Sure enough

for hosts: 0=OK, 1=CRITICAL.

I am blind! Thanks!