1. 程式人生 > 實用技巧 >Zabbix安裝配置釘釘告警

Zabbix安裝配置釘釘告警

一、 更改主機名
[[email protected] ~]# hostnamectl set-hostname zabbix.bystp.com
二、 關閉防護牆及SELINUX
[[email protected] ~]# systemctl stop firewalld
[[email protected] ~]# systemctl disable firewalld
[[email protected] ~]# setenforce 0
編輯/etc/selinux/config檔案關閉SELINUX
三、 配置阿里源及軟體源
wget -O /etc/yum.repos.d/CentOS-Base.repo

http://mirrors.aliyun.com/repo/Centos-7.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
建立zabbix源repo檔案
四、 安裝zabbix,mariadb
[[email protected] ~]# yum install zabbix-server-mysql zabbix-get
[[email protected] ~]# yum install mariadb-server mariadb
四、 開啟mariadb服務
[[email protected]
~]# systemctl start mariadb-server
[[email protected] ~]mysql_secure_installation
五、 建立資料庫
create database zabbix charset 'utf8';
grant all on zabbix. to [email protected] identified by '123456';
flush privileges;
六、 匯入資料庫
[[email protected] ~]# rpm -ql zabbix-server-mysql
/etc/logrotate.d/zabbix-server
/etc/zabbix/zabbix_server.conf
/usr/lib/systemd/system/zabbix-server.service
/usr/lib/tmpfiles.d/zabbix-server.conf
/usr/lib/zabbix/alertscripts
/usr/lib/zabbix/externalscripts
/usr/sbin/zabbix_server_mysql
/usr/share/doc/zabbix-server-mysql-4.2.1
/usr/share/doc/zabbix-server-mysql-4.2.1/AUTHORS
/usr/share/doc/zabbix-server-mysql-4.2.1/COPYING
/usr/share/doc/zabbix-server-mysql-4.2.1/ChangeLog
/usr/share/doc/zabbix-server-mysql-4.2.1/NEWS
/usr/share/doc/zabbix-server-mysql-4.2.1/README
/usr/share/doc/zabbix-server-mysql-4.2.1/create.sql.gz
/usr/share/man/man8/zabbix_server.8.gz
/var/log/zabbix
/var/run/zabbix
[[email protected] ~]# cp /usr/share/doc/zabbix-server-mysql-4.2.1/create.sql.gz create.sql.gz
[[email protected] ~]# gunzip create.sql.gz
[[email protected] ~]ls
anaconda-ks.cfg create.sql
[[email protected] ~] mysql -uroot -p zabbix < create.sql
[[email protected] ~]
七、 配置/etc/zabbix/zabbix_server.conf
ListenPort=10051
SourceIP=192.168.0.5
LogType=file
LogFile=/var/log/zabbix/zabbix_server.log
LogFileSize=0
DebugLevel=3
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=123456
DBSocket=/var/lib/mysql/mysql.sock
DBPort=3306
八、開啟服務
[[email protected] ~] systemctl start zabbix-server
九、安裝Zabbix web
[[email protected] ~] yum install httpd php php-mysql php-mbstring php-gd php-bcmath php-ldap php-xml
[[email protected] ~] yum install zabbix-web zabbix-web-mysql
十、 配置/etc/httpd/conf.d/zabbix.conf
[[email protected] ~]# vi /etc/httpd/conf.d/zabbix.conf
Zabbix安裝配置釘釘告警
十一、啟動httpd
[[email protected] ~]# systemctl start httpd
十二、訪問http://192.168.0.5配置zabbix
十三、安裝python庫
[[email protected] alertscripts]# yum install epel-release
[[email protected] alertscripts]# yum install python-pip
[[email protected] alertscripts]# pip install requests
十四、配置python指令碼
[[email protected] ~]# cd /usr/lib/zabbix/alertscripts/
[[email protected] alertscripts]# vi dingding.py
#!/usr/bin/env python
#coding:utf-8
#zabbix釘釘報警
import requests,json,sys,os,datetime
webhook="https://oapi.dingtalk.com/robot/send?access_token=e9f690a7e200ef362e4015b9c2f5a64849bfadc71d947d150e5be0b7d89d299b"
user=sys.argv[1]
text=sys.argv[3]
data={
"msgtype": "text",
"text": {
"content": text
},
"at": {
"atMobiles": [
user
],
"isAtAll": False
}
}
headers = {'Content-Type': 'application/json'}
x=requests.post(url=webhook,data=json.dumps(data),headers=headers)
if os.path.exists("/tmp/zabbix_dingding.log"):
f=open("/tmp/zabbix_dingding.log","a+")
else:
f=open("/tmp/zabbix_dingding.log","w+")
f.write("\n"+"--"*30)
if x.json()["errcode"] == 0:
f.write("\n"+str(datetime.datetime.now())+" "+str(user)+" "+"傳送成功"+"\n"+str(text))
f.close()
else:
f.write("\n"+str(datetime.datetime.now()) + " " + str(user) + " " + "傳送失敗" + "\n" + str(text))
f.close()
Zabbix安裝配置釘釘告警
[[email protected] alertscripts]# chmod +x dingding.py
十五、測試python指令碼
[[email protected] alertscripts]# ./dingding.py asd 32d TEST
[[email protected] alertscripts]
Zabbix安裝配置釘釘告警
十六、配置python指令碼許可權
[[email protected] alertscripts]# chown zabbix.zabbix /usr/lib/zabbix/alertscripts/dingding.py
[[email protected] alertscripts]# chmod +x /tmp/zabbix_dingding.log
[[email protected] alertscripts]# chown zabbix.zabbix /tmp/zabbix_dingding.log
十七、配置報警媒介型別
Zabbix安裝配置釘釘告警
十八、配置使用者報警媒介,收件人為手機號
Zabbix安裝配置釘釘告警
十九、配置動作
Zabbix安裝配置釘釘告警
Zabbix安裝配置釘釘告警
Zabbix安裝配置釘釘告警
Zabbix安裝配置釘釘告警
操作:伺服器:{HOST.NAME}發生: {TRIGGER.NAME}故障!
訊息內容:
{
報警主機:{HOST.NAME}
主機地址:{HOST.IP}
監控專案:{ITEM.NAME}
監控取值:{ITEM.LASTVALUE}
報警等級:{TRIGGER.SEVERITY}
當前狀態:{TRIGGER.STATUS}
報警資訊:{TRIGGER.NAME}
報警時間:{EVENT.DATE} {EVENT.TIME}
事件ID:{EVENT.ID}
}

恢復操作
預設標題:伺服器:{HOST.NAME}: {TRIGGER.NAME}已恢復!
訊息內容:
{
報警主機:{HOST.NAME}
主機地址:{HOST.IP}
監控專案:{ITEM.NAME}
監控取值:{ITEM.LASTVALUE}
報警等級:{TRIGGER.SEVERITY}
當前狀態:{TRIGGER.STATUS}
報警資訊:{TRIGGER.NAME}
報警時間:{EVENT.DATE} {EVENT.TIME}
恢復時間:{EVENT.RECOVERY.DATE} {EVENT.RECOVERY.TIME}
持續時間:{EVENT.AGE}
事件ID:{EVENT.ID}
}

更新操作
預設標題:伺服器:{HOST.NAME}: {TRIGGER.NAME}已更新!
訊息內容:
更新人:{USER.FULLNAME}
時間:{ACK.DATE} {ACK.TIME}
更新資訊如下:
"{ACK.MESSAGE}"
問題伺服器IP:{HOSTNAME1}
問題ID:{EVENT.ID}
當前的問題是: {TRIGGER.NAME}
}

轉載於:https://blog.51cto.com/wanglei1024/2393048