[ZBXNEXT-5562] Create webhook integration with slack. Created: 2019 Nov 12  Updated: 2024 Apr 10  Resolved: 2020 Feb 01

Status: Closed
Project: ZABBIX FEATURE REQUESTS
Component/s: Templates (T)
Affects Version/s: None
Fix Version/s: 4.4.5rc1, 5.0.0alpha1, 5.0 (plan)

Type: New Feature Request Priority: Trivial
Reporter: Aleksandrs Larionovs (Inactive) Assignee: Anton Fayantsev (Inactive)
Resolution: Fixed Votes: 4
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
Sub-task
Team: Team INT
Sprint: Sprint 58 (Nov 2019), Sprint 59 (Dec 2019), Sprint 60 (Jan 2020)
Story Points: 3

 Description   

Slack is popular messenger. Having a webhook integration that is shipped with Zabbix will result in more efficient monitoring



 Comments   
Comment by Marco Hofmann [ 2019 Nov 12 ]

IMHO the same can be said about MS Teams, which is getting more important every day in the Enterprise business.

Comment by Anton Fayantsev (Inactive) [ 2020 Jan 15 ]

Avaliable in:
4.4.4rc1a2239e4ab5b
5.0alpha1ee447e8397b

Comment by Atsushi Tanaka [ 2020 Jan 28 ]

I tried it with Zabbix 4.4.5rc1 and Zabbix 5.0.0alpha1, but I could not send it properly due to an error. When a failure occurs, the following transmission error is recorded.

Slack notification failed : SyntaxError: invalid json (at offset 1)

Since an error occurs during transmission, three retries are set for the media.

At the time of recovery from the failure, the tag settings have not been inherited or the channel cannot be specified normally, and the following error is recorded.

Slack notification failed : channel_not_found
Comment by Steffen Scheib [ 2020 Jan 28 ]

I just upgraded to 4.4.5 on a Raspbian 10.2. I was very excited to try out the new media type, however, it does not seem to be automatically added.

Is there anything, which needs to be done in order to get this working, besides upgrading the package via apt?

The upgrade log also did not reveal any errors at all:

root@zabbix:/home/steffen# apt-get upgrade
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Calculating upgrade... Done
The following packages will be upgraded:
  zabbix-agent zabbix-frontend-php zabbix-get zabbix-server-mysql
4 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Need to get 5,739 kB of archives.
After this operation, 58.4 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://repo.zabbix.com/zabbix/4.4/raspbian buster/main armhf zabbix-server-mysql armhf 1:4.4.5-1+buster [2,402 kB]
Get:2 http://repo.zabbix.com/zabbix/4.4/raspbian buster/main armhf zabbix-agent armhf 1:4.4.5-1+buster [444 kB]
Get:3 http://repo.zabbix.com/zabbix/4.4/raspbian buster/main armhf zabbix-frontend-php all 1:4.4.5-1+buster [2,547 kB]
Get:4 http://repo.zabbix.com/zabbix/4.4/raspbian buster/main armhf zabbix-get armhf 1:4.4.5-1+buster [346 kB]
Fetched 5,739 kB in 4s (1,291 kB/s)  
Reading changelogs... Done
(Reading database ... 51592 files and directories currently installed.)
Preparing to unpack .../zabbix-server-mysql_1%3a4.4.5-1+buster_armhf.deb ...
Unpacking zabbix-server-mysql (1:4.4.5-1+buster) over (1:4.4.4-1+buster) ...
Preparing to unpack .../zabbix-agent_1%3a4.4.5-1+buster_armhf.deb ...
Unpacking zabbix-agent (1:4.4.5-1+buster) over (1:4.4.4-1+buster) ...
Preparing to unpack .../zabbix-frontend-php_1%3a4.4.5-1+buster_all.deb ...
Unpacking zabbix-frontend-php (1:4.4.5-1+buster) over (1:4.4.4-1+buster) ...
Preparing to unpack .../zabbix-get_1%3a4.4.5-1+buster_armhf.deb ...
Unpacking zabbix-get (1:4.4.5-1+buster) over (1:4.4.4-1+buster) ...
Setting up zabbix-server-mysql (1:4.4.5-1+buster) ...
Setting up zabbix-frontend-php (1:4.4.5-1+buster) ...
Setting up zabbix-agent (1:4.4.5-1+buster) ...
Setting up zabbix-get (1:4.4.5-1+buster) ...
Processing triggers for man-db (2.8.5-2) ...
Processing triggers for systemd (241-7~deb10u2+rpi1) ...
root@zabbix:/home/steffen#

I have to mention, I already have added a media type named "Slack" (mind the uppercase S) - is this maybe causing some issues here?

Comment by Atsushi Tanaka [ 2020 Jan 29 ]

Even in a new installation of 4.4.5, an error occurs in the same way and a failure occurrence notification is performed three times, and failure recovery notification cannot be performed.

 

@sscheib

Newly added media is not added when upgrading from a previous version. Try import what you exported from the newly installed environment, or get XML from Git and import it. If you already have a media named Slack, you should simply change the name value in the XML to something else when importing.

Slack webhook:
https://git.zabbix.com/projects/ZBX/repos/zabbix/browse/templates/media/slack

Comment by Steffen Scheib [ 2020 Jan 29 ]

@Atsushi Tanaka

I already did that, however, facing the following issue:

https://www.zabbix.com/forum/zabbix-troubleshooting-and-problems/394351-zabbix-4-4-5-slack-media-type-tcp-close-wait

Comment by Atsushi Tanaka [ 2020 Jan 30 ]

The environment where the problem is occurring is as follows.

OS: CentOS 7.7.1908
Zabbix: 4.4.5
How to install: yum command from Offical Zabbix repository

Reproduction procedure
1. Create an application with Slack's free plan
2. Generate Token and Invite Application to Channel
3. Confirm that a simple message can be posted on Slack with the curl command
4. Set {$ZABBIX.URL} as a global macro of Zabbix
5. Set the generated token to bot_token in the media settings of Slack
6. Specify a channel that can post Slack as media for users on Zabbix and configure

Problem occurrence situation
Action is performed when a failure occurs, but an error occurs. The following message is recorded for the error that occurs.

Slack notification failed : SyntaxError: invalid json (at offset 1)

The message has been posted to Slack, but Zabbix will send the message three times because it determines that it failed with an error. Since an error occurs when Zabbix notifies Slack of a failure, no value is set in the event tag.

Comment by Steffen Scheib [ 2020 Jan 30 ]

@Atsushi Tanaka

I experienced the same behaviour if {$ZABBIX.URL} is set without a scheme (eg zabbix.lan). Have you tried it with https://zabbix.lan or http://zabbix.lan (obviously adjust the URL for your environment)?

This fixes the issue with the multiple notifications, leaves however for every notification/event a TCP CLOSE-WAIT socket behind, which is every unfortunate.

Would be great, if you could verify whether you have the same issue on CentOS.

Comment by Travis Roberts [ 2020 Jan 30 ]

I am running into the same issue on CentOS as well.  The URL macro is set as well.

Comment by Atsushi Tanaka [ 2020 Jan 31 ]

I specify a URL using a private IP address in the global macro {$ZABBIX.URL}.

ex.

http://192.168.1.1/zabbix/

With this setting, I can confirm that the button in the message notified to Slack has the URL to the trigger event.

ex.

http://192.168.1.1/zabbix/tr_events.php?triggerid=16199&eventid=53
Comment by Alexander Vladishev [ 2020 Feb 01 ]

Updated documentation:

Comment by Atsushi Tanaka [ 2020 Feb 04 ]

It was confirmed that it works normally in Ubuntu 18.04 environment.
Doesn't work on CentOS 7, does closing mean that CentOS 7 is not considered to work? Or should I report a new bug?

 

Zabbix 4.4.5 on CentOS 8 has been confirmed to work.

Comment by Aleksandrs Larionovs (Inactive) [ 2020 Feb 04 ]

atanaka - what issue are you experiencing on centos 7. Can you please provide a little more detail.

 

Comment by Atsushi Tanaka [ 2020 Feb 04 ]

Please see the post above.

If an action is performed when a failure occurs, an error will occur when sending to Slack. The error messages that are confirmed on the Web front end are as follows.

Slack notification failed : SyntaxError: invalid json (at offset 1)

The message is sent to Slack, but Zabbix recognizes it as an error and retries three times as configured.

An error occurs when a failure occurs, and no value is set in the event tag. In that case, when executing the action at the time of failure recovery, information such as channels will not be inherited, so this will also result in an error. The error messages that are confirmed on the Web front end are as follows.

Slack notification failed : channel_not_found
Comment by Krzysztof Hajdamowicz [ 2020 May 05 ]

I have same errors as @Atsushi Tanaka, after looking for a cause of error it's looking that requests sent to Slack API are from Mattermost, not current-spec JSON described here https://api.slack.com/tools/block-kit-builder

 

What script was sending:

{
    "channel": "#monitoring",
    "as_user": "true",
    "attachments": [
        {
            "fallback": "PROBLEM: Free disk space is less than 3% on volume /",
            "title": "PROBLEM: Free disk space is less than 3% on volume /",
            "color": "#E97659",
            "title_link": "https://zabbix.example.com/tr_events.php?triggerid=32296&eventid=2520621",
            "pretext": "",
            "fields": [
                {
                    "title": "Host",
                    "value": "example.com [127.0.0.1]",
                    "short": true
                },
                {
                    "title": "Event time",
                    "value": "2020.05.05 14:22:53",
                    "short": true
                },
                {
                    "title": "Severity",
                    "value": "High",
                    "short": true
                },
                {
                    "title": "Opdata",
                    "value": "0.15 %",
                    "short": true
                },
                {
                    "title": "Event tags",
                    "value": "None",
                    "short": true
                },
                {
                    "title": "Trigger description",
                    "value": "",
                    "short": true
                }
            ],
            "actions": [
                {
                    "type": "button",
                    "text": "Open in Zabbix",
                    "url": "https://zabbix.example.com/tr_events.php?triggerid=32296&eventid=2520621"
                }
            ]
        }
    ]
}

Example payload slack was expecting:

{{ "blocks": [ { "type": "section", "text": { "type": "mrkdwn", "text": "Hello, Assistant to the Regional Manager Dwight! *Michael Scott* wants to know where you'd like to take the Paper Company investors to dinner tonight.\n\n *Please select a restaurant:*" } }, { "type": "divider" }, { "type": "section", "text": { "type": "mrkdwn", "text": "*Farmhouse Thai Cuisine*\n:star::star::star::star: 1528 reviews\n They do have some vegan options, like the roti and curry, plus they have a ton of salad stuff and noodles can be ordered without meat!! They have something for everyone here" }, "accessory": { "type": "image", "image_url": "https://s3-media3.fl.yelpcdn.com/bphoto/c7ed05m9lC2EmA3Aruue7A/o.jpg", "alt_text": "alt text for image" } }, { "type": "section", "text": { "type": "mrkdwn", "text": "*Kin Khao*\n:star::star::star::star: 1638 reviews\n The sticky rice also goes wonderfully with the caramelized pork belly, which is absolutely melt-in-your-mouth and so soft." }, "accessory": { "type": "image", "image_url": "https://s3-media2.fl.yelpcdn.com/bphoto/korel-1YjNtFtJlMTaC26A/o.jpg", "alt_text": "alt text for image" } }, { "type": "section", "text": { "type": "mrkdwn", "text": "*Ler Ros*\n:star::star::star::star: 2082 reviews\n I would really recommend the  Yum Koh Moo Yang - Spicy lime dressing and roasted quick marinated pork shoulder, basil leaves, chili & rice powder." }, "accessory": { "type": "image", "image_url": "https://s3-media2.fl.yelpcdn.com/bphoto/DawwNigKJ2ckPeDeDM7jAg/o.jpg", "alt_text": "alt text for image" } }, { "type": "divider" }, { "type": "actions", "elements": [ { "type": "button", "text": { "type": "plain_text", "text": "Farmhouse", "emoji": true }, "value": "click_me_123" }, { "type": "button", "text": { "type": "plain_text", "text": "Kin Khao", "emoji": true }, "value": "click_me_123" }, { "type": "button", "text": { "type": "plain_text", "text": "Ler Ros", "emoji": true }, "value": "click_me_123" } ] } ]}
Generated at Fri Apr 25 06:20:18 EEST 2025 using Jira 9.12.4#9120004-sha1:625303b708afdb767e17cb2838290c41888e9ff0.