select alertid,actionid,eventid,from_unixtime(clock,'%Y%m%d %H:%i:%S'),message from alerts where message like 'hostname%';
| 468566 | 5 | 3256580 | 20140312 09:04:02 | hostname:/apps/svr/zabbix_server/scripts/zabbix_exec_command.py ip 23500 "Agent ping" hostname agent.ping Up (1) PROBLEM |
| 468567 | 5 | 3256580 | 20140312 09:06:03 | hostname:/apps/svr/zabbix_server/scripts/zabbix_exec_command.py ip 23500 "Agent ping" hostname agent.ping Up (1) PROBLEM手动执行脚本,报错:
/apps/svr/zabbix_server/scripts/zabbix_exec_command.py ip 27731 "Agent ping" hostname agent.ping Up (1) PROBLEM
-bash: syntax error near unexpected token `('脚本输入参数的顺序:ip,itemid,itemname,hostname,itemkey,itemvalue,triggerstatus,出问题的时itemvalue字段,因为没有用引号,导致脚本运行出错,fix下脚本就可以了。。。
不过,rc还没有找到,这个Up (1) 是怎么来的呢?一般情况下数字型的item产生的itemvalue不会有这种值啊?
为了验证这个问题,手动stop掉一台机器zabbix_agentd进程,并查看zabbix server端的log:
发现在存储agent.ping类的item的值时,有如下操作,把1变成了UP(1)。
5009:20140312:113302.211 In zbx_format_value()
5009:20140312:113302.211 In replace_value_by_map() value:'1' valuemapid:10
5009:20140312:113302.211 query [txnlev:1] [select newvalue from mappings where valuemapid=10 and value='1']
5009:20140312:113302.211 End of replace_value_by_map() value:'Up (1)'说明还是和item的设置有关,再来看agent.ping的设置,在show value设置中,可以看到并不是as is,而是设置的zabbix agent ping status,这里面就是1->up的map:
再来看zabbix的doc中关于map value的描述,其实是为了返回更易理解的值:
For a more “human” representation of received values, you can use value maps that contain the mapping between numeric values and string representations.
rc找到了,把show value改成as is就ok了。
小结:
1.日志+数据库是解决zabbix问题的利器。
2.有时候需要设置多种报警方式,比如在这个例子中,由于有zabbix host update percent的报警,发现了这个问题。