Send Alert's Notification's from Zabbix to Slack - Hammadiqbal02/Installation-of-Zabbix-on-Ubuntu- GitHub Wiki

Slack Setup

The first step is to create an App and retrieve a Slack bot token. Slack’s API works really well but if your workplace has been in use for years it can be frustrating to find the correct page that has the information you need. They seem to have changed their API a few times and it’s not very clear which page you need to go to for which tokens, and what those tokens specifically do. I’ll try to make it clear in these instructions. image

Start at https://api.slack.com/apps. You will need to login to your Workplace if you are not logged in already. When logged in, the page should look like this:

image

Click on Create an App. Name the app Zabbix Alerts or something similar:

image

It should take you to the Basic Information for your new app: image

Click on “Bots” on the bottom left. Now you are directed to App Home (which is not the Bots page)

image

click on :OAuth and Permission and get bot-token

c

Under Bot Token Scopes add an OAuth Scope of “chat:write”:

image

Now that the Bot Token has a scope, the “Install App in Workplace” button located on the same page (OAuth & Permissions) should be green. Click on it and it should redirect you to a page, then be redirected back to the OAuth & Permissions page, but now you have a Bot User OAuth Access Token:

image

The last step is to create a test Slack channel and add the app. Open Slack and create a channel named zabbix-test or whatever you want to name it:

image

Since Slack is so intuitive you have to click the (i) Details button in the top right corner of the channel box, then click More, then click Add apps. From there you can select your Zabbix Alerts app:

image

When you click Add it will say something about Zabbix Alerts in the main chat area:

image

That should be all that is required for Slack setup. Everything else is on Zabbix now.

Zabbix Setup I highly, highly recommend considering updating to Zabbix 5.0+ for the sole reason that it allows for secret macros. The official documentation for Zabbix 6.4.3 Slack integration allows any user with access to global macros to see the bot token in plain text.

IF YOU DON'T HAVE SLACK FILE YOU CAN DOWNLOAD IT FROM ZABBIX OFFICAL:

https://git.zabbix.com/projects/ZBX/repos/zabbix/browse/templates/media/slack/media_slack.yaml

you will get your machine server-compatible version from here : image

you can create and import Media type's if slack not available

image

Zabbix Webhook configuration

Create a global macro

  1. Before setting up the Webhook, you need to setup the global macro {$ZABBIX.URL}, which must contain the URL to the Zabbix frontend.

  2. In the Administration > Media types section, import the media_slack.yaml

  3. Open the added Slack media type and set bot_token to the previously created token.

You can also choose between two notification modes: alarm (default) Update messages will be attached as replies to Slack message thread Recovery message from Zabbix will update initial message event Recovery and update messages from Zabbix will be posted as new messages 4. Click the Update button to save the Webhook settings.

  1. To receive notifications in Slack, you need to create a Zabbix user and add Media with the Slack type.

The Send to field can contain several variants of values:

Channel name in #channel_name format User name in @slack_user format for direct messages Identifier (for example: GQMNQ5G5R) 6. You must add your bot to the target channel

You can add Macros here : $Zabbix_url : hhtp://ip/zabbix $Zabbix.url=ip in macros

image

nce you upload that, there should be a green bar at the top of the screen that says success, then navigate back to the Media types page and select Slack. You should be presented with many fields: You must Enable it image

whne you click on slack it will open like below :

bot_token is set for {$SLACKTOKEN} put the bot token Remember to scroll to the bottom and click Update when you make any updates.

image

Now need to Test the Notification Alert

image

Click on Test and enter value's:

image

open your slack app and see

image

if you did not get check and verify it your app is install on your channel

image

Now just navigate to Adminstration > Users. You will need to create a user for every channel or direct message that is used. For example, I want to send notifications to #zabbix-test channel, so I create a user specifically for that. If I wanted to send notifications to #zabbix-alerts also, I would have to create a second user. So to start I am creating Alias “Slack_zabbix-test” and it is added to the Group “No access to the frontend”:

image Go to the Media tab and add the Type “Slack” and Send to should be your channel name, so for my case it is #zabbix-test:

image

Leave all the severity levels default, we will define what triggers cause notifications with Actions. Add the Media and add the user: image

This sets up all of the routing needed to get notifications to Slack, now we just need to setup triggers to cause notifications. Navigate to image

image

Set the Name to “Report to #zabbix-test Slack” or whatever you named your channel. This is where you clearly define what triggers will cause notifications to go to Slack. The easiest way to keep your Zabbix system under control is to use Tags here. I’ll set mine to “Tag value” and have the name be “#slack_zabbix-test” “equals” “1”. This means any tag with the name of #slack_zabbix-test and the value of 1 will be sent to the Slack channel #zabbix-test.

when you click on it add a condition if for host or host group or trigger image

when you click on add image

click on 2nd tab Operations:

image

can add for user or user group and after all of these click update :

image

you can make more Trigger actions and Get Enable them in the most right corner : image

Click Update then head over to Monitoring > Problems and make sure a host is selected. After a minute or two you should see the problems start. If you look under Actions you will see it also sent a notification to Slack.

image

if there is a problem it will show like below

image

image

after the source is up it will show recovery alert image

image

Conclusion

Any trigger generated in Zabbix can be specifically routed to any Slack channel as a message with details about the host experiencing the trigger. It is not difficult to setup and it provides users with simple notifications that don’t require checking Zabbix.