zabbix自定義監控程序
阿新 • • 發佈:2018-12-16
在客戶端寫指令碼:
[[email protected] ~]# mkdir /scripts [[email protected] ~]# vim /scripts/getprocess.sh #!/bin/bash stat=$(ps -ef|grep -Ev "grep|$0"|grep "\b$1\b"|wc -l) if [ $stat -ne 0 ];then echo '1' else echo '0' fi [[email protected] ~]# chown -R zabbix.zabbix /scripts/getprocess.sh [[email protected]
~]# chown -R zabbix.zabbix /scripts/ [[email protected] ~]# chmod +x /scripts/getprocess.sh //檢測 [[email protected] ~]# systemctl start vsftpd [[email protected] ~]# /scripts/getprocess.sh vsftpd 1 [[email protected] ~]# systemctl stop vsftpd [[email protected] ~]# /scripts/getprocess.sh vsftpd 0
修改/usr/local/etc/zabbix_agentd.conf配置檔案
UnsafeUserParameters=1
UserParameter=ckftp,/bin/bash /scripts/getprocess.sh vsftpd
重啟服務
[[email protected] ~]# pkill zabbix
[[email protected] ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 80 :::3306 :::*
[ [email protected] ~]# zabbix_agentd
服務端檢測
[[email protected] ~]# zabbix_get -s 192.168.102.129 -k ckftp
0 //客戶端vsftpd停止
[[email protected] ~]# zabbix_get -s 192.168.102.129 -k ckftp
1
//客戶端vsftpd啟動
新增監控項、觸發器、動作
上面表示式需要新增的:
將客戶端vsftpd停掉、檢測是否成功
[[email protected] ~]# systemctl stop vsftpd