alertmanager
alertmanager copied to clipboard
feat: add rocketchat notifier
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
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.
I removed the rocketchat SDK. Do you prefer that i squash the commits in this PR?
@roidelapluie I am aware you have a lot on your plate. I just wanted to kindly ask if there is any chance of this getting some love, since you mentioned some interest in the referenced issue.
@gotjosh can I get a review please?
@TheMeier I started to look at this, but I'm not sure how to test this. I've run into a number of issues getting RocketChat to run on Apple M1 as it seems there are no docker images for linux/arm64
. I've also tried building from source and I'm running into a number of errors with yarn
. I'm following these instructions here.
Have you been able to test these changes?
@grobinson-grafana I have tested them with a real-live inhouse rocketchat server.
Any chance for some progress here or in #3776 ?
Let's fix the headers differently
// New returns a new Rocketchat notification handler.
func New(c *config.RocketchatConfig, t *template.Template, l log.Logger, httpOpts ...commoncfg.HTTPClientOption) (*Notifier, error) {
client, err := commoncfg.NewClientFromConfig(*c.HTTPConfig, "rocketchat", httpOpts...)
if err != nil {
return nil, err
}
token, err := getToken(c)
if err != nil {
return nil, err
}
tokenID, err := getTokenID(c)
if err != nil {
return nil, err
}
// Define the RoundTripper to set the headers
roundTripper := http.RoundTripperFunc(func(req *http.Request) (*http.Response, error) {
req.Header.Set("X-Auth-Token", token)
req.Header.Set("X-User-Id", tokenID)
return client.Transport.RoundTrip(req)
})
// Assign the custom RoundTripper to the client
client.Transport = roundTripper
return &Notifier{
conf: c,
tmpl: t,
logger: l,
client: client,
retrier: ¬ify.Retrier{},
postJSONFunc: notify.PostJSON,
token: token,
tokenID: tokenID,
}, nil
}
Am I missing something, or is this functionality not available yet https://github.com/golang/go/issues/38479
I did adapt the code with a custom RoundTripper