I am wondering if there is a limit with the API that I am hitting or if the Zabbix API handles pagination? I am writing a python script to programmatically create SLA's in Zabbix, and I am running into issues where the IT services are not being created or added.
Here is the function in Python:
SITE = <Enter Location>
NETWORK_TRIGGER_DESC = <Description on Network device trigger>
def create_network_infrastructure(network_devices):
"""This funtion will add the network components to the Network Resource"""
parentid = ZAPI.service.get(filter={"name": SITE + " Network"})[0]['serviceid']
print "Network devices being added: "
for network_device in network_devices:
triggers = ZAPI.trigger.get(filter={'host': network_device['name']})
triggerid = []
for trigger in triggers:
if trigger['description'] == NETWORK_TRIGGER_DESC:
triggerid = trigger['triggerid']
if triggerid:
ZAPI.service.create(
{
"name": network_device['name'][:-16],
"algorithm": 1,
"showsla": 1,
"goodsla": 99.05,
"sortorder": 0,
"parentid": parentid,
"triggerid": triggerid
}
)
print network_device['name']
time.sleep(2)
return True
When I test this line by line in terminal, I get the devices to show up. But when I run this as part of the larger script, nothing happens. One network device I checked had 450 triggers but, returned nothing and did not get added to the parent service when I ran the script. This leads me to believe that the API is not returning all 450 triggers when I make the 'ZAPI.trigger.get()' call. Also, when recieving a large data set like 450 triggers in JSON format, does the API page this for you (ie: it gives you 4 pages of 100 results, and one page of 50, for a total of 5 pages)?
Does this make sense?
Thank you,
Tyler
Here is the function in Python:
SITE = <Enter Location>
NETWORK_TRIGGER_DESC = <Description on Network device trigger>
def create_network_infrastructure(network_devices):
"""This funtion will add the network components to the Network Resource"""
parentid = ZAPI.service.get(filter={"name": SITE + " Network"})[0]['serviceid']
print "Network devices being added: "
for network_device in network_devices:
triggers = ZAPI.trigger.get(filter={'host': network_device['name']})
triggerid = []
for trigger in triggers:
if trigger['description'] == NETWORK_TRIGGER_DESC:
triggerid = trigger['triggerid']
if triggerid:
ZAPI.service.create(
{
"name": network_device['name'][:-16],
"algorithm": 1,
"showsla": 1,
"goodsla": 99.05,
"sortorder": 0,
"parentid": parentid,
"triggerid": triggerid
}
)
print network_device['name']
time.sleep(2)
return True
When I test this line by line in terminal, I get the devices to show up. But when I run this as part of the larger script, nothing happens. One network device I checked had 450 triggers but, returned nothing and did not get added to the parent service when I ran the script. This leads me to believe that the API is not returning all 450 triggers when I make the 'ZAPI.trigger.get()' call. Also, when recieving a large data set like 450 triggers in JSON format, does the API page this for you (ie: it gives you 4 pages of 100 results, and one page of 50, for a total of 5 pages)?
Does this make sense?
Thank you,
Tyler