sensu / sensu-pagerduty-handler

Sensu Go PagerDuty Handler
https://sensu.io
MIT License
6 stars 21 forks source link

Details Template Example #34

Closed DanielRoberson closed 3 years ago

DanielRoberson commented 3 years ago

Hello,

I'm trying to override the default details template sent to pager duty: https://github.com/sensu/sensu-pagerduty-handler/blob/88e12e734df92cbdf1a1a41aa1a6c8453c84344b/main.go#L74

I just want my Check output to be displayed in the details section, nothing else. I tried setting PAGERDUTY_DETAILS_TEMPLATE={{.Check.Output}} as an environment variable on my handler, but I'm still getting the full check JSON.

When I configure an annotation on the check like this: "sensu.io/plugins/sensu-pagerduty-handler/config/details-template": "{{.Check.Output}}"

I get this error message: error preparing check: unmatched token: template: :1:945: executing "" at <.Check.Output>: map has no entry for key "Check"

Do you have a working example of how to modify the Check JSON or a way to only send the check output to pager duty?

Thanks!

nixwiz commented 3 years ago

I'm not sure why the environment variable is not working. It worked in my testing, as did using the --details-template argument. Did you test with the command line argument as well?

In regards to using it is a check annotation, we (thanks to @echlebek) have discovered a little caveat that we need to make sure is documented in the README. Since checks also support token substitution the check definition is ran through template expansion, and it attempts to expand that annotation. Thus the error message you received in the log. The workaround for this is to enclose the template as a golang string literal within a template so that when the check token substitution is processed the actual desired template is produced in an event that is passed on to a handler. This can be done as as such.

JSON:

"sensu.io/plugins/sensu-pagerduty-handler/config/details-template": "{{`{{.Check.Output}}`}}"

YAML:

sensu.io/plugins/sensu-pagerduty-handler/config/details-template: "{{`{{.Check.Output}}`}}"
DanielRoberson commented 3 years ago

Ok, so after more troubleshooting, it had to do the version of the handler/asset I was running. I updated to 2.1.0 and it's now working as expected. Thanks for your help!