Ad Widget

Collapse

Query: Trigger age

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bashman
    Senior Member
    • Dec 2009
    • 432

    #1

    Query: Trigger age

    I would like to query Zabbix DB to get the age of all corrected triggers in order to know how long did the problem take to get solved, during last month.
    978 Hosts / 16.901 Items / 8.703 Triggers / 44 usr / 90,59 nvps / v1.8.15
  • zabbix_zen
    Senior Member
    • Jul 2009
    • 426

    #2
    Hola Bashman.

    This post show how to query the *currently* active Triggers showing how long they're already active.

    It should get you in the right direction with some slight modifications.

    Comment

    • bashman
      Senior Member
      • Dec 2009
      • 432

      #3
      Obrigado zabbix_zen!,

      I'm getting close to what I want, I already have this:

      Code:
      SELECT DISTINCT t.triggerid, h.host, t.description, FROM_UNIXTIME(UNIX_TIMESTAMP(NOW()) - i.lastclock, '%h:%i:%s'), t.value
      FROM   triggers t
             INNER JOIN functions f ON ( f.triggerid = t.triggerid )
             INNER JOIN events e ON ( e.objectid = t.triggerid )
             INNER JOIN items i ON ( i.itemid = f.itemid )
             INNER JOIN hosts h ON ( i.hostid = h.hostid )
             INNER JOIN hosts_groups hg ON ( hg.hostid = h.hostid )
             INNER JOIN groups g ON ( hg.groupid = g.groupid )
      WHERE  t.value IN (0, 1)
             AND h.status = 0
             AND i.status = 0
             AND t.status = 0
             AND t.priority > 2
             AND e.acknowledged = 0
             AND i.lastclock >= UNIX_TIMESTAMP(NOW() - INTERVAL 9 MINUTE)
             AND e.eventid = (SELECT max(eventid)
                              FROM   events e
                              WHERE  t.value IN (0, 1)
                                     AND h.status = 0
                                     AND i.status = 0
                                     AND t.status = 0
                                     AND e.objectid = t.triggerid)
             AND g.name = "Linux"
             ORDER BY h.host, i.lastclock DESC;
      But I would like to get the trigger duration, the time a trigger has been "on".
      978 Hosts / 16.901 Items / 8.703 Triggers / 44 usr / 90,59 nvps / v1.8.15

      Comment

      • gessel
        Junior Member
        • Mar 2017
        • 24

        #4
        Calculated event age, formatted as days hours:minutes

        SELECT DISTINCT host, p.ip, t.description,
        CONCAT(
        FLOOR(HOUR(TIMEDIFF(NOW(), FROM_UNIXTIME(e.clock))) / 24), ' days ',
        MOD(HOUR(TIMEDIFF(NOW(), FROM_UNIXTIME(e.clock))), 24), ':',
        LPAD(MINUTE(TIMEDIFF(NOW(), FROM_UNIXTIME(e.clock))), 2, '0')) as time FROM triggers t
        INNER JOIN functions f ON ( f.triggerid = t.triggerid )
        INNER JOIN items i ON ( i.itemid = f.itemid )
        INNER JOIN hosts h ON ( i.hostid = h.hostid )
        INNER JOIN interface p ON ( h.hostid = p.hostid )
        INNER JOIN events e ON ( e.objectid = t.triggerid )
        LEFT JOIN acknowledges a ON ( a.eventid = e.eventid )
        WHERE (e.eventid DIV 100000000000000)
        IN (0)
        AND e.object = 0
        AND (t.value=1 OR (t.value =0 AND unix_timestamp(now()) - t.lastchange <60))
        AND h.status = 0
        AND i.status = 0
        AND t.status = 0
        AND t.priority > 3
        AND e.acknowledged = 0
        AND e.eventid = (SELECT max(eventid)
        FROM events e
        WHERE (e.eventid DIV 100000000000000)
        IN (0)
        AND e.object = 0
        AND (t.value=1 OR (t.value =0 AND unix_timestamp(now()) - t.lastchange <60))
        AND h.status = 0
        AND i.status = 0
        AND t.status = 0
        AND e.acknowledged = 0
        AND e.objectid = t.triggerid
        )
        GROUP BY host, f.triggerid
        ORDER BY e.clock DESC;

        Comment

        • fgo.oliver
          Junior Member
          • Dec 2019
          • 6

          #5
          hello Gessel, can you help me?
          I need the same, but, for now, i'm searching for a query that bring the event duration for a x trigger...

          for example, trigger activate today 10am and back up at 11am, the duration in this case was 60 minutes...

          please, help me...

          Comment

          • fgo.oliver
            Junior Member
            • Dec 2019
            • 6

            #6
            Look, I have this post https://www.zabbix.com/forum/zabbix-...r-get-duration

            Comment

            • gessel
              Junior Member
              • Mar 2017
              • 24

              #7
              You'd just use time math compared to (NOW) https://dev.mysql.com/doc/refman/8.0...functions.html to find the duration of unresolved events. I'm not sure how to recreate the "history" table with the resolved problems and duration it was a problem. I'd think this data would be in https://zabbix.org/wiki/Docs/DB_sche...event_recovery but there's no clock value in that table. But as you will find, there's zero documentation about what these values mean. Each of the table descriptions is "This table contains [please add a brief table description]." The best I can find at the moment is the acknowledge time. https://zabbix.org/wiki/Docs/DB_schema/4.0/acknowledges (a nicely commented table page - thanks to whoever provided the detail)

              Comment

              Working...