Ad Widget

Collapse

Add priority condition to Zabbix API event.get

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kellip
    Junior Member
    • Apr 2018
    • 2

    #1

    Add priority condition to Zabbix API event.get

    Add triggers.priority condition to Zabbix API event.get ...


    {
    "output": "extend",
    "selectRelatedObject": "extend",
    "select_acknowledges": "extend",
    "selectHosts": "extend",
    "source": 0,
    "sortfield": "clock",
    "sortorder": "DESC",
    "limit": 15,
    "filter": {
    "priority": [
    3
    ]
    }

    }


    I would like to call data with triggers.priority 3 in event.get
    I want to know the correct syntax for filter or search.
    Last edited by kellip; 20-06-2018, 03:36.
  • kernbug
    Senior Member
    • Feb 2013
    • 330

    #2
    Originally posted by kellip
    Add triggers.priority condition to Zabbix API event.get ...


    I want to know the correct syntax for filter or search.
    Hi

    Zabbix API is well documented:


    could you clarify the task?

    Comment


    • kellip
      kellip commented
      Editing a comment
      Thank you kernbug for the help.

      I want to call only the priority 3 in event.get
  • kernbug
    Senior Member
    • Feb 2013
    • 330

    #3
    Hello

    Depending on the programming language used to match the data, you need to execute 2 requests between the events and triggers;

    Here is the example for you (using curl), first of all get Auth token:
    Code:
    curl  -H "Content-Type: application/json-rpc" -X POST  http://[COLOR=#00FFFF]192.168.1.50/zabbix/[/COLOR]api_jsonrpc.php -d '{"jsonrpc":"2.0","method":"user.login","params":{ "user":"Admin","password":"zabbix"},"auth":null,"id":0}'
    
    (answer): {"jsonrpc":"2.0","result":"[COLOR=#FF0000]a72d28f6792556fe847ef1c107999f05[/COLOR]","id":0}
    Next, we need to ask about fired up triggers (value: 1) with the priority value 3 using Auth token:
    Code:
    curl  -H "Content-Type: application/json-rpc" -X POST  http://[COLOR=#00FFFF]192.168.1.50/zabbix/[/COLOR]api_jsonrpc.php -d '{"jsonrpc": "2.0","method": "trigger.get","params": {"output": ["triggerid","description","priority"],"filter": {"value": 1,"priority": [COLOR=#FF0000]3[/COLOR]},"sortfield": "priority","sortorder": "DESC"},"auth": "[COLOR=#FF0000]a72d28f6792556fe847ef1c107999f05[/COLOR]","id": 1}'
    
    (answer):  {"jsonrpc":"2.0","result":[{"triggerid":"[COLOR=#FF0000]13491[/COLOR]","description":"Zabbix agent on {HOST.NAME} is unreachable for 5 minutes","priority":"3"}],"id":1}
    Ok, we have 'triggerid', let's find events:
    Code:
    curl  -H "Content-Type: application/json-rpc" -X POST  http://[COLOR=#00FFFF]192.168.1.50/zabbix/[/COLOR]api_jsonrpc.php -d '{"jsonrpc": "2.0","method": "event.get","params": {"output": "extend","select_acknowledges": "extend","objectids": "[COLOR=#FF0000]13491[/COLOR]","sortfield": ["clock", "eventid"],"sortorder": "DESC"},"auth": "a72d28f6792556fe847ef1c107999f05","id": 1}'
    
    (answer):  {"jsonrpc":"2.0","result":[{"eventid":"10","source":"0","object":"0","objectid":"[COLOR=#FF0000]13491[/COLOR]","clock":"1529468010","value":"1","acknowledged":"0","ns":"672817644","r_eventid":"0","c_eventid":"0","correlationid":"0","userid":"0","acknowledges":[]}],"id":1}
    Overall schema is: for all 'trigger.get' with priority 3 find 'events.get' by triggerid
    Last edited by kernbug; 20-06-2018, 06:41.

    Comment


    • kellip
      kellip commented
      Editing a comment
      I will make two requests as advised.
      Thank you for answer.
Working...