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!
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!

Comment