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
  name: check-ping
  namespace: default
  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: ""
    - (!!entity)
    splay: true
    splay_coverage: 90
  publish: true
  round_robin: true
  - 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:

    - 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?



1 Like


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


Sorry, only just got chance to try this.

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