/** * Process screen. * * @return CDiv (screen inside container) */ public function get() { // if screen is defined in template, then 'real_resourceid' is defined and should be used if (!empty($this->screenitem['real_resourceid'])) { $this->screenitem['resourceid'] = $this->screenitem['real_resourceid']; } if ($this->screenitem['dynamic'] == SCREEN_DYNAMIC_ITEM && !empty($this->hostid)) { $newitemid = get_same_item_for_host($this->screenitem['resourceid'], $this->hostid); $this->screenitem['resourceid'] = !empty($newitemid) ? $newitemid : 0; } if ($this->screenitem['resourceid'] == 0) { $table = (new CTableInfo())->setHeader([_('Timestamp'), _('Item')]); return $this->getOutput($table); } $items = CMacrosResolverHelper::resolveItemNames([get_item_by_itemid($this->screenitem['resourceid'])]); $item = reset($items); switch ($item['value_type']) { case ITEM_VALUE_TYPE_TEXT: case ITEM_VALUE_TYPE_LOG: $orderField = 'id'; break; case ITEM_VALUE_TYPE_FLOAT: case ITEM_VALUE_TYPE_UINT64: default: $orderField = ['itemid', 'clock']; } $host = get_host_by_itemid($this->screenitem['resourceid']); $table = (new CTableInfo())->setHeader([_('Timestamp'), _('Value')]); $stime = zbxDateToTime($this->timeline['stime']); $histories = API::History()->get(['history' => $item['value_type'], 'itemids' => $this->screenitem['resourceid'], 'output' => API_OUTPUT_EXTEND, 'sortorder' => ZBX_SORT_DOWN, 'sortfield' => $orderField, 'limit' => $this->screenitem['elements'], 'time_from' => $stime, 'time_till' => $stime + $this->timeline['period']]); foreach ($histories as $history) { switch ($item['value_type']) { case ITEM_VALUE_TYPE_FLOAT: sscanf($history['value'], '%f', $value); break; case ITEM_VALUE_TYPE_TEXT: case ITEM_VALUE_TYPE_STR: case ITEM_VALUE_TYPE_LOG: $value = $this->screenitem['style'] ? new CJsScript($history['value']) : $history['value']; break; default: $value = $history['value']; break; } if ($item['valuemapid'] > 0) { $value = applyValueMap($value, $item['valuemapid']); } if ($this->screenitem['style'] == 0) { $value = new CPre($value); } $table->addRow([zbx_date2str(DATE_TIME_FORMAT_SECONDS, $history['clock']), $value]); } $footer = (new CList())->addItem(_s('Updated: %s', zbx_date2str(TIME_FORMAT_SECONDS)))->addClass(ZBX_STYLE_DASHBRD_WIDGET_FOOT); return $this->getOutput((new CUiWidget(uniqid(), [$table, $footer]))->setHeader($host['name'] . NAME_DELIMITER . $item['name_expanded'])); }
/** * Process screen. * * @return CDiv (screen inside container) */ public function get() { // if screen is defined in template, then 'real_resourceid' is defined and should be used if (!empty($this->screenitem['real_resourceid'])) { $this->screenitem['resourceid'] = $this->screenitem['real_resourceid']; } if ($this->screenitem['dynamic'] == SCREEN_DYNAMIC_ITEM && !empty($this->hostid)) { $newitemid = get_same_item_for_host($this->screenitem['resourceid'], $this->hostid); $this->screenitem['resourceid'] = !empty($newitemid) ? $newitemid : 0; } if ($this->screenitem['resourceid'] == 0) { $table = new CTableInfo(_('No values found.')); $table->setHeader(array(_('Timestamp'), _('Item'))); return $this->getOutput($table); } $items = CMacrosResolverHelper::resolveItemNames(array(get_item_by_itemid($this->screenitem['resourceid']))); $item = reset($items); switch ($item['value_type']) { case ITEM_VALUE_TYPE_TEXT: case ITEM_VALUE_TYPE_LOG: $orderField = 'id'; break; case ITEM_VALUE_TYPE_FLOAT: case ITEM_VALUE_TYPE_UINT64: default: $orderField = array('itemid', 'clock'); } $host = get_host_by_itemid($this->screenitem['resourceid']); $table = new CTableInfo(_('No values found.')); $table->setHeader(array(_('Timestamp'), $host['name'] . NAME_DELIMITER . $item['name_expanded'])); $stime = zbxDateToTime($this->timeline['stime']); $histories = API::History()->get(array('history' => $item['value_type'], 'itemids' => $this->screenitem['resourceid'], 'output' => API_OUTPUT_EXTEND, 'sortorder' => ZBX_SORT_DOWN, 'sortfield' => $orderField, 'limit' => $this->screenitem['elements'], 'time_from' => $stime, 'time_till' => $stime + $this->timeline['period'])); foreach ($histories as $history) { switch ($item['value_type']) { case ITEM_VALUE_TYPE_FLOAT: sscanf($history['value'], '%f', $value); break; case ITEM_VALUE_TYPE_TEXT: case ITEM_VALUE_TYPE_STR: case ITEM_VALUE_TYPE_LOG: $value = $this->screenitem['style'] ? new CJsScript($history['value']) : $history['value']; break; default: $value = $history['value']; break; } if ($item['valuemapid'] > 0) { $value = applyValueMap($value, $item['valuemapid']); } $class = $this->screenitem['style'] ? null : 'pre'; $table->addRow(array(zbx_date2str(DATE_TIME_FORMAT_SECONDS, $history['clock']), new CCol($value, $class))); } return $this->getOutput($table); }
public function addItem($itemid, $calc_fnc = CALC_FNC_AVG, $color = null, $type = null) { $items = CMacrosResolverHelper::resolveItemNames(array(get_item_by_itemid($itemid))); $this->items[$this->num] = reset($items); $host = get_host_by_hostid($this->items[$this->num]['hostid']); $this->items[$this->num]['host'] = $host['host']; $this->items[$this->num]['hostname'] = $host['name']; $this->items[$this->num]['color'] = is_null($color) ? 'Dark Green' : $color; $this->items[$this->num]['calc_fnc'] = is_null($calc_fnc) ? CALC_FNC_AVG : $calc_fnc; $this->items[$this->num]['calc_type'] = is_null($type) ? GRAPH_ITEM_SIMPLE : $type; $this->num++; }
/** * Get favourite graphs and simple graph data. * * @return array['graphs'] * @return array['simpleGraphs'] */ function getFavouriteGraphsData() { $graphs = $simpeGraphs = []; $favourites = CFavorite::get('web.favorite.graphids'); if ($favourites) { $graphIds = $itemIds = $dbGraphs = $dbItems = []; foreach ($favourites as $favourite) { if ($favourite['source'] === 'itemid') { $itemIds[$favourite['value']] = $favourite['value']; } else { $graphIds[$favourite['value']] = $favourite['value']; } } if ($graphIds) { $dbGraphs = API::Graph()->get(['output' => ['graphid', 'name'], 'selectHosts' => ['hostid', 'name'], 'expandName' => true, 'graphids' => $graphIds, 'preservekeys' => true]); } if ($itemIds) { $dbItems = API::Item()->get(['output' => ['itemid', 'hostid', 'name', 'key_'], 'selectHosts' => ['hostid', 'name'], 'itemids' => $itemIds, 'webitems' => true, 'preservekeys' => true]); $dbItems = CMacrosResolverHelper::resolveItemNames($dbItems); } foreach ($favourites as $favourite) { $sourceId = $favourite['value']; if ($favourite['source'] === 'itemid') { if (isset($dbItems[$sourceId])) { $dbItem = $dbItems[$sourceId]; $dbHost = reset($dbItem['hosts']); $simpeGraphs[] = ['id' => $sourceId, 'label' => $dbHost['name'] . NAME_DELIMITER . $dbItem['name_expanded']]; } } else { if (isset($dbGraphs[$sourceId])) { $dbGraph = $dbGraphs[$sourceId]; $dbHost = reset($dbGraph['hosts']); $graphs[] = ['id' => $sourceId, 'label' => $dbHost['name'] . NAME_DELIMITER . $dbGraph['name']]; } } } } return ['graphs' => $graphs, 'simpleGraphs' => $simpeGraphs]; }
/** * Retrieves items created for item prototype given as resource for this screen item * and returns array of the item IDs, ordered by item name. * * @return array */ protected function getCreatedItemIds() { if (!$this->createdItemIds) { $itemPrototype = $this->getItemPrototype(); if ($itemPrototype) { // get all created (discovered) items for current host $allCreatedItems = API::Item()->get(array('output' => array('itemid', 'name', 'key_', 'hostid'), 'hostids' => array($itemPrototype['discoveryRule']['hostid']), 'selectItemDiscovery' => array('itemid', 'parent_itemid'), 'filter' => array('flags' => ZBX_FLAG_DISCOVERY_CREATED))); // collect those items where parent item is item prototype selected for this screen item as resource $createdItems = array(); foreach ($allCreatedItems as $item) { if ($item['itemDiscovery']['parent_itemid'] == $itemPrototype['itemid']) { $createdItems[] = $item; } } $createdItems = CMacrosResolverHelper::resolveItemNames($createdItems); foreach ($createdItems as $item) { $this->createdItemIds[$item['itemid']] = $item['name_expanded']; } natsort($this->createdItemIds); $this->createdItemIds = array_keys($this->createdItemIds); } } return $this->createdItemIds; }
} } } else { if (preg_match('/^([a-z]+)\\[([=><]{1,2})\\]$/i', $exprType, $matches)) { $function = $matches[1]; $operator = $matches[2]; if (!isset($functions[$exprType])) { unset($function); } } // fetch item $item = API::Item()->get(array('output' => array('itemid', 'hostid', 'name', 'key_', 'value_type'), 'selectHosts' => array('host', 'name'), 'itemids' => $itemId, 'webitems' => true, 'filter' => array('flags' => null))); $item = reset($item); } if ($itemId) { $items = CMacrosResolverHelper::resolveItemNames(array($item)); $item = $items[0]; $itemValueType = $item['value_type']; $itemKey = $item['key_']; $itemHostData = reset($item['hosts']); $description = $itemHostData['name'] . NAME_DELIMITER . $item['name_expanded']; } else { $itemKey = ''; $description = ''; $itemValueType = null; } if (is_null($paramType) && isset($functions[$exprType]['params']['M'])) { $paramType = is_array($functions[$exprType]['params']['M']) ? reset($functions[$exprType]['params']['M']) : $functions[$exprType]['params']['M']; } elseif (is_null($paramType)) { $paramType = PARAM_TYPE_TIME; }
function make_graph_submenu() { $graphids = array(); $itemids = array(); $favGraphs = array(); $fav_graphs = CFavorite::get('web.favorite.graphids'); if (!$fav_graphs) { return $favGraphs; } foreach ($fav_graphs as $favorite) { if ('itemid' == $favorite['source']) { $itemids[$favorite['value']] = $favorite['value']; } else { $graphids[$favorite['value']] = $favorite['value']; } } if ($graphids) { $options = array('graphids' => $graphids, 'selectHosts' => array('hostid', 'host'), 'output' => array('graphid', 'name'), 'expandName' => true); $graphs = API::Graph()->get($options); $graphs = zbx_toHash($graphs, 'graphid'); } if ($itemids) { $items = API::Item()->get(array('output' => array('itemid', 'hostid', 'name', 'key_'), 'selectHosts' => array('hostid', 'host'), 'itemids' => $itemids, 'webitems' => true, 'preservekeys' => true)); $items = CMacrosResolverHelper::resolveItemNames($items); } foreach ($fav_graphs as $favorite) { $source = $favorite['source']; $sourceid = $favorite['value']; if ($source == 'itemid') { if (!isset($items[$sourceid])) { continue; } $item_added = true; $item = $items[$sourceid]; $host = reset($item['hosts']); $favGraphs[] = array('name' => $host['host'] . NAME_DELIMITER . $item['name_expanded'], 'favobj' => 'itemid', 'favid' => $sourceid, 'favaction' => 'remove'); } else { if (!isset($graphs[$sourceid])) { continue; } $graph_added = true; $graph = $graphs[$sourceid]; $ghost = reset($graph['hosts']); $favGraphs[] = array('name' => $ghost['host'] . NAME_DELIMITER . $graph['name'], 'favobj' => 'graphid', 'favid' => $sourceid, 'favaction' => 'remove'); } } if (isset($graph_added)) { $favGraphs[] = array('name' => _('Remove') . ' ' . _('All') . ' ' . _('Graphs'), 'favobj' => 'graphid', 'favid' => 0, 'favaction' => 'remove'); } if (isset($item_added)) { $favGraphs[] = array('name' => _('Remove') . ' ' . _('All') . ' ' . _('Simple graphs'), 'favobj' => 'itemid', 'favid' => 0, 'favaction' => 'remove'); } return $favGraphs; }
} } } else { if (preg_match('/^([a-z]+)\\[([=><]{1,2})\\]$/i', $exprType, $matches)) { $function = $matches[1]; $operator = $matches[2]; if (!isset($functions[$exprType])) { unset($function); } } // fetch item $item = API::Item()->get(['output' => ['itemid', 'hostid', 'name', 'key_', 'value_type'], 'selectHosts' => ['host', 'name'], 'itemids' => $itemId, 'webitems' => true, 'filter' => ['flags' => null]]); $item = reset($item); } if ($itemId) { $items = CMacrosResolverHelper::resolveItemNames([$item]); $item = $items[0]; $itemValueType = $item['value_type']; $itemKey = $item['key_']; $itemHostData = reset($item['hosts']); $description = $itemHostData['name'] . NAME_DELIMITER . $item['name_expanded']; } else { $itemKey = ''; $description = ''; $itemValueType = null; } if (is_null($paramType) && isset($functions[$exprType]['params']['M'])) { $paramType = is_array($functions[$exprType]['params']['M']) ? reset($functions[$exprType]['params']['M']) : $functions[$exprType]['params']['M']; } elseif (is_null($paramType)) { $paramType = PARAM_TYPE_TIME; }
if ($hostDiscoveryRules) { $hostDiscoveryRules = CMacrosResolverHelper::resolveItemNames($hostDiscoveryRules); $discoveryRuleList = array(); foreach ($hostDiscoveryRules as $discoveryRule) { $discoveryRuleList[$discoveryRule['itemid']] = $discoveryRule['name_expanded']; } order_result($discoveryRuleList); $hostDiscoveryRuleids = array_keys($discoveryRuleList); $listBox = new CListBox('discoveryRules', null, 8); $listBox->setAttribute('disabled', 'disabled'); $listBox->addItems($discoveryRuleList); $templateList->addRow(_('Discovery rules'), $listBox); // item prototypes $hostItemPrototypes = API::ItemPrototype()->get(array('hostids' => $templateid, 'discoveryids' => $hostDiscoveryRuleids, 'inherited' => false, 'output' => API_OUTPUT_EXTEND)); if ($hostItemPrototypes) { $hostItemPrototypes = CMacrosResolverHelper::resolveItemNames($hostItemPrototypes); $prototypeList = array(); foreach ($hostItemPrototypes as $itemPrototype) { $prototypeList[$itemPrototype['itemid']] = $itemPrototype['name_expanded']; } order_result($prototypeList); $listBox = new CListBox('itemsPrototypes', null, 8); $listBox->setAttribute('disabled', 'disabled'); $listBox->addItems($prototypeList); $templateList->addRow(_('Item prototypes'), $listBox); } // Trigger prototypes $hostTriggerPrototypes = API::TriggerPrototype()->get(array('hostids' => $templateid, 'discoveryids' => $hostDiscoveryRuleids, 'inherited' => false, 'output' => API_OUTPUT_EXTEND)); if (!empty($hostTriggerPrototypes)) { $prototypeList = array(); foreach ($hostTriggerPrototypes as $triggerPrototype) {
/** * Retrieve overview table object for items. * * @param array $hostIds * @param string $application name of application to filter * @param int $viewMode * * @return CTableInfo */ function getItemsDataOverview($hostIds, $application, $viewMode) { $sqlFrom = ''; $sqlWhere = ''; if ($application !== '') { $sqlFrom = 'applications a,items_applications ia,'; $sqlWhere = ' AND i.itemid=ia.itemid AND a.applicationid=ia.applicationid AND a.name=' . zbx_dbstr($application); } $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, 'selectScreens' => $viewMode == STYLE_LEFT ? API_OUTPUT_COUNT : null)); $items = array(); foreach ($dbItems as $dbItem) { $name = $dbItem['name_expanded']; $dbItem['hostname'] = get_node_name_by_elid($dbItem['hostid'], null, NAME_DELIMITER) . $dbItem['hostname']; $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(getMenuPopupHost($host, $scripts[$hostId])); $tableRow = array(new CCol($name)); foreach ($items as $ithosts) { $tableRow = getItemDataOverviewCells($tableRow, $ithosts, $hostName); } $table->addRow($tableRow); } } return $table; }
$expressions[$id]['view'] = trim($value); } } else { $description = get_request('description', ''); $expressions = get_request('expressions', array()); $type = get_request('type', 0); $priority = get_request('priority', 0); $comments = get_request('comments', ''); $url = get_request('url', ''); $status = get_request('status', 0); } $keys = get_request('keys', array()); $frmTRLog->addRow(_('Description'), new CTextBox('description', $description, 80)); $itemName = ''; $dbItems = DBfetchArray(DBselect('SELECT itemid,hostid,name,key_,templateid' . ' FROM items' . ' WHERE itemid=' . zbx_dbstr($itemid))); $dbItems = CMacrosResolverHelper::resolveItemNames($dbItems); $dbItem = reset($dbItems); if ($dbItem['templateid']) { $template = get_realhost_by_itemid($dbItem['templateid']); $itemName = $template['host'] . NAME_DELIMITER . $dbItem['name_expanded']; } else { $itemName = $dbItem['name_expanded']; } $ctb = new CTextBox('item', $itemName, 80); $ctb->setAttribute('id', 'item'); $ctb->setAttribute('disabled', 'disabled'); $script = "javascript: return PopUp('popup.php?dstfrm=" . $frmTRLog->getName() . "&dstfld1=itemid&dstfld2=item&srctbl=items&srcfld1=itemid&srcfld2=name',800,450);"; $cbtn = new CSubmit('select_item', _('Select'), $script); $frmTRLog->addRow(_('Item'), array($ctb, $cbtn)); $frmTRLog->addVar('itemid', $itemid); $exp_select = new CComboBox('expr_type');
/** * 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 = $css = $style = null; $desc = $menuPopup = $triggerItems = $acknowledge = array(); // for how long triggers should blink on status change (set by user in administration->general) $config = select_config(); 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 = DBfetchArray(DBselect('SELECT DISTINCT i.itemid,i.hostid,i.name,i.key_,i.value_type' . ' FROM items i,functions f' . ' WHERE f.itemid=i.itemid' . ' AND f.triggerid=' . zbx_dbstr($trigger['triggerid']))); $dbItems = CMacrosResolverHelper::resolveItemNames($dbItems); foreach ($dbItems as $dbItem) { $triggerItems[] = array('name' => $dbItem['name_expanded'], 'params' => array('action' => in_array($dbItem['value_type'], array(ITEM_VALUE_TYPE_FLOAT, ITEM_VALUE_TYPE_UINT64)) ? 'showgraph' : 'showlatest', 'itemid' => $dbItem['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; }
/** * Get particular screen object. * * @static * * @param array $options * @param int $options['resourcetype'] * @param int $options['screenitemid'] * @param int $options['hostid'] * @param array $options['screen'] * @param int $options['screenid'] * * @return CScreenBase */ public static function getScreen(array $options = array()) { // get resourcetype from screenitem if (empty($options['screenitem']) && !empty($options['screenitemid'])) { if (!empty($options['hostid'])) { $options['screenitem'] = API::TemplateScreenItem()->get(array('screenitemids' => $options['screenitemid'], 'hostids' => $options['hostid'], 'output' => API_OUTPUT_EXTEND)); } else { $options['screenitem'] = API::ScreenItem()->get(array('screenitemids' => $options['screenitemid'], 'output' => API_OUTPUT_EXTEND)); } $options['screenitem'] = reset($options['screenitem']); } if (zbx_empty($options['resourcetype']) && !zbx_empty($options['screenitem']['resourcetype'])) { $options['resourcetype'] = $options['screenitem']['resourcetype']; } if (zbx_empty($options['resourcetype'])) { return null; } // get screen switch ($options['resourcetype']) { case SCREEN_RESOURCE_GRAPH: return new CScreenGraph($options); case SCREEN_RESOURCE_SIMPLE_GRAPH: return new CScreenSimpleGraph($options); case SCREEN_RESOURCE_MAP: return new CScreenMap($options); case SCREEN_RESOURCE_PLAIN_TEXT: return new CScreenPlainText($options); case SCREEN_RESOURCE_HOSTS_INFO: return new CScreenHostsInfo($options); case SCREEN_RESOURCE_TRIGGERS_INFO: return new CScreenTriggersInfo($options); case SCREEN_RESOURCE_SERVER_INFO: return new CScreenServerInfo($options); case SCREEN_RESOURCE_CLOCK: return new CScreenClock($options); case SCREEN_RESOURCE_SCREEN: return new CScreenScreen($options); case SCREEN_RESOURCE_TRIGGERS_OVERVIEW: return new CScreenTriggersOverview($options); case SCREEN_RESOURCE_DATA_OVERVIEW: return new CScreenDataOverview($options); case SCREEN_RESOURCE_URL: $options = self::appendTemplatedScreenOption($options); return new CScreenUrl($options); case SCREEN_RESOURCE_ACTIONS: return new CScreenActions($options); case SCREEN_RESOURCE_EVENTS: return new CScreenEvents($options); case SCREEN_RESOURCE_HOSTGROUP_TRIGGERS: return new CScreenHostgroupTriggers($options); case SCREEN_RESOURCE_SYSTEM_STATUS: return new CScreenSystemStatus($options); case SCREEN_RESOURCE_HOST_TRIGGERS: return new CScreenHostTriggers($options); case SCREEN_RESOURCE_HISTORY: // TODO: pass the items from the outside instead of retrieving them by ids if (isset($options['itemids'])) { $items = API::Item()->get(array('itemids' => $options['itemids'], 'webitems' => true, 'selectHosts' => array('name'), 'output' => array('itemid', 'hostid', 'name', 'key_', 'value_type', 'valuemapid'), 'preservekeys' => true)); $items = CMacrosResolverHelper::resolveItemNames($items); $options['items'] = $items; unset($options['itemids']); } return new CScreenHistory($options); case SCREEN_RESOURCE_CHART: return new CScreenChart($options); case SCREEN_RESOURCE_LLD_GRAPH: $options = self::appendTemplatedScreenOption($options); return new CScreenLldGraph($options); case SCREEN_RESOURCE_LLD_SIMPLE_GRAPH: $options = self::appendTemplatedScreenOption($options); return new CScreenLldSimpleGraph($options); default: return null; } }
**/ require_once dirname(__FILE__) . '/include/config.inc.php'; require_once dirname(__FILE__) . '/include/triggers.inc.php'; require_once dirname(__FILE__) . '/include/js.inc.php'; $dstfrm = get_request('dstfrm', 0); $page['title'] = _('Graph item'); $page['file'] = 'popup_bitem.php'; define('ZBX_PAGE_NO_MENU', 1); require_once dirname(__FILE__) . '/include/page_header.php'; // VAR TYPE OPTIONAL FLAGS VALIDATION EXCEPTION $fields = array('dstfrm' => array(T_ZBX_STR, O_MAND, P_SYS, NOT_EMPTY, null), 'config' => array(T_ZBX_INT, O_OPT, P_SYS, IN('0,1,2,3'), null), 'gid' => array(T_ZBX_INT, O_OPT, P_SYS, BETWEEN(0, 65535), null), 'list_name' => array(T_ZBX_STR, O_OPT, P_SYS, NOT_EMPTY, 'isset({save})&&isset({gid})'), 'caption' => array(T_ZBX_STR, O_OPT, null, null, null), 'itemid' => array(T_ZBX_INT, O_OPT, P_SYS, DB_ID . '({}!=0)', 'isset({save})', _('Parameter')), 'color' => array(T_ZBX_CLR, O_OPT, null, null, 'isset({save})', _('Colour')), 'calc_fnc' => array(T_ZBX_INT, O_OPT, null, IN('0,1,2,4,7,9'), 'isset({save})'), 'axisside' => array(T_ZBX_INT, O_OPT, null, IN(GRAPH_YAXIS_SIDE_LEFT . ',' . GRAPH_YAXIS_SIDE_RIGHT), null), 'add' => array(T_ZBX_STR, O_OPT, P_SYS | P_ACT, null, null), 'save' => array(T_ZBX_STR, O_OPT, P_SYS | P_ACT, null, null), 'form' => array(T_ZBX_STR, O_OPT, P_SYS, null, null), 'form_refresh' => array(T_ZBX_STR, O_OPT, null, null, null), 'host' => array(T_ZBX_STR, O_OPT, null, null, null), 'name' => array(T_ZBX_STR, O_OPT, null, null, null)); check_fields($fields); $_REQUEST['caption'] = get_request('caption', ''); $_REQUEST['axisside'] = get_request('axisside', GRAPH_YAXIS_SIDE_LEFT); if (zbx_empty($_REQUEST['caption']) && isset($_REQUEST['itemid']) && $_REQUEST['itemid'] > 0) { $items = CMacrosResolverHelper::resolveItemNames(array(get_item_by_itemid($_REQUEST['itemid']))); $item = reset($items); $_REQUEST['caption'] = $item['name_expanded']; } insert_js_function('add_bitem'); insert_js_function('update_bitem'); if (isset($_REQUEST['save']) && !isset($_REQUEST['gid'])) { insert_js("add_bitem(" . zbx_jsvalue($_REQUEST['dstfrm']) . "," . zbx_jsvalue($_REQUEST['caption']) . ",'" . $_REQUEST['itemid'] . "','" . $_REQUEST['color'] . "'," . $_REQUEST['calc_fnc'] . "," . $_REQUEST['axisside'] . ");\n"); } if (isset($_REQUEST['save']) && isset($_REQUEST['gid'])) { insert_js("update_bitem(" . zbx_jsvalue($_REQUEST['dstfrm']) . "," . zbx_jsvalue($_REQUEST['list_name']) . ",'" . $_REQUEST['gid'] . "'," . zbx_jsvalue($_REQUEST['caption']) . ",'" . $_REQUEST['itemid'] . "','" . $_REQUEST['color'] . "'," . $_REQUEST['calc_fnc'] . "," . $_REQUEST['axisside'] . ");\n"); } else { echo SBR; $frmGItem = new CFormTable(_('New item for the graph')); $frmGItem->setName('graph_item'); $frmGItem->setHelp('web.graph.item.php');
/** * 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', [ZBX_FLAG_DISCOVERY_NORMAL, ZBX_FLAG_DISCOVERY_CREATED]) . $sqlWhere)); $dbItems = CMacrosResolverHelper::resolveItemNames($dbItems); CArrayHelper::sort($dbItems, [['field' => 'name_expanded', 'order' => ZBX_SORT_UP], ['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(['output' => ['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 = []; $item_counter = []; $host_items = []; foreach ($dbItems as $dbItem) { $item_name = $dbItem['name_expanded']; $host_name = $dbItem['hostname']; $hostNames[$dbItem['hostid']] = $host_name; if (!array_key_exists($host_name, $item_counter)) { $item_counter[$host_name] = []; } if (!array_key_exists($item_name, $item_counter[$host_name])) { $item_counter[$host_name][$item_name] = 0; } if (!array_key_exists($item_name, $host_items) || !array_key_exists($host_name, $host_items[$item_name])) { $host_items[$item_name][$host_name] = []; } // a little tricky check for attempt to overwrite active trigger (value=1) with // inactive or active trigger with lower priority. if (!array_key_exists($dbItem['itemid'], $host_items[$item_name][$host_name]) || ($host_items[$item_name][$host_name][$dbItem['itemid']]['tr_value'] == TRIGGER_VALUE_FALSE && $dbItem['tr_value'] == TRIGGER_VALUE_TRUE || ($host_items[$item_name][$host_name][$dbItem['itemid']]['tr_value'] == TRIGGER_VALUE_FALSE || $dbItem['tr_value'] == TRIGGER_VALUE_TRUE) && $dbItem['priority'] > $host_items[$item_name][$host_name][$dbItem['itemid']]['severity'])) { if (array_key_exists($dbItem['itemid'], $host_items[$item_name][$host_name])) { $item_place = $host_items[$item_name][$host_name][$dbItem['itemid']]['item_place']; } else { $item_place = $item_counter[$host_name][$item_name]; $item_counter[$host_name][$item_name]++; } $items[$item_name][$item_place][$host_name] = ['itemid' => $dbItem['itemid'], 'value_type' => $dbItem['value_type'], 'value' => isset($history[$dbItem['itemid']]) ? $history[$dbItem['itemid']][0]['value'] : null, 'units' => $dbItem['units'], 'valuemapid' => $dbItem['valuemapid'], 'severity' => $dbItem['priority'], 'tr_value' => $dbItem['tr_value'], 'triggerid' => $dbItem['triggerid'], 'item_place' => $item_place]; $host_items[$item_name][$host_name][$dbItem['itemid']] = $items[$item_name][$item_place][$host_name]; } } $table = new CTableInfo(); if (empty($hostNames)) { return $table; } $table->makeVerticalRotation(); order_result($hostNames); if ($viewMode == STYLE_TOP) { $header = [_('Items')]; foreach ($hostNames as $hostName) { $header[] = (new CColHeader($hostName))->addClass('vertical_rotation'); } $table->setHeader($header); foreach ($items as $item_name => $item_data) { foreach ($item_data as $ithosts) { $tableRow = [nbsp($item_name)]; foreach ($hostNames as $hostName) { $tableRow = getItemDataOverviewCells($tableRow, $ithosts, $hostName); } $table->addRow($tableRow); } } } else { $scripts = API::Script()->getScriptsByHosts(zbx_objectValues($hosts, 'hostid')); $header = [_('Hosts')]; foreach ($items as $item_name => $item_data) { foreach ($item_data as $ithosts) { $header[] = (new CColHeader($item_name))->addClass('vertical_rotation'); } } $table->setHeader($header); foreach ($hostNames as $hostId => $hostName) { $host = $hosts[$hostId]; $name = (new CSpan($host['name']))->addClass(ZBX_STYLE_LINK_ACTION)->setMenuPopup(CMenuPopupHelper::getHost($host, $scripts[$hostId])); $tableRow = [(new CCol($name))->addClass(ZBX_STYLE_NOWRAP)]; foreach ($items as $item_data) { foreach ($item_data as $ithosts) { $tableRow = getItemDataOverviewCells($tableRow, $ithosts, $hostName); } } $table->addRow($tableRow); } } return $table; }
/** * Process screen. * * @return CDiv (screen inside container) */ public function get() { $output = []; $items = API::Item()->get(['output' => ['itemid', 'hostid', 'name', 'key_', 'value_type', 'valuemapid'], 'selectHosts' => ['name'], 'itemids' => $this->itemids, 'webitems' => true, 'preservekeys' => true]); $items = CMacrosResolverHelper::resolveItemNames($items); $stime = zbxDateToTime($this->timeline['stime']); $firstItem = reset($items); $iv_string = [ITEM_VALUE_TYPE_LOG => 1, ITEM_VALUE_TYPE_TEXT => 1]; $iv_numeric = [ITEM_VALUE_TYPE_FLOAT => 1, ITEM_VALUE_TYPE_UINT64 => 1]; if ($this->action == HISTORY_VALUES || $this->action == HISTORY_LATEST) { $options = ['history' => $firstItem['value_type'], 'itemids' => $this->itemids, 'output' => API_OUTPUT_EXTEND, 'sortorder' => ZBX_SORT_DOWN]; if ($this->action == HISTORY_LATEST) { $options['limit'] = 500; } elseif ($this->action == HISTORY_VALUES) { $config = select_config(); // interval start value is non-inclusive, hence the + 1 second $options['time_from'] = $stime + 1; $options['time_till'] = $stime + $this->timeline['period']; $options['limit'] = $config['search_limit']; } // text log if (isset($iv_string[$firstItem['value_type']])) { $isManyItems = count($items) > 1; $useLogItem = $firstItem['value_type'] == ITEM_VALUE_TYPE_LOG; $useEventLogItem = strpos($firstItem['key_'], 'eventlog[') === 0; if (empty($this->plaintext)) { $historyTable = (new CTableInfo())->setHeader([(new CColHeader(_('Timestamp')))->addClass(ZBX_STYLE_CELL_WIDTH), $isManyItems ? _('Item') : null, $useLogItem ? (new CColHeader(_('Local time')))->addClass(ZBX_STYLE_CELL_WIDTH) : null, $useEventLogItem && $useLogItem ? (new CColHeader(_('Source')))->addClass(ZBX_STYLE_CELL_WIDTH) : null, $useEventLogItem && $useLogItem ? (new CColHeader(_('Severity')))->addClass(ZBX_STYLE_CELL_WIDTH) : null, $useEventLogItem && $useLogItem ? (new CColHeader(_('Event ID')))->addClass(ZBX_STYLE_CELL_WIDTH) : null, _('Value')]); } if ($this->filter !== '' && in_array($this->filterTask, [FILTER_TASK_SHOW, FILTER_TASK_HIDE])) { $options['search'] = ['value' => $this->filter]; if ($this->filterTask == FILTER_TASK_HIDE) { $options['excludeSearch'] = 1; } } $options['sortfield'] = 'id'; $historyData = API::History()->get($options); foreach ($historyData as $data) { $data['value'] = rtrim($data['value'], " \t\r\n"); if (empty($this->plaintext)) { $item = $items[$data['itemid']]; $host = reset($item['hosts']); $color = null; if ($this->filter !== '') { $haystack = mb_strtolower($data['value']); $needle = mb_strtolower($this->filter); $pos = mb_strpos($haystack, $needle); if ($pos !== false && $this->filterTask == FILTER_TASK_MARK) { $color = $this->markColor; } elseif ($pos === false && $this->filterTask == FILTER_TASK_INVERT_MARK) { $color = $this->markColor; } switch ($color) { case MARK_COLOR_RED: $color = ZBX_STYLE_RED; break; case MARK_COLOR_GREEN: $color = ZBX_STYLE_GREEN; break; case MARK_COLOR_BLUE: $color = ZBX_STYLE_BLUE; break; } } $row = []; $row[] = (new CCol(zbx_date2str(DATE_TIME_FORMAT_SECONDS, $data['clock'])))->addClass(ZBX_STYLE_NOWRAP)->addClass($color); if ($isManyItems) { $row[] = (new CCol($host['name'] . NAME_DELIMITER . $item['name_expanded']))->addClass($color); } if ($useLogItem) { $row[] = $data['timestamp'] != 0 ? (new CCol(zbx_date2str(DATE_TIME_FORMAT_SECONDS, $data['timestamp'])))->addClass(ZBX_STYLE_NOWRAP)->addClass($color) : ''; // if this is a eventLog item, showing additional info if ($useEventLogItem) { $row[] = (new CCol($data['source']))->addClass(ZBX_STYLE_NOWRAP)->addClass($color); $row[] = $data['severity'] != 0 ? (new CCol(get_item_logtype_description($data['severity'])))->addClass(ZBX_STYLE_NOWRAP)->addClass(get_item_logtype_style($data['severity'])) : ''; $row[] = $data['logeventid'] != 0 ? (new CCol($data['logeventid']))->addClass(ZBX_STYLE_NOWRAP)->addClass($color) : ''; } } $row[] = (new CCol(new CPre(zbx_nl2br($data['value']))))->addClass($color); $historyTable->addRow($row); } else { $output[] = zbx_date2str(DATE_TIME_FORMAT_SECONDS, $data['clock']) . ' ' . $data['clock'] . ' ' . htmlspecialchars($data['value']); } } if (empty($this->plaintext)) { $output[] = $historyTable; } } else { if (empty($this->plaintext)) { $historyTable = (new CTableInfo())->setHeader([(new CColHeader(_('Timestamp')))->addClass(ZBX_STYLE_CELL_WIDTH), _('Value')]); } $options['sortfield'] = ['itemid', 'clock']; $historyData = API::History()->get($options); foreach ($historyData as $data) { $item = $items[$data['itemid']]; $value = rtrim($data['value'], " \t\r\n"); // format the value as float if ($item['value_type'] == ITEM_VALUE_TYPE_FLOAT) { sscanf($data['value'], '%f', $value); } // html table if (empty($this->plaintext)) { if ($item['valuemapid']) { $value = applyValueMap($value, $item['valuemapid']); } $historyTable->addRow([(new CCol(zbx_date2str(DATE_TIME_FORMAT_SECONDS, $data['clock'])))->addClass(ZBX_STYLE_NOWRAP), new CPre(zbx_nl2br($value))]); } else { $output[] = zbx_date2str(DATE_TIME_FORMAT_SECONDS, $data['clock']) . ' ' . $data['clock'] . ' ' . htmlspecialchars($value); } } if (empty($this->plaintext)) { $output[] = $historyTable; } } } // time control if (!$this->plaintext && str_in_array($this->action, [HISTORY_VALUES, HISTORY_GRAPH, HISTORY_BATCH_GRAPH])) { $graphDims = getGraphDims(); $this->timeline['starttime'] = date(TIMESTAMP_FORMAT, get_min_itemclock_by_itemid($firstItem['itemid'])); $this->dataId = 'historyGraph'; $timeControlData = ['periodFixed' => CProfile::get('web.history.timelinefixed', 1), 'sliderMaximumTimePeriod' => ZBX_MAX_PERIOD]; if (($this->action == HISTORY_GRAPH || $this->action == HISTORY_BATCH_GRAPH) && !isset($iv_string[$firstItem['value_type']])) { $containerId = 'graph_cont1'; $output[] = (new CDiv())->addClass('center')->setId($containerId); $timeControlData['id'] = $this->getDataId(); $timeControlData['containerid'] = $containerId; $timeControlData['src'] = $this->getGraphUrl($this->itemids); $timeControlData['objDims'] = $graphDims; $timeControlData['loadSBox'] = 1; $timeControlData['loadImage'] = 1; $timeControlData['dynamic'] = 1; } else { $timeControlData['id'] = $this->getDataId(); $timeControlData['mainObject'] = 1; } if ($this->mode == SCREEN_MODE_JS) { $timeControlData['dynamic'] = 0; return 'timeControl.addObject("' . $this->getDataId() . '", ' . CJs::encodeJson($this->timeline) . ', ' . CJs::encodeJson($timeControlData) . ');'; } else { zbx_add_post_js('timeControl.addObject("' . $this->getDataId() . '", ' . CJs::encodeJson($this->timeline) . ', ' . CJs::encodeJson($timeControlData) . ');'); } } if (!empty($this->plaintext)) { return $output; } else { if ($this->mode != SCREEN_MODE_JS) { $flickerfreeData = ['itemids' => $this->itemids, 'action' => $this->action == HISTORY_BATCH_GRAPH ? HISTORY_GRAPH : $this->action, 'filter' => $this->filter, 'filterTask' => $this->filterTask, 'markColor' => $this->markColor]; return $this->getOutput($output, true, $flickerfreeData); } } }
/** * Create report bar for for "Compare values for multiple periods" * * @return object $reportForm */ function valueComparisonFormForMultiplePeriods() { $config = get_request('config', 1); $title = get_request('title', _('Report 3')); $xlabel = get_request('xlabel', ''); $ylabel = get_request('ylabel', ''); $scaletype = get_request('scaletype', TIMEPERIOD_TYPE_WEEKLY); $avgperiod = get_request('avgperiod', TIMEPERIOD_TYPE_DAILY); $report_timesince = get_request('report_timesince', date(TIMESTAMP_FORMAT_ZERO_TIME, time() - SEC_PER_DAY)); $report_timetill = get_request('report_timetill', date(TIMESTAMP_FORMAT_ZERO_TIME)); $itemId = get_request('itemid', 0); $hostids = get_request('hostids', array()); $hostids = zbx_toHash($hostids); $showlegend = get_request('showlegend', 0); $palette = get_request('palette', 0); $palettetype = get_request('palettetype', 0); $reportForm = new CFormTable(null, null, 'get'); $reportForm->setAttribute('name', 'zbx_report'); $reportForm->setAttribute('id', 'zbx_report'); if (isset($_REQUEST['report_show']) && $itemId) { $reportForm->addVar('report_show', 'show'); } $reportForm->addVar('config', $config); $reportForm->addVar('report_timesince', date(TIMESTAMP_FORMAT, $report_timesince)); $reportForm->addVar('report_timetill', date(TIMESTAMP_FORMAT, $report_timetill)); $reportForm->addRow(_('Title'), new CTextBox('title', $title, 40)); $reportForm->addRow(_('X label'), new CTextBox('xlabel', $xlabel, 40)); $reportForm->addRow(_('Y label'), new CTextBox('ylabel', $ylabel, 40)); $reportForm->addRow(_('Legend'), new CCheckBox('showlegend', $showlegend, null, 1)); $reportForm->addVar('sortorder', 0); $groupids = get_request('groupids', array()); $group_tb = new CTweenBox($reportForm, 'groupids', $groupids, 10); $options = array('real_hosts' => true, 'output' => 'extend'); $db_groups = API::HostGroup()->get($options); order_result($db_groups, 'name'); foreach ($db_groups as $gnum => $group) { $groupids[$group['groupid']] = $group['groupid']; $group_tb->addItem($group['groupid'], $group['name']); } $reportForm->addRow(_('Groups'), $group_tb->Get(_('Selected groups'), _('Other groups'))); $groupid = get_request('groupid', 0); $cmbGroups = new CComboBox('groupid', $groupid, 'submit()'); $cmbGroups->addItem(0, _('All')); foreach ($db_groups as $gnum => $group) { $cmbGroups->addItem($group['groupid'], $group['name']); } $td_groups = new CCol(array(_('Group'), SPACE, $cmbGroups)); $td_groups->setAttribute('style', 'text-align: right;'); $host_tb = new CTweenBox($reportForm, 'hostids', $hostids, 10); $options = array('real_hosts' => true, 'output' => array('hostid', 'name')); if ($groupid > 0) { $options['groupids'] = $groupid; } $db_hosts = API::Host()->get($options); $db_hosts = zbx_toHash($db_hosts, 'hostid'); order_result($db_hosts, 'name'); foreach ($db_hosts as $hnum => $host) { $host_tb->addItem($host['hostid'], $host['name']); } $options = array('real_hosts' => true, 'output' => array('hostid', 'name'), 'hostids' => $hostids); $db_hosts2 = API::Host()->get($options); order_result($db_hosts2, 'name'); foreach ($db_hosts2 as $hnum => $host) { if (!isset($db_hosts[$host['hostid']])) { $host_tb->addItem($host['hostid'], $host['name']); } } $reportForm->addRow(_('Hosts'), $host_tb->Get(_('Selected hosts'), array(_('Other hosts | Group') . SPACE, $cmbGroups))); $reporttimetab = new CTable(null, 'calendar'); $timeSinceRow = createDateSelector('report_timesince', $report_timesince, 'report_timetill'); array_unshift($timeSinceRow, _('From')); $reporttimetab->addRow($timeSinceRow); $timeTillRow = createDateSelector('report_timetill', $report_timetill, 'report_timesince'); array_unshift($timeTillRow, _('Till')); $reporttimetab->addRow($timeTillRow); $reportForm->addRow(_('Period'), $reporttimetab); $scale = new CComboBox('scaletype', $scaletype); $scale->addItem(TIMEPERIOD_TYPE_HOURLY, _('Hourly')); $scale->addItem(TIMEPERIOD_TYPE_DAILY, _('Daily')); $scale->addItem(TIMEPERIOD_TYPE_WEEKLY, _('Weekly')); $scale->addItem(TIMEPERIOD_TYPE_MONTHLY, _('Monthly')); $scale->addItem(TIMEPERIOD_TYPE_YEARLY, _('Yearly')); $reportForm->addRow(_('Scale'), $scale); $avgcmb = new CComboBox('avgperiod', $avgperiod); $avgcmb->addItem(TIMEPERIOD_TYPE_HOURLY, _('Hourly')); $avgcmb->addItem(TIMEPERIOD_TYPE_DAILY, _('Daily')); $avgcmb->addItem(TIMEPERIOD_TYPE_WEEKLY, _('Weekly')); $avgcmb->addItem(TIMEPERIOD_TYPE_MONTHLY, _('Monthly')); $avgcmb->addItem(TIMEPERIOD_TYPE_YEARLY, _('Yearly')); $reportForm->addRow(_('Average by'), $avgcmb); $itemName = ''; if ($itemId) { $items = CMacrosResolverHelper::resolveItemNames(array(get_item_by_itemid($itemId))); $item = reset($items); $itemName = $item['name_expanded']; } $itemidVar = new CVar('itemid', $itemId, 'itemid'); $reportForm->addItem($itemidVar); $txtCondVal = new CTextBox('item_name', $itemName, 50, 'yes'); $txtCondVal->setAttribute('id', 'item_name'); $btnSelect = new CButton('btn1', _('Select'), 'return PopUp("popup.php?dstfrm=' . $reportForm->GetName() . '&dstfld1=itemid' . '&dstfld2=item_name' . '&srctbl=items' . '&srcfld1=itemid' . '&srcfld2=name' . '&monitored_hosts=1");', 'T'); $reportForm->addRow(_('Item'), array($txtCondVal, $btnSelect)); $paletteCmb = new CComboBox('palette', $palette); $paletteCmb->addItem(0, _s('Palette #%1$s', 1)); $paletteCmb->addItem(1, _s('Palette #%1$s', 2)); $paletteCmb->addItem(2, _s('Palette #%1$s', 3)); $paletteCmb->addItem(3, _s('Palette #%1$s', 4)); $paletteTypeCmb = new CComboBox('palettetype', $palettetype); $paletteTypeCmb->addItem(0, _('Middle')); $paletteTypeCmb->addItem(1, _('Darken')); $paletteTypeCmb->addItem(2, _('Brighten')); $reportForm->addRow(_('Palette'), array($paletteCmb, $paletteTypeCmb)); $reportForm->addItemToBottomRow(new CSubmit('report_show', _('Show'))); $reset = new CButton('reset', _('Reset')); $reset->setType('reset'); $reportForm->addItemToBottomRow($reset); return $reportForm; }
/** * Init screen data. * * @param array $options * @param array $options['itemids'] * @param string $options['filter'] * @param int $options['filterTask'] * @param int $options['markColor'] * @param boolean $options['plaintext'] * @param array $options['items'] * @param array $options['item'] */ public function __construct(array $options = array()) { parent::__construct($options); $this->resourcetype = SCREEN_RESOURCE_HISTORY; // mandatory $this->itemids = isset($options['itemids']) ? $options['itemids'] : null; $this->filter = isset($options['filter']) ? $options['filter'] : null; $this->filterTask = isset($options['filter_task']) ? $options['filter_task'] : null; $this->markColor = isset($options['mark_color']) ? $options['mark_color'] : MARK_COLOR_RED; // optional $this->items = isset($options['items']) ? $options['items'] : null; $this->item = isset($options['item']) ? $options['item'] : null; $this->plaintext = isset($options['plaintext']) ? $options['plaintext'] : false; if (empty($this->items)) { $this->items = API::Item()->get(array('nodeids' => get_current_nodeid(), 'itemids' => $this->itemids, 'webitems' => true, 'selectHosts' => array('name'), 'output' => array('itemid', 'hostid', 'name', 'key_', 'value_type', 'valuemapid'), 'preservekeys' => true)); $this->items = CMacrosResolverHelper::resolveItemNames($this->items); $this->item = reset($this->items); } }
require_once dirname(__FILE__) . '/include/config.inc.php'; require_once dirname(__FILE__) . '/include/triggers.inc.php'; require_once dirname(__FILE__) . '/include/js.inc.php'; $dstfrm = getRequest('dstfrm', 0); $page['title'] = _('Graph item'); $page['file'] = 'popup_bitem.php'; define('ZBX_PAGE_NO_MENU', 1); require_once dirname(__FILE__) . '/include/page_header.php'; // VAR TYPE OPTIONAL FLAGS VALIDATION EXCEPTION $fields = array('dstfrm' => array(T_ZBX_STR, O_MAND, P_SYS, NOT_EMPTY, null), 'config' => array(T_ZBX_INT, O_OPT, P_SYS, IN('0,1,2,3'), null), 'gid' => array(T_ZBX_INT, O_OPT, P_SYS, DB_ID . '({} != 0)', null), 'list_name' => array(T_ZBX_STR, O_OPT, P_SYS, NOT_EMPTY, '(isset({add}) || isset({update})) && isset({gid})'), 'caption' => array(T_ZBX_STR, O_OPT, null, null, null), 'itemid' => array(T_ZBX_INT, O_OPT, P_SYS, DB_ID . '({} != 0)', 'isset({add}) || isset({update})', _('Parameter')), 'color' => array(T_ZBX_CLR, O_OPT, null, null, 'isset({add}) || isset({update})', _('Colour')), 'calc_fnc' => array(T_ZBX_INT, O_OPT, null, IN('0,1,2,4,7,9'), 'isset({add}) || isset({update})'), 'axisside' => array(T_ZBX_INT, O_OPT, null, IN(GRAPH_YAXIS_SIDE_LEFT . ',' . GRAPH_YAXIS_SIDE_RIGHT), null), 'add' => array(T_ZBX_STR, O_OPT, P_SYS | P_ACT, null, null), 'update' => array(T_ZBX_STR, O_OPT, P_SYS | P_ACT, null, null), 'form' => array(T_ZBX_STR, O_OPT, P_SYS, null, null), 'form_refresh' => array(T_ZBX_INT, O_OPT, null, null, null), 'host' => array(T_ZBX_STR, O_OPT, null, null, null), 'name' => array(T_ZBX_STR, O_OPT, null, null, null), 'name_expanded' => array(T_ZBX_STR, O_OPT, null, null, null)); check_fields($fields); $caption = getRequest('caption', ''); $autoCaption = ''; $_REQUEST['axisside'] = getRequest('axisside', GRAPH_YAXIS_SIDE_LEFT); if (getRequest('itemid') > 0) { $items = CMacrosResolverHelper::resolveItemNames(array(get_item_by_itemid(getRequest('itemid')))); $item = reset($items); $autoCaption = $item['name_expanded']; if (!hasRequest('caption') || getRequest('caption') === $item['name']) { $caption = $item['name_expanded']; } } insert_js_function('add_bitem'); insert_js_function('update_bitem'); if (hasRequest('add') && !hasRequest('gid')) { insert_js("add_bitem(" . zbx_jsvalue(getRequest('dstfrm')) . "," . zbx_jsvalue($caption) . ",'" . getRequest('itemid') . "','" . getRequest('color') . "'," . getRequest('calc_fnc') . "," . getRequest('axisside') . ");\n"); } if (hasRequest('update') && hasRequest('gid')) { insert_js("update_bitem(" . zbx_jsvalue(getRequest('dstfrm')) . "," . zbx_jsvalue(getRequest('list_name')) . ",'" . getRequest('gid') . "'," . zbx_jsvalue($caption) . ",'" . getRequest('itemid') . "','" . getRequest('color') . "'," . getRequest('calc_fnc') . "," . getRequest('axisside') . ");\n"); } else { echo BR();
/** * Prepare data for trigger menu popup. * * @param array $trigger trigger data * @param string $trigger['triggerid'] trigger ID * @param int $trigger['flags'] trigger flags (TRIGGER_FLAG_DISCOVERY*) * @param array $trigger['hosts'] hosts, used by trigger expression * @param string $trigger['hosts'][]['hostid'] host ID * @param string $trigger['hosts'][]['name'] host name * @param string $trigger['hosts'][]['status'] host status * @param array $trigger['items'] trigger items * @param string $trigger['items'][]['itemid'] item ID * @param string $trigger['items'][]['hostid'] host ID * @param string $trigger['items'][]['name'] item name * @param string $trigger['items'][]['key_'] item key * @param string $trigger['items'][]['value_type'] type of information of the item * @param string $trigger['url'] trigger URL * @param array $acknowledge acknowledge link parameters (optional) * @param string $acknowledge['eventid'] event ID * @param string $acknowledge['screenid'] screen ID (optional) * @param string $acknowledge['backurl'] return URL (optional) * @param string $eventTime event navigation time parameter (optional) * * @return array */ public static function getTrigger(array $trigger, array $acknowledge = null, $eventTime = null) { $hosts = array(); $showEvents = true; foreach ($trigger['hosts'] as $host) { $hosts[$host['hostid']] = $host['name']; if ($host['status'] != HOST_STATUS_MONITORED) { $showEvents = false; } } $trigger['items'] = CMacrosResolverHelper::resolveItemNames($trigger['items']); foreach ($trigger['items'] as &$item) { $item['hostname'] = $hosts[$item['hostid']]; } unset($item); CArrayHelper::sort($trigger['items'], array('name', 'hostname', 'itemid')); $hostCount = count($hosts); $items = array(); foreach ($trigger['items'] as $item) { $items[] = array('name' => $hostCount > 1 ? $hosts[$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)) ? HISTORY_GRAPH : HISTORY_VALUES)); } $data = array('type' => 'trigger', 'groupid' => $trigger['groupid'], 'hostid' => $trigger['hostid'], 'triggerid' => $trigger['triggerid'], 'items' => $items, 'acknowledge' => $acknowledge, 'eventTime' => $eventTime, 'url' => resolveTriggerUrl($trigger)); if ($showEvents) { $data['showEvents'] = true; } if (in_array(CWebUser::$data['type'], array(USER_TYPE_ZABBIX_ADMIN, USER_TYPE_SUPER_ADMIN)) && $trigger['flags'] == ZBX_FLAG_DISCOVERY_NORMAL) { $data['configuration'] = true; } return $data; }
// get host scripts $scriptsByHosts = API::Script()->getScriptsByHosts($hostIds); // get trigger dependencies $dbTriggerDependencies = DBselect('SELECT triggerid_down,triggerid_up' . ' FROM trigger_depends' . ' WHERE ' . dbConditionInt('triggerid_up', $triggerIds)); $triggerIdsDown = array(); 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'])); }
public function addItem($itemid, $axis = GRAPH_YAXIS_SIDE_DEFAULT, $calc_fnc = CALC_FNC_AVG, $color = null, $drawtype = null, $type = null) { if ($this->type == GRAPH_TYPE_STACKED) { $drawtype = GRAPH_ITEM_DRAWTYPE_FILLED_REGION; } // TODO: graphs shouldn't retrieve items and resolve macros themselves // all of the data must be passed as parameters $items = CMacrosResolverHelper::resolveItemNames([get_item_by_itemid($itemid)]); $item = reset($items); $item['name'] = $item['name_expanded']; $this->items[$this->num] = $item; $parser = new CItemDelayFlexParser($item['delay_flex']); $this->items[$this->num]['delay'] = getItemDelay($item['delay'], $parser->getFlexibleIntervals()); $this->items[$this->num]['intervals'] = $parser->getIntervals(); if (strpos($item['units'], ',') === false) { $this->items[$this->num]['unitsLong'] = ''; } else { list($this->items[$this->num]['units'], $this->items[$this->num]['unitsLong']) = explode(',', $item['units']); } $host = get_host_by_hostid($item['hostid']); $this->items[$this->num]['host'] = $host['host']; $this->items[$this->num]['hostname'] = $host['name']; $this->items[$this->num]['color'] = is_null($color) ? 'Dark Green' : $color; $this->items[$this->num]['drawtype'] = is_null($drawtype) ? GRAPH_ITEM_DRAWTYPE_LINE : $drawtype; $this->items[$this->num]['axisside'] = is_null($axis) ? GRAPH_YAXIS_SIDE_DEFAULT : $axis; $this->items[$this->num]['calc_fnc'] = is_null($calc_fnc) ? CALC_FNC_AVG : $calc_fnc; $this->items[$this->num]['calc_type'] = is_null($type) ? GRAPH_ITEM_SIMPLE : $type; if ($this->items[$this->num]['axisside'] == GRAPH_YAXIS_SIDE_LEFT) { $this->yaxisleft = 1; } if ($this->items[$this->num]['axisside'] == GRAPH_YAXIS_SIDE_RIGHT) { $this->yaxisright = 1; } $this->num++; }
} $graphFormList->addRow(_('Y axis MIN value'), $yaxisMinData); $yaxisMaxData = array(); $yTypeComboBox = new CComboBox('ymax_type', $this->data['ymax_type']); $yTypeComboBox->addItem(GRAPH_YAXIS_TYPE_CALCULATED, _('Calculated')); $yTypeComboBox->addItem(GRAPH_YAXIS_TYPE_FIXED, _('Fixed')); $yTypeComboBox->addItem(GRAPH_YAXIS_TYPE_ITEM_VALUE, _('Item')); $yaxisMaxData[] = $yTypeComboBox; if ($this->data['ymax_type'] == GRAPH_YAXIS_TYPE_FIXED) { $yaxisMaxData[] = new CTextBox('yaxismax', $this->data['yaxismax'], 7); } elseif ($this->data['ymax_type'] == GRAPH_YAXIS_TYPE_ITEM_VALUE) { $graphForm->addVar('yaxismax', $this->data['yaxismax']); $ymax_name = ''; if (!empty($this->data['ymax_itemid'])) { $max_host = get_host_by_itemid($this->data['ymax_itemid']); $maxItems = CMacrosResolverHelper::resolveItemNames(array(get_item_by_itemid($this->data['ymax_itemid']))); $maxItem = reset($maxItems); $ymax_name = $max_host['name'] . NAME_DELIMITER . $maxItem['name_expanded']; } $yaxisMaxData[] = new CTextBox('ymax_name', $ymax_name, 36, true); $yaxisMaxData[] = new CButton('yaxis_max', _('Select'), 'javascript: ' . 'return PopUp("popup.php?dstfrm=' . $graphForm->getName() . '&dstfld1=ymax_itemid' . '&dstfld2=ymax_name' . '&srctbl=items' . '&srcfld1=itemid' . '&srcfld2=name' . '&numeric=1' . '&writeonly=1" + getOnlyHostParam(), 0, 0, "zbx_popup_item");', 'formlist'); // select prototype button if (!empty($this->data['parent_discoveryid'])) { $yaxisMaxData[] = new CButton('yaxis_max_prototype', _('Select prototype'), 'javascript: ' . 'return PopUp("popup.php?dstfrm=' . $graphForm->getName() . '&parent_discoveryid=' . $this->data['parent_discoveryid'] . '&dstfld1=ymax_itemid' . '&dstfld2=ymax_name' . '&srctbl=item_prototypes' . '&srcfld1=itemid' . '&srcfld2=name' . '&numeric=1", 0, 0, "zbx_popup_item");', 'formlist'); } } else { $graphForm->addVar('yaxismax', $this->data['yaxismax']); } $graphFormList->addRow(_('Y axis MAX value'), $yaxisMaxData); } else { $graphFormList->addRow(_('3D view'), new CCheckBox('show_3d', $this->data['show_3d'], null, 1));
// render view $itemView = new CView('configuration.item.prototype.edit', $data); $itemView->render(); $itemView->show(); } else { $sortField = getRequest('sort', CProfile::get('web.' . $page['file'] . '.sort', 'name')); $sortOrder = getRequest('sortorder', CProfile::get('web.' . $page['file'] . '.sortorder', ZBX_SORT_UP)); CProfile::update('web.' . $page['file'] . '.sort', $sortField, PROFILE_TYPE_STR); CProfile::update('web.' . $page['file'] . '.sortorder', $sortOrder, PROFILE_TYPE_STR); $config = select_config(); $data = ['form' => getRequest('form'), 'parent_discoveryid' => getRequest('parent_discoveryid'), 'hostid' => $discoveryRule['hostid'], 'sort' => $sortField, 'sortorder' => $sortOrder]; $data['items'] = API::ItemPrototype()->get(['discoveryids' => $data['parent_discoveryid'], 'output' => API_OUTPUT_EXTEND, 'editable' => true, 'selectApplications' => API_OUTPUT_EXTEND, 'sortfield' => $sortField, 'limit' => $config['search_limit'] + 1]); foreach ($data['items'] as &$item) { if ($item['value_type'] == ITEM_VALUE_TYPE_STR || $item['value_type'] == ITEM_VALUE_TYPE_LOG || $item['value_type'] == ITEM_VALUE_TYPE_TEXT) { $item['trends'] = ''; } if ($item['type'] == ITEM_TYPE_TRAPPER || $item['type'] == ITEM_TYPE_SNMPTRAP) { $item['delay'] = ''; } } unset($item); $data['items'] = CMacrosResolverHelper::resolveItemNames($data['items']); order_result($data['items'], $sortField, $sortOrder); $url = (new CUrl('disc_prototypes.php'))->setArgument('parent_discoveryid', $data['parent_discoveryid']); $data['paging'] = getPagingLine($data['items'], $sortOrder, $url); // render view $itemView = new CView('configuration.item.prototype.list', $data); $itemView->render(); $itemView->show(); } require_once dirname(__FILE__) . '/include/page_footer.php';
public function addItem($itemid, $axis = GRAPH_YAXIS_SIDE_DEFAULT, $calc_fnc = CALC_FNC_AVG, $color = null, $drawtype = null) { if ($this->type == GRAPH_TYPE_STACKED) { $drawtype = GRAPH_ITEM_DRAWTYPE_FILLED_REGION; } $items = CMacrosResolverHelper::resolveItemNames(array(get_item_by_itemid($itemid))); $item = reset($items); $item['name'] = $item['name_expanded']; $this->items[$this->num] = $item; $this->items[$this->num]['delay'] = getItemDelay($item['delay'], $item['delay_flex']); if (strpos($item['units'], ',') === false) { $this->items[$this->num]['unitsLong'] = ''; } else { list($this->items[$this->num]['units'], $this->items[$this->num]['unitsLong']) = explode(',', $item['units']); } $host = get_host_by_hostid($item['hostid']); $this->items[$this->num]['host'] = $host['host']; $this->items[$this->num]['hostname'] = $host['name']; $this->items[$this->num]['color'] = is_null($color) ? 'Dark Green' : $color; $this->items[$this->num]['drawtype'] = is_null($drawtype) ? GRAPH_ITEM_DRAWTYPE_LINE : $drawtype; $this->items[$this->num]['axisside'] = is_null($axis) ? GRAPH_YAXIS_SIDE_DEFAULT : $axis; $this->items[$this->num]['calc_fnc'] = is_null($calc_fnc) ? CALC_FNC_AVG : $calc_fnc; $this->items[$this->num]['calc_type'] = GRAPH_ITEM_SIMPLE; if ($this->items[$this->num]['axisside'] == GRAPH_YAXIS_SIDE_LEFT) { $this->yaxisleft = 1; } if ($this->items[$this->num]['axisside'] == GRAPH_YAXIS_SIDE_RIGHT) { $this->yaxisright = 1; } $this->num++; }
clearCookies($goResult, $_REQUEST['hostid']); } /* * Display */ if (isset($_REQUEST['form'])) { $data = getItemFormData(array('is_discovery_rule' => true)); $data['page_header'] = _('CONFIGURATION OF DISCOVERY RULES'); // render view $itemView = new CView('configuration.item.edit', $data); $itemView->render(); $itemView->show(); } else { $data = array('hostid' => get_request('hostid', 0), 'host' => $host, 'showErrorColumn' => $host['status'] != HOST_STATUS_TEMPLATE); $sortfield = getPageSortField('name'); // discoveries $data['discoveries'] = API::DiscoveryRule()->get(array('hostids' => $data['hostid'], 'output' => API_OUTPUT_EXTEND, 'editable' => true, 'selectItems' => API_OUTPUT_COUNT, 'selectGraphs' => API_OUTPUT_COUNT, 'selectTriggers' => API_OUTPUT_COUNT, 'selectHostPrototypes' => API_OUTPUT_COUNT, 'sortfield' => $sortfield, 'limit' => $config['search_limit'] + 1)); $data['discoveries'] = CMacrosResolverHelper::resolveItemNames($data['discoveries']); if ($sortfield === 'status') { orderItemsByStatus($data['discoveries'], getPageSortOrder()); } else { order_result($data['discoveries'], $sortfield, getPageSortOrder()); } // paging $data['paging'] = getPagingLine($data['discoveries'], array('itemid'), array('hostid' => get_request('hostid'))); // render view $discoveryView = new CView('configuration.host.discovery.list', $data); $discoveryView->render(); $discoveryView->show(); } require_once dirname(__FILE__) . '/include/page_footer.php';
foreach ($_REQUEST['periods'] as $pid => $period) { if (!isset($_REQUEST['group_pid'][$pid])) { continue; } unset($_REQUEST['periods'][$pid]); } unset($_REQUEST['delete_period'], $_REQUEST['group_pid']); } // item validation $config = $_REQUEST['config'] = getRequest('config', BR_DISTRIBUTION_MULTIPLE_PERIODS); // items array validation if ($config != BR_COMPARE_VALUE_MULTIPLE_PERIODS) { $items = getRequest('items'); $validItems = validateBarReportItems($items); if ($validItems) { $validItems = CMacrosResolverHelper::resolveItemNames($validItems); foreach ($validItems as &$item) { if ($item['caption'] === $item['name']) { $item['caption'] = $item['name_expanded']; } } unset($item); } if ($config == BR_DISTRIBUTION_MULTIPLE_ITEMS) { $validPeriods = validateBarReportPeriods(getRequest('periods')); } } $_REQUEST['report_timesince'] = zbxDateToTime(getRequest('report_timesince', date(TIMESTAMP_FORMAT_ZERO_TIME, time() - SEC_PER_DAY))); $_REQUEST['report_timetill'] = zbxDateToTime(getRequest('report_timetill', date(TIMESTAMP_FORMAT_ZERO_TIME, time()))); $rep6_wdgt = new CWidget(); $r_form = new CForm();