zabbix監控平臺設置報警發送郵件

前言

一:配置郵件報警功能

1.1:server端配置

郵件協議:SMTP、POP3、IMAP

郵件發送協議:SMTP 25端口用來發送郵件

郵件接收協議:POP3 110接口,用來接收郵件

IMAP也是郵件接收協議,143端口

pop3與IMAP區別:

pop3在客戶端刪除郵件不會刪除服務端的郵件

IMAP會同時刪除客戶端和服務端的郵件

  • 1、安裝

    [root@server ~]# yum -y install mailx
    [root@server ~]# vim /etc/mail.rc 
        '//文件末尾新增'
    set [email protected]
    set smtp=smtp.qq.com
    set [email protected]
    set smtp-auth-password=mwyspkdnhdbobbef	'//qq郵箱授權碼'
    set smtp-auth=login
    [root@server ~]# echo "hello world" | mail -s "zb-test" [email protected]	'//測試郵件是否發送正常,下圖爲正常'
    
    
  • mark

  • 2、編寫發郵件腳本,zabbix可以調用腳本

    [root@server alertscripts]# vim mailx.sh
    #!/bin/bash
    #send mail
    
    messages=`echo $3 | tr '\r\n' '\n'`
    subject=`echo $2 | tr '\r\n' '\n'`
    echo "${messages}" | mail -s "${subject}" $1 >>/tmp/mailx.log 2>&1
    [root@server alertscripts]# touch /tmp/mailx.log 	'//創建輸出日誌'
    [root@server alertscripts]# chown -R zabbix.zabbix  /tmp/mailx.log 
    [root@server alertscripts]# chmod +x /usr/lib/zabbix/alertscripts/mailx.sh
    [root@server alertscripts]# chown -R zabbix.zabbix /usr/lib/zabbix/
    [root@server alertscripts]# ./mailx.sh [email protected] test test	'//測試腳本是否正常'
    
    

    成功收到

    mark

1.2:web界面配置監控

  • 1、管理–報警媒體類型–創建媒體類型

    mark

    mark

  • 2、管理-用戶-點擊Admin-報警媒介

    mark

    mark

  • 3、配置-》動作-》創建動作-》刪除默認標籤,修改觸發條件

    mark

  • 4、操作-》如下配置

    mark

    mark

  • 5、恢復操作

    mark

    mark

    最後點擊添加

    mark

  • 6、重啓zabbix服務

    [root@server alertscripts]# systemctl restart zabbix-server
    [root@server alertscripts]# systemctl restart zabbix-agent.service
    
    

1.3:測試報警

  • 1、配置–主機–client01–模板–選擇監控的服務–添加–更新

    mark

  • 2、client端關閉sshd服務

    [root@client ~]# systemctl stop sshd
    
    

    mark

  • 3、client端開啓sshd服務

    [root@client ~]# systemctl start sshd
    

    mark

如有疑問可評論區交流!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章