Ad Widget

Collapse

Getting working the Slack Bot

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Jason
    Senior Member
    • Nov 2007
    • 430

    #31
    Ok. I'm still getting channel not found error. Something isn't quite right somewhere. It's only on the resolved message, which is the curious part.

    Comment

    • mwildam
      Member
      • Feb 2021
      • 72

      #32
      Then probably it is a difference in my Zabbix version, which is pretty much newer. Is an update an option for you?

      Comment

      • Jason
        Senior Member
        • Nov 2007
        • 430

        #33
        Originally posted by mwildam
        Then probably it is a difference in my Zabbix version, which is pretty much newer. Is an update an option for you?
        Unfortunately we use vmbix as well which doesn't work in versions newer than 5.0.X without crashing server/proxy. Evaluating the inbuilt vmware, but it's lacking in a few key functionalities.

        It looks main difference between 5.0.X script and 5.2.X is the process tags section.

        Comment

        • mwildam
          Member
          • Feb 2021
          • 72

          #34
          I started using Zabbix with v5.2.4 and never did an update so far - so I really can't tell, have no experience with older versions nor looked at any of the underlying code.

          Comment

          • Jason
            Senior Member
            • Nov 2007
            • 430

            #35
            Getting closer to the problem. permaLink is working I think and it's in handlerAlarm and it's not getting the channel id correctly in the "else if (isEventResolve(params)) { " section



            Code:
            function handlerAlarm(params) {
            var fields = {
            channel: params.channel,
            as_user: params.slack_as_user,
            };
            
            if (isEventProblem(params)) {
            fields.attachments = [
            createMessage(
            SEVERITY_COLORS[params.event_nseverity] || 0,
            params.event_date,
            params.event_time,
            createProblemURL(params.zabbix_url, params.trigger_id, params.event_id, params.event_source)
            )
            ];
            
            var resp = JSON.parse(req.Post(Slack.postMessage, JSON.stringify(fields)));
            
            if (req.Status != 200 && !resp.ok) {
            throw resp.error;
            }
            
            result.tags.__message_ts = resp.ts;
            result.tags.__channel_id = resp.channel;
            result.tags.__channel_name = params.channel;
            result.tags.__message_link = getPermalink(resp.channel, resp.ts);
            }
            else if (isEventUpdate(params)) {
            fields.thread_ts = getTagValue(params.event_tags, 'message_ts');
            fields.attachments = [
            createMessage(
            SEVERITY_COLORS[params.event_nseverity] || 0,
            params.event_update_date,
            params.event_update_time,
            createProblemURL(params.zabbix_url, params.trigger_id, params.event_id, params.event_source),
            true
            )
            ];
            
            resp = JSON.parse(req.Post(Slack.postMessage, JSON.stringify(fields)));
            if (req.Status != 200 && !resp.ok) {
            throw resp.error;
            }
            
            }
            else if (isEventResolve(params)) {
            fields.channel = getTagValue(params.event_tags, 'channel_id');
            fields.text = '';
            fields.ts = getTagValue(params.event_tags, 'message_ts');
            fields.attachments = [
            createMessage(
            RESOLVE_COLOR,
            params.event_date,
            params.event_time,
            createProblemURL(params.zabbix_url, params.trigger_id, params.event_id, params.event_source)
            )
            ];
            
            resp = JSON.parse(req.Post(Slack.chatUpdate, JSON.stringify(fields)));
            if (req.Status != 200 && !resp.ok) {
            throw resp.error;
            }
            }
            }

            Comment

            • Jason
              Senior Member
              • Nov 2007
              • 430

              #36
              Ah-ha!. Got it working. The script was correct but I was missing channel_id and message_ts in the variables.

              Here is my working media type. zbx_export_mediatypes.xml and I've defined a global macro called {$BOT_TOKEN} that is a secret string holding the api key

              Comment


              • KeeFeeRe
                KeeFeeRe commented
                Editing a comment
                Thanks! Thats's work as espected!
            Working...