I was trying to get events related to a specific sensu check using curl i.e., all the events related to specific sensu check on all entities.
But as per the documentation, it seems like there is no way to do so. But, I found a way to get for specific entity and check but not for a check alone.
Please help me how to get events related to specific check.
Hey,
I believe you can use the field selector commercial feature with curl when using the official sensu-backend binaries to get the behavior you want by filtering on the field ‘event.check.name’.
Here’s an example using an Sensu API key that will give me all events matching the check name ‘keepalive’
curl -H "Authorization: Key $SENSU_API_KEY" https://127.0.0.1:8080/api/core/v2/events -G --data-urlencode 'fieldSelector=event.check.name == "keepalive"'
You can combine field selector expressions, for example I can get all keepalive events outside of default namespace thusly:
curl -H "Authorization: Key $SENSU_API_KEY" https://127.0.0.1:8080/api/core/v2/events -G --data-urlencode 'fieldSelector=event.check.name == "keepalive && event.namespace != "default""'
Field selectors are covered here:
https://docs.sensu.io/sensu-go/latest/api/#field-selector
With selectors, you should be able to do some good selections.
As a note, last time I drilled into this the selector is a string match. This means you can’t filter based on integer comparisons (e.g. “event.check.status >= 1” to be either in warning or in critical – so you’ll need to use inequalities, ‘notin’ to form some of your queries).
We have a similar use case where we an external systemd wanted to see if a particular check was failing and not silenced. Similar to Jef’s examples above.
curl -sS -G \
-H "Authorization: Key $SENSU_API_KEY" \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
https://127.0.0.1:8080/api/core/v2/namespaces/default/events --data-urlencode 'fieldSelector=event.check.status == "2" && event.is_silenced == "false" && event.check.name == "prod-tax-heartbeat-alert"'
thanks my issue has been fixed.