配置系統mail命令,使其能夠發送外網郵件
mail 命令配置
修改zabbix_server配置文件,使其能夠執行告警腳本
[root@rexen etc]# vim /usr/local/zabbix/etc/zabbix_server.conf 474 ### Option: AlertScriptsPath 475 # Full path to location of custom alert scripts. 476 # Default depends on compilation options. 477 # 478 # Mandatory: no 479 # Default: 480 AlertScriptsPath=/usr/local/zabbix/share/zabbix/alertscripts #放開這裏的註釋,咱們把告警腳本寫在這裏.
8
1
[root@rexen etc]# vim /usr/local/zabbix/etc/zabbix_server.conf
2
474 ### Option: AlertScriptsPath
3
475 # Full path to location of custom alert scripts.
4
476 # Default depends on compilation options.
5
477 #
6
478 # Mandatory: no
7
479 # Default:
8
480 AlertScriptsPath=/usr/local/zabbix/share/zabbix/alertscripts #放開這裏的註釋,咱們把告警腳本寫在這裏.
告警腳本
[root@rexen etc]# cd /usr/local/zabbix/share/zabbix/alertscripts [root@rexen alertscripts]# vim sendmail.sh #!/bin/bash export LANG=zh_CN.UTF-8 FILE=/tmp/mailtmp.txt echo "$3" > $FILE #echo "$3" | mail -s "$2" "$1" dos2unix -k $FILE /bin/mail -s "$2" $1 < $FILE # 注意dos2unix須要獨立安裝,解決郵件沒有正文(正文變成附件AT0000001.bin)的問題.
x
1
[root@rexen etc]# cd /usr/local/zabbix/share/zabbix/alertscripts
2
[root@rexen alertscripts]# vim sendmail.sh
3
#!/bin/bash
4
export LANG=zh_CN.UTF-8
5
6
FILE=/tmp/mailtmp.txt
7
8
echo "$3" > $FILE
9
#echo "$3" | mail -s "$2" "$1"
10
dos2unix -k $FILE
11
/bin/mail -s "$2" $1 < $FILE
12
13
# 注意dos2unix須要獨立安裝,解決郵件沒有正文(正文變成附件AT0000001.bin)的問題.
Web上配置新告警媒介
![](http://static.javashuo.com/static/loading.gif)
注意腳本的參數的宏變量名字, 這裏是官方推薦的.
![](http://static.javashuo.com/static/loading.gif)
配置將要發送的目標郵箱
在用戶管理裏面建立對應的用戶
![](http://static.javashuo.com/static/loading.gif)
這裏配置發送的郵箱, 和都有哪些種類的告警信息須要發送.
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
注意! 注意! 注意! 用戶的權限必須是超級管理員, 讓他能夠有全部羣組的讀寫權限, 這樣才能夠收到郵件.
![](http://static.javashuo.com/static/loading.gif)
配置高級發送動做(Action)
![](http://static.javashuo.com/static/loading.gif)
填寫名稱, 填寫觸發條件, 這裏咱們選擇服務器(該服務器的全部內容都會發送告警)
![](http://static.javashuo.com/static/loading.gif)
定義操做, 將相關的信息發送給指定負責人. 這裏咱們能夠修改標題和內容.
![](http://static.javashuo.com/static/loading.gif)
注意: 這裏能夠定義告警發生時的操做, 和告警恢復的時候的操做.