1、自定义进程监控
1.1 编写脚本
在客户端除root家目录外创建一个脚本问题,每个自定义脚本都放到这个目录中
[root@localhostetc]
[root@localhost scripts]
count=$(ps -ef | grep -Ev "grep|$0" | grep -c "$1")
if [ $count -eq 0 ];then
echo '1'
else
echo '0'
fi
1.2 修改配置文件
[root@localhost etc]
/usr/local/etc
[root@localhost etc]
...
UnsafeUserParameters=1
...
UserParameter=check_process[*],/scripts/check_process.sh $1
//“check_process[*]”是在web界面中要写的key *表示某个服务,$1的参数来自于check_process[*]
也就是说check_process[*]中*是什么服务,$1就会传什么服务名
例如httpd:
web界面中的key是 check_process[httpd] 说明是监控httpd服务是否开启
1.3 重启
关闭zabbix服务,然后开启
[root@localhost ~]
[root@localhost ~]
1.4 在web界面配置监控项和触发器
     关闭httpd服务就会报错
[root@localhost scripts]
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 0.0.0.0:10050 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 [::]:22 [::]:*
[root@localhost scripts]

2、自定义日志监控
2.1 编写脚本
[root@localhost scripts]
总用量 8
-rwxr-xr-x. 1 root root 124 10月 8 22:28 check_process.sh
-rwxr-xr-x. 1 root root 1854 10月 8 23:05 log.py
[root@localhost scripts]
/scripts
2.2 修改配置文件
[root@localhost etc]
//最后一行添加
UserParameter=check_log[*],/scripts/log.py $1 $2 $3
//修改文件权限便于key访问
[root@localhost tmp]
//在控制主机测试
[root@zabbix ~]
0
2.3 重启
[root@localhost tmp]
[root@localhost tmp]
2.4 web界面配置监控项和触发
创建监控项和触发器
  添加完触发器后验证一下,往/var/log/httpd/error.log文件中添加Error
[root@localhost httpd]
30s后就会触发错误并且发送邮箱  

|