Ad Widget

Collapse

Problem API host.create

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Neringan
    Junior Member
    • Dec 2014
    • 1

    #1

    Problem API host.create

    Hi everyone,

    I got a problem using the api to add a host entry.

    I am using the pyZabbix api for python.
    My problem is the host seems to be created but he is not.
    I receive the JSON response with a return code 200 (OK) and the hostid of the (normally) created host. But it doesn't appear in the zabbix frontend. If i try to execute my python script several times it always return the same hostid (normal, because he can't create it he doesn't increment it).

    Here is the Json sent :

    Code:
    Sending: {
        "params": {
            "interfaces": [
                {
                    "ip": "x.x.x.x",
                    "useip": 0,
                    "dns": "srv.my.domain",
                    "main": 1,
                    "type": 1,
                    "port": "10050"
                }
            ],
            "host": "srv.my.domain",
            "name": "srv",
            "groups": [
                {
                    "groupid": "9"
                }
            ],
            "inventory": [
                {
                    "inventory_mode": 1
                }
            ]
        },
        "jsonrpc": "2.0",
        "method": "host.create",
        "auth": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
        "id": 2
    }
    and the json received :

    Code:
    Response Code: 200
    Response Body: {
        "jsonrpc": "2.0",
        "result": {
            "hostids": [
                "10255"
            ]
        },
        "id": 2
    }

    Did someone encounter a similar problem ?

    Thank you for you help.
    Last edited by Neringan; 09-12-2014, 18:02.
  • swann
    Junior Member
    • Jan 2015
    • 2

    #2
    Problem API host.create

    Hi,

    I encounter the exactly same issue! I Cannot figured out why.

    I remark if I don't use 'inventory' attributes it works as expected... but I need this attribut!

    I use zabbix 2.2.8, mysql 5.6, php 5.3.3, nginx on Centos 6.6

    Comment

    • swann
      Junior Member
      • Jan 2015
      • 2

      #3
      I figured out the issue

      This is due the fact fields (text type) of the table host_inventory have default value null but must be null.
      I guess this is due the mysql version which changed it's default behavior.

      This results a rollback totaly ignored by zabbix, see below SQL traces.

      A dirty workaround is to add these inventory fields each time you create host:

      inventory: { ... add your inventory ...
      'poc_2_notes': '','poc_1_notes':'',
      'site_notes': '', 'host_networks': '',
      'notes': '', 'location': '',
      'contact':'', 'software_full':'', 'hardware_full':'' }



      SQL Trace:
      BEGIN
      SELECT g.* FROM groups g WHERE g.groupid='17'
      SELECT h.hostid,h.host,h.name FROM hosts h WHERE h.flags IN (0,4) AND h.status IN (0,1) AND (h.host='test7' OR h.name='test7')
      SELECT h.hostid,h.host,h.name FROM hosts h WHERE h.status=3 AND (h.host='test7' OR h.name='test7')
      SELECT nextid FROM ids WHERE nodeid=0 AND table_name='hosts' AND field_name='hostid' FOR UPDATE
      UPDATE ids SET nextid=nextid+1 WHERE nodeid=0 AND table_name='hosts' AND field_name='hostid'
      INSERT INTO hosts (proxy_hostid,host,name,hostid) VALUES ('10137','test7','test7','10144')
      SELECT nextid FROM ids WHERE nodeid=0 AND table_name='hosts_groups' AND field_name='hostgroupid' FOR UPDATE
      UPDATE ids SET nextid=nextid+1 WHERE nodeid=0 AND table_name='hosts_groups' AND field_name='hostgroupid'
      INSERT INTO hosts_groups (hostid,groupid,hostgroupid) VALUES ('10144','17','186')
      SELECT COUNT(DISTINCT h.hostid) AS rowscount FROM hosts h WHERE h.flags IN (0,4) AND h.hostid='10144' AND h.status IN (0,1,3)
      SELECT h.hostid,h.host FROM hosts h WHERE h.flags IN (0,4) AND h.hostid='10144' AND h.status IN (0,1)
      SELECT h.hostid,h.host FROM hosts h WHERE h.status IN (5,6) AND h.hostid='10144'
      SELECT h.hostid,h.host FROM hosts h WHERE h.flags IN (0,4) AND h.hostid='10144' AND h.status IN (0,1) AND h.flags='4' LIMIT 1 OFFSET 0
      SELECT hi.interfaceid,hi.hostid,hi.main,hi.type FROM interface hi WHERE hi.hostid='10144'
      SELECT nextid FROM ids WHERE nodeid=0 AND table_name='interface' AND field_name='interfaceid' FOR UPDATE
      UPDATE ids SET nextid=nextid+1 WHERE nodeid=0 AND table_name='interface' AND field_name='interfaceid'
      INSERT INTO interface (ip,useip,dns,main,type,port,hostid,interfaceid) VALUES ('192.168.0.9','1','','1','1','10050','10144','12' )
      INSERT INTO host_inventory (hostid, tag, inventory_mode) VALUES (10144, '12345678901234567890123456789009', 0)
      ROLLBACK

      Comment

      Working...