Ad Widget

Collapse

API Problem: Trigger.get with lastEvent returns empty array

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • iyossi
    Junior Member
    • May 2016
    • 15

    #1

    API Problem: Trigger.get with lastEvent returns empty array

    Hi

    Wwe are using Zabbix 3.0

    When asking for triggers with problems we want to get lastEvent
    In our case we got trigger with problem but with no lastEvent

    Zabbix return no lastEvent as an empty array. We expect an object. We get:


    {
    "jsonrpc": "2.0",
    "result": [
    {
    "triggerid": "19868",
    "expression": "{20089} > 1.0",
    "description": "Check if too much disk space is used",
    "url": "",
    "status": "0",
    "value": "1",
    "priority": "4",
    "lastchange": "1483229759",
    "comments": "",
    "error": "Agent is unavailable.",
    "templateid": "0",
    "type": "0",
    "state": "1",
    "flags": "0",
    "lastEvent": [
    ]

    }
    ],
    "id": 564643980
    }

    In normal cases we get lastEvent as an object.
    Is it a bug In Zabbix API ?
  • estein
    Junior Member
    • Mar 2017
    • 4

    #2
    Not all triggers are created via events

    I realized this is a (semi-) old post, but I figured others might benefit:

    I have discovered through a lot of trial and error that not all triggers are created equally. some are from events, while others are system generated. However, none of that matters because the date value and the age specified in the trigger page within Zabbix is actually taken from the lastchange trigger property. So using that millisecond value (* 1000) and formatting it against yyyy-MM-dd H:mm:ss, you can then get the creation date as you see it on the dashboard. To get the age, I had to get creative with Joda time, since it's more reliant than standard java date-time. I've provided my logic for convenience:

    Code:
    DateTime now = new DateTime();
    Period diffPeriod = new Interval(Long.parseLong(trigger.lastchange)*1000, now.getMillis()).toPeriod();
    
    Then use diffPeriod to extract each of the period values like 
    
    diffPeriod.getYears()
    or
    diffPeriod.getMonths()
    Joda offers getWeeks() as well, but the trigger page combines them into total days.

    Comment

    Working...