天天看點

Zabbix郵件報警

本文主要以外部郵箱賬号完成報警郵件的發送。

1 如果安裝了Sendmail或postfix,則需要停止服務:

[root@www alertscripts]# uname -a

Linux www 3.10.0-514.el7.x86_64 #1 SMP Tue Nov 22 16:42:41 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

[root@www ~]# systemctl stop sendmail.service

[root@www ~]# systemctl disable sendmail.service

2 安裝郵件發送工具mailx:

[root@www ~]# yum install mailx

3 配置Zabbix服務端外部郵箱:

下面的語句可以追加到配置檔案的最後:

[root@www ~]# vim /etc/mail.rc 

set [email protected]  smtp=smtp.sina.com

set [email protected]  smtp-auth-password=19sssss

set smtp-auth=login

from:發送郵件的位址

smtp:外部smtp伺服器位址

smtp-auth-user:外部smtp伺服器認證的使用者名

smtp-auth-password:外部smtp伺服器認證的使用者密碼

smtp-auth:郵件認證的方式,

4 測試:

[root@www ~]# echo "a" | mail -s "b" [email protected]

其中a為内容,b為标題。

5 配置Zabbix伺服器郵件報警:

5.1 配置報警媒體:

打開zabbix的管理------處理方法----create media type:

<a href="https://s3.51cto.com/wyfs02/M01/9A/C0/wKioL1laEKGyF32-AABSyY5T420627.jpg-wh_500x0-wm_3-wmp_4-s_2936150828.jpg" target="_blank"></a>

我用的是腳本發郵件的方式來報警的,腳本名字為mail.sh。腳本存放位置,在zabbix_server.conf配置檔案中設定:AlertScriptsPath=/usr/lib/zabbix/alertscripts

[root@www alertscripts]# vim mail.sh 

#!/bin/bash

/usr/bin/echo "$3" | /usr/bin/mail -s "$2" $1

5.2 設定報警使用者:

我直接使用了已存在的管理者組,然後在其中添加使用者。

<a href="https://s5.51cto.com/wyfs02/M02/9A/C1/wKiom1laEyjgUos4AAKStUwNVY4841.jpg-wh_500x0-wm_3-wmp_4-s_3106292890.jpg" target="_blank"></a>

5.3 設定報警動作:

打開zabbix的系統配置---操作---- 選擇事件源為觸發器------create action:

<a href="http://img1.51cto.com/attachment/201211/134147651.jpg" target="_blank"></a>

觸發條件設定:

<a href="http://img1.51cto.com/attachment/201211/134222827.jpg" target="_blank"></a>

詳細操作設定,即滿足觸發條件之後執行什麼動作,這裡一般設定為發郵件之類的,設定收郵件的使用者(建議每個組對應一個使用者,這樣發郵件的時候容易設定發送對象):

<a href="http://img1.51cto.com/attachment/201211/134257761.jpg" target="_blank"></a>

至此,郵件報警已經設定完成。

附 1:Zabbix監控伺服器一般配置步驟:

1)自定義監控模闆

2)以自動發現(或者自動注冊)的方式增加監控裝置

3)根據需求自定義監控項和觸發器

4)設定報警方式(如郵件或短信)

5)Zabbix伺服器的優化

附 2 :解決郵件報警發送附件的辦法:

報警腳本如下:

#export.UTF-8

FILE=/tmp/mailtmp.txt

echo "$3" &gt;$FILE

dos2unix -k $FILE

/bin/mail -s "$2" $1 &lt; $FILE

[root@localhost alertscripts]# touch /tmp/mailtmp.txt

[root@localhost alertscripts]# chown zabbix.zabbix /tmp/mailtmp.txt

本文轉自 zengwj1949 51CTO部落格,原文連結:http://blog.51cto.com/zengwj1949/1944155

繼續閱讀