public function getMenuIcons() { $icons = array(); if ($this->canRefresh()) { $icon = new CIcon(_('Menu'), 'iconmenu'); $icon->setMenuPopup(CMenuPopupHelper::getRefresh($this->getID(), $this->getSetting('rf_rate', $this->defaultRefreshRate))); $icons[] = $icon; } return $icons; }
/** * Creates nodes that can be used to display the service configuration tree using the CTree class. * * @see CTree * * @param array $services * @param array $parentService * @param array $service * @param array $dependency * @param array $tree */ function createServiceConfigurationTree(array $services, &$tree, array $parentService = array(), array $service = array(), array $dependency = array()) { if (!$service) { $caption = new CLink(_('root'), '#'); $caption->setMenuPopup(CMenuPopupHelper::getServiceConfiguration(null, _('root'), false)); $serviceNode = array('id' => 0, 'parentid' => 0, 'caption' => $caption, 'trigger' => array(), 'algorithm' => SPACE, 'description' => SPACE); $service = $serviceNode; $service['serviceid'] = 0; $service['dependencies'] = array(); $service['trigger'] = array(); // add all top level services as children of "root" foreach ($services as $topService) { if (!$topService['parent']) { $service['dependencies'][] = array('servicedownid' => $topService['serviceid'], 'soft' => 0, 'linkid' => 0); } } $tree = array($serviceNode); } else { // caption $caption = new CLink($service['name'], '#'); // service is deletable only if it has no hard dependency $deletable = true; foreach ($service['dependencies'] as $dep) { if ($dep['soft'] == 0) { $deletable = false; break; } } $caption->setMenuPopup(CMenuPopupHelper::getServiceConfiguration($service['serviceid'], $service['name'], $deletable)); $serviceNode = array('id' => $service['serviceid'], 'caption' => $caption, 'description' => $service['trigger'] ? $service['trigger']['description'] : '-', 'parentid' => $parentService ? $parentService['serviceid'] : 0, 'algorithm' => serviceAlgorythm($service['algorithm'])); } if (!$dependency || !$dependency['soft']) { $tree[$serviceNode['id']] = $serviceNode; foreach ($service['dependencies'] as $dependency) { $childService = $services[$dependency['servicedownid']]; createServiceConfigurationTree($services, $tree, $service, $childService, $dependency); } } else { $serviceNode['caption'] = new CSpan($serviceNode['caption'], 'service-caption-soft'); $tree[$serviceNode['id'] . '.' . $dependency['linkid']] = $serviceNode; } }
** 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;
} else { $triggerInfo = SPACE; } // if item type is 'Log' we must show log menu if (in_array($item['value_type'], array(ITEM_VALUE_TYPE_LOG, ITEM_VALUE_TYPE_STR, ITEM_VALUE_TYPE_TEXT))) { $triggers = array(); foreach ($item['triggers'] as $trigger) { foreach ($trigger['functions'] as $function) { if (!str_in_array($function['function'], array('regexp', 'iregexp'))) { continue 2; } } $triggers[] = array('id' => $trigger['triggerid'], 'name' => $trigger['description']); } $menuIcon = new CIcon(_('Menu'), 'iconmenu_b'); $menuIcon->setMenuPopup(CMenuPopupHelper::getTriggerLog($item['itemid'], $item['name'], $triggers)); } else { $menuIcon = SPACE; } $checkBox = new CCheckBox('group_itemid[' . $item['itemid'] . ']', null, null, $item['itemid']); $checkBox->setEnabled(empty($item['discoveryRule'])); $itemTable->addRow(array($checkBox, $menuIcon, empty($this->data['filter_hostid']) ? $item['host'] : null, $description, $triggerInfo, CHtml::encode($item['key_']), $item['type'] == ITEM_TYPE_TRAPPER || $item['type'] == ITEM_TYPE_SNMPTRAP ? '' : $item['delay'], $item['history'], in_array($item['value_type'], array(ITEM_VALUE_TYPE_STR, ITEM_VALUE_TYPE_LOG, ITEM_VALUE_TYPE_TEXT)) ? '' : $item['trends'], item_type2str($item['type']), new CCol(CHtml::encode($item['applications_list']), 'wraptext'), $status, $infoIcons)); } // create go buttons $goComboBox = new CComboBox('action'); $goOption = new CComboItem('item.massenable', _('Enable selected')); $goOption->setAttribute('confirm', _('Enable selected items?')); $goComboBox->addItem($goOption); $goOption = new CComboItem('item.massdisable', _('Disable selected')); $goOption->setAttribute('confirm', _('Disable selected items?')); $goComboBox->addItem($goOption);
/** * 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)); }
$sql .= ' AND ' . dbConditionInt('t.flags', array(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']; } $triggers = API::Trigger()->get(array('triggerids' => array_keys($triggersEventCount), 'output' => array('triggerid', 'description', 'expression', 'priority', 'flags', 'url', 'lastchange'), 'selectItems' => array('hostid', 'name', 'value_type', 'key_'), 'selectHosts' => array('hostid', 'status', 'name'), 'expandDescription' => true, 'preservekeys' => true, 'nopermissions' => true)); $hostIds = array(); foreach ($triggers as $triggerId => $trigger) { $hostIds[$trigger['hosts'][0]['hostid']] = $trigger['hosts'][0]['hostid']; $triggerItems = array(); $trigger['items'] = CMacrosResolverHelper::resolveItemNames($trigger['items']); foreach ($trigger['items'] as $item) { $triggerItems[] = array('name' => $item['name_expanded'], 'params' => array('itemid' => $item['itemid'], 'action' => in_array($item['value_type'], array(ITEM_VALUE_TYPE_FLOAT, ITEM_VALUE_TYPE_UINT64)) ? HISTORY_GRAPH : HISTORY_VALUES)); } $triggers[$triggerId]['items'] = $triggerItems; $triggers[$triggerId]['cnt_event'] = $triggersEventCount[$triggerId]; } CArrayHelper::sort($triggers, array(array('field' => 'cnt_event', 'order' => ZBX_SORT_DOWN), 'host', 'description', 'priority')); $hosts = API::Host()->get(array('output' => array('hostid', 'status'), 'hostids' => $hostIds, 'selectGraphs' => API_OUTPUT_COUNT, 'selectScreens' => API_OUTPUT_COUNT, 'preservekeys' => true)); $scripts = API::Script()->getScriptsByHosts($hostIds); foreach ($triggers as $trigger) { $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, $trigger['items'])); $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';
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';
$dashboardGrid[$col][$row] = (new CCollapsibleUiWidget($widgetid, $widget['data']))->setExpanded((bool) CProfile::get('web.dashboard.widget.' . $widgetid . '.state', true))->setHeader($widget['header'], [$icon], true, 'zabbix.php?action=dashboard.widget')->setFooter($footer); } $widgets = [WIDGET_SYSTEM_STATUS => ['action' => 'widget.system.view', 'header' => _('System status'), 'defaults' => ['col' => 1, 'row' => 1]], WIDGET_HOST_STATUS => ['action' => 'widget.hosts.view', 'header' => _('Host status'), 'defaults' => ['col' => 1, 'row' => 2]], WIDGET_LAST_ISSUES => ['action' => 'widget.issues.view', 'header' => _n('Last %1$d issue', 'Last %1$d issues', DEFAULT_LATEST_ISSUES_CNT), 'defaults' => ['col' => 1, 'row' => 3]], WIDGET_WEB_OVERVIEW => ['action' => 'widget.web.view', 'header' => _('Web monitoring'), 'defaults' => ['col' => 1, 'row' => 4]]]; if ($data['show_status_widget']) { $widgets[WIDGET_ZABBIX_STATUS] = ['action' => 'widget.status.view', 'header' => _('Status of Zabbix'), 'defaults' => ['col' => 1, 'row' => 0]]; } if ($data['show_discovery_widget']) { $widgets[WIDGET_DISCOVERY_STATUS] = ['action' => 'widget.discovery.view', 'header' => _('Discovery status'), 'defaults' => ['col' => 1, 'row' => 5]]; } foreach ($widgets as $widgetid => $widget) { $profile = 'web.dashboard.widget.' . $widgetid; $rate = CProfile::get($profile . '.rf_rate', 60); $expanded = (bool) CProfile::get($profile . '.state', true); $col = CProfile::get($profile . '.col', $widget['defaults']['col']); $row = CProfile::get($profile . '.row', $widget['defaults']['row']); $icon = (new CButton(null))->addClass(ZBX_STYLE_BTN_WIDGET_ACTION)->setTitle(_('Action'))->setMenuPopup(CMenuPopupHelper::getRefresh($widgetid, $rate)); $dashboardGrid[$col][$row] = (new CCollapsibleUiWidget($widgetid, (new CDiv())->addClass('preloader')))->setExpanded($expanded)->setHeader($widget['header'], [$icon], true, 'zabbix.php?action=dashboard.widget')->setFooter((new CList())->setId($widgetid . '_footer')); $widgetRefreshParams[$widgetid] = ['frequency' => $rate, 'url' => 'zabbix.php?action=' . $widget['action'], 'counter' => 0, 'darken' => 0, 'params' => ['widgetRefresh' => $widgetid]]; } // sort dashboard grid foreach ($dashboardGrid as $key => $val) { ksort($dashboardGrid[$key]); } $dashboardRow = (new CDiv([(new CDiv($dashboardGrid[0]))->addClass('cell'), (new CDiv($dashboardGrid[1]))->addClass('cell'), (new CDiv($dashboardGrid[2]))->addClass('cell')]))->addClass('row'); $dashboardTable = (new CDiv($dashboardRow))->addClass('table')->addClass('widget-placeholder'); $dashboard->addItem($dashboardTable)->show(); /* * Javascript */ // start refresh process $this->addPostJS('initPMaster("dashboard", ' . CJs::encodeJson($widgetRefreshParams) . ');');
/** * 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]; }
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; }
$icon = new CIcon(_('Menu'), 'iconmenu'); $icon->setMenuPopup(CMenuPopupHelper::getRefresh(WIDGET_WEB_OVERVIEW, $rate)); $webMonitoring = new CCollapsibleUiWidget(WIDGET_WEB_OVERVIEW, new CSpan(_('Loading...'), 'textcolorstyles')); $webMonitoring->open = (bool) CProfile::get('web.dashboard.widget.' . WIDGET_WEB_OVERVIEW . '.state', true); $webMonitoring->setHeader(_('Web monitoring'), $icon); $webMonitoring->setFooter(new CDiv(SPACE, 'textwhite', WIDGET_WEB_OVERVIEW . '_footer')); $col = CProfile::get('web.dashboard.widget.' . WIDGET_WEB_OVERVIEW . '.col', 1); $row = CProfile::get('web.dashboard.widget.' . WIDGET_WEB_OVERVIEW . '.row', 4); $dashboardGrid[$col][$row] = $webMonitoring; $widgetRefreshParams[WIDGET_WEB_OVERVIEW] = array('frequency' => $rate, 'url' => '?output=html', 'counter' => 0, 'darken' => 0, 'params' => array('widgetRefresh' => WIDGET_WEB_OVERVIEW)); // discovery rules $dbDiscoveryRules = DBfetch(DBselect('SELECT COUNT(d.druleid) AS cnt' . ' FROM drules d' . ' WHERE d.status=' . DRULE_STATUS_ACTIVE)); if ($dbDiscoveryRules['cnt'] > 0 && check_right_on_discovery()) { $rate = CProfile::get('web.dashboard.widget.' . WIDGET_DISCOVERY_STATUS . '.rf_rate', 60); $icon = new CIcon(_('Menu'), 'iconmenu'); $icon->setMenuPopup(CMenuPopupHelper::getRefresh(WIDGET_DISCOVERY_STATUS, $rate)); $discoveryStatus = new CCollapsibleUiWidget(WIDGET_DISCOVERY_STATUS, new CSpan(_('Loading...'), 'textcolorstyles')); $discoveryStatus->open = (bool) CProfile::get('web.dashboard.widget.' . WIDGET_DISCOVERY_STATUS . '.state', true); $discoveryStatus->setHeader(_('Discovery status'), $icon); $discoveryStatus->setFooter(new CDiv(SPACE, 'textwhite', WIDGET_DISCOVERY_STATUS . '_footer')); $col = CProfile::get('web.dashboard.widget.' . WIDGET_DISCOVERY_STATUS . '.col', 1); $row = CProfile::get('web.dashboard.widget.' . WIDGET_DISCOVERY_STATUS . '.row', 5); $dashboardGrid[$col][$row] = $discoveryStatus; $widgetRefreshParams[WIDGET_DISCOVERY_STATUS] = array('frequency' => $rate, 'url' => '?output=html', 'counter' => 0, 'darken' => 0, 'params' => array('widgetRefresh' => WIDGET_DISCOVERY_STATUS)); } // sort dashboard grid foreach ($dashboardGrid as $key => $val) { ksort($dashboardGrid[$key]); } $dashboardTable = new CTable(); $dashboardTable->addRow(array(new CDiv($dashboardGrid[0], 'column'), new CDiv($dashboardGrid[1], 'column'), new CDiv($dashboardGrid[2], 'column')), 'top');
$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 getItemDataOverviewCells($tableRow, $ithosts, $hostName) { $ack = null; $css = ''; $value = UNKNOWN_VALUE; if (isset($ithosts[$hostName])) { $item = $ithosts[$hostName]; if ($item['tr_value'] == TRIGGER_VALUE_TRUE) { $css = getSeverityStyle($item['severity']); // Display event acknowledgement. $config = select_config(); if ($config['event_ack_enable']) { $ack = get_last_event_by_triggerid($item['triggerid']); $ack = $ack['acknowledged'] == 1 ? [SPACE, (new CSpan())->addClass(ZBX_STYLE_ICON_ACKN)] : null; } } if ($item['value'] !== null) { $value = formatHistoryValue($item['value'], $item); } } if ($value != UNKNOWN_VALUE) { $value = $value; } $column = (new CCol([$value, $ack]))->addClass($css); if (isset($ithosts[$hostName])) { $column->setMenuPopup(CMenuPopupHelper::getHistory($item))->addClass(ZBX_STYLE_CURSOR_POINTER)->addClass(ZBX_STYLE_NOWRAP); } $tableRow[] = $column; return $tableRow; }
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; }
$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');
$nameTextBox->attr('autofocus', 'autofocus'); $triggersFormList->addRow(_('Name'), $nameTextBox); // append expression to form list $expressionTextBox = new CTextArea($this->data['expression_field_name'], $this->data['expression_field_value'], array('rows' => ZBX_TEXTAREA_STANDARD_ROWS, 'width' => ZBX_TEXTAREA_STANDARD_WIDTH, 'readonly' => $this->data['expression_field_readonly'])); if ($this->data['expression_field_readonly']) { $triggersForm->addVar('expression', $this->data['expression']); } $addExpressionButton = new CButton('insert', $this->data['input_method'] == IM_TREE ? _('Edit') : _('Add'), 'return PopUp("popup_trexpr.php?dstfrm=' . $triggersForm->getName() . '&dstfld1=' . $this->data['expression_field_name'] . '&srctbl=expression' . url_param('parent_discoveryid') . '&srcfld1=expression&expression=" + encodeURIComponent(jQuery(\'[name="' . $this->data['expression_field_name'] . '"]\').val()), 800, 265);', 'formlist'); if ($this->data['limited']) { $addExpressionButton->setAttribute('disabled', 'disabled'); } $expressionRow = array($expressionTextBox, $addExpressionButton); if ($this->data['input_method'] == IM_TREE) { // insert macro button $insertMacroButton = new CButton('insert_macro', _('Insert expression'), null, 'formlist'); $insertMacroButton->setMenuPopup(CMenuPopupHelper::getTriggerMacro()); if ($this->data['limited']) { $insertMacroButton->setAttribute('disabled', 'disabled'); } $expressionRow[] = $insertMacroButton; array_push($expressionRow, BR()); if (empty($this->data['outline'])) { // add button $addExpressionButton = new CSubmit('add_expression', _('Add'), null, 'formlist'); if ($this->data['limited']) { $addExpressionButton->setAttribute('disabled', 'disabled'); } array_push($expressionRow, $addExpressionButton); } else { // add button $addExpressionButton = new CSubmit('and_expression', _('And'), null, 'formlist');
if (!empty($this->data['templates'])) { $triggersFormList->addRow(_('Parent triggers'), $this->data['templates']); } $triggersFormList->addRow(_('Name'), (new CTextBox('description', $this->data['description'], $this->data['limited']))->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH)->setAttribute('autofocus', 'autofocus')); // append expression to form list if ($this->data['expression_field_readonly']) { $triggersForm->addVar('expression', $this->data['expression']); } $addExpressionButton = (new CButton('insert', $this->data['input_method'] == IM_TREE ? _('Edit') : _('Add')))->addClass(ZBX_STYLE_BTN_GREY)->onClick('return PopUp("popup_trexpr.php?dstfrm=' . $triggersForm->getName() . '&dstfld1=' . $this->data['expression_field_name'] . '&srctbl=expression&srcfld1=expression' . '&expression=" + encodeURIComponent(jQuery(\'[name="' . $this->data['expression_field_name'] . '"]\').val()));'); if ($this->data['limited']) { $addExpressionButton->setAttribute('disabled', 'disabled'); } $expressionRow = [(new CTextArea($this->data['expression_field_name'], $this->data['expression_field_value'], ['readonly' => $this->data['expression_field_readonly']]))->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH), (new CDiv())->addClass(ZBX_STYLE_FORM_INPUT_MARGIN), $addExpressionButton]; if ($this->data['input_method'] == IM_TREE) { // insert macro button $insertMacroButton = (new CButton('insert_macro', _('Insert expression')))->addClass(ZBX_STYLE_BTN_GREY)->setMenuPopup(CMenuPopupHelper::getTriggerMacro()); if ($this->data['limited']) { $insertMacroButton->setAttribute('disabled', 'disabled'); } $expressionRow[] = (new CDiv())->addClass(ZBX_STYLE_FORM_INPUT_MARGIN); $expressionRow[] = $insertMacroButton; array_push($expressionRow, BR()); if (empty($this->data['outline'])) { // add button $addExpressionButton = (new CSubmit('add_expression', _('Add')))->addClass(ZBX_STYLE_BTN_GREY); if ($this->data['limited']) { $addExpressionButton->setAttribute('disabled', 'disabled'); } $expressionRow[] = $addExpressionButton; } else { // add button
function getItemDataOverviewCells($tableRow, $ithosts, $hostName) { $css = ''; $value = '-'; $ack = null; if (isset($ithosts[$hostName])) { $item = $ithosts[$hostName]; if ($item['tr_value'] == TRIGGER_VALUE_TRUE) { $css = getSeverityStyle($item['severity']); $ack = get_last_event_by_triggerid($item['triggerid']); $ack = $ack['acknowledged'] == 1 ? array(SPACE, new CImg('images/general/tick.png', 'ack')) : null; } $value = $item['value'] !== null ? formatHistoryValue($item['value'], $item) : UNKNOWN_VALUE; } if ($value != '-') { $value = new CSpan($value, 'link'); } $column = new CCol(array($value, $ack), $css); if (isset($ithosts[$hostName])) { $column->setMenuPopup(CMenuPopupHelper::getHistory($item)); } $tableRow[] = $column; return $tableRow; }
** 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. **/ $widget = (new CWidget())->setTitle(_('Slide shows'))->addItem((new CList())->addClass(ZBX_STYLE_OBJECT_GROUP)->addItem([(new CSpan())->addItem(new CLink(_('All slide shows'), 'slideconf.php')), '/', (new CSpan())->addClass(ZBX_STYLE_SELECTED)->addItem(new CLink($data['screen']['name'], 'slides.php?elementid=' . $data['screen']['slideshowid'] . '&fullscreen=' . $data['fullscreen']))])); // Create header form. $header = (new CForm('get'))->setName('slideHeaderForm'); $controls = (new CList())->addItem(new CComboBox('config', 'slides.php', 'redirect(this.options[this.selectedIndex].value);', ['screens.php' => _('Screens'), 'slides.php' => _('Slide shows')])); $favourite_icon = $this->data['screen'] ? get_icon('favourite', ['fav' => 'web.favorite.screenids', 'elname' => 'slideshowid', 'elid' => $this->data['elementId']]) : (new CIcon(_('Favourites')))->addClass('iconplus'); $refresh_icon = get_icon('screenconf'); if ($this->data['screen']) { $refresh_icon->setMenuPopup(CMenuPopupHelper::getRefresh(WIDGET_SLIDESHOW, 'x' . $this->data['refreshMultiplier'], true, ['elementid' => $this->data['elementId']])); } $header->addVar('fullscreen', $this->data['fullscreen']); if (isset($this->data['isDynamicItems'])) { $controls->addItem([SPACE, _('Group'), SPACE, $this->data['pageFilter']->getGroupsCB()]); $controls->addItem([SPACE, _('Host'), SPACE, $this->data['pageFilter']->getHostsCB()]); } $controls->addItem($data['screen']['editable'] ? (new CButton('edit', _('Edit slide show')))->onClick('redirect("slideconf.php?form=update&slideshowid=' . $data['screen']['slideshowid'] . '")') : null)->addItem($favourite_icon)->addItem($refresh_icon)->addItem(get_icon('fullscreen', ['fullscreen' => $this->data['fullscreen']])); $header->addItem($controls); $widget->setControls($header); $filter = (new CFilter('web.slides.filter.state'))->addNavigator(); $widget->addItem($filter); $widget->addItem((new CDiv((new CDiv())->addClass('preloader')))->setId(WIDGET_SLIDESHOW)); require_once dirname(__FILE__) . '/js/monitoring.slides.js.php'; return $widget;
$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]; }
$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;
** ** 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 map area with submenu for sysmap elements. * In submenu gathered information about urls, scripts and submaps. * * @param array $sysmap * @param array $options * @param int $options['severity_min'] * * @return CAreaMap */ function getActionMapBySysmap($sysmap, array $options = array()) { $sysmap['selements'] = zbx_toHash($sysmap['selements'], 'selementid'); $sysmap['links'] = zbx_toHash($sysmap['links'], 'linkid'); $actionMap = new CAreaMap('links' . $sysmap['sysmapid']); $areas = populateFromMapAreas($sysmap); $mapInfo = getSelementsInfo($sysmap, $options); processAreasCoordinates($sysmap, $areas, $mapInfo); $hostIds = array(); $triggerIds = array(); foreach ($sysmap['selements'] as $id => &$selement) { if ($selement['elementtype'] == SYSMAP_ELEMENT_TYPE_HOST) { $hostIds[$selement['elementid']] = $selement['elementid']; // expanding host URL macros again as some hosts were added from hostgroup areas // and automatic expanding only happens for elements that are defined for map in db foreach ($selement['urls'] as $urlId => $url) { $selement['urls'][$urlId]['url'] = str_replace('{HOST.ID}', $selement['elementid'], $url['url']); } } elseif ($selement['elementtype'] == SYSMAP_ELEMENT_TYPE_TRIGGER) { $triggerIds[$selement['elementid']] = $selement['elementid']; } if ($selement['elementsubtype'] == SYSMAP_ELEMENT_SUBTYPE_HOST_GROUP_ELEMENTS) { unset($sysmap['selements'][$id]); } } unset($selement); $hostScripts = API::Script()->getScriptsByHosts($hostIds); $hosts = API::Host()->get(array('hostids' => $hostIds, 'output' => array('hostid', 'status'), 'nopermissions' => true, 'preservekeys' => true, 'selectGraphs' => API_OUTPUT_COUNT, 'selectScreens' => API_OUTPUT_COUNT)); $triggers = API::Trigger()->get(array('output' => array('triggerid'), 'triggerids' => $triggerIds, 'selectHosts' => array('status'), 'preservekeys' => true, 'nopermissions' => true)); foreach ($sysmap['selements'] as $elem) { $back = get_png_by_selement($mapInfo[$elem['selementid']]); $area = new CArea(array($elem['x'], $elem['y'], $elem['x'] + imagesx($back), $elem['y'] + imagesy($back)), '', '', 'rect'); $area->addClass('menu-map'); $hostId = null; $scripts = null; $gotos = null; switch ($elem['elementtype']) { case SYSMAP_ELEMENT_TYPE_HOST: $host = $hosts[$elem['elementid']]; if ($hostScripts[$elem['elementid']]) { $hostId = $elem['elementid']; $scripts = $hostScripts[$elem['elementid']]; } $gotos['triggerStatus'] = array('hostid' => $elem['elementid'], 'show_severity' => isset($options['severity_min']) ? $options['severity_min'] : null); $gotos['showTriggers'] = $hosts[$elem['elementid']]['status'] == HOST_STATUS_MONITORED; $gotos['graphs'] = array('hostid' => $host['hostid']); $gotos['showGraphs'] = (bool) $host['graphs']; $gotos['screens'] = array('hostid' => $host['hostid']); $gotos['showScreens'] = (bool) $host['screens']; $gotos['inventory'] = array('hostid' => $host['hostid']); $gotos['latestData'] = array('hostids' => array($host['hostid'])); break; case SYSMAP_ELEMENT_TYPE_MAP: $gotos['submap'] = array('sysmapid' => $elem['elementid'], 'severity_min' => isset($options['severity_min']) ? $options['severity_min'] : null); break; case SYSMAP_ELEMENT_TYPE_TRIGGER: $gotos['events'] = array('triggerid' => $elem['elementid'], 'stime' => date(TIMESTAMP_FORMAT, time() - SEC_PER_WEEK), 'period' => SEC_PER_WEEK); $gotos['showEvents'] = false; if (isset($triggers[$elem['elementid']])) { foreach ($triggers[$elem['elementid']]['hosts'] as $host) { if ($host['status'] == HOST_STATUS_MONITORED) { $gotos['showEvents'] = true; break; } } } break; case SYSMAP_ELEMENT_TYPE_HOST_GROUP: $gotos['triggerStatus'] = array('groupid' => $elem['elementid'], 'hostid' => 0, 'show_severity' => isset($options['severity_min']) ? $options['severity_min'] : null); // always show active trigger link for host group map elements $gotos['showTriggers'] = true; break; } order_result($elem['urls'], 'name'); $area->setMenuPopup(CMenuPopupHelper::getMap($hostId, $scripts, $gotos, $elem['urls'])); $actionMap->addItem($area); } return $actionMap; }
protected function doAction() { $object = $this->getInput('object'); $operation = $this->getInput('operation'); $objectids = $this->getInput('objectids'); $data = []; $result = true; DBstart(); switch ($object) { // favourite graphs case 'itemid': case 'graphid': zbx_value2array($objectids); foreach ($objectids as $id) { if ($operation == 'create') { $result &= CFavorite::add('web.favorite.graphids', $id, $object); } elseif ($operation == 'delete') { $result &= CFavorite::remove('web.favorite.graphids', $id, $object); } } $graphs = getFavouriteGraphs(); $graphs = $graphs->toString(); $data['main_block'] = 'jQuery("#' . WIDGET_FAVOURITE_GRAPHS . '").html(' . CJs::encodeJson($graphs) . ');' . 'jQuery(".action-menu").remove();' . 'jQuery("#favouriteGraphs").data(' . '"menu-popup", ' . CJs::encodeJson(CMenuPopupHelper::getFavouriteGraphs()) . ');'; break; // favourite maps // favourite maps case 'sysmapid': zbx_value2array($objectids); foreach ($objectids as $id) { if ($operation == 'create') { $result &= CFavorite::add('web.favorite.sysmapids', $id, $object); } elseif ($operation == 'delete') { $result &= CFavorite::remove('web.favorite.sysmapids', $id, $object); } } $maps = getFavouriteMaps(); $maps = $maps->toString(); $data['main_block'] = 'jQuery("#' . WIDGET_FAVOURITE_MAPS . '").html(' . CJs::encodeJson($maps) . ');' . 'jQuery(".action-menu").remove();' . 'jQuery("#favouriteMaps").data(' . '"menu-popup", ' . CJs::encodeJson(CMenuPopupHelper::getFavouriteMaps()) . ');'; break; // favourite screens, slideshows // favourite screens, slideshows case 'screenid': case 'slideshowid': zbx_value2array($objectids); foreach ($objectids as $id) { if ($operation == 'create') { $result &= CFavorite::add('web.favorite.screenids', $id, $object); } elseif ($operation == 'delete') { $result &= CFavorite::remove('web.favorite.screenids', $id, $object); } } $screens = getFavouriteScreens(); $screens = $screens->toString(); $data['main_block'] = 'jQuery("#' . WIDGET_FAVOURITE_SCREENS . '").html(' . CJs::encodeJson($screens) . ');' . 'jQuery(".action-menu").remove();' . 'jQuery("#favouriteScreens").data(' . '"menu-popup", ' . CJs::encodeJson(CMenuPopupHelper::getFavouriteScreens()) . ');'; break; default: $data['main_block'] = ''; } DBend($result); $this->setResponse(new CControllerResponseData($data)); }