diff options
Diffstat (limited to 'frontends/php/events.php')
-rw-r--r-- | frontends/php/events.php | 130 |
1 files changed, 96 insertions, 34 deletions
diff --git a/frontends/php/events.php b/frontends/php/events.php index 1cd78aacb9e..6fdbd1384cd 100644 --- a/frontends/php/events.php +++ b/frontends/php/events.php @@ -64,10 +64,6 @@ $fields = array( 'hostid'=> array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, null), 'triggerid'=> array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, null), 'period'=> array(T_ZBX_INT, O_OPT, null, null, null), - 'dec'=> array(T_ZBX_INT, O_OPT, null, null, null), - 'inc'=> array(T_ZBX_INT, O_OPT, null, null, null), - 'left'=> array(T_ZBX_INT, O_OPT, null, null, null), - 'right'=> array(T_ZBX_INT, O_OPT, null, null, null), 'stime'=> array(T_ZBX_STR, O_OPT, null, null, null), 'load'=> array(T_ZBX_STR, O_OPT, P_SYS, NULL, null), 'fullscreen'=> array(T_ZBX_INT, O_OPT, P_SYS, IN('0,1'), null), @@ -303,7 +299,7 @@ else { $frmForm->addItem(new CSubmit('csv_export', _('Export to CSV'))); $eventsWidget->addPageHeader( - _('HISTORY OF EVENTS').SPACE.'['.zbx_date2str(_('d M Y H:i:s')).']', + _('HISTORY OF EVENTS').SPACE.'['.zbx_date2str(DATE_TIME_FORMAT_SECONDS).']', array( $frmForm, SPACE, @@ -319,7 +315,7 @@ else { // add host and group filters to the form if ($source == EVENT_SOURCE_TRIGGERS) { if (getRequest('triggerid') != 0) { - $r_form->addVar('triggerid', get_request('triggerid')); + $r_form->addVar('triggerid', getRequest('triggerid')); } $r_form->addItem(array( @@ -346,6 +342,7 @@ else { if ($source == EVENT_SOURCE_TRIGGERS) { $filterForm = new CFormTable(null, null, 'get'); + $filterForm->setTableClass('formtable old-filter'); $filterForm->setAttribute('name', 'zbx_filter'); $filterForm->setAttribute('id', 'zbx_filter'); $filterForm->addVar('triggerid', $triggerId); @@ -377,7 +374,7 @@ else { $filterForm->addRow(new CRow(array( new CCol(_('Trigger'), 'form_row_l'), new CCol(array( - new CTextBox('trigger', $trigger, 96, 'yes'), + new CTextBox('trigger', $trigger, 96, true), new CButton('btn1', _('Select'), 'return PopUp("popup.php?'. 'dstfrm='.$filterForm->getName(). @@ -601,7 +598,7 @@ else { if ($csvExport) { $csvRows[] = array( - zbx_date2str(EVENTS_DISCOVERY_TIME_FORMAT, $event_data['clock']), + zbx_date2str(DATE_TIME_FORMAT_SECONDS, $event_data['clock']), $event_data['object_data']['ip'], $event_data['object_data']['dns'], $event_data['description'], @@ -610,7 +607,7 @@ else { } else { $table->addRow(array( - zbx_date2str(EVENTS_DISCOVERY_TIME_FORMAT, $event_data['clock']), + zbx_date2str(DATE_TIME_FORMAT_SECONDS, $event_data['clock']), $event_data['object_data']['ip'], zbx_empty($event_data['object_data']['dns']) ? SPACE : $event_data['object_data']['dns'], $event_data['description'], @@ -623,39 +620,104 @@ else { // source not discovery i.e. trigger else { if ($csvExport || $pageFilter->hostsSelected) { - $options = array( + $knownTriggerIds = array(); + $validTriggerIds = array(); + + $triggerOptions = array( 'output' => array('triggerid'), + 'preservekeys' => true, 'monitored' => true ); - if ($triggerId) { - $options['triggerids'] = $triggerId; - } - else { - if (getRequest('hostid', 0) > 0) { - $options['hostids'] = getRequest('hostid'); - } - elseif (getRequest('groupid') > 0) { - $options['groupids'] = getRequest('groupid'); - } - } - - $triggers = API::Trigger()->get($options); + $allEventsSliceLimit = $config['search_limit']; - // query event with short data - $events = API::Event()->get(array( + $eventOptions = array( 'source' => EVENT_SOURCE_TRIGGERS, 'object' => EVENT_OBJECT_TRIGGER, - 'objectids' => zbx_objectValues($triggers, 'triggerid'), 'time_from' => $from, 'time_till' => $till, - 'output' => array('eventid'), + 'output' => array('eventid', 'objectid'), 'sortfield' => array('clock', 'eventid'), 'sortorder' => ZBX_SORT_DOWN, - 'limit' => $config['search_limit'] + 1 - )); + 'limit' => $allEventsSliceLimit + 1 + ); + + if (getRequest('triggerid')) { + $filterTriggerIds = array(getRequest('triggerid')); + $knownTriggerIds = array_combine($filterTriggerIds, $filterTriggerIds); + $validTriggerIds = $knownTriggerIds; + + $eventOptions['objectids'] = $filterTriggerIds; + } + elseif ($pageFilter->hostid > 0) { + $hostTriggers = API::Trigger()->get(array( + 'output' => array('triggerid'), + 'hostids' => $pageFilter->hostid, + 'monitored' => true, + 'preservekeys' => true + )); + $filterTriggerIds = array_map('strval', array_keys($hostTriggers)); + $knownTriggerIds = array_combine($filterTriggerIds, $filterTriggerIds); + $validTriggerIds = $knownTriggerIds; + + $eventOptions['hostids'] = $pageFilter->hostid; + $eventOptions['objectids'] = $validTriggerIds; + } + elseif ($pageFilter->groupid > 0) { + $eventOptions['groupids'] = $pageFilter->groupid; + + $triggerOptions['groupids'] = $pageFilter->groupid; + } + + $events = array(); + + while (true) { + $allEventsSlice = API::Event()->get($eventOptions); + + $triggerIdsFromSlice = array_keys(array_flip(zbx_objectValues($allEventsSlice, 'objectid'))); + + $unknownTriggerIds = array_diff($triggerIdsFromSlice, $knownTriggerIds); + + if ($unknownTriggerIds) { + $triggerOptions['triggerids'] = $unknownTriggerIds; + $validTriggersFromSlice = API::Trigger()->get($triggerOptions); + + foreach ($validTriggersFromSlice as $trigger) { + $validTriggerIds[$trigger['triggerid']] = $trigger['triggerid']; + } + + foreach ($unknownTriggerIds as $id) { + $id = strval($id); + $knownTriggerIds[$id] = $id; + } + } + + foreach ($allEventsSlice as $event) { + if (isset($validTriggerIds[$event['objectid']])) { + $events[] = array('eventid' => $event['eventid']); + } + } + + // break loop when either enough events have been retrieved, or last slice was not full + if (count($events) >= $config['search_limit'] || count($allEventsSlice) <= $allEventsSliceLimit) { + break; + } + + /* + * Because events in slices are sorted descending by eventid (i.e. bigger eventid), + * first event in next slice must have eventid that is previous to last eventid in current slice. + */ + $lastEvent = end($allEventsSlice); + $eventOptions['eventid_till'] = $lastEvent['eventid'] - 1; + } + + /* + * At this point it is possible that more than $config['search_limit'] events are selected, + * therefore at most only first $config['search_limit'] + 1 events will be used for pagination. + */ + $events = array_slice($events, 0, $config['search_limit'] + 1); - // get pagging + // get paging $paging = getPagingLine($events); // query event with extend data @@ -676,7 +738,7 @@ else { $triggers = API::Trigger()->get(array( 'triggerids' => zbx_objectValues($events, 'objectid'), - 'selectHosts' => array('hostid'), + 'selectHosts' => array('hostid', 'status'), 'selectItems' => array('itemid', 'hostid', 'name', 'key_', 'value_type'), 'output' => array('description', 'expression', 'priority', 'flags', 'url') )); @@ -722,7 +784,7 @@ else { 'params' => array( 'itemid' => $item['itemid'], 'action' => in_array($item['value_type'], array(ITEM_VALUE_TYPE_FLOAT, ITEM_VALUE_TYPE_UINT64)) - ? 'showgraph' : 'showvalues' + ? HISTORY_GRAPH : HISTORY_VALUES ) ); } @@ -742,7 +804,7 @@ else { if ($csvExport) { $csvRows[] = array( - zbx_date2str(EVENTS_ACTION_TIME_FORMAT, $event['clock']), + zbx_date2str(DATE_TIME_FORMAT_SECONDS, $event['clock']), (getRequest('hostid', 0) == 0) ? $host['name'] : null, $description, trigger_value2str($event['value']), @@ -780,7 +842,7 @@ else { } $table->addRow(array( - new CLink(zbx_date2str(EVENTS_ACTION_TIME_FORMAT, $event['clock']), + new CLink(zbx_date2str(DATE_TIME_FORMAT_SECONDS, $event['clock']), 'tr_events.php?triggerid='.$event['objectid'].'&eventid='.$event['eventid'], 'action' ), |