/** * Process screen. * * @return CDiv (screen inside container) */ public function get() { // fetch hosts $hosts = API::Host()->get(['output' => ['hostid', 'status'], 'selectGraphs' => $this->screenitem['style'] == STYLE_LEFT ? API_OUTPUT_COUNT : null, 'selectScreens' => $this->screenitem['style'] == STYLE_LEFT ? API_OUTPUT_COUNT : null, 'groupids' => $this->screenitem['resourceid'], 'preservekeys' => true]); $hostids = array_keys($hosts); $options = ['output' => ['triggerid', 'expression', 'description', 'url', 'value', 'priority', 'lastchange', 'flags'], 'selectHosts' => ['hostid', 'name', 'status'], 'selectItems' => ['itemid', 'hostid', 'name', 'key_', 'value_type'], 'hostids' => $hostids, 'monitored' => true, 'skipDependent' => true, 'sortfield' => 'description', 'preservekeys' => true]; // application filter if ($this->screenitem['application'] !== '') { $applications = API::Application()->get(['output' => [], 'hostids' => $hostids, 'search' => ['name' => $this->screenitem['application']], 'preservekeys' => true]); $options['applicationids'] = array_keys($applications); } $triggers = API::Trigger()->get($options); $triggers = CMacrosResolverHelper::resolveTriggerUrls($triggers); /* * Each screen cell with "Triggers overview" depends on one specific group which in this case is 'resourceid'. * Pass it as 'groupid' to menu pop-up "Events" link. */ foreach ($triggers as &$trigger) { $trigger['groupid'] = $this->screenitem['resourceid']; } unset($trigger); $groups = API::HostGroup()->get(['output' => ['name'], 'groupids' => [$this->screenitem['resourceid']]]); $header = (new CDiv([new CTag('h4', true, _('Triggers overview')), (new CList())->addItem([_('Group'), ':', SPACE, $groups[0]['name']])]))->addClass(ZBX_STYLE_DASHBRD_WIDGET_HEAD); $table = getTriggersOverview($hosts, $triggers, $this->pageFile, $this->screenitem['style'], $this->screenid); $footer = (new CList())->addItem(_s('Updated: %s', zbx_date2str(TIME_FORMAT_SECONDS)))->addClass(ZBX_STYLE_DASHBRD_WIDGET_FOOT); return $this->getOutput(new CUiWidget(uniqid(), [$header, $table, $footer])); }
/** * 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]; }
*/ $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 paging $url = (new CUrl('events.php'))->setArgument('fullscreen', getRequest('fullscreen'))->setArgument('groupid', $pageFilter->groupid)->setArgument('hostid', $pageFilter->hostid); $paging = getPagingLine($events, ZBX_SORT_DOWN, $url); // query event with extend data $events = API::Event()->get(['source' => EVENT_SOURCE_TRIGGERS, 'object' => EVENT_OBJECT_TRIGGER, 'eventids' => zbx_objectValues($events, 'eventid'), 'output' => API_OUTPUT_EXTEND, 'select_acknowledges' => API_OUTPUT_COUNT, 'sortfield' => ['clock', 'eventid'], 'sortorder' => ZBX_SORT_DOWN, 'nopermissions' => true]); $triggers = API::Trigger()->get(['output' => ['triggerid', 'description', 'expression', 'priority', 'flags', 'url'], 'selectHosts' => ['hostid', 'name', 'status'], 'selectItems' => ['itemid', 'hostid', 'name', 'key_', 'value_type'], 'triggerids' => zbx_objectValues($events, 'objectid'), 'preservekeys' => true]); $triggers = CMacrosResolverHelper::resolveTriggerUrls($triggers); // fetch hosts $hosts = []; foreach ($triggers as &$trigger) { $hosts[] = reset($trigger['hosts']); // Add already filtered read and read-write 'groupid' and 'hostid' to pass to menu pop-up "Events" link. $trigger['groupid'] = $pageFilter->groupid; $trigger['hostid'] = $pageFilter->hostid; } unset($trigger); $hostids = zbx_objectValues($hosts, 'hostid'); $hosts = API::Host()->get(['output' => ['name', 'hostid', 'status'], 'hostids' => $hostids, 'selectGraphs' => API_OUTPUT_COUNT, 'selectScreens' => API_OUTPUT_COUNT, 'preservekeys' => true]); // fetch scripts for the host JS menu if (!$csvExport && $pageFilter->hostid == 0) { $scripts = API::Script()->getScriptsByHosts($hostids); }
} if (CWebUser::getType() == USER_TYPE_SUPER_ADMIN && ($data['filter']['groupids'] || $data['filter']['hostids'])) { $sql .= ' AND EXISTS (' . 'SELECT NULL' . ' FROM functions f,items i,hosts_groups hgg' . ' WHERE t.triggerid=f.triggerid' . ' AND f.itemid=i.itemid' . ' AND i.hostid=hgg.hostid' . ($data['filter']['hostids'] ? $inHosts : '') . ($data['filter']['groupids'] ? $inGroups : '') . ')'; } elseif (CWebUser::getType() != USER_TYPE_SUPER_ADMIN) { // add permission filter $userId = CWebUser::$data['userid']; $userGroups = getUserGroupsByUserId($userId); $sql .= ' AND EXISTS (' . 'SELECT NULL' . ' FROM functions f,items i,hosts_groups hgg' . ' JOIN rights r' . ' ON r.id=hgg.groupid' . ' AND ' . dbConditionInt('r.groupid', $userGroups) . ' WHERE t.triggerid=f.triggerid' . ' AND f.itemid=i.itemid' . ' AND i.hostid=hgg.hostid' . ($data['filter']['hostids'] ? $inHosts : '') . ($data['filter']['groupids'] ? $inGroups : '') . ' GROUP BY f.triggerid' . ' HAVING MIN(r.permission)>' . PERM_DENY . ')'; } $sql .= ' AND ' . dbConditionInt('t.flags', [ZBX_FLAG_DISCOVERY_NORMAL, ZBX_FLAG_DISCOVERY_CREATED]) . ' GROUP BY e.objectid' . ' ORDER BY cnt_event DESC'; $result = DBselect($sql, 100); while ($row = DBfetch($result)) { $triggersEventCount[$row['objectid']] = $row['cnt_event']; } $data['triggers'] = API::Trigger()->get(['output' => ['triggerid', 'description', 'expression', 'priority', 'flags', 'url', 'lastchange'], 'selectItems' => ['itemid', 'hostid', 'name', 'key_', 'value_type'], 'selectHosts' => ['hostid', 'status', 'name'], 'triggerids' => array_keys($triggersEventCount), 'expandDescription' => true, 'preservekeys' => true]); $data['triggers'] = CMacrosResolverHelper::resolveTriggerUrls($data['triggers']); $hostIds = []; foreach ($data['triggers'] as $triggerId => $trigger) { $hostId = $trigger['hosts'][0]['hostid']; $hostIds[$hostId] = $hostId; $data['triggers'][$triggerId]['cnt_event'] = $triggersEventCount[$triggerId]; } CArrayHelper::sort($data['triggers'], [['field' => 'cnt_event', 'order' => ZBX_SORT_DOWN], 'host', 'description', 'priority']); $data['hosts'] = API::Host()->get(['output' => ['hostid', 'status'], 'selectGraphs' => API_OUTPUT_COUNT, 'selectScreens' => API_OUTPUT_COUNT, 'hostids' => $hostIds, 'preservekeys' => true]); $data['scripts'] = API::Script()->getScriptsByHosts($hostIds); $monitored_hostids = []; foreach ($data['triggers'] as $trigger) { foreach ($trigger['hosts'] as $host) { if ($host['status'] == HOST_STATUS_MONITORED) { $monitored_hostids[$host['hostid']] = true; }