alertmanager icon indicating copy to clipboard operation
alertmanager copied to clipboard

feat: add rocketchat notifier

Open TheMeier opened this issue 1 year ago • 10 comments

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 avatar Nov 12 '23 15:11 TheMeier

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.

TheMeier avatar Nov 13 '23 15:11 TheMeier

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

TheMeier avatar Nov 18 '23 16:11 TheMeier

@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.

TheMeier avatar Feb 13 '24 18:02 TheMeier

@gotjosh can I get a review please?

TheMeier avatar Mar 09 '24 13:03 TheMeier

@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 avatar Mar 25 '24 10:03 grobinson-grafana

@grobinson-grafana I have tested them with a real-live inhouse rocketchat server.

TheMeier avatar Mar 25 '24 10:03 TheMeier

Any chance for some progress here or in #3776 ?

TheMeier avatar Jun 14 '24 12:06 TheMeier

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:      &notify.Retrier{},
        postJSONFunc: notify.PostJSON,
        token:        token,
        tokenID:      tokenID,
    }, nil
}

roidelapluie avatar Aug 19 '24 08:08 roidelapluie

Am I missing something, or is this functionality not available yet https://github.com/golang/go/issues/38479

TheMeier avatar Aug 19 '24 15:08 TheMeier

I did adapt the code with a custom RoundTripper

TheMeier avatar Aug 19 '24 16:08 TheMeier