function hosts() { global $config, $device_actions, $item_rows; /* ================= input validation and session storage ================= */ $filters = array('rows' => array('filter' => FILTER_VALIDATE_INT, 'pageset' => true, 'default' => '-1'), 'page' => array('filter' => FILTER_VALIDATE_INT, 'default' => '1'), 'filter' => array('filter' => FILTER_CALLBACK, 'pageset' => true, 'default' => '', 'options' => array('options' => 'sanitize_search_string')), 'sort_column' => array('filter' => FILTER_CALLBACK, 'default' => 'description', 'options' => array('options' => 'sanitize_search_string')), 'sort_direction' => array('filter' => FILTER_CALLBACK, 'default' => 'ASC', 'options' => array('options' => 'sanitize_search_string')), 'host_template_id' => array('filter' => FILTER_VALIDATE_INT, 'pageset' => true, 'default' => '-1'), 'host_status' => array('filter' => FILTER_VALIDATE_INT, 'pageset' => true, 'default' => '-4')); validate_store_request_vars($filters, 'sess_thold_hstatus'); /* ================= input validation ================= */ /* if the number of rows is -1, set it to the default */ if (get_request_var('rows') == -1) { $rows = read_config_option('num_rows_table'); } else { $rows = get_request_var('rows'); } html_start_box(__('Device Status'), '100%', '', '3', 'center', ''); form_host_filter(); html_end_box(); /* form the 'where' clause for our main sql query */ $sql_where = ''; if (get_request_var('filter') != '') { $sql_where = "((h.hostname LIKE '%" . get_request_var('filter') . "%' OR h.description LIKE '%" . get_request_var('filter') . "%')"; } if (get_request_var('host_status') == '-1') { /* Show all items */ } elseif (get_request_var('host_status') == '-2') { $sql_where .= (strlen($sql_where) ? ' AND ' : '(') . "h.disabled='on'"; } elseif (get_request_var('host_status') == '-3') { $sql_where .= (strlen($sql_where) ? ' AND ' : '(') . "h.disabled=''"; } elseif (get_request_var('host_status') == '-4') { $sql_where .= (strlen($sql_where) ? ' AND ' : '(') . "(h.status!='3' OR h.disabled='on')"; } elseif (get_request_var('host_status') == '-5') { $sql_where .= (strlen($sql_where) ? ' AND ' : '(') . "(h.availability_method=0)"; } elseif (get_request_var('host_status') == '3') { $sql_where .= (strlen($sql_where) ? ' AND ' : '(') . "(h.availability_method!=0 AND h.status=3 AND h.disabled='')"; } else { $sql_where .= (strlen($sql_where) ? ' AND ' : '(') . "(h.status=" . get_request_var('host_status') . " AND h.disabled = '')"; } if (get_request_var('host_template_id') == '-1') { /* Show all items */ } elseif (get_request_var('host_template_id') == '0') { $sql_where .= (strlen($sql_where) ? ' AND ' : '(') . "h.host_template_id=0'"; } elseif (!isempty_request_var('host_template_id')) { $sql_where .= (strlen($sql_where) ? ' AND ' : '(') . "h.host_template_id=" . get_request_var('host_template_id'); } $sql_where .= strlen($sql_where) ? ')' : ''; $sortby = get_request_var('sort_column'); if ($sortby == 'hostname') { $sortby = 'INET_ATON(hostname)'; } $host_graphs = array_rekey(db_fetch_assoc('SELECT host_id, count(*) as graphs FROM graph_local GROUP BY host_id'), 'host_id', 'graphs'); $host_data_sources = array_rekey(db_fetch_assoc('SELECT host_id, count(*) as data_sources FROM data_local GROUP BY host_id'), 'host_id', 'data_sources'); $hosts = get_allowed_devices($sql_where, $sortby . ' ' . get_request_var('sort_direction'), $rows * (get_request_var('page') - 1) . ',' . $rows, $total_rows); $nav = html_nav_bar('thold_graph.php?action=hoststat', MAX_DISPLAY_PAGES, get_request_var('page'), $rows, $total_rows, 12, __('Devices'), 'page', 'main'); print $nav; html_start_box('', '100%', '', '3', 'center', ''); $display_text = array('nosort' => array('display' => __('Actions'), 'align' => 'left', 'sort' => '', 'tip' => __('Hover over icons for help')), 'description' => array('display' => __('Description'), 'align' => 'left', 'sort' => 'ASC', 'tip' => __('A description for the Device')), 'id' => array('display' => __('ID'), 'align' => 'right', 'sort' => 'ASC', 'tip' => __('A Cacti unique identifier for the Device')), 'nosort1' => array('display' => __('Graphs'), 'align' => 'right', 'sort' => 'ASC', 'tip' => __('The number of Graphs for this Device')), 'nosort2' => array('display' => __('Data Sources'), 'align' => 'right', 'sort' => 'ASC', 'tip' => __('The number of Data Sources for this Device')), 'status' => array('display' => __('Status'), 'align' => 'center', 'sort' => 'ASC', 'tip' => __('The status for this Device as of the last time it was polled')), 'nosort3' => array('display' => __('In State'), 'align' => 'right', 'sort' => 'ASC', 'tip' => __('The last time Cacti found an issues with this Device. It can be higher than the Uptime for the the Device, if it was rebooted between Cacti polling cycles')), 'snmp_sysUpTimeInstance' => array('display' => __('Uptime'), 'align' => 'right', 'sort' => 'ASC', 'tip' => __('The official uptime of the Device as reported by SNMP')), 'hostname' => array('display' => __('Hostname'), 'align' => 'right', 'sort' => 'ASC', 'tip' => __('The official hostname for this Device')), 'cur_time' => array('display' => __('Current (ms)'), 'align' => 'right', 'sort' => 'DESC', 'tip' => __('The current response time for the Cacti Availability check')), 'avg_time' => array('display' => __('Average (ms)'), 'align' => 'right', 'sort' => 'DESC', 'tip' => __('The average response time for the Cacti Availability check')), 'availability' => array('display' => __('Availability'), 'align' => 'right', 'sort' => 'ASC', 'tip' => __('The overall Availability of this Device since the last counter reset in Cacti'))); html_header_sort($display_text, get_request_var('sort_column'), get_request_var('sort_direction'), false, 'thold_graph.php?action=hoststat'); if (sizeof($hosts)) { foreach ($hosts as $host) { if ($host['disabled'] == '' && ($host['status'] == HOST_RECOVERING || $host['status'] == HOST_UP) && ($host['availability_method'] != AVAIL_NONE && $host['availability_method'] != AVAIL_PING)) { $snmp_uptime = $host['snmp_sysUpTimeInstance']; $days = intval($snmp_uptime / (60 * 60 * 24 * 100)); $remainder = $snmp_uptime % (60 * 60 * 24 * 100); $hours = intval($remainder / (60 * 60 * 100)); $remainder = $remainder % (60 * 60 * 100); $minutes = intval($remainder / (60 * 100)); $uptime = $days . 'd:' . substr('00' . $hours, -2) . 'h:' . substr('00' . $minutes, -2) . 'm'; } else { $uptime = __('N/A'); } if (isset($host_graphs[$host['id']])) { $graphs = $host_graphs[$host['id']]; } else { $graphs = 0; } if (isset($host_data_sources[$host['id']])) { $ds = $host_data_sources[$host['id']]; } else { $ds = 0; } if ($host['availability_method'] != 0) { form_host_status_row_color($host['status'], $host['disabled']); print "<td width='1%' class='nowrap'>"; if (api_user_realm_auth('host.php')) { print '<a href="' . htmlspecialchars($config['url_path'] . 'host.php?action=edit&id=' . $host['id']) . '"><img src="' . $config['url_path'] . 'plugins/thold/images/edit_object.png" border="0" alt="" title="' . __('Edit Device') . '"></a>'; } print "<a href='" . htmlspecialchars($config['url_path'] . 'graph_view.php?action=preview&graph_template_id=0&filter=&host_id=' . $host['id']) . "'><img src='" . $config['url_path'] . "plugins/thold/images/view_graphs.gif' border='0' alt='' title='" . __('View Graphs') . "'></a>"; print '</td>'; ?> <td style='text-align:left'> <?php print filter_value($host['description'], get_request_var('filter')); ?> </td> <td style='text-align:right'><?php print round($host['id'], 2); ?> </td> <td style='text-align:right'><i><?php print number_format_i18n($graphs); ?> </i></td> <td style='text-align:right'><i><?php print number_format_i18n($ds); ?> </i></td> <td style='text-align:center'><?php print get_uncolored_device_status($host['disabled'] == 'on' ? true : false, $host['status']); ?> </td> <td style='text-align:right'><?php print get_timeinstate($host); ?> </td> <td style='text-align:right'><?php print $uptime; ?> </td> <td style='text-align:right'><?php print filter_value($host['hostname'], get_request_var('filter')); ?> </td> <td style='text-align:right'><?php print round($host['cur_time'], 2); ?> </td> <td style='text-align:right'><?php print round($host['avg_time'], 2); ?> </td> <td style='text-align:right'><?php print round($host['availability'], 2); ?> %</td> <?php } else { print "<tr class='deviceNotMonFull'>\n"; print "<td width='1%' class='nowrap'>\n"; if (api_user_realm_auth('host.php')) { print '<a href="' . htmlspecialchars($config['url_path'] . 'host.php?action=edit&id=' . $host["id"]) . '"><img src="' . $config['url_path'] . 'plugins/thold/images/edit_object.png" border="0" alt="" title="' . __('Edit Device') . '"></a>'; } print "<a href='" . htmlspecialchars($config['url_path'] . "graph_view.php?action=preview&graph_template_id=0&filter=&host_id=" . $host["id"]) . "'><img src='" . $config['url_path'] . "plugins/thold/images/view_graphs.gif' border='0' alt='' title='" . __('View Graphs') . "'></a>"; print "</td>"; ?> <td style='text-align:left'> <?php print filter_value($host['description'], get_request_var('filter')); ?> </td> <td style='text-align:right'><?php print $host['id']; ?> </td> <td style='text-align:right'><i><?php print number_format_i18n($graphs); ?> </i></td> <td style='text-align:right'><i><?php print number_format_i18n($ds); ?> </i></td> <td style='text-align:center'><?php print 'Not Monitored'; ?> </td> <td style='text-align:right'><?php print 'N/A'; ?> </td> <td style='text-align:right'><?php print $uptime; ?> </td> <td style='text-align:right'><?php print filter_value($host['hostname'], get_request_var('filter')); ?> </td> <td style='text-align:right'><?php print 'N/A'; ?> </td> <td style='text-align:right'><?php print 'N/A'; ?> </td> <td style='text-align:right'><?php print 'N/A'; ?> </td> <?php } form_end_row(); } } else { print '<tr><td class="center" colspan="12">' . __('No Devices') . '</td></tr>'; } html_end_box(false); if (sizeof($hosts)) { print $nav; } host_legend(); //thold_display_rusage(); }
function host() { global $device_actions, $item_rows; /* ================= input validation ================= */ input_validate_input_number(get_request_var_request('host_template_id')); input_validate_input_number(get_request_var_request('page')); input_validate_input_number(get_request_var_request('host_status')); input_validate_input_number(get_request_var_request('rows')); /* ==================================================== */ /* clean up search string */ if (isset($_REQUEST['filter'])) { $_REQUEST['filter'] = sanitize_search_string(get_request_var_request('filter')); } /* clean up sort_column */ if (isset($_REQUEST['sort_column'])) { $_REQUEST['sort_column'] = sanitize_search_string(get_request_var_request('sort_column')); } /* clean up search string */ if (isset($_REQUEST['sort_direction'])) { $_REQUEST['sort_direction'] = sanitize_search_string(get_request_var_request('sort_direction')); } /* if the user pushed the 'clear' button */ if (isset($_REQUEST['clear_x'])) { kill_session_var('sess_device_current_page'); kill_session_var('sess_device_filter'); kill_session_var('sess_device_host_template_id'); kill_session_var('sess_host_status'); kill_session_var('sess_default_rows'); kill_session_var('sess_host_sort_column'); kill_session_var('sess_host_sort_direction'); unset($_REQUEST['page']); unset($_REQUEST['filter']); unset($_REQUEST['host_template_id']); unset($_REQUEST['host_status']); unset($_REQUEST['rows']); unset($_REQUEST['sort_column']); unset($_REQUEST['sort_direction']); } if (!empty($_SESSION['sess_host_status']) && !empty($_REQUEST['host_status'])) { if ($_SESSION['sess_host_status'] != $_REQUEST['host_status']) { $_REQUEST['page'] = 1; } } /* remember these search fields in session vars so we don't have to keep passing them around */ load_current_session_value('page', 'sess_device_current_page', '1'); load_current_session_value('filter', 'sess_device_filter', ''); load_current_session_value('host_template_id', 'sess_device_host_template_id', '-1'); load_current_session_value('host_status', 'sess_host_status', '-1'); load_current_session_value('rows', 'sess_default_rows', read_config_option('num_rows_table')); load_current_session_value('sort_column', 'sess_host_sort_column', 'description'); load_current_session_value('sort_direction', 'sess_host_sort_direction', 'ASC'); /* if the number of rows is -1, set it to the default */ if ($_REQUEST['rows'] == -1) { $_REQUEST['rows'] = read_config_option('num_rows_table'); } ?> <script type="text/javascript"> <!-- function applyFilter() { strURL = 'host.php?host_status=' + $('#host_status').val(); strURL = strURL + '&host_template_id=' + $('#host_template_id').val(); strURL = strURL + '&rows=' + $('#rows').val(); strURL = strURL + '&filter=' + $('#filter').val(); strURL = strURL + '&page=' + $('#page').val(); strURL = strURL + '&header=false'; $.get(strURL, function(data) { $('#main').html(data); applySkin(); }); } function clearFilter() { strURL = 'host.php?clear_x=1&header=false'; $.get(strURL, function(data) { $('#main').html(data); applySkin(); }); } $(function(data) { $('#refresh').click(function() { applyFilter(); }); $('#clear').click(function() { clearFilter(); }); $('#form_devices').submit(function(event) { event.preventDefault(); applyFilter(); }); }); --> </script> <?php html_start_box('<strong>Devices</strong>', '100%', '', '3', 'center', 'host.php?action=edit&host_template_id=' . htmlspecialchars(get_request_var_request('host_template_id')) . '&host_status=' . htmlspecialchars(get_request_var_request('host_status'))); ?> <tr class='even noprint'> <td> <form id='form_devices' name="form_devices" action="host.php"> <table cellpadding="2" cellspacing="0"> <tr> <td width='50'> Search </td> <td> <input id='filter' type="text" name="filter" size="25" value="<?php print htmlspecialchars(get_request_var_request('filter')); ?> " onChange='applyFilter()'> </td> <td> Template </td> <td> <select id='host_template_id' name="host_template_id" onChange="applyFilter()"> <option value="-1"<?php if (get_request_var_request('host_template_id') == '-1') { ?> selected<?php } ?> >Any</option> <option value="0"<?php if (get_request_var_request('host_template_id') == '0') { ?> selected<?php } ?> >None</option> <?php $host_templates = db_fetch_assoc('SELECT id, name FROM host_template ORDER BY name'); if (sizeof($host_templates) > 0) { foreach ($host_templates as $host_template) { print "<option value='" . $host_template['id'] . "'"; if (get_request_var_request('host_template_id') == $host_template['id']) { print ' selected'; } print '>' . htmlspecialchars($host_template['name']) . "</option>\n"; } } ?> </select> </td> <td> Status </td> <td> <select id='host_status' name="host_status" onChange="applyFilter()"> <option value="-1"<?php if (get_request_var_request('host_status') == '-1') { ?> selected<?php } ?> >Any</option> <option value="-3"<?php if (get_request_var_request('host_status') == '-3') { ?> selected<?php } ?> >Enabled</option> <option value="-2"<?php if (get_request_var_request('host_status') == '-2') { ?> selected<?php } ?> >Disabled</option> <option value="-4"<?php if (get_request_var_request('host_status') == '-4') { ?> selected<?php } ?> >Not Up</option> <option value="3"<?php if (get_request_var_request('host_status') == '3') { ?> selected<?php } ?> >Up</option> <option value="1"<?php if (get_request_var_request('host_status') == '1') { ?> selected<?php } ?> >Down</option> <option value="2"<?php if (get_request_var_request('host_status') == '2') { ?> selected<?php } ?> >Recovering</option> <option value="0"<?php if (get_request_var_request('host_status') == '0') { ?> selected<?php } ?> >Unknown</option> </select> </td> <td> Devices </td> <td> <select id='rows' name="rows" onChange="applyFilter()"> <?php if (sizeof($item_rows) > 0) { foreach ($item_rows as $key => $value) { print "<option value='" . $key . "'"; if (get_request_var_request('rows') == $key) { print ' selected'; } print '>' . htmlspecialchars($value) . "</option>\n"; } } ?> </select> </td> <td> <input type="button" id='refresh' value="Go" title="Set/Refresh Filters"> </td> <td> <input type="button" id='clear' name="clear_x" value="Clear" title="Clear Filters"> </td> </tr> </table> <input type='hidden' id='page' name='page' value='<?php print $_REQUEST['page']; ?> '> </form> </td> </tr> <?php html_end_box(); /* form the 'where' clause for our main sql query */ if (strlen(get_request_var_request('filter'))) { $sql_where = "where (host.hostname like '%%" . get_request_var_request('filter') . "%%' OR host.description like '%%" . get_request_var_request('filter') . "%%')"; } else { $sql_where = ''; } if (get_request_var_request('host_status') == '-1') { /* Show all items */ } elseif (get_request_var_request('host_status') == '-2') { $sql_where .= strlen($sql_where) ? " AND host.disabled='on'" : " WHERE host.disabled='on'"; } elseif (get_request_var_request('host_status') == '-3') { $sql_where .= strlen($sql_where) ? " AND host.disabled=''" : " WHERE host.disabled=''"; } elseif (get_request_var_request('host_status') == '-4') { $sql_where .= strlen($sql_where) ? " AND (host.status!='3' OR host.disabled='on')" : " WHERE (host.status!='3' OR host.disabled='on')"; } else { $sql_where .= strlen($sql_where) ? ' AND (host.status=' . get_request_var_request('host_status') . " AND host.disabled = '')" : 'where (host.status=' . get_request_var_request('host_status') . " AND host.disabled = '')"; } if (get_request_var_request('host_template_id') == '-1') { /* Show all items */ } elseif (get_request_var_request('host_template_id') == '0') { $sql_where .= strlen($sql_where) ? ' AND host.host_template_id=0' : ' WHERE host.host_template_id=0'; } elseif (!empty($_REQUEST['host_template_id'])) { $sql_where .= strlen($sql_where) ? ' AND host.host_template_id=' . get_request_var_request('host_template_id') : ' WHERE host.host_template_id=' . get_request_var_request('host_template_id'); } /* print checkbox form for validation */ print "<form name='chk' method='post' action='host.php'>\n"; html_start_box('', '100%', '', '3', 'center', ''); $total_rows = db_fetch_cell("SELECT\n\t\tCOUNT(host.id)\n\t\tFROM host\n\t\t{$sql_where}"); $sortby = get_request_var_request('sort_column'); if ($sortby == 'hostname') { $sortby = 'INET_ATON(hostname)'; } $sql_query = "SELECT host.*, graphs, data_sources\n\t\tFROM host\n\t\tLEFT JOIN (SELECT host_id, COUNT(*) AS graphs FROM graph_local GROUP BY host_id) AS gl\n\t\tON host.id=gl.host_id\n\t\tLEFT JOIN (SELECT host_id, COUNT(*) AS data_sources FROM data_local GROUP BY host_id) AS dl\n\t\tON host.id=dl.host_id\n\t\t{$sql_where}\n\t\tGROUP BY host.id\n\t\tORDER BY " . $sortby . ' ' . get_request_var_request('sort_direction') . ' LIMIT ' . get_request_var_request('rows') * (get_request_var_request('page') - 1) . ',' . get_request_var_request('rows'); $hosts = db_fetch_assoc($sql_query); $nav = html_nav_bar('host.php?filter=' . get_request_var_request('filter') . '&host_template_id=' . get_request_var_request('host_template_id') . '&host_status=' . get_request_var_request('host_status'), MAX_DISPLAY_PAGES, get_request_var_request('page'), get_request_var_request('rows'), $total_rows, 13, 'Devices', 'page', 'main'); print $nav; $display_text = array('description' => array('display' => 'Device Description', 'align' => 'left', 'sort' => 'ASC', 'tip' => 'The name by which this Device will be referred to.'), 'hostname' => array('display' => 'Hostname', 'align' => 'left', 'sort' => 'ASC', 'tip' => 'Either an IP address, or hostname. If a hostname, it must be resolvable by either DNS, or from your hosts file.'), 'id' => array('display' => 'ID', 'align' => 'right', 'sort' => 'ASC', 'tip' => 'The internal database ID for this Device. Useful when performing automation or debugging.'), 'graphs' => array('display' => 'Graphs', 'align' => 'right', 'sort' => 'ASC', 'tip' => 'The total number of Graphs generated from this Device.'), 'data_sources' => array('display' => 'Data Sources', 'align' => 'right', 'sort' => 'ASC', 'tip' => 'The total number of Data Sources generated from this Device.'), 'status' => array('display' => 'Status', 'align' => 'center', 'sort' => 'ASC', 'tip' => 'The monitoring status of the Device based upon ping results. If this Device is a special type Device, by using the hostname "localhost", or due to the setting to not perform an Availability Check, it will always remain Up. When using cmd.php data collector, a Device with no Graphs, is not pinged by the data collector and will remain in an "Unknown" state.'), 'status_rec_date' => array('display' => 'In State', 'align' => 'right', 'sort' => 'ASC', 'tip' => 'The amount of time that this Device has been in its current state.'), 'snmp_sysUpTimeInstance' => array('display' => 'Uptime', 'align' => 'right', 'sort' => 'ASC', 'tip' => 'The current amount of time that the host has been up.'), 'polling_time' => array('display' => 'Poll Time', 'align' => 'right', 'sort' => 'ASC', 'tip' => 'The the amount of time it takes to collect data from this Device.'), 'cur_time' => array('display' => 'Current (ms)', 'align' => 'right', 'sort' => 'DESC', 'tip' => 'The current ping time in milliseconds to reach the Device.'), 'avg_time' => array('display' => 'Average (ms)', 'align' => 'right', 'sort' => 'DESC', 'tip' => 'The average ping time in milliseconds to reach the Device since the counters were cleared for this Device.'), 'availability' => array('display' => 'Availability', 'align' => 'right', 'sort' => 'ASC', 'tip' => 'The availability percentage based upon ping results insce the counters were cleared for this Device.')); html_header_sort_checkbox($display_text, get_request_var_request('sort_column'), get_request_var_request('sort_direction'), false); $i = 0; if (sizeof($hosts) > 0) { foreach ($hosts as $host) { if ($host['disabled'] == '' && ($host['status'] == HOST_RECOVERING || $host['status'] == HOST_UP) && ($host['availability_method'] != AVAIL_NONE && $host['availability_method'] != AVAIL_PING)) { $snmp_uptime = $host['snmp_sysUpTimeInstance']; $days = intval($snmp_uptime / (60 * 60 * 24 * 100)); $remainder = $snmp_uptime % (60 * 60 * 24 * 100); $hours = intval($remainder / (60 * 60 * 100)); $remainder = $remainder % (60 * 60 * 100); $minutes = intval($remainder / (60 * 100)); $uptime = "{$days} d {$hours} h {$minutes} m"; } else { $uptime = "N/A"; } form_alternate_row('line' . $host['id'], true); form_selectable_cell("<a class='linkEditMain' href='" . htmlspecialchars('host.php?action=edit&id=' . $host['id']) . "'>" . (strlen(get_request_var_request('filter')) ? preg_replace('/(' . preg_quote(get_request_var_request('filter'), '/') . ')/i', "<span class='filteredValue'>\\1</span>", htmlspecialchars($host['description'])) : htmlspecialchars($host['description'])) . '</a>', $host['id']); form_selectable_cell(strlen(get_request_var_request('filter')) ? preg_replace('/(' . preg_quote(get_request_var_request('filter'), '/') . ')/i', "<span class='filteredValue'>\\1</span>", htmlspecialchars($host['hostname'])) : htmlspecialchars($host['hostname']), $host['id']); form_selectable_cell($host['id'], $host['id'], '', 'text-align:right'); form_selectable_cell(number_format($host['graphs']), $host['id'], '', 'text-align:right'); form_selectable_cell(number_format($host['data_sources']), $host['id'], '', 'text-align:right'); form_selectable_cell(get_colored_device_status($host['disabled'] == 'on' ? true : false, $host['status']), $host['id'], '', 'text-align:center'); form_selectable_cell(get_timeinstate($host), $host['id'], '', 'text-align:right'); form_selectable_cell($uptime, $host['id'], '', 'text-align:right'); form_selectable_cell(round($host['polling_time'], 2), $host['id'], '', 'text-align:right'); form_selectable_cell(round($host['cur_time'], 2), $host['id'], '', 'text-align:right'); form_selectable_cell(round($host['avg_time'], 2), $host['id'], '', 'text-align:right'); form_selectable_cell(round($host['availability'], 2) . ' %', $host['id'], '', 'text-align:right'); form_checkbox_cell($host['description'], $host['id']); form_end_row(); } /* put the nav bar on the bottom as well */ print $nav; } else { print "<tr class='tableRow'><td colspan='11'><em>No Devices</em></td></tr>"; } html_end_box(false); /* add a list of tree names to the actions dropdown */ add_tree_names_to_actions_array(); /* draw the dropdown containing a list of available actions for this form */ draw_actions_dropdown($device_actions); print "</form>\n"; }
function host() { global $colors, $device_actions, $item_rows; /* ================= input validation ================= */ input_validate_input_number(get_request_var_request("host_template_id")); input_validate_input_number(get_request_var_request("page")); input_validate_input_number(get_request_var_request("host_status")); input_validate_input_number(get_request_var_request("host_rows")); /* ==================================================== */ /* clean up search string */ if (isset($_REQUEST["filter"])) { $_REQUEST["filter"] = sanitize_search_string(get_request_var("filter")); } /* clean up sort_column */ if (isset($_REQUEST["sort_column"])) { $_REQUEST["sort_column"] = sanitize_search_string(get_request_var("sort_column")); } /* clean up search string */ if (isset($_REQUEST["sort_direction"])) { $_REQUEST["sort_direction"] = sanitize_search_string(get_request_var("sort_direction")); } /* if the user pushed the 'clear' button */ if (isset($_REQUEST["clear_x"])) { kill_session_var("sess_device_current_page"); kill_session_var("sess_device_filter"); kill_session_var("sess_device_host_template_id"); kill_session_var("sess_host_status"); kill_session_var("sess_host_rows"); kill_session_var("sess_host_sort_column"); kill_session_var("sess_host_sort_direction"); unset($_REQUEST["page"]); unset($_REQUEST["filter"]); unset($_REQUEST["host_template_id"]); unset($_REQUEST["host_status"]); unset($_REQUEST["host_rows"]); unset($_REQUEST["sort_column"]); unset($_REQUEST["sort_direction"]); } if (!empty($_SESSION["sess_host_status"]) && !empty($_REQUEST["host_status"])) { if ($_SESSION["sess_host_status"] != $_REQUEST["host_status"]) { $_REQUEST["page"] = 1; } } /* remember these search fields in session vars so we don't have to keep passing them around */ load_current_session_value("page", "sess_device_current_page", "1"); load_current_session_value("filter", "sess_device_filter", ""); load_current_session_value("host_template_id", "sess_device_host_template_id", "-1"); load_current_session_value("host_status", "sess_host_status", "-1"); load_current_session_value("host_rows", "sess_host_rows", read_config_option("num_rows_device")); load_current_session_value("sort_column", "sess_host_sort_column", "description"); load_current_session_value("sort_direction", "sess_host_sort_direction", "ASC"); /* if the number of rows is -1, set it to the default */ if ($_REQUEST["host_rows"] == -1) { $_REQUEST["host_rows"] = read_config_option("num_rows_device"); } ?> <script type="text/javascript"> <!-- function applyViewDeviceFilterChange(objForm) { strURL = '?host_status=' + objForm.host_status.value; strURL = strURL + '&host_template_id=' + objForm.host_template_id.value; strURL = strURL + '&host_rows=' + objForm.host_rows.value; strURL = strURL + '&filter=' + objForm.filter.value; document.location = strURL; } --> </script> <?php /* modify for multi user start */ if (check_resource_count(RESOURCE_HOST) == TRUE) { html_start_box("<strong>Devices</strong>", "100%", $colors["header"], "3", "center", "host.php?action=edit&host_template_id=" . htmlspecialchars(get_request_var_request("host_template_id")) . "&host_status=" . htmlspecialchars(get_request_var_request("host_status"))); } else { html_start_box("<strong>Devices</strong>", "100%", $colors["header"], "3", "center", ""); } /* modify for multi user end */ ?> <tr bgcolor="#<?php print $colors["panel"]; ?> "> <td> <form name="form_devices" action="host.php"> <table width="100%" cellpadding="0" cellspacing="0"> <tr> <td nowrap style='white-space: nowrap;' width="50"> Type: </td> <td width="1"> <select name="host_template_id" onChange="applyViewDeviceFilterChange(document.form_devices)"> <option value="-1"<?php if (get_request_var_request("host_template_id") == "-1") { ?> selected<?php } ?> >Any</option> <option value="0"<?php if (get_request_var_request("host_template_id") == "0") { ?> selected<?php } ?> >None</option> <?php if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) { $host_templates = db_fetch_assoc("\r\n SELECT DISTINCT host_template.id,host_template.name FROM host_template\r\n INNER JOIN host ON host_template.id = host.host_template_id\r\n INNER JOIN user_auth_perms ON host.id = user_auth_perms.item_id AND user_auth_perms.user_id = '" . $_SESSION["sess_user_id"] . "' AND user_auth_perms.type = '3'\r\n ORDER BY host_template.name"); } else { $host_templates = db_fetch_assoc("select id,name from host_template order by name"); } /* modify for multi user end */ if (sizeof($host_templates) > 0) { foreach ($host_templates as $host_template) { print "<option value='" . $host_template["id"] . "'"; if (get_request_var_request("host_template_id") == $host_template["id"]) { print " selected"; } print ">" . htmlspecialchars($host_template["name"]) . "</option>\n"; } } ?> </select> </td> <td nowrap style='white-space: nowrap;' width="50"> Status: </td> <td width="1"> <select name="host_status" onChange="applyViewDeviceFilterChange(document.form_devices)"> <option value="-1"<?php if (get_request_var_request("host_status") == "-1") { ?> selected<?php } ?> >Any</option> <option value="-3"<?php if (get_request_var_request("host_status") == "-3") { ?> selected<?php } ?> >Enabled</option> <option value="-2"<?php if (get_request_var_request("host_status") == "-2") { ?> selected<?php } ?> >Disabled</option> <option value="-4"<?php if (get_request_var_request("host_status") == "-4") { ?> selected<?php } ?> >Not Up</option> <option value="3"<?php if (get_request_var_request("host_status") == "3") { ?> selected<?php } ?> >Up</option> <option value="1"<?php if (get_request_var_request("host_status") == "1") { ?> selected<?php } ?> >Down</option> <option value="2"<?php if (get_request_var_request("host_status") == "2") { ?> selected<?php } ?> >Recovering</option> <option value="0"<?php if (get_request_var_request("host_status") == "0") { ?> selected<?php } ?> >Unknown</option> </select> </td> <td nowrap style='white-space: nowrap;' width="20"> Search: </td> <td width="1"> <input type="text" name="filter" size="20" value="<?php print htmlspecialchars(get_request_var_request("filter")); ?> "> </td> <td nowrap style='white-space: nowrap;' width="50"> Rows per Page: </td> <td width="1"> <select name="host_rows" onChange="applyViewDeviceFilterChange(document.form_devices)"> <option value="-1"<?php if (get_request_var_request("host_rows") == "-1") { ?> selected<?php } ?> >Default</option> <?php if (sizeof($item_rows) > 0) { foreach ($item_rows as $key => $value) { print "<option value='" . $key . "'"; if (get_request_var_request("host_rows") == $key) { print " selected"; } print ">" . htmlspecialchars($value) . "</option>\n"; } } ?> </select> </td> <td nowrap> <input type="submit" value="Go" title="Set/Refresh Filters"> <input type="submit" name="clear_x" value="Clear" title="Clear Filters"> </td> </tr> </table> <input type='hidden' name='page' value='1'> </form> </td> </tr> <?php html_end_box(); /* form the 'where' clause for our main sql query */ if (strlen(get_request_var_request("filter"))) { $sql_where = "where (host.hostname like '%%" . get_request_var_request("filter") . "%%' OR host.description like '%%" . get_request_var_request("filter") . "%%')"; } else { $sql_where = ""; } if (get_request_var_request("host_status") == "-1") { /* Show all items */ } elseif (get_request_var_request("host_status") == "-2") { $sql_where .= strlen($sql_where) ? " and host.disabled='on'" : "where host.disabled='on'"; } elseif (get_request_var_request("host_status") == "-3") { $sql_where .= strlen($sql_where) ? " and host.disabled=''" : "where host.disabled=''"; } elseif (get_request_var_request("host_status") == "-4") { $sql_where .= strlen($sql_where) ? " and (host.status!='3' or host.disabled='on')" : "where (host.status!='3' or host.disabled='on')"; } else { $sql_where .= strlen($sql_where) ? " and (host.status=" . get_request_var_request("host_status") . " AND host.disabled = '')" : "where (host.status=" . get_request_var_request("host_status") . " AND host.disabled = '')"; } if (get_request_var_request("host_template_id") == "-1") { /* Show all items */ } elseif (get_request_var_request("host_template_id") == "0") { $sql_where .= strlen($sql_where) ? " and host.host_template_id=0" : "where host.host_template_id=0"; } elseif (!empty($_REQUEST["host_template_id"])) { $sql_where .= strlen($sql_where) ? " and host.host_template_id=" . get_request_var_request("host_template_id") : "where host.host_template_id=" . get_request_var_request("host_template_id"); } /* modify for multi user start */ $sql_join = ""; if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) { $sql_join = "INNER JOIN user_auth_perms ON host.id = user_auth_perms.item_id AND user_auth_perms.user_id = '" . $_SESSION["sess_user_id"] . "' AND user_auth_perms.type = '3'"; } /* modify for multi user end */ /* print checkbox form for validation */ print "<form name='chk' method='post' action='host.php'>\n"; html_start_box("", "100%", $colors["header"], "3", "center", ""); /* modify for multi user start */ $total_rows = db_fetch_cell("select\r\n\t\tCOUNT(host.id)\r\n\t\tfrom host\r\n {$sql_join}\r\n\t\t{$sql_where}"); /* modify for multi user end */ $sortby = get_request_var_request("sort_column"); if ($sortby == "hostname") { $sortby = "INET_ATON(hostname)"; } $host_graphs = array_rekey(db_fetch_assoc("SELECT host_id, count(*) as graphs FROM graph_local GROUP BY host_id"), "host_id", "graphs"); $host_data_sources = array_rekey(db_fetch_assoc("SELECT host_id, count(*) as data_sources FROM data_local GROUP BY host_id"), "host_id", "data_sources"); /* modify for multi user start */ $sql_query = "SELECT host.*\r\n\t\tFROM host\r\n\t\t{$sql_join}\r\n\t\t{$sql_where}\r\n\t\tORDER BY " . $sortby . " " . get_request_var_request("sort_direction") . "\r\n\t\tLIMIT " . get_request_var_request("host_rows") * (get_request_var_request("page") - 1) . "," . get_request_var_request("host_rows"); /* modify for multi user end */ $hosts = db_fetch_assoc($sql_query); /* generate page list */ $url_page_select = get_page_list(get_request_var_request("page"), MAX_DISPLAY_PAGES, get_request_var_request("host_rows"), $total_rows, "host.php?filter=" . get_request_var_request("filter") . "&host_template_id=" . get_request_var_request("host_template_id") . "&host_status=" . get_request_var_request("host_status")); $nav = "<tr bgcolor='#" . $colors["header"] . "'>\r\n\t\t\t<td colspan='11'>\r\n\t\t\t\t<table width='100%' cellspacing='0' cellpadding='0' border='0'>\r\n\t\t\t\t\t<tr>\r\n\t\t\t\t\t\t<td align='left' class='textHeaderDark'>\r\n\t\t\t\t\t\t\t<strong><< "; if (get_request_var_request("page") > 1) { $nav .= "<a class='linkOverDark' href='" . htmlspecialchars("host.php?filter=" . get_request_var_request("filter") . "&host_template_id=" . get_request_var_request("host_template_id") . "&host_status=" . get_request_var_request("host_status") . "&page=" . (get_request_var_request("page") - 1)) . "'>"; } $nav .= "Previous"; if (get_request_var_request("page") > 1) { $nav .= "</a>"; } $nav .= "</strong>\r\n\t\t\t\t\t\t</td>\n\r\n\t\t\t\t\t\t<td align='center' class='textHeaderDark'>\r\n\t\t\t\t\t\t\tShowing Rows " . (get_request_var_request("host_rows") * (get_request_var_request("page") - 1) + 1) . " to " . ($total_rows < read_config_option("num_rows_device") || $total_rows < get_request_var_request("host_rows") * get_request_var_request("page") ? $total_rows : get_request_var_request("host_rows") * get_request_var_request("page")) . " of {$total_rows} [{$url_page_select}]\r\n\t\t\t\t\t\t</td>\n\r\n\t\t\t\t\t\t<td align='right' class='textHeaderDark'>\r\n\t\t\t\t\t\t\t<strong>"; if (get_request_var_request("page") * get_request_var_request("host_rows") < $total_rows) { $nav .= "<a class='linkOverDark' href='" . htmlspecialchars("host.php?filter=" . get_request_var_request("filter") . "&host_template_id=" . get_request_var_request("host_template_id") . "&host_status=" . get_request_var_request("host_status") . "&page=" . (get_request_var_request("page") + 1)) . "'>"; } $nav .= "Next"; if (get_request_var_request("page") * get_request_var_request("host_rows") < $total_rows) { $nav .= "</a>"; } $nav .= " >></strong>\r\n\t\t\t\t\t\t</td>\n\r\n\t\t\t\t\t</tr>\r\n\t\t\t\t</table>\r\n\t\t\t</td>\r\n\t\t</tr>\n"; print $nav; $display_text = array("description" => array("Description", "ASC"), "id" => array("ID", "ASC"), "nosort1" => array("Graphs", "ASC"), "nosort2" => array("Data Sources", "ASC"), "status" => array("Status", "ASC"), "status_rec_date" => array("In State", "ASC"), "hostname" => array("Hostname", "ASC"), "cur_time" => array("Current (ms)", "DESC"), "avg_time" => array("Average (ms)", "DESC"), "availability" => array("Availability", "ASC")); html_header_sort_checkbox($display_text, get_request_var_request("sort_column"), get_request_var_request("sort_direction"), false); $i = 0; if (sizeof($hosts) > 0) { foreach ($hosts as $host) { form_alternate_row_color($colors["alternate"], $colors["light"], $i, 'line' . $host["id"]); $i++; form_selectable_cell("<a class='linkEditMain' href='" . htmlspecialchars("host.php?action=edit&id=" . $host["id"]) . "'>" . (strlen(get_request_var_request("filter")) ? preg_replace("/(" . preg_quote(get_request_var_request("filter")) . ")/i", "<span style='background-color: #F8D93D;'>\\1</span>", htmlspecialchars($host["description"])) : htmlspecialchars($host["description"])) . "</a>", $host["id"], 250); form_selectable_cell(round($host["id"], 2), $host["id"]); form_selectable_cell(isset($host_graphs[$host["id"]]) ? $host_graphs[$host["id"]] : 0, $host["id"]); form_selectable_cell(isset($host_data_sources[$host["id"]]) ? $host_data_sources[$host["id"]] : 0, $host["id"]); /* modify for multi user start */ form_selectable_cell(get_colored_device_status($host["disabled"] == "on" || $host["disabled"] == "ps" ? $host["disabled"] : false, $host["status"]), $host["id"]); /* modify for multi user end */ form_selectable_cell(get_timeinstate($host), $host["id"]); form_selectable_cell(strlen(get_request_var_request("filter")) ? preg_replace("/(" . preg_quote(get_request_var_request("filter")) . ")/i", "<span style='background-color: #F8D93D;'>\\1</span>", htmlspecialchars($host["hostname"])) : htmlspecialchars($host["hostname"]), $host["id"]); form_selectable_cell(round($host["cur_time"], 2), $host["id"]); form_selectable_cell(round($host["avg_time"], 2), $host["id"]); form_selectable_cell(round($host["availability"], 2), $host["id"]); form_checkbox_cell($host["description"], $host["id"]); form_end_row(); } /* put the nav bar on the bottom as well */ print $nav; } else { print "<tr><td><em>No Hosts</em></td></tr>"; } html_end_box(false); /* add a list of tree names to the actions dropdown */ add_tree_names_to_actions_array(); /* draw the dropdown containing a list of available actions for this form */ draw_actions_dropdown($device_actions); print "</form>\n"; }