zabbix自定义监控配置
自定义监控配置
配置监控脚本
//为agentd配置文件添加自定义配置
[root@zabbix ~]# tail -2 /usr/local/etc/zabbix_agentd.conf
UnsafeUserParameters=1
UserParameter=check_process[*],/bin/bash /scripts/check_process.sh $1
[root@zabbix ~]# pkill zabbix
[root@zabbix ~]# zabbix_agentd //修改后重启zabbix
[root@zabbix ~]# mkdir -p /scripts/
[root@zabbix scripts]# vim check_process.sh
[root@zabbix scripts]# cat check_process.sh
#!/bin/bash
count=`ps -ef|grep $1 |grep -Ev "grep|$0" |wc -l`
if [$count -eq 0 ];then
echo "1"
else
echo "0"
fi
[root@zabbix ~]# chmod +x /scripts/check_process.sh
[root@zabbix ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 100 127.0.0.1:25 0.0.0.0:*
LISTEN 0 128 0.0.0.0:10050 0.0.0.0:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 100 [::1]:25 [::]:*
在zabbix服务测试 因为zabbix_agentd没有开启httpd所以报1
[root@node1 ~]# zabbix_get -s 192.168.124.128 -k check_process[httpd]
1
开启httpd
[root@zabbix ~]# service httpd start
Redirecting to /bin/systemctl start httpd.service
[root@zabbix ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 100 127.0.0.1:25 0.0.0.0:*
LISTEN 0 128 0.0.0.0:10050 0.0.0.0:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 100 [::1]:25 [::]:*
将httpd关闭手动触发告警
[root@zabbix ~]# service httpd stop
Redirecting to /bin/systemctl stop httpd.service
告警
发送邮箱
邮件已接收
自定义监控日志
[root@zabbix ~]# dnf -y install python36 //安装python
[root@zabbix scripts]# vim log.py
[root@zabbix scripts]# chmod +x log.py //给他添加可执行权限
[root@zabbix ~]# tail -1 /usr/local/etc/zabbix_agentd.conf
UserParameter=check_logs[*],/scripts/log.py $1 $2 $3
[root@zabbix ~]# pkill zabbix
[root@zabbix ~]# zabbix_agentd 重启zabbix
[root@zabbix ~]# ll -d /var/log/httpd/
drwx------ 2 root root 41 Sep 6 20:44 /var/log/httpd/
[root@zabbix ~]# chmod 755 /var/log/httpd/ //给这个目录执行权限
[root@zabbix ~]# ll /var/log/httpd/
total 4
-rw-r--r-- 1 root root 0 Sep 6 20:44 access_log
-rw-r--r-- 1 root root 3308 Sep 6 21:35 error_log
[root@zabbix ~]# echo "Error" >> /var/log/httpd/error_log //手动告警
[root@node1 ~]# zabbix_get -s 192.168.124.128 -k //去服务端检测是否成功配置 check_logs[/var/log/httpd/error_log]
1
告警已触发,邮件已发送