Handler (Variable as parameter to command)

I am trying to create a handler that uses “labels” dynamically in the command as an argument. however below when it runs the command, the command receives “{{ .labels.hostname. }}” as the argument. So sensu isn’t performing any interpretation of the variable?

Is there a way to do this?

Example:
type: Handler
api_version: core/v2
metadata:
name: remediate
namespace: default
spec:
command: /usr/local/bin/remediate.py {{ .labels.hostname }}
env_vars:

  • “”
    filters:
  • is_incident
    handlers: null
    runtime_assets: null
    timeout: 0
    type: pipe

Posting the “work-around” that worked for me:

there’s no way to do token substitution for handlers (see https://github.com/sensu/sensu-go/issues/2528) however, the handler is provided with the full event in its stdin, so the data is nonetheless available. It’s just a matter of extracting what you need.

jq .entity.metadata.labels.hostname | xargs -I{} ./usr/bin/remediate.py {}

1 Like

Nice!

Yeah, now that Sensu Classic is EOL, what I hope we can do as a community is figure out some common practices moving forward on how to build Sensu Go handlers that know how to consume entity and check level annotations embedded into the events.

The legacy plugins originally designed for Sensu Classic’s event model won’t be able to use this pattern, but now that we are past EOL we can put some effort into new versions of these handlers that can integrate better with Sensu Go without causing undue disruption for users.