icinga2
icinga2 copied to clipboard
process-check-result returns HTTP 500 when filter matches no objects
Describe the bug
The API endpoint /v1/actions/process-check-result returns HTTP 500 when the given filter doesn't match any objects.
To Reproduce
POST https://localhost:5665/v1/actions/process-check-result
{"type": "Service", "filter": "host.name==\"does not exist\" && service.name==\"does not exist\"", "exit_status": 0}
returns HTTP 500 with the body
{"results": []}
Expected behavior
I would expect HTTP 400 or 404 with an appropriate error message.
Your Environment
- Version used (
icinga2 --version
): 2.13.2
Additional context
There is already code that tries to handle this: https://github.com/Icinga/icinga2/blob/bbc2b59b0dbfbfd08ef3ac79edb46621a8613608/lib/remote/actionshandler.cpp#L57-L64
However GetFilterTargets() only throws an exception on invalid filters or missing permissions, but not if the filter doesn't match any objects.
The exception handler should probably send a HTTP 400 response with a different message and a new check if objs
is empty should be added.