Hi,
I'm trying to use the new Zabbix API to add hosts with Zabbix php-class API. I would like my script to check whether the host exist or not before adding the host.
if the host exists then the script should skip to the next one without sending an error. currently, my script is able to add hosts from a file. However it generates an error when the host exist in zabbix:
<li>Unable to create host: Array
(
[code] => -32602
[message] => Invalid params.
[data] => [ CHost::create ] Host [ host1 ] already exists
)
I've tried to check an existing host with a simple script:
$check_host = ZabbixAPI::fetch_array('host','get',array("host"=> host1, "groups"=>array(array("groupid"=>6))))
or die('Unable to get host: '.print_r(ZabbixAPI::getLastError(),true));
echo " hosts exist: ".print_r($check_host, true)."\n<br>";
But, it outputs all the existing hosts.
Does anyone know how to do this?
Many thanks,
Mike,
I'm trying to use the new Zabbix API to add hosts with Zabbix php-class API. I would like my script to check whether the host exist or not before adding the host.
if the host exists then the script should skip to the next one without sending an error. currently, my script is able to add hosts from a file. However it generates an error when the host exist in zabbix:
<li>Unable to create host: Array
(
[code] => -32602
[message] => Invalid params.
[data] => [ CHost::create ] Host [ host1 ] already exists
)
I've tried to check an existing host with a simple script:
$check_host = ZabbixAPI::fetch_array('host','get',array("host"=> host1, "groups"=>array(array("groupid"=>6))))
or die('Unable to get host: '.print_r(ZabbixAPI::getLastError(),true));
echo " hosts exist: ".print_r($check_host, true)."\n<br>";
But, it outputs all the existing hosts.
Does anyone know how to do this?
Many thanks,
Mike,
Comment