zabbix对一个服务进行监控,例如crond,zabbix本身没有此模板,需要手动书写脚本
场景介绍:
192.168.10.10: zabbix server
192.168.10.11: zabbix client
2:脚本内容如下:
[root@zabbiclient1 scripts]# pwd
/etc/zabbix/scripts
[root@zabbiclient1 scripts]# cat check_process_running
#!/bin/sh
###################################################
#
# check process runing status
#
###################################################
procjetName="${1:-NULL}"
LOCK_PATH="/var/lock/subsys"
RUN_PATH="/var/run"
ret_ok=1
ret_warn=2
ret_critical=3
ret_unknown=4
if [[ ${procjetName} == "NULL" ]] ; then
echo ${ret_unknown}
fi
if [ -f "${LOCK_PATH}/${procjetName}" ] || [ -f "${RUN_PATH}/${procjetName}.pid" ] ; then
echo ${ret_ok}
else
echo ${ret_critical}
fi
[root@zabbiclient1 zabbix_agentd.conf.d]# pwd
/etc/zabbix/zabbix_agentd.d
[root@zabbiclient1 zabbix_agentd.conf.d]# ll check_process.conf
-rw-r--r-- 1 root root 533 Dec 26 2013 check_process.conf
[root@zabbiclient1 zabbix_agentd.d]# cat check_process.conf
UserParameter=check.crontab,/etc/zabbix/scripts/check_process_running crond ##注意check.crontab必须和下面创建item时的key相对应
在zabbix client机器上include 相关文件,
[root@zabbiclient1 etc]# ls
zabbix_agent.conf zabbix_agent.conf.d zabbix_agentd.conf zabbix_agentd.conf.d
[root@zabbiclient1 etc]# cat zabbix_agentd.conf | grep -v "#" | grep -v "^$"
PidFile=/var/run/zabbix/zabbix_agentd.pid
LogFile=/var/log/zabbix/zabbix_agentd.log
LogFileSize=0
Server=10.15.0.8
ServerActive=127.0.0.1
Hostname=prod-public-ecs-aliyun
Include=/etc/zabbix/zabbix_agentd.d/ ###Include该文件!
3: 下面关键的重点是通过zabbix_get 获取check.crontab key的值,这个值在创建trigger时时需要,否则
trigger表达式填写不正确,就无法触发trigger
下面就创建一个模板,我创建的模板名为apptemplate,在模板里面创建一个item,crond is running,update interval 我设置为5s,见附件
然后创建一个trigger,trigger名为:crond does not work, 表达式值为{apptemplate:check.crontab.last(0)}=3
Severity 选择disaster,点save按钮即可创建。见附件
4:然后就可以在134机器上手动执行service crond stop,看看是否触发trigger