Using python script to get all triggers via Zabbix API

Question:

I am using Python Script with pyzabbix module to get all triggers via Zabbix API. Using the trigger.get() function to get all triggers list.
The Script works fine with all other functions like host.get() etc. But for this one it fails giving me 500 Internal Server Error. But when i specify certain object parameters for the same it runs.

Running it with some parameters specified for trigger.get() method then it works but i want to list out all triggers without using any of the parameters for the method triggers.get().

MY CODE :

from pyzabbix import ZabbixAPI


zapi = ZabbixAPI("http://Zabbix-Server-IP/zabbix")

zapi.login("username","password")

trigger=zapi.trigger.get()  #Method to get all triggers from zabbix

ERROR

Traceback (most recent call last):
  File "zabbix.py", line 69, in <module>
    get_all_zabbix_host()
  File "zabbix.py", line 16, in get_all_zabbix_host
    trigger=zapi.trigger.get()
  File "/usr/lib/python2.7/site-packages/pyzabbix/__init__.py", line 157, in fn
    args or kwargs
  File "/usr/lib/python2.7/site-packages/pyzabbix/__init__.py", line 109, in do_request
    response.raise_for_status()
  File "/usr/lib/python2.7/site-packages/requests/models.py", line 928, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 500 Server Error: Internal Server Error for url:
 http://Zabbix-Server-IP/zabbix/api_jsonrpc.php
Asked By: Vipul Sharma

||

Answers:

As you said, the trigger.get() call without params should return all of the defined triggers (hosts and templates).

A new zabbix system with 2 hosts and the default templates with a few additions (works with api 3.4 and 4.0):

>>> from zabbix.api import ZabbixAPI
>>> zabbixServer    = 'http://localhost/zabbix/'
>>> zabbixUser      = 'admin'
>>> zabbixPass      = 'zabbix'

>>> zapi = ZabbixAPI(url=zabbixServer, user=zabbixUser, password=zabbixPass)
>>> triggers = zapi.trigger.get()
>>> len(triggers)
482
>>> sys.getsizeof(triggers)
4280

The 500 Internal Server error is probably caused by an excessive response, for instance a result bigger than php’s memory_limit.
You should check first your httpd’s error.log for something like:

PHP Fatal error:  Allowed memory size of xxxxxxx bytes exhausted

If this is the case, you should tune your /etc/httpd/conf.d/zabbix.conf (default for Centos) accordingly then restart httpd and retry.

Answered By: Simone Zabberoni

@Vipul Sharma, I had the same problem today, but it ocurred with another python script. The solution was made the configuration of "Frontend URL" on the location: Administration – General – Others

Answered By: Romulo Billieri
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.