Zabbix教程2-创建自定义监控项实现邮箱报警
2021-12-09 本文已影响0人
二郎5
1.自定义监控项
Zabbix虽然自带了许多Key,能满足大多数的监控需求。但是真正在生产上还是有很多不足的,比如想监控Nginx连接数、MySQL的状态信息都没有Key能实现,所以Zabbix还提供了一种自定义Key来实现这种需求。这就是Zabbix的UserParameter功能。UserParameter功能需要在zabbix-agent客户端的配置文件中配置。
监控系统的登录状态,如果登录的xshell超过两个用户则触发报警, 在zabbix-agent端自定义监控项,使用UserParameter。
$ vim /etc/zabbix/zabbix_agentd.conf
# 添加以下内容
UserParameter=login.number,uptime | awk '{print $4}'
格式:
UserParameter = <键>,<命令>
重启zabbix-agent
$ systemctl restart zabbix-agent
检查zabbix-agent端上自定义监控项是否生效
$ zabbix_agentd -p # 获取zabbix-agent端所有的监控项内容
$ zabbix_agentd -p | grep login.number
login.number [t|1]
在zabbix-server端测试是否可以获取到zabbix-agent端上的自定义监控项的值
$ yum -y install zabbix-get.x86_64 # 安装zabbix-get软件包
$ zabbix_get -s 192.168.223.131 -k login.number
1
参数含义:
-s --host host-name-or-IP Specify host name or IP address of a host \\指定监控客户端IP
-k --key item-key Specify key of the item to retrieve value for \\指定要获取值的key
web页面添加监控项




自定义触发器



配置好触发器之后我们可以使用xshell连接zabbix-agent服务器,然后多复制几个终端,查看是否触发了触发器。


3.配置动作


下图中需要注意的是"密码"选项配置的不是qq邮箱的密码,而是授权码。
授权码该如何设置,请参考链接:
https://service.mail.qq.com/cgi-bin/help?subtype=1&id=28&no=1001256



