function hmib_devices() { global $config, $colors, $item_rows; /* ================= input validation ================= */ input_validate_input_number(get_request_var_request("type")); input_validate_input_number(get_request_var_request("status")); input_validate_input_number(get_request_var_request("template")); input_validate_input_number(get_request_var_request("page")); input_validate_input_number(get_request_var_request("rows")); /* ==================================================== */ /* clean up sort_column */ if (isset($_REQUEST["sort_column"])) { $_REQUEST["sort_column"] = sanitize_search_string(get_request_var("sort_column")); } /* clean up sort_direction */ if (isset($_REQUEST["sort_direction"])) { $_REQUEST["sort_direction"] = sanitize_search_string(get_request_var("sort_direction")); } /* clean up process string */ if (isset($_REQUEST["process"])) { $_REQUEST["process"] = sanitize_search_string(get_request_var("process")); } /* clean up filter string */ if (isset($_REQUEST["filter"])) { $_REQUEST["filter"] = sanitize_search_string(get_request_var("filter")); } if (isset($_REQUEST["reset"])) { kill_session_var("sess_hmib_device_sort_column"); kill_session_var("sess_hmib_device_sort_direction"); kill_session_var("sess_hmib_device_type"); kill_session_var("sess_hmib_device_status"); kill_session_var("sess_hmib_device_template"); kill_session_var("sess_hmib_device_filter"); kill_session_var("sess_hmib_device_process"); kill_session_var("sess_hmib_device_rows"); kill_session_var("sess_hmib_device_current_page"); } elseif (isset($_REQUEST["clear"])) { kill_session_var("sess_hmib_device_sort_column"); kill_session_var("sess_hmib_device_sort_direction"); kill_session_var("sess_hmib_device_type"); kill_session_var("sess_hmib_device_status"); kill_session_var("sess_hmib_device_template"); kill_session_var("sess_hmib_device_filter"); kill_session_var("sess_hmib_device_process"); kill_session_var("sess_hmib_device_rows"); kill_session_var("sess_hmib_device_current_page"); unset($_REQUEST["sort_column"]); unset($_REQUEST["sort_direction"]); unset($_REQUEST["type"]); unset($_REQUEST["status"]); unset($_REQUEST["template"]); unset($_REQUEST["filter"]); unset($_REQUEST["process"]); unset($_REQUEST["rows"]); unset($_REQUEST["page"]); } else { /* if any of the settings changed, reset the page number */ $changed = false; $changed += hmib_check_changed("type", "sess_hmib_device_type"); $changed += hmib_check_changed("status", "sess_hmib_device_status"); $changed += hmib_check_changed("template", "sess_hmib_device_template"); $changed += hmib_check_changed("fitler", "sess_hmib_device_filter"); $changed += hmib_check_changed("process", "sess_hmib_device_process"); $changed += hmib_check_changed("rows", "sess_hmib_device_rows"); if ($changed) { $_REQUEST["page"] = "1"; } } load_current_session_value("page", "sess_hmib_device_current_page", "1"); load_current_session_value("rows", "sess_hmib_device_rows", "-1"); load_current_session_value("sort_column", "sess_hmib_device_sort_column", "description"); load_current_session_value("sort_direction", "sess_hmib_device_sort_direction", "ASC"); load_current_session_value("type", "sess_hmib_device_type", "-1"); load_current_session_value("status", "sess_hmib_device_status", "-1"); load_current_session_value("template", "sess_hmib_device_template", "-1"); load_current_session_value("filter", "sess_hmib_device_filter", ""); load_current_session_value("process", "sess_hmib_device_process", ""); ?> <script type="text/javascript"> <!-- function applyHostFilter(objForm) { strURL = '?action=devices'; strURL = strURL + '&type=' + objForm.type.value; strURL = strURL + '&status=' + objForm.status.value; strURL = strURL + '&process=' + objForm.process.value; strURL = strURL + '&template=' + objForm.template.value; strURL = strURL + '&filter=' + objForm.filter.value; strURL = strURL + '&rows=' + objForm.rows.value; document.location = strURL; } function clearHosts() { strURL = '?action=devices&clear='; document.location = strURL; } --> </script> <?php html_start_box("<strong>Device Filter</strong>", "100%", $colors["header"], "3", "center", ""); ?> <tr bgcolor="#<?php print $colors["panel"]; ?> "> <td> <form name="devices" action="hmib.php?action=devices"> <table cellpadding="0" cellspacing="0"> <tr> <td nowrap style='white-space: nowrap;' width="60"> OS Type: </td> <td width="1"> <select name="type" onChange="applyHostFilter(document.devices)"> <option value="-1"<?php if (get_request_var_request("type") == "-1") { ?> selected<?php } ?> >All</option> <?php $types = db_fetch_assoc("SELECT DISTINCT id, CONCAT_WS('', name, ' [', version, ']') AS name\n\t\t\t\t\t\t\t\tFROM plugin_hmib_hrSystemTypes AS hrst\n\t\t\t\t\t\t\t\tINNER JOIN plugin_hmib_hrSystem AS hrs\n\t\t\t\t\t\t\t\tON hrst.id=hrs.host_type\n\t\t\t\t\t\t\t\tWHERE name!='' ORDER BY name"); if (sizeof($types)) { foreach ($types as $t) { echo "<option value='" . $t["id"] . "' " . (get_request_var_request("type") == $t["id"] ? "selected" : "") . ">" . $t["name"] . "</option>"; } } ?> </select> </td> <td nowrap style='white-space: nowrap;' width="60"> Template: </td> <td width="1"> <select name="template" onChange="applyHostFilter(document.devices)"> <option value="-1"<?php if (get_request_var_request("template") == "-1") { ?> selected<?php } ?> >All</option> <?php $templates = db_fetch_assoc("SELECT DISTINCT ht.id, ht.name\n\t\t\t\t\t\t\t\tFROM host_template AS ht\n\t\t\t\t\t\t\t\tINNER JOIN host\n\t\t\t\t\t\t\t\tON ht.id=host.host_template_id\n\t\t\t\t\t\t\t\tINNER JOIN plugin_hmib_hrSystem AS hrs\n\t\t\t\t\t\t\t\tON host.id=hrs.host_id\n\t\t\t\t\t\t\t\tORDER BY name"); if (sizeof($templates)) { foreach ($templates as $t) { echo "<option value='" . $t["id"] . "' " . (get_request_var_request("template") == $t["id"] ? "selected" : "") . ">" . $t["name"] . "</option>"; } } ?> </select> </td> <td nowrap style='white-space: nowrap;' width="60"> Process: </td> <td width="1"> <select name="process" onChange="applyHostFilter(document.devices)"> <option value="-1"<?php if (get_request_var_request("process") == "-1") { ?> selected<?php } ?> >All</option> <?php $processes = db_fetch_assoc("SELECT DISTINCT name FROM plugin_hmib_hrSWRun WHERE name!='' ORDER BY name"); if (sizeof($processes)) { foreach ($processes as $p) { echo "<option value='" . $p["name"] . "' " . (get_request_var_request("process") == $p["name"] ? "selected" : "") . ">" . $p["name"] . "</option>"; } } ?> </select> </td> </tr> </table> <table cellpadding="0" cellspacing="0"> <tr> <td nowrap style='white-space: nowrap;' width="60"> Status: </td> <td width="1"> <select name="status" onChange="applyHostFilter(document.devices)"> <option value="-1"<?php if (get_request_var_request("type") == "-1") { ?> selected<?php } ?> >All</option> <?php $statuses = db_fetch_assoc("SELECT DISTINCT status\n\t\t\t\t\t\t\t\tFROM host\n\t\t\t\t\t\t\t\tINNER JOIN plugin_hmib_hrSystem\n\t\t\t\t\t\t\t\tON host.id=plugin_hmib_hrSystem.host_id"); $statuses = array_merge($statuses, array("-2" => array("status" => "-2"))); if (sizeof($statuses)) { foreach ($statuses as $s) { switch ($s["status"]) { case "0": $status = "Unknown"; break; case "1": $status = "Down"; break; case "2": $status = "Recovering"; break; case "3": $status = "Up"; break; case "-2": $status = "Disabled"; break; } echo "<option value='" . $s["status"] . "' " . (get_request_var_request("status") == $s["status"] ? "selected" : "") . ">" . $status . "</option>"; } } ?> </select> </td> <td nowrap style='white-space: nowrap;' width="60"> Rows: </td> <td width="1"> <select name="rows" onChange="applyHostFilter(document.devices)"> <option value="-1"<?php if (get_request_var_request("rows") == "-1") { ?> selected<?php } ?> >Default</option> <?php if (sizeof($item_rows)) { foreach ($item_rows as $key => $name) { echo "<option value='" . $key . "' " . (get_request_var_request("rows") == $key ? "selected" : "") . ">" . $name . "</option>"; } } ?> </select> </td> <td nowrap style='white-space: nowrap;' width="60"> Search: </td> <td> <input type='text' size='40' name='filter' value='<?php print get_request_var_request("filter"); ?> '> </td> <td nowrap> <input type="button" onClick="applyHostFilter(document.devices)" value="Go" border="0"> <input type="button" onClick="clearHosts()" value="Clear" name="clear" border="0"> </td> </tr> </table> <input type='hidden' name='action' value='devices'> </form> </td> </tr> <?php html_end_box(); html_start_box("", "100%", $colors["header"], "3", "center", ""); if ($_REQUEST["rows"] == "-1") { $num_rows = read_config_option("num_rows_device"); } else { $num_rows = get_request_var_request("rows"); } $limit = " LIMIT " . $num_rows * (get_request_var_request("page") - 1) . "," . $num_rows; $sql_where = ""; if ($_REQUEST["template"] != "-1") { $sql_where .= (strlen($sql_where) ? " AND" : "WHERE") . " host.host_template_id=" . $_REQUEST["template"]; } if ($_REQUEST["status"] != "-1") { $sql_where .= (strlen($sql_where) ? " AND" : "WHERE") . " hrs.host_status=" . $_REQUEST["status"]; } if ($_REQUEST["type"] != "-1") { $sql_where .= (strlen($sql_where) ? " AND" : "WHERE") . " hrs.host_type=" . $_REQUEST["type"]; } if ($_REQUEST["process"] != "" && $_REQUEST["process"] != "-1") { $sql_join = "INNER JOIN plugin_hmib_hrSWRun AS hrswr ON host.id=hrswr.host_id"; $sql_where .= (strlen($sql_where) ? " AND" : "WHERE") . " hrswr.name='" . $_REQUEST["process"] . "'"; } else { $sql_join = ""; } if ($_REQUEST["filter"] != "") { $sql_where .= (strlen($sql_where) ? " AND" : "WHERE") . " host.description LIKE '%" . $_REQUEST["filter"] . "%' OR\n\t\t\thost.hostname LIKE '%" . $_REQUEST["filter"] . "%'"; } $sql = "SELECT hrs.*, host.hostname, host.description, host.disabled\n\t\tFROM plugin_hmib_hrSystem AS hrs\n\t\tINNER JOIN host ON host.id=hrs.host_id\n\t\t{$sql_join}\n\t\t{$sql_where}\n\t\tORDER BY " . get_request_var_request("sort_column") . " " . get_request_var_request("sort_direction") . " " . $limit; //echo $sql; $rows = db_fetch_assoc($sql); $total_rows = db_fetch_cell("SELECT COUNT(*)\n\t\tFROM plugin_hmib_hrSystem AS hrs\n\t\tINNER JOIN host ON host.id=hrs.host_id\n\t\t{$sql_join}\n\t\t{$sql_where}"); if ($total_rows > 0) { /* generate page list */ $url_page_select = get_page_list(get_request_var_request("page"), MAX_DISPLAY_PAGES, $num_rows, $total_rows, "hmib.php" . "?action=devices"); $nav = "<tr bgcolor='#" . $colors["header"] . "'>\n\t\t\t<td colspan='16'>\n\t\t\t\t<table width='100%' cellspacing='0' cellpadding='0' border='0'>\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<td align='left' class='textHeaderDark'>\n\t\t\t\t\t\t\t<strong><< "; if (get_request_var_request("page") > 1) { $nav .= "<a class='linkOverDark' href='" . htmlspecialchars("hmib.php" . "?action=devices&page=" . (get_request_var_request("page") - 1)) . "'>"; } $nav .= "Previous"; if (get_request_var_request("page") > 1) { $nav .= "</a>"; } $nav .= "</strong>\n\t\t\t\t\t\t</td>\n\n\t\t\t\t\t\t<td align='center' class='textHeaderDark'>\n\t\t\t\t\t\t\tShowing Rows " . ($num_rows * (get_request_var_request("page") - 1) + 1) . " to " . ($total_rows < $num_rows || $total_rows < $num_rows * get_request_var_request("page") ? $total_rows : $num_rows * get_request_var_request("page")) . " of {$total_rows} [{$url_page_select}]\n\t\t\t\t\t\t</td>\n\n\t\t\t\t\t\t<td align='right' class='textHeaderDark'>\n\t\t\t\t\t\t\t<strong>"; if (get_request_var_request("page") * $num_rows < $total_rows) { $nav .= "<a class='linkOverDark' href='" . htmlspecialchars("hmib.php" . "?action=devices&page=" . (get_request_var_request("page") + 1)) . "'>"; } $nav .= "Next"; if (get_request_var_request("page") * $num_rows < $total_rows) { $nav .= "</a>"; } $nav .= " >></strong>\n\t\t\t\t\t\t</td>\n\n\t\t\t\t\t</tr>\n\t\t\t\t</table>\n\t\t\t</td>\n\t\t</tr>\n"; } else { $nav = "<tr bgcolor='#" . $colors["header"] . "'>\n\t\t\t<td colspan='16'>\n\t\t\t\t<table width='100%' cellspacing='0' cellpadding='0' border='0'>\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<td align='center' class='textHeaderDark'>\n\t\t\t\t\t\t\tNo Rows Found\n\t\t\t\t\t\t</td>\n\n\t\t\t\t\t</tr>\n\t\t\t\t</table>\n\t\t\t</td>\n\t\t</tr>\n"; } print $nav; $display_text = array("nosort" => array("Actions", array("ASC", "left")), "description" => array("Name", array("ASC", "left")), "host_status" => array("Status", array("DESC", "right")), "uptime" => array("Uptime(d:h:m)", array("DESC", "right")), "users" => array("Users", array("DESC", "right")), "cpuPercent" => array("CPU %", array("DESC", "right")), "numCpus" => array("CPUs", array("DESC", "right")), "processes" => array("Processes", array("DESC", "right")), "memSize" => array("Total Mem", array("DESC", "right")), "memUsed" => array("Used Mem", array("DESC", "right")), "swapSize" => array("Total Swap", array("DESC", "right")), "swapUsed" => array("Used Swap", array("DESC", "right"))); hmib_header_sort($display_text, get_request_var_request("sort_column"), get_request_var_request("sort_direction"), "action=devices"); /* set some defaults */ $url = $config["url_path"] . "plugins/hmib/hmib.php"; $proc = $config["url_path"] . "plugins/hmib/images/view_processes.gif"; $host = $config["url_path"] . "plugins/hmib/images/view_hosts.gif"; $hardw = $config["url_path"] . "plugins/hmib/images/view_hardware.gif"; $inven = $config["url_path"] . "plugins/hmib/images/view_inventory.gif"; $storage = $config["url_path"] . "plugins/hmib/images/view_storage.gif"; $dashboard = $config["url_path"] . "plugins/hmib/images/view_dashboard.gif"; $graphs = $config["url_path"] . "plugins/hmib/images/view_graphs.gif"; $nographs = $config["url_path"] . "plugins/hmib/images/view_graphs_disabled.gif"; $htdq = read_config_option("hmib_dq_host_type"); $hcpudq = read_config_option("hmib_dq_host_cpu"); $hugt = read_config_option("hmib_gt_users"); $hpgt = read_config_option("hmib_gt_processes"); $i = 0; if (sizeof($rows)) { foreach ($rows as $row) { $days = intval($row["uptime"] / (60 * 60 * 24 * 100)); $remainder = $row["uptime"] % (60 * 60 * 24 * 100); $hours = intval($remainder / (60 * 60 * 100)); $remainder = $remainder % (60 * 60 * 100); $minutes = intval($remainder / (60 * 100)); $found = db_fetch_cell("SELECT COUNT(*) FROM graph_local WHERE host_id=" . $row["host_id"]); form_alternate_row_color($colors["alternate"], $colors["light"], $i); $i++; echo "<td width='120'>"; //echo "<a style='padding:1px;' href='" . htmlspecialchars("$url?action=dashboard&reset=1&device=" . $row["host_id"]) . "'><img src='$dashboard' title='View Dashboard' align='absmiddle' border='0'></a>"; echo "<a style='padding:1px;' href='" . htmlspecialchars("{$url}?action=storage&reset=1&device=" . $row["host_id"]) . "'><img src='{$storage}' title='View Storage' align='absmiddle' border='0'></a>"; echo "<a style='padding:1px;' href='" . htmlspecialchars("{$url}?action=hardware&reset=1&device=" . $row["host_id"]) . "'><img src='{$hardw}' title='View Hardware' align='absmiddle' border='0'></a>"; echo "<a style='padding:1px;' href='" . htmlspecialchars("{$url}?action=running&reset=1&device=" . $row["host_id"]) . "'><img src='{$proc}' title='View Processes' align='absmiddle' border='0'></a>"; echo "<a style='padding:1px;' href='" . htmlspecialchars("{$url}?action=software&reset=1&device=" . $row["host_id"]) . "'><img src='{$inven}' title='View Software Inventory' align='absmiddle' border='0'></a>"; if ($found) { echo "<a style='padding:1px;' href='" . htmlspecialchars("{$url}?action=graphs&reset=1&host=" . $row["host_id"] . "&style=selective&graph_add=&graph_list=&graph_template_id=0&filter=") . "'><img src='{$graphs}' title='View Graphs' align='absmiddle' border='0'></a>"; } else { echo "<img src='{$nographs}' title='No Graphs Defined' align='absmiddle' border='0'>"; } $graph_cpu = hmib_get_graph_url($hcpudq, 0, $row["host_id"], "", $row["numCpus"], false); $graph_cpup = hmib_get_graph_url($hcpudq, 0, $row["host_id"], "", round($row["cpuPercent"], 2) . " %", false); $graph_users = hmib_get_graph_template_url($hugt, 0, $row["host_id"], $row["host_status"] < 2 ? "N/A" : $row["users"], false); $graph_aproc = hmib_get_graph_template_url($hpgt, 0, $row["host_id"], $row["host_status"] < 2 ? "N/A" : $row["processes"], false); if (api_plugin_user_realm_auth('host.php')) { $host_url = "<a href='" . htmlspecialchars($config["url_path"] . "host.php?action=edit&id=" . $row["host_id"]) . "' title='Edit Hosts'>" . $row["hostname"] . "</a>"; } else { $host_url = $row["hostname"]; } echo "</td>"; echo "<td style='white-space:nowrap;' align='left' width='200'><strong>" . $row["description"] . "</strong> [" . $host_url . "]" . "</td>"; echo "<td style='white-space:nowrap;' align='right'>" . get_colored_device_status($row["disabled"] == "on" ? true : false, $row["host_status"]) . "</td>"; echo "<td style='white-space:nowrap;' align='right'>" . hmib_format_uptime($days, $hours, $minutes) . "</td>"; echo "<td style='white-space:nowrap;' align='right'>" . $graph_users . "</td>"; echo "<td style='white-space:nowrap;' align='right'>" . ($row["host_status"] < 2 ? "N/A" : $graph_cpup) . "</td>"; echo "<td style='white-space:nowrap;' align='right'>" . ($row["host_status"] < 2 ? "N/A" : $graph_cpu) . "</td>"; echo "<td style='white-space:nowrap;' align='right'>" . $graph_aproc . "</td>"; echo "<td style='white-space:nowrap;' align='right'>" . hmib_memory($row["memSize"]) . "</td>"; echo "<td style='white-space:nowrap;' align='right'>" . ($row["host_status"] < 2 ? "N/A" : round($row["memUsed"], 0)) . " %</td>"; echo "<td style='white-space:nowrap;' align='right'>" . hmib_memory($row["swapSize"]) . "</td>"; echo "<td style='white-space:nowrap;' align='right'>" . ($row["host_status"] < 2 ? "N/A" : round($row["swapUsed"], 0)) . " %</td>"; } echo "</tr>"; print $nav; } else { print "<tr><td><em>No Devices Found</em></td></tr>"; } html_end_box(); }
function hmib_devices() { global $config, $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'), 'template' => array('filter' => FILTER_VALIDATE_INT, 'pageset' => true, 'default' => '-1'), 'process' => array('filter' => FILTER_VALIDATE_INT, 'pageset' => true, 'default' => '-1'), 'status' => array('filter' => FILTER_VALIDATE_INT, 'pageset' => true, 'default' => '-1'), 'type' => array('filter' => FILTER_VALIDATE_INT, 'pageset' => true, 'default' => '-1'), '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'))); validate_store_request_vars($filters, 'sess_hmib_devices'); /* ================= input validation ================= */ ?> <script type='text/javascript'> function applyFilter(objForm) { strURL = '?action=devices'; strURL += '&type=' + $('#type').val(); strURL += '&status=' + $('#status').val(); strURL += '&process=' + $('#process').val(); strURL += '&template=' + $('#template').val(); strURL += '&filter=' + $('#filter').val(); strURL += '&rows=' + $('#rows').val(); strURL += '&page=' + $('#page').val(); strURL += '&header=false'; loadPageNoHeader(strURL); } function clearFilter() { strURL = '?action=devices&clear=true&header=false'; loadPageNoHeader(strURL); } $(function() { $('#devices').submit(function(event) { event.preventDefault(); applyFilter(); }); }); </script> <?php html_start_box(__('Device Filter'), '100%', '', '3', 'center', ''); ?> <tr class='even'> <td> <form id='devices' action='hmib.php?action=devices'> <table class='filterTable'> <tr> <td style='white-space:nowrap;width:55px;'> <?php print __('OS Type'); ?> </td> <td> <select id='type' onChange='applyFilter()'> <option value='-1'<?php if (get_request_var('type') == '-1') { ?> selected<?php } ?> ><?php print __('All'); ?> </option> <?php $types = db_fetch_assoc("SELECT DISTINCT id, CONCAT_WS('', name, ' [', version, ']') AS name\n\t\t\t\t\t\t\t\tFROM plugin_hmib_hrSystemTypes AS hrst\n\t\t\t\t\t\t\t\tINNER JOIN plugin_hmib_hrSystem AS hrs\n\t\t\t\t\t\t\t\tON hrst.id=hrs.host_type\n\t\t\t\t\t\t\t\tWHERE name!='' ORDER BY name"); if (sizeof($types)) { foreach ($types as $t) { echo "<option value='" . $t['id'] . "' " . (get_request_var('type') == $t['id'] ? 'selected' : '') . '>' . $t['name'] . '</option>'; } } ?> </select> </td> <td> <?php print __('Template'); ?> </td> <td> <select id='template' onChange='applyFilter()'> <option value='-1'<?php if (get_request_var('template') == '-1') { ?> selected<?php } ?> ><?php print __('All'); ?> </option> <?php $templates = db_fetch_assoc('SELECT DISTINCT ht.id, ht.name FROM host_template AS ht INNER JOIN host ON ht.id=host.host_template_id INNER JOIN plugin_hmib_hrSystem AS hrs ON host.id=hrs.host_id ORDER BY name'); if (sizeof($templates)) { foreach ($templates as $t) { echo "<option value='" . $t['id'] . "' " . (get_request_var('template') == $t['id'] ? 'selected' : '') . '>' . $t['name'] . '</option>'; } } ?> </select> </td> <td> <?php print __('Process'); ?> </td> <td> <select id='process' onChange='applyFilter()'> <option value='-1'<?php if (get_request_var('process') == '-1') { ?> selected<?php } ?> ><?php print __('All'); ?> </option> <?php $processes = db_fetch_assoc("SELECT DISTINCT name FROM plugin_hmib_hrSWRun WHERE name!='' ORDER BY name"); if (sizeof($processes)) { foreach ($processes as $p) { echo "<option value='" . $p['name'] . "' " . (get_request_var('process') == $p['name'] ? 'selected' : '') . '>' . $p['name'] . '</option>'; } } ?> </select> </td> <td> <input type='button' onClick='applyFilter(document.devices)' value='<?php print __('Go'); ?> '> </td> <td> <input type='button' onClick='clearFilter()' value='<?php print __('Clear'); ?> '> </td> </tr> </table> <table class='filterTable'> <tr> <td style='width:55px;'> <?php print __('Search'); ?> </td> <td> <input type='textbox' size='25' id='filter' value='<?php print get_request_var('filter'); ?> '> </td> <td> <?php print __('Status'); ?> </td> <td> <select id='status' onChange='applyFilter()'> <option value='-1'<?php if (get_request_var('type') == '-1') { ?> selected<?php } ?> ><?php print __('All'); ?> </option> <?php $statuses = db_fetch_assoc('SELECT DISTINCT status FROM host INNER JOIN plugin_hmib_hrSystem ON host.id=plugin_hmib_hrSystem.host_id'); $statuses = array_merge($statuses, array('-2' => array('status' => '-2'))); if (sizeof($statuses)) { foreach ($statuses as $s) { switch ($s['status']) { case '0': $status = __('Unknown'); break; case '1': $status = __('Down'); break; case '2': $status = __('Recovering'); break; case '3': $status = __('Up'); break; case '-2': $status = __('Disabled'); break; } echo "<option value='" . $s['status'] . "' " . (get_request_var('status') == $s['status'] ? 'selected' : '') . '>' . $status . '</option>'; } } ?> </select> </td> <td> <?php print __('Devices'); ?> </td> <td> <select id='rows' onChange='applyFilter()'> <option value='-1'<?php if (get_request_var('rows') == '-1') { ?> selected<?php } ?> ><?php print __('Default'); ?> </option> <?php if (sizeof($item_rows)) { foreach ($item_rows as $key => $name) { echo "<option value='" . $key . "' " . (get_request_var('rows') == $key ? 'selected' : '') . '>' . $name . '</option>'; } } ?> </select> </td> </tr> </table> <input type='hidden' id='page' value='<?php print get_request_var('page'); ?> '> </form> </td> </tr> <?php html_end_box(); if (get_request_var('rows') == '-1') { $num_rows = read_config_option('num_rows_table'); } else { $num_rows = get_request_var('rows'); } $limit = ' LIMIT ' . $num_rows * (get_request_var('page') - 1) . ',' . $num_rows; $sql_where = ''; if (get_request_var('template') != '-1') { $sql_where .= (strlen($sql_where) ? ' AND' : 'WHERE') . ' host.host_template_id=' . get_request_var('template'); } if (get_request_var('status') != '-1') { $sql_where .= (strlen($sql_where) ? ' AND' : 'WHERE') . ' hrs.host_status=' . get_request_var('status'); } if (get_request_var('type') != '-1') { $sql_where .= (strlen($sql_where) ? ' AND' : 'WHERE') . ' hrs.host_type=' . get_request_var('type'); } if (get_request_var('process') != '' && get_request_var('process') != '-1') { $sql_join = 'INNER JOIN plugin_hmib_hrSWRun AS hrswr ON host.id=hrswr.host_id'; $sql_where .= (strlen($sql_where) ? ' AND' : 'WHERE') . " hrswr.name='" . get_request_var('process') . "'"; } else { $sql_join = ''; } if (get_request_var('filter') != '') { $sql_where .= (strlen($sql_where) ? ' AND' : 'WHERE') . " host.description LIKE '%" . get_request_var('filter') . "%' OR\n\t\t\thost.hostname LIKE '%" . get_request_var('filter') . "%'"; } $sql = "SELECT hrs.*, host.hostname, host.description, host.disabled\n\t\tFROM plugin_hmib_hrSystem AS hrs\n\t\tINNER JOIN host ON host.id=hrs.host_id\n\t\t{$sql_join}\n\t\t{$sql_where}\n\t\tORDER BY " . get_request_var('sort_column') . ' ' . get_request_var('sort_direction') . ' ' . $limit; $rows = db_fetch_assoc($sql); $total_rows = db_fetch_cell("SELECT COUNT(*)\n\t\tFROM plugin_hmib_hrSystem AS hrs\n\t\tINNER JOIN host ON host.id=hrs.host_id\n\t\t{$sql_join}\n\t\t{$sql_where}"); $nav = html_nav_bar('hmib.php?action=devices', MAX_DISPLAY_PAGES, get_request_var('page'), $num_rows, $total_rows, 16, __('Devices'), 'page', 'main'); print $nav; html_start_box('', '100%', '', '3', 'center', ''); $display_text = array('nosort' => array('display' => __('Actions'), 'sort' => 'ASC', 'align' => 'left'), 'description' => array('display' => __('Hostname'), 'sort' => 'ASC', 'align' => 'left'), 'host_status' => array('display' => __('Status'), 'sort' => 'DESC', 'align' => 'right'), 'uptime' => array('display' => __('Uptime(d:h:m)'), 'sort' => 'DESC', 'align' => 'right'), 'users' => array('display' => __('Users'), 'sort' => 'DESC', 'align' => 'right'), 'cpuPercent' => array('display' => __('CPU %'), 'sort' => 'DESC', 'align' => 'right'), 'numCpus' => array('display' => __('CPUs'), 'sort' => 'DESC', 'align' => 'right'), 'processes' => array('display' => __('Processes'), 'sort' => 'DESC', 'align' => 'right'), 'memSize' => array('display' => __('Total Mem'), 'sort' => 'DESC', 'align' => 'right'), 'memUsed' => array('display' => __('Used Mem'), 'sort' => 'DESC', 'align' => 'right'), 'swapSize' => array('display' => __('Total Swap'), 'sort' => 'DESC', 'align' => 'right'), 'swapUsed' => array('display' => __('Used Swap'), 'sort' => 'DESC', 'align' => 'right')); html_header_sort($display_text, get_request_var('sort_column'), get_request_var('sort_direction'), false, 'hmib.php?action=devices'); /* set some defaults */ $url = $config['url_path'] . 'plugins/hmib/hmib.php'; $proc = $config['url_path'] . 'plugins/hmib/images/cog.png'; $host = $config['url_path'] . 'plugins/hmib/images/server.png'; $hardw = $config['url_path'] . 'plugins/hmib/images/view_hardware.gif'; $inven = $config['url_path'] . 'plugins/hmib/images/view_inventory.gif'; $storage = $config['url_path'] . 'plugins/hmib/images/drive.png'; $dashboard = $config['url_path'] . 'plugins/hmib/images/view_dashboard.gif'; $graphs = $config['url_path'] . 'plugins/hmib/images/view_graphs.gif'; $nographs = $config['url_path'] . 'plugins/hmib/images/view_graphs_disabled.gif'; $htdq = db_fetch_cell("SELECT id \n\t\tFROM snmp_query \n\t\tWHERE hash='137aeab842986a76cf5bdef41b96c9a3'"); $hcpudq = db_fetch_cell("SELECT id \n\t\tFROM snmp_query \n\t\tWHERE hash='0d1ab53fe37487a5d0b9e1d3ee8c1d0d'"); $hugt = db_fetch_cell("SELECT id \n\t\tFROM graph_templates \n\t\tWHERE hash='e8462bbe094e4e9e814d4e681671ea82'"); $hpgt = db_fetch_cell("SELECT id \n\t\tFROM graph_templates \n\t\tWHERE hash='62205afbd4066e5c4700338841e3901e'"); if (sizeof($rows)) { foreach ($rows as $row) { $days = intval($row['uptime'] / (60 * 60 * 24 * 100)); $remainder = $row['uptime'] % (60 * 60 * 24 * 100); $hours = intval($remainder / (60 * 60 * 100)); $remainder = $remainder % (60 * 60 * 100); $minutes = intval($remainder / (60 * 100)); $found = db_fetch_cell('SELECT COUNT(*) FROM graph_local WHERE host_id=' . $row['host_id']); form_alternate_row(); echo "<td width='120'>"; //echo "<a style='padding:1px;' href='" . htmlspecialchars("$url?action=dashboard&reset=1&device=" . $row["host_id"]) . "'><img src='$dashboard' title='View Dashboard' align='absmiddle'></a>"; echo "<a style='padding:1px;' href='" . htmlspecialchars("{$url}?action=storage&reset=1&device=" . $row['host_id']) . "'><img src='{$storage}' title='" . __('View Storage') . "' align='absmiddle' alt=''></a>"; echo "<a style='padding:1px;' href='" . htmlspecialchars("{$url}?action=hardware&reset=1&device=" . $row['host_id']) . "'><img src='{$hardw}' title='" . __('View Hardware') . "' align='absmiddle' alt=''></a>"; echo "<a style='padding:1px;' href='" . htmlspecialchars("{$url}?action=running&reset=1&device=" . $row['host_id']) . "'><img src='{$proc}' title='" . __('View Processes') . "' align='absmiddle' alt=''></a>"; echo "<a style='padding:1px;' href='" . htmlspecialchars("{$url}?action=software&reset=1&device=" . $row['host_id']) . "'><img src='{$inven}' title='" . __('View Software Inventory') . "' align='absmiddle' alt=''></a>"; if ($found) { echo "<a style='padding:1px;' href='" . htmlspecialchars("{$url}?action=graphs&reset=1&host_id=" . $row['host_id'] . "&style=selective&graph_add=&graph_list=&graph_template_id=0&filter=") . "'><img src='{$graphs}' title='" . __('View Graphs') . "' align='absmiddle' alt=''></a>"; } else { echo "<img src='{$nographs}' title='" . __('No Graphs Defined') . "' align='absmiddle' alt=''>"; } $graph_cpu = hmib_get_graph_url($hcpudq, 0, $row['host_id'], '', $row['numCpus'], false); $graph_cpup = hmib_get_graph_url($hcpudq, 0, $row['host_id'], '', round($row['cpuPercent'], 2) . ' %', false); $graph_users = hmib_get_graph_template_url($hugt, 0, $row['host_id'], $row['host_status'] < 2 ? 'N/A' : $row['users'], false); $graph_aproc = hmib_get_graph_template_url($hpgt, 0, $row['host_id'], $row['host_status'] < 2 ? 'N/A' : $row['processes'], false); if (api_plugin_user_realm_auth('host.php')) { $host_url = "<a href='" . htmlspecialchars($config['url_path'] . 'host.php?action=edit&id=' . $row['host_id']) . "' title='" . __('Edit Device') . "'>" . $row['hostname'] . '</a>'; } else { $host_url = $row['hostname']; } echo '</td>'; echo "<td class='nowrap left'>" . $row['description'] . ' [' . $host_url . ']' . '</td>'; echo "<td class='nowrap right'>" . get_colored_device_status($row['disabled'] == 'on' ? true : false, $row['host_status']) . '</td>'; echo "<td class='nowrap right'>" . hmib_format_uptime($days, $hours, $minutes) . '</td>'; echo "<td class='nowrap right'>" . $graph_users . '</td>'; echo "<td class='nowrap right'>" . ($row['host_status'] < 2 ? 'N/A' : $graph_cpup) . '</td>'; echo "<td class='nowrap right'>" . ($row['host_status'] < 2 ? 'N/A' : $graph_cpu) . '</td>'; echo "<td class='nowrap right'>" . $graph_aproc . '</td>'; echo "<td class='nowrap right'>" . hmib_memory($row['memSize']) . '</td>'; echo "<td class='nowrap right'>" . ($row['host_status'] < 2 ? 'N/A' : round($row['memUsed'], 0)) . ' %</td>'; echo "<td class='nowrap right'>" . hmib_memory($row['swapSize']) . '</td>'; echo "<td class='nowrap right'>" . ($row['host_status'] < 2 ? 'N/A' : round($row['swapUsed'], 0)) . ' %</td>'; } echo '</tr>'; } else { print '<tr><td><em>' . __('No Devices Found') . '</em></td></tr>'; } html_end_box(false); if (sizeof($rows)) { print $nav; } }