Ad Widget

Collapse

[DEV help] - Active Triggers except aknowledged ones

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • zabbix_zen
    Senior Member
    • Jul 2009
    • 426

    #1

    [DEV help] - Active Triggers except aknowledged ones

    Hi.

    I've cloned Zabbix make_latest_issues function source and successfully modified it for a periodic report which shows all Active events
    (for emailing a team that is not required to know how to use Zabbix)

    Now I'm having trouble getting it to filter out the corresponding Acknowledged events.

    Adding,
    ' AND e.acknowledged=0'.
    I was expecting it to only return the Active events which are not Acknowledged, however...
    for each Active Acknowledged event, it returns the previous historic
    (non active) event as seen in,

    the 'Events List [Previous 20]' from zabbix/tr_events.php?triggerid=_trigger_id&eventid=_event _id&sid=_session_id

    $sql = 'SELECT DISTINCT t.triggerid,t.status,t.description, t.priority, t.lastchange,t.value,h.host,h.hostid '.
    ' FROM triggers t,hosts h,items i,functions f, hosts_groups hg '.
    ' WHERE f.itemid=i.itemid '.
    ' AND h.hostid=i.hostid '.
    ' AND hg.hostid=h.hostid '.
    ' AND t.triggerid=f.triggerid '.
    ' AND t.status='.TRIGGER_STATUS_ENABLED.
    ' AND t.value = 1 '.
    ' AND t.status=0 '.
    // ' AND '.DBin_node('t.triggerid').
    ' AND '.DBcondition('t.triggerid',$available_triggers).
    ' AND h.status='.HOST_STATUS_MONITORED.
    ' AND h.hostid IN (select hostid from hosts_groups where groupid IN (16,27))'.
    ' ORDER BY t.lastchange DESC';
    }

    $result = DBselect($sql);
    while($row=DBfetch($result)){
    // Check for dependencies
    if(trigger_dependent($row["triggerid"])) continue;

    $event_sql = 'SELECT e.eventid, e.value, e.clock, e.objectid as triggerid, e.acknowledged, t.type '.
    ' FROM events e, triggers t '.
    ' WHERE e.object='.EVENT_SOURCE_TRIGGERS.
    // Filter by unacknowledged Events
    ' AND e.acknowledged=0'.
    ' AND e.objectid='.$row['triggerid'].
    ' AND t.triggerid=e.objectid '.
    ' ORDER by e.object DESC, e.objectid DESC, e.eventid DESC';
    Which condition change am I missing?
  • zabbix_zen
    Senior Member
    • Jul 2009
    • 426

    #2
    It turns out all I needed was to sleep on it

    $sql = 'SELECT DISTINCT t.triggerid,t.status,t.description, t.priority, t.lastchange,t.value,h.host,h.hostid '.
    ' FROM triggers t,hosts h,items i,functions f, hosts_groups hg '.
    ' WHERE f.itemid=i.itemid '.
    ' AND h.hostid=i.hostid '.
    ' AND hg.hostid=h.hostid '.
    ' AND t.triggerid=f.triggerid '.
    ' AND t.status='.TRIGGER_STATUS_ENABLED.
    ' AND t.value = 1 '.
    ' AND t.status=0 '.
    // ' AND '.DBin_node('t.triggerid').
    ' AND '.DBcondition('t.triggerid',$available_triggers).
    ' AND h.status='.HOST_STATUS_MONITORED.
    ' AND h.hostid IN (select hostid from hosts_groups where groupid IN (16,27))'.
    ' ORDER BY t.lastchange DESC';
    }

    $result = DBselect($sql);
    while($row=DBfetch($result)){
    // Check for dependencies
    if(trigger_dependent($row["triggerid"])) continue;

    $event_sql = 'SELECT e.eventid, e.value, e.clock, e.objectid as triggerid, e.acknowledged, t.type
    ' FROM events e, triggers t
    ' WHERE e.object='.EVENT_SOURCE_TRIGGERS.
    ' AND e.objectid='.$row['triggerid'].
    ' AND t.triggerid=e.objectid '.
    ' AND e.value = 1 '.
    ' ORDER by e.objectid DESC, e.eventid DESC';

    $res_events = DBSelect($event_sql,1);

    while($row_event=DBfetch($res_events)){
    $unack_sql = 'SELECT e.eventid, e.clock, e.objectid as triggerid '.
    ' FROM events e, triggers t '.
    // Filter by unaknowledged Events
    ' WHERE e.acknowledged=0'.
    ' AND e.eventid='.$row_event['eventid'];

    $unack_rows = DBSelect($unack_sql,1);
    while($unack_row=DBfetch($unack_rows))
    {

    $description = expand_trigger_description_by_data(
    array_merge($row, array("clock"=>$row_unack["clock"])),
    ZBX_FLAG_EVENT);
    print_r($row_unack);

    Comment

    Working...