function get_tac_html() { $tac_data = get_tac_data(); $tac = ""; $tac .= info_table() . '<br />'; $tac .= overview_table($tac_data) . '<br />'; $tac .= health_meters($tac_data); //added health meters -MG 4/23/11 $tac .= hosts_table($tac_data) . '<br />'; $tac .= services_table($tac_data) . '<br />'; $tac .= features_table($tac_data); $tac .= search_box() . '<br />'; return $tac; }
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; }
function page_router() { global $authorizations; global $NagiosUser; list($mode, $type) = array(NULL, NULL); list($state_filter, $name_filter, $objtype_filter, $host_filter) = array(NULL, NULL, NULL, NULL); if (isset($_GET['type'])) { $type = strtolower($_GET['type']); } else { $type = 'overview'; } if (isset($_GET['mode'])) { $mode = strtolower($_GET['mode']); } else { $mode = 'html'; } if (isset($_GET['state_filter']) && trim($_GET['state_filter']) != '') { $state_filter = process_state_filter(htmlentities($_GET['state_filter'])); } if (isset($_GET['name_filter']) && trim($_GET['name_filter']) != '') { $name_filter = process_name_filter(htmlentities($_GET['name_filter']), ENT_QUOTES); } if (isset($_GET['host_filter']) && trim($_GET['host_filter']) != '') { $host_filter = htmlentities($_GET['host_filter'], ENT_QUOTES); } if (isset($_GET['objtype_filter']) && trim($_GET['objtype_filter']) != '') { $objtype_filter = process_objtype_filter(htmlentities($_GET['objtype_filter'])); } list($data, $html_output_function) = array(NULL, NULL); switch ($type) { case 'services': case 'hosts': $data = hosts_and_services_data($type, $state_filter, $name_filter, $host_filter); $html_output_function = 'hosts_and_services_output'; break; case 'hostgroups': case 'servicegroups': if ($type == 'hostgroups' || $type == 'servicegroups') { $data = hostgroups_and_servicegroups_data($type, $name_filter); $html_output_function = 'hostgroups_and_servicegroups_output'; } break; case 'hostdetail': case 'servicedetail': $data = host_and_service_detail_data($type, $name_filter); if (!$data) { send_home(); } //bail if not authorized $html_output_function = 'host_and_service_detail_output'; break; case 'object': if ($objtype_filter) { if ($NagiosUser->if_has_authKey('authorized_for_configuration_information')) { $data = object_data($objtype_filter, $name_filter); $type = $objtype_filter; $html_output_function = 'object_output'; } else { send_home(); } } break; case 'backend': $xmlout = tac_xml(get_tac_data()); break; case 'overview': default: //create function to return tac data as an array $html_output_function = 'get_tac_html'; break; } $output = NULL; switch ($mode) { case 'html': default: $output = mode_header($mode); $output .= $html_output_function($type, $data, $mode); $output .= mode_footer($mode); break; case 'json': header('Content-type: application/json'); $output = json_encode($data); break; case 'xml': if ($type != 'backend') { require_once DIRBASE . '/views/xml.php'; $title = ucwords($type); build_xml_page($data, $title); header('Location: ' . BASEURL . 'tmp/' . $title . '.xml'); } header('Content-type: text/xml'); if ($type == 'backend') { echo $xmlout; } //xml backend access for nagios fusion #$output = build_xml_data($data, $title); break; } print $output; }
function display_services($services, $start, $limit) { //LOGIC $resultsCount = count($services); //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']) ? $_GET['name_filter'] : ''; //VIEW / html output $page = ''; $st = services_table(get_tac_data()); //tac Summary table $page .= "<div class='tacTable'>{$st}</div>\n"; $page .= "<div class='tableOptsWrapper'>\n"; //check if more than one page is needed if ($doPagination) { $page .= do_pagenumbers($pageCount, $start, $limit, $resultsCount, 'services'); } //creates notes for total results as well as form for setting page limits $page .= do_result_notes($start, $limit, $resultsCount, 'services'); //moved result filter to display_functions.php and made into function $page .= result_filter($name_filter, 'service'); $page .= "\n</div> <!-- end tableOptsWrapper --> \n"; //Table header generation $page .= '<div class="statusTable"> <table class="servicetable"><tr> <th class="hostname">' . gettext('Host Name') . '</th> <th class="service_description">' . gettext('Service') . '</th> <th class="status">' . gettext('Status') . '</th> <th class="duration">' . gettext('Duration') . '</th> <th class="attempt">' . gettext('Attempt') . '</th> <th class="last_check">' . gettext('Last Check') . '</th> <th class="plugin_output">' . gettext('Status Information') . '</th></tr>'; /* // Fixup post filtering indices $curidx = 0; foreach ($services as $id => $servinfo) { unset($services[$id]); $services[$curidx++] = $servinfo; } */ //process service array //service table rows $last_displayed_host = NULL; for ($i = $start; $i <= $start + $limit; $i++) { if ($i > $resultsCount) { break; } //short circuit if (!isset($services[$i])) { continue; } //skip undefined indexes of array process_service_status_keys($services[$i]); //get $vars to complete table data $tr = get_color_code($services[$i]); //$url = htmlentities(BASEURL.'index.php?cmd=getservicedetail&arg='.$services[$i]['serviceID']); $url = htmlentities(BASEURL . 'index.php?type=servicedetail&name_filter=' . $services[$i]['service_id']); //$host_url = htmlentities(BASEURL.'index.php?cmd=gethostdetail&arg='.$services[$i]['host_name']); $host_url = htmlentities(BASEURL . 'index.php?type=hostdetail&name_filter=') . urlencode($services[$i]['host_name']); $color = get_host_status_color($services[$i]['host_name']); $hosticons = fetch_host_icons($services[$i]['host_name']); $serviceicons = fetch_service_icons($services[$i]['service_id']); //removing duplicate host names from table for a cleaner look if ($services[$i]['host_name'] == $last_displayed_host) { $td1 = '<td></td>'; } else { $last_displayed_host = $services[$i]['host_name']; $hostlink = "<a class='highlight' href='{$host_url}' title='" . gettext('View Host Details') . "'>"; $td1 = "<td class='{$color}'><div class='hostname'>{$hostlink}" . htmlentities($services[$i]['host_name']) . "</a> {$hosticons} </div></td>"; } //table data generation //Using HEREDOC string syntax to print rows $pagerow = <<<TABLEROW \t\t \t\t<tr class='statustablerow'>\t \t\t\t{$td1} \t\t\t<td class='service_description'><div class='service_description'><a href="{$url}">{$services[$i]['service_description']}</a> {$serviceicons} </div></td> \t\t\t<td class="{$tr}">{$services[$i]['current_state']}</td> \t\t\t<td class='duration'>{$services[$i]['duration']}</td> \t\t\t<td class='attempt'>{$services[$i]['attempt']}</td> \t\t\t<td class='last_check'>{$services[$i]['last_check']}</td> \t\t\t<td class='plugin_output'><div class='plugin_output'>{$services[$i]['plugin_output']}</div></td> \t\t</tr> \t\t TABLEROW; $page .= $pagerow; } $page .= "</table>\n</div> <!--end div.statusTable -->\n"; if ($doPagination) { $page .= do_pagenumbers($pageCount, $start, $limit, $resultsCount, 'services'); } return $page; }