From b92e874d23825b1d65df3589936fc3b45f3f1065 Mon Sep 17 00:00:00 2001 From: guruevi Date: Tue, 3 Mar 2009 22:12:06 +0000 Subject: [PATCH] 2009-03-03 Evi Vanoost * general/logon_ok.php: Minor edit in language and colors for warning * include/functions_reporting.php: Changed get_group_stats for better queries based on query debugging. * include/functions_db.php: Change get_server_info for better queries based on query debugging. Documentation updates and function updates * operation/agentes/tactical.php: Removed a row with duplicate info * operation/reporting/reporting_viewer.php, operation/reporting/reporting_xml.php, include/functions_modules.php, godmode/agentes/module_manager_editor.php: Function renaming. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1502 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_console/ChangeLog | 17 ++++ pandora_console/general/logon_ok.php | 16 ++-- .../godmode/agentes/module_manager_editor.php | 2 +- pandora_console/include/functions_db.php | 70 +++++++++-------- pandora_console/include/functions_modules.php | 2 +- .../include/functions_reporting.php | 77 ++++++------------- .../operation/agentes/tactical.php | 15 ++-- .../operation/reporting/reporting_viewer.php | 2 +- .../operation/reporting/reporting_xml.php | 2 +- 9 files changed, 95 insertions(+), 108 deletions(-) diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 944b702108..0ebadcdfff 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,20 @@ +2009-03-03 Evi Vanoost + + * general/logon_ok.php: Minor edit in language and colors for warning + + * include/functions_reporting.php: Changed get_group_stats for better + queries based on query debugging. + + * include/functions_db.php: Change get_server_info for better queries + based on query debugging. Documentation updates and function updates + + * operation/agentes/tactical.php: Removed a row with duplicate info + + * operation/reporting/reporting_viewer.php, + operation/reporting/reporting_xml.php, include/functions_modules.php, + godmode/agentes/module_manager_editor.php: + Function renaming. + 2009-03-03 Esteban Sanchez * godmode/alerts/configure_alert_template.php: Add id to separator diff --git a/pandora_console/general/logon_ok.php b/pandora_console/general/logon_ok.php index c2df4cbacc..5f83cf6c11 100644 --- a/pandora_console/general/logon_ok.php +++ b/pandora_console/general/logon_ok.php @@ -59,7 +59,7 @@ echo ''; // Site stats echo '
'; -$data = get_group_stats (0); +$data = get_group_stats (); $table->class = "databox"; $table->cellpadding = 4; @@ -91,27 +91,27 @@ $cells[0][1] = $data["total_agents"]; $cells[0]["color"] = "#000"; $cells[0]["href"] = "index.php?sec=estado&sec2=operation/agentes/estado_agente&refr=60"; -$cells[1][0] = __('Total checks'); -$cells[1][1] = $data["total_checks"]; +$cells[1][0] = __('Monitor checks'); +$cells[1][1] = $data["monitor_checks"]; $cells[1]["color"] = "#000"; $cells[1]["href"] = "index.php?sec=estado&sec2=operation/agentes/status_monitor&refr=60&status=-1"; -$cells[2][0] = __('Modules critical'); +$cells[2][0] = __('Monitors critical'); $cells[2][1] = $data["monitor_critical"]; $cells[2]["color"] = "#f00"; $cells[2]["href"] = "index.php?sec=estado&sec2=operation/agentes/status_monitor&refr=60&status=2"; -$cells[3][0] = __('Modules warning'); +$cells[3][0] = __('Monitors warning'); $cells[3][1] = $data["monitor_warning"]; $cells[3]["color"] = "#FFB900"; $cells[3]["href"] = "index.php?sec=estado&sec2=operation/agentes/status_monitor&refr=60&status=1"; -$cells[4][0] = __('Modules normal'); +$cells[4][0] = __('Monitors normal'); $cells[4][1] = $data["monitor_ok"]; $cells[4]["color"] = "#00ff00"; $cells[4]["href"] = "index.php?sec=estado&sec2=operation/agentes/status_monitor&refr=60&status=0"; -$cells[5][0] = __('Modules unknown'); +$cells[5][0] = __('Monitors unknown'); $cells[5][1] = $data["monitor_unknown"]; $cells[5]["color"] = "#aaaaaa"; $cells[5]["href"] = "index.php?sec=estado&sec2=operation/agentes/status_monitor&refr=60&status=3"; @@ -176,4 +176,4 @@ foreach ($sessions as $session) { } print_table ($table); echo "
"; // activity -?> +?> \ No newline at end of file diff --git a/pandora_console/godmode/agentes/module_manager_editor.php b/pandora_console/godmode/agentes/module_manager_editor.php index 0a40be8004..9913f66f13 100644 --- a/pandora_console/godmode/agentes/module_manager_editor.php +++ b/pandora_console/godmode/agentes/module_manager_editor.php @@ -75,7 +75,7 @@ require_once ("include/functions_exportserver.php"); // Using network component to fill some fields if ($id_agent_module) { - $module = get_agent_module ($id_agent_module); + $module = get_agentmodule ($id_agent_module); $moduletype = $module['id_modulo']; $name = $module['nombre']; $description = $module['descripcion']; diff --git a/pandora_console/include/functions_db.php b/pandora_console/include/functions_db.php index 909e43507b..88d87c7c22 100644 --- a/pandora_console/include/functions_db.php +++ b/pandora_console/include/functions_db.php @@ -313,15 +313,14 @@ function get_group_agents ($id_group = 0, $disabled = false, $case = "lower") { } /** - * Get a singlemodule in an agent. + * Get a single module information. * - * @param mixed Agent id to get modules. It can also be an array of agent id's. + * @param int agentmodule id to get. * - * @return array An array with all modules in the agent. - * If multiple rows are selected, they will be in an array + * @return array An array with module information */ -function get_agent_module ($id_agent_module) { - return get_db_row ('tagente_modulo', 'id_agente_modulo', (int) $id_agent_module); +function get_agentmodule ($id_agentmodule) { + return get_db_row ('tagente_modulo', 'id_agente_modulo', (int) $id_agentmodule); } /** @@ -337,7 +336,7 @@ function get_agent_module ($id_agent_module) { * the WHERE keyword). Example: Both are similars: -$modules = get_agent_modules ($id_agent, false, array ('disabled', 0)); +$modules = get_agent_modules ($id_agent, false, array ('disabled' => 0)); $modules = get_agent_modules ($id_agent, false, 'disabled = 0'); Both are similars: @@ -2599,6 +2598,7 @@ function get_server_info ($id_server = -1) { $sql = "SELECT * FROM tserver".$select_id; $result = get_db_all_rows_sql ($sql); + $time = get_system_time (); if (empty ($result)) { return false; @@ -2624,36 +2624,44 @@ function get_server_info ($id_server = -1) { $server["type"] = "unknown"; } - $server["modules"] = get_db_sql ("SELECT COUNT(*) FROM tagente_estado, tagente_modulo + $modules = array (); + $result = get_db_all_rows_sql ("SELECT tagente_estado.id_agente_modulo, tagente_modulo.nombre FROM tagente_estado, tagente_modulo WHERE tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo AND tagente_modulo.disabled = 0 + AND tagente_modulo.delete_pending = 0 AND tagente_estado.running_by = ".$server["id_server"]); + + if ($result === false) { + $result = array (); + } + foreach ($result as $module_info) { + $modules[$module_info["id_agente_modulo"]] = $module_info["nombre"]; + } + + $server["modules"] = count ($modules); + $server["module_info"] = $modules; //We have it, so we might as well pass it just in case somebody might find out a use for it. + $server["module_lag"] = 0; + $server["lag"] = 0; + + if ($server["modules"] > 0) { + //If the server doesn't have modules, it doesn't have lag - $server["module_lag"] = get_db_sql ("SELECT COUNT(*) FROM tagente_estado, tagente_modulo, tagente - WHERE tagente_estado.last_execution_try > 0 - AND tagente_estado.running_by = ".$server["id_server"]." - AND tagente_modulo.id_agente = tagente.id_agente - AND tagente.disabled = 0 - AND tagente_modulo.disabled = 0 - AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo - AND (UNIX_TIMESTAMP() - tagente_estado.last_execution_try - tagente_estado.current_interval < 1200)"); + $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 + AND running_by = ".$server["id_server"]." + AND id_agente_modulo IN (".implode (",", array_keys ($modules)).") + AND (UNIX_TIMESTAMP() - last_execution_try - current_interval < current_interval * 2)"); - // Lag over 1200 seconds is not lag, is module without contacting data in several time.or with a - // 1200 sec is 20 min - $server["lag"] = get_db_sql ("SELECT MAX(tagente_estado.last_execution_try - tagente_estado.current_interval) - FROM tagente_estado, tagente_modulo, tagente - WHERE tagente_estado.last_execution_try > 0 - AND tagente_estado.running_by = ".$server["id_server"]." - AND tagente_modulo.id_agente = tagente.id_agente - AND tagente.disabled = 0 - AND tagente_modulo.disabled = 0 - AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo - AND (UNIX_TIMESTAMP() - tagente_estado.last_execution_try - tagente_estado.current_interval < 1200)"); + // Lag over current_interval * 2 is not lag, it's a timed out module + // And we can't check current_interval = 0 (data modules) because they come as they want - if (empty ($server["lag"])) { - $server["lag"] = 0; - } else { - $server["lag"] = get_system_time () - $server["lag"]; + if (!empty ($result["lag"])) { + $server["lag"] = $time - $result["lag"]; + } + if (!empty ($result["module_lag"])) { + $server["module_lag"] = $result["module_lag"]; + } } //Push the raw data on the return stack diff --git a/pandora_console/include/functions_modules.php b/pandora_console/include/functions_modules.php index 7a58c0d887..ced05f1ea5 100644 --- a/pandora_console/include/functions_modules.php +++ b/pandora_console/include/functions_modules.php @@ -29,7 +29,7 @@ * False on error. */ function copy_agent_module_to_agent ($id_agent_module, $id_destiny_agent) { - $module = get_agent_module ($id_agent_module); + $module = get_agentmodule ($id_agent_module); if ($module === false) return false; diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index 37ab59ab95..fa8d0d5e7e 100644 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -79,13 +79,13 @@ function get_agentmodule_sla ($id_agentmodule, $period = 0, $min_value = 1, $max } /** - * Get general stats info on a group + * Get general statistical info on a group * - * @param int Group Id to get info. + * @param int Group Id to get info from * - * @return array + * @return array Group statistics */ -function get_group_stats ($id_group) { +function get_group_stats ($id_group = 0) { $data = array (); $data["monitor_checks"] = 0; $data["monitor_not_init"] = 0; @@ -110,64 +110,31 @@ function get_group_stats ($id_group) { $groups = array_keys (get_user_groups ()); if ($id_group > 0 && in_array ($id_group, $groups)) { - //If a group is selected, and we have permissions to it then we don't need to look for them - $groups = array (); - $groups[0] = $id_group; + //If a singular group is selected, and we have permissions to it then we don't need to get all + $groups = array ((int) $id_group); + } elseif ($id_group > 0) { + return $data; //We don't have selected any valid groups (select 0 for all groups your user can get to) } - - //Select all modules in group - $agents = get_group_agents ($groups); - $modules = array (); - $module_ids = array (); + $agents = array_keys (get_group_agents ($groups)); if (empty ($agents)) { //No agents in this group, means no data return $data; } - - $sql = sprintf ("SELECT tagente_estado.id_agente_modulo, - tagente_modulo.id_tipo_modulo, - estado, datos, - current_interval, - utimestamp - FROM tagente_estado, tagente_modulo - WHERE tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo - AND tagente_modulo.delete_pending = 0 - AND tagente_modulo.id_agente IN (%s)", implode (",", array_keys ($agents))); - $result = get_db_all_rows_sql ($sql); - - if ($result === false) { - //No data for any agents, means everything is 0 anyway. - return $data; - } - - foreach ($result as $row) { - $last_update = $cur_time - $row["utimestamp"]; - $data["monitor_checks"]++; - - //Check whether it's down, not init, unknown or OK - if ($last_update == $cur_time) { - //The utimestamp is 0 and has never been updated - $data["monitor_not_init"]++; - } elseif ($last_update >= ($row["current_interval"] * 2)) { - //The utimestamp is greater than 2x the interval (it has timed out) - $data["monitor_unknown"]++; - } elseif ($row["estado"] == 1){ - $data["monitor_critical"]++; - } elseif ($row["estado"] == 2){ - $data["monitor_warning"]++; - } - else { - $data["monitor_ok"]++; - } - } //End foreach module + $filter = 'id_agente IN ('.implode (",", $agents).') '; + + $data["monitor_checks"] = (int) get_db_sql ("SELECT COUNT(*) FROM tagente_estado WHERE ".$filter); + $data["monitor_not_init"] = (int) get_db_sql ("SELECT COUNT(*) FROM tagente_estado WHERE ".$filter."AND utimestamp = 0"); + $data["monitor_unknown"] = (int) get_db_sql ("SELECT COUNT(*) FROM tagente_estado WHERE ".$filter."AND UNIX_TIMESTAMP() - utimestamp >= current_interval * 2"); + $data["monitor_critical"] = (int) get_db_sql ("SELECT COUNT(*) FROM tagente_estado WHERE ".$filter."AND estado = 1"); + $data["monitor_warning"] = (int) get_db_sql ("SELECT COUNT(*) FROM tagente_estado WHERE ".$filter."AND estado = 2"); + $data["monitor_ok"] = $data["monitor_checks"] - $data["monitor_not_init"] - $data["monitor_unknown"] - $data["monitor_critical"] - $data["monitor_warning"]; - //Moved it out of the loop otherwise for each module there would be a SQL query $sql = sprintf ("SELECT times_fired FROM talert_template_modules WHERE id_agent_module IN (%s)", implode (",", array_keys ($agents))); $result = get_db_all_rows_sql ($sql); - if ($result === false) { + if (empty ($result)) { $result = array (); //It's possible there are no alerts so we don't return } @@ -182,7 +149,7 @@ function get_group_stats ($id_group) { $data["total_agents"] = count ($agents); $data["total_checks"] = $data["monitor_checks"]; $data["total_ok"] = $data["monitor_ok"]; - // Todo, count SNMP Alerts and Inventory alerts here + //TODO: count SNMP Alerts and Inventory alerts here $data["total_alerts"] = $data["monitor_alerts"] + $data["monitor_alerts_fired"]; $data["total_alerts_fired"] = $data["monitor_alerts_fired"]; $data["total_alerts_fire_count"] = $data["monitor_alerts_fire_count"]; @@ -225,7 +192,7 @@ function get_group_stats ($id_group) { $data["alert_level"] = 100; } - $data["server_sanity"] = 100 - $data["module_sanity"]; + $data["server_sanity"] = format_numeric (100 - $data["module_sanity"], 1); return $data; } @@ -483,9 +450,9 @@ function get_monitors_down_reporting_table ($monitors_down) { * @param int Group to get the report * @param bool Flag to return or echo the report (by default). * - * @return string + * @return HTML string with group report */ -function general_group_reporting ($id_group, $return = false) { +function print_group_reporting ($id_group, $return = false) { $agents = get_group_agents ($id_group, false, "none"); $output = ''.__('Agents in group').': '.count ($agents).'
'; diff --git a/pandora_console/operation/agentes/tactical.php b/pandora_console/operation/agentes/tactical.php index 82a0bd93ed..00981537d5 100644 --- a/pandora_console/operation/agentes/tactical.php +++ b/pandora_console/operation/agentes/tactical.php @@ -49,7 +49,7 @@ function print_cells_temp ($cells) { echo "

".__('Pandora Agents')." > ".__('Tactical view')."

"; -$data = get_group_stats (0); +$data = get_group_stats (); echo '
'; // Monitor checks @@ -103,7 +103,7 @@ $cells[1]["color"] = "#000"; $cells[2][0] = __('Monitors warning'); $cells[2][1] = $data["monitor_warning"]; $cells[2]["href"] = "index.php?sec=estado&sec2=operation/agentes/status_monitor&refr=60&status=1"; //Down -$cells[2]["color"] = "#f00"; +$cells[2]["color"] = "#FFB900"; $cells[3][0] = __('Monitors critical'); $cells[3][1] = $data["monitor_critical"]; @@ -140,15 +140,10 @@ $cells[0][1] = $data["total_agents"]; $cells[0]["color"] = "#000"; $cells[0]["href"] = "index.php?sec=estado&sec2=operation/agentes/estado_agente&refr=60"; -$cells[1][0] = __('Total Checks'); -$cells[1][1] = $data["total_checks"]; +$cells[1][0] = __('Uninitialized modules'); +$cells[1][1] = $data["server_sanity"] . "%"; $cells[1]["color"] = "#000"; -$cells[1]["href"] = "index.php?sec=estado&sec2=operation/agentes/status_monitor&refr=60&status=-1"; - -$cells[2][0] = __('Uninitialized modules'); -$cells[2][1] = $data["server_sanity"] . "%"; -$cells[2]["color"] = "#000"; -$cells[2]["href"] = "index.php?sec=estado_server&sec2=operation/servers/view_server&refr=60"; +$cells[1]["href"] = "index.php?sec=estado_server&sec2=operation/servers/view_server&refr=60"; print_cells_temp ($cells); diff --git a/pandora_console/operation/reporting/reporting_viewer.php b/pandora_console/operation/reporting/reporting_viewer.php index 5f09b5c6cf..4da6791d8f 100644 --- a/pandora_console/operation/reporting/reporting_viewer.php +++ b/pandora_console/operation/reporting/reporting_viewer.php @@ -443,7 +443,7 @@ foreach ($contents as $content) { $data = array (); $table->colspan[1][0] = 2; - $data[0] = general_group_reporting ($report['id_group'], true); + $data[0] = print_group_reporting ($report['id_group'], true); array_push ($table->data, $data); break; diff --git a/pandora_console/operation/reporting/reporting_xml.php b/pandora_console/operation/reporting/reporting_xml.php index 634ad46f19..49c81301f6 100644 --- a/pandora_console/operation/reporting/reporting_xml.php +++ b/pandora_console/operation/reporting/reporting_xml.php @@ -261,7 +261,7 @@ foreach ($contents as $content) { case 'general_group_report': $data["title"] = __('Group'); $data["objdata"] = ""; break; case 12: