This is simply a Bash script that uses the custom alert script functionality within Zabbix along with the incoming web-hook feature of Slack. I originally created this since I could not find any already existing/similar scripts at the time. This is one of many now.
This works with Zabbix 1.8 or greater - including 2.x and 3.x, as well as the newest 4.0 and 4.2 versions!
The latest version of Zabbix (4.4) has included its own built-in webhook media type which is documented here:
Official Zabbix Documentation 4.4 > Media Types > Webhook
The Zabbix 4.4 webhook documentation includes a specific example of how to set up Slack webhook notifications with their new included feature.
Huge thanks and appreciation to every one who has submitted issues or pull requests including:
This slack.sh
script needs to be placed in the AlertScriptsPath
directory that is specified within the Zabbix servers' configuration file (zabbix_server.conf
) and must be executable by the user running the zabbix_server binary (usually "zabbix") on the Zabbix server:
[root@zabbix ~]# grep AlertScriptsPath /etc/zabbix/zabbix_server.conf
### Option: AlertScriptsPath
AlertScriptsPath=/usr/local/share/zabbix/alertscripts
[root@zabbix ~]# ls -lh /usr/local/share/zabbix/alertscripts/slack.sh
-rwxr-xr-x 1 root root 1.4K Dec 27 13:48 /usr/local/share/zabbix/alertscripts/slack.sh
If you do change AlertScriptsPath
(or any other values) within zabbix_server.conf
, a restart of the Zabbix server software is required.
An incoming web-hook integration must be created within your Slack.com account which can be done at https://my.slack.com/services/new/incoming-webhook as shown below:
Given the above screenshot, the incoming Slack.com web-hook URL would be:
https://hooks.slack.com/services/QW3R7Y/D34DC0D3/BCADFGabcDEF123
Make sure that you specify your correct Slack.com incoming web-hook URL and feel free to edit the sender user name at the top of the script:
# Slack incoming web-hook URL and user name
url='https://hooks.slack.com/services/QW3R7Y/D34DC0D3/BCADFGabcDEF123'
username='Zabbix'
When logged in to the Zabbix servers web interface with super-administrator privileges, navigate to the "Administration" tab, access the "Media Types" sub-tab, and click the "Create media type" button.
You need to create a media type as follows:
...and ensure that it is enabled before clicking "Save", like so:
However, on Zabbix 3.x and greater (including 4.x), media types are configured slightly differently and you must explicity define the parameters sent to the slack.sh
script. On Zabbix 3.x and 4.x, three script parameters should be added as follows:
{ALERT.SENDTO}
{ALERT.SUBJECT}
{ALERT.MESSAGE}
...as shown here:
An optional fourth script parameter can be added to over-ride the url
value that is hard-coded in the slack.sh
script. This makes it possible to re-use the script for multiple Slack teams.
An optional fifth script parameter can be added for proxy support. You can supply a host:port
value (such as example.com:8080
) that will be used when connecting to the Slack.com web-hook URL.
Then, create a "Slack" user on the "Users" sub-tab of the "Administration" tab within the Zabbix servers web interface and specify this users "Media" as the "Slack" media type that was just created with the Slack.com channel ("#alerts" in the example) or user name (such as "@ericoc") that you want messages to go to in the "Send to" field as seen below:
Finally, an action can then be created on the "Actions" sub-tab of the "Configuration" tab within the Zabbix servers web interface to notify the Zabbix "Slack" user.You can stick with the default subject and message text for your problem (and optional recovery) operations.
Additionally, you can have multiple different Zabbix users each with "Slack" media types that notify unique Slack users or channels upon different triggered Zabbix actions.
The new Testing media types feature within Zabbix 4.2 should allow you to test sending messages to Slack:
Alternatively, you can execute the script manually (as opposed to via Zabbix) from Bash on a terminal:
$ bash slack.sh '@ericoc' 'Problem: This is a test' 'This is a test of something being wrong!'
Alerting a specific user name results in the message actually coming from the "Slackbot" user using a sort-of "spoofed" user name within the message. A channel alert is sent as you would normally expect from whatever user name you specify in slack.sh
:
slack script find / -name 'alertscripts' cd /usr/local/share/zabbix/alertscripts wget https://raw.githubusercontent.com/ssplatt/zabbix-slack-alertscript/master/slack_zabbix.py chmod 755 slack_zabbix.p
RHEL 7 上安装1. 准备 yum 源 # rpm -ivh https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm # subscription-manager repos --enable="rhel-7-server-extras-rpms" # subscription-m
Zabbix 是一个企业级分布式开源监控解决方案。 Zabbix 软件能够监控众多网络参数和服务器的健康度、完整性。Zabbix 使用灵活的告警机制,允许用户为几乎任何事件配置基于邮件的告警。这样用户可以快速响应服务器问题。Zabbix 基于存储的数据提供出色的报表和数据可视化功能。这些功能使得 Zabbix 成为容量规划的理想选择。 Zabbix 支持主动轮询(polling)和被动捕获(tra
slack-term A Slack client for your terminal. Installation Binary installation Download acompatible binary for your system. For convenience, place slack-term in adirectory where you can access it from
slack-cli | Powerful Slack CLI via pure bash A pure bash, pipe friendly, feature rich, command line interface for Slack.Richly formatted messages,file uploads, and even creating Slack posts are first
Elixir-Slack This is a Slack Real Time Messaging API client for Elixir. You'll need aSlack API token which can be retrieved by following the Token GenerationInstructions or by creating anew bot integr
这里主要汇总了一些在使用zabbix过程中经常用的监控模板。 OS: OS_Linux_Server OS_Netstats OS_Network_Status ... App: App_Apache_Status App_Nginx_Status App_Php-fpm_Status ... 使用方法: 这里使用的template基本是使用zabbix trapper的方式通过程序收集数据,通过