Ad Widget

Collapse

Getting working the Slack Bot

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Raaweni
    Junior Member
    • Mar 2021
    • 6

    #16
    I have the same exact situation. I "fixed" the 3 alert-messages problems by changing "Attempts" from 3 to 1 in the Slack media type Options. But I still get every now and then "invalid_auth" for some alerts even though they do come through into Slack. Every single Resolved-message fails in "channel_not_found".

    Comment

    • Valinor
      Junior Member
      • Sep 2020
      • 20

      #17
      I have the same one, 3 alerts fixed by reducing attempts, but every Problem message marked as invalid_auth, though delivered into Slack. Resolved messages don't have error somehow.

      Comment

      • mwildam
        Member
        • Feb 2021
        • 72

        #18
        Originally posted by Valinor
        I have the same one, 3 alerts fixed by reducing attempts, but every Problem message marked as invalid_auth, though delivered into Slack. Resolved messages don't have error somehow.
        In my case it is exactly the opposite - I have problems with the resolved messages.

        Comment

        • dig412
          Junior Member
          • Apr 2021
          • 2

          #19
          Thanks to the advice in this thread and the linked Jira issue I've found a fix for slack notifications on Zabbix 5.2.6.

          The issue was in the `getPermalink` method - the script was posting to slack correctly, but failing to get a link to the posted message. It was then trying to tag the problem with the message link so it could be updated automatically when the problem was resolved.
          This caused the problems with the resolved messages as well - they couldn't find the original message to update.

          Slack's documentation says that `getPermalink` is a `GET` method, but it appears to only accept `POST`.

          Here's a fixed `getPermalink` method - replace the one in your script and hopefully it should work:

          Code:
          function getPermalink(channelId, messageTimestamp) {
          var req = new CurlHttpRequest();
          
          req.AddHeader('Content-Type: application/x-www-form-urlencoded; charset=utf-8');
          req.AddHeader('Authorization: Bearer ' + params.bot_token);
          
          var resp = JSON.parse(
          req.Post(Slack.getPermalink + '?channel={0}&message_ts={1}'.format(
          channelId,
          messageTimestamp
          ), 'token='+params.bot_token)
          );
          
          if (req.Status != 200 && !resp.ok) {
          throw resp.error;
          }
          
          return resp.permalink;
          }
          You don't need to make the change to `{EVENT.UPDATE.STATUS}` as posted earlier - that sidestepped the problem by not trying to update messages at all.

          Comment

          • Zwirni
            Junior Member
            • Sep 2019
            • 5

            #20
            Thanks. This works for me

            Comment

            • Raaweni
              Junior Member
              • Mar 2021
              • 6

              #21
              Thanks dig412,

              That helped me get my Resolved messages through to Slack. That's awesome!
              But for some reason I still do get an occasional "Slack notification failed : invalid_auth" error for Problems too. Most get through, but not all. Which is kind of strange.

              Comment

              • mwildam
                Member
                • Feb 2021
                • 72

                #22
                Thanks a very lot to digi412! - I did now use the original webhook template without any other modification than replacing the getPermalink, as you mentioned, and now it seems to work (although I did believe that already a few times were it worked one or two times and then failed again...). However, I tried several times with success. A last doubt I have: Maybe if too many notifications in a too short period, Slack limits messages per second or minute and then makes them fail again. Maybe - I will keep an eye on that.

                Comment

                • Raaweni
                  Junior Member
                  • Mar 2021
                  • 6

                  #23
                  Worked for me too! Well mostly. Some messages still don't come through and then at some point I started to witness a weird phenomenon: A Problem would come through to Slack only to be _replaced_ by a Resolved-message when one came through. Then it started spamming a ton of resolved messages and I had no problems on the Slack channel to connect them to.

                  Comment

                  • mwildam
                    Member
                    • Feb 2021
                    • 72

                    #24
                    Yes, - but not weird, that is a cool feature! - And for example does not do so in the direct Telegram integration.

                    Comment

                    • Jason
                      Senior Member
                      • Nov 2007
                      • 430

                      #25
                      Have the same channel not found error despite having that updated script above.

                      Comment

                      • mwildam
                        Member
                        • Feb 2021
                        • 72

                        #26
                        Can you post something to this channel using curl or other tool? First you should make sure that in Slack everything is done correctly.

                        Comment

                        • Jason
                          Senior Member
                          • Nov 2007
                          • 430

                          #27
                          I can post to the channel. Zabbix can send the problem to the channel ok. It's just the resolved part that seems to go wrong.

                          That is the weird part. It's already posted to the channel so it knows the channel is there. I have the permalink fix above (without that the problem message fails even though it appears in slack 3 times)

                          It worked once for me ok. The only thing I can see there is on that message in slack it has event tags as none and now it has [] there on the later messages

                          ​​​​​I feel the problem is in the getPermalink function somehow
                          Last edited by Jason; 18-09-2021, 10:26. Reason: Added more info

                          Comment

                          • mwildam
                            Member
                            • Feb 2021
                            • 72

                            #28
                            Here is my current script, which is working.
                            Attached Files

                            Comment

                            • Jason
                              Senior Member
                              • Nov 2007
                              • 430

                              #29
                              Originally posted by mwildam
                              Here is my current script, which is working.
                              Many thanks. I'll try that. What version is your zabbix? Mine is 5.0.10

                              Comment

                              • mwildam
                                Member
                                • Feb 2021
                                • 72

                                #30
                                No, I use v5.2.4 - and it was a fresh installation.

                                Comment

                                Working...