问题:zabbix添加自动发现端口,提示Value should be a JSON object
[root@localhost zabbix_agentd.d]# zabbix_get -s 192.168.100.223 -k discovery.port (Not all processes could be identified, non-owned process info will not be shown, you would have to be root to see it all.) { "data":[ {"{#TCP_PORT}":"10050"}, {"{#TCP_PORT}":"10051"}, {"{#TCP_PORT}":"111"}, {"{#TCP_PORT}":"20048"}, {"{#TCP_PORT}":"20255"}, {"{#TCP_PORT}":"2049"}, {"{#TCP_PORT}":"2371"}, {"{#TCP_PORT}":"25"}, {"{#TCP_PORT}":"28390"}, {"{#TCP_PORT}":"3306"}, {"{#TCP_PORT}":"41709"}, {"{#TCP_PORT}":"57454"}, {"{#TCP_PORT}":"80"} ] }
因为shell脚本中使用到了netstat命令,权限问题,zabbix-agent是zabbix用户启动的,默认是不能执行netstat等命令,导致从服务器取到的自动发现脚本为空
解决方法: chmod +s /bin/netstat
为了方便普通用户执行一些特殊命令,SUID/SGID程序允许普通用户以root身份暂时执行该程序,并在执行结束之后再回复身份,chmod +s 就是给某个程序或者脚本suid权限