/** * Retrieve overview table object for items. * * @param $hostids * @param null $view_style * * @return CTableInfo */ function get_items_data_overview($hostids, $view_style) { global $USER_DETAILS; $db_items = DBselect('SELECT DISTINCT h.hostid,h.name AS hostname,i.itemid,i.key_,i.value_type,i.lastvalue,i.units,i.lastclock,' . 'i.name,t.priority,i.valuemapid,t.value AS tr_value,t.triggerid' . ' FROM hosts h,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)) . ' ORDER BY i.name,i.itemid'); $options = array('output' => array('name', 'hostid'), 'monitored_hosts' => true, 'hostids' => $hostids, 'with_monitored_items' => true, 'preservekeys' => true); if ($view_style == STYLE_LEFT) { $options['selectScreens'] = API_OUTPUT_COUNT; $options['selectInventory'] = array('hostid'); } // fetch data for the host JS menu $hosts = API::Host()->get($options); $items = array(); while ($row = DBfetch($db_items)) { $descr = itemName($row); $row['hostname'] = get_node_name_by_elid($row['hostid'], null, ': ') . $row['hostname']; $hostnames[$row['hostid']] = $row['hostname']; // a little tricky check for attempt to overwrite active trigger (value=1) with // inactive or active trigger with lower priority. if (!isset($items[$descr][$row['hostname']]) || ($items[$descr][$row['hostname']]['tr_value'] == TRIGGER_VALUE_FALSE && $row['tr_value'] == TRIGGER_VALUE_TRUE || ($items[$descr][$row['hostname']]['tr_value'] == TRIGGER_VALUE_FALSE || $row['tr_value'] == TRIGGER_VALUE_TRUE) && $row['priority'] > $items[$descr][$row['hostname']]['severity'])) { $items[$descr][$row['hostname']] = array('itemid' => $row['itemid'], 'value_type' => $row['value_type'], 'lastvalue' => $row['lastvalue'], 'lastclock' => $row['lastclock'], 'units' => $row['units'], 'name' => $row['name'], 'valuemapid' => $row['valuemapid'], 'severity' => $row['priority'], 'tr_value' => $row['tr_value'], 'triggerid' => $row['triggerid']); } } $table = new CTableInfo(_('No items defined.')); if (empty($hostnames)) { return $table; } $table->makeVerticalRotation(); order_result($hostnames); if ($view_style == 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 = get_item_data_overview_cells($tableRow, $ithosts, $hostname); } $table->addRow($tableRow); } } else { $hostScripts = API::Script()->getScriptsByHosts(zbx_objectValues($hosts, 'hostid')); foreach ($hostScripts as $hostid => $scripts) { $hosts[$hostid]['scripts'] = $scripts; } $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]; // host js menu link $hostSpan = new CSpan(nbsp($host['name']), 'link_menu menu-host'); $hostSpan->setAttribute('data-menu', hostMenuData($host, $hostScripts[$host['hostid']])); $tableRow = array(new CCol($hostSpan)); foreach ($items as $ithosts) { $tableRow = get_item_data_overview_cells($tableRow, $ithosts, $hostname); } $table->addRow($tableRow); } } return $table; }
function get_items_data_overview($hostids, $view_style = null) { if (is_null($view_style)) { $view_style = get_profile('web.overview.view.style', STYLE_TOP); } $table = new CTableInfo(S_NO_ITEMS_DEFINED); COpt::profiling_start('prepare data'); $result = DBselect('SELECT DISTINCT h.hostid, h.host,i.itemid, i.key_, i.value_type, i.lastvalue, i.units, ' . ' i.description, t.priority, i.valuemapid, t.value as tr_value, t.triggerid ' . ' FROM hosts h, items i ' . ' LEFT JOIN functions f on f.itemid=i.itemid ' . ' LEFT JOIN triggers t on t.triggerid=f.triggerid ' . ' WHERE ' . DBcondition('h.hostid', $hostids) . ' AND h.status=' . HOST_STATUS_MONITORED . ' AND h.hostid=i.hostid ' . ' AND i.status=' . ITEM_STATUS_ACTIVE . ' ORDER BY i.description,i.itemid'); unset($items); unset($hosts); // get rid of warnings about $triggers undefined $items = array(); while ($row = DBfetch($result)) { $descr = item_description($row); $row['host'] = get_node_name_by_elid($row['hostid']) . $row['host']; $hosts[strtolower($row['host'])] = $row['host']; // A little tricky check for attempt to overwrite active trigger (value=1) with // inactive or active trigger with lower priority. if (!isset($items[$descr][$row['host']]) || ($items[$descr][$row['host']]['tr_value'] == TRIGGER_VALUE_FALSE && $row['tr_value'] == TRIGGER_VALUE_TRUE || ($items[$descr][$row['host']]['tr_value'] == TRIGGER_VALUE_FALSE || $row['tr_value'] == TRIGGER_VALUE_TRUE) && $row['priority'] > $items[$descr][$row['host']]['severity'])) { $items[$descr][$row['host']] = array('itemid' => $row['itemid'], 'value_type' => $row['value_type'], 'lastvalue' => $row['lastvalue'], 'units' => $row['units'], 'description' => $row['description'], 'valuemapid' => $row['valuemapid'], 'severity' => $row['priority'], 'tr_value' => $row['tr_value'], 'triggerid' => $row['triggerid']); } } if (!isset($hosts)) { return $table; } ksort($hosts); COpt::profiling_stop('prepare data'); COpt::profiling_start('prepare table'); if ($view_style == STYLE_TOP) { $header = array(new CCol(S_ITEMS, 'center')); foreach ($hosts as $hostname) { $header = array_merge($header, array(new CImg('vtext.php?text=' . $hostname))); } $table->SetHeader($header, 'vertical_header'); $curr_rime = time(); foreach ($items as $descr => $ithosts) { $table_row = array(nbsp($descr)); foreach ($hosts as $hostname) { $table_row = get_item_data_overview_cells($table_row, $ithosts, $hostname); } $table->AddRow($table_row); } } else { $header = array(new CCol(S_HOSTS, 'center')); foreach ($items as $descr => $ithosts) { $header = array_merge($header, array(new CImg('vtext.php?text=' . $descr))); } $table->SetHeader($header, 'vertical_header'); $curr_rime = time(); foreach ($hosts as $hostname) { $table_row = array(nbsp($hostname)); foreach ($items as $descr => $ithosts) { $table_row = get_item_data_overview_cells($table_row, $ithosts, $hostname); } $table->AddRow($table_row); } } COpt::profiling_stop('prepare table'); return $table; }