-
Type:
Incident report
-
Resolution: Fixed
-
Priority:
Major
-
None
-
Affects Version/s: 1.9.0 (alpha)
-
Component/s: API (A)
-
None
-
Environment:Zabbix 1.7 (trunk), revision 8126, CLI revision 19
Linux RHEL5.3 (2.6.18-128.el5 #1 SMP Wed Dec 17 11:41:38 EST 2008 x86_64 x86_64 x86_64 GNU/Linux)
mysql Ver 14.12 Distrib 5.0.45, for redhat-linux-gnu (x86_64) using readline 5.0
Hi.
I'm doing some modification on the zabcon, the Zabbix CLI, to import configuration from XML. I've just failed to add an item through the add_item()/add() functions. I took the liberty to put the priority to Major, as this is a showstopper for my work to import config through the CLI/JSon interface. I'm sorry if it's just a matter of getting the API call wrong.
I'm calling the function add() in api/classes/class.citem.php (line 713) from the Zabbix CLI, but something goes awry.
add() calls add_item() in include/items.inc.php (line 1637), where the error seem to occur. My current guess is that there is an error in the parameters passed to add_item() that are incorrect.
add() expects an array of arrays (my interpretationis that it's an array of hashes in Ruby) that it splits up before calling add_item():
$result = true;
foreach($items as $item)
The structure for $item in add() is:
$item_db_fields = array(
'description' => null,
'key_' => null,
'hostid' => null,
'delay' => 60,
'history' => 7,
'status' => ITEM_STATUS_ACTIVE,
'type' => ITEM_TYPE_ZABBIX,
'snmp_community' => '',
'snmp_oid' => '',
'value_type' => ITEM_VALUE_TYPE_STR,
'data_type' => ITEM_DATA_TYPE_DECIMAL,
'trapper_hosts' => 'localhost',
'snmp_port' => 161,
'units' => '',
'multiplier' => 0,
'delta' => 0,
'snmpv3_securityname' => '',
'snmpv3_securitylevel' => 0,
'snmpv3_authpassphrase' => '',
'snmpv3_privpassphrase' => '',
'formula' => 0,
'trends' => 365,
'logtimefmt' => '',
'valuemapid' => 0,
'delay_flex' => '',
'params' => '',
'ipmi_sensor' => '',
'applications' => array(),
'templateid' => 0);
The input ($item) is compared to $item_db_fields, so it's practically what it expects.
I'm calling add_item() with an array with one hash for each item. I've also copied and pasted the default structure ($item_db_fields) into my Ruby code to make sure I create the array of hashes exactly as the add()/add_item() function expects. I'm aware that the PHP definition says it wants an array of an array, but I have to assume that array and hash is the same thing in PHP, as the array is defined as keyword/value pairs.
Another problem is that I don't get any reasonable error codes:
An error was received from the Zabbix server Error code: -32500 Error message: Application error.
Error data: Internal zabbix error
This is because the error is set to this every time (api/classes/class.citem.php, line 713):
self::$error[] = array('error' => ZBX_API_ERROR_INTERNAL, 'data' => 'Internal zabbix error');
There are loads of good error messages in add_item() in include/items.inc.php, but I don't know how to get to them (only true/false is returned and I don't know how the function error() works).
The debug output from Ruby clearly shows that I'm passing an array of hashes that conforms to the structure in $item (as far as I can see at elast):
+> import import4.xml
[
] An error was received from the Zabbix server Error code: -32500 Error message: Application error.
Error data: Internal zabbix error
The above example only has one item in the array, though.
Any ideas if I'm calling add() with incorrect parameters or if there is a bug in add_item()?
While I have your attention: is there any API documentation?
Regards,
Dan