Overall entity status

Is there a sensible way to grab overall entity status? I’m thinking something like the way the Hostgroup Overview appears in Nagios/Icinga (a table with the first column being hostname, and second column showing how many checks are OK/WARNING/CRITICAL/UNKNOWN). With the current API, it seems that it would take an excessive number of API calls to generate this data (1 call per check per host).

The only idea I came up with was to actually generate this data in a scheduled check, but I was hoping there is a better way.

One alternative to consider would be in the dashboard using the entity: hostname Filter in the events view. That doesn’t provide a summary/count, however.

Though not its intended purpose, you could probably use the aggregate check to come up with a similar outcome.

Otherwise you could go the route of querying the API and building this information. However, rather than doing a query for each check per host, I would suggest using the events API and using response filtering with a fieldSelector=event.entity.name == hostname for each host. However, be aware that response filtering is a commercial feature.

Here’s an example I came up with querying the /events API using curl and jq to group and count the data. Maybe something like this could be adapted?

$ cat state.jq
map({State: .check.state})
| group_by(.State)
| map({State: .[0].State, Count: length})
| .[]

$ curl -s -H "Authorization: Bearer $SENSU_ACCESS_TOKEN" -k https://backend:8080/api/core/v2/events -G --data-urlencode 'fieldSelector=event.entity.name == "hostname"' | jq  -f state.jq
{
  "State": "failing",
  "Count": 1
}
{
  "State": "passing",
  "Count": 2
}

Thanks for all the ideas. I’m actually trying to figure out a way to display it in Grafana. I’m wondering if a custom data source might do the trick.

There’s the Sensu Go Grafana datasource.

I’ve been using the existing datasource for some dashboards, but it’s seems to be too limited for creating a dashboard like I’ve mentioned above. I was thinking of creating a custom source that would implement something similar to your code above. A custom panel might also work, but I think the custom data source might be a better option to reduce api queries.

The datasource repo has also had bug fixing pull requests sitting for half a year… Know anyone that can merge them into a new release? :slight_smile:

I’ll check on getting someone to look into the PR.