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

feat: add rocketchat notifier #3600

Merged
merged 2 commits into from
Oct 23, 2024
Merged

feat: add rocketchat notifier #3600

merged 2 commits into from
Oct 23, 2024

Conversation

TheMeier
Copy link
Contributor

This adds native support for Rocketchat notifications. It uses the Rocketchat REST API. For authentication access tokens are used. This is a solution for #3546

@TheMeier TheMeier force-pushed the rocketchat branch 6 times, most recently from 90e581d to 11915f0 Compare November 12, 2023 16:10
Copy link
Contributor

@grobinson-grafana grobinson-grafana left a comment

Choose a reason for hiding this comment

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

I'm not a maintainer but in general looks good! You might have to remove use of the SDK as 1. these tend to be quite large and 2. all of the other integrations avoid using their respective SDKs.

However, I'd wait until @simonpasquier or @gotjosh review before making further changes as I don't want to give you incorrect advice! 🙂

config/notifiers.go Outdated Show resolved Hide resolved
docs/configuration.md Outdated Show resolved Hide resolved
notify/rocketchat/rocketchat.go Outdated Show resolved Hide resolved
notify/rocketchat/rocketchat.go Outdated Show resolved Hide resolved
@TheMeier
Copy link
Contributor Author

I'm not a maintainer but in general looks good! You might have to remove use of the SDK as 1. these tend to be quite large and 2. all of the other integrations avoid using their respective SDKs.

However, I'd wait until @simonpasquier or @gotjosh review before making further changes as I don't want to give you incorrect advice! 🙂

@grobinson-grafana thanks for your feedback.
Actually since I had a night to sleep on it, i already am planning to refactor it since it feels so alien, and some things do not really work like the retry mechanism.
So I will probably set this to Draft and work on it a bit more in the coming days.

@gotjosh gotjosh self-assigned this Nov 14, 2023
@TheMeier TheMeier marked this pull request as draft November 15, 2023 09:28
@TheMeier TheMeier force-pushed the rocketchat branch 5 times, most recently from d6a5e1c to 2e16289 Compare November 18, 2023 16:03
@TheMeier TheMeier marked this pull request as ready for review November 18, 2023 16:03
@TheMeier
Copy link
Contributor Author

I removed the rocketchat SDK. Do you prefer that i squash the commits in this PR?

@TheMeier TheMeier force-pushed the rocketchat branch 2 times, most recently from e44a344 to ed5d734 Compare November 27, 2023 11:51
@TheMeier TheMeier force-pushed the rocketchat branch 2 times, most recently from 7614223 to e3653ad Compare December 8, 2023 08:46
@TheMeier TheMeier force-pushed the rocketchat branch 4 times, most recently from 7139615 to 37df9c1 Compare January 8, 2024 16:16
@TheMeier TheMeier force-pushed the rocketchat branch 2 times, most recently from 93f9014 to a507e77 Compare January 30, 2024 13:33
Copy link
Contributor

@grobinson-grafana grobinson-grafana left a comment

Choose a reason for hiding this comment

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

LGTM! A couple of nits and questions. I appreciate it's very short notice, do you think you'll have time to address the feedback in the next 24 hours, as we would like to merge this tomorrow and get it into the 0.26 release?

config/config.go Outdated Show resolved Hide resolved
config/config.go Outdated Show resolved Hide resolved
config/config.go Outdated Show resolved Hide resolved
config/config.go Outdated Show resolved Hide resolved
config/config_test.go Outdated Show resolved Hide resolved
notify/rocketchat/rocketchat.go Outdated Show resolved Hide resolved
notify/rocketchat/rocketchat.go Outdated Show resolved Hide resolved
config/notifiers.go Show resolved Hide resolved
ImageURL string `yaml:"image_url,omitempty" json:"image_url,omitempty"`
ThumbURL string `yaml:"thumb_url,omitempty" json:"thumb_url,omitempty"`
LinkNames bool `yaml:"link_names" json:"link_names,omitempty"`
Actions []*RocketchatAttachmentAction `yaml:"actions,omitempty" json:"actions,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we also need a validation rule on the maximum number of actions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same as above. Also, what would be a sensible limit?

template/default.tmpl Show resolved Hide resolved
@TheMeier TheMeier force-pushed the rocketchat branch 4 times, most recently from 43db2ef to 25a773a Compare October 23, 2024 07:45
config/notifiers.go Outdated Show resolved Hide resolved
config/notifiers.go Outdated Show resolved Hide resolved
@grobinson-grafana
Copy link
Contributor

I think for slack we expect the user to provide the suffix api/v1/chat.postMessage. Let's do the same here. https://github.com/prometheus/alertmanager/blob/main/notify/slack/slack.go#L197-L206

The reason I asked if we can remove the suffix is I think RocketChat also supports webhooks (and appending a URL suffix would break them). Do you think you could also test this to make sure it works too?

https://docs.rocket.chat/docs/integrations#create-a-new-incoming-webhook

Thank you very much for your patience. We would like to merge your PR as soon as these last two nits are addressed.

@TheMeier
Copy link
Contributor Author

TheMeier commented Oct 23, 2024

I think for slack we expect the user to provide the suffix api/v1/chat.postMessage. Let's do the same here. https://github.com/prometheus/alertmanager/blob/main/notify/slack/slack.go#L197-L206

The reason I asked if we can remove the suffix is I think RocketChat also supports webhooks (and appending a URL suffix would break them). Do you think you could also test this to make sure it works too?

https://docs.rocket.chat/docs/integrations#create-a-new-incoming-webhook

Thank you very much for your patience. We would like to merge your PR as soon as these last two nits are addressed.

I did remove it from the code and added it to the docs for configuration. This notifier is explicitly for the API and does not support rocketchat webhooks.

@TheMeier TheMeier reopened this Oct 23, 2024
@TheMeier TheMeier force-pushed the rocketchat branch 2 times, most recently from e69340b to b2ee824 Compare October 23, 2024 10:50
@TheMeier
Copy link
Contributor Author

Point about the webhooks is as you can see from the docs, it requires a custom webhook script. And that may be very different for different rocketchat servers. In fact one of the motivations for this notifier was to get away from a "broken" custom webhook script on the server side.

@grobinson-grafana
Copy link
Contributor

Point about the webhooks is as you can see from the docs, it requires a custom webhook script. And that may be very different for different rocketchat servers. In fact one of the motivations for this notifier was to get away from a "broken" custom webhook script on the server side.

Oh... I've misunderstood. I thought it would be a 1:1 with Slack where it would support both: webhooks and bot tokens.

In which case, I think I might make sense to append the URL suffix like you had the first time around, as this will allow us to support other features like replies and reactions in future, if we ever need it. I'm sorry to ask you to undo this change.

Signed-off-by: Christoph Maser <christoph.maser+github@gmail.com>
Co-authored-by: George Robinson <george.robinson@grafana.com>
@TheMeier
Copy link
Contributor Author

Point about the webhooks is as you can see from the docs, it requires a custom webhook script. And that may be very different for different rocketchat servers. In fact one of the motivations for this notifier was to get away from a "broken" custom webhook script on the server side.

Oh... I've misunderstood. I thought it would be a 1:1 with Slack where it would support both: webhooks and bot tokens.

In which case, I think I might make sense to append the URL suffix like you had the first time around, as this will allow us to support other features like replies and reactions in future, if we ever need it. I'm sorry to ask you to undo this change.

No problem. Already done ;)

Copy link
Contributor

@grobinson-grafana grobinson-grafana left a comment

Choose a reason for hiding this comment

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

One last change to make sure we join the paths correctly, and then I think we are good to merge it! Thank you for your contribution.

notify/rocketchat/rocketchat.go Outdated Show resolved Hide resolved
Co-authored-by: George Robinson <george.robinson@grafana.com>
Signed-off-by: gotjosh <josue.abreu@gmail.com>
Copy link
Member

@gotjosh gotjosh left a comment

Choose a reason for hiding this comment

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

LGTM

@gotjosh gotjosh enabled auto-merge (squash) October 23, 2024 14:26
@gotjosh gotjosh merged commit 8572fe8 into prometheus:main Oct 23, 2024
11 checks passed
@gotjosh
Copy link
Member

gotjosh commented Oct 23, 2024

@TheMeier thank you so much for your contribution!

mogoll92 pushed a commit to staketown/alertmanager that referenced this pull request Oct 23, 2024
* feat: add rocketchat notifier

Signed-off-by: Christoph Maser <christoph.maser+github@gmail.com>
Co-authored-by: George Robinson <george.robinson@grafana.com>

* Update notify/rocketchat/rocketchat.go

Co-authored-by: George Robinson <george.robinson@grafana.com>
Signed-off-by: gotjosh <josue.abreu@gmail.com>

---------

Signed-off-by: Christoph Maser <christoph.maser+github@gmail.com>
Signed-off-by: gotjosh <josue.abreu@gmail.com>
Co-authored-by: George Robinson <george.robinson@grafana.com>
Co-authored-by: gotjosh <josue.abreu@gmail.com>
mogoll92 added a commit to staketown/alertmanager that referenced this pull request Oct 23, 2024
gotjosh added a commit that referenced this pull request Oct 24, 2024
* Release v0.28.0-rc.0

* [CHANGE] Templating errors in the SNS integration now return an error. #3531 #3879
* [FEATURE] Add a new Microsoft Teams integration based on Flows #4024
* [FEATURE] Add a new Rocket.Chat integration #3600
* [FEATURE] Add a new Jira integration #3590 #3931
* [FEATURE] Add support for `GOMEMLIMIT`, enable it via the feature flag `--enable-feature=auto-gomemlimit`. #3895
* [FEATURE] Add support for `GOMAXPROCS`, enable it via the feature flag `--enable-feature=auto-gomaxprocs`. #3837
* [FEATURE] Add support for limits of silences including the maximum number of active and pending silences, and the maximum size per silence (in bytes). You can use the flags `--silences.max-silences` and `--silences.max-silence-size-bytes` to set them accordingly #3852 #3862 #3866 #3885 #3886 #3877
* [FEATURE] Muted alerts now show whether they are suppressed or not in both the `/api/v2/alerts` endpoint and the Alertmanager UI. #3793 #3797 #3792
* [ENHANCEMENT] Add support for `content`, `username` and `avatar_url` in the Discord integration. `content` and `username` also support templating. #4007
* [ENHANCEMENT] Only invalidate the silences cache if a new silence is created or an existing silence replaced - should improve latency on both `GET api/v2/alerts` and `POST api/v2/alerts` API endpoint. #3961
* [ENHANCEMENT] Add image source label to Dockerfile. To get changelogs shown when using Renovate #4062
* [ENHANCEMENT] Build using go 1.23 #4071
* [ENHANCEMENT] Support setting a global SMTP TLS configuration. #3732
* [ENHANCEMENT] The setting `room_id` in the WebEx integration can now be templated to allow for dynamic room IDs. #3801
* [ENHANCEMENT] Enable setting `message_thread_id` for the Telegram integration. #3638
* [ENHANCEMENT] Support the `since` and `humanizeDuration` functions to templates. This means users can now format time to more human-readable text. #3863
* [ENHANCEMENT] Support the `date` and `tz` functions to templates. This means users can now format time in a specified format and also change the timezone to their specific locale. #3812
* [ENHANCEMENT] Latency metrics now support native histograms. #3737
* [BUGFIX] Fix the SMTP integration not correctly closing an SMTP submission, which may lead to unsuccessful dispatches being marked as successful. #4006
* [BUGFIX]  The `ParseMode` option is now set explicitly in the Telegram integration. If we don't HTML tags had not been parsed by default. #4027
* [BUGFIX] Fix a memory leak that was caused by updates silences continuously. #3930
* [BUGFIX] Fix hiding secret URLs when the URL is incorrect. #3887
* [BUGFIX] Fix a race condition in the alerts - it was more of a hypothetical race condition that could have occurred in the alert reception pipeline. #3648
* [BUGFIX] Fix a race condition in the alert delivery pipeline that would cause a firing alert that was delivered earlier to be deleted from the aggregation group when instead it should have been delivered again. #3826
* [BUGFIX] Fix version in APIv1 deprecation notice. #3815
* [BUGFIX] Fix crash errors when using `url_file` in the Webhook integration. #3800
* [BUGFIX] fix `Route.ID()` returns conflicting IDs. #3803
* [BUGFIX] Fix deadlock on the alerts memory store. #3715
* [BUGFIX] Fix `amtool template render` when using the default values. #3725
* [BUGFIX] Fix `webhook_url_file` for both the Discord and Microsoft Teams integrations. #3728 #3745

---------

Signed-off-by: SuperQ <superq@gmail.com>
Signed-off-by: gotjosh <josue.abreu@gmail.com>
Co-authored-by: gotjosh <josue.abreu@gmail.com>
SuperQ added a commit that referenced this pull request Dec 19, 2024
* [CHANGE] Templating errors in the SNS integration now return an error. #3531 #3879
* [CHANGE] Adopt log/slog, drop go-kit/log #4089
* [FEATURE] Add a new Microsoft Teams integration based on Flows #4024
* [FEATURE] Add a new Rocket.Chat integration #3600
* [FEATURE] Add a new Jira integration #3590 #3931
* [FEATURE] Add support for `GOMEMLIMIT`, enable it via the feature flag `--enable-feature=auto-gomemlimit`. #3895
* [FEATURE] Add support for `GOMAXPROCS`, enable it via the feature flag `--enable-feature=auto-gomaxprocs`. #3837
* [FEATURE] Add support for limits of silences including the maximum number of active and pending silences, and the maximum size per silence (in bytes). You can use the flags `--silences.max-silences` and `--silences.max-silence-size-bytes` to set them accordingly #3852 #3862 #3866 #3885 #3886 #3877
* [FEATURE] Muted alerts now show whether they are suppressed or not in both the `/api/v2/alerts` endpoint and the Alertmanager UI. #3793 #3797 #3792
* [ENHANCEMENT] Add support for `content`, `username` and `avatar_url` in the Discord integration. `content` and `username` also support templating. #4007
* [ENHANCEMENT] Only invalidate the silences cache if a new silence is created or an existing silence replaced - should improve latency on both `GET api/v2/alerts` and `POST api/v2/alerts` API endpoint. #3961
* [ENHANCEMENT] Add image source label to Dockerfile. To get changelogs shown when using Renovate #4062
* [ENHANCEMENT] Build using go 1.23 #4071
* [ENHANCEMENT] Support setting a global SMTP TLS configuration. #3732
* [ENHANCEMENT] The setting `room_id` in the WebEx integration can now be templated to allow for dynamic room IDs. #3801
* [ENHANCEMENT] Enable setting `message_thread_id` for the Telegram integration. #3638
* [ENHANCEMENT] Support the `since` and `humanizeDuration` functions to templates. This means users can now format time to more human-readable text. #3863
* [ENHANCEMENT] Support the `date` and `tz` functions to templates. This means users can now format time in a specified format and also change the timezone to their specific locale. #3812
* [ENHANCEMENT] Latency metrics now support native histograms. #3737
* [ENHANCEMENT] Add timeout option for webhook notifier. #4137
* [BUGFIX] Fix the SMTP integration not correctly closing an SMTP submission, which may lead to unsuccessful dispatches being marked as successful. #4006
* [BUGFIX]  The `ParseMode` option is now set explicitly in the Telegram integration. If we don't HTML tags had not been parsed by default. #4027
* [BUGFIX] Fix a memory leak that was caused by updates silences continuously. #3930
* [BUGFIX] Fix hiding secret URLs when the URL is incorrect. #3887
* [BUGFIX] Fix a race condition in the alerts - it was more of a hypothetical race condition that could have occurred in the alert reception pipeline. #3648
* [BUGFIX] Fix a race condition in the alert delivery pipeline that would cause a firing alert that was delivered earlier to be deleted from the aggregation group when instead it should have been delivered again. #3826
* [BUGFIX] Fix version in APIv1 deprecation notice. #3815
* [BUGFIX] Fix crash errors when using `url_file` in the Webhook integration. #3800
* [BUGFIX] fix `Route.ID()` returns conflicting IDs. #3803
* [BUGFIX] Fix deadlock on the alerts memory store. #3715
* [BUGFIX] Fix `amtool template render` when using the default values. #3725
* [BUGFIX] Fix `webhook_url_file` for both the Discord and Microsoft Teams integrations. #3728 #3745
* [BUGFIX] Fix wechat api link #4084
* [BUGFIX] Fix build info metric #4166

Signed-off-by: SuperQ <superq@gmail.com>
@SuperQ SuperQ mentioned this pull request Dec 19, 2024
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.

4 participants