/** * Creates and returns a trigger status cell for the trigger overview table. * * @see getTriggersOverview() * * @param array $trigger * @param string $pageFile the page where the element is displayed * @param string $screenId * * @return CCol */ function getTriggerOverviewCells($trigger, $pageFile, $screenId = null) { $ack = null; $css = null; $style = null; $desc = array(); $config = select_config(); // for how long triggers should blink on status change (set by user in administration->general) $menuPopup = array(); $triggerItems = array(); $acknowledge = array(); if ($trigger) { $style = 'cursor: pointer; '; // problem trigger if ($trigger['value'] == TRIGGER_VALUE_TRUE) { $css = getSeverityStyle($trigger['priority']); $ack = null; if ($config['event_ack_enable'] == 1) { if ($event = get_last_event_by_triggerid($trigger['triggerid'])) { if ($screenId) { $acknowledge = array('eventid' => $event['eventid'], 'screenid' => $screenId, 'backurl' => $pageFile); } else { $acknowledge = array('eventid' => $event['eventid'], 'backurl' => 'overview.php'); } if ($event['acknowledged'] == 1) { $ack = new CImg('images/general/tick.png', 'ack'); } } } } else { $css = 'normal'; } $dbItems = DBselect('SELECT DISTINCT i.itemid,i.name,i.key_,i.value_type' . ' FROM items i,functions f' . ' WHERE f.itemid=i.itemid' . ' AND f.triggerid=' . zbx_dbstr($trigger['triggerid'])); while ($item = DBfetch($dbItems)) { $triggerItems[] = array('name' => itemName($item), 'params' => array('action' => in_array($item['value_type'], array(ITEM_VALUE_TYPE_FLOAT, ITEM_VALUE_TYPE_UINT64)) ? 'showgraph' : 'showlatest', 'itemid' => $item['itemid'], 'period' => 3600)); } // dependency: triggers on which depends this $triggerId = empty($trigger['triggerid']) ? 0 : $trigger['triggerid']; // trigger dependency DOWN $dependencyTable = new CTableInfo(); $dependencyTable->setAttribute('style', 'width: 200px;'); $dependencyTable->addRow(bold(_('Depends on') . NAME_DELIMITER)); $isDependencyFound = false; $dbDependencies = DBselect('SELECT td.* FROM trigger_depends td WHERE td.triggerid_down=' . zbx_dbstr($triggerId)); while ($dbDependency = DBfetch($dbDependencies)) { $dependencyTable->addRow(SPACE . '-' . SPACE . CMacrosResolverHelper::resolveTriggerNameById($dbDependency['triggerid_up'])); $isDependencyFound = true; } if ($isDependencyFound) { $icon = new Cimg('images/general/arrow_down2.png', 'DEP_DOWN'); $icon->setAttribute('style', 'vertical-align: middle; border: 0px;'); $icon->setHint($dependencyTable, '', '', false); $desc[] = $icon; } // trigger dependency UP $dependencyTable = new CTableInfo(); $dependencyTable->setAttribute('style', 'width: 200px;'); $dependencyTable->addRow(bold(_('Dependent') . NAME_DELIMITER)); $isDependencyFound = false; $dbDependencies = DBselect('SELECT td.* FROM trigger_depends td WHERE td.triggerid_up=' . zbx_dbstr($triggerId)); while ($dbDependency = DBfetch($dbDependencies)) { $dependencyTable->addRow(SPACE . '-' . SPACE . CMacrosResolverHelper::resolveTriggerNameById($dbDependency['triggerid_down'])); $isDependencyFound = true; } if ($isDependencyFound) { $icon = new Cimg('images/general/arrow_up2.png', 'DEP_UP'); $icon->setAttribute('style', 'vertical-align: middle; border: none;'); $icon->setHint($dependencyTable, '', '', false); $desc[] = $icon; } } $column = is_array($desc) && count($desc) > 0 || $ack ? new CCol(array($desc, $ack), $css . ' hosts') : new CCol(SPACE, $css . ' hosts'); $column->setAttribute('style', $style); if ($trigger && $config['blink_period'] > 0 && time() - $trigger['lastchange'] < $config['blink_period']) { $column->addClass('blink'); $column->setAttribute('data-toggle-class', $css); } if ($trigger) { $column->setMenuPopup(getMenuPopupTrigger($trigger, $triggerItems, $acknowledge)); } return $column; }
while ($row = DBfetch($dbTriggerDependencies)) { $triggerIdsDown[$row['triggerid_up']][] = intval($row['triggerid_down']); } foreach ($triggers as $trigger) { $usedHosts = array(); foreach ($trigger['hosts'] as $host) { $usedHosts[$host['hostid']] = $host['name']; } $usedHostCount = count($usedHosts); $triggerItems = array(); $trigger['items'] = CMacrosResolverHelper::resolveItemNames($trigger['items']); foreach ($trigger['items'] as $item) { $triggerItems[] = array('name' => $usedHostCount > 1 ? $usedHosts[$item['hostid']] . NAME_DELIMITER . $item['name_expanded'] : $item['name_expanded'], 'params' => array('itemid' => $item['itemid'], 'action' => in_array($item['value_type'], array(ITEM_VALUE_TYPE_FLOAT, ITEM_VALUE_TYPE_UINT64)) ? 'showgraph' : 'showvalues')); } $description = new CSpan($trigger['description'], 'link_menu'); $description->setMenuPopup(getMenuPopupTrigger($trigger, $triggerItems)); if ($_REQUEST['show_details']) { $description = array($description, BR(), explode_exp($trigger['expression'], true, true)); } if (!empty($trigger['dependencies'])) { $dependenciesTable = new CTableInfo(); $dependenciesTable->setAttribute('style', 'width: 200px;'); $dependenciesTable->addRow(bold(_('Depends on') . NAME_DELIMITER)); foreach ($trigger['dependencies'] as $dependency) { $dependenciesTable->addRow(' - ' . CMacrosResolverHelper::resolveTriggerNameById($dependency['triggerid'])); } $img = new Cimg('images/general/arrow_down2.png', 'DEP_UP'); $img->setAttribute('style', 'vertical-align: middle; border: 0px;'); $img->setHint($dependenciesTable); $description = array($img, SPACE, $description); }
} $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'), 'expandDescription' => true, 'expandData' => true, 'preservekeys' => true, 'nopermissions' => true)); $hostIds = array(); foreach ($triggers as $triggerId => $trigger) { $hostIds[$trigger['hostid']] = $trigger['hostid']; $triggerItems = array(); foreach ($trigger['items'] as $item) { $triggerItems[] = array('name' => itemName($item), 'params' => array('itemid' => $item['itemid'], 'action' => in_array($item['value_type'], array(ITEM_VALUE_TYPE_FLOAT, ITEM_VALUE_TYPE_UINT64)) ? 'showgraph' : 'showvalues')); } $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'), 'hostids' => $hostIds, 'selectScreens' => API_OUTPUT_COUNT, 'preservekeys' => true)); $scripts = API::Script()->getScriptsByHosts($hostIds); foreach ($triggers as $trigger) { $hostId = $trigger['hostid']; $hostName = new CSpan($trigger['hostname'], 'link_menu'); $hostName->setMenuPopup(getMenuPopupHost($hosts[$hostId], $scripts[$hostId])); $triggerDescription = new CSpan($trigger['description'], 'link_menu'); $triggerDescription->setMenuPopup(getMenuPopupTrigger($trigger, $trigger['items'])); $table->addRow(array(get_node_name_by_elid($trigger['triggerid']), $hostName, $triggerDescription, getSeverityCell($trigger['priority']), $trigger['cnt_event'])); } $rprt_wdgt->addItem($table); $rprt_wdgt->show(); require_once dirname(__FILE__) . '/include/page_footer.php';
$scripts = API::Script()->getScriptsByHosts($hostids); } // actions $actions = getEventActionsStatus(zbx_objectValues($events, 'eventid')); // events foreach ($events as $event) { $trigger = $triggers[$event['objectid']]; $host = reset($trigger['hosts']); $host = $hosts[$host['hostid']]; $triggerItems = array(); foreach ($trigger['items'] as $item) { $triggerItems[] = array('name' => itemName($item), 'params' => array('itemid' => $item['itemid'], 'action' => in_array($item['value_type'], array(ITEM_VALUE_TYPE_FLOAT, ITEM_VALUE_TYPE_UINT64)) ? 'showgraph' : 'showvalues')); } $description = CMacrosResolverHelper::resolveEventDescription(zbx_array_merge($trigger, array('clock' => $event['clock'], 'ns' => $event['ns']))); $triggerDescription = new CSpan($description, 'pointer link_menu'); $triggerDescription->setMenuPopup(getMenuPopupTrigger($trigger, $triggerItems, null, $event['clock'])); // acknowledge $ack = getEventAckState($event, true); // duration $event['duration'] = ($nextEvent = get_next_event($event, $events)) ? zbx_date2age($event['clock'], $nextEvent['clock']) : zbx_date2age($event['clock']); $statusSpan = new CSpan(trigger_value2str($event['value'])); // add colors and blinking to span depending on configuration and trigger parameters addTriggerValueStyle($statusSpan, $event['value'], $event['clock'], $event['acknowledged']); // host JS menu link $hostName = null; if ($_REQUEST['hostid'] == 0) { $hostName = new CSpan($host['name'], 'link_menu'); $hostName->setMenuPopup(getMenuPopupHost($host, $scripts[$host['hostid']])); } // action $action = isset($actions[$event['eventid']]) ? $actions[$event['eventid']] : ' - ';