Ad Widget

Collapse

Zabbix API. How to extract " Most busy triggers top 100"?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mal
    Junior Member
    • Feb 2009
    • 4

    #1

    Zabbix API. How to extract " Most busy triggers top 100"?

    Hi,

    I want automatically extract "Most busy triggers top 100" for week period and send e-mail with extracted info. I can't find some feature in Zabbix API.

    Does anybody know how to do it with Zabbix API or other workaround?

    Thanks.
  • mal
    Junior Member
    • Feb 2009
    • 4

    #2
    workaround. extract data directly from DB (MySQL)

    After unsuccessful attempt to do it with API I found some workaround. Extract information directly from DB. Maybe it helps for somebody.

    To run php file: /usr/bin/php /path/to/php/file (you can include it to your crontab jobs)

    Code:
    <?php
    
    $con = mysql_connect("localhost","user","password");
    if (!$con)
    {
            die('Could not connect: ' . mysql_error());
    }
    
    mysql_select_db("zabbix", $con);
    
    $current_time = time();
    $week_ago_time = $current_time - 604800;
    
    $result = mysql_query("
    SELECT count(distinct e.eventid) as cnt_event, h.host, t.description, t.priority
    FROM events e, hosts h, triggers t, functions f, items i
    WHERE h.hostid = i.hostid
    and i.itemid = f.itemid
    and t.triggerid=f.triggerid
    and t.triggerid=e.objectid
    and t.priority>3
    and e.clock>" . $week_ago_time . "
    GROUP BY h.host,t.triggerid,t.description,t.expression,t.priority
    ORDER BY cnt_event desc, h.host, t.description, t.triggerid
    ");
    
    $mail_message = ' 
    <html>
    <head>
    <style type="text/css">
    table {border-collapse:collapse;}
    th {background-color:#8BB381;}
    table,th,td {border: 1px solid black;}
    </style>
    </head>
    <body>
    Most busy triggers from: ' . date("Y-m-d H:i",$week_ago_time) . ' till: ' . date("Y-m-d H:i",$current_time) . "\n" . '<br><br>' .
    '<table>
    <tr>
    <th>Status changes count</th><th>Host</th><th>Trigger description</th><th>Priority</th>
    </tr>';
    
    while($row = mysql_fetch_array($result))
    {
            $row['description'] = str_replace("{HOSTNAME}",$row['host'],$row['description']);
            $mail_message .= '<tr>' . "\n" .
                                    '<td align="center">' . $row['cnt_event'] .
                                    '</td><td>' . $row['host'] .
                                    '</td><td>' . $row['description'] .
                                    '</td><td align="center">' . $row['priority'] . '</td>' . "\n" .
                             '</tr>' . "\n";
    }
    
    
    $mail_message .= '
    </table>
    </body>
    </html>';
    
    mysql_close($con);
    
    $headers  = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
    
    $to = '[email protected]';
    $headers .= 'From: [email][email protected][/email]e' . "\r\n";
    
    mail($to, 'Top most busy triggers ' . date("Y-m-d H:i",$week_ago_time) . ' - ' . date("Y-m-d H:i",$current_time), $mail_message, $headers);
    ?>

    Comment

    • zabbixfk
      Senior Member
      • Jun 2013
      • 256

      #3
      I know this is quite an old thread, does anyone got this working via API? Please comment.
      I was able to get this query working, problem is, when you have hosts > 5K, events > 10L, its difficult to wait for this query to get over - its taking close to 7mins to run and that's a really long time , was wondering if any API based aproach present, specially when you know what's the hostGroup to search for.

      Comment

      • Raghavendra Shekhawat
        Junior Member
        • Dec 2023
        • 1

        #4
        Workaround, I used selenium to extract the busiest triggers, worked like a charm.

        Comment

        Working...