From ef0f906d889f8ca4f7f8369c25be1413249b0e4a Mon Sep 17 00:00:00 2001 From: guruevi Date: Tue, 24 Mar 2009 16:53:03 +0000 Subject: [PATCH] 2009-03-24 Evi Vanoost * include/functions_db.php: Made get_server_info more accurate as far as exact module types etc. * operation/servers/view_server.php: Return dash in case there is no lag * operation/servers/view_server_detail.php: Style fixes git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1558 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_console/ChangeLog | 9 +++ pandora_console/include/functions_db.php | 58 ++++++++++++++++--- .../operation/servers/view_server.php | 2 +- .../operation/servers/view_server_detail.php | 25 ++++---- 4 files changed, 75 insertions(+), 19 deletions(-) diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index b3df89ee3a..944758a224 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,12 @@ +2009-03-24 Evi Vanoost + + * include/functions_db.php: Made get_server_info more accurate as far as + exact module types etc. + + * operation/servers/view_server.php: Return dash in case there is no lag + + * operation/servers/view_server_detail.php: Style fixes + 2009-03-24 Esteban Sanchez * general/pandora_help.php: Added support for enterprise help files. diff --git a/pandora_console/include/functions_db.php b/pandora_console/include/functions_db.php index 9efde91db3..11115646b4 100644 --- a/pandora_console/include/functions_db.php +++ b/pandora_console/include/functions_db.php @@ -2619,8 +2619,8 @@ function get_server_info ($id_server = -1) { } $modules_info = array (); - $modules_total = 0; - $result = get_db_all_rows_sql ("SELECT DISTINCT(tagente_estado.running_by) , COUNT(*) AS modules + $modules_total = array (); + $result = get_db_all_rows_sql ("SELECT DISTINCT(tagente_estado.running_by), COUNT(*) AS modules, id_modulo FROM tagente_estado, tagente_modulo WHERE tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo AND tagente_modulo.disabled = 0 @@ -2631,9 +2631,14 @@ function get_server_info ($id_server = -1) { foreach ($result as $row) { $modules_info[$row["running_by"]] = $row["modules"]; - $modules_total += $row["modules"]; + if (!isset ($modules_total[$row["id_modulo"]])) { + $modules_total[$row["id_modulo"]] = $row["modules"]; + } else { + $modules_total[$row["id_modulo"]] += $row["modules"]; + } } + $recon_total = get_db_sql ("SELECT COUNT(*) FROM trecon_task"); $sql = "SELECT * FROM tserver".$select_id; $result = get_db_all_rows_sql ($sql); @@ -2647,20 +2652,28 @@ function get_server_info ($id_server = -1) { foreach ($result as $server) { if ($server["network_server"] == 1) { $server["type"] = "network"; + $id_modulo = 2; } elseif ($server["data_server"] == 1) { $server["type"] = "data"; + $id_modulo = 1; } elseif ($server["plugin_server"] == 1) { $server["type"] = "plugin"; + $id_modulo = 4; } elseif ($server["wmi_server"] == 1) { $server["type"] = "wmi"; + $id_modulo = 6; } elseif ($server["recon_server"] == 1) { $server["type"] = "recon"; + $id_modulo = 0; } elseif ($server["snmp_server"] == 1) { $server["type"] = "snmp"; + $id_modulo = 0; } elseif ($server["prediction_server"] == 1) { $server["type"] = "prediction"; + $id_modulo = 5; } else { $server["type"] = "unknown"; + $id_modulo = 0; } if (empty ($modules_info[$server["id_server"]])) { @@ -2671,10 +2684,15 @@ function get_server_info ($id_server = -1) { $server["module_lag"] = 0; $server["lag"] = 0; $server["load"] = 0; - $server["modules_total"] = $modules_total; - if ($server["modules"] > 0) { - //If the server doesn't have modules, it doesn't have lag + if (!isset ($modules_total[$id_modulo])) { + $server["modules_total"] = 0; + } else { + $server["modules_total"] = $modules_total[$id_modulo]; + } + + if ($id_modulo > 0 && $server["modules"] > 0) { + //If the server doesn't have modules, it doesn't have lag so nothing to calculate. If it's not a module server, don't go here either $result = get_db_row_sql ("SELECT COUNT(*) AS module_lag, MAX(last_execution_try - current_interval) AS lag FROM tagente_estado WHERE last_execution_try > 0 AND current_interval > 0 @@ -2691,7 +2709,33 @@ function get_server_info ($id_server = -1) { $server["module_lag"] = $result["module_lag"]; } - $server["load"] = (int) $server["modules"] / $modules_total * 100; + $server["load"] = round ($server["modules"] / $server["modules_total"] * 100); + } else { + switch ($server["type"]) { + case "recon": + $tasks = get_db_all_rows_sql ("SELECT status, utimestamp FROM trecon_task WHERE id_recon_server = ".$server["id_server"]); + if (empty ($tasks)) { + $tasks = array (); + } + //Jobs running on this recon server + $server["modules"] = count ($tasks); + //Total recon jobs (all servers) + $server["modules_total"] = $recon_total; + $server["load"] = round ($server["modules"] / $server["modules_total"] * 100); + //Lag (take average active time of all active tasks) + $lags = array (); + foreach ($tasks as $task) { + if ($task["status"] > 0 && $task["status"] <= 100) { + $lags[] = $time - $task["utimestamp"]; + } + } + if (count ($lags) > 0) { + $server["lag"] = (int) array_sum ($lags) / count ($lags); + } + break; + default: + break; + } } //Push the raw data on the return stack diff --git a/pandora_console/operation/servers/view_server.php b/pandora_console/operation/servers/view_server.php index da999e5ea1..9651021f61 100644 --- a/pandora_console/operation/servers/view_server.php +++ b/pandora_console/operation/servers/view_server.php @@ -77,7 +77,7 @@ foreach ($servers as $server) { // Load $data[2] = print_image ("reporting/fgraph.php?tipo=progress&percent=".$server["load"]."&height=20&width=80", true); $data[3] = $server["modules"] . " ".__('of')." ". $server["modules_total"]; - $data[4] = ''.human_time_description_raw ($server["lag"]) . " / ". $server["module_lag"].''; + $data[4] = ''.($server["lag"] == 0 ? '-' : human_time_description_raw ($server["lag"])) . " / ". $server["module_lag"].''; $data[5] = ''; if ($server['network_server'] == 1) { $data[5] .= print_image ("images/network.png", true, array ("title" => __('Network Server'))); diff --git a/pandora_console/operation/servers/view_server_detail.php b/pandora_console/operation/servers/view_server_detail.php index 5caf09d090..a0576f4369 100644 --- a/pandora_console/operation/servers/view_server_detail.php +++ b/pandora_console/operation/servers/view_server_detail.php @@ -48,16 +48,17 @@ $id_server = (int) get_parameter ("server_id", -1); $server_name = get_server_name ($id_server); $recon_tasks = get_db_all_rows_field_filter ("trecon_task", "id_recon_server", $id_server); -echo "

". __('Configuration detail') . " - ".$server_name; -echo ' '; -echo "

"; +echo "

". __('Configuration detail') . " - ".safe_input ($server_name); +echo ' '; +print_image ("images/refresh.png"); +echo "

"; // Show network tasks for Recon Server if ($recon_tasks === false) { $recon_tasks = array (); - } + $table->cellpadding = 4; $table->cellspacing = 4; $table->width = 725; @@ -102,15 +103,17 @@ $table->align[10] = "center"; foreach ($recon_tasks as $task) { $data = array (); - $data[0] = ''.__('Force').''; + $data[0] = ''; + $data[0] .= print_image ("images/target.png", true, array ("title" => __('Force'))); + $data[0] .= ''; - $data[1] = ''.$task["name"].''; + $data[1] = ''.safe_input ($task["name"]).''; $data[2] = human_time_description ($task["interval_sweep"]); $data[3] = $task["subnet"]; - if ($task["status"] == -1) { + if ($task["status"] <= 0) { $data[4] = __('Done'); } else { $data[4] = __('Pending'); @@ -122,16 +125,16 @@ foreach ($recon_tasks as $task) { $data[7] = print_os_icon ($task["id_os"], false, true); - if ($task["status"] < 0 || $task["status"] > 100) { + if ($task["status"] <= 0 || $task["status"] > 100) { $data[8] = "-"; } else { - $data[8] = ''; + $data[8] = print_image ("reporting/fgraph.php?tipo=progress&percent=".$task['status']."&height=20&width=100", true, array ("title" => __('Progress').':'.$task["status"].'%')); } $data[9] = print_timestamp ($task["utimestamp"], true); if (give_acl ($config["id_user"], $task["id_group"], "PM")) { - $data[10] = ''; + $data[10] = ''.print_image ("images/wrench_orange.png", true).''; } else { $data[10] = ''; } @@ -145,4 +148,4 @@ if (empty ($table->data)) { print_table ($table); } unset ($table); -?> +?> \ No newline at end of file