From 0fa74b59744d76fcac42f99fcf53041cf2d968e9 Mon Sep 17 00:00:00 2001 From: guruevi Date: Wed, 25 Feb 2009 15:04:26 +0000 Subject: [PATCH] 2009-02-25 Evi Vanoost * include/functions_reporting.php: Thanks to Esteban's functions found out some bad performers. Fixed it * include/auth/ldap.php: Calling get_system_time() 800 times is too much. Moved it to a variable. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1485 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_console/ChangeLog | 8 ++++++ pandora_console/include/auth/ldap.php | 3 +- .../include/functions_reporting.php | 28 ++++++++++++------- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 4ef3f4722e..fdcb4c90cd 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,11 @@ +2009-02-25 Evi Vanoost + + * include/functions_reporting.php: Thanks to Esteban's functions found out + some bad performers. Fixed it + + * include/auth/ldap.php: Calling get_system_time() 800 times is too much. + Moved it to a variable. + 2009-02-25 Esteban Sanchez * include/functions_db.php: Do not show errors on sql_error_handler() diff --git a/pandora_console/include/auth/ldap.php b/pandora_console/include/auth/ldap.php index ab0667fab9..0065e8b3c6 100644 --- a/pandora_console/include/auth/ldap.php +++ b/pandora_console/include/auth/ldap.php @@ -411,6 +411,7 @@ function get_users ($order = false) { } $ldap_cache["cached_users"] = array (); + $time = get_system_time (); if (ldap_connect_bind ()) { $sr = @ldap_search ($ldap_cache["ds"], $config["auth"]["ldap_base_dn"], $config["auth"]["ldap_user_filter"], array_values ($config["auth"]["ldap_user_attr"])); @@ -421,7 +422,7 @@ function get_users ($order = false) { $info = @ldap_get_entries( $ldap_cache["ds"], $sr ); for ( $i = 0; $i < $info['count']; $i++ ) { foreach ($config["auth"]["ldap_user_attr"] as $internal_key => $ldap_key) { - $ret[$info[$i][$config["auth"]["ldap_user_attr"]["id_user"]][0]]["last_connect"] = get_system_time (); + $ret[$info[$i][$config["auth"]["ldap_user_attr"]["id_user"]][0]]["last_connect"] = $time; if (isset ($info[$i][$ldap_key])) { $ret[$info[$i][$config["auth"]["ldap_user_attr"]["id_user"]][0]][$internal_key] = $info[$i][$ldap_key][0]; } else { diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index 4024addcad..008bcbf42f 100644 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -171,9 +171,10 @@ function get_group_stats ($id_group) { $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"]; @@ -194,17 +195,24 @@ function get_group_stats ($id_group) { else { $data["monitor_ok"]++; } - - $fired = get_db_value ('times_fired', 'talert_template_modules', 'id_agent_module', $row["id_agente_modulo"]); - if ($fired !== false) { - $data["monitor_alerts"]++; - if ($fired > 0) { - $data["monitor_alerts_fired"]++; - $data["monitor_alerts_fire_count"] += $fired; - } - } } //End foreach module + //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) { + $result = array (); //It's possible there are no alerts so we don't return + } + + foreach ($result as $row) { + $data["monitor_alerts"]++; + if ($row["times_fired"] > 0) { + $data["monitor_alerts_fired"]++; + $data["monitor_alerts_fire_count"] += $fired; + } + } + $data["total_agents"] = count ($agents); $data["total_checks"] = $data["monitor_checks"]; $data["total_ok"] = $data["monitor_ok"];