Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for templating for feature parity with Sensu Core/Enterprise Slack handler #22

Open
asachs01 opened this issue Jul 17, 2019 · 8 comments

Comments

@asachs01
Copy link
Contributor

As the issue title says, it would be useful to have support to create a template file to use when posting to the Slack API. This is present in both the Core/Enterprise Slack handlers.

@calebhailey
Copy link

calebhailey commented Jul 17, 2019

We should support templates but avoid the usage of a file for config (because containers). We've already done some work around this in our plugin library that should make this easy to support.

@gojkoz
Copy link

gojkoz commented Feb 24, 2020

We would love to see templating support too

@sensu-discourse
Copy link

This issue has been mentioned on Sensu Community. There might be relevant details there:

https://discourse.sensu.io/t/add-custom-output-to-check-http-rb-and-pass-it-to-slack/1656/3

@asachs01
Copy link
Contributor Author

I think this issue is resolved by the code that you can find in https://github.com/sensu/sensu-slack-handler/blob/master/main.go#L83. I'll have to play with it a bit more, but I'd say this solves the issue.

@gojkoz
Copy link

gojkoz commented Mar 30, 2020

I saw that commit, but it's not had a release yet, correct?
Can you make a new sensu-slack-handler release please to include this change?

Thanks

@asachs01
Copy link
Contributor Author

@gojkoz a release has been pushed. Can you give it a shot to see if this provides the functionality you need?

@gojkoz
Copy link

gojkoz commented Apr 14, 2020

It's not a full template modification, but it's a start :) It allowed me to modify the "description" field of the notification output only. I was able to squeeze in something other than .Check.Output in it, that we find useful in the slack notifications.

However it is kind of limiting, for example I can't do any parsing (like wanted to use time.Parse to parse the Timestamp field to something readable. I was not able to add line breaks, they just show up as \n or
in the slack channel. Not sure if you know another way of adding a line break there, just to help with making the output more readable?

I was also not able to use ":" in the template (quoted and everything), sensuctl errors with 'mapping values are not allowed in this context'. I think it wants to parse that column as part of my yaml definition.
Ie: command: sensu-slack-handler --channel '#channel' --username 'Sensu' -w $SLACK_WEBHOOK_URL -t '{{ .Check.Output }} Occurrences: {{ .Check.Occurrences }}'
This causes sensuctl error when you try to apply it. But if you use it manually on the CLI to invoke the handler binary, it works fine, so the handler itself does not have a problem with that ":".

I guess if these were all fully templated, this would be more flexible. For example just next to (to the right of) the Status field in the slack notification, I'd like to add Occurrences. Not sure how hard it would be to load the whole template definition from a file, similar to what you do for the slack email handler? That and fix to allow some kind of formatting and timestamp parsing would be awesome.

@jsnod
Copy link

jsnod commented Dec 1, 2020

Agreed, the default alerts take up way too much space:

Screen Shot 2020-12-01 at 2 38 46 PM

Ideally we could customize this with a template string so that we can condense all that wasted whitespace into 1 or 2 lines if desired. Also note I added the occurrences with -t "{{ .Check.Output }} ({{ .Check.Occurrences }} occurrences)" but you can see there is an extra linebreak after the Check.Output. Where does that come from? If it's in the output itself perhaps it should be trimmed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants