Hi guys,
I've just upgraded from zabbix 1.8 to 2.0 and expectedly, i've got to make some tweaks to my php API scaling scripts.
in particular, I use this code to compare an AWS instance's IP and then update the zabbix host if necessary:
The result coming back is:
For some reason, even thought the interfaceid's are the same, it's trying to create a new interface rather than updating the existing one.
Unfortunately there's no example of updating an interface in the API reference, so, after trying a few different things (including sending all of the fields, not just id and ip) i'm not sure how to proceed.
Any help would be really appreciated.
Thanks,
T
I've just upgraded from zabbix 1.8 to 2.0 and expectedly, i've got to make some tweaks to my php API scaling scripts.
in particular, I use this code to compare an AWS instance's IP and then update the zabbix host if necessary:
Code:
if ( !strcmp($current_instances[$ai]->nameTag,$current_hosts[$zi]['host']) ) {
//AWS host already exists in Zabbix.
if (strcmp($current_instances[$ai]->privateIpAddress,$current_hosts[$zi]['interfaces']["$interfaceID"]['ip'])) {
//IP needs to be updated
$updated_interface = array('interfaceid'=>$current_hosts[$zi]['interfaces']["$interfaceID"]['interfaceid'],'ip'=>$current_instances[$ai]->privateIpAddress->to_string());
print_r($updated_interface);
print_r($current_hosts[$zi]['interfaces']["$interfaceID"]);
echo " -/+ ".$current_hosts[$zi]['host']." IP Update:";
if ($this->update_host($current_hosts[$zi]['hostid'],'interfaces',$updated_interface)) {
echo " SUCCESS\n";
$changes_made=true;
} else {
$errormsg = ZABBIXAPI::getLastError();
echo " ERROR: ".$errormsg['data']."\n";
}
}
$found=true;
$safe_zabbix_hosts[]=$zi;
break;
}
The result coming back is:
Code:
Array
(
[interfaceid] => 36160
[ip] => 10.32.7.186
)
Array
(
[interfaceid] => 36160
[hostid] => 12061
[main] => 1
[type] => 1
[useip] => 1
[ip] => 10.32.7.187
[dns] => **************
[port] => 10050
)
-/+ HOSTNAME IP Update: ERROR: Host cannot have more than one default interface of the same type.
For some reason, even thought the interfaceid's are the same, it's trying to create a new interface rather than updating the existing one.
Unfortunately there's no example of updating an interface in the API reference, so, after trying a few different things (including sending all of the fields, not just id and ip) i'm not sure how to proceed.
Any help would be really appreciated.
Thanks,
T
Comment