Ad Widget

Collapse

Problem tu use zabbix api

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • angelhc
    Senior Member
    Zabbix Certified Specialist
    • Nov 2009
    • 226

    #1

    Problem tu use zabbix api

    Hello all,
    I just develop a new scrip to add items to a defined host.
    The script is a copy/paste from
    https://github.com/gescheit/scripts/tree/master/zabbix/ and I call it add_item_api.py:
    from zabbix_api import ZabbixAPI

    server="127.0.0.1"
    username="api"
    password="apipass"

    zapi = ZabbixAPI(server=server, path="/zabbix/", log_level=3)
    zapi.login(username, password)

    host_name="test"
    description='Pruebas de api $1 en %'
    key='vfs.fs.size[/,pused]'

    hostid=zapi.host.get({"filter":{"host":host_name}} )[0]["hostid"]
    print hostid
    zapi.item.create({ 'hostid' : (hostid),'description' : (description),'key_' : key })

    But when I execute it the json show this_

    [root@zabpro01 api]# python add_item_api.py
    30: Set 'path':'/zabbix/'
    30: Set 'path':'/zabbix/'
    30: Set 'path':'/zabbix/'
    30: Set 'path':'/zabbix/'
    30: Set 'path':'/zabbix/'
    30: Set 'path':'/zabbix/'
    30: Set 'path':'/zabbix/'
    30: Set 'path':'/zabbix/'
    30: Set 'path':'/zabbix/'
    30: Set 'path':'/zabbix/'
    30: Set 'path':'/zabbix/'
    30: Set 'path':'/zabbix/'
    30: Set 'path':'/zabbix/'
    30: Set 'path':'/zabbix/'
    30: Set 'path':'/zabbix/'
    30: Set 'path':'/zabbix/'
    30: Set 'path':'/zabbix/'
    30: Set 'path':'/zabbix/'
    30: Set 'path':'/zabbix/'
    30: Set 'path':'/zabbix/'
    30: Set 'path':'/zabbix/'
    30: Set 'path':'/zabbix/'
    20: url: 127.0.0.1/api_jsonrpc.php
    10: Trying to login with 'api':'md5(146079b602960d62e6df7c96b4502b32)'
    10: json_obj: {'params': {'password': 'apipass', 'user': 'api'}, 'jsonrpc': '2.0', 'method': 'user.authenticate', 'auth': '', 'id': 0}
    Traceback (most recent call last):
    File "add_item_api.py", line 16, in ?
    zapi.login(username, password)
    File "/home/zabbix/api/zabbix_api.py", line 185, in login
    obj = self.json_obj('user.authenticate', { 'user' : l_user,
    File "/home/zabbix/api/zabbix_api.py", line 165, in json_obj
    return json.dumps(obj)
    AttributeError: 'module' object has no attribute 'dumps'
    [root@zabpro01 api]#
    The user api with apipass is created into API access group
    What am I do incorrectly?
    Thanks all!
    Number of hosts 1600,Number of items +90k,Number of triggers +22k, Number of users +100, New values per second +1270

    http://zabbixes.wordpress.com/
  • angelhc
    Senior Member
    Zabbix Certified Specialist
    • Nov 2009
    • 226

    #2
    Finally the problem was the json call method, the system didn't find the python simplejson.
    It's solved.
    Thanks all.
    Number of hosts 1600,Number of items +90k,Number of triggers +22k, Number of users +100, New values per second +1270

    http://zabbixes.wordpress.com/

    Comment

    Working...