-
Incident report
-
Resolution: Fixed
-
Blocker
-
None
-
1.9.0 (alpha)
-
None
-
CLI Tool rev 45
As noted in bug #1053 arrays are not returned properly from php code, they are returned as associative arrays, otherwise known as a hash. This is a critical issue because other languages handle hashes and arrays differently. This is especially critical since the JSON library in Ruby is properly interpreting the "arrays" returned from the API as a hash. Hashes do not necessarily store values in the order in which they are added, so hash.each does not return data in the order it was received, also hash[position] does not work.
Here are two examples.
Sending: {"jsonrpc": "2.0", "method":"item.get", "params":
, "auth":"e955a45283c02df4f6a88fa0ff78a172", "id":11}
Response: {"jsonrpc":"2.0","result":
,"id":11}
I would expect to have a result set of : ["10001","10002","10003", ... , "10010"]
Sending: {"jsonrpc": "2.0", "method":"item.get", "params":
{"limit":1, "extendoutput":true}, "auth":"e955a45283c02df4f6a88fa0ff78a172", "id":10}
Response: {"jsonrpc":"2.0","result":{"10001":{"hostids":
,"itemid":"10001","type":"0","snmp_community":"","snmp_oid":"","snmp_port":"161","hostid":"10001","description":"Free memory","key_":"vm.memory.size[free]","delay":"30","history":"7","trends":"365","nextcheck":"0","lastvalue":null,"lastclock":null,"prevvalue":null,"status":"0","value_type":"3","trapper_hosts":"","units":"B", "multiplier":"0","delta":"0","prevorgvalue":null,"snmpv3_securityname":"","snmpv3_securitylevel":"0","snmpv3_authpassphrase":"","snmpv3_privpassphrase":"","formula":"0", "error":"","lastlogsize":"0","logtimefmt":"","templateid":"0","valuemapid":"0","delay_flex":"","params":"","ipmi_sensor":"","data_type":"0"}},"id":10}
The second example is a little harder to spot it, the problem is the hostids field. This should be an array, not a hash with key/value pairs.
If this bug is not going to be fixed then please update the documentation to say that an "associative array" is returned not an "array", that way we can know that we must do additional parsing to have useful data.
Bug marked as critical as hashes break the cli tool.