1、自定义key的语法
在/etc/zabbix/zabbix_agentd.conf中配置参数,写法如下:UserParameter=key,command 或 UserParameter=key[*],command $1 $2 $3
2、特殊字符的处理
如果UserParameter包含\ ' ” ` * ? [ ] { } ~ $ ! & ; ( ) < > | # @这些字符,需要在zabbix_agentd.conf开启UnsafeUserParameters=1shell# vim /etc/zabbix/zabbix_agentd.conf
UnsafeUserParameters=1
3、子配置文件的注意事项
为了方便维护和分类管理,UserParameter的内容可以单独写一个配置文件。shell# vim /etc/zabbix/zabbix_agentd.conf
Include=/etc/zabbix/zabbix_agentd.conf.d/
注意在/etc/zabbix/zabbix_agentd.conf.d文件夹下所有的配置文件都会被当作子配置文件,如果有重复的,会导致agent启动失败。
4、自定义key的步骤总结
(1)agent配置文件修改
shell# vim /etc/zabbix/zabbix_agentd.confUnsafeUserParameters=1 #处理特殊字符
Include=/etc/zabbix/zabbix_agentd.conf.d/ #子配置文件路径
(2)子配置文件
shell# vim /etc/zabbix/zabbix_agentd.conf.d/get_os_type.confUserParameter=get.os.type,head -1 /etc/issue
(3)重启服务测试key
shell# service zabbix/zabbix-agent restart #重启服务shell# zabbix_get -s 127.0.0.1 -k get.os.type #测试key获取参数
CentOS release 6.4(Final)
(4)用zabbix_agentd查看key是否支持
shell# zabbix_agentd -p|grep get\.osget.oa.type [t|CentOS release 6.5 (Final)]