Exemple #1
0
 $triggers = zbx_toHash($triggers, 'triggerid');
 foreach ($events as $enum => $event) {
     $trigger = $triggers[$event['objectid']];
     $host = reset($trigger['hosts']);
     $items = array();
     foreach ($trigger['items'] as $inum => $item) {
         $i = array();
         $i['itemid'] = $item['itemid'];
         $i['value_type'] = $item['value_type'];
         //ZBX-3059: So it would be possible to show different caption for history for chars and numbers (KB)
         $i['action'] = str_in_array($item['value_type'], array(ITEM_VALUE_TYPE_FLOAT, ITEM_VALUE_TYPE_UINT64)) ? 'showgraph' : 'showvalues';
         $i['description'] = item_description($item);
         $items[] = $i;
     }
     // Actions
     $actions = get_event_actions_status($event['eventid']);
     if ($config['event_ack_enable']) {
         if ($event['acknowledged'] == 1) {
             $ack = new CLink(S_YES, 'acknow.php?eventid=' . $event['eventid'] . '&backurl=' . $page['file']);
         } else {
             $ack = new CLink(S_NO, 'acknow.php?eventid=' . $event['eventid'] . '&backurl=' . $page['file'], 'on');
         }
     }
     $description = expand_trigger_description_by_data(zbx_array_merge($trigger, array('clock' => $event['clock'])), ZBX_FLAG_EVENT);
     $tr_desc = new CSpan($description, 'pointer');
     $tr_desc->addAction('onclick', "create_mon_trigger_menu(event, " . " new Array({'triggerid': '" . $trigger['triggerid'] . "', 'lastchange': '" . $event['clock'] . "'})," . zbx_jsvalue($items, true) . ");");
     // Duration
     $tr_event = $event + $trigger;
     if ($next_event = get_next_event($tr_event, $events, $_REQUEST['hide_unknown'])) {
         $event['duration'] = zbx_date2age($tr_event['clock'], $next_event['clock']);
     } else {
Exemple #2
0
function make_system_summary($args = array())
{
    global $USER_DETAILS;
    $config = select_config();
    $available_hosts = get_accessible_hosts_by_user($USER_DETAILS, PERM_READ_ONLY, PERM_RES_IDS_ARRAY);
    $available_groups = get_accessible_groups_by_user($USER_DETAILS, PERM_READ_ONLY, PERM_RES_IDS_ARRAY);
    $available_triggers = get_accessible_triggers(PERM_READ_ONLY, array(), PERM_RES_IDS_ARRAY);
    if (isset($args['hosts']) && !empty($args['hosts'])) {
        $available_hosts = zbx_uint_array_intersect($args['hosts'], $available_hosts);
    }
    if (isset($args['groups']) && !empty($args['groups'])) {
        $available_groups = zbx_uint_array_intersect($args['groups'], $available_groups);
    }
    $sql_where = '';
    if (isset($args['severity']) && ctype_digit($args['severity'])) {
        $sql_where = ' AND t.priority>=' . $args['severity'];
    }
    $table = new CTableInfo();
    $table->setHeader(array(is_show_all_nodes() ? S_NODE : null, S_HOST_GROUP, S_DISASTER, S_HIGH, S_AVERAGE, S_WARNING, S_INFORMATION, S_NOT_CLASSIFIED));
    $sql = 'SELECT DISTINCT g.groupid,g.name ' . ' FROM groups g, hosts_groups hg, hosts h, items i, functions f, triggers t ' . ' WHERE ' . DBcondition('h.hostid', $available_hosts) . ' AND ' . DBcondition('g.groupid', $available_groups) . ' AND hg.groupid=g.groupid ' . ' AND h.status=' . HOST_STATUS_MONITORED . ' AND h.hostid=i.hostid ' . ' AND hg.hostid=h.hostid ' . ' AND i.status=' . ITEM_STATUS_ACTIVE . ' AND i.itemid=f.itemid ' . ' AND t.triggerid=f.triggerid ' . ' AND t.status=' . TRIGGER_STATUS_ENABLED . ' ORDER BY g.name';
    $gr_result = DBselect($sql);
    while ($group = DBFetch($gr_result)) {
        $group_row = new CRow();
        if (is_show_all_nodes()) {
            $group_row->addItem(get_node_name_by_elid($group['groupid']));
        }
        $name = new CLink($group['name'], 'tr_status.php?groupid=' . $group['groupid'] . '&show_triggers=' . TRIGGERS_OPTION_ONLYTRUE);
        $name->setTarget('blank');
        $group_row->addItem($name);
        $tab_priority[TRIGGER_SEVERITY_DISASTER] = 0;
        $tab_priority[TRIGGER_SEVERITY_HIGH] = 0;
        $tab_priority[TRIGGER_SEVERITY_AVERAGE] = 0;
        $tab_priority[TRIGGER_SEVERITY_WARNING] = 0;
        $tab_priority[TRIGGER_SEVERITY_INFORMATION] = 0;
        $tab_priority[TRIGGER_SEVERITY_NOT_CLASSIFIED] = 0;
        $sql = 'SELECT count(DISTINCT t.triggerid) as tr_cnt,t.priority ' . ' FROM hosts h,items i,hosts_groups hg, functions f, triggers t ' . ' WHERE h.status=' . HOST_STATUS_MONITORED . ' AND h.hostid=i.hostid ' . ' AND hg.groupid=' . $group['groupid'] . ' AND hg.hostid=h.hostid' . ' AND i.status=' . ITEM_STATUS_ACTIVE . ' AND i.itemid=f.itemid ' . ' AND t.triggerid=f.triggerid ' . ' AND t.value=' . TRIGGER_VALUE_TRUE . ' AND t.status=' . TRIGGER_STATUS_ENABLED . ' AND ' . DBcondition('h.hostid', $available_hosts) . ' GROUP BY t.priority';
        //SDI($sql);
        $tr_result = DBSelect($sql);
        while ($group_stat = DBFetch($tr_result)) {
            $tab_priority[$group_stat['priority']] = $group_stat['tr_cnt'];
        }
        foreach ($tab_priority as $key => $value) {
            $tr_count = 0;
            if ($value) {
                //* trigger list
                $table_inf = new CTableInfo();
                $table_inf->setAttribute('style', 'width: 400px;');
                $table_inf->setHeader(array(is_show_all_nodes() ? S_NODE : null, S_HOST, S_ISSUE, S_AGE, $config['event_ack_enable'] ? S_ACK : NULL, S_ACTIONS));
                $sql = 'SELECT DISTINCT t.triggerid,t.status,t.description,t.expression,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 hg.groupid=' . $group['groupid'] . ' AND h.hostid=i.hostid ' . ' AND hg.hostid=h.hostid ' . ' AND t.triggerid=f.triggerid ' . ' AND t.status=' . TRIGGER_STATUS_ENABLED . ' AND i.status=' . ITEM_STATUS_ACTIVE . ' AND ' . DBcondition('t.triggerid', $available_triggers) . ' AND h.status=' . HOST_STATUS_MONITORED . ' AND t.value=' . TRIGGER_VALUE_TRUE . ' AND t.priority=' . $key . ' ORDER BY t.lastchange DESC';
                $result = DBselect($sql);
                while ($row_inf = DBfetch($result)) {
                    // Check for dependencies
                    if (trigger_dependent($row_inf["triggerid"])) {
                        continue;
                    }
                    $tr_count++;
                    if ($tr_count > 30) {
                        continue;
                    }
                    $host = new CSpan($row_inf['host']);
                    $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_inf['triggerid'] . ' AND t.triggerid=e.objectid ' . ' AND e.value=' . TRIGGER_VALUE_TRUE . ' ORDER by e.object DESC, e.objectid DESC, e.eventid DESC';
                    if ($row_inf_event = DBfetch(DBselect($event_sql, 1))) {
                        if ($config['event_ack_enable']) {
                            if ($row_inf_event['acknowledged'] == 1) {
                                $ack = new CLink(S_YES, 'acknow.php?eventid=' . $row_inf_event['eventid'], 'action');
                            } else {
                                $ack = new CLink(S_NO, 'acknow.php?eventid=' . $row_inf_event['eventid'], 'on');
                            }
                        }
                        $description = expand_trigger_description_by_data(array_merge($row_inf, array('clock' => $row_inf_event['clock'])), ZBX_FLAG_EVENT);
                        //actions
                        $actions = get_event_actions_status($row_inf_event['eventid']);
                        //--------
                    } else {
                        $description = expand_trigger_description_by_data($row_inf, ZBX_FLAG_EVENT);
                        $ack = '-';
                        $actions = S_NO_DATA_SMALL;
                        $row_inf_event['clock'] = $row_inf['clock'];
                    }
                    $table_inf->addRow(array(get_node_name_by_elid($row_inf['triggerid']), $host, new CCol($description, get_severity_style($row_inf['priority'])), zbx_date2age($row_inf_event['clock']), $config['event_ack_enable'] ? new CCol($ack, 'center') : NULL, $actions));
                    unset($row_inf, $description, $actions);
                }
                $value = new CSpan($tr_count, 'pointer');
                $value->setHint($table_inf);
                //-------------*/
            }
            $group_row->AddItem(new CCol($value, get_severity_style($key, $tr_count)));
            unset($table_inf);
        }
        $table->addRow($group_row);
    }
    $table->setFooter(new CCol(S_UPDATED . ': ' . date("H:i:s", time())));
    return $table;
}
function make_system_status($filter)
{
    $config = select_config();
    $table = new CTableInfo();
    $table->setHeader(array(is_show_all_nodes() ? S_NODE : null, S_HOST_GROUP, is_null($filter['severity']) || isset($filter['severity'][TRIGGER_SEVERITY_DISASTER]) ? S_DISASTER : null, is_null($filter['severity']) || isset($filter['severity'][TRIGGER_SEVERITY_HIGH]) ? S_HIGH : null, is_null($filter['severity']) || isset($filter['severity'][TRIGGER_SEVERITY_AVERAGE]) ? S_AVERAGE : null, is_null($filter['severity']) || isset($filter['severity'][TRIGGER_SEVERITY_WARNING]) ? S_WARNING : null, is_null($filter['severity']) || isset($filter['severity'][TRIGGER_SEVERITY_INFORMATION]) ? S_INFORMATION : null, is_null($filter['severity']) || isset($filter['severity'][TRIGGER_SEVERITY_NOT_CLASSIFIED]) ? S_NOT_CLASSIFIED : null));
    // SELECT HOST GROUPS {{{
    $options = array('nodeids' => get_current_nodeid(), 'monitored_hosts' => 1, 'groupids' => $filter['groupids'], 'output' => API_OUTPUT_EXTEND);
    $groups = CHostGroup::get($options);
    $groups = zbx_toHash($groups, 'groupid');
    order_result($groups, 'name');
    $groupids = array();
    foreach ($groups as $gnum => $group) {
        $groupids[] = $group['groupid'];
        $group['tab_priority'] = array();
        $group['tab_priority'][TRIGGER_SEVERITY_DISASTER] = array('count' => 0, 'triggers' => array(), 'count_unack' => 0, 'triggers_unack' => array());
        $group['tab_priority'][TRIGGER_SEVERITY_HIGH] = array('count' => 0, 'triggers' => array(), 'count_unack' => 0, 'triggers_unack' => array());
        $group['tab_priority'][TRIGGER_SEVERITY_AVERAGE] = array('count' => 0, 'triggers' => array(), 'count_unack' => 0, 'triggers_unack' => array());
        $group['tab_priority'][TRIGGER_SEVERITY_WARNING] = array('count' => 0, 'triggers' => array(), 'count_unack' => 0, 'triggers_unack' => array());
        $group['tab_priority'][TRIGGER_SEVERITY_INFORMATION] = array('count' => 0, 'triggers' => array(), 'count_unack' => 0, 'triggers_unack' => array());
        $group['tab_priority'][TRIGGER_SEVERITY_NOT_CLASSIFIED] = array('count' => 0, 'triggers' => array(), 'count_unack' => 0, 'triggers_unack' => array());
        $groups[$group['groupid']] = $group;
    }
    // }}} SELECT HOST GROUPS
    // SELECT TRIGGERS {{{
    $options = array('nodeids' => get_current_nodeid(), 'groupids' => $groupids, 'monitored' => 1, 'maintenance' => $filter['maintenance'], 'expandData' => 1, 'skipDependent' => 1, 'expandDescription' => 1, 'filter' => array('priority' => $filter['severity'], 'value' => TRIGGER_VALUE_TRUE), 'output' => API_OUTPUT_EXTEND);
    if ($filter['extAck'] == EXTACK_OPTION_UNACK) {
        $options['withLastEventUnacknowledged'] = 1;
    }
    $triggers = CTrigger::get($options);
    order_result($triggers, 'lastchange', ZBX_SORT_DOWN);
    foreach ($triggers as $tnum => $trigger) {
        $options = array('nodeids' => get_current_nodeid(), 'triggerids' => $trigger['triggerid'], 'object' => EVENT_SOURCE_TRIGGERS, 'value' => TRIGGER_VALUE_TRUE, 'output' => API_OUTPUT_EXTEND, 'nopermissions' => 1, 'limit' => 1, 'sortfield' => 'eventid', 'sortorder' => ZBX_SORT_DOWN);
        $event = CEvent::get($options);
        if (empty($event)) {
            $trigger['event'] = array('acknowledged' => 1, 'clock' => $trigger['lastchange']);
        } else {
            $trigger['event'] = reset($event);
        }
        foreach ($trigger['groups'] as $group) {
            if ($groups[$group['groupid']]['tab_priority'][$trigger['priority']]['count'] < 30) {
                $groups[$group['groupid']]['tab_priority'][$trigger['priority']]['triggers'][] = $trigger;
            }
            if ($groups[$group['groupid']]['tab_priority'][$trigger['priority']]['count_unack'] < 30 && !$trigger['event']['acknowledged']) {
                $groups[$group['groupid']]['tab_priority'][$trigger['priority']]['triggers_unack'][] = $trigger;
            }
            $groups[$group['groupid']]['tab_priority'][$trigger['priority']]['count']++;
            if (!$trigger['event']['acknowledged']) {
                $groups[$group['groupid']]['tab_priority'][$trigger['priority']]['count_unack']++;
            }
        }
    }
    unset($triggers);
    order_result($groups, 'name');
    // }}} SELECT TRIGGERS
    foreach ($groups as $gnum => $group) {
        $group_row = new CRow();
        if (is_show_all_nodes()) {
            $group_row->addItem(get_node_name_by_elid($group['groupid']));
        }
        $name = new CLink($group['name'], 'tr_status.php?groupid=' . $group['groupid'] . '&show_triggers=' . TRIGGERS_OPTION_ONLYTRUE);
        $group_row->addItem($name);
        foreach ($group['tab_priority'] as $severity => $data) {
            if (!is_null($filter['severity']) && !isset($filter['severity'][$severity])) {
                continue;
            }
            if ($data['count'] && in_array($filter['extAck'], array(EXTACK_OPTION_ALL, EXTACK_OPTION_BOTH))) {
                $table_inf = new CTableInfo();
                $table_inf->setAttribute('style', 'width: 400px;');
                $table_inf->setHeader(array(is_show_all_nodes() ? S_NODE : null, S_HOST, S_ISSUE, S_AGE, $config['event_ack_enable'] ? S_ACK : NULL, S_ACTIONS));
                foreach ($data['triggers'] as $tnum => $trigger) {
                    $event = $trigger['event'];
                    if ($config['event_ack_enable'] && isset($event['eventid'])) {
                        $ack = $event['acknowledged'] ? new CLink(S_YES, 'acknow.php?eventid=' . $event['eventid'], 'off') : new CLink(S_NO, 'acknow.php?eventid=' . $event['eventid'], 'on');
                        $actions = get_event_actions_status($event['eventid']);
                    } else {
                        $ack = '-';
                        $actions = S_NO_DATA_SMALL;
                    }
                    $table_inf->addRow(array(get_node_name_by_elid($trigger['triggerid']), $trigger['host'], new CCol($trigger['description'], get_severity_style($trigger['priority'])), zbx_date2age($event['clock']), $config['event_ack_enable'] ? new CCol($ack, 'center') : NULL, $actions));
                }
            }
            if ($data['count_unack'] && in_array($filter['extAck'], array(EXTACK_OPTION_UNACK, EXTACK_OPTION_BOTH))) {
                $table_inf_unack = new CTableInfo();
                $table_inf_unack->setAttribute('style', 'width: 400px;');
                $table_inf_unack->setHeader(array(is_show_all_nodes() ? S_NODE : null, S_HOST, S_ISSUE, S_AGE, $config['event_ack_enable'] ? S_ACK : NULL, S_ACTIONS));
                foreach ($data['triggers_unack'] as $tnum => $trigger) {
                    $event = $trigger['event'];
                    if ($config['event_ack_enable']) {
                        $ack = new CLink(S_NO, 'acknow.php?eventid=' . $event['eventid'], 'on');
                        $actions = get_event_actions_status($event['eventid']);
                    } else {
                        $ack = '-';
                        $actions = S_NO_DATA_SMALL;
                    }
                    $table_inf_unack->addRow(array(get_node_name_by_elid($trigger['triggerid']), $trigger['host'], new CCol($trigger['description'], get_severity_style($trigger['priority'])), zbx_date2age($event['clock']), $config['event_ack_enable'] ? new CCol($ack, 'center') : NULL, $actions));
                }
            }
            switch ($filter['extAck']) {
                case EXTACK_OPTION_ALL:
                    $trigger_count = new CSpan($data['count'], 'pointer');
                    if ($data['count']) {
                        $trigger_count->setHint($table_inf);
                    }
                    $group_row->addItem(new CCol($trigger_count, get_severity_style($severity, $data['count'])));
                    break;
                case EXTACK_OPTION_UNACK:
                    $trigger_count = $data['count_unack'];
                    if ($trigger_count) {
                        $trigger_count = new CSpan($data['count_unack'], 'pointer red bold');
                        $trigger_count->setHint($table_inf_unack);
                    }
                    $group_row->addItem(new CCol($trigger_count, get_severity_style($severity, $data['count_unack'])));
                    break;
                case EXTACK_OPTION_BOTH:
                    if ($data['count_unack']) {
                        $unack_count = new CSpan($data['count_unack'], 'bold red pointer');
                        $unack_count->setHint($table_inf_unack);
                        $unack_count = new CSpan(array($unack_count, SPACE . S_OF . SPACE));
                    } else {
                        $unack_count = null;
                    }
                    $trigger_count = new CSpan($data['count'], 'pointer');
                    if ($data['count']) {
                        $trigger_count->setHint($table_inf);
                    }
                    $group_row->addItem(new CCol(array($unack_count, $trigger_count), get_severity_style($severity, $data['count'])));
                    break;
            }
        }
        $table->addRow($group_row);
    }
    $table->setFooter(new CCol(S_UPDATED . ': ' . zbx_date2str(S_BLOCKS_SYSTEM_SUMMARY_TIME_FORMAT)));
    return $table;
}