D
D
de_iiah_teji9_iiace2017-09-11 14:42:21
Python
de_iiah_teji9_iiace, 2017-09-11 14:42:21

How to create a zabbix api host?

I am using pyzabbix, I want to add a new host

z = ZabbixAPI(SERVER)

z.login(user=NAME, password=PASSWORD)

z.host.create({ "jsonrpc": "2.0",
            "method": "host.create",
            "params": {
                "host": "blablalbalba",
                "interfaces": [
                    {
                        "type": 1,
                        "main": 1,
                        "useip": 1,
                        "ip": "myip/zabbix",
                        "dns": "",
                        "port": "10050"
                    }
                ],
                "groups": [
                    {
                        "groupid": "37"
                    }
                ],
                "templates": [
                    {
                        "templateid": "20045"
                    }
                ],
            },
            "auth": null,
            "id": 1})

Here is the result
Traceback (most recent call last):
  File "/home/kolas/PycharmProjects/untitled/test1.py", line 62, in <module>
    "id": 1})
  File "/usr/local/lib/python2.7/dist-packages/pyzabbix/__init__.py", line 157, in fn
    args or kwargs
  File "/usr/local/lib/python2.7/dist-packages/pyzabbix/__init__.py", line 99, in do_request
    separators=(',', ': ')))
  File "/usr/lib/python2.7/json/__init__.py", line 251, in dumps
    sort_keys=sort_keys, **kw).encode(obj)
  File "/usr/lib/python2.7/json/encoder.py", line 209, in encode
    chunks = list(chunks)
  File "/usr/lib/python2.7/json/encoder.py", line 434, in _iterencode
    for chunk in _iterencode_dict(o, _current_indent_level):
  File "/usr/lib/python2.7/json/encoder.py", line 408, in _iterencode_dict
    for chunk in chunks:
  File "/usr/lib/python2.7/json/encoder.py", line 332, in _iterencode_list
    for chunk in chunks:
  File "/usr/lib/python2.7/json/encoder.py", line 408, in _iterencode_dict
    for chunk in chunks:
  File "/usr/lib/python2.7/json/encoder.py", line 442, in _iterencode
    o = _default(o)
  File "/usr/lib/python2.7/json/encoder.py", line 184, in default
    raise TypeError(repr(o) + " is not JSON serializable")
TypeError: <module 'null' from '/usr/local/lib/python2.7/dist-packages/null.pyc'> is not JSON serializable

I can't understand why he didn't like it.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
de_iiah_teji9_iiace, 2017-09-11
@de_iiah_teji9_iiace

found the answer instead of host.create() you need to use do_request

z.do_request(method="host.create",params= {
        "host": "blablalbalba",
        "interfaces": [
            {
                "type": 1,
                "main": 1,
                "useip": 1,
                "ip": "ip",
                "dns": "",
                "port": "10050"
            }
        ],
        "groups": [
            {
                "groupid": "37"
            }
        ],
        "templates": [
            {
                "templateid": "10104"
            }
        ],
    }
)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question