/** * Process screen. * * @return CDiv (screen inside container) */ public function get() { $options = array('monitored' => true, 'value' => array(TRIGGER_VALUE_TRUE, TRIGGER_VALUE_FALSE), 'triggerLimit' => $this->screenitem['elements'], 'eventLimit' => $this->screenitem['elements']); $item = new CTableInfo(_('No events found.')); $item->setHeader(array(_('Time'), is_show_all_nodes() ? _('Node') : null, _('Host'), _('Description'), _('Value'), _('Severity'))); $events = getLastEvents($options); foreach ($events as $event) { $trigger = $event['trigger']; $host = $event['host']; $statusSpan = new CSpan(trigger_value2str($event['value'])); // add colors and blinking to span depending on configuration and trigger parameters addTriggerValueStyle($statusSpan, $event['value'], $event['clock'], $event['acknowledged']); $item->addRow(array(zbx_date2str(_('d M Y H:i:s'), $event['clock']), get_node_name_by_elid($event['objectid']), $host['name'], new CLink($trigger['description'], 'tr_events.php?triggerid=' . $event['objectid'] . '&eventid=' . $event['eventid']), $statusSpan, getSeverityCell($trigger['priority']))); } return $this->getOutput($item); }
function make_popup_eventlist($triggerId, $eventId) { $config = select_config(); $table = new CTableInfo(); $table->setAttribute('style', 'width: 400px;'); // if acknowledges are turned on, we show 'ack' column if ($config['event_ack_enable']) { $table->setHeader(array(_('Time'), _('Status'), _('Duration'), _('Age'), _('Ack'))); } else { $table->setHeader(array(_('Time'), _('Status'), _('Duration'), _('Age'))); } $events = API::Event()->get(array('source' => EVENT_SOURCE_TRIGGERS, 'object' => EVENT_OBJECT_TRIGGER, 'output' => API_OUTPUT_EXTEND, 'objectids' => $triggerId, 'eventid_till' => $eventId, 'select_acknowledges' => API_OUTPUT_COUNT, 'sortfield' => array('clock', 'eventid'), 'sortorder' => ZBX_SORT_DOWN, 'limit' => ZBX_WIDGET_ROWS)); $lclock = time(); foreach ($events as $event) { $duration = zbx_date2age($lclock, $event['clock']); $lclock = $event['clock']; $eventStatusSpan = new CSpan(trigger_value2str($event['value'])); // add colors and blinking to span depending on configuration and trigger parameters addTriggerValueStyle($eventStatusSpan, $event['value'], $event['clock'], $event['acknowledged']); $table->addRow(array(zbx_date2str(_('d M Y H:i:s'), $event['clock']), $eventStatusSpan, $duration, zbx_date2age($event['clock']), getEventAckState($event, false, false))); } return $table; }
/** * Create table with trigger description and events. * * @param array $trigger An array of trigger data. * @param string $trigger['triggerid'] Trigger ID to select events. * @param string $trigger['description'] Trigger description. * @param string $trigger['url'] Trigger URL. * @param string $trigger['lastEvent']['eventid'] Last event ID * @param string $backurl URL to return to. * * @return CDiv */ function make_popup_eventlist($trigger, $backurl) { // Show trigger description and URL. $div = new CDiv(); if ($trigger['comments'] !== '') { $div->addItem((new CDiv())->addItem(zbx_str2links($trigger['comments']))->addClass(ZBX_STYLE_OVERLAY_DESCR)); } if ($trigger['url'] !== '') { $div->addItem((new CDiv())->addItem(new CLink($trigger['url'], $trigger['url']))->addClass(ZBX_STYLE_OVERLAY_DESCR_URL)); } // Select and show events. $config = select_config(); $table = new CTableInfo(); // If acknowledges are turned on, we show 'ack' column. if ($config['event_ack_enable']) { $table->setHeader([_('Time'), _('Status'), _('Duration'), _('Age'), _('Ack')]); } else { $table->setHeader([_('Time'), _('Status'), _('Duration'), _('Age')]); } if ($trigger['lastEvent']) { $events = API::Event()->get(['source' => EVENT_SOURCE_TRIGGERS, 'object' => EVENT_OBJECT_TRIGGER, 'output' => API_OUTPUT_EXTEND, 'objectids' => [$trigger['triggerid']], 'eventid_till' => $trigger['lastEvent']['eventid'], 'select_acknowledges' => API_OUTPUT_COUNT, 'sortfield' => ['clock', 'eventid'], 'sortorder' => ZBX_SORT_DOWN, 'limit' => ZBX_WIDGET_ROWS]); $lclock = time(); foreach ($events as $event) { $duration = zbx_date2age($lclock, $event['clock']); $lclock = $event['clock']; $eventStatusSpan = new CSpan(trigger_value2str($event['value'])); // add colors and blinking to span depending on configuration and trigger parameters addTriggerValueStyle($eventStatusSpan, $event['value'], $event['clock'], $event['acknowledged']); $table->addRow([zbx_date2str(DATE_TIME_FORMAT_SECONDS, $event['clock']), $eventStatusSpan, $duration, zbx_date2age($event['clock']), $config['event_ack_enable'] ? getEventAckState($event, $backurl) : null]); } } $div->addItem($table); return $div; }
foreach ($events as $event) { $trigger = $triggers[$event['objectid']]; $host = reset($trigger['hosts']); $host = $hosts[$host['hostid']]; $description = CMacrosResolverHelper::resolveEventDescription(zbx_array_merge($trigger, ['clock' => $event['clock'], 'ns' => $event['ns']])); // duration $event['duration'] = ($nextEvent = get_next_event($event, $events)) ? zbx_date2age($event['clock'], $nextEvent['clock']) : zbx_date2age($event['clock']); // action $action = isset($actions[$event['eventid']]) ? $actions[$event['eventid']] : ''; if ($csvExport) { $csvRows[] = [zbx_date2str(DATE_TIME_FORMAT_SECONDS, $event['clock']), $pageFilter->hostid == 0 ? $host['name'] : null, $description, trigger_value2str($event['value']), getSeverityName($trigger['priority'], $config), $event['duration'], $config['event_ack_enable'] ? $event['acknowledges'] ? _('Yes') : _('No') : null, strip_tags((string) $action)]; } else { $triggerDescription = (new CSpan($description))->addClass(ZBX_STYLE_LINK_ACTION)->setMenuPopup(CMenuPopupHelper::getTrigger($trigger, null, $event['clock'])); // add colors and blinking to span depending on configuration and trigger parameters $statusSpan = new CSpan(trigger_value2str($event['value'])); addTriggerValueStyle($statusSpan, $event['value'], $event['clock'], $event['acknowledged']); // host JS menu link $hostName = null; if ($pageFilter->hostid == 0) { $hostName = (new CSpan($host['name']))->addClass(ZBX_STYLE_LINK_ACTION)->setMenuPopup(CMenuPopupHelper::getHost($host, $scripts[$host['hostid']])); } $table->addRow([(new CLink(zbx_date2str(DATE_TIME_FORMAT_SECONDS, $event['clock']), 'tr_events.php?triggerid=' . $event['objectid'] . '&eventid=' . $event['eventid']))->addClass('action'), $hostName, $triggerDescription, $statusSpan, getSeverityCell($trigger['priority'], $config, null, !$event['value']), $event['duration'], $config['event_ack_enable'] ? getEventAckState($event, $page['file']) : null, (new CCol($action))->addClass(ZBX_STYLE_NOWRAP)]); } } } else { if (!$csvExport) { $events = []; $url = (new CUrl('events.php'))->setArgument('fullscreen', getRequest('fullscreen'))->setArgument('groupid', $pageFilter->groupid)->setArgument('hostid', $pageFilter->hostid); $paging = getPagingLine($events, ZBX_SORT_UP, $url); } }
$comments = new CLink(zbx_empty($trigger['comments']) ? _('Add') : _('Show'), 'tr_comments.php?triggerid=' . $trigger['triggerid']); } else { $comments = zbx_empty($trigger['comments']) ? new CSpan('') : new CLink(_('Show'), 'tr_comments.php?triggerid=' . $trigger['triggerid']); } $triggerTable->addRow([$openOrCloseDiv, $ack_checkbox, getSeverityCell($trigger['priority'], $config, null, !$trigger['value']), $statusSpan, $trigger['state'] == TRIGGER_STATE_UNKNOWN ? makeUnknownIcon($trigger['error']) : '', $trigger['lastchange'] == 0 ? _('Never') : new CLink(zbx_date2str(DATE_TIME_FORMAT_SECONDS, $trigger['lastchange']), 'events.php?filter_set=1&triggerid=' . $trigger['triggerid'] . '&source=' . EVENT_SOURCE_TRIGGERS . '&stime=' . date(TIMESTAMP_FORMAT, $trigger['lastchange']) . '&period=' . ZBX_PERIOD_DEFAULT), $trigger['lastchange'] == 0 ? '' : zbx_date2age($trigger['lastchange']), $showEvents == EVENTS_OPTION_ALL || $showEvents == EVENTS_OPTION_NOT_ACK ? '' : null, $ackColumn, $hostList, $description, $comments]); if ($showEvents == EVENTS_OPTION_ALL || $showEvents == EVENTS_OPTION_NOT_ACK) { $next_event_clock = time(); foreach (array_slice($trigger['events'], 0, $config['event_show_max']) as $enum => $event) { if ($showEvents == EVENTS_OPTION_NOT_ACK) { if ($event['acknowledged'] || $event['value'] != TRIGGER_VALUE_TRUE) { continue; } } $eventStatusSpan = new CSpan(trigger_value2str($event['value'])); // add colors and blinking to span depending on configuration and trigger parameters addTriggerValueStyle($eventStatusSpan, $event['value'], $event['clock'], $config['event_ack_enable'] && $event['acknowledged']); $clock = new CLink(zbx_date2str(DATE_TIME_FORMAT_SECONDS, $event['clock']), 'tr_events.php?triggerid=' . $trigger['triggerid'] . '&eventid=' . $event['eventid']); if ($enum != 0) { $next_event_clock = $trigger['events'][$enum - 1]['clock']; } $triggerTable->addRow((new CRow([(new CCol())->setColSpan($config['event_ack_enable'] ? 3 : 2), (new CCol($eventStatusSpan))->setColSpan(2), $clock, zbx_date2age($event['clock']), zbx_date2age($next_event_clock, $event['clock']), $config['event_ack_enable'] ? getEventAckState($event, $page['file']) : null, (new CCol())->setColSpan(3)]))->setAttribute('data-parentid', $trigger['triggerid'])->addStyle('display: none;')); } } } /* * Go buttons */ $footer = null; if ($config['event_ack_enable']) { $footer = new CActionButtonList('action', 'eventids', ['acknowledge.edit' => ['name' => _('Bulk acknowledge')]]); }