From b3a8f7da1b2740e1ff5f1b78dc6048c7aab762ff Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Tue, 5 Feb 2013 14:46:16 +0000 Subject: [PATCH] 2013-02-05 Miguel de Dios * ajax.php: added the autologin hash for some ajax call of user without login (but with hash autologin). * godmode/reporting/reporting_builder.list_items.php, include/db/mysql.php: cleaned source code style. * include/functions_reporting.php, include/functions_events.php, operation/reporting/reporting_xml.php: optimized the get by steps the group events. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@7588 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_console/ChangeLog | 12 ++ pandora_console/ajax.php | 21 +++ .../reporting_builder.list_items.php | 1 + pandora_console/include/db/mysql.php | 6 +- pandora_console/include/functions_events.php | 60 +++++++ .../include/functions_reporting.php | 166 +++++++++--------- .../operation/reporting/reporting_xml.php | 20 ++- 7 files changed, 190 insertions(+), 96 deletions(-) diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index f77ea5507a..d3647ec53c 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,15 @@ +2013-02-05 Miguel de Dios + + * ajax.php: added the autologin hash for some ajax call of user + without login (but with hash autologin). + + * godmode/reporting/reporting_builder.list_items.php, + include/db/mysql.php: cleaned source code style. + + * include/functions_reporting.php, include/functions_events.php, + operation/reporting/reporting_xml.php: optimized the get by steps + the group events. + 2013-02-05 Sancho Lerena * operation/menu.php: Fixed duplicity in SNMP trap menu. SNMP diff --git a/pandora_console/ajax.php b/pandora_console/ajax.php index d178ada518..9c73c19ffc 100644 --- a/pandora_console/ajax.php +++ b/pandora_console/ajax.php @@ -26,9 +26,30 @@ require_once ('include/auth/mysql.php'); // Real start session_start (); +// Hash login process +if (isset ($_GET["loginhash"])) { + + $loginhash_data = get_parameter("loginhash_data", ""); + $loginhash_user = get_parameter("loginhash_user", ""); + + if ($config["loginhash_pwd"] != "" + && $loginhash_data == md5($loginhash_user.$config["loginhash_pwd"])) { + db_logon ($loginhash_user, $_SERVER['REMOTE_ADDR']); + $_SESSION['id_usuario'] = $loginhash_user; + $config["id_user"] = $loginhash_user; + } + else { + require_once ('general/login_page.php'); + db_pandora_audit("Logon Failed (loginhash", "", "system"); + while (@ob_end_flush ()); + exit (""); + } +} + // Check user check_login (); + define ('AJAX', true); /* Enterprise support */ diff --git a/pandora_console/godmode/reporting/reporting_builder.list_items.php b/pandora_console/godmode/reporting/reporting_builder.list_items.php index 469531edae..1eb0dc4cd7 100644 --- a/pandora_console/godmode/reporting/reporting_builder.list_items.php +++ b/pandora_console/godmode/reporting/reporting_builder.list_items.php @@ -228,6 +228,7 @@ $table = null; $table->style[0] = 'text-align: right;'; + if ($items) { $table->width = '100%'; diff --git a/pandora_console/include/db/mysql.php b/pandora_console/include/db/mysql.php index ee3a528201..04846afb55 100644 --- a/pandora_console/include/db/mysql.php +++ b/pandora_console/include/db/mysql.php @@ -339,7 +339,7 @@ function mysql_db_process_sql($sql, $rettype = "affected_rows", $dbconnection = */ function mysql_escape_string_sql($string) { $str = mysql_real_escape_string($string); - + return $str; } @@ -506,7 +506,7 @@ function mysql_db_format_array_where_clause_sql ($values, $join = 'AND', $prefix if (is_numeric ($field)) { /* User provide the exact operation to do */ $query .= $value; - + if ($i < $max) { $query .= ' '.$join.' '; } @@ -908,7 +908,7 @@ function mysql_db_process_sql_delete($table, $where, $where_join = 'AND') { $query .= db_format_array_where_clause_sql ($where, $where_join); } } - + return db_process_sql ($query); } diff --git a/pandora_console/include/functions_events.php b/pandora_console/include/functions_events.php index 80e2af3277..c2d0c6efac 100644 --- a/pandora_console/include/functions_events.php +++ b/pandora_console/include/functions_events.php @@ -1060,6 +1060,7 @@ function events_print_type_description ($type, $return = false) { function events_get_group_events ($id_group, $period, $date, $filter_event_validated = false, $filter_event_critical = false, $filter_event_warning = false, $filter_event_no_validated = false) { + global $config; $id_group = groups_safe_acl ($config["id_user"], $id_group, "ER"); @@ -1102,6 +1103,65 @@ function events_get_group_events ($id_group, $period, $date, return db_get_all_rows_sql ($sql); } +/** + * Get all the events happened in a group during a period of time. + * + * The returned events will be in the time interval ($date - $period, $date] + * + * @param mixed $id_group Group id to get events for. + * @param int $period Period of time in seconds to get events. + * @param int $date Beginning date to get events. + * + * @return array An array with all the events happened. + */ +function events_get_group_events_steps ($begin, &$result, $id_group, $period, $date, + $filter_event_validated = false, $filter_event_critical = false, + $filter_event_warning = false, $filter_event_no_validated = false) { + + global $config; + + $id_group = groups_safe_acl ($config["id_user"], $id_group, "ER"); + + if (empty ($id_group)) { + //An empty array means the user doesn't have access + return false; + } + + $datelimit = $date - $period; + + $sql_where = ' AND 1 = 1 '; + if ($filter_event_critical) { + $sql_where .= ' AND criticity = 4 '; + } + if ($filter_event_warning) { + $sql_where .= ' AND criticity = 3 '; + } + if ($filter_event_validated) { + $sql_where .= ' AND estado = 1 '; + } + if ($filter_event_no_validated) { + $sql_where .= ' AND estado = 0 '; + } + + + $sql = sprintf ('SELECT *, + (SELECT t2.nombre + FROM tagente AS t2 + WHERE t2.id_agente = t3.id_agente) AS agent_name, + (SELECT t2.fullname + FROM tusuario AS t2 + WHERE t2.id_user = t3.id_usuario) AS user_name + FROM tevento AS t3 + WHERE utimestamp > %d AND utimestamp <= %d + AND id_grupo IN (%s) ' . $sql_where . ' + ORDER BY utimestamp ASC', + $datelimit, $date, implode (",", $id_group)); + + //html_debug_print($sql); + + return db_get_all_row_by_steps_sql($begin, $result, $sql); +} + /** * Get all the events happened in an Agent during a period of time. * diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index 838376e26d..f9a308fcb6 100644 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -183,7 +183,7 @@ function reporting_get_agentmodule_data_max ($id_agent_module, $period, $date = $previous_data['utimestamp'] = $datelimit; array_unshift ($interval_data, $previous_data); } - + // Get next data $next_data = modules_get_next_data ($id_agent_module, $date); if ($next_data !== false) { @@ -347,7 +347,7 @@ function reporting_get_agentmodule_data_sum ($id_agent_module, $period, $date = $previous_data['utimestamp'] = $datelimit; array_unshift ($interval_data, $previous_data); } - + // Get next data $next_data = modules_get_next_data ($id_agent_module, $date); if ($next_data !== false) { @@ -429,7 +429,7 @@ function reporting_get_agentmodule_sla ($id_agent_module, $period = 0, $min_valu WHERE id_agente_modulo = %d AND utimestamp > %d AND utimestamp <= %d', $id_agent_module, $datelimit, $date); - + //Add the working times (mon - tue - wed ...) and from time to time $days = array(); //Translate to mysql week days @@ -537,17 +537,18 @@ function reporting_get_agentmodule_sla ($id_agent_module, $period = 0, $min_valu $previous_utimestamp = $first_data['utimestamp']; if ((($max_value > $min_value AND ($first_data['datos'] > $max_value OR $first_data['datos'] < $min_value))) OR ($max_value <= $min_value AND $first_data['datos'] < $min_value)) { - $previous_status = 1; - foreach ($downtime_dates as $date_dt) { - if (($date_dt['date_from'] <= $previous_utimestamp) AND ($date_dt['date_to'] >= $previous_utimestamp)) { - $previous_status = 0; - } - } + + $previous_status = 1; + foreach ($downtime_dates as $date_dt) { + if (($date_dt['date_from'] <= $previous_utimestamp) AND ($date_dt['date_to'] >= $previous_utimestamp)) { + $previous_status = 0; + } + } } else { $previous_status = 0; } - + foreach ($interval_data as $data) { // Previous status was critical if ($previous_status == 1) { @@ -671,7 +672,7 @@ function reporting_get_agentmodule_sla_array ($id_agent_module, $period = 0, $mi foreach($interval_data as $idata) { $interval_data_indexed[$idata['utimestamp']]['data'] = $idata['datos']; } - + //-----------Calculate unknown status events------------------------ $events_unknown = db_get_all_rows_filter ('tevento', array ('id_agentmodule' => $id_agent_module, @@ -680,7 +681,7 @@ function reporting_get_agentmodule_sla_array ($id_agent_module, $period = 0, $mi "event_type" => 'going_unknown', 'order' => 'utimestamp ASC'), array ('id_evento', 'evento', 'timestamp', 'utimestamp', 'event_type')); - + if ($events_unknown === false) { $events_unknown = array (); } @@ -690,7 +691,7 @@ function reporting_get_agentmodule_sla_array ($id_agent_module, $period = 0, $mi $interval_data_indexed[$eu['utimestamp']]['data'] = 0; $interval_data_indexed[$eu['utimestamp']]['status'] = 4; } - + // Get the last event before inverval to know if graph start on unknown $prev_event = db_get_row_filter ('tevento', array ('id_agentmodule' => $id_agent_module, @@ -703,7 +704,7 @@ function reporting_get_agentmodule_sla_array ($id_agent_module, $period = 0, $mi $start_unknown = false; } //------------------------------------------------------------------ - + //-----------------Set limits of the interval----------------------- // If the starting of the graph is unknown we set it if($start_unknown) { @@ -713,7 +714,7 @@ function reporting_get_agentmodule_sla_array ($id_agent_module, $period = 0, $mi else { // Get previous data (This adds the first data if the begin of module data is after the begin time interval) $previous_data = modules_get_previous_data ($id_agent_module, $datelimit); - + if ($previous_data !== false ) { $interval_data_indexed[$datelimit]['data'] = $previous_data['datos']; } @@ -722,7 +723,7 @@ function reporting_get_agentmodule_sla_array ($id_agent_module, $period = 0, $mi $interval_data_indexed[$datelimit]['status'] = 4; } } - + // Get next data (This adds data before the interval of the report) $next_data = modules_get_next_data ($id_agent_module, $date); if ($next_data !== false) { @@ -734,7 +735,7 @@ function reporting_get_agentmodule_sla_array ($id_agent_module, $period = 0, $mi $last_data = array_pop($interval_data_indexed); $interval_data_indexed[$date] = $last_data; } - + //------------------------------------------------------------------ //--------Calculate planned downtime dates-------------------------- @@ -746,7 +747,7 @@ function reporting_get_agentmodule_sla_array ($id_agent_module, $period = 0, $mi } $i = 0; $downtime_dates = array(); - + foreach ($downtimes as $downtime) { $id_downtime = $downtime['id_downtime']; $sql_date = "SELECT date_from, date_to FROM tplanned_downtime WHERE id=$id_downtime"; @@ -781,7 +782,7 @@ function reporting_get_agentmodule_sla_array ($id_agent_module, $period = 0, $mi // Sort the array ksort($interval_data_indexed); - + // We need more or equal two points if (count ($interval_data_indexed) < 2) { return false; @@ -1003,7 +1004,7 @@ function reporting_get_group_stats ($id_group = 0, $access = 'AR') { if (!empty($group_array)) { // FOR THE FUTURE: Split the groups into groups with tags restrictions and groups without it // To calculate in the light way the non tag restricted and in the heavy way the others - /* + /* $group_restricted_data = tags_get_acl_tags($config['id_user'], $group_array, $access, 'data'); $tags_restricted_groups = array_keys($group_restricted_data); @@ -1018,13 +1019,13 @@ function reporting_get_group_stats ($id_group = 0, $access = 'AR') { if(!empty($group_array)) { // Get unknown agents by using the status code in modules $data["agents_unknown"] += groups_agent_unknown ($group_array); - + // Get monitor NOT INIT, except disabled AND async modules $data["monitor_not_init"] += groups_monitor_not_init ($group_array); - + // Get monitor OK, except disabled and non-init $data["monitor_ok"] += groups_monitor_ok ($group_array); - + // Get monitor CRITICAL, except disabled and non-init $data["monitor_critical"] += groups_monitor_critical ($group_array); @@ -1068,9 +1069,9 @@ function reporting_get_group_stats ($id_group = 0, $access = 'AR') { $data["monitor_checks"] = $data["monitor_not_init"] + $data["monitor_unknown"] + $data["monitor_warning"] + $data["monitor_critical"] + $data["monitor_ok"]; } - + // Get total count of monitors for this group, except disabled. - + $data["monitor_checks"] = $data["monitor_not_init"] + $data["monitor_unknown"] + $data["monitor_warning"] + $data["monitor_critical"] + $data["monitor_ok"]; /* @@ -1173,6 +1174,7 @@ function reporting_event_reporting ($id_group, $period, $date = 0, $return = fal if (empty ($return)) html_print_table ($table); + return $table; } @@ -2096,68 +2098,64 @@ function reporting_get_group_detailed_event ($id_group, $period = 0, $table->head[5] = __('Val. by'); $table->head[6] = __('Timestamp'); - $events = events_get_group_events($id_group, $period, $date, + $begin = true; + $result = null; + $count = 0; + while ($event = events_get_group_events_steps($begin, $result, $id_group, $period, $date, $filter_event_validated, $filter_event_critical, - $filter_event_warning, $filter_event_no_validated); - - if ($events) { - foreach ($events as $event) { - //First pass along the class of this row - $table->rowclass[] = - get_priority_class ($event["criticity"]); - - $data = array (); - - // Colored box - switch ($event['estado']) { - case 0: - $img_st = "images/star.png"; - $title_st = __('New event'); - break; - case 1: - $img_st = "images/tick.png"; - $title_st = __('Event validated'); - break; - case 2: - $img_st = "images/hourglass.png"; - $title_st = __('Event in process'); - break; - } - $data[] = html_print_image ($img_st, true, - array ("class" => "image_status", - "width" => 16, - "height" => 16, - "title" => $title_st, - "id" => 'status_img_' . $event["id_evento"])); - - $data[] = ui_print_truncate_text( - io_safe_output($event['evento']), - 140, false, true); - - //$data[1] = $event['event_type']; - $data[] = events_print_type_img ($event["event_type"], true); - - if (!empty($event['agent_name'])) - $data[] = $event['agent_name']; - else - $data[] = __('Pandora System'); - $data[] = get_priority_name ($event['criticity']); - $data[] = io_safe_output($event['user_name']); - $data[] = '' . - $event['timestamp'] . - ''; - array_push ($table->data, $data); - } + $filter_event_warning, $filter_event_no_validated)) { - if ($html) { - return html_print_table ($table, $return); - } - else { - return $table; + //html_debug_print(++$count, true); + + $data = array (); + $begin = false; + + // Colored box + switch ($event['estado']) { + case 0: + $img_st = "images/star.png"; + $title_st = __('New event'); + break; + case 1: + $img_st = "images/tick.png"; + $title_st = __('Event validated'); + break; + case 2: + $img_st = "images/hourglass.png"; + $title_st = __('Event in process'); + break; } + $data[] = html_print_image ($img_st, true, + array ("class" => "image_status", + "width" => 16, + "height" => 16, + "title" => $title_st, + "id" => 'status_img_' . $event["id_evento"])); + + $data[] = ui_print_truncate_text( + io_safe_output($event['evento']), + 140, false, true); + + //$data[1] = $event['event_type']; + $data[] = events_print_type_img ($event["event_type"], true); + + if (!empty($event['agent_name'])) + $data[] = $event['agent_name']; + else + $data[] = __('Pandora System'); + $data[] = get_priority_name ($event['criticity']); + $data[] = io_safe_output($event['user_name']); + $data[] = '' . + $event['timestamp'] . + ''; + array_push ($table->data, $data); + } + + if ($html) { + return html_print_table ($table, $return); } else { - return false; + return $table; } } @@ -2303,7 +2301,7 @@ function reporting_get_agent_module_info ($id_agent, $filter = false) { } } - + if ($return["modules"] > 0) { if ($return["monitor_critical"] > 0) { $return["status"] = STATUS_AGENT_CRITICAL; @@ -2336,7 +2334,7 @@ function reporting_get_agent_module_info ($id_agent, $filter = false) { } return $return; -} +} /** * This is the callback sorting function for SLA values descending diff --git a/pandora_console/operation/reporting/reporting_xml.php b/pandora_console/operation/reporting/reporting_xml.php index 80577022c8..c445facc36 100644 --- a/pandora_console/operation/reporting/reporting_xml.php +++ b/pandora_console/operation/reporting/reporting_xml.php @@ -121,7 +121,7 @@ if (isset ($_GET["direct"])) { else { require_once ("include/config.php"); require_once ("include/functions_reporting.php"); - require_once ("include/auth/mysql.php"); + require_once ("include/auth/mysql.php"); } global $config; @@ -733,18 +733,18 @@ foreach ($contents as $content) { $id_group = groups_safe_acl ($config["id_user"], $content['id_group'], "AR"); /// if (!empty ($id_group)) { - + //An empty array means the user doesn't have access $datelimit = $report["datetime"] - $content['period']; - + $sql_count = sprintf ('SELECT count(*) FROM tevento WHERE utimestamp > %d AND utimestamp <= %d AND id_grupo IN (%s) ORDER BY utimestamp ASC', $datelimit, $report["datetime"], implode (",", $id_group)); - + $data_count = db_get_value_sql($sql_count); - + $temp_file = $config['attachment_store'] . '/event_report_group_' . $time.'_'.$content['id_rc'] . '.tmp'; $file = fopen ($temp_file, 'a+'); $buffer_file["objdata"] = $config['attachment_store'] . '/event_report_group_' . $time.'_'.$content['id_rc'] . '.tmp'; @@ -756,7 +756,8 @@ foreach ($contents as $content) { $content_report = " \n"; $result = fwrite($file, $content_report); fclose($file); - } else if ($data_count <= $limit) { + } + else if ($data_count <= $limit) { $content_report = " \n"; $result = fwrite($file, $content_report); fclose($file); @@ -772,8 +773,9 @@ foreach ($contents as $content) { $file = fopen ($temp_file, 'a+'); $content_report = " \n"; $result = fwrite($file, $content_report); - - } else { + + } + else { $content_report = " \n"; $result = fwrite($file, $content_report); fclose($file); @@ -786,7 +788,7 @@ foreach ($contents as $content) { AND id_grupo IN (%s) ORDER BY utimestamp ASC LIMIT %d,%d', $datelimit, $report["datetime"], implode (",", $id_group), $offset,$limit); - + $events = db_get_all_rows_sql($sql); $position = xml_file_event ($events, $temp_file, $position, $content['id_agent']);