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 amtool command for rendering templates. #2414

Closed
wants to merge 1 commit into from

Conversation

FUSAKLA
Copy link
Contributor

@FUSAKLA FUSAKLA commented Nov 4, 2020

Hi, I found quite difficult for users to write the Alertmanager templates.
Mainly it's quite difficult to test them.

Now user has to:

  1. run the alertmanager with the new configuration
  2. send the test aler probably using amtool
  3. have some receiver configured where he can check the result

I do not think this is much user-friendly and I hope we can do better.

This PR is just draft, because the changes required for it are quite big, so I'm not polishing it and finalizing it but just to show the idea:

The command would generate specified number of synthetic alerts which could be somehow parametrized (add custom annotation, label etc). These will be used for rendering of the templates.

It's bit complicated to specify which templates should be rendered, by default it could render al of them possibly user could filter just specified type, id or name of receiver to render.

The rendered output as should be mainly human readable IMHO (but also reproducible in case someone would want to use it for testing for example.) That's why as initial implementation I did the templating as rendering the receiver config as yaml. That unfortunately required bigger refactoring of the receivers configs templating.

Example tool help

$ ./amtool config templates render --config.file examples/ha/alertmanager.yml --help
usage: amtool config templates render

Flags:
  -h, --help                     Show context-sensitive help (also try --help-long and --help-man).
      --config.file=CONFIG.FILE  Config file to be used.
      --receiver.name=RECEIVER.NAME  
                                 Name of receiver to be used for templating.
      --receiver.type=RECEIVER.TYPE  
                                 Type of receiver to be used for templating.
      --receiver.id=-1           Id of receiver to be used for templating.
      --additional.labels="label-name=label-value"  
                                 Labels of the alert used for rendering of the templates.
      --additional.annotations="annotation-name=annotation-value"  
                                 Annotations of the alert used for rendering of the templates.
      --alert.count="annotation-name=annotation-value"  
                                 Number of alerts to be passed to the rendering.

Example usage output:

$ ./amtool config templates render --config.file examples/ha/alertmanager.yml 
--- # receiver:  type: opsgenie index: 1

send_resolved: true
http_config: {}
api_key: <secret>
api_url: https://api.opsgenie.com/
message: '[FIRING:1]  (bar)'
description: |+
  bar
  Alerts Firing:
  Labels:
   - foo = bar
  Annotations:
   - foo = bar
  Source: http://foo.bar

I'll be happy to finish this but I'm not 100% sure about the ideal form of output and input.
Would you be willing to accept such thing and if so, how should it look like ideally?

Thanks for any ideas!

Signed-off-by: Martin Chodur <m.chodur@seznam.cz>
@FUSAKLA
Copy link
Contributor Author

FUSAKLA commented Nov 4, 2020

@simonpasquier if you find a while would you give it a look? 🙏

@stale stale bot added the stale label Jan 4, 2021
@GiedriusS
Copy link
Contributor

Attempting to implement a more generic variant here: #2538

@stale stale bot removed the stale label Apr 14, 2021
@stale stale bot added the stale label Jun 13, 2021
@roidelapluie
Copy link
Member

#2538 has been merged. Thanks!

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

Successfully merging this pull request may close these issues.

3 participants