0

I am using zabbix for infrastructure monitoring. I want to export alerts real time to a centralized platform like splunk, ELK? Can i pull all active alerts for last 15 mins using Zabbix API

ALso, is the api mature enough to implement auto close functionality?

Thanks in Advance !!!!

1 Answers1

0

You should use the problem.get api:

This method is for retrieving unresolved problems. It is also possible, if specified, to additionally retrieve recently resolved problems.

A small python sample:

from zabbix.api import ZabbixAPI

zabbixServer    = 'http://yourserver/zabbix/'
zabbixUser      = 'someuser'
zabbixPass      = 'somepass'

zapi = ZabbixAPI(url=zabbixServer, user=zabbixUser, password=zabbixPass)

problems = zapi.problem.get()

for problem in problems:
    trigger = zapi.trigger.get (triggerids=problem['objectid'], selectHosts='extend')
    interface = zapi.hostinterface.get(hostids=trigger[0]['hosts'][0]['hostid'])
    group = zapi.hostgroup.get(hostids=trigger[0]['hosts'][0]['hostid'])

    enabled = "Enabled"
    if (trigger[0]['hosts'][0]['status'] == "1"):
        enabled = "Disabled"

    print "Group:{}; Host:{}; IP:{}; Problem:{}; {}".format(group[1]['name'],
                                                           trigger[0]['hosts'][0]['host'],
                                                           interface[0]['ip'],
                                                           trigger[0]['description'],
                                                           enabled )
Simone Zabberoni
  • 2,024
  • 1
  • 10
  • 15
  • Getting error: `Traceback (most recent call last): File "zabbix_alerting.py", line 7, in zapi = ZabbixAPI(url=zabbixServer, user=zabbixUser, password=zabbixPass) File "/usr/lib/python2.7/site-packages/pyzabbix/api.py", line 180, in __init__ self._login(user, password) File "/usr/lib/python2.7/site-packages/pyzabbix/api.py", line 210, in _login self.auth = self.user.login(user=user, password=password) File "/usr/lib/python2.7/site-packages/pyzabbix/api.py", line 94, in fn args or kwargs urllib2.URLError: ` – Ajay Singh Jul 01 '20 at 15:51
  • "Connection timed out". Did you set `zabbixServer` to the correct url? – Simone Zabberoni Jul 01 '20 at 20:21
  • yeah , i doubled check URL, username and password, but same error. Do my user need some specific permissions? currently using admin – Ajay Singh Jul 02 '20 at 12:05
  • Are you running the script on your pc? On the server itself? On another linux machine? Did you check for firewall rules? Did you add a try..catch to the Zapii connect? You can also do a tcpdump to be sure... there are lots of thing to do and check. – Simone Zabberoni Jul 02 '20 at 12:07