if ($host['status'] == HOST_STATUS_MONITORED) { $monitoredHostIds[$host['hostid']] = true; } } } if ($monitoredHostIds) { $monitoredHosts = API::Host()->get(array('output' => array('hostid'), 'selectGroups' => array('groupid'), 'hostids' => array_keys($monitoredHostIds), 'preservekeys' => true)); } foreach ($triggers as $trigger) { foreach ($trigger['hosts'] as $host) { if ($host['status'] == HOST_STATUS_MONITORED) { // Pass a monitored 'hostid' and corresponding first 'groupid' to menu pop-up "Events" link. $trigger['hostid'] = $host['hostid']; $trigger['groupid'] = $monitoredHosts[$trigger['hostid']]['groups'][0]['groupid']; break; } else { // Unmonitored will have disabled "Events" link and there is no 'groupid' or 'hostid'. $trigger['hostid'] = 0; $trigger['groupid'] = 0; } } $hostId = $trigger['hosts'][0]['hostid']; $hostName = new CSpan($trigger['hosts'][0]['name'], 'link_menu menu-host' . ($hosts[$hostId]['status'] == HOST_STATUS_NOT_MONITORED ? ' not-monitored' : '')); $hostName->setMenuPopup(CMenuPopupHelper::getHost($hosts[$hostId], $scripts[$hostId])); $triggerDescription = new CSpan($trigger['description'], 'link_menu'); $triggerDescription->setMenuPopup(CMenuPopupHelper::getTrigger($trigger)); $table->addRow(array($hostName, $triggerDescription, getSeverityCell($trigger['priority']), $trigger['cnt_event'])); } $rprt_wdgt->addItem($table); $rprt_wdgt->show(); require_once dirname(__FILE__) . '/include/page_footer.php';
/** * Create DIV with latest problem triggers. * * If no sortfield and sortorder are defined, the sort indicater in the column name will not be displayed. * * @param array $filter['groupids'] * @param array $filter['hostids'] * @param array $filter['maintenance'] * @param int $filter['extAck'] * @param int $filter['severity'] * @param int $filter['limit'] * @param string $filter['sortfield'] * @param string $filter['sortorder'] * @param string $backurl * * @return CDiv */ function make_latest_issues(array $filter = [], $backurl) { // hide the sort indicator if no sortfield and sortorder are given $show_sort_indicator = isset($filter['sortfield']) || isset($filter['sortorder']); if (isset($filter['sortfield']) && $filter['sortfield'] !== 'lastchange') { $sort_field = [$filter['sortfield'], 'lastchange']; $sort_order = [$filter['sortorder'], ZBX_SORT_DOWN]; } else { $sort_field = ['lastchange']; $sort_order = [ZBX_SORT_DOWN]; } $options = ['groupids' => $filter['groupids'], 'hostids' => isset($filter['hostids']) ? $filter['hostids'] : null, 'monitored' => true, 'maintenance' => $filter['maintenance'], 'search' => $filter['trigger_name'] !== '' ? ['description' => $filter['trigger_name']] : null, 'filter' => ['priority' => $filter['severity'], 'value' => TRIGGER_VALUE_TRUE]]; $triggers = API::Trigger()->get(array_merge($options, ['output' => ['triggerid', 'expression', 'description', 'url', 'priority', 'lastchange', 'comments', 'error', 'state'], 'selectHosts' => ['hostid'], 'selectLastEvent' => ['eventid', 'acknowledged', 'objectid', 'clock', 'ns'], 'withLastEventUnacknowledged' => isset($filter['extAck']) && $filter['extAck'] == EXTACK_OPTION_UNACK ? true : null, 'skipDependent' => true, 'sortfield' => $sort_field, 'sortorder' => $sort_order, 'limit' => isset($filter['limit']) ? $filter['limit'] : DEFAULT_LATEST_ISSUES_CNT, 'preservekeys' => true, 'expandComment' => true])); $triggers = CMacrosResolverHelper::resolveTriggerUrls($triggers); // don't use withLastEventUnacknowledged and skipDependent because of performance issues $triggers_total_count = API::Trigger()->get(array_merge($options, ['countOutput' => true])); // get acknowledges $hostids = []; $eventids = []; foreach ($triggers as $trigger) { foreach ($trigger['hosts'] as $host) { $hostids[$host['hostid']] = true; } if ($trigger['lastEvent']) { $eventids[] = $trigger['lastEvent']['eventid']; } } $config = select_config(); if ($config['event_ack_enable'] && $eventids) { $event_acknowledges = API::Event()->get(['output' => ['eventid'], 'eventids' => $eventids, 'select_acknowledges' => API_OUTPUT_EXTEND, 'preservekeys' => true]); } // actions $actions = makeEventsActions($eventids); // indicator of sort field if ($show_sort_indicator) { $sort_div = (new CDiv())->addClass($filter['sortorder'] === ZBX_SORT_DOWN ? ZBX_STYLE_ARROW_DOWN : ZBX_STYLE_ARROW_UP); } $table = (new CTableInfo())->setHeader([$show_sort_indicator && $filter['sortfield'] === 'hostname' ? [_('Host'), $sort_div] : _('Host'), $show_sort_indicator && $filter['sortfield'] === 'priority' ? [_('Issue'), $sort_div] : _('Issue'), $show_sort_indicator && $filter['sortfield'] === 'lastchange' ? [_('Last change'), $sort_div] : _('Last change'), _('Age'), _('Info'), $config['event_ack_enable'] ? _('Ack') : null, _('Actions')]); $hostids = array_keys($hostids); $scripts = API::Script()->getScriptsByHosts($hostids); // get hosts $hosts = API::Host()->get(['hostids' => $hostids, 'output' => ['hostid', 'name', 'status', 'maintenance_status', 'maintenance_type', 'maintenanceid'], 'selectGraphs' => API_OUTPUT_COUNT, 'selectScreens' => API_OUTPUT_COUNT, 'preservekeys' => true]); $maintenanceids = []; foreach ($hosts as $host) { if ($host['maintenance_status'] == HOST_MAINTENANCE_STATUS_ON) { $maintenanceids[$host['maintenanceid']] = true; } } if ($maintenanceids) { $maintenances = API::Maintenance()->get(['maintenanceids' => array_keys($maintenanceids), 'output' => ['name', 'description'], 'preservekeys' => true]); } // triggers foreach ($triggers as $trigger) { $host_list = []; foreach ($trigger['hosts'] as $trigger_host) { $host = $hosts[$trigger_host['hostid']]; $host_name = (new CSpan($host['name']))->addClass(ZBX_STYLE_LINK_ACTION)->setMenuPopup(CMenuPopupHelper::getHost($host, $scripts[$host['hostid']])); if ($host['maintenance_status'] == HOST_MAINTENANCE_STATUS_ON) { $maintenance_icon = (new CSpan())->addClass(ZBX_STYLE_ICON_MAINT)->addClass(ZBX_STYLE_CURSOR_POINTER); if (array_key_exists($host['maintenanceid'], $maintenances)) { $maintenance = $maintenances[$host['maintenanceid']]; $hint = $maintenance['name'] . ' [' . ($host['maintenance_type'] ? _('Maintenance without data collection') : _('Maintenance with data collection')) . ']'; if ($maintenance['description']) { $hint .= "\n" . $maintenance['description']; } $maintenance_icon->setHint($hint); } $host_name = (new CSpan([$host_name, $maintenance_icon]))->addClass(ZBX_STYLE_REL_CONTAINER); } $host_list[] = $host_name; $host_list[] = ', '; } array_pop($host_list); // unknown triggers $unknown = ''; if ($trigger['state'] == TRIGGER_STATE_UNKNOWN) { $unknown = makeUnknownIcon($trigger['error']); } // trigger has events if ($trigger['lastEvent']) { // description $description = CMacrosResolverHelper::resolveEventDescription(zbx_array_merge($trigger, ['clock' => $trigger['lastEvent']['clock'], 'ns' => $trigger['lastEvent']['ns']])); } else { // description $description = CMacrosResolverHelper::resolveEventDescription(zbx_array_merge($trigger, ['clock' => $trigger['lastchange'], 'ns' => '999999999'])); } if ($config['event_ack_enable']) { if ($trigger['lastEvent']) { $trigger['lastEvent']['acknowledges'] = $event_acknowledges[$trigger['lastEvent']['eventid']]['acknowledges']; $ack = getEventAckState($trigger['lastEvent'], $backurl); } else { $ack = (new CSpan(_('No events')))->addClass(ZBX_STYLE_GREY); } } else { $ack = null; } // description if ($trigger['lastEvent'] || $trigger['comments'] !== '' || $trigger['url'] !== '') { $description = (new CSpan($description))->setHint(make_popup_eventlist($trigger, $backurl), '', true, 'max-width: 500px')->addClass(ZBX_STYLE_LINK_ACTION); } $description = (new CCol($description))->addClass(getSeverityStyle($trigger['priority'])); // clock $clock = new CLink(zbx_date2str(DATE_TIME_FORMAT_SECONDS, $trigger['lastchange']), 'events.php?filter_set=1&triggerid=' . $trigger['triggerid'] . '&period=' . ZBX_PERIOD_DEFAULT . '&stime=' . date(TIMESTAMP_FORMAT, $trigger['lastchange'])); // actions $action_hint = $trigger['lastEvent'] && isset($actions[$trigger['lastEvent']['eventid']]) ? $actions[$trigger['lastEvent']['eventid']] : SPACE; $table->addRow([new CCol($host_list), $description, $clock, zbx_date2age($trigger['lastchange']), $unknown, $ack, (new CCol($action_hint))->addClass(ZBX_STYLE_NOWRAP)]); } // initialize blinking zbx_add_post_js('jqBlink.blink();'); $info = _n('%1$d of %2$d issue is shown', '%1$d of %2$d issues are shown', count($triggers), $triggers_total_count); return [$table, $info]; }
$severity_columns[$severity % 2][] = new CLabel([(new CCheckBox('severities[' . $severity . ']'))->setChecked(in_array($severity, $this->data['filter']['severities'])), getSeverityName($severity, $this->data['config'])], 'severities[' . $severity . ']'); } $filterColumn1->addRow(_('Severity'), (new CTable())->addRow($severity_columns[0])->addRow($severity_columns[1])); $filterForm->addColumn($filterColumn1)->addColumn($filterColumn2); $topTriggers->addItem($filterForm); // table $table = (new CTableInfo())->setHeader([_('Host'), _('Trigger'), _('Severity'), _('Number of status changes')]); foreach ($this->data['triggers'] as $trigger) { foreach ($trigger['hosts'] as $host) { if ($host['status'] == HOST_STATUS_MONITORED) { // Pass a monitored 'hostid' and corresponding first 'groupid' to menu pop-up "Events" link. $trigger['hostid'] = $host['hostid']; $trigger['groupid'] = $data['monitored_hosts'][$trigger['hostid']]['groups'][0]['groupid']; break; } else { // Unmonitored will have disabled "Events" link and there is no 'groupid' or 'hostid'. $trigger['hostid'] = 0; $trigger['groupid'] = 0; } } $hostId = $trigger['hosts'][0]['hostid']; $hostName = (new CSpan($trigger['hosts'][0]['name']))->addClass(ZBX_STYLE_LINK_ACTION); if ($this->data['hosts'][$hostId]['status'] == HOST_STATUS_NOT_MONITORED) { $hostName->addClass(ZBX_STYLE_RED); } $hostName->setMenuPopup(CMenuPopupHelper::getHost($this->data['hosts'][$hostId], $this->data['scripts'][$hostId])); $triggerDescription = (new CSpan($trigger['description']))->addClass(ZBX_STYLE_LINK_ACTION)->setMenuPopup(CMenuPopupHelper::getTrigger($trigger)); $table->addRow([$hostName, $triggerDescription, getSeverityCell($trigger['priority'], $this->data['config']), $trigger['cnt_event']]); } $topTriggers->addItem($table); return $topTriggers;
** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. ** ** You should have received a copy of the GNU General Public License ** along with this program; if not, write to the Free Software ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. **/ $hostInventoryWidget = new CWidget(null, 'inventory-host'); $hostInventoryWidget->addPageHeader(_('HOST INVENTORY'), SPACE); /* * Overview tab */ $overviewFormList = new CFormList(); $hostSpan = new CSpan($this->data['host']['host'], 'link_menu menu-host'); $hostSpan->setMenuPopup(CMenuPopupHelper::getHost($this->data['host'], $this->data['hostScripts'][$this->data['host']['hostid']], false)); $hostName = $this->data['host']['maintenance_status'] == HOST_MAINTENANCE_STATUS_ON ? array($hostSpan, SPACE, new CDiv(null, 'icon-maintenance-inline')) : $hostSpan; $overviewFormList->addRow(_('Host name'), $hostName); if ($this->data['host']['host'] !== $this->data['host']['name']) { $overviewFormList->addRow(_('Visible name'), new CSpan($this->data['host']['name'], 'text-field')); } $agentInterfaceRows = $snmpInterfaceRows = $ipmiInterfaceRows = $jmxInterfaceRows = array(); foreach ($this->data['host']['interfaces'] as $interface) { $spanClass = $interface['main'] ? ' default_interface' : ''; switch ($interface['type']) { case INTERFACE_TYPE_AGENT: $agentInterfaceRows[] = new CRow(array(new CDiv($interface['ip'], 'ip' . $spanClass), new CDiv($interface['dns'], 'dns' . $spanClass), new CDiv($interface['useip'] == INTERFACE_USE_IP ? _('IP') : _('DNS'), 'useip' . $spanClass), new CDiv($interface['port'], 'port' . $spanClass))); break; case INTERFACE_TYPE_SNMP: $snmpInterfaceRows[] = new CRow(array(new CDiv($interface['ip'], 'ip' . $spanClass), new CDiv($interface['dns'], 'dns' . $spanClass), new CDiv($interface['useip'] == INTERFACE_USE_IP ? _('IP') : _('DNS'), 'useip' . $spanClass), new CDiv($interface['port'], 'port' . $spanClass))); break;
$host = $hosts[$dbHost['hostid']]; if (!isset($tab_rows[$hostId])) { continue; } $appRows = $tab_rows[$hostId]; $openState = CProfile::get('web.latest.toggle_other', null, $host['hostid']); $toggle = new CDiv(null, 'app-list-toggle icon-plus-9x9'); if ($openState) { $toggle->addClass('icon-minus-9x9'); } $toggle->setAttribute('data-app-id', '0_' . $host['hostid']); $toggle->setAttribute('data-open-state', $openState); $hostName = null; if (!$singleHostSelected) { $hostName = new CSpan($host['name'], 'link_menu menu-host' . ($host['status'] == HOST_STATUS_NOT_MONITORED ? ' not-monitored' : '')); $hostName->setMenuPopup(CMenuPopupHelper::getHost($host, $hostScripts[$host['hostid']])); } // add toggle row $table->addRow(array($toggle, '', $hostName, new CCol(array(bold('- ' . 'other' . ' -'), ' (' . _n('%1$s Item', '%1$s Items', $dbHost['item_cnt']) . ')'), null, $filter['showDetails'] ? 10 : 5)), 'odd_row'); // add toggle sub rows foreach ($appRows as $row) { $row->setAttribute('parent_app_id', '0_' . $host['hostid']); $row->addClass('odd_row'); if (!$openState) { $row->addClass('hidden'); } $table->addRow($row); } } $goBox = new CComboBox('graphtype', GRAPH_TYPE_STACKED, null, array(GRAPH_TYPE_STACKED => _('Display stacked graph'), GRAPH_TYPE_NORMAL => _('Display graph'))); $goBox->setAttribute('id', 'action');
** ** This program is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. ** ** You should have received a copy of the GNU General Public License ** along with this program; if not, write to the Free Software ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. **/ $hostInventoryWidget = (new CWidget())->setTitle(_('Host inventory')); /* * Overview tab */ $overviewFormList = new CFormList(); $host_name = (new CSpan($data['host']['host']))->addClass(ZBX_STYLE_LINK_ACTION)->setMenuPopup(CMenuPopupHelper::getHost($data['host'], $data['hostScripts'][$data['host']['hostid']], false)); if ($data['host']['maintenance_status'] == HOST_MAINTENANCE_STATUS_ON) { $maintenance_icon = (new CSpan())->addClass(ZBX_STYLE_ICON_MAINT)->addClass(ZBX_STYLE_CURSOR_POINTER); if (array_key_exists($data['host']['maintenanceid'], $data['maintenances'])) { $maintenance = $data['maintenances'][$data['host']['maintenanceid']]; $hint = $maintenance['name'] . ' [' . ($data['host']['maintenance_type'] ? _('Maintenance without data collection') : _('Maintenance with data collection')) . ']'; if ($maintenance['description']) { $hint .= "\n" . $maintenance['description']; } $maintenance_icon->setHint($hint); } $host_name = (new CSpan([$host_name, $maintenance_icon]))->addClass(ZBX_STYLE_REL_CONTAINER); } $overviewFormList->addRow(_('Host name'), (new CDiv($host_name))->setWidth(ZBX_TEXTAREA_BIG_WIDTH)); if ($data['host']['host'] !== $data['host']['name']) { $overviewFormList->addRow(_('Visible name'), (new CDiv($data['host']['name']))->setWidth(ZBX_TEXTAREA_BIG_WIDTH));
/** * Create DIV with latest problem triggers. * * If no sortfield and sortorder are defined, the sort indicater in the column name will not be displayed. * * @param array $filter['screenid'] * @param array $filter['groupids'] * @param array $filter['hostids'] * @param array $filter['maintenance'] * @param int $filter['extAck'] * @param int $filter['severity'] * @param int $filter['limit'] * @param string $filter['sortfield'] * @param string $filter['sortorder'] * @param string $filter['backUrl'] * * @return CDiv */ function make_latest_issues(array $filter = array()) { // hide the sort indicator if no sortfield and sortorder are given $showSortIndicator = isset($filter['sortfield']) || isset($filter['sortorder']); if (isset($filter['sortfield']) && $filter['sortfield'] !== 'lastchange') { $sortField = array($filter['sortfield'], 'lastchange'); $sortOrder = array($filter['sortorder'], ZBX_SORT_DOWN); } else { $sortField = array('lastchange'); $sortOrder = array(ZBX_SORT_DOWN); } $options = array('groupids' => $filter['groupids'], 'hostids' => isset($filter['hostids']) ? $filter['hostids'] : null, 'monitored' => true, 'maintenance' => $filter['maintenance'], 'filter' => array('priority' => $filter['severity'], 'value' => TRIGGER_VALUE_TRUE)); $triggers = API::Trigger()->get(array_merge($options, array('withLastEventUnacknowledged' => isset($filter['extAck']) && $filter['extAck'] == EXTACK_OPTION_UNACK ? true : null, 'skipDependent' => true, 'output' => array('triggerid', 'state', 'error', 'url', 'expression', 'description', 'priority', 'lastchange'), 'selectHosts' => array('hostid', 'name'), 'selectLastEvent' => array('eventid', 'acknowledged', 'objectid', 'clock', 'ns'), 'sortfield' => $sortField, 'sortorder' => $sortOrder, 'limit' => isset($filter['limit']) ? $filter['limit'] : DEFAULT_LATEST_ISSUES_CNT))); // don't use withLastEventUnacknowledged and skipDependent because of performance issues $triggersTotalCount = API::Trigger()->get(array_merge($options, array('countOutput' => true))); // get acknowledges $eventIds = array(); foreach ($triggers as $trigger) { if ($trigger['lastEvent']) { $eventIds[] = $trigger['lastEvent']['eventid']; } } if ($eventIds) { $eventAcknowledges = API::Event()->get(array('output' => array('eventid'), 'eventids' => $eventIds, 'select_acknowledges' => API_OUTPUT_EXTEND, 'preservekeys' => true)); } foreach ($triggers as $tnum => $trigger) { // if trigger is lost (broken expression) we skip it if (empty($trigger['hosts'])) { unset($triggers[$tnum]); continue; } $host = reset($trigger['hosts']); $trigger['hostid'] = $host['hostid']; $trigger['hostname'] = $host['name']; if ($trigger['lastEvent']) { $trigger['lastEvent']['acknowledges'] = isset($eventAcknowledges[$trigger['lastEvent']['eventid']]) ? $eventAcknowledges[$trigger['lastEvent']['eventid']]['acknowledges'] : null; } $triggers[$tnum] = $trigger; } $hostIds = zbx_objectValues($triggers, 'hostid'); // get hosts $hosts = API::Host()->get(array('hostids' => $hostIds, 'output' => array('hostid', 'name', 'status', 'maintenance_status', 'maintenance_type', 'maintenanceid'), 'selectGraphs' => API_OUTPUT_COUNT, 'selectScreens' => API_OUTPUT_COUNT, 'preservekeys' => true)); // actions $actions = getEventActionsStatHints($eventIds); // ack params $ackParams = isset($filter['screenid']) ? array('screenid' => $filter['screenid']) : array(); $config = select_config(); // indicator of sort field if ($showSortIndicator) { $sortDiv = new CDiv(SPACE, $filter['sortorder'] === ZBX_SORT_DOWN ? 'icon_sortdown default_cursor' : 'icon_sortup default_cursor'); $sortDiv->addStyle('float: left'); $hostHeaderDiv = new CDiv(array(_('Host'), SPACE)); $hostHeaderDiv->addStyle('float: left'); $issueHeaderDiv = new CDiv(array(_('Issue'), SPACE)); $issueHeaderDiv->addStyle('float: left'); $lastChangeHeaderDiv = new CDiv(array(_('Time'), SPACE)); $lastChangeHeaderDiv->addStyle('float: left'); } $table = new CTableInfo(_('No events found.')); $table->setHeader(array($showSortIndicator && $filter['sortfield'] === 'hostname' ? array($hostHeaderDiv, $sortDiv) : _('Host'), $showSortIndicator && $filter['sortfield'] === 'priority' ? array($issueHeaderDiv, $sortDiv) : _('Issue'), $showSortIndicator && $filter['sortfield'] === 'lastchange' ? array($lastChangeHeaderDiv, $sortDiv) : _('Last change'), _('Age'), _('Info'), $config['event_ack_enable'] ? _('Ack') : null, _('Actions'))); $scripts = API::Script()->getScriptsByHosts($hostIds); // triggers foreach ($triggers as $trigger) { $host = $hosts[$trigger['hostid']]; $hostName = new CSpan($host['name'], 'link_menu'); $hostName->setMenuPopup(CMenuPopupHelper::getHost($host, $scripts[$host['hostid']])); // add maintenance icon with hint if host is in maintenance $maintenanceIcon = null; if ($host['maintenance_status']) { $maintenanceIcon = new CDiv(null, 'icon-maintenance-abs'); // get maintenance $maintenances = API::Maintenance()->get(array('maintenanceids' => $host['maintenanceid'], 'output' => API_OUTPUT_EXTEND, 'limit' => 1)); if ($maintenance = reset($maintenances)) { $hint = $maintenance['name'] . ' [' . ($host['maintenance_type'] ? _('Maintenance without data collection') : _('Maintenance with data collection')) . ']'; if (isset($maintenance['description'])) { // double quotes mandatory $hint .= "\n" . $maintenance['description']; } $maintenanceIcon->setHint($hint); $maintenanceIcon->addClass('pointer'); } $hostName->addClass('left-to-icon-maintenance-abs'); } $hostDiv = new CDiv(array($hostName, $maintenanceIcon), 'maintenance-abs-cont'); // unknown triggers $unknown = SPACE; if ($trigger['state'] == TRIGGER_STATE_UNKNOWN) { $unknown = new CDiv(SPACE, 'status_icon iconunknown'); $unknown->setHint($trigger['error'], 'on'); } // trigger has events if ($trigger['lastEvent']) { // description $description = CMacrosResolverHelper::resolveEventDescription(zbx_array_merge($trigger, array('clock' => $trigger['lastEvent']['clock'], 'ns' => $trigger['lastEvent']['ns']))); // ack $ack = getEventAckState($trigger['lastEvent'], empty($filter['backUrl']) ? true : $filter['backUrl'], true, $ackParams); } else { // description $description = CMacrosResolverHelper::resolveEventDescription(zbx_array_merge($trigger, array('clock' => $trigger['lastchange'], 'ns' => '999999999'))); // ack $ack = new CSpan(_('No events'), 'unknown'); } // description if (!zbx_empty($trigger['url'])) { $description = new CLink($description, resolveTriggerUrl($trigger), null, null, true); } else { $description = new CSpan($description, 'pointer'); } $description = new CCol($description, getSeverityStyle($trigger['priority'])); if ($trigger['lastEvent']) { $description->setHint(make_popup_eventlist($trigger['triggerid'], $trigger['lastEvent']['eventid']), '', false); } // clock $clock = new CLink(zbx_date2str(DATE_TIME_FORMAT_SECONDS, $trigger['lastchange']), 'events.php?filter_set=1&triggerid=' . $trigger['triggerid'] . '&source=' . EVENT_SOURCE_TRIGGERS . '&show_unknown=1&hostid=' . $trigger['hostid'] . '&stime=' . date(TIMESTAMP_FORMAT, $trigger['lastchange']) . '&period=' . ZBX_PERIOD_DEFAULT); // actions $actionHint = $trigger['lastEvent'] && isset($actions[$trigger['lastEvent']['eventid']]) ? $actions[$trigger['lastEvent']['eventid']] : SPACE; $table->addRow(array($hostDiv, $description, $clock, zbx_date2age($trigger['lastchange']), $unknown, $ack, $actionHint)); } // initialize blinking zbx_add_post_js('jqBlink.blink();'); $script = new CJsScript(get_js('jQuery("#' . WIDGET_LAST_ISSUES . '_footer").html("' . _s('Updated: %s', zbx_date2str(TIME_FORMAT_SECONDS)) . '");')); $infoDiv = new CDiv(_n('%1$d of %2$d issue is shown', '%1$d of %2$d issues are shown', count($triggers), $triggersTotalCount)); $infoDiv->addStyle('text-align: right; padding-right: 3px;'); return new CDiv(array($table, $infoDiv, $script)); }
$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); } } } if (!$csvExport) { $table = [$table, $paging]; }
/** * Retrieve overview table object for items. * * @param array $hostIds * @param array|null $applicationIds IDs of applications to filter items by * @param int $viewMode * * @return CTableInfo */ function getItemsDataOverview($hostIds, array $applicationIds = null, $viewMode) { $sqlFrom = ''; $sqlWhere = ''; if ($applicationIds !== null) { $sqlFrom = 'items_applications ia,'; $sqlWhere = ' AND i.itemid=ia.itemid AND ' . dbConditionInt('ia.applicationid', $applicationIds); } $dbItems = DBfetchArray(DBselect('SELECT DISTINCT h.hostid,h.name AS hostname,i.itemid,i.key_,i.value_type,i.units,' . 'i.name,t.priority,i.valuemapid,t.value AS tr_value,t.triggerid' . ' FROM hosts h,' . $sqlFrom . 'items i' . ' LEFT JOIN functions f ON f.itemid=i.itemid' . ' LEFT JOIN triggers t ON t.triggerid=f.triggerid AND t.status=' . TRIGGER_STATUS_ENABLED . ' WHERE ' . dbConditionInt('h.hostid', $hostIds) . ' AND h.status=' . HOST_STATUS_MONITORED . ' AND h.hostid=i.hostid' . ' AND i.status=' . ITEM_STATUS_ACTIVE . ' AND ' . dbConditionInt('i.flags', array(ZBX_FLAG_DISCOVERY_NORMAL, ZBX_FLAG_DISCOVERY_CREATED)) . $sqlWhere)); $dbItems = CMacrosResolverHelper::resolveItemNames($dbItems); CArrayHelper::sort($dbItems, array(array('field' => 'name_expanded', 'order' => ZBX_SORT_UP), array('field' => 'itemid', 'order' => ZBX_SORT_UP))); // fetch latest values $history = Manager::History()->getLast(zbx_toHash($dbItems, 'itemid'), 1, ZBX_HISTORY_PERIOD); // fetch data for the host JS menu $hosts = API::Host()->get(array('output' => array('name', 'hostid', 'status'), 'monitored_hosts' => true, 'hostids' => $hostIds, 'with_monitored_items' => true, 'preservekeys' => true, 'selectGraphs' => API_OUTPUT_COUNT, 'selectScreens' => $viewMode == STYLE_LEFT ? API_OUTPUT_COUNT : null)); $items = array(); foreach ($dbItems as $dbItem) { $name = $dbItem['name_expanded']; $hostNames[$dbItem['hostid']] = $dbItem['hostname']; // a little tricky check for attempt to overwrite active trigger (value=1) with // inactive or active trigger with lower priority. if (!isset($items[$name][$dbItem['hostname']]) || ($items[$name][$dbItem['hostname']]['tr_value'] == TRIGGER_VALUE_FALSE && $dbItem['tr_value'] == TRIGGER_VALUE_TRUE || ($items[$name][$dbItem['hostname']]['tr_value'] == TRIGGER_VALUE_FALSE || $dbItem['tr_value'] == TRIGGER_VALUE_TRUE) && $dbItem['priority'] > $items[$name][$dbItem['hostname']]['severity'])) { $items[$name][$dbItem['hostname']] = array('itemid' => $dbItem['itemid'], 'value_type' => $dbItem['value_type'], 'value' => isset($history[$dbItem['itemid']]) ? $history[$dbItem['itemid']][0]['value'] : null, 'units' => $dbItem['units'], 'name' => $name, 'valuemapid' => $dbItem['valuemapid'], 'severity' => $dbItem['priority'], 'tr_value' => $dbItem['tr_value'], 'triggerid' => $dbItem['triggerid']); } } $table = new CTableInfo(_('No items found.')); if (empty($hostNames)) { return $table; } $table->makeVerticalRotation(); order_result($hostNames); if ($viewMode == STYLE_TOP) { $header = array(new CCol(_('Items'), 'center')); foreach ($hostNames as $hostName) { $header[] = new CCol($hostName, 'vertical_rotation'); } $table->setHeader($header, 'vertical_header'); foreach ($items as $descr => $ithosts) { $tableRow = array(nbsp($descr)); foreach ($hostNames as $hostName) { $tableRow = getItemDataOverviewCells($tableRow, $ithosts, $hostName); } $table->addRow($tableRow); } } else { $scripts = API::Script()->getScriptsByHosts(zbx_objectValues($hosts, 'hostid')); $header = array(new CCol(_('Hosts'), 'center')); foreach ($items as $descr => $ithosts) { $header[] = new CCol($descr, 'vertical_rotation'); } $table->setHeader($header, 'vertical_header'); foreach ($hostNames as $hostId => $hostName) { $host = $hosts[$hostId]; $name = new CSpan($host['name'], 'link_menu'); $name->setMenuPopup(CMenuPopupHelper::getHost($host, $scripts[$hostId])); $tableRow = array(new CCol($name)); foreach ($items as $ithosts) { $tableRow = getItemDataOverviewCells($tableRow, $ithosts, $hostName); } $table->addRow($tableRow); } } return $table; }
function make_trigger_details($trigger) { $hostNames = array(); $hostIds = zbx_objectValues($trigger['hosts'], 'hostid'); $hosts = API::Host()->get(array('output' => array('name', 'hostid', 'status'), 'hostids' => $hostIds, 'selectScreens' => API_OUTPUT_COUNT, 'selectGraphs' => API_OUTPUT_COUNT)); if (count($hosts) > 1) { order_result($hosts, 'name', ZBX_SORT_UP); } $scripts = API::Script()->getScriptsByHosts($hostIds); foreach ($hosts as $host) { $hostName = new CSpan($host['name'], 'link_menu'); $hostName->setMenuPopup(CMenuPopupHelper::getHost($host, $scripts[$host['hostid']])); $hostNames[] = $hostName; $hostNames[] = ', '; } array_pop($hostNames); $table = new CTableInfo(); $table->addRow(array(new CCol(_n('Host', 'Hosts', count($hosts))), new CCol($hostNames, 'wraptext'))); $table->addRow(array(new CCol(_('Trigger')), new CCol(CMacrosResolverHelper::resolveTriggerName($trigger), 'wraptext'))); $table->addRow(array(_('Severity'), getSeverityCell($trigger['priority']))); $table->addRow(array(new CCol(_('Expression')), new CCol(explode_exp($trigger['expression'], true, true), 'trigger-expression'))); $table->addRow(array(_('Event generation'), _('Normal') . (TRIGGER_MULT_EVENT_ENABLED == $trigger['type'] ? SPACE . '+' . SPACE . _('Multiple PROBLEM events') : ''))); $table->addRow(array(_('Disabled'), TRIGGER_STATUS_ENABLED == $trigger['status'] ? new CCol(_('No'), 'off') : new CCol(_('Yes'), 'on'))); return $table; }
$description = array($img, SPACE, $description); } unset($img, $dependenciesTable, $dependency); $triggerDescription = new CSpan($description, 'pointer'); // host js menu $hostList = array(); foreach ($trigger['hosts'] as $triggerHost) { // fetch scripts for the host js menu $scripts = array(); if (isset($scriptsByHosts[$triggerHost['hostid']])) { foreach ($scriptsByHosts[$triggerHost['hostid']] as $script) { $scripts[] = $script; } } $hostName = new CSpan($triggerHost['name'], 'link_menu'); $hostName->setMenuPopup(CMenuPopupHelper::getHost($hosts[$triggerHost['hostid']], $scripts)); $hostDiv = new CDiv($hostName); // add maintenance icon with hint if host is in maintenance if ($triggerHost['maintenance_status']) { $maintenanceIcon = new CDiv(null, 'icon-maintenance-inline'); $maintenances = API::Maintenance()->get(array('maintenanceids' => $triggerHost['maintenanceid'], 'output' => API_OUTPUT_EXTEND, 'limit' => 1)); if ($maintenance = reset($maintenances)) { $hint = $maintenance['name'] . ' [' . ($triggerHost['maintenance_type'] ? _('Maintenance without data collection') : _('Maintenance with data collection')) . ']'; if (isset($maintenance['description'])) { // double quotes mandatory $hint .= "\n" . $maintenance['description']; } $maintenanceIcon->setHint($hint); $maintenanceIcon->addClass('pointer'); } $hostDiv->addItem($maintenanceIcon);
function make_trigger_details($trigger) { $hostNames = []; $config = select_config(); $hostIds = zbx_objectValues($trigger['hosts'], 'hostid'); $hosts = API::Host()->get(['output' => ['name', 'hostid', 'status'], 'hostids' => $hostIds, 'selectScreens' => API_OUTPUT_COUNT, 'selectGraphs' => API_OUTPUT_COUNT]); if (count($hosts) > 1) { order_result($hosts, 'name', ZBX_SORT_UP); } $scripts = API::Script()->getScriptsByHosts($hostIds); foreach ($hosts as $host) { $hostName = new CSpan($host['name'], ZBX_STYLE_LINK_ACTION); $hostName->setMenuPopup(CMenuPopupHelper::getHost($host, $scripts[$host['hostid']])); $hostNames[] = $hostName; $hostNames[] = ', '; } array_pop($hostNames); $expression = CMacrosResolverHelper::resolveTriggerExpression($trigger['expression'], ['html' => true, 'resolve_usermacros' => true, 'resolve_macros' => true]); $table = (new CTableInfo())->addRow([new CCol(_n('Host', 'Hosts', count($hosts))), new CCol($hostNames)])->addRow([new CCol(_('Trigger')), new CCol(CMacrosResolverHelper::resolveTriggerName($trigger))])->addRow([_('Severity'), getSeverityCell($trigger['priority'], $config)])->addRow([new CCol(_('Expression')), new CCol($expression)])->addRow([_('Event generation'), _('Normal') . (TRIGGER_MULT_EVENT_ENABLED == $trigger['type'] ? SPACE . '+' . SPACE . _('Multiple PROBLEM events') : '')])->addRow([_('Disabled'), TRIGGER_STATUS_ENABLED == $trigger['status'] ? (new CCol(_('No')))->addClass(ZBX_STYLE_GREEN) : (new CCol(_('Yes')))->addClass(ZBX_STYLE_RED)]); return $table; }