# Handler (Variable as parameter to command)

**URL:** <https://discourse.sensu.io/t/handler-variable-as-parameter-to-command/1488>\
**Category:** Sensu Go\
**Created:** [December 10, 2019, 5:17am UTC](https://discourse.sensu.io/t/handler-variable-as-parameter-to-command/1488 "2019-12-10T05:17:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![devinacosta](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.sensu.io/devinacosta/32/75_2.png) [@devinacosta](https://discourse.sensu.io/u/devinacosta)\
**Post date:** [December 10, 2019, 5:17am UTC](https://discourse.sensu.io/t/handler-variable-as-parameter-to-command/1488/1 "2019-12-10T05:17:06Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![devinacosta](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.sensu.io/devinacosta/32/75_2.png) [@devinacosta](https://discourse.sensu.io/u/devinacosta)\
**Post date:** [December 10, 2019, 5:31pm UTC](https://discourse.sensu.io/t/handler-variable-as-parameter-to-command/1488/2 "2019-12-10T17:31:29Z")

</div>

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](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 {}

---

<div class="post-metadata">

**Author:** ![jspaleta](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.sensu.io/jspaleta/32/141_2.png) [@jspaleta](https://discourse.sensu.io/u/jspaleta)\
**Post date:** [December 10, 2019, 7:14pm UTC](https://discourse.sensu.io/t/handler-variable-as-parameter-to-command/1488/3 "2019-12-10T19:14:20Z")

</div>

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.
