Hey Guys,
I've written the following piece of python code to fetch the list of items for a given host. It works for hostAAA and hostBBB, which have ~80 and ~4000 items respectively. But it consistently fails for hostCCC which has about 10000 items. Error is always the same: "urllib2.HTTPError: HTTP Error 500: Internal Server Error"
Any ideas? Workarounds are welcome too as long as I can get the list in python..
I believe I'm using this python port of the API.
I've written the following piece of python code to fetch the list of items for a given host. It works for hostAAA and hostBBB, which have ~80 and ~4000 items respectively. But it consistently fails for hostCCC which has about 10000 items. Error is always the same: "urllib2.HTTPError: HTTP Error 500: Internal Server Error"
Any ideas? Workarounds are welcome too as long as I can get the list in python..
I believe I'm using this python port of the API.
Code:
import sys
import zabbix_api
import logging
import csv
if __name__ != '__main__':
print 'Run from command line. Do not import.'
sys.exit(1)
# Connect...
ZABBIX_USERNAME, ZABBIX_PASSWORD, zabbixServer = 'admin', 'password', 'zabbix.dev.com'
zapi = zabbix_api.ZabbixAPI(server="http://%s/zabbix/" % zabbixServer)
zapi.login(ZABBIX_USERNAME, ZABBIX_PASSWORD)
def getItems(host):
# get the hostId from hostName
hostId = zapi.host.get({"filter": {"host": host}})[0]["hostid"]
return zapi.item.getObjects({'hostid': hostId})
def getItemsForHost(host):
items = getItems(host)
with open(host + '_items.csv', 'wb') as csvFile:
# we're interested only in these fields for our analysis.
fieldNames = ['hostid', 'itemid', 'name', 'type', 'key_', 'templateid', 'status', 'description']
out = csv.DictWriter(csvFile, fieldNames, extrasaction='ignore')
out.writeheader()
for item in items:
out.writerow(item)
getItemsForHost('hostAAA') # around 78 items
getItemsForHost('hostBBB') # around 3800 items
getItemsForHost('hostCCC') # 10000+ items
Code:
Traceback (most recent call last):
File "C:\Workspaces\eclipse-kepler\ZabbixConfig\zabbixClient.py", line 64, in <module>
getItemsForHost('hostCCC')
File "C:\Workspaces\eclipse-kepler\ZabbixConfig\zabbixClient.py", line 52, in getItemsForHost
items = getItems(host)
File "C:\Workspaces\eclipse-kepler\ZabbixConfig\zabbixClient.py", line 34, in getItems
items = zapi.item.getObjects({'hostid': hostId})
File "C:\Workspaces\eclipse-kepler\zabbix_api.py", line 347, in method
return self.universal("%s.%s" % (self.data["prefix"], name), opts[0])
File "C:\Workspaces\eclipse-kepler\zabbix_api.py", line 85, in wrapper
return self.do_request(self.json_obj(method, opts))['result']
File "C:\Workspaces\eclipse-kepler\zabbix_api.py", line 354, in do_request
return self.parent.do_request(req)
File "C:\Workspaces\eclipse-kepler\zabbix_api.py", line 283, in do_request
response = opener.open(request, timeout=self.timeout)
File "C:\ProgFiles\Python275\lib\urllib2.py", line 410, in open
response = meth(req, response)
File "C:\ProgFiles\Python275\lib\urllib2.py", line 523, in http_response
'http', request, response, code, msg, hdrs)
File "C:\ProgFiles\Python275\lib\urllib2.py", line 448, in error
return self._call_chain(*args)
File "C:\ProgFiles\Python275\lib\urllib2.py", line 382, in _call_chain
result = func(*args)
File "C:\ProgFiles\Python275\lib\urllib2.py", line 531, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 500: Internal Server Error
Comment