function get_hostgroup_data() { global $NagiosData; global $NagiosUser; $hostgroups = $NagiosData->getProperty('hostgroups'); $hosts = $NagiosData->getProperty('hosts'); $hostgroup_data = array(); foreach ($hostgroups as $group => $members) { $hostgroup_data[$group] = array('member_data' => array(), 'host_counts' => get_state_of('hosts', build_hostgroup_details($members)), 'service_counts' => get_state_of('services', build_host_servicegroup_details($members))); //skip ahead if there are no authorized hosts if (array_sum($hostgroup_data[$group]['host_counts']) == 0) { continue; } //skip empty groups foreach ($members as $member) { if (!$NagiosUser->is_authorized_for_host($member)) { continue; } //user-level filtering $host = $hosts[$member]; process_host_status_keys($host); $hostgroup_data[$group]['member_data'][$member]['host_name'] = $host['host_name']; $hostgroup_data[$group]['member_data'][$member]['host_state'] = $host['current_state']; $hostgroup_data[$group]['member_data'][$member]['state_class'] = get_color_code($host); $hostgroup_data[$group]['member_data'][$member]['services'] = array(); $hostgroup_data[$group]['member_data'][$member]['host_url'] = BASEURL . 'index.php?type=hostdetail&name_filter=' . urlencode($host['host_name']); if (isset($host['services'])) { foreach ($host['services'] as $service) { if (!$NagiosUser->is_authorized_for_service($member, $service['service_description'])) { continue; } //user-level filtering process_service_status_keys($service); $service_data = array('state_class' => get_color_code($service), 'description' => $service['service_description'], 'service_url' => htmlentities(BASEURL . 'index.php?type=servicedetail&name_filter=' . $service['service_id'])); $hostgroup_data[$group]['member_data'][$member]['services'][] = $service_data; } } } } return $hostgroup_data; }
function display_hosts($hosts, $start, $limit) { //LOGIC //get variables needed to display page $resultsCount = count($hosts); //if results are greater than number that the page can display, create page links //calculate number of pages $pageCount = $resultsCount / $limit < 1 ? 1 : intval($resultsCount / $limit); $doPagination = $pageCount * $limit < $resultsCount; $name_filter = isset($_GET['name_filter']) ? htmlentities($_GET['name_filter']) : ''; $hostnames = array_keys($hosts); sort($hostnames); //begin html output / VIEW $page = ''; $ht = hosts_table(get_tac_data()); //tac host summary table $page .= "<div class='tacTable'>{$ht}</div>\n"; $page .= "<div class='tableOptsWrapper'>\n"; if ($doPagination) { $page .= do_pagenumbers($pageCount, $start, $limit, $resultsCount, 'hosts'); } //creates notes for total results as well as form for setting page limits $page .= do_result_notes($start, $limit, $resultsCount, 'hosts'); //moved result filter to display_functions.php and made into function $page .= result_filter($name_filter, 'host'); $page .= "\n</div> <!-- end tableOptsWrapper --> \n"; //begin status table $page .= '<div class="statusTable"> <table class="statusTable"> <tr> <th>' . gettext('Host Name') . '</th> <th>' . gettext('Status') . '</th> <th>' . gettext('Duration') . '</th> <th>' . gettext('Attempt') . '</th> <th>' . gettext('Last Check') . '</th> <th>' . gettext('Status Information') . '</th> </tr>' . "\n"; //begin looping table results for ($i = $start; $i <= $start + $limit; $i++) { if ($i >= $resultsCount) { break; } if (!isset($hosts[$hostnames[$i]])) { continue; } //skip undefined indexes of hosts array $host = $hosts[$hostnames[$i]]; //process remaining variables for display here process_host_status_keys($host); $tr = get_color_code($host); // CSS style class based on status $url = htmlentities(BASEURL . 'index.php?type=hostdetail&name_filter=' . $host['host_name']); //add function to fetch_icons $icons = fetch_host_icons($host['host_name']); //returns all icons in one string $pagerow = <<<TABLEROW \t \t\t<tr>\t \t\t\t<td><a href="{$url}">{$host['host_name']}</a>{$icons}</td> \t\t\t<td class="{$tr}">{$host['current_state']}</td> \t\t\t<td>{$host['duration']}</td> \t\t\t<td>{$host['attempt']}</td> \t\t\t<td>{$host['last_check']}</td> \t\t\t<td>{$host['plugin_output']}</td> \t\t</tr> \t\t\t TABLEROW; $page .= $pagerow; } $page .= "</table></div><!--end statusTable div -->\n"; //check if more than one page is needed if ($doPagination) { $page .= do_pagenumbers($pageCount, $start, $limit, $resultsCount, 'hosts'); } //print the page numbers here accordingly return $page; }