Skip to content

Conversation

@waltherlee
Copy link
Member

It's an old thread, but there's been some discussion here about supporting templating in webhook url fields: #684

The issue was closed in 2017 because the alertmanager didn't support templating for any http/url fields, but there're some examples where it does support it now, for example SlackAction.URL and PushoverConfig.URL, so I think we can re-evaluate adding support for this.

There's some good use cases described by others in the thread since it was closed.

This change adds templating to the fields. Existing tests already check that secret URL is still not exposed.

Copy link
Contributor

@SoloJacobs SoloJacobs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I understand:

  1. We don't expose MarshallYAML, so the new implementation is backwards compatible. I.e, all old configurations are accepted by the new UnmarshallYAML implementation. Here are two configurations, which are only accepted by the new implementation.
- name: 'empty-url'
  webhook_configs:
  - url: ''
    url_file: 'url.txt'

- name: 'not-a-url'
  webhook_configs:
  - url: 'ssh://ab'

For the not-a-url config the new behaviour is rather unfortunate. Did you consider validating URLs, which don't have a template?

  1. Could we maybe get some tests for the new templating in notify/webhook/webhook.go?
  2. There are also some other configurations, which could be handled in a similar manor I think:
  • SlackConfig
  • MSTeamsConfig
  • MSTeamsV2Config
  • MattermostConfig
  • DiscordConfig

I guess that is out-off-scope for this PR, though.

@waltherlee
Copy link
Member Author

Sure, I can add the change for those too and some tests. Thanks Solomon

Signed-off-by: Walther Lee <walthere.lee@gmail.com>
Signed-off-by: Walther Lee <walthere.lee@gmail.com>
Signed-off-by: Walther Lee <walthere.lee@gmail.com>
@waltherlee
Copy link
Member Author

The change from SecretURL to Secret was breaking some tests and validations, so I created a new SecretTemplURL to keep all the existing checks at config-level for URLs without templating.

I added tests for templated urls in webhook but won't change the other URL fields from other configs in this PR to keep it small. I'll send a second one with just the switch to SecretTemplURL.

@waltherlee waltherlee requested a review from SoloJacobs December 8, 2025 02:17
Signed-off-by: Walther Lee <walthere.lee@gmail.com>
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

Successfully merging this pull request may close these issues.

2 participants