Ad Widget

Collapse

Slack webhook in Zabbix

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Slack webhook in Zabbix

    Hi,

    Recently upgraded to 5.2.0 on one of my installations.
    As we would like to have the notifications in Slack, I tried it for the first time (never done and configured that before).
    Went with the "built in" instead of 3rd party solutions.
    First of all, I soon figured that the documentation is somewhat behind - Slack has changed and to set up the Slack app, it does not correspond to what is said in Zabbix manual. Tried to intuitively do and think/hope did it correct.
    But then immediately hit the wall on Zabbix side too as the actions fail with this error:
    Code:
    TypeError: undefined not callable (property 'log' of [object Object])
    at [anon] (duktape.c:65639) internal
    at [anon] (function:382) preventsyield
    As I do not have any reasonable experience with webhooks in zabbix or elsewhere and this error does not really help much I decided to try another one that is easily available to me, Discord.
    Magic - that worked out of the box, so its not that bad with me. After some more troubleshooting I decided to compare the JS code for Slack and Discord webhooks. The code is wrapped in try/catch statements that in Slack's JS ends like this:
    Code:
    catch (error) {
    Zabbix.log(4, '[ Slack Webhook ] Slack notification failed : ' + error);
    throw 'Slack notification failed : ' + error;
    }
    Ha. Corresponding part of Discord's script calls Zabbix.Log. OK, changed L to capital one and now in action log I get the real error that throws this catch actually:
    Code:
    Slack notification failed : ReferenceError: identifier 'HttpRequest' undefined
    Here though, comparing two scripts didn't really help as Discord's script uses CurlHttpRequest. Yes, I tried replacing HttpRequest with CurlHttpRequest, then there were some more problems with uppercase and lowercase letters but eventually it started complaining about badly formed JSON or something and thats where I gave up.

    So to sum up, it seems the documentation on Slack webhook is well outdated and the script for it also seems to have its problems. Might consider submitting a bug report but as I really do not have much experience with webhooks / JS, I still am not sure if I am doing everything right. Does anyone have the bundled Slack thing work out of the box on 5.2.0?
    (I know 5.2.1 is out now but the Slack thing is not mentioned in the release notes)

    Regards,
    Ervins

    #2
    I've hit the same issues on my Dev Server - have never had any slack integration and tried to install from git templates and README. I've submitted a bug report here https://support.zabbix.com/browse/ZBX-18673

    Comment


      #3
      This is the fix that worked for me on the pagerduty scripts

      Change HttpRequest to CurlHttpRequest, then any .log needs to be .Log, addHeader needs to be AddHeader and req.post needs to be req.Post that should get you up and running

      Cheers

      Comment


        #4
        Appreciate the attempt Liquid - after your suggestions I then get a json error -
        • Slack notification failed : SyntaxError: invalid json (at offset 1)

        Comment


          #5
          Hello,

          I see that Slack change logics with tokens, but it still works.
          I can provide a short manual about it for you:
          Go to your Slack -> Apps -> App Directory -> Build -> Start Building -> Create Slack App ->
          -> add features and functionality section -> choose Bots -> Review Scopes to Add -> Add an OAuth Scope
          -> chose Chat:Write. -> Install App to the Workspace -> copy Token inside Zabbix Webhook bot_token value
          -> Configure Message templates (add necessary) -> Add Slack Media to your zabbix user (send to row please use your zabbix channel name, don't forgot add your channel to your app) -> go to Actions -> Triger actions and enable it

          Click image for larger version

Name:	webhook.PNG
Views:	168
Size:	136.3 KB
ID:	413571
          Last edited by AVP.Riga; 20-11-2020, 17:31.

          Comment


            #6
            Riga -

            I have slack side and tokens set correctly, it's just the script on Zabbix server side not executing correctly. I never had any integration setup before so this is all new from official git webhook. I've tested on DEV server running 5.2 and our production server running 5.0.5 - same errors as OP from install. Changing some function calls in the script as outlined in the posts responses has got me to the last json error I posted. I can manually call Slack channel with success from server cli, and have other APPs working fine (i.e. Zendesk w? Slack).

            Comment


              #7
              To any and all -

              The issue resides with the git download template - as we all seem to be leaning towards the script itself (besides the out dated Slack documentation). I did a fresh server install instance, one where you import the packages DB schema and all the current templates, media types, value maps, webhooks, etc are installed as default (server 5.2.1). Once I set the test parameters in this instance the slack integration worked as expected. I then copied the new instance script over to my DEV and Productions servers and everything is working as expected. I'm going to do a diff between git template and schema import to find all teh differences - at first glance it was everything listed by Liquid earlier in the posts, but must have some more.

              ...hope this helps erv

              camelCase instances that need updating in git template import : all req.X (Status, Get, Post, etc should be capital, not lowercase), Zabbix.Log, not 'log', HttpRequest ->CurlHttpRequest *found 18 diff in script comparison from git import to schema import.

              Those not wanting the hassle of the schema script - attached here for slack. Note it seems most of the git templates have this error - I added Zendesk and ran into same issues
              Attached Files
              Last edited by cwhite; 20-11-2020, 20:40.

              Comment


                #8
                I can confirm that replacing the webhook script from the git with the one posted here does the trick and then it works as intended.

                Comment

                Announcement

                Collapse
                No announcement yet.
                Working...
                X