Targeting checks against and agent from a proxy

My configuration management tooling (SaltStack) generates the sensu agent.yml file for each host and populates subscriptions with the roles.

eg, a web/app server might end up with subscriptions set to:

  - nginx
  - php
  - ftpd

What I then do is have some checks which run from a proxy, to check things on that host from elsewhere on the network.

So I have a check like this to ping each host from the proxy - but then the results of that check-ping event are attributed against the entity being checked, not the proxy.

---
type: CheckConfig
api_version: core/v2
metadata:
  name: check-ping
  namespace: default
spec:
  check_hooks: null
  command: /usr/lib/nagios/plugins/check_v46 /usr/lib/nagios/plugins/check_ping -H
    {{ .name }} -w 200,10% -c 500.0,75% -p 5 -t 5
  interval: 60
  proxy_entity_name: ""
  proxy_requests:
    entity_attributes:
    - (!!entity)
    splay: true
    splay_coverage: 90
  publish: true
  round_robin: true
  subscriptions:
  - sensu-proxy
  timeout: 15

For many checks though, I need to target boxes with certain roles.

I hoped i’d be able to do that using entity.subscriptions, with something like:

  proxy_requests:
    entity_attributes:
    - routeserver in entity.subscriptions

That didn’t work, so I ended up getting saltstack to add a roles label to each agent.yml. Obviously that has to have a string value and can’t be an array, so I made it a comma separated list of roles (eg: nginx, php, ftpd).

I thought i’d be able to do this:

(!!entity.labels.roles) && entity.labels.roles.split(', ').includes('nginx') 

…but that didn’t work either.

But, this does work! -

(!!entity.labels.roles) && entity.labels.roles.split(', ').indexOf('nginx') >= 0)

That seems to work ok - but i’m interested if anyone else does similar or has any neater ways / tips?

Thanks,

Ian

1 Like

Hey!

Have you tried going back and using the indexOf syntax in the subscriptions?

entity.subscriptions.indexOf('routeserver') >= 0

There’s an example for suscription matching in
https://docs.sensu.io/sensu-go/latest/reference/sensu-query-expressions/

2 Likes

Sorry, only just got chance to try this.

Good call! - that seems to work, and is neater.

Thanks!

Ian