Ad Widget

Collapse

Zabbix 1.8 API & Host check & creation

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mike13
    Member
    • Apr 2010
    • 30

    #1

    Zabbix 1.8 API & Host check & creation

    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,
  • Aly
    ZABBIX developer
    • May 2007
    • 1126

    #2
    In pre1.8.3 it possible like this:
    Code:
    {'method':'host.get', 'params':{'filter': {'host': 'host1'}}, ...}
    Zabbix | ex GUI developer

    Comment

    • mike13
      Member
      • Apr 2010
      • 30

      #3
      Hi Aly,

      First of all, thank you for the answer.

      I 've seen this method in zabbix manuel http://www.zabbix.com/documentation/...jects/host#add

      But, i don't know how to use it in my code. I've tried the following code which generates an error:

      $check_hosts = ZabbixAPI::fetch_array('host','get',array({'method ':'host.get', 'params':{'filter': {'host': 'host1'}}, "groups"=>array(array("groupid"=>6))))
      or die('Unable to get hosts: '.print_r(ZabbixAPI::getLastError(),true));
      echo " hosts exist: ".print_r($check_hosts, true)."\n<br>";

      Could you please give me some practical advice?

      Thanks
      Mike

      Comment

      Working...