From 10156ffa77f4502f3286f473c83b429b97cedc1c Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Wed, 18 Mar 2015 13:51:14 +0100 Subject: [PATCH 01/80] Working in the refactor the code of reports. --- .../include/functions_reporting.php | 8496 +---------------- .../operation/reporting/reporting_viewer.php | 15 +- 2 files changed, 98 insertions(+), 8413 deletions(-) diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index d3f41ad895..3d88fa8d1e 100644 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -37,8432 +37,116 @@ include_once($config['homedir'] . "/include/functions_forecast.php"); include_once($config['homedir'] . "/include/functions_ui.php"); include_once($config['homedir'] . "/include/functions_netflow.php"); -/** - * Get the average value of an agent module in a period of time. - * - * @param int Agent module id - * @param int Period of time to check (in seconds) - * @param int Top date to check the values. Default current time. - * - * @return float The average module value in the interval. - */ -function reporting_get_agentmodule_data_average ($id_agent_module, $period=0, $date = 0) { - global $config; +function reporting_make_reporting_data($id_report, $datetime) { + $return = array(); - // Initialize variables - if (empty ($date)) $date = get_system_time (); - $datelimit = $date - $period; - - $search_in_history_db = db_search_in_history_db($datelimit); - - $id_module_type = modules_get_agentmodule_type ($id_agent_module); - $module_type = modules_get_moduletype_name ($id_module_type); - $uncompressed_module = is_module_uncompressed ($module_type); - - // Get module data - $interval_data = db_get_all_rows_sql ('SELECT * - FROM tagente_datos - WHERE id_agente_modulo = ' . (int) $id_agent_module . - ' AND utimestamp > ' . (int) $datelimit . - ' AND utimestamp < ' . (int) $date . - ' ORDER BY utimestamp ASC', $search_in_history_db); - if ($interval_data === false) $interval_data = array (); - - // Uncompressed module data - if ($uncompressed_module) { - $min_necessary = 1; - - // Compressed module data - } - else { - // Get previous data - $previous_data = modules_get_previous_data ($id_agent_module, $datelimit); - if ($previous_data !== false) { - $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) { - $next_data['utimestamp'] = $date; - array_push ($interval_data, $next_data); - } - else if (count ($interval_data) > 0) { - // Propagate the last known data to the end of the interval - $next_data = array_pop ($interval_data); - array_push ($interval_data, $next_data); - $next_data['utimestamp'] = $date; - array_push ($interval_data, $next_data); - } - - $min_necessary = 2; - } - - if (count ($interval_data) < $min_necessary) { - return false; - } - - // Set initial conditions - $total = 0; - $count = 0; - if (! $uncompressed_module) { - $previous_data = array_shift ($interval_data); - - // Do not count the empty start of an interval as 0 - if ($previous_data['utimestamp'] != $datelimit) { - $period = $date - $previous_data['utimestamp']; - } - } - foreach ($interval_data as $data) { - if (! $uncompressed_module) { - $total += $previous_data['datos'] * ($data['utimestamp'] - $previous_data['utimestamp']); - $previous_data = $data; - } - else { - $total += $data['datos']; - $count++; - } - } - - // Compressed module data - if (! $uncompressed_module) { - if ($period == 0) { - return 0; - } - - return $total / $period; - } - - // Uncompressed module data - if ($count == 0) { - return 0; - } - - return $total / $count; -} - -/** - * Get the maximum value of an agent module in a period of time. - * - * @param int Agent module id to get the maximum value. - * @param int Period of time to check (in seconds) - * @param int Top date to check the values. Default current time. - * - * @return float The maximum module value in the interval. - */ -function reporting_get_agentmodule_data_max ($id_agent_module, $period=0, $date = 0) { - global $config; - - // Initialize variables - if (empty ($date)) $date = get_system_time (); - $datelimit = $date - $period; - - $search_in_history_db = db_search_in_history_db($datelimit); - - $id_module_type = modules_get_agentmodule_type ($id_agent_module); - $module_type = modules_get_moduletype_name ($id_module_type); - $uncompressed_module = is_module_uncompressed ($module_type); - - // Get module data - $interval_data = db_get_all_rows_sql ('SELECT * - FROM tagente_datos - WHERE id_agente_modulo = ' . (int) $id_agent_module . - ' AND utimestamp > ' . (int) $datelimit . - ' AND utimestamp < ' . (int) $date . - ' ORDER BY utimestamp ASC', $search_in_history_db); - if ($interval_data === false) $interval_data = array (); - - // Uncompressed module data - if ($uncompressed_module) { - - // Compressed module data - } - else { - // Get previous data - $previous_data = modules_get_previous_data ($id_agent_module, $datelimit); - if ($previous_data !== false) { - $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) { - $next_data['utimestamp'] = $date; - array_push ($interval_data, $next_data); - } - else if (count ($interval_data) > 0) { - // Propagate the last known data to the end of the interval - $next_data = array_pop ($interval_data); - array_push ($interval_data, $next_data); - $next_data['utimestamp'] = $date; - array_push ($interval_data, $next_data); - } - } - - // Set initial conditions - if (empty($iterval_data)) { - $max = 0; - } - else { - if ($uncompressed_module || $interval_data[0]['utimestamp'] == $datelimit) { - $max = $interval_data[0]['datos']; - } - else { - $max = 0; - } - } - - foreach ($interval_data as $data) { - if ($data['datos'] > $max) { - $max = $data['datos']; - } - } - - return $max; -} - -/** - * Get the minimum value of an agent module in a period of time. - * - * @param int Agent module id to get the minimum value. - * @param int Period of time to check (in seconds) - * @param int Top date to check the values in Unix time. Default current time. - * - * @return float The minimum module value of the module - */ -function reporting_get_agentmodule_data_min ($id_agent_module, $period=0, $date = 0) { - global $config; - - // Initialize variables - if (empty ($date)) $date = get_system_time (); - $datelimit = $date - $period; - - $search_in_history_db = db_search_in_history_db($datelimit); - - $id_module_type = modules_get_agentmodule_type ($id_agent_module); - $module_type = modules_get_moduletype_name ($id_module_type); - $uncompressed_module = is_module_uncompressed ($module_type); - - // Get module data - $interval_data = db_get_all_rows_sql ('SELECT * - FROM tagente_datos - WHERE id_agente_modulo = ' . (int) $id_agent_module . - ' AND utimestamp > ' . (int) $datelimit . - ' AND utimestamp < ' . (int) $date . - ' ORDER BY utimestamp ASC', $search_in_history_db); - if ($interval_data === false) $interval_data = array (); - - // Uncompressed module data - if ($uncompressed_module) { - $min_necessary = 1; - - // Compressed module data - } - else { - // Get previous data - $previous_data = modules_get_previous_data ($id_agent_module, $datelimit); - if ($previous_data !== false) { - $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) { - $next_data['utimestamp'] = $date; - array_push ($interval_data, $next_data); - } - else if (count ($interval_data) > 0) { - // Propagate the last known data to the end of the interval - $next_data = array_pop ($interval_data); - array_push ($interval_data, $next_data); - $next_data['utimestamp'] = $date; - array_push ($interval_data, $next_data); - } - } - - if (count ($interval_data) < 1) { - return false; - } - - // Set initial conditions - $min = $interval_data[0]['datos']; - - foreach ($interval_data as $data) { - if ($data['datos'] < $min) { - $min = $data['datos']; - } - } - - return $min; -} - -/** - * Get the sum of values of an agent module in a period of time. - * - * @param int Agent module id to get the sumatory. - * @param int Period of time to check (in seconds) - * @param int Top date to check the values. Default current time. - * - * @return float The sumatory of the module values in the interval. - */ -function reporting_get_agentmodule_data_sum ($id_agent_module, - $period = 0, $date = 0) { - - global $config; - - // Initialize variables - if (empty ($date)) $date = get_system_time (); - $datelimit = $date - $period; - - $search_in_history_db = db_search_in_history_db($datelimit); - - $id_module_type = db_get_value ('id_tipo_modulo', 'tagente_modulo', - 'id_agente_modulo', $id_agent_module); - $module_name = db_get_value ('nombre', 'ttipo_modulo', 'id_tipo', - $id_module_type); - $module_interval = modules_get_interval ($id_agent_module); - $uncompressed_module = is_module_uncompressed ($module_name); - - // Wrong module type - if (is_module_data_string ($module_name)) { - return 0; - } - - // Incremental modules are treated differently - $module_inc = is_module_inc ($module_name); - - // Get module data - $interval_data = db_get_all_rows_sql(' - SELECT * FROM tagente_datos - WHERE id_agente_modulo = ' . (int) $id_agent_module . ' - AND utimestamp > ' . (int) $datelimit . ' - AND utimestamp < ' . (int) $date . ' - ORDER BY utimestamp ASC', $search_in_history_db); - if ($interval_data === false) $interval_data = array (); - - // Uncompressed module data - if ($uncompressed_module) { - $min_necessary = 1; - - // Compressed module data - } - else { - // Get previous data - $previous_data = modules_get_previous_data ($id_agent_module, $datelimit); - if ($previous_data !== false) { - $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) { - $next_data['utimestamp'] = $date; - array_push ($interval_data, $next_data); - } - else if (count ($interval_data) > 0) { - // Propagate the last known data to the end of the interval - $next_data = array_pop ($interval_data); - array_push ($interval_data, $next_data); - $next_data['utimestamp'] = $date; - array_push ($interval_data, $next_data); - } - - $min_necessary = 2; - } - - if (count ($interval_data) < $min_necessary) { - return false; - } - - // Set initial conditions - $total = 0; - if (! $uncompressed_module) { - $previous_data = array_shift ($interval_data); - } - - foreach ($interval_data as $data) { - if ($uncompressed_module) { - $total += $data['datos']; - } - else if ($module_inc) { - $total += $previous_data['datos'] * ($data['utimestamp'] - $previous_data['utimestamp']); - } - else { - $total += $previous_data['datos'] * ($data['utimestamp'] - $previous_data['utimestamp']) / $module_interval; - } - $previous_data = $data; - } - - return $total; -} - -/** - * Get SLA of a module. - * - * @param int Agent module to calculate SLA - * @param int Period to check the SLA compliance. - * @param int Minimum data value the module in the right interval - * @param int Maximum data value the module in the right interval. False will - * ignore max value - * @param int Beginning date of the report in UNIX time (current date by default). - * @param array $dayWeek Array of days week to extract as array('monday' => false, 'tuesday' => true....), and by default is null. - * @param string $timeFrom Time in the day to start to extract in mysql format, by default null. - * @param string $timeTo Time in the day to end to extract in mysql format, by default null. - * - * @return float SLA percentage of the requested module. False if no data were - * found - */ -function reporting_get_agentmodule_sla ($id_agent_module, $period = 0, $min_value = 1, $max_value = false, $date = 0, $daysWeek = null, $timeFrom = null, $timeTo = null) { - global $config; - - if (empty($id_agent_module)) - return false; - - // Initialize variables - if (empty ($date)) { - $date = get_system_time (); - } - if ($daysWeek === null) { - $daysWeek = array(); - } - // Limit date to start searching data - $datelimit = $date - $period; - - $search_in_history_db = db_search_in_history_db($datelimit); - - // Get interval data - $sql = sprintf ('SELECT * - FROM tagente_datos - 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 - if ($daysWeek) { - foreach ($daysWeek as $key => $value) { - if (!$value) { - if ($key == 'monday') { - $days[] = 2; - } - if ($key == 'tuesday') { - $days[] = 3; - } - if ($key == 'wednesday') { - $days[] = 4; - } - if ($key == 'thursday') { - $days[] = 5; - } - if ($key == 'friday') { - $days[] = 6; - } - if ($key == 'saturday') { - $days[] = 7; - } - if ($key == 'sunday') { - $days[] = 1; - } - } - } - } - - if (count($days) > 0) { - $sql .= ' AND DAYOFWEEK(FROM_UNIXTIME(utimestamp)) NOT IN (' . implode(',', $days) . ')'; - } - - if ($timeFrom < $timeTo) { - $sql .= ' AND (TIME(FROM_UNIXTIME(utimestamp)) >= "' . $timeFrom . '" AND TIME(FROM_UNIXTIME(utimestamp)) <= "'. $timeTo . '")'; - } - elseif ($timeFrom > $timeTo) { - $sql .= ' AND (TIME(FROM_UNIXTIME(utimestamp)) >= "' . $timeFrom . '" OR TIME(FROM_UNIXTIME(utimestamp)) <= "'. $timeTo . '")'; - } - $sql .= ' ORDER BY utimestamp ASC'; - $interval_data = db_get_all_rows_sql ($sql, $search_in_history_db); - - if ($interval_data === false) { - $interval_data = array (); - } - - // Calculate planned downtime dates - $downtime_dates = reporting_get_planned_downtimes_intervals($id_agent_module, $datelimit, $date); - - // Get previous data - $previous_data = modules_get_previous_data ($id_agent_module, $datelimit); - if ($previous_data !== false) { - $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) { - $next_data['utimestamp'] = $date; - array_push ($interval_data, $next_data); - } - else if (count ($interval_data) > 0) { - // Propagate the last known data to the end of the interval - $next_data = array_pop ($interval_data); - array_push ($interval_data, $next_data); - $next_data['utimestamp'] = $date; - array_push ($interval_data, $next_data); - } - - if (count ($interval_data) < 2) { - return false; - } - - // Set initial conditions - $bad_period = 0; - $first_data = array_shift ($interval_data); - - // Do not count the empty start of an interval as 0 - if ($first_data['utimestamp'] != $datelimit) { - $period = $date - $first_data['utimestamp']; - } - - $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; - } - } - } - else { - $previous_status = 0; - } - - foreach ($interval_data as $data) { - // Previous status was critical - if ($previous_status == 1) { - $bad_period += $data['utimestamp'] - $previous_utimestamp; - } - - if (array_key_exists('datos', $data)) { - // Re-calculate previous status for the next data - if ((($max_value > $min_value AND ($data['datos'] > $max_value OR $data['datos'] < $min_value))) OR - ($max_value <= $min_value AND $data['datos'] < $min_value)) { - - $previous_status = 1; - foreach ($downtime_dates as $date_dt) { - if (($date_dt['date_from'] <= $data['utimestamp']) AND ($date_dt['date_to'] >= $data['utimestamp'])) { - $previous_status = 0; - } - } - } - else { - $previous_status = 0; - } - } - - $previous_utimestamp = $data['utimestamp']; - } - - // Return the percentage of SLA compliance - return (float) (100 - ($bad_period / $period) * 100); -} -/** - * Get several SLA data for an agentmodule within a period divided on subperiods - * - * @param int Agent module to calculate SLA - * @param int Period to check the SLA compliance. - * @param int Minimum data value the module in the right interval - * @param int Maximum data value the module in the right interval. False will - * ignore max value - * @param array $days Array of days week to extract as array('monday' => false, 'tuesday' => true....), and by default is null. - * @param string $timeFrom Time in the day to start to extract in mysql format, by default null. - * @param string $timeTo Time in the day to end to extract in mysql format, by default null. - * - * @return Array with values either 1, 2, 3 or 4 depending if the SLA percentage for this subperiod - * is within the sla limits, on the edge, outside or with an unknown value. - */ -function reporting_get_agentmodule_sla_array ($id_agent_module, $period = 0, $min_value = 1, $max_value = false, $date = 0, $daysWeek = null, $timeFrom = null, $timeTo = null) { - global $config; - - if (empty($id_agent_module)) - return false; - - // Initialize variables - if (empty ($date)) { - $date = get_system_time (); - } - if ($daysWeek === null) { - $daysWeek = array(); - } - - // Hotfix: The edge values are confuse to the users - $percent = 0; - - // Limit date to start searching data - $datelimit = $date - $period; - - $search_in_history_db = db_search_in_history_db($datelimit); - - // Get interval data - $sql = sprintf ('SELECT * FROM tagente_datos - 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 - - if ($daysWeek) { - foreach ($daysWeek as $key => $value) { - if (!$value) { - if ($key == 'monday') { - $days[] = 2; - } - if ($key == 'tuesday') { - $days[] = 3; - } - if ($key == 'wednesday') { - $days[] = 4; - } - if ($key == 'thursday') { - $days[] = 5; - } - if ($key == 'friday') { - $days[] = 6; - } - if ($key == 'saturday') { - $days[] = 7; - } - if ($key == 'sunday') { - $days[] = 1; - } - } - } - } - - if (count($days) > 0) { - $sql .= ' AND DAYOFWEEK(FROM_UNIXTIME(utimestamp)) NOT IN (' . implode(',', $days) . ')'; - } - - if ($timeFrom != $timeTo) { - if ($timeFrom < $timeTo) { - $sql .= ' AND (TIME(FROM_UNIXTIME(utimestamp)) >= "' . $timeFrom . '" AND TIME(FROM_UNIXTIME(utimestamp)) <= "'. $timeTo . '")'; - } - elseif ($timeFrom > $timeTo) { - $sql .= ' AND (TIME(FROM_UNIXTIME(utimestamp)) >= "' . $timeFrom . '" OR TIME(FROM_UNIXTIME(utimestamp)) <= "'. $timeTo . '")'; - } - } - - $sql .= ' ORDER BY utimestamp ASC'; - $interval_data = db_get_all_rows_sql ($sql, $search_in_history_db); - - if ($interval_data === false) { - $interval_data = array (); - } - - - // Indexing data - $interval_data_indexed = array(); - 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, - "utimestamp > $datelimit", - "utimestamp < $date", - 'order' => 'utimestamp ASC'), - array ('id_evento', 'evento', 'timestamp', 'utimestamp', 'event_type')); - - if ($events_unknown === false) { - $events_unknown = array (); - } - - // Add unknown periods to data - for ($i = 0; isset($events_unknown[$i]); $i++) { - $eu = $events_unknown[$i]; - - if ($eu['event_type'] == 'going_unknown') { - $interval_data_indexed[$eu['utimestamp']]['data'] = 0; - $interval_data_indexed[$eu['utimestamp']]['status'] = 4; - - // Search the corresponding recovery event. - for ($j = $i+1; isset($events_unknown[$j]); $j++) { - $eu = $events_unknown[$j]; - - if ($eu['event_type'] != 'going_unknown' && substr ($eu['event_type'], 0, 5) == 'going') { - $interval_data_indexed[$eu['utimestamp']]['data'] = 0; - $interval_data_indexed[$eu['utimestamp']]['status'] = 6; - - // Do not process read events again. - $i = $j; - break; - } - } - } - } - - // 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, - "utimestamp <= $datelimit", - 'order' => 'utimestamp DESC')); - if (isset($prev_event['event_type']) && $prev_event['event_type'] == 'going_unknown') { - $start_unknown = true; - } - else { - $start_unknown = false; - } - //------------------------------------------------------------------ - - //-----------------Set limits of the interval----------------------- - // 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 ) { - $previous_value = $previous_data['datos']; - // if ((($previous_value > ($min_value - $percent)) && ($previous_value < ($min_value + $percent))) || - // (($previous_value > ($max_value - $percent)) && ($previous_value < ($max_value + $percent)))) {//2 when value is within the edges - // $previous_known_status = 2; - // } - // else - if (($previous_value >= ($min_value + $percent)) && ($previous_value <= ($max_value - $percent))) { //1 when value is OK - $previous_known_status = 1; - } - elseif (($previous_value <= ($min_value - $percent)) || ($previous_value >= ($max_value + $percent))) { //3 when value is Wrong - $previous_known_status = 3; - } - } - - // If the starting of the graph is unknown we set it - if ($start_unknown) { - $interval_data_indexed[$datelimit]['data'] = 0; - $interval_data_indexed[$datelimit]['status'] = 4; - } - else { - if ($previous_data !== false ) { - $interval_data_indexed[$datelimit]['data'] = $previous_data['datos']; - } - else { // If there are not data befor interval set unknown - $interval_data_indexed[$datelimit]['data'] = 0; - $interval_data_indexed[$datelimit]['status'] = 4; - $previous_known_status = 1; // Assume the module was in normal status if there is no previous data. - } - } - - // 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) { - $interval_data_indexed[$date]['data'] = $previous_data['datos']; - } - else if (count ($interval_data_indexed) > 0) { - // Propagate the last known data to the end of the interval (if there is no module data at the end point) - ksort($interval_data_indexed); - $last_data = end($interval_data_indexed); - $interval_data_indexed[$date] = $last_data; - } - - //------------------------------------------------------------------ - - //--------Calculate planned downtime dates-------------------------- - $downtime_dates = reporting_get_planned_downtimes_intervals($id_agent_module, $datelimit, $date); - - foreach ($downtime_dates as $downtime_date) { - // Delete data of the planned downtime and put the last data on the upper limit - $interval_data_indexed[$downtime_date['date_from']]['data'] = 0; - $interval_data_indexed[$downtime_date['date_from']]['status'] = 5; - $interval_data_indexed[$downtime_date['date_to']]['data'] = 0; - $interval_data_indexed[$downtime_date['date_to']]['status'] = 4; - - $last_downtime_data = false; - foreach ($interval_data_indexed as $idi_timestamp => $idi) { - if ($idi_timestamp != $downtime_date['date_from'] && $idi_timestamp != $downtime_date['date_to'] && - $idi_timestamp >= $downtime_date['date_from'] && $idi_timestamp <= $downtime_date['date_to']) { - $last_downtime_data = $idi['data']; - unset($interval_data_indexed[$idi_timestamp]); - } - } - - // Set the last data of the interval as limit - if ($last_downtime_data !== false) { - $interval_data_indexed[$downtime_date['date_to']]['data'] = $last_downtime_data; - } - } - //------------------------------------------------------------------ - - // Sort the array - ksort($interval_data_indexed); - - // We need more or equal two points - if (count ($interval_data_indexed) < 2) { - return false; - } - - //Get the percentage for the limits - $diff = $max_value - $min_value; - - // Get module type - $id_module_type = db_get_value('id_tipo_modulo', 'tagente_modulo', 'id_agente_modulo', $id_agent_module); - // If module is boolean don't create translation intervals (on the edge intervals) - // if ($id_module_type == 2 or $id_module_type == 6 or $id_module_type == 9 or $id_module_type == 18){ - // $percent = 0; - // } - // else { - // // Getting 10% of $diff --> $percent = ($diff/100)*10, so... - // $percent = $diff / 10; - // } - - //Set initial conditions - $first_data = array_shift ($interval_data); - $previous_utimestamp = $date - $period; - - $previous_value = $first_data ['datos']; - $previous_status = 0; - - if (isset($first_data['status'])) { - // 4 for the Unknown value and 5 for planned downtime - $previous_status = $first_data['status']; - } - // elseif ((($previous_value > ($min_value - $percent)) && ($previous_value < ($min_value + $percent))) || - // (($previous_value > ($max_value - $percent)) && ($previous_value < ($max_value + $percent)))) {//2 when value is within the edges - // $previous_status = 2; - // } - elseif (($previous_value >= ($min_value + $percent)) && ($previous_value <= ($max_value - $percent))) { //1 when value is OK - $previous_status = 1; - } - elseif (($previous_value <= ($min_value - $percent)) || ($previous_value >= ($max_value + $percent))) { //3 when value is Wrong - $previous_status = 3; - } - - $data_colors = array(); - $i = 0; - - foreach ($interval_data_indexed as $utimestamp => $data) { - $change = false; - $value = $data['data']; - if (isset($data['status'])) { - // Leaving unkown status. - if ($data['status'] == 6) { - $status = $previous_known_status; - } - // 4 unknown, 5 planned downtime. - else { - $status = $data['status']; - } - } - // elseif ((($value > ($min_value - $percent)) && ($value < ($min_value + $percent))) || - // (($value > ($max_value - $percent)) && ($value < ($max_value + $percent)))) { //2 when value is within the edges - // $status = 2; - // } - elseif (($value >= ($min_value + $percent)) && ($value <= ($max_value - $percent))) { //1 when value is OK - $status = 1; - } - elseif (($value <= ($min_value - $percent)) || ($value >= ($max_value + $percent))) { //3 when value is Wrong - $status = 3; - } - - if ($status != $previous_status) { - $change = true; - $data_colors[$i]['data'] = $previous_status; - $data_colors[$i]['utimestamp'] = $utimestamp - $previous_utimestamp; - $i++; - $previous_status = $status; - $previous_utimestamp = $utimestamp; - } - - // Save the last known status. - if ($status <= 3) { - $previous_known_status = $status; - } - } - if ($change == false) { - $data_colors[$i]['data'] = $previous_status; - $data_colors[$i]['utimestamp'] = $date - $previous_utimestamp; - } - - return $data_colors; -} - -/** - * Get the time intervals where an agentmodule is affected by the planned downtimes. - * - * @param int Agent module to calculate planned downtimes intervals. - * @param int Start date in utimestamp. - * @param int End date in utimestamp. - * @param bool Whether ot not to get the planned downtimes that affect the service associated with the agentmodule. - * - * @return Array with time intervals. - */ -function reporting_get_planned_downtimes_intervals ($id_agent_module, $start_date, $end_date, $check_services = false) { - global $config; - - if (empty($id_agent_module)) - return false; - - require_once ($config['homedir'] . '/include/functions_planned_downtimes.php'); - - $malformed_planned_downtimes = planned_downtimes_get_malformed(); - if (empty($malformed_planned_downtimes)) - $malformed_planned_downtimes = array(); - - $sql_downtime = "SELECT DISTINCT(tpdr.id), tpdr.* - FROM ( - SELECT tpd.* - FROM tplanned_downtime tpd, tplanned_downtime_agents tpda, tagente_modulo tam - WHERE tpd.id = tpda.id_downtime - AND tpda.all_modules = 1 - AND tpda.id_agent = tam.id_agente - AND tam.id_agente_modulo = $id_agent_module - UNION ALL - SELECT tpd.* - FROM tplanned_downtime tpd, tplanned_downtime_modules tpdm - WHERE tpd.id = tpdm.id_downtime - AND tpdm.id_agent_module = $id_agent_module - ) tpdr - ORDER BY tpdr.id"; - - $downtimes = db_get_all_rows_sql($sql_downtime); - - if ($downtimes == false) { - $downtimes = array(); - } - $downtime_dates = array(); - foreach ($downtimes as $downtime) { - $downtime_id = $downtime['id']; - $downtime_type = $downtime['type_execution']; - $downtime_periodicity = $downtime['type_periodicity']; - - if ($downtime_type == 'once') { - $dates = array(); - $dates['date_from'] = $downtime['date_from']; - $dates['date_to'] = $downtime['date_to']; - $downtime_dates[] = $dates; - } - else if ($downtime_type == 'periodically') { - - // If a planned downtime have malformed dates, its intervals aren't taken account - $downtime_malformed = false; - foreach ($malformed_planned_downtimes as $malformed_planned_downtime) { - if ($downtime_id == $malformed_planned_downtime['id']) { - $downtime_malformed = true; - break; - } - } - if ($downtime_malformed == true) { - continue; - } - // If a planned downtime have malformed dates, its intervals aren't taken account - - $downtime_time_from = $downtime['periodically_time_from']; - $downtime_time_to = $downtime['periodically_time_to']; - - $downtime_hour_from = date("H", strtotime($downtime_time_from)); - $downtime_minute_from = date("i", strtotime($downtime_time_from)); - $downtime_second_from = date("s", strtotime($downtime_time_from)); - $downtime_hour_to = date("H", strtotime($downtime_time_to)); - $downtime_minute_to = date("i", strtotime($downtime_time_to)); - $downtime_second_to = date("s", strtotime($downtime_time_to)); - - if ($downtime_periodicity == "monthly") { - $downtime_day_from = $downtime['periodically_day_from']; - $downtime_day_to = $downtime['periodically_day_to']; - - $date_aux = strtotime(date("Y-m-01", $start_date)); - $year_aux = date("Y", $date_aux); - $month_aux = date("m", $date_aux); - - $end_year = date("Y", $end_date); - $end_month = date("m", $end_date); - - while ($year_aux < $end_year || ($year_aux == $end_year && $month_aux <= $end_month)) { - - if ($downtime_day_from > $downtime_day_to) { - $dates = array(); - $dates['date_from'] = strtotime("$year_aux-$month_aux-$downtime_day_from $downtime_hour_from:$downtime_minute_from:$downtime_second_from"); - $dates['date_to'] = strtotime(date("Y-m-t H:i:s", strtotime("$year_aux-$month_aux-28 23:59:59"))); - $downtime_dates[] = $dates; - - $dates = array(); - if ($month_aux + 1 <= 12) { - $dates['date_from'] = strtotime("$year_aux-".($month_aux + 1)."-01 00:00:00"); - $dates['date_to'] = strtotime("$year_aux-".($month_aux + 1)."-$downtime_day_to $downtime_hour_to:$downtime_minute_to:$downtime_second_to"); - } - else { - $dates['date_from'] = strtotime(($year_aux + 1)."-01-01 00:00:00"); - $dates['date_to'] = strtotime(($year_aux + 1)."-01-$downtime_day_to $downtime_hour_to:$downtime_minute_to:$downtime_second_to"); - } - $downtime_dates[] = $dates; - } - else { - if ($downtime_day_from == $downtime_day_to && strtotime($downtime_time_from) > strtotime($downtime_time_to)) { - $date_aux_from = strtotime("$year_aux-$month_aux-$downtime_day_from $downtime_hour_from:$downtime_minute_from:$downtime_second_from"); - $max_day_num = date('t', $date_aux); - - $dates = array(); - $dates['date_from'] = strtotime("$year_aux-$month_aux-$downtime_day_from $downtime_hour_from:$downtime_minute_from:$downtime_second_from"); - $dates['date_to'] = strtotime("$year_aux-$month_aux-$downtime_day_from 23:59:59"); - $downtime_dates[] = $dates; - - if ($downtime_day_to + 1 > $max_day_num) { - - $dates = array(); - if ($month_aux + 1 <= 12) { - $dates['date_from'] = strtotime("$year_aux-".($month_aux + 1)."-01 00:00:00"); - $dates['date_to'] = strtotime("$year_aux-".($month_aux + 1)."-01 $downtime_hour_to:$downtime_minute_to:$downtime_second_to"); - } - else { - $dates['date_from'] = strtotime(($year_aux + 1)."-01-01 00:00:00"); - $dates['date_to'] = strtotime(($year_aux + 1)."-01-01 $downtime_hour_to:$downtime_minute_to:$downtime_second_to"); - } - $downtime_dates[] = $dates; - } - else { - $dates = array(); - $dates['date_from'] = strtotime("$year_aux-$month_aux-".($downtime_day_to + 1)." 00:00:00"); - $dates['date_to'] = strtotime("$year_aux-$month_aux-".($downtime_day_to + 1)." $downtime_hour_to:$downtime_minute_to:$downtime_second_to"); - $downtime_dates[] = $dates; - } - } - else { - $dates = array(); - $dates['date_from'] = strtotime("$year_aux-$month_aux-$downtime_day_from $downtime_hour_from:$downtime_minute_from:$downtime_second_from"); - $dates['date_to'] = strtotime("$year_aux-$month_aux-$downtime_day_to $downtime_hour_to:$downtime_minute_to:$downtime_second_to"); - $downtime_dates[] = $dates; - } - } - - $month_aux++; - if ($month_aux > 12) { - $month_aux = 1; - $year_aux++; - } - } - } - else if ($downtime_periodicity == "weekly") { - $date_aux = $start_date; - $active_days = array(); - $active_days[0] = ($downtime['sunday'] == 1) ? true : false; - $active_days[1] = ($downtime['monday'] == 1) ? true : false; - $active_days[2] = ($downtime['tuesday'] == 1) ? true : false; - $active_days[3] = ($downtime['wednesday'] == 1) ? true : false; - $active_days[4] = ($downtime['thursday'] == 1) ? true : false; - $active_days[5] = ($downtime['friday'] == 1) ? true : false; - $active_days[6] = ($downtime['saturday'] == 1) ? true : false; - - while ($date_aux <= $end_date) { - $weekday_num = date('w', $date_aux); - - if ($active_days[$weekday_num]) { - $day_num = date('d', $date_aux); - $month_num = date('m', $date_aux); - $year_num = date('Y', $date_aux); - - $max_day_num = date('t', $date_aux); - - if (strtotime($downtime_time_from) > strtotime($downtime_time_to)) { - $dates = array(); - $dates['date_from'] = strtotime("$year_num-$month_num-$day_num $downtime_hour_from:$downtime_minute_from:$downtime_second_from"); - $dates['date_to'] = strtotime("$year_num-$month_num-$day_num 23:59:59"); - $downtime_dates[] = $dates; - - $dates = array(); - if ($day_num + 1 > $max_day_num) { - if ($month_num + 1 > 12) { - $dates['date_from'] = strtotime(($year_num + 1)."-01-01 00:00:00"); - $dates['date_to'] = strtotime(($year_num + 1)."-01-01 $downtime_hour_to:$downtime_minute_to:$downtime_second_to"); - } - else { - $dates['date_from'] = strtotime("$year_num-".($month_num + 1)."-01 00:00:00"); - $dates['date_to'] = strtotime("$year_num-".($month_num + 1)."-01 $downtime_hour_to:$downtime_minute_to:$downtime_second_to"); - } - } - else { - $dates['date_from'] = strtotime("$year_num-$month_num-".($day_num + 1)." 00:00:00"); - $dates['date_to'] = strtotime("$year_num-$month_num-".($day_num + 1)." $downtime_hour_to:$downtime_minute_to:$downtime_second_to"); - } - $downtime_dates[] = $dates; - } - else { - $dates = array(); - $dates['date_from'] = strtotime("$year_num-$month_num-$day_num $downtime_hour_from:$downtime_minute_from:$downtime_second_from"); - $dates['date_to'] = strtotime("$year_num-$month_num-$day_num $downtime_hour_to:$downtime_minute_to:$downtime_second_to"); - $downtime_dates[] = $dates; - } - } - - $date_aux += SECONDS_1DAY; - } - } - } - } - - if ($check_services) { - enterprise_include_once("include/functions_services.php"); - if (function_exists("services_get_planned_downtimes_intervals")) { - services_get_planned_downtimes_intervals($downtime_dates, $start_date, $end_date, false, $id_agent_module); - } - } - - return $downtime_dates; -} - -/** - * Get the planned downtimes that affect the passed modules on an specific datetime range. - * - * @param int Start date in utimestamp. - * @param int End date in utimestamp. - * @param array The agent modules ids. - * - * @return Array with the planned downtimes that are executed in any moment of the range selected and affect the - * agent modules selected. - */ -function reporting_get_planned_downtimes ($start_date, $end_date, $id_agent_modules = false) { - $start_time = date("H:i:s", $start_date); - $end_time = date("H:i:s", $end_date); - - $start_day = date("d", $start_date); - $end_day = date("d", $end_date); - - $start_month = date("m", $start_date); - $end_month = date("m", $end_date); - - if ($start_date > $end_date) { - return false; - } - - if ($end_date - $start_date >= SECONDS_1MONTH) { - // If the date range is larger than 1 month, every monthly planned downtime will be inside - $periodically_monthly_w = "type_periodicity = 'monthly'"; - } - else { - // Check if the range is larger than the planned downtime execution, or if its start or end - // is inside the planned downtime execution. - // The start and end time is very important. - $periodically_monthly_w = "type_periodicity = 'monthly' - AND (((periodically_day_from > '$start_day' - OR (periodically_day_from = '$start_day' - AND periodically_time_from >= '$start_time')) - AND (periodically_day_to < '$end_day' - OR (periodically_day_to = '$end_day' - AND periodically_time_to <= '$end_time'))) - OR ((periodically_day_from < '$start_day' - OR (periodically_day_from = '$start_day' - AND periodically_time_from <= '$start_time')) - AND (periodically_day_to > '$start_day' - OR (periodically_day_to = '$start_day' - AND periodically_time_to >= '$start_time'))) - OR ((periodically_day_from < '$end_day' - OR (periodically_day_from = '$end_day' - AND periodically_time_from <= '$end_time')) - AND (periodically_day_to > '$end_day' - OR (periodically_day_to = '$end_day' - AND periodically_time_to >= '$end_time'))))"; - } - - $periodically_weekly_days = array(); - $date_aux = $start_date; - $i = 0; - - if (($end_date - $start_date) >= SECONDS_1WEEK) { - // If the date range is larger than 7 days, every weekly planned downtime will be inside. - for ($i = 0; $i < 7; $i++) { - $weekday_actual = strtolower(date('l', $date_aux)); - $periodically_weekly_days[] = "($weekday_actual = 1)"; - $date_aux += SECONDS_1DAY; - } - } - else if (($end_date - $start_date) <= SECONDS_1DAY && $start_day == $end_day) { - // If the date range is smaller than 1 day, the start and end days can be equal or consecutive. - // If they are equal, the execution times have to be contained in the date range times or contain - // the start or end time of the date range. - $weekday_actual = strtolower(date('l', $start_date)); - $periodically_weekly_days[] = "($weekday_actual = 1 - AND ((periodically_time_from > '$start_time' AND periodically_time_to < '$end_time') - OR (periodically_time_from = '$start_time' - OR (periodically_time_from < '$start_time' - AND periodically_time_to >= '$start_time')) - OR (periodically_time_from = '$end_time' - OR (periodically_time_from < '$end_time' - AND periodically_time_to >= '$end_time'))))"; - } - else { - while ($date_aux <= $end_date && $i < 7) { - - $weekday_actual = strtolower(date('l', $date_aux)); - $day_num_actual = date('d', $date_aux); - - if ($date_aux == $start_date) { - $periodically_weekly_days[] = "($weekday_actual = 1 AND periodically_time_to >= '$start_time')"; - } - else if ($day_num_actual == $end_day) { - $periodically_weekly_days[] = "($weekday_actual = 1 AND periodically_time_from <= '$end_time')"; - } - else { - $periodically_weekly_days[] = "($weekday_actual = 1)"; - } - - $date_aux += SECONDS_1DAY; - $i++; - } - } - - if (!empty($periodically_weekly_days)) { - $periodically_weekly_w = "type_periodicity = 'weekly' AND (".implode(" OR ", $periodically_weekly_days).")"; - $periodically_condition = "(($periodically_monthly_w) OR ($periodically_weekly_w))"; - } - else { - $periodically_condition = "($periodically_monthly_w)"; - } - - if ($id_agent_modules !== false) { - if (empty($id_agent_modules)) - return array(); - - $id_agent_modules_str = implode(",", $id_agent_modules); - - $sql_downtime = "SELECT DISTINCT(tpdr.id), tpdr.* - FROM ( - SELECT tpd.* - FROM tplanned_downtime tpd, tplanned_downtime_agents tpda, tagente_modulo tam - WHERE (tpd.id = tpda.id_downtime - AND tpda.all_modules = 1 - AND tpda.id_agent = tam.id_agente - AND tam.id_agente_modulo IN ($id_agent_modules_str)) - AND ((type_execution = 'periodically' - AND $periodically_condition) - OR (type_execution = 'once' - AND ((date_from >= '$start_date' AND date_to <= '$end_date') - OR (date_from <= '$start_date' AND date_to >= '$end_date') - OR (date_from <= '$start_date' AND date_to >= '$start_date') - OR (date_from <= '$end_date' AND date_to >= '$end_date')))) - UNION ALL - SELECT tpd.* - FROM tplanned_downtime tpd, tplanned_downtime_modules tpdm - WHERE (tpd.id = tpdm.id_downtime - AND tpdm.id_agent_module IN ($id_agent_modules_str)) - AND ((type_execution = 'periodically' - AND $periodically_condition) - OR (type_execution = 'once' - AND ((date_from >= '$start_date' AND date_to <= '$end_date') - OR (date_from <= '$start_date' AND date_to >= '$end_date') - OR (date_from <= '$start_date' AND date_to >= '$start_date') - OR (date_from <= '$end_date' AND date_to >= '$end_date')))) - ) tpdr - ORDER BY tpdr.id"; - } - else { - $sql_downtime = "SELECT * - FROM tplanned_downtime tpd, tplanned_downtime_modules tpdm - WHERE (type_execution = 'periodically' - AND $periodically_condition) - OR (type_execution = 'once' - AND ((date_from >= '$start_date' AND date_to <= '$end_date') - OR (date_from <= '$start_date' AND date_to >= '$end_date') - OR (date_from <= '$start_date' AND date_to >= '$start_date') - OR (date_from <= '$end_date' AND date_to >= '$end_date')))"; - } - - $downtimes = db_get_all_rows_sql($sql_downtime); - if ($downtimes == false) { - $downtimes = array(); - } - - return $downtimes; -} - -function reporting_get_stats_servers($tiny = true) { - global $config; - - $server_performance = servers_get_performance(); - - // Alerts table - $table_srv = html_get_predefined_table(); - - $table_srv->style[0] = $table_srv->style[2] = 'text-align: right; padding: 5px;'; - $table_srv->style[1] = $table_srv->style[3] = 'text-align: left; padding: 5px;'; - - $tdata = array(); - $tdata[0] = html_print_image('images/module.png', true, array('title' => __('Total running modules'), 'width' => '25px')); - $tdata[1] = '' . format_numeric($server_performance ["total_modules"]) . ''; - - $tdata[2] = '' . format_numeric($server_performance ["total_modules_rate"], 2) . ''; - $tdata[3] = html_print_image('images/module.png', true, array('title' => __('Ratio') . ': ' . __('Modules by second'), 'width' => '16px')) . '/sec '; - - $table_srv->rowclass[] = ''; - $table_srv->data[] = $tdata; - - $tdata = array(); - $tdata[0] = '
'; - $table_srv->colspan[count($table_srv->data)][0] = 4; - $table_srv->rowclass[] = ''; - $table_srv->data[] = $tdata; - - $tdata = array(); - $tdata[0] = html_print_image('images/database.png', true, array('title' => __('Local modules'), 'width' => '25px')); - $tdata[1] = '' . format_numeric($server_performance ["total_local_modules"]) . ''; - - $tdata[2] = '' . - format_numeric($server_performance ["local_modules_rate"], 2) . ''; - $tdata[3] = html_print_image('images/module.png', true, array('title' => __('Ratio') . ': ' . __('Modules by second'), 'width' => '16px')) . '/sec '; - - $table_srv->rowclass[] = ''; - $table_srv->data[] = $tdata; - - if ($tiny) { - $tdata = array(); - $tdata[0] = html_print_image('images/network.png', true, array('title' => __('Remote modules'), 'width' => '25px')); - $tdata[1] = '' . format_numeric($server_performance ["total_remote_modules"]) . ''; - - $tdata[2] = '' . format_numeric($server_performance ["remote_modules_rate"], 2) . ''; - $tdata[3] = html_print_image('images/module.png', true, array('title' => __('Ratio') . ': ' . __('Modules by second'), 'width' => '16px')) . '/sec '; - - $table_srv->rowclass[] = ''; - $table_srv->data[] = $tdata; - } - else { - if (isset($server_performance ["total_network_modules"])) { - $tdata = array(); - $tdata[0] = html_print_image('images/network.png', true, array('title' => __('Network modules'), 'width' => '25px')); - $tdata[1] = '' . format_numeric($server_performance ["total_network_modules"]) . ''; - - $tdata[2] = '' . - format_numeric($server_performance["network_modules_rate"], 2) . - ''; - $tdata[3] = html_print_image('images/module.png', true, array('title' => __('Ratio') . ': ' . __('Modules by second'), 'width' => '16px')) . '/sec '; - - $table_srv->rowclass[] = ''; - $table_srv->data[] = $tdata; - } - - if (isset($server_performance ["total_plugin_modules"])) { - $tdata = array(); - $tdata[0] = html_print_image('images/plugin.png', true, array('title' => __('Plugin modules'), 'width' => '25px')); - $tdata[1] = '' . format_numeric($server_performance ["total_plugin_modules"]) . ''; - - $tdata[2] = '' . format_numeric($server_performance ["plugin_modules_rate"], 2) . ''; - $tdata[3] = html_print_image('images/module.png', true, array('title' => __('Ratio') . ': ' . __('Modules by second'), 'width' => '16px')) . '/sec '; - - $table_srv->rowclass[] = ''; - $table_srv->data[] = $tdata; - } - - if (isset($server_performance ["total_prediction_modules"])) { - $tdata = array(); - $tdata[0] = html_print_image('images/chart_bar.png', true, array('title' => __('Prediction modules'), 'width' => '25px')); - $tdata[1] = '' . format_numeric($server_performance ["total_prediction_modules"]) . ''; - - $tdata[2] = '' . format_numeric($server_performance ["prediction_modules_rate"], 2) . ''; - $tdata[3] = html_print_image('images/module.png', true, array('title' => __('Ratio') . ': ' . __('Modules by second'), 'width' => '16px')) . '/sec '; - - $table_srv->rowclass[] = ''; - $table_srv->data[] = $tdata; - } - - if (isset($server_performance ["total_wmi_modules"])) { - $tdata = array(); - $tdata[0] = html_print_image('images/wmi.png', true, array('title' => __('WMI modules'), 'width' => '25px')); - $tdata[1] = '' . format_numeric($server_performance ["total_wmi_modules"]) . ''; - - $tdata[2] = '' . format_numeric($server_performance ["wmi_modules_rate"], 2) . ''; - $tdata[3] = html_print_image('images/module.png', true, array('title' => __('Ratio') . ': ' . __('Modules by second'), 'width' => '16px')) . '/sec '; - - $table_srv->rowclass[] = ''; - $table_srv->data[] = $tdata; - } - - if (isset($server_performance ["total_web_modules"])) { - $tdata = array(); - $tdata[0] = html_print_image('images/world.png', true, array('title' => __('Web modules'), 'width' => '25px')); - $tdata[1] = '' . - format_numeric($server_performance ["total_web_modules"]) . - ''; - - $tdata[2] = '' . - format_numeric($server_performance ["web_modules_rate"], 2) . - ''; - $tdata[3] = html_print_image('images/module.png', true, array('title' => __('Ratio') . ': ' . __('Modules by second'), 'width' => '16px')) . '/sec '; - - $table_srv->rowclass[] = ''; - $table_srv->data[] = $tdata; - } - - $tdata = array(); - $tdata[0] = '
'; - $table_srv->colspan[count($table_srv->data)][0] = 4; - $table_srv->rowclass[] = ''; - $table_srv->data[] = $tdata; - - - switch ($config["dbtype"]) { - case "mysql": - $system_events = db_get_value_sql( - 'SELECT SQL_NO_CACHE COUNT(id_evento) - FROM tevento'); - break; - case "postgresql": - case "oracle": - $system_events = db_get_value_sql( - 'SELECT COUNT(id_evento) - FROM tevento'); - break; - } - - - - $tdata = array(); - $tdata[0] = html_print_image('images/lightning_go.png', true, - array('title' => __('Total events'), 'width' => '25px')); - $tdata[1] = '' . - format_numeric($system_events) . ''; - - $table_srv->colspan[count($table_srv->data)][1] = 3; - $table_srv->rowclass[] = ''; - $table_srv->data[] = $tdata; - } - - $output = '
- ' . - __('Server performance') . - '' . - html_print_table($table_srv, true) . '
'; - - return $output; -} - -function reporting_get_stats_modules_status($data, $graph_width = 250, $graph_height = 150, $links = false, $data_agents=false) { - global $config; - - // Link URLS - if ($links === false) { - $urls = array(); - $urls['monitor_critical'] = "index.php?" . - "sec=estado&sec2=operation/agentes/status_monitor&" . - "refr=60&status=" . AGENT_MODULE_STATUS_CRITICAL_BAD . "&pure=" . $config['pure']; - $urls['monitor_warning'] = "index.php?" . - "sec=estado&sec2=operation/agentes/status_monitor&" . - "refr=60&status=" . AGENT_MODULE_STATUS_WARNING . "&pure=" . $config['pure']; - $urls['monitor_ok'] = "index.php?" . - "sec=estado&sec2=operation/agentes/status_monitor&" . - "refr=60&status=" . AGENT_MODULE_STATUS_NORMAL . "&pure=" . $config['pure']; - $urls['monitor_unknown'] = "index.php?" . - "sec=estado&sec2=operation/agentes/status_monitor&" . - "refr=60&status=" . AGENT_MODULE_STATUS_UNKNOWN . "&pure=" . $config['pure']; - $urls['monitor_not_init'] = "index.php?" . - "sec=estado&sec2=operation/agentes/status_monitor&" . - "refr=60&status=" . AGENT_MODULE_STATUS_NOT_INIT . "&pure=" . $config['pure']; - } - else { - $urls = array(); - $urls['monitor_critical'] = $links['monitor_critical']; - $urls['monitor_warning'] = $links['monitor_warning']; - $urls['monitor_ok'] = $links['monitor_ok']; - $urls['monitor_unknown'] = $links['monitor_unknown']; - $urls['monitor_not_init'] = $links['monitor_not_init']; - } - - // Modules by status table - $table_mbs = html_get_predefined_table(); - - $tdata = array(); - $tdata[0] = html_print_image('images/module_critical.png', true, array('title' => __('Monitor critical'))); - $tdata[1] = $data["monitor_critical"] <= 0 ? '-' : $data["monitor_critical"]; - $tdata[1] = '' . $tdata[1] . ''; - - $tdata[2] = html_print_image('images/module_warning.png', true, array('title' => __('Monitor warning'))); - $tdata[3] = $data["monitor_warning"] <= 0 ? '-' : $data["monitor_warning"]; - $tdata[3] = '' . $tdata[3] . ''; - $table_mbs->rowclass[] = ''; - $table_mbs->data[] = $tdata; - - $tdata = array(); - $tdata[0] = html_print_image('images/module_ok.png', true, array('title' => __('Monitor normal'))); - $tdata[1] = $data["monitor_ok"] <= 0 ? '-' : $data["monitor_ok"]; - $tdata[1] = '' . $tdata[1] . ''; - - $tdata[2] = html_print_image('images/module_unknown.png', true, array('title' => __('Monitor unknown'))); - $tdata[3] = $data["monitor_unknown"] <= 0 ? '-' : $data["monitor_unknown"]; - $tdata[3] = '' . $tdata[3] . ''; - $table_mbs->rowclass[] = ''; - $table_mbs->data[] = $tdata; - - $tdata = array(); - $tdata[0] = html_print_image('images/module_notinit.png', true, array('title' => __('Monitor not init'))); - $tdata[1] = $data["monitor_not_init"] <= 0 ? '-' : $data["monitor_not_init"]; - $tdata[1] = '' . $tdata[1] . ''; - - $tdata[2] = $tdata[3] = ''; - $table_mbs->rowclass[] = ''; - $table_mbs->data[] = $tdata; - - if ($data["monitor_checks"] > 0) { - $tdata = array(); - $table_mbs->colspan[count($table_mbs->data)][0] = 4; - $table_mbs->cellstyle[count($table_mbs->data)][0] = 'text-align: center;'; - $tdata[0] = '
' . - '
' . - graph_agent_status(false, $graph_width, $graph_height, true, true, $data_agents) . - '
'; - $table_mbs->rowclass[] = ''; - $table_mbs->data[] = $tdata; - } - - if(!defined("METACONSOLE")){ - $output = ' -
- ' . - __('Monitors by status') . - '' . - html_print_table($table_mbs, true) . - '
'; - } - else{ - $table_mbs->class = "tactical_view"; - $table_mbs->style=array(); - $output = ' -
- ' . - __('Monitors by status') . - '' . - html_print_table($table_mbs, true) . - '
'; - } - return $output; -} - -function reporting_get_stats_summary($data, $graph_width, $graph_height) { - global $config; - - // Alerts table - $table_sum = html_get_predefined_table(); - - $tdata = array(); - $table_sum->colspan[count($table_sum->data)][0] = 2; - $table_sum->colspan[count($table_sum->data)][2] = 2; - $table_sum->cellstyle[count($table_sum->data)][0] = 'text-align: center;'; - $table_sum->cellstyle[count($table_sum->data)][2] = 'text-align: center;'; - $tdata[0] = '' . __('Module status') . ''; - $tdata[2] = '' . __('Alert level') . ''; - $table_sum->rowclass[] = ''; - $table_sum->data[] = $tdata; - - $tdata = array(); - $table_sum->colspan[count($table_sum->data)][0] = 2; - $table_sum->colspan[count($table_sum->data)][2] = 2; - $table_sum->cellstyle[count($table_sum->data)][0] = 'text-align: center;'; - $table_sum->cellstyle[count($table_sum->data)][2] = 'text-align: center;'; - - if ($data["monitor_checks"] > 0) { - $tdata[0] = '
' . graph_agent_status (false, $graph_width, $graph_height, true, true) . '
'; - } - else { - $tdata[2] = html_print_image('images/image_problem.png', true, array('width' => $graph_width)); - } - if ($data["monitor_alerts"] > 0) { - $tdata[2] = '
' . graph_alert_status ($data["monitor_alerts"], $data["monitor_alerts_fired"], $graph_width, $graph_height, true, true) . '
'; - } - else { - $tdata[2] = html_print_image('images/image_problem.png', true, array('width' => $graph_width)); - } - $table_sum->rowclass[] = ''; - $table_sum->data[] = $tdata; - - $output = '
- ' . - __('Summary') . - '' . - html_print_table($table_sum, true) . '
'; - - return $output; -} - -function reporting_get_stats_alerts($data, $links = false) { - global $config; - - // Link URLS - $mobile = false; - if (isset($data['mobile'])) { - if ($data['mobile']) { - $mobile = true; - } - } - - if ($mobile) { - $urls = array(); - $urls['monitor_alerts'] = "index.php?page=alerts&status=all_enabled"; - $urls['monitor_alerts_fired'] = "index.php?page=alerts&status=fired"; - } - else { - $urls = array(); - if ($links) { - $urls['monitor_alerts'] = "index.php?sec=estado&sec2=operation/agentes/alerts_status&pure=" . $config['pure']; - $urls['monitor_alerts_fired'] = "index.php?sec=estado&sec2=operation/agentes/alerts_status&filter=fired&pure=" . $config['pure']; - } else { - $urls['monitor_alerts'] = "index.php?sec=estado&sec2=operation/agentes/alerts_status&refr=60"; - $urls['monitor_alerts_fired'] = "index.php?sec=estado&sec2=operation/agentes/alerts_status&refr=60&filter=fired"; - } - } - - // Alerts table - $table_al = html_get_predefined_table(); - - $tdata = array(); - $tdata[0] = html_print_image('images/bell.png', true, array('title' => __('Defined alerts'))); - $tdata[1] = $data["monitor_alerts"] <= 0 ? '-' : $data["monitor_alerts"]; - $tdata[1] = '' . $tdata[1] . ''; - - $tdata[2] = html_print_image('images/bell_error.png', true, array('title' => __('Fired alerts'))); - $tdata[3] = $data["monitor_alerts_fired"] <= 0 ? '-' : $data["monitor_alerts_fired"]; - $tdata[3] = '' . $tdata[3] . ''; - $table_al->rowclass[] = ''; - $table_al->data[] = $tdata; - - if(!defined('METACONSOLE')){ - $output = '
- ' . - __('Defined and fired alerts') . - '' . - html_print_table($table_al, true) . '
'; - }else{ - $table_al->class = "tactical_view"; - $table_al->style = array(); - $output = '
- ' . - __('Defined and fired alerts') . - '' . - html_print_table($table_al, true) . '
'; - } - return $output; -} - -function reporting_get_stats_users($data) { - global $config; - - // Link URLS - $urls = array(); - if (check_acl ($config['id_user'], 0, "UM")) { - $urls['defined_users'] = "index.php?sec=gusuarios&sec2=godmode/users/user_list"; - } - else { - $urls['defined_users'] = 'javascript:'; - } - - // Users table - $table_us = html_get_predefined_table(); - - $tdata = array(); - $tdata[0] = html_print_image('images/user_green.png', true, array('title' => __('Defined users'))); - $tdata[1] = count (get_users ()); - $tdata[1] = '' . $tdata[1] . ''; - - $tdata[2] = $tdata[3] = ' '; - $table_us->rowclass[] = ''; - $table_us->data[] = $tdata; - - $output = '
- ' . - __('Users') . - '' . - html_print_table($table_us, true) . '
'; - - return $output; -} - -function reporting_get_stats_agents_monitors($data) { - global $config; - - // Link URLS - $mobile = false; - if (isset($data['mobile'])) { - if ($data['mobile']) { - $mobile = true; - } - } - - if ($mobile) { - $urls = array(); - $urls['total_agents'] = "index.php?page=agents"; - $urls['monitor_checks'] = "index.php?page=modules"; - } - else { - $urls = array(); - $urls['total_agents'] = "index.php?sec=estado&sec2=operation/agentes/estado_agente&refr=60"; - $urls['monitor_checks'] = "index.php?sec=estado&sec2=operation/agentes/status_monitor&refr=60&status=-1"; - } - - // Agents and modules table - $table_am = html_get_predefined_table(); - - $tdata = array(); - $tdata[0] = html_print_image('images/agent.png', true, array('title' => __('Total agents'))); - $tdata[1] = $data["total_agents"] <= 0 ? '-' : $data["total_agents"]; - $tdata[1] = '' . $tdata[1] . ''; - - $tdata[2] = html_print_image('images/module.png', true, array('title' => __('Monitor checks'))); - $tdata[3] = $data["monitor_checks"] <= 0 ? '-' : $data["monitor_checks"]; - $tdata[3] = '' . $tdata[3] . ''; - $table_am->rowclass[] = ''; - $table_am->data[] = $tdata; - - $output = '
- ' . - __('Total agents and monitors') . - '' . - html_print_table($table_am, true) . '
'; - - return $output; -} - -function reporting_get_stats_indicators($data, $width = 280, $height = 20, $html = true) { - $table_ind = html_get_predefined_table(); - - $servers = array(); - $servers["all"] = (int) db_get_value ('COUNT(id_server)','tserver'); - $servers["up"] = (int) servers_check_status (); - $servers["down"] = $servers["all"] - $servers["up"]; - if ($servers["all"] == 0) { - $servers["health"] = 0; - } - else { - $servers["health"] = $servers["up"] / ($servers["all"] / 100); - } - - if ($html) { - $tdata[0] = '
- ' . - __('Server health') . ui_print_help_tip (sprintf(__('%d Downed servers'), $servers["down"]), true) . - '' . - progress_bar($servers["health"], $width, $height, '', 0) . '
'; - $table_ind->rowclass[] = ''; - $table_ind->data[] = $tdata; - - $tdata[0] = '
- ' . - __('Monitor health') . ui_print_help_tip (sprintf(__('%d Not Normal monitors'), $data["monitor_not_normal"]), true) . - '' . - progress_bar($data["monitor_health"], $width, $height, $data["monitor_health"].'% '.__('of monitors up'), 0) . '
'; - $table_ind->rowclass[] = ''; - $table_ind->data[] = $tdata; - - $tdata[0] = '
- ' . - __('Module sanity') . ui_print_help_tip (sprintf(__('%d Not inited monitors'), $data["monitor_not_init"]), true) . - '' . - progress_bar($data["module_sanity"], $width, $height, $data["module_sanity"].'% '.__('of total modules inited'), 0) . '
'; - $table_ind->rowclass[] = ''; - $table_ind->data[] = $tdata; - - $tdata[0] = '
- ' . - __('Alert level') . ui_print_help_tip (sprintf(__('%d Fired alerts'), $data["monitor_alerts_fired"]), true) . - '' . - progress_bar($data["alert_level"], $width, $height, $data["alert_level"].'% '.__('of defined alerts not fired'), 0) . '
'; - $table_ind->rowclass[] = ''; - $table_ind->data[] = $tdata; - - - return html_print_table($table_ind, true); - } - else { - $return = array(); - - $return['server_health'] = array( - 'title' => __('Server health'), - 'graph' => progress_bar($servers["health"], $width, $height, '', 0)); - $return['monitor_health'] = array( - 'title' => __('Monitor health'), - 'graph' => progress_bar($data["monitor_health"], $width, $height, $data["monitor_health"].'% '.__('of monitors up'), 0)); - $return['module_sanity'] = array( - 'title' => __('Module sanity'), - 'graph' => progress_bar($data["module_sanity"], $width, $height, $data["module_sanity"].'% '.__('of total modules inited'), 0)); - $return['alert_level'] = array( - 'title' => __('Alert level'), - 'graph' => progress_bar($data["alert_level"], $width, $height, $data["alert_level"].'% '.__('of defined alerts not fired'), 0)); - - return $return; - } -} - -/** - * Get general statistical info on a group - * - * @param int Group Id to get info from. 0 = all - * - * @return array Group statistics - */ -function reporting_get_group_stats ($id_group = 0, $access = 'AR') { - global $config; - - $data = array (); - $data["monitor_checks"] = 0; - $data["monitor_not_init"] = 0; - $data["monitor_unknown"] = 0; - $data["monitor_ok"] = 0; - $data["monitor_bad"] = 0; // Critical + Unknown + Warning - $data["monitor_warning"] = 0; - $data["monitor_critical"] = 0; - $data["monitor_not_normal"] = 0; - $data["monitor_alerts"] = 0; - $data["monitor_alerts_fired"] = 0; - $data["monitor_alerts_fire_count"] = 0; - $data["total_agents"] = 0; - $data["total_alerts"] = 0; - $data["total_checks"] = 0; - $data["alerts"] = 0; - $data["agents_unknown"] = 0; - $data["monitor_health"] = 100; - $data["alert_level"] = 100; - $data["module_sanity"] = 100; - $data["server_sanity"] = 100; - $data["total_not_init"] = 0; - $data["monitor_non_init"] = 0; - $data["agent_ok"] = 0; - $data["agent_warning"] = 0; - $data["agent_critical"] = 0; - $data["agent_unknown"] = 0; - $data["agent_not_init"] = 0; - - $cur_time = get_system_time (); - - //Check for access credentials using check_acl. More overhead, much safer - if (!check_acl ($config["id_user"], $id_group, $access)) { - return $data; - } - - if ($id_group == 0) { - $id_group = array_keys( - users_get_groups($config['id_user'], $access, false)); - } - - // ----------------------------------------------------------------- - // Server processed stats. NOT realtime (taken from tgroup_stat) - // ----------------------------------------------------------------- - if ($config["realtimestats"] == 0) { - - if (!is_array($id_group)){ - $my_group = $id_group; - $id_group = array(); - $id_group[0] = $my_group; - } - - foreach ($id_group as $group) { - $group_stat = db_get_all_rows_sql ("SELECT * - FROM tgroup_stat, tgrupo - WHERE tgrupo.id_grupo = tgroup_stat.id_group - AND tgroup_stat.id_group = $group - ORDER BY nombre"); - - $data["monitor_checks"] += $group_stat[0]["modules"]; - $data["agent_not_init"] += $group_stat[0]["non-init"]; - $data["agent_unknown"] += $group_stat[0]["unknown"]; - $data["agent_ok"] += $group_stat[0]["normal"]; - $data["agent_warning"] += $group_stat[0]["warning"]; - $data["agent_critical"] += $group_stat[0]["critical"]; - $data["monitor_alerts"] += $group_stat[0]["alerts"]; - $data["monitor_alerts_fired"] += $group_stat[0]["alerts_fired"]; - $data["monitor_alerts_fire_count"] += $group_stat[0]["alerts_fired"]; - $data["total_checks"] += $group_stat[0]["modules"]; - $data["total_alerts"] += $group_stat[0]["alerts"]; - $data["total_agents"] += $group_stat[0]["agents"]; - $data["agents_unknown"] += $group_stat[0]["agents_unknown"]; - $data["utimestamp"] = $group_stat[0]["utimestamp"]; - - // This fields are not in database - $data["monitor_ok"] += (int) groups_get_normal_monitors($group); - $data["monitor_warning"] += (int) groups_get_warning_monitors($group); - $data["monitor_critical"] += (int) groups_get_critical_monitors($group); - $data["monitor_unknown"] += (int) groups_get_unknown_monitors($group); - $data["monitor_not_init"] += (int) groups_get_not_init_monitors($group); - } - - // ------------------------------------------------------------------- - // Realtime stats, done by PHP Console - // ------------------------------------------------------------------- - } - else { - - if (!is_array($id_group)) { - $my_group = $id_group; - $id_group = array(); - $id_group[0] = $my_group; - } - - // Store the groups where we are quering - $covered_groups = array(); - $group_array = array(); - foreach ($id_group as $group) { - $children = groups_get_childrens($group); - - //Show empty groups only if they have children with agents - //$group_array = array(); - - foreach ($children as $sub) { - // If the group is quering previously, we ingore it - if (!in_array($sub['id_grupo'],$covered_groups)) { - array_push($covered_groups, $sub['id_grupo']); - array_push($group_array, $sub['id_grupo']); - } - - } - - // Add id of this group to create the clause - // If the group is quering previously, we ingore it - if (!in_array($group,$covered_groups)) { - array_push($covered_groups, $group); - array_push($group_array, $group); - } - - // If there are not groups to query, we jump to nextone - - if (empty($group_array)) { - continue; - } - } - - 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); - - $no_tags_restricted_groups = $group_array; - foreach ($no_tags_restricted_groups as $k => $v) { - if (in_array($v, $tags_restricted_groups)) { - unset($no_tags_restricted_groups[$k]); - } - } - */ - - if (!empty($group_array)) { - // Get monitor NOT INIT, except disabled AND async modules - $data["monitor_not_init"] += (int) groups_get_not_init_monitors ($group_array, array(), array(), false, false, true); - - // Get monitor OK, except disabled and non-init - $data["monitor_ok"] += (int) groups_get_normal_monitors ($group_array, array(), array(), false, false, true); - - // Get monitor CRITICAL, except disabled and non-init - $data["monitor_critical"] += (int) groups_get_critical_monitors ($group_array, array(), array(), false, false, true); - - // Get monitor WARNING, except disabled and non-init - $data["monitor_warning"] += (int) groups_get_warning_monitors ($group_array, array(), array(), false, false, true); - - // Get monitor UNKNOWN, except disabled and non-init - $data["monitor_unknown"] += (int) groups_get_unknown_monitors ($group_array, array(), array(), false, false, true); - - // Get alerts configured, except disabled - $data["monitor_alerts"] += groups_monitor_alerts ($group_array) ; - - // Get alert configured currently FIRED, except disabled - $data["monitor_alerts_fired"] += groups_monitor_fired_alerts ($group_array); - - // Calculate totals using partial counts from above - - // Get TOTAL non-init modules, except disabled ones and async modules - $data["total_not_init"] += $data["monitor_not_init"]; - - // Get TOTAL agents in a group - $data["total_agents"] += (int) groups_get_total_agents ($group_array, array(), array(), false, false, true); - - // Get Agents OK - $data["agent_ok"] += (int) groups_get_normal_agents ($group_array, array(), array(), false, false, true); - - // Get Agents Warning - $data["agent_warning"] += (int) groups_get_warning_agents ($group_array, array(), array(), false, false, true); - - // Get Agents Critical - $data["agent_critical"] += (int) groups_get_critical_agents ($group_array, array(), array(), false, false, true); - - // Get Agents Unknown - $data["agent_unknown"] += (int) groups_get_unknown_agents ($group_array, array(), array(), false, false, true); - - // Get Agents Not init - $data["agent_not_init"] += (int) groups_get_not_init_agents ($group_array, array(), array(), false, false, true); - } - - // 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"]; - - // Calculate not_normal monitors - $data["monitor_not_normal"] += $data["monitor_checks"] - $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"]; - - /* - Monitor health (percentage) - Data health (percentage) - Global health (percentage) - Module sanity (percentage) - Alert level (percentage) - - Server Sanity 0% Uninitialized modules - - */ - } - - if ($data["monitor_unknown"] > 0 && $data["monitor_checks"] > 0) { - $data["monitor_health"] = format_numeric (100 - ($data["monitor_not_normal"] / ($data["monitor_checks"] / 100)), 1); - } - else { - $data["monitor_health"] = 100; - } - - if ($data["monitor_not_init"] > 0 && $data["monitor_checks"] > 0) { - $data["module_sanity"] = format_numeric (100 - ($data["monitor_not_init"] / ($data["monitor_checks"] / 100)), 1); - } - else { - $data["module_sanity"] = 100; - } - - if (isset($data["alerts"])) { - if ($data["monitor_alerts_fired"] > 0 && $data["alerts"] > 0) { - $data["alert_level"] = format_numeric (100 - ($data ["monitor_alerts_fired"] / ($data["alerts"] / 100)), 1); - } - else { - $data["alert_level"] = 100; - } - } - else { - $data["alert_level"] = 100; - $data["alerts"] = 0; - } - - $data["monitor_bad"] = $data["monitor_critical"] + $data["monitor_warning"]; - - if ($data["monitor_bad"] > 0 && $data["monitor_checks"] > 0) { - $data["global_health"] = format_numeric (100 - ($data["monitor_bad"] / ($data["monitor_checks"] / 100)), 1); - } - else { - $data["global_health"] = 100; - } - - $data["server_sanity"] = format_numeric (100 - $data["module_sanity"], 1); - - - $data['alert_fired'] = 0; - if ($data["monitor_alerts_fired"] > 0) { - $data['alert_fired'] = 1; - } - - - if ($data["monitor_critical"] > 0) { - $data['status'] = 'critical'; - } - elseif ($data["monitor_warning"] > 0) { - $data['status'] = 'warning'; - } - elseif (($data["monitor_unknown"] > 0) || ($data["agents_unknown"] > 0)) { - $data['status'] = 'unknown'; - } - elseif ($data["monitor_ok"] > 0) { - $data['status'] = 'ok'; - } - elseif ($data["agent_not_init"] > 0) { - $data['status'] = 'not_init'; - } - else { - $data['status'] = 'none'; - } - - return ($data); -} - - -/** - * Get an event reporting table. - * - * It construct a table object with all the events happened in a group - * during a period of time. - * - * @param int Group id to get the report. - * @param int Period of time to get the report. - * @param int Beginning date of the report - * @param int Flag to return or echo the report table (echo by default). - * - * @return object A table object - */ -function reporting_event_reporting ($id_group, $period, $date = 0, $return = false) { - if (empty ($date)) { - $date = get_system_time (); - } - elseif (!is_numeric ($date)) { - $date = strtotime ($date); - } - - $table->data = array (); - $table->head = array (); - $table->head[0] = __('Status'); - $table->head[1] = __('Event name'); - $table->head[2] = __('User ID'); - $table->head[3] = __('Timestamp'); - - $events = events_get_group_events ($id_group, $period, $date); - if (empty ($events)) { - $events = array (); - } - foreach ($events as $event) { - $data = array (); - if ($event["estado"] == 0) - $data[0] = html_print_image("images/dot_red.png", true); - else - $data[0] = html_print_image("images/dot_green.png", true); - $data[1] = $event['evento']; - $data[2] = $event['id_usuario'] != '0' ? $event['id_usuario'] : ''; - $data[3] = $event["timestamp"]; - array_push ($table->data, $data); - } - - if (empty ($return)) - html_print_table ($table); - - return $table; -} - -/** - * Get a table report from a alerts fired array. - * - * @param array Alerts fired array. - * @see function get_alerts_fired () - * - * @return object A table object with a report of the fired alerts. - */ -function reporting_get_fired_alerts_table ($alerts_fired) { - $agents = array (); - global $config; - - require_once ($config["homedir"].'/include/functions_alerts.php'); - - foreach (array_keys ($alerts_fired) as $id_alert) { - $alert_module = alerts_get_alert_agent_module ($id_alert); - $template = alerts_get_alert_template ($id_alert); - - /* Add alerts fired to $agents_fired_alerts indexed by id_agent */ - $id_agent = db_get_value ('id_agente', 'tagente_modulo', - 'id_agente_modulo', $alert_module['id_agent_module']); - if (!isset ($agents[$id_agent])) { - $agents[$id_agent] = array (); - } - array_push ($agents[$id_agent], array ($alert_module, $template)); - } - - $table->data = array (); - $table->head = array (); - $table->head[0] = __('Agent'); - $table->head[1] = __('Alert description'); - $table->head[2] = __('Times fired'); - $table->head[3] = __('Priority'); - - foreach ($agents as $id_agent => $alerts) { - $data = array (); - foreach ($alerts as $tuple) { - $alert_module = $tuple[0]; - $template = $tuple[1]; - if (! isset ($data[0])) - $data[0] = agents_get_name ($id_agent); - else - $data[0] = ''; - $data[1] = $template['name']; - $data[2] = $alerts_fired[$alert_module['id']]; - $data[3] = get_alert_priority ($alert_module['priority']); - array_push ($table->data, $data); - } - } - - return $table; -} - -/** - * Get a report for alerts of agent. - * - * It prints the numbers of alerts defined, fired and not fired of agent. - * - * @param int $id_agent Agent to get info of the alerts. - * @param int $period Period of time of the desired alert report. - * @param int $date Beggining date of the report (current date by default). - * @param bool $return Flag to return or echo the report (echo by default). - * @param bool Flag to return the html or table object, by default html. - * - * @return mixed A table object (XHTML) or object table is false the html. - */ -function reporting_alert_reporting_agent ($id_agent, $period = 0, $date = 0, $return = true, $html = true) { - if (!is_numeric ($date)) { - $date = strtotime ($date); - } - if (empty ($date)) { - $date = get_system_time (); - } - $table->width = '99%'; - $table->data = array (); - $table->head = array (); - $table->head[0] = __('Module'); - $table->head[1] = __('Template'); - $table->head[2] = __('Actions'); - $table->head[3] = __('Fired'); - - $alerts = agents_get_alerts ($id_agent); - - if (isset($alerts['simple'])) { - $i = 0; - if ($alerts['simple'] === false) - $alerts['simple'] = array(); - - foreach ($alerts['simple'] as $alert) { - $data = array(); - $data[0] = db_get_value_filter('nombre', 'tagente_modulo', array('id_agente_modulo' => $alert['id_agent_module'])); - $data[1] = db_get_value_filter('name', 'talert_templates', array('id' => $alert['id_alert_template'])); - $actions = db_get_all_rows_sql('SELECT name - FROM talert_actions - WHERE id IN (SELECT id_alert_action - FROM talert_template_module_actions - WHERE id_alert_template_module = ' . $alert['id'] . ');'); - $data[2] = ''; - - $data[3] = ''; - - if ($alert['disabled']) { - $table->rowstyle[$i] = 'color: grey; font-style: italic;'; - } - $i++; - - array_push ($table->data, $data); - } - } - - if ($html) { - return html_print_table ($table, $return); - } - else { - return $table; - } -} - -/** - * Get a report for alerts of group. - * - * It prints the numbers of alerts defined, fired and not fired of agent. - * - * @param int $id_agent_module Module to get info of the alerts. - * @param int $period Period of time of the desired alert report. - * @param int $date Beggining date of the report (current date by default). - * @param bool $return Flag to return or echo the report (echo by default). - * @param bool Flag to return the html or table object, by default html. - * - * @return mixed A table object (XHTML) or object table is false the html. - */ -function reporting_alert_reporting_group ($id_group, $period = 0, $date = 0, $return = true, $html = true) { - if (!is_numeric ($date)) { - $date = strtotime ($date); - } - if (empty ($date)) { - $date = get_system_time (); - } - - $table->width = '99%'; - $table->data = array (); - $table->head = array (); - - $table->head[0] = __('Agent'); - $table->head[1] = __('Module'); - $table->head[2] = __('Template'); - $table->head[3] = __('Actions'); - $table->head[4] = __('Fired'); - - if ($id_group == 0) { - $alerts = db_get_all_rows_sql(' - SELECT * - FROM talert_template_modules - WHERE disabled = 0 - AND id_agent_module IN ( - SELECT id_agente_modulo - FROM tagente_modulo)'); - } - else { - $alerts = db_get_all_rows_sql(' - SELECT * - FROM talert_template_modules - WHERE disabled = 0 - AND id_agent_module IN ( - SELECT id_agente_modulo - FROM tagente_modulo - WHERE id_agente IN ( - SELECT id_agente - FROM tagente WHERE id_grupo = ' . $id_group . '))'); - } - - if ($alerts === false) { - $alerts = array(); - } - - $i = 0; - foreach ($alerts as $alert) { - $data = array(); - - $data[] = io_safe_output( - agents_get_name( - agents_get_agent_id_by_module_id( - $alert['id_agent_module']))); - - $data[] = io_safe_output( - modules_get_agentmodule_name($alert['id_agent_module'])); - - $data[] = db_get_value_filter('name', - 'talert_templates', - array('id' => $alert['id_alert_template'])); - - $actions = db_get_all_rows_sql('SELECT name - FROM talert_actions - WHERE id IN (SELECT id_alert_action - FROM talert_template_module_actions - WHERE id_alert_template_module = ' . $alert['id_agent_module'] . ');'); - $list = ''; - $data[] = $list; - - $list = ''; - - if ($alert['disabled']) { - $table->rowstyle[$i] = 'color: grey; font-style: italic;'; - } - $i++; - $data[] = $list; - - array_push ($table->data, $data); - } - - if ($html) { - return html_print_table ($table, $return); - } - else { - return $table; - } -} - -/** - * Get a report for alerts of module. - * - * It prints the numbers of alerts defined, fired and not fired of agent. - * - * @param int $id_agent_module Module to get info of the alerts. - * @param int $period Period of time of the desired alert report. - * @param int $date Beggining date of the report (current date by default). - * @param bool $return Flag to return or echo the report (echo by default). - * @param bool Flag to return the html or table object, by default html. - * - * @return mixed A table object (XHTML) or object table is false the html. - */ -function reporting_alert_reporting_module ($id_agent_module, $period = 0, $date = 0, $return = true, $html = true) { - if (!is_numeric ($date)) { - $date = strtotime ($date); - } - if (empty ($date)) { - $date = get_system_time (); - } - - $table->width = '99%'; - $table->data = array (); - $table->head = array (); - $table->head[1] = __('Template'); - $table->head[2] = __('Actions'); - $table->head[3] = __('Fired'); - - - $alerts = db_get_all_rows_sql('SELECT *, t1.id as id_alert_template_module - FROM talert_template_modules AS t1 - INNER JOIN talert_templates AS t2 ON t1.id_alert_template = t2.id - WHERE id_agent_module = ' . $id_agent_module); - - if ($alerts === false) { - $alerts = array(); - } - - $i = 0; - foreach ($alerts as $alert) { - $data = array(); - $data[1] = db_get_value_filter('name', 'talert_templates', array('id' => $alert['id_alert_template'])); - $actions = db_get_all_rows_sql('SELECT name - FROM talert_actions - WHERE id IN (SELECT id_alert_action - FROM talert_template_module_actions - WHERE id_alert_template_module = ' . $alert['id_alert_template_module'] . ');'); - $data[2] = ''; - - $data[3] = ''; - - if ($alert['disabled']) { - $table->rowstyle[$i] = 'color: grey; font-style: italic;'; - } - $i++; - - array_push ($table->data, $data); - } - - if ($html) { - return html_print_table ($table, $return); - } - else { - return $table; - } -} - -/** - * Get a report for alerts in a group of agents. - * - * It prints the numbers of alerts defined, fired and not fired in a group. - * It also prints all the alerts that were fired grouped by agents. - * - * @param int $id_group Group to get info of the alerts. - * @param int $period Period of time of the desired alert report. - * @param int $date Beggining date of the report (current date by default). - * @param bool $return Flag to return or echo the report (echo by default). - * - * @return string - */ -function reporting_alert_reporting ($id_group, $period = 0, $date = 0, $return = false) { - global $config; - - $output = ''; - $alerts = get_group_alerts ($id_group); - $alerts_fired = get_alerts_fired ($alerts, $period, $date); - - $fired_percentage = 0; - if (sizeof ($alerts) > 0) - $fired_percentage = round (sizeof ($alerts_fired) / sizeof ($alerts) * 100, 2); - $not_fired_percentage = 100 - $fired_percentage; - - $data = array (); - $data[__('Alerts fired')] = $fired_percentage; - $data[__('Alerts not fired')] = $not_fired_percentage; - - $output .= pie3d_graph(false, $data, 280, 150, - __("other"), - ui_get_full_url(false, false, false, false) . '/', - ui_get_full_url(false, false, false, false) . "/images/logo_vertical_water.png", - $config['fontpath'], $config['font_size']); - - $output .= ''.__('Alerts fired').': '.sizeof ($alerts_fired).'
'; - $output .= ''.__('Total alerts monitored').': '.sizeof ($alerts).'
'; - - if (! sizeof ($alerts_fired)) { - if (!$return) - echo $output; - - return $output; - } - $table = reporting_get_fired_alerts_table ($alerts_fired); - $table->width = '100%'; - $table->class = 'databox'; - $table->size = array (); - $table->size[0] = '100px'; - $table->style = array (); - $table->style[0] = 'font-weight: bold'; - - $output .= html_print_table ($table, true); - - if (!$return) - echo $output; - - return $output; -} - -/** - * Get a report for monitors modules in a group of agents. - * - * It prints the numbers of monitors defined, showing those which went up and down, in a group. - * It also prints all the down monitors in the group. - * - * @param int $id_group Group to get info of the monitors. - * @param int $period Period of time of the desired monitor report. - * @param int $date Beginning date of the report in UNIX time (current date by default). - * @param bool $return Flag to return or echo the report (by default). - * - * @return string - */ -function reporting_monitor_health ($id_group, $period = 0, $date = 0, $return = false) { - if (empty ($date)) //If date is 0, false or empty - $date = get_system_time (); - - $datelimit = $date - $period; - $output = ''; - - $monitors = modules_get_monitors_in_group ($id_group); - if (empty ($monitors)) //If monitors has returned false or an empty array - return; - $monitors_down = modules_get_monitors_down ($monitors, $period, $date); - $down_percentage = round (count ($monitors_down) / count ($monitors) * 100, 2); - $not_down_percentage = 100 - $down_percentage; - - $output .= ''.__('Total monitors').': '.count ($monitors).'
'; - $output .= ''.__('Monitors down on period').': '.count ($monitors_down).'
'; - - $table = reporting_get_monitors_down_table ($monitors_down); - $table->width = '100%'; - $table->class = 'databox'; - $table->size = array (); - $table->size[0] = '100px'; - $table->style = array (); - $table->style[0] = 'font-weight: bold'; - - $table->size = array (); - $table->size[0] = '100px'; - - $output .= html_print_table ($table, true); - - $data = array(); - $data[__('Monitors OK')] = $down_percentage; - $data[__('Monitors BAD')] = $not_down_percentage; - - $output .= pie3d_graph(false, $data, 280, 150, - __("other"), - ui_get_full_url(false, false, false, false) . '/', - ui_get_full_url(false, false, false, false) . "/images/logo_vertical_water.png", - $config['fontpath'], $config['font_size']); - - if (!$return) - echo $output; - - return $output; -} - -/** - * Get a report table with all the monitors down. - * - * @param array An array with all the monitors down - * @see function modules_get_monitors_down() - * - * @return object A table object with a monitors down report. - */ -function reporting_get_monitors_down_table ($monitors_down) { - $table->data = array (); - $table->head = array (); - $table->head[0] = __('Agent'); - $table->head[1] = __('Monitor'); - - $agents = array (); - if ($monitors_down) { - foreach ($monitors_down as $monitor) { - /* Add monitors fired to $agents_fired_alerts indexed by id_agent */ - $id_agent = $monitor['id_agente']; - if (!isset ($agents[$id_agent])) { - $agents[$id_agent] = array (); - } - array_push ($agents[$id_agent], $monitor); - - $monitors_down++; - } - foreach ($agents as $id_agent => $monitors) { - $data = array (); - foreach ($monitors as $monitor) { - if (! isset ($data[0])) - $data[0] = agents_get_name ($id_agent); - else - $data[0] = ''; - if ($monitor['descripcion'] != '') { - $data[1] = $monitor['descripcion']; - } - else { - $data[1] = $monitor['nombre']; - } - array_push ($table->data, $data); - } - } - } - - return $table; -} - -/** - * Get a general report of a group of agents. - * - * It shows the number of agents and no more things right now. - * - * @param int Group to get the report - * @param bool Flag to return or echo the report (by default). - * - * @return HTML string with group report - */ -function reporting_print_group_reporting ($id_group, $return = false) { - $agents = agents_get_group_agents ($id_group, false, "none"); - $output = '' . - sprintf(__('Agents in group: %s'), count($agents)) . - '
'; - - if ($return === false) - echo $output; - - return $output; -} - -/** - * Get a report table of the fired alerts group by agents. - * - * @param int Agent id to generate the report. - * @param int Period of time of the report. - * @param int Beginning date of the report in UNIX time (current date by default). - * - * @return object A table object with the alert reporting.. - */ -function reporting_get_agent_alerts_table ($id_agent, $period = 0, $date = 0) { - global $config; - $table->data = array (); - $table->head = array (); - $table->head[0] = __('Type'); - $table->head[1] = __('Description'); - $table->head[2] = __('Value'); - $table->head[3] = __('Threshold'); - $table->head[4] = __('Last fired'); - $table->head[5] = __('Times fired'); - - require_once ($config["homedir"].'/include/functions_alerts.php'); - - $alerts = agents_get_alerts ($id_agent); - - foreach ($alerts['simple'] as $alert) { - $fires = get_alert_fires_in_period ($alert['id'], $period, $date); - if (! $fires) { - continue; - } - - $template = alerts_get_alert_template ($alert['id_alert_template']); - $data = array (); - $data[0] = alerts_get_alert_templates_type_name ($template['type']); - $data[1] = $template['name']; - - switch ($template['type']) { - case 'regex': - if ($template['matches_value']) - $data[2] = '≃ "'.$template['value'].'"'; - else - $data[2] = '≄ "'.$template['value'].'"'; + switch ($config["dbtype"]) { + case "mysql": + $contents = db_get_all_rows_field_filter ("treport_content", + "id_report", $id_report, "`order`"); break; - case 'equal': - case 'not_equal': - $data[2] = $template['value']; - + case "postgresql": + $contents = db_get_all_rows_field_filter ("treport_content", + "id_report", $id_report, '"order"'); break; - case 'max-min': - $data[2] = __('Min.').': '.$template['min_value']. ' '; - $data[2] .= __('Max.').': '.$template['max_value']. ' '; - + case "oracle": + $contents = db_get_all_rows_field_filter ("treport_content", + "id_report", $id_report, '"order"'); break; - case 'max': - $data[2] = $template['max_value']; - - break; - case 'min': - $data[2] = $template['min_value']; - - break; - } - $data[3] = $template['time_threshold']; - $data[4] = ui_print_timestamp (get_alert_last_fire_timestamp_in_period ($alert['id'], $period, $date), true); - $data[5] = $fires; - - array_push ($table->data, $data); } - - return $table; -} - -/** - * Get a report of monitors in an agent. - * - * @param int Agent id to get the report - * @param int Period of time of the report. - * @param int Beginning date of the report in UNIX time (current date by default). - * - * @return object A table object with the report. - */ -function reporting_get_agent_monitors_table ($id_agent, $period = 0, $date = 0) { - $n_a_string = __('N/A').'(*)'; - $table->head = array (); - $table->head[0] = __('Monitor'); - $table->head[1] = __('Last failure'); - $table->data = array (); - $monitors = modules_get_monitors_in_agent ($id_agent); - - if ($monitors === false) { - return $table; - } - foreach ($monitors as $monitor) { - $downs = modules_get_monitor_downs_in_period ($monitor['id_agente_modulo'], $period, $date); - if (! $downs) { - continue; - } - $data = array (); - if ($monitor['descripcion'] != $n_a_string && $monitor['descripcion'] != '') - $data[0] = $monitor['descripcion']; - else - $data[0] = $monitor['nombre']; - $data[1] = modules_get_last_down_timestamp_in_period ($monitor['id_agente_modulo'], $period, $date); - array_push ($table->data, $data); - } - - return $table; -} - -/** - * Get a report of all the modules in an agent. - * - * @param int Agent id to get the report. - * @param int Period of time of the report - * @param int Beginning date of the report in UNIX time (current date by default). - * - * @return object - */ -function reporting_get_agent_modules_table ($id_agent, $period = 0, $date = 0) { - $table->data = array (); - $n_a_string = __('N/A').'(*)'; - $modules = agents_get_modules ($id_agent, array ("nombre", "descripcion")); - if ($modules === false) - $modules = array(); - $data = array (); - - foreach ($modules as $module) { - if ($module['descripcion'] != $n_a_string && $module['descripcion'] != '') - $data[0] = $module['descripcion']; - else - $data[0] = $module['nombre']; - array_push ($table->data, $data); - } - - return $table; -} - -/** - * Get a detailed report of an agent - * - * @param int Agent to get the report. - * @param int Period of time of the desired report. - * @param int Beginning date of the report in UNIX time (current date by default). - * @param bool Flag to return or echo the report (by default). - * - * @return string - */ -function reporting_get_agent_detailed ($id_agent, $period = 0, $date = 0, $return = false) { - $output = ''; - $n_a_string = __('N/A(*)'); - - /* Show modules in agent */ - $output .= '
'; - $output .= '

' . - __('Agent') . ' - ' . agents_get_name ($id_agent) . '

'; - $output .= '

'.__('Modules').'

'; - $table_modules = reporting_get_agent_modules_table ($id_agent, $period, $date); - $table_modules->width = '99%'; - $output .= html_print_table ($table_modules, true); - - /* Show alerts in agent */ - $table_alerts = reporting_get_agent_alerts_table ($id_agent, $period, $date); - $table_alerts->width = '99%'; - if (sizeof ($table_alerts->data)) { - $output .= '

'.__('Alerts').'

'; - $output .= html_print_table ($table_alerts, true); - } - - /* Show monitor status in agent (if any) */ - $table_monitors = reporting_get_agent_monitors_table ($id_agent, $period, $date); - if (sizeof ($table_monitors->data) == 0) { - $output .= '
'; - if (! $return) - echo $output; - return $output; - } - $table_monitors->width = '99%'; - $table_monitors->align = array (); - $table_monitors->align[1] = 'right'; - $table_monitors->size = array (); - $table_monitors->align[1] = '10%'; - $output .= '

'.__('Monitors').'

'; - $output .= html_print_table ($table_monitors, true); - - $output .= ''; - - if (! $return) - echo $output; - return $output; -} - -/** - * Get a detailed report of agents in a group. - * - * @param mixed Group(s) to get the report - * @param int Period - * @param int Timestamp to start from - * @param bool Flag to return or echo the report (by default). - * - * @return string - */ -function reporting_agents_get_group_agents_detailed ($id_group, $period = 0, $date = 0, $return = false) { - $agents = agents_get_group_agents ($id_group, false, "none"); - - $output = ''; - foreach ($agents as $agent_id => $agent_name) { - $output .= reporting_get_agent_detailed ($agent_id, $period, $date, true); - } - - if ($return === false) - echo $output; - - return $output; -} - - -/** - * Get a detailed report of summarized events per agent - * - * It construct a table object with all the grouped events happened in an agent - * during a period of time. - * - * @param mixed Agent id(s) to get the report from. - * @param int Period of time (in seconds) to get the report. - * @param int Beginning date (unixtime) of the report - * @param bool Flag to return or echo the report table (echo by default). - * - * @return A table object (XHTML) - */ -function reporting_get_agents_detailed_event ($id_agents, $period = 0, - $date = 0, $return = false, $filter_event_validated = false, - $filter_event_critical = false, $filter_event_warning = false, $filter_event_no_validated = false) { - - global $config; - - $id_agents = (array)safe_int ($id_agents, 1); - - if (!is_numeric ($date)) { - $date = strtotime ($date); - } - if (empty ($date)) { - $date = get_system_time (); - } - - $table->width = '99%'; - - $table->align = array(); - $table->align[0] = 'center'; - $table->align[1] = 'center'; - $table->align[3] = 'center'; - - $table->data = array (); - - $table->head = array (); - $table->head[0] = __('Status'); - $table->head[1] = __('Count'); - $table->head[2] = __('Name'); - $table->head[3] = __('Type'); - $table->head[4] = __('Criticity'); - $table->head[5] = __('Val. by'); - $table->head[6] = __('Timestamp'); - - $events = array (); - - foreach ($id_agents as $id_agent) { - $event = events_get_agent ($id_agent, - (int)$period, - (int)$date, - $filter_event_validated, $filter_event_critical, - $filter_event_warning, $filter_event_no_validated); - - if (!empty ($event)) { - array_push ($events, $event); - } - } - - if ($events) { - $note = ''; - if (count($events) >= 1000) { - $note .= '* ' . __('Maximum of events shown') . ' (1000)
'; - } - foreach ($events as $eventRow) { - foreach ($eventRow as $k => $event) { - //First pass along the class of this row - $table->cellclass[$k][1] = $table->cellclass[$k][2] = - $table->cellclass[$k][4] = $table->cellclass[$k][5] = - $table->cellclass[$k][6] = - 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, - "title" => $title_st)); - - $data[] = $event['event_rep']; - - $data[] = ui_print_truncate_text( - io_safe_output($event['evento']), - 140, false, true); - //$data[] = $event['event_type']; - $data[] = events_print_type_img ($event["event_type"], true); - - $data[] = get_priority_name ($event['criticity']); - if (empty($event['id_usuario']) && $event['estado'] == EVENT_VALIDATE) { - $data[] = '' . __('System') . ''; - } - else { - $user_name = db_get_value ('fullname', 'tusuario', 'id_user', $event['id_usuario']); - $data[] = io_safe_output($user_name); - } - $data[] = '' . - date($config['date_format'], $event['timestamp_rep']) . ''; - array_push ($table->data, $data); - } - } - } - - if ($events) - return html_print_table ($table, $return) . $note; -} - -/** - * Gets a detailed reporting of groups's events. - * - * @param unknown_type $id_group Id of the group. - * @param unknown_type $period Time period of the report. - * @param unknown_type $date Date of the report. - * @param unknown_type $return Whether to return or not. - * @param unknown_type $html Whether to return HTML code or not. - * - * @return string Report of groups's events - */ -function reporting_get_group_detailed_event ($id_group, $period = 0, - $date = 0, $return = false, $html = true, - $filter_event_validated = false, $filter_event_critical = false, - $filter_event_warning = false, $filter_event_no_validated = false) { - - global $config; - - if (!is_numeric ($date)) { - $date = strtotime ($date); - } - if (empty ($date)) { - $date = get_system_time (); - } - - $table->width = '99%'; - - $table->align = array(); - $table->align[0] = 'center'; - $table->align[2] = 'center'; - - $table->data = array (); - - $table->head = array (); - $table->head[0] = __('Status'); - $table->head[1] = __('Name'); - $table->head[2] = __('Type'); - $table->head[3] = __('Agent'); - $table->head[4] = __('Criticity'); - $table->head[5] = __('Val. by'); - $table->head[6] = __('Timestamp'); - - $events = events_get_group_events($id_group, $period, $date, - $filter_event_validated, $filter_event_critical, - $filter_event_warning, $filter_event_no_validated); - - if ($events) { - $note = ''; - if (count($events) >= 1000) { - $note .= '* ' . __('Maximum of events shown') . ' (1000)
'; - } - foreach ($events as $k => $event) { - //First pass along the class of this row - $table->cellclass[$k][1] = $table->cellclass[$k][3] = - $table->cellclass[$k][4] = $table->cellclass[$k][5] = - $table->cellclass[$k][6] = - 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, - "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['id_agente'])) - $data[] = agents_get_name($event['id_agente']); - else - $data[] = __('Pandora System'); - $data[] = get_priority_name ($event['criticity']); - if (empty($event['id_usuario']) && $event['estado'] == EVENT_VALIDATE) { - $data[] = '' . __('System') . ''; - } - else { - $user_name = db_get_value ('fullname', 'tusuario', 'id_user', $event['id_usuario']); - $data[] = io_safe_output($user_name); - } - $data[] = '' . - date($config['date_format'], $event['timestamp_rep']) . - ''; - array_push ($table->data, $data); - } - - if ($html) { - return html_print_table ($table, $return) . $note; - } - else { - return $table; - } - } - else { - return false; - } -} - - -/** - * Get a detailed report of summarized events per agent - * - * It construct a table object with all the grouped events happened in an agent - * during a period of time. - * - * @param mixed Module id to get the report from. - * @param int Period of time (in seconds) to get the report. - * @param int Beginning date (unixtime) of the report - * @param bool Flag to return or echo the report table (echo by default). - * @param bool Flag to return the html or table object, by default html. - * - * @return mixed A table object (XHTML) or object table is false the html. - */ -function reporting_get_module_detailed_event ($id_modules, $period = 0, $date = 0, $return = false, $html = true) { - global $config; - - $id_modules = (array)safe_int ($id_modules, 1); - - if (!is_numeric ($date)) { - $date = strtotime ($date); - } - if (empty ($date)) { - $date = get_system_time (); - } - - $table->width = '99%'; - $table->data = array (); - $table->head = array (); - $table->head[0] = __('Status'); - $table->head[1] = __('Event name'); - $table->head[2] = __('Event type'); - $table->head[3] = __('Criticity'); - $table->head[4] = __('Count'); - $table->head[5] = __('Timestamp'); - $table->style[0] = 'text-align: center;'; - $table->style[4] = 'text-align: center;'; - - $events = array (); - - foreach ($id_modules as $id_module) { - $event = events_get_module ($id_module, (int) $period, (int) $date); - if (!empty ($event)) { - array_push ($events, $event); - } - } - - if ($events) { - $note = ''; - if (count($events) >= 1000) { - $note .= '* ' . __('Maximum of events shown') . ' (1000)
'; - } - foreach ($events as $eventRow) { - foreach ($eventRow as $k => $event) { - //$k = count($table->data); - $table->cellclass[$k][1] = $table->cellclass[$k][2] = - $table->cellclass[$k][3] = $table->cellclass[$k][4] = - $table->cellclass[$k][5] = 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[0] = html_print_image ($img_st, true, - array ("class" => "image_status", - "width" => 16, - "title" => $title_st, - "id" => 'status_img_' . $event["id_evento"])); - - $data[1] = io_safe_output($event['evento']); - $data[2] = $event['event_type']; - $data[3] = get_priority_name ($event['criticity']); - $data[4] = $event['event_rep']; - $data[5] = date($config['date_format'], $event['timestamp_rep']); - array_push ($table->data, $data); - } - } - - if ($html) { - return html_print_table ($table, $return) . $note; - } - else { - return $table; - } - } - else { - return false; - } -} - -/** - * Get a detailed report of the modules of the agent - * - * @param int $id_agent Agent id to get the report for. - * @param string $filter filter for get partial modules. - * - * @return array An array - */ -function reporting_get_agent_module_info ($id_agent, $filter = false) { - global $config; - - $return = array (); - $return["last_contact"] = 0; //Last agent contact - $return["status"] = STATUS_AGENT_NO_DATA; - $return["status_img"] = ui_print_status_image (STATUS_AGENT_NO_DATA, __('Agent without data'), true); - $return["alert_status"] = "notfired"; - $return["alert_value"] = STATUS_ALERT_NOT_FIRED; - $return["alert_img"] = ui_print_status_image (STATUS_ALERT_NOT_FIRED, __('Alert not fired'), true); - $return["agent_group"] = agents_get_agent_group ($id_agent); - - if (!check_acl ($config["id_user"], $return["agent_group"], "AR")) { + if ($contents === false) { return $return; } - if ($filter != '') { - $filter = 'AND '; - } + $report["group_name"] = groups_get_name ($report['id_group']); - $filter = 'disabled = 0'; - - $modules = agents_get_modules($id_agent, false, $filter, true, false); - - if ($modules === false) { - return $return; - } - - $now = get_system_time (); - - // Get modules status for this agent - - $agent = db_get_row ("tagente", "id_agente", $id_agent); + return $return; +} - $return["total_count"] = $agent["total_count"]; - $return["normal_count"] = $agent["normal_count"]; - $return["warning_count"] = $agent["warning_count"]; - $return["critical_count"] = $agent["critical_count"]; - $return["unknown_count"] = $agent["unknown_count"]; - $return["fired_count"] = $agent["fired_count"]; - $return["notinit_count"] = $agent["notinit_count"]; - - if ($return["total_count"] > 0) { - if ($return["critical_count"] > 0) { - $return["status"] = STATUS_AGENT_CRITICAL; - $return["status_img"] = ui_print_status_image (STATUS_AGENT_CRITICAL, __('At least one module in CRITICAL status'), true); - } - else if ($return["warning_count"] > 0) { - $return["status"] = STATUS_AGENT_WARNING; - $return["status_img"] = ui_print_status_image (STATUS_AGENT_WARNING, __('At least one module in WARNING status'), true); - } - else if ($return["unknown_count"] > 0) { - $return["status"] = STATUS_AGENT_DOWN; - $return["status_img"] = ui_print_status_image (STATUS_AGENT_DOWN, __('At least one module is in UKNOWN status'), true); +function reporting_simple_graph($id_report, $id_report_item, $type = 'dinamic') { + global $config; + + $return = array(); + + $content = db_get_row('treport_content_item', 'id', $id_report_item); + if (empty($content['name'])) { + $content['name'] = __('Simple graph'); + } + + $module_name = io_safe_output( + modules_get_agentmodule_name($content['id_agent_module'])); + $agent_name = io_safe_output( + modules_get_agentmodule_agent_name ($content['id_agent_module'])); + + + + + $return['title'] = $content['name']; + $return['subtitle'] = $agent_name . " - " . $module_name; + $return["description"] = $content["description"]; + $return["date"] = reporting_get_date_text($id_report, $id_report_item); + + // Get chart + switch ($type) { + case 'dinamic': + break; + case 'static': + break; + case 'data': + break; + } + + return reporting_check_structure_content($return); +} + +function reporting_get_date_text($id_report, $id_report_item) { + global $config; + + $return = array(); + $return['date'] = ""; + $return['period'] = ""; + $return['from'] = ""; + $return['to'] = ""; + + $report = db_get_row('treport_content_item', 'id', $id_report_item); + $content = db_get_row('treport', 'id_report', $id_report); + + if ($content['period'] == 0) { + $es = json_decode($content['external_source'], true); + if ($es['date'] == 0) { + $return['date'] = __('Last data'); } else { - $return["status"] = STATUS_AGENT_OK; - $return["status_img"] = ui_print_status_image (STATUS_AGENT_OK, __('All Monitors OK'), true); + $return['date'] = date($config["date_format"], $es['date']); } } - - //Alert not fired is by default - if ($return["fired_count"] > 0) { - $return["alert_status"] = "fired"; - $return["alert_img"] = ui_print_status_image (STATUS_ALERT_FIRED, __('Alert fired'), true); - $return["alert_value"] = STATUS_ALERT_FIRED; - } - elseif (groups_give_disabled_group ($return["agent_group"])) { - $return["alert_status"] = "disabled"; - $return["alert_value"] = STATUS_ALERT_DISABLED; - $return["alert_img"] = ui_print_status_image (STATUS_ALERT_DISABLED, __('Alert disabled'), true); + else { + $return['period'] = human_time_description_raw ($content['period']); + $return['from'] = date($config["date_format"], $report["datetime"] - $content['period']); + $return['from'] = date($config["date_format"], $report["datetime"]); } return $return; } /** - * This is the callback sorting function for SLA values descending - * - * @param array $a Array element 1 to compare - * @param array $b Array element 2 to compare - * + * Check the common items exits */ -function sla_value_desc_cmp($a, $b) { - // This makes 'Unknown' values the lastest - if (preg_match('/^(.)*Unknown(.)*$/', $a[5])) - $a[6] = -1; - - if (preg_match('/^(.)*Unknown(.)*$/', $b[5])) - $b[6] = -1; - - return ($a[6] < $b[6])? 1 : 0; -} - -/** - * This is the callback sorting function for SLA values ascending - * - * @param array $a Array element 1 to compare - * @param array $b Array element 2 to compare - * - */ -function sla_value_asc_cmp($a, $b) { - // This makes 'Unknown' values the lastest - if (preg_match('/^(.)*Unknown(.)*$/', $a[5])) - $a[6] = -1; - - if (preg_match('/^(.)*Unknown(.)*$/', $b[5])) - $b[6] = -1; - - return ($a[6] > $b[6])? 1 : 0; -} - -/** - * Make the header for each content. - */ -function reporting_header_content($mini, $content, $report, &$table, $title = false, $name = false, $period = false) { - global $config; - - if ($mini) { - $sizh = ''; - $sizhfin = ''; - } - else { - $sizh = '

'; - $sizhfin = '

'; - } - - $data = array(); - - $count_empty = 0; - - if ($title !== false) { - $data[] = $sizh . $title . $sizhfin; - } - else $count_empty++; - - if ($name !== false) { - $data[] = $sizh . $name . $sizhfin; - } - else $count_empty++; - - if ($period !== false && $content['period'] > 0) { - $data[] = $sizh . $period . $sizhfin; - } - else if ($content['period'] == 0) { - $es = json_decode($content['external_source'], true); - if ($es['date'] == 0) { - $date = __('Last data'); - } - else { - $date = date($config["date_format"], $es['date']); - } - - $data[] = "
" . $sizh . $date . $sizhfin . "
"; - } - else { - $data[] = "
" . $sizh . - "(" . human_time_description_raw ($content['period']) . ") " . - __("From:") . " " . date($config["date_format"], $report["datetime"] - $content['period']) . "
" . - __("To:") . " " . date($config["date_format"], $report["datetime"]) . "
" . - $sizhfin . "
"; - } - - $table->colspan[0][2 - $count_empty] = 1 + $count_empty; - - array_push ($table->data, $data); -} - -/** - * This function is used once, in reporting_viewer.php, the HTML report render - * file. This function proccess each report item and write the render in the - * table record. - * - * @param array $content Record of treport_content table for current item - * @param array $table HTML Table row - * @param array $report Report contents, with some added fields. - * @param array $mini Mini flag for reduce the size. - * - */ - -function reporting_render_report_html_item ($content, $table, $report, $mini = false) { - global $config; - global $graphic_type; - - $only_image = (bool)$config['flash_charts'] ? false : true; - - if ($mini) { - $sizem = '1.5'; - $sizgraph_w = '450'; - $sizgraph_h = '100'; - } - else { - $sizem = '3'; - $sizgraph_w = '900'; - $sizgraph_h = '230'; - } - - // Disable remote connections for netflow report items - if ($content['type'] != 'netflow_area' && - $content['type'] != 'netflow_pie' && - $content['type'] != 'netflow_data' && - $content['type'] != 'netflow_statistics' && - $content['type'] != 'netflow_summary') { - - $remote_connection = 1; - } - else { - $remote_connection = 0; - } - - $server_name = $content ['server_name']; - if (($config ['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE') && $remote_connection == 1) { - $connection = metaconsole_get_connection($server_name); - if (metaconsole_load_external_db($connection) != NOERR) { - //ui_print_error_message ("Error connecting to ".$server_name); - } - } - - $module_name = db_get_value ('nombre', 'tagente_modulo', 'id_agente_modulo', $content['id_agent_module']); - if ($content['id_agent_module'] != 0) { - $agent_name = modules_get_agentmodule_agent_name ($content['id_agent_module']); - } - else { - $agent_name = agents_get_name($content['id_agent']); - } - - $item_title = $content['name']; - - switch ($content["type"]) { - case 1: - case 'simple_graph': - if (empty($item_title)) { - $item_title = __('Simple graph'); - } - reporting_header_content($mini, $content, $report, $table, $item_title, - ui_print_truncate_text($agent_name, 'agent_medium', false).'
' . - ui_print_truncate_text($module_name, 'module_medium', false)); - - //RUNNING - - $next_row = 1; - - // Put description at the end of the module (if exists) - if ($content["description"] != "") { - $data_desc = array(); - $data_desc[0] = $content["description"]; - array_push ($table->data, $data_desc); - $table->colspan[$next_row][0] = 3; - $next_row++; - } - - $table->colspan[$next_row][0] = 3; - $table->cellstyle[$next_row][0] = 'text-align: center;'; - - $data = array (); - - $moduletype_name = modules_get_moduletype_name( - modules_get_agentmodule_type( - $content['id_agent_module'])); - - $only_avg = true; - // Due to database compatibility problems, the 'only_avg' value - // is stored into the json contained into the 'style' column. - if (isset($content['style'])) { - $style_json = io_safe_output($content['style']); - $style = json_decode($style_json, true); - - if (isset($style['only_avg'])) { - $only_avg = (bool) $style['only_avg']; - } - } - - if (preg_match ("/string/", $moduletype_name)) { - - $urlImage = ui_get_full_url(false, false, false, false); - - $data[0] = grafico_modulo_string ($content['id_agent_module'], $content['period'], - false, $sizgraph_w, $sizgraph_h, '', '', false, $only_avg, false, - $report["datetime"], $only_image, $urlImage); - - } - else { - - $data[0] = grafico_modulo_sparse( - $content['id_agent_module'], - $content['period'], - false, - $sizgraph_w, - $sizgraph_h, - '', - '', - false, - $only_avg, - true, - $report["datetime"], - '', - 0, - 0, - true, - $only_image, - ui_get_full_url(false, false, false, false), - 1, - false, - '', - false, - true); - } - - array_push ($table->data, $data); - break; - case 'projection_graph': - if (empty($item_title)) { - $item_title = __('Projection graph'); - } - reporting_header_content($mini, $content, $report, $table, $item_title, - ui_print_truncate_text($agent_name, 'agent_medium', false).'
' . - ui_print_truncate_text($module_name, 'module_medium', false)); - - //RUNNING - $table->colspan[1][0] = 4; - - set_time_limit(500); - - $next_row = 1; - // Put description at the end of the module (if exists) - if ($content["description"] != "") { - $data_desc = array(); - $data_desc[0] = $content["description"]; - array_push ($table->data, $data_desc); - $table->colspan[$next_row][0] = 3; - $next_row++; - } - - $table->colspan[$next_row][0] = 3; - $table->cellstyle[$next_row][0] = 'text-align: center;'; - $data = array (); - - $output_projection = forecast_projection_graph($content['id_agent_module'], $content['period'], $content['top_n_value']); - - // If projection doesn't have data then don't draw graph - if ($output_projection == NULL) { - $output_projection = false; - } - - $modules = array($content['id_agent_module']); - $weights = array(); - $data[0] = graphic_combined_module( - $modules, - $weights, - $content['period'], - $sizgraph_w, $sizgraph_h, - 'Projection%20Sample%20Graph', - '', - 0, - 0, - 0, - 0, - $report["datetime"], - true, - ui_get_full_url(false, false, false, false) . '/', - 1, - // Important parameter, this tell to graphic_combined_module function that is a projection graph - $output_projection, - $content['top_n_value'] - ); - array_push ($table->data, $data); - break; - case 'prediction_date': - if (empty($item_title)) { - $item_title = __('Prediction date'); - } - reporting_header_content($mini, $content, $report, $table, $item_title, - ui_print_truncate_text($agent_name, 'agent_medium', false).'
' . - ui_print_truncate_text($module_name, 'module_medium', false)); - - //RUNNING - $table->colspan[1][0] = 4; - - set_time_limit(500); - - // Put description at the end of the module (if exists) - $table->colspan[2][0] = 4; - if ($content["description"] != ""){ - $data_desc = array(); - $data_desc[0] = $content["description"]; - array_push ($table->data, $data_desc); - } - - $data = array (); - $table->colspan[2][0] = 3; - $intervals_text = $content['text']; - $max_interval = substr($intervals_text, 0, strpos($intervals_text, ';')); - $min_interval = substr($intervals_text, strpos($intervals_text, ';') + 1); - $value = forecast_prediction_date ($content['id_agent_module'], $content['period'], $max_interval, $min_interval); - - if ($value === false) { - $value = __('Unknown'); - } - else { - $value = date ('d M Y H:i:s', $value); - } - $data[0] = '

'.$value.'

'; - array_push ($table->data, $data); - break; - case 'simple_baseline_graph': - if (empty($item_title)) { - $item_title = __('Simple baseline graph'); - } - reporting_header_content($mini, $content, $report, $table, $item_title, - ui_print_truncate_text($agent_name, 'agent_medium', false).'
' . - ui_print_truncate_text($module_name, 'module_medium', false)); - - //RUNNING - $table->colspan[1][0] = 4; - - // Put description at the end of the module (if exists) - $table->colspan[2][0] = 4; - if ($content["description"] != "") { - $data_desc = array(); - $data_desc[0] = $content["description"]; - array_push ($table->data, $data_desc); - } - - $data = array (); - $data[0] = grafico_modulo_sparse($content['id_agent_module'], $content['period'], - false, $sizgraph_w, $sizgraph_h, '', '', false, true, true, - $report["datetime"], '', true, 0, true, $only_image, - ui_get_full_url(false, false, false, false)); - - /*$data[0] = graphic_combined_module( - $modules, - $weights, - $content['period'], - $sizgraph_w, $sizgraph_h, - 'Combined%20Sample%20Graph', - '', - 0, - 0, - 0, - $graph["stacked"], - $report["datetime"]); */ - - array_push ($table->data, $data); - - break; - - case 2: - case 'custom_graph': - case 'automatic_custom_graph': - $graph = db_get_row ("tgraph", "id_graph", $content['id_gs']); - - if (empty($item_title)) { - $item_title = __('Custom graph'); - } - reporting_header_content($mini, $content, $report, $table, $item_title, - ui_print_truncate_text($graph['name'], 'item_title', false)); - - //RUNNING - // Put description at the end of the module (if exists) - - $table->colspan[2][0] = 3; - if ($content["description"] != "") { - $data_desc = array(); - $data_desc[0] = $content["description"]; - array_push ($table->data, $data_desc); - } - - $result = db_get_all_rows_field_filter ("tgraph_source", - "id_graph", $content['id_gs']); - $modules = array (); - $weights = array (); - if ($result === false) - $result = array(); - - foreach ($result as $content2) { - array_push ($modules, $content2['id_agent_module']); - array_push ($weights, $content2["weight"]); - } - - // Increase the height to fix the leyend rise - $sizgraph_h += count($modules) * 15; - - $table->colspan[1][0] = 3; - $data = array(); - - require_once ($config["homedir"] . '/include/functions_graph.php'); - $data[0] = graphic_combined_module( - $modules, - $weights, - $content['period'], - $sizgraph_w, $sizgraph_h, - 'Combined%20Sample%20Graph', - '', - 0, - 0, - 0, - $graph["stacked"], - $report["datetime"], - $only_image, - ui_get_full_url(false, false, false, false)); - array_push ($table->data, $data); - - break; - case 'SLA_monthly': - if (function_exists("reporting_enterprise_sla_monthly")) - reporting_enterprise_sla_monthly($mini, $content, $report, $table, $item_title); - break; - case 'SLA_services': - if (function_exists("reporting_enterprise_sla_services")) - reporting_enterprise_sla_services($mini, $content, $report, $table, $item_title); - break; - case 3: - case 'SLA': - if (empty($item_title)) { - $item_title = __('S.L.A.'); - } - reporting_header_content($mini, $content, $report, $table, $item_title); - - $edge_interval = 10; - - // What show? - $show_table = $content['show_graph'] == 0 || $content['show_graph'] == 1; - $show_graphs = $content['show_graph'] == 1 || $content['show_graph'] == 2; - - //RUNNING - $table->style[1] = 'text-align: right'; - - // Put description at the end of the module (if exists) - - $table->colspan[0][1] = 2; - $next_row = 1; - if ($content["description"] != "") { - $table->colspan[$next_row][0] = 3; - $next_row++; - $data_desc = array(); - $data_desc[0] = $content["description"]; - array_push ($table->data, $data_desc); - } - - $slas = db_get_all_rows_field_filter ('treport_content_sla_combined', - 'id_report_content', $content['id_rc']); - - if ($slas === false) { - $data = array (); - $table->colspan[$next_row][0] = 3; - $next_row++; - $data[0] = __('There are no SLAs defined'); - array_push ($table->data, $data); - $slas = array (); - break; - } - elseif ($show_table) { - $table1->width = '99%'; - $table1->data = array (); - $table1->head = array (); - $table1->head[0] = __('Agent'); - $table1->head[1] = __('Module'); - $table1->head[2] = __('Max/Min Values'); - $table1->head[3] = __('SLA Limit'); - $table1->head[4] = __('SLA Compliance'); - $table1->head[5] = __('Status'); - // $table1->head[6] = __('Criticity'); - $table1->style[0] = 'text-align: left'; - $table1->style[1] = 'text-align: left'; - $table1->style[2] = 'text-align: right'; - $table1->style[3] = 'text-align: right'; - $table1->style[4] = 'text-align: right'; - $table1->style[5] = 'text-align: right'; - // $table1->style[6] = 'text-align: center'; - } - - // Table Planned Downtimes - require_once ($config['homedir'] . '/include/functions_planned_downtimes.php'); - $metaconsole_on = ($config['metaconsole'] == 1) && defined('METACONSOLE'); - $downtime_malformed = false; - - $planned_downtimes_empty = true; - $malformed_planned_downtimes_empty = true; - - if ($metaconsole_on) { - $id_agent_modules_by_server = array(); - - foreach ($slas as $sla) { - $server = $sla['server_name']; - if (empty($server)) - continue; - - if (!isset($id_agent_modules_by_server[$server])) - $id_agent_modules_by_server[$server] = array(); - - $id_agent_modules_by_server[$server][] = $sla['id_agent_module']; - } - - $planned_downtimes_by_server = array(); - $malformed_planned_downtimes_by_server = array(); - foreach ($id_agent_modules_by_server as $server => $id_agent_modules) { - //Metaconsole connection - if (!empty($server)) { - $connection = metaconsole_get_connection($server); - if (!metaconsole_load_external_db($connection)) { - continue; - } - - $planned_downtimes_by_server[$server] = reporting_get_planned_downtimes(($report['datetime']-$content['period']), $report['datetime'], $id_agent_modules); - $malformed_planned_downtimes_by_server[$server] = planned_downtimes_get_malformed(); - - if (!empty($planned_downtimes_by_server[$server])) - $planned_downtimes_empty = false; - if (!empty($malformed_planned_downtimes_by_server[$server])) - $malformed_planned_downtimes_empty = false; - - //Restore db connection - metaconsole_restore_db(); - } - } - - if (!$planned_downtimes_empty) { - $table_planned_downtimes = new StdClass(); - $table_planned_downtimes->width = '100%'; - $table_planned_downtimes->title = __('This SLA has been affected by the following planned downtimes'); - $table_planned_downtimes->head = array(); - $table_planned_downtimes->head[0] = __('Server'); - $table_planned_downtimes->head[1] = __('Name'); - $table_planned_downtimes->head[2] = __('Description'); - $table_planned_downtimes->head[3] = __('Execution'); - $table_planned_downtimes->head[4] = __('Dates'); - $table_planned_downtimes->headstyle = array(); - $table_planned_downtimes->style = array(); - $table_planned_downtimes->cellstyle = array(); - $table_planned_downtimes->data = array(); - - foreach ($planned_downtimes_by_server as $server => $planned_downtimes) { - foreach ($planned_downtimes as $planned_downtime) { - $data = array(); - $data[0] = $server; - $data[1] = $planned_downtime['name']; - $data[2] = $planned_downtime['description']; - $data[3] = ucfirst($planned_downtime['type_execution']); - $data[4] = ""; - switch ($planned_downtime['type_execution']) { - case 'once': - $data[3] = date ("Y-m-d H:i", $planned_downtime['date_from']) . - " " . __('to') . " ". - date ("Y-m-d H:i", $planned_downtime['date_to']); - break; - case 'periodically': - switch ($planned_downtime['type_periodicity']) { - case 'weekly': - $data[4] = __('Weekly:'); - $data[4] .= " "; - if ($planned_downtime['monday']) { - $data[4] .= __('Mon'); - $data[4] .= " "; - } - if ($planned_downtime['tuesday']) { - $data[4] .= __('Tue'); - $data[4] .= " "; - } - if ($planned_downtime['wednesday']) { - $data[4] .= __('Wed'); - $data[4] .= " "; - } - if ($planned_downtime['thursday']) { - $data[4] .= __('Thu'); - $data[4] .= " "; - } - if ($planned_downtime['friday']) { - $data[4] .= __('Fri'); - $data[4] .= " "; - } - if ($planned_downtime['saturday']) { - $data[4] .= __('Sat'); - $data[4] .= " "; - } - if ($planned_downtime['sunday']) { - $data[4] .= __('Sun'); - $data[4] .= " "; - } - $data[4] .= " (" . $planned_downtime['periodically_time_from']; - $data[4] .= "-" . $planned_downtime['periodically_time_to'] . ")"; - break; - case 'monthly': - $data[4] = __('Monthly:') . " "; - $data[4] .= __('From day') . " " . $planned_downtime['periodically_day_from']; - $data[4] .= " " . strtolower(__('To day')) . " "; - $data[4] .= $planned_downtime['periodically_day_to']; - $data[4] .= " (" . $planned_downtime['periodically_time_from']; - $data[4] .= "-" . $planned_downtime['periodically_time_to'] . ")"; - break; - } - break; - } - - if (!$malformed_planned_downtimes_empty - && isset($malformed_planned_downtimes_by_server[$server]) - && isset($malformed_planned_downtimes_by_server[$server][$planned_downtime['id']])) { - $next_row_num = count($table_planned_downtimes->data); - $table_planned_downtimes->cellstyle[$next_row_num][0] = 'color: red'; - $table_planned_downtimes->cellstyle[$next_row_num][1] = 'color: red'; - $table_planned_downtimes->cellstyle[$next_row_num][2] = 'color: red'; - $table_planned_downtimes->cellstyle[$next_row_num][3] = 'color: red'; - $table_planned_downtimes->cellstyle[$next_row_num][4] = 'color: red'; - - if (!$downtime_malformed) - $downtime_malformed = true; - } - - $table_planned_downtimes->data[] = $data; - } - } - } - } - else { - $id_agent_modules = array(); - foreach ($slas as $sla) { - if (!empty($sla['id_agent_module'])) - $id_agent_modules[] = $sla['id_agent_module']; - } - - $planned_downtimes = reporting_get_planned_downtimes(($report['datetime']-$content['period']), $report['datetime'], $id_agent_modules); - $malformed_planned_downtimes = planned_downtimes_get_malformed(); - - if (!empty($planned_downtimes)) - $planned_downtimes_empty = false; - if (!empty($malformed_planned_downtimes)) - $malformed_planned_downtimes_empty = false; - - if (!$planned_downtimes_empty) { - $table_planned_downtimes = new StdClass(); - $table_planned_downtimes->width = '100%'; - $table_planned_downtimes->title = __('This SLA has been affected by the following planned downtimes'); - $table_planned_downtimes->head = array(); - $table_planned_downtimes->head[0] = __('Name'); - $table_planned_downtimes->head[1] = __('Description'); - $table_planned_downtimes->head[2] = __('Execution'); - $table_planned_downtimes->head[3] = __('Dates'); - $table_planned_downtimes->headstyle = array(); - $table_planned_downtimes->style = array(); - $table_planned_downtimes->cellstyle = array(); - $table_planned_downtimes->data = array(); - - foreach ($planned_downtimes as $planned_downtime) { - - $data = array(); - $data[0] = $planned_downtime['name']; - $data[1] = $planned_downtime['description']; - $data[2] = ucfirst($planned_downtime['type_execution']); - $data[3] = ""; - switch ($planned_downtime['type_execution']) { - case 'once': - $data[3] = date ("Y-m-d H:i", $planned_downtime['date_from']) . - " " . __('to') . " ". - date ("Y-m-d H:i", $planned_downtime['date_to']); - break; - case 'periodically': - switch ($planned_downtime['type_periodicity']) { - case 'weekly': - $data[3] = __('Weekly:'); - $data[3] .= " "; - if ($planned_downtime['monday']) { - $data[3] .= __('Mon'); - $data[3] .= " "; - } - if ($planned_downtime['tuesday']) { - $data[3] .= __('Tue'); - $data[3] .= " "; - } - if ($planned_downtime['wednesday']) { - $data[3] .= __('Wed'); - $data[3] .= " "; - } - if ($planned_downtime['thursday']) { - $data[3] .= __('Thu'); - $data[3] .= " "; - } - if ($planned_downtime['friday']) { - $data[3] .= __('Fri'); - $data[3] .= " "; - } - if ($planned_downtime['saturday']) { - $data[3] .= __('Sat'); - $data[3] .= " "; - } - if ($planned_downtime['sunday']) { - $data[3] .= __('Sun'); - $data[3] .= " "; - } - $data[3] .= " (" . $planned_downtime['periodically_time_from']; - $data[3] .= "-" . $planned_downtime['periodically_time_to'] . ")"; - break; - case 'monthly': - $data[3] = __('Monthly:') . " "; - $data[3] .= __('From day') . " " . $planned_downtime['periodically_day_from']; - $data[3] .= " " . strtolower(__('To day')) . " "; - $data[3] .= $planned_downtime['periodically_day_to']; - $data[3] .= " (" . $planned_downtime['periodically_time_from']; - $data[3] .= "-" . $planned_downtime['periodically_time_to'] . ")"; - break; - } - break; - } - - if (!$malformed_planned_downtimes_empty && isset($malformed_planned_downtimes[$planned_downtime['id']])) { - $next_row_num = count($table_planned_downtimes->data); - $table_planned_downtimes->cellstyle[$next_row_num][0] = 'color: red'; - $table_planned_downtimes->cellstyle[$next_row_num][1] = 'color: red'; - $table_planned_downtimes->cellstyle[$next_row_num][2] = 'color: red'; - $table_planned_downtimes->cellstyle[$next_row_num][3] = 'color: red'; - - if (!$downtime_malformed) - $downtime_malformed = true; - } - - $table_planned_downtimes->data[] = $data; - } - } - } - - if ($downtime_malformed) { - $info_malformed = ui_print_error_message( - __('This item is affected by a malformed planned downtime') . ". " . - __('Go to the planned downtimes section to solve this') . ".", '', true); - - $data = array(); - $data[0] = $info_malformed; - $data[0] .= html_print_table($table_planned_downtimes, true); - $table->colspan[$next_row][0] = 3; - $next_row++; - array_push ($table->data, $data); - break; - } - - $data_graph = array (); - // $data_horin_graph = array(); - $data_graph[__('Inside limits')] = 0; - $data_graph[__('Out of limits')] = 0; - $data_graph[__('On the edge')] = 0; - $data_graph[__('Unknown')] = 0; - // $data_horin_graph[__('Inside limits')] = 0; - // $data_horin_graph[__('Out of limits')] = 0; - // $data_horin_graph[__('On the edge')] = 0; - // $data_horin_graph[__('Unknown')] = 0; - - $data_graph[__('Plannified downtime')] = 0; - - $urlImage = ui_get_full_url(false, true, false, false); - - $sla_failed = false; - $total_SLA = 0; - $total_result_SLA = 'ok'; - $sla_showed = array(); - $sla_showed_values = array(); - - foreach ($slas as $sla) { - $server_name = $sla ['server_name']; - //Metaconsole connection - if (($config ['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE')) { - $connection = metaconsole_get_connection($server_name); - if (!metaconsole_load_external_db($connection)) { - //ui_print_error_message ("Error connecting to ".$server_name); - continue; - } - } - - if (modules_is_disable_agent($sla['id_agent_module'])) { - continue; - } - - //Get the sla_value in % and store it on $sla_value - $sla_value = reporting_get_agentmodule_sla( - $sla['id_agent_module'], $content['period'], - $sla['sla_min'], $sla['sla_max'], - $report["datetime"], $content, - $content['time_from'], $content['time_to']); - - if (($config ['metaconsole'] == 1) && defined('METACONSOLE')) { - //Restore db connection - metaconsole_restore_db(); - } - - //Do not show right modules if 'only_display_wrong' is active - if ($content['only_display_wrong'] == 1 && - $sla_value >= $sla['sla_limit']) { - - continue; - } - - $sla_showed[] = $sla; - $sla_showed_values[] = $sla_value; - - } - - // SLA items sorted descending () - if ($content['top_n'] == 2) { - arsort($sla_showed_values); - } - // SLA items sorted ascending - else if ($content['top_n'] == 1) { - asort($sla_showed_values); - } - - // Slice graphs calculation - if ($show_graphs && !empty($slas)) { - $tableslice->width = '99%'; - $tableslice->style[0] = 'text-align: right'; - $tableslice->data = array (); - } - - foreach ($sla_showed_values as $k => $sla_value) { - $sla = $sla_showed[$k]; - - $server_name = $sla ['server_name']; - //Metaconsole connection - if (($config ['metaconsole'] == 1) && ($server_name != '') && defined('METACONSOLE')) { - $connection = metaconsole_get_connection($server_name); - if (metaconsole_connect($connection) != NOERR) { - //ui_print_error_message ("Error connecting to ".$server_name); - continue; - } - } - - //Fill the array data_graph for the pie graph - // if ($sla_value === false) { - // $data_graph[__('Unknown')]++; - // // $data_horin_graph[__('Unknown')]['g']++; - // } - // # Fix : 100% accurance is 'inside limits' although 10% was not overrun - // else if (($sla_value == 100 && $sla_value >= $sla['sla_limit']) ) { - // $data_graph[__('Inside limits')]++; - // $data_horin_graph[__('Inside limits')]['g']++; - // } - // else if ($sla_value <= ($sla['sla_limit']+10) && $sla_value >= ($sla['sla_limit']-10)) { - // $data_graph[__('On the edge')]++; - // $data_horin_graph[__('On the edge')]['g']++; - // } - // else if ($sla_value > ($sla['sla_limit']+10)) { - // $data_graph[__('Inside limits')]++; - // $data_horin_graph[__('Inside limits')]['g']++; - // } - // else if ($sla_value < ($sla['sla_limit']-10)) { - // $data_graph[__('Out of limits')]++; - // $data_horin_graph[__('Out of limits')]['g']++; - // } - - // if ($sla_value === false) { - // if ($total_result_SLA != 'fail') - // $total_result_SLA = 'unknown'; - // } - // else if ($sla_value < $sla['sla_limit']) { - // $total_result_SLA = 'fail'; - // } - - $total_SLA += $sla_value; - - if ($show_table) { - $data = array (); - $data[0] = modules_get_agentmodule_agent_name ($sla['id_agent_module']); - $data[1] = modules_get_agentmodule_name ($sla['id_agent_module']); - $data[2] = $sla['sla_max'].'/'; - $data[2] .= $sla['sla_min']; - $data[3] = $sla['sla_limit'].'%'; - - if ($sla_value === false) { - $data[4] = ''; - $data[5] = ''.__('Unknown').''; - // $data[6] = html_print_image('images/status_sets/default/severity_maintenance.png',true,array('title'=>__('Unknown'))); - } - else { - $data[4] = ''; - $data[5] = ''; - // $data[6] = ''; - - if ($sla_value >= $sla['sla_limit']) { - $data[4] = ''; - $data[5] = ''.__('OK').''; - } - else { - $sla_failed = true; - $data[4] = ''; - $data[5] = ''.__('Fail').''; - } - - // Print icon with status including edge - # Fix : 100% accurance is 'inside limits' although 10% was not overrun - // if (($sla_value == 100 && $sla_value >= $sla['sla_limit']) || ($sla_value > ($sla['sla_limit'] + $edge_interval))) { - // $data[6] = html_print_image('images/status_sets/default/severity_normal.png',true,array('title'=>__('Inside limits'))); - // } - // elseif (($sla_value <= $sla['sla_limit'] + $edge_interval) - // && ($sla_value >= $sla['sla_limit'] - $edge_interval)) { - // $data[6] = html_print_image('images/status_sets/default/severity_warning.png',true,array('title'=>__('On the edge'))); - // } - // else { - // $data[6] = html_print_image('images/status_sets/default/severity_critical.png',true,array('title'=>__('Out of limits'))); - // } - - $data[4] .= format_numeric ($sla_value, 2). "%"; - } - $data[4] .= ""; - - array_push ($table1->data, $data); - } - - // Slice graphs calculation - if ($show_graphs) { - $dataslice = array(); - $dataslice[0] = modules_get_agentmodule_agent_name ($sla['id_agent_module']); - $dataslice[0] .= "
"; - $dataslice[0] .= modules_get_agentmodule_name ($sla['id_agent_module']); - - $dataslice[1] = graph_sla_slicebar ($sla['id_agent_module'], $content['period'], - $sla['sla_min'], $sla['sla_max'], $report['datetime'], $content, $content['time_from'], - $content['time_to'], 650, 25, $urlImage, 1, false, false); - - array_push ($tableslice->data, $dataslice); - } - - if ($config ['metaconsole'] == 1 && defined('METACONSOLE')) { - //Restore db connection - metaconsole_restore_db(); - } - } - - if ($show_table) { - $data = array(); - $data[0] = html_print_table($table1, true); - $table->colspan[$next_row][0] = 3; - $next_row++; - array_push ($table->data, $data); - } - - // $data = array(); - // $data_pie_graph = json_encode ($data_graph); - if ($show_graphs && !empty($slas)) { - $table->colspan[$next_row][0] = 3; - $next_row++; - $data = array(); - $data[0] = html_print_table($tableslice, true); - array_push ($table->data, $data); - } - - if (!empty($table_planned_downtimes)) { - $data = array(); - $data[0] = html_print_table($table_planned_downtimes, true); - $table->colspan[$next_row][0] = 3; - $next_row++; - array_push ($table->data, $data); - } - break; - case 6: - case 'monitor_report': - if (empty($item_title)) { - $item_title = __('Monitor report'); - } - reporting_header_content($mini, $content, $report, $table, $item_title, - ui_print_truncate_text($agent_name, 'agent_medium', false) . - '
'.ui_print_truncate_text($module_name, 'module_medium', false)); - - //RUNNING - $next_row = 1; - - // Put description at the end of the module (if exists) - if ($content["description"] != "") { - $table->colspan[1][0] = 3; - $data_desc = array(); - $data_desc[0] = $content["description"]; - array_push ($table->data, $data_desc); - $next_row++; - } - - $data = array (); - $monitor_value = reporting_get_agentmodule_sla ($content['id_agent_module'], $content['period'], 1, false, $report["datetime"]); - if ($monitor_value === false) { - $monitor_value = __('Unknown'); - } - else { - $monitor_value = format_numeric ($monitor_value); - } - - $table->colspan[$next_row][0] = 2; - $data[0] = '

'; - $data[0] .= html_print_image("images/module_ok.png", true) . ' ' . __('OK') . ': ' . $monitor_value.' %

'; - if ($monitor_value !== __('Unknown')) { - $monitor_value = format_numeric (100 - $monitor_value, 2) ; - } - $data[1] = '

'; - $data[1] .= html_print_image("images/module_critical.png", true) . ' ' .__('Not OK') . ': ' .$monitor_value.' % ' . '

'; - array_push ($table->data, $data); - - break; - case 7: - case 'avg_value': - if (empty($item_title)) { - $item_title = __('Avg. Value'); - } - reporting_header_content($mini, $content, $report, $table, $item_title, - ui_print_truncate_text($agent_name, 'agent_medium', false) . - '
'.ui_print_truncate_text($module_name, 'module_medium', false)); - - //RUNNING - - // Put description at the end of the module (if exists) - $table->colspan[1][0] = 3; - if ($content["description"] != "") { - $data_desc = array(); - $data_desc[0] = $content["description"]; - array_push ($table->data, $data_desc); - } - - $data = array (); - $table->colspan[2][0] = 3; - $unit = db_get_value('unit', 'tagente_modulo', 'id_agente_modulo', $content['id_agent_module']); - $value = reporting_get_agentmodule_data_average ($content['id_agent_module'], $content['period'], $report["datetime"]); - if ($value === false) { - $value = __('Unknown'); - } - else { - $value = format_for_graph($value, 2) . " " . $unit; - } - $data[0] = '

'.$value.'

'; - array_push ($table->data, $data); - - break; - case 8: - case 'max_value': - if (empty($item_title)) { - $item_title = __('Max. Value'); - } - reporting_header_content($mini, $content, $report, $table, $item_title, - ui_print_truncate_text($agent_name, 'agent_medium', false) . - '
' . ui_print_truncate_text($module_name, 'module_medium', false)); - - //RUNNING - - // Put description at the end of the module (if exists) - $table->colspan[1][0] = 3; - if ($content["description"] != ""){ - $data_desc = array(); - $data_desc[0] = $content["description"]; - array_push ($table->data, $data_desc); - } - - $data = array (); - $table->colspan[2][0] = 3; - - $value = reporting_get_agentmodule_data_max ($content['id_agent_module'], $content['period'], $report["datetime"]); - - $unit = db_get_value('unit', 'tagente_modulo', 'id_agente_modulo', $content ['id_agent_module']); - $data[0] = '

' . - format_for_graph($value, 2) . " " . $unit .'

'; - array_push ($table->data, $data); - - break; - case 9: - case 'min_value': - if (empty($item_title)) { - $item_title = __('Min. Value'); - } - reporting_header_content($mini, $content, $report, $table, $item_title, - ui_print_truncate_text($agent_name, 'agent_medium', false) . - '
'.ui_print_truncate_text($module_name, 'module_medium', false)); - - //RUNNING - - // Put description at the end of the module (if exists) - $table->colspan[1][0] = 3; - if ($content["description"] != "") { - $data_desc = array(); - $data_desc[0] = $content["description"]; - array_push ($table->data, $data_desc); - } - - $data = array (); - $table->colspan[2][0] = 3; - - $value = reporting_get_agentmodule_data_min ($content['id_agent_module'], $content['period'], $report["datetime"]); - $unit = db_get_value('unit', 'tagente_modulo', 'id_agente_modulo', $content ['id_agent_module']); - if ($value === false) { - $value = __('Unknown'); - } - else { - $value = format_for_graph($value, 2) . " " . $unit; - } - $data[0] = '

'.$value.'

'; - array_push ($table->data, $data); - - break; - case 10: - case 'sumatory': - if (empty($item_title)) { - $item_title = __('Summatory'); - } - reporting_header_content($mini, $content, $report, $table, $item_title, - ui_print_truncate_text($agent_name, 'agent_medium', false) . - '
' . ui_print_truncate_text($module_name, 'module_medium', false)); - - //RUNNING - - $next_row = 1; - - // Put description at the end of the module (if exists) - if ($content["description"] != "") { - $data_desc = array(); - $data_desc[0] = $content["description"]; - array_push ($table->data, $data_desc); - $table->colspan[$next_row][0] = 3; - $next_row++; - } - - $table->colspan[$next_row][0] = 3; - - $data = array (); - $unit = db_get_value('unit', 'tagente_modulo', 'id_agente_modulo', $content['id_agent_module']); - - $value = reporting_get_agentmodule_data_sum ($content['id_agent_module'], $content['period'], $report["datetime"]); - if ($value === false) { - $value = __('Unknown'); - } - else { - $value = format_for_graph($value, 2) . " " . $unit; - } - - $data[0] = '

'.$value.'

'; - array_push ($table->data, $data); - - break; - case 'agent_detailed_event': - case 'event_report_agent': - if (empty($item_title)) { - $item_title = __('Agent detailed event'); - } - reporting_header_content($mini, $content, $report, $table, $item_title, - ui_print_truncate_text(agents_get_name($content['id_agent']), 'agent_medium', false)); - - $style = json_decode(io_safe_output($content['style']), true); - - $filter_event_no_validated = $style['filter_event_no_validated']; - $filter_event_validated = $style['filter_event_validated']; - $filter_event_critical = $style['filter_event_critical']; - $filter_event_warning = $style['filter_event_warning']; - - $event_graph_by_agent = $style['event_graph_by_agent']; - $event_graph_by_user_validator = $style['event_graph_by_user_validator']; - $event_graph_by_criticity = $style['event_graph_by_criticity']; - $event_graph_validated_vs_unvalidated = $style['event_graph_validated_vs_unvalidated']; - - $next_row = 1; - - // Put description at the end of the module (if exists) - if ($content["description"] != "") { - $data_desc = array(); - $data_desc[0] = $content["description"]; - array_push ($table->data, $data_desc); - $table->colspan[$next_row][0] = 3; - $next_row++; - } - - $data = array (); - $table->colspan[$next_row][0] = 3; - $next_row++; - $data[0] = reporting_get_agents_detailed_event( - $content['id_agent'], $content['period'], - $report["datetime"], true, - $filter_event_validated, - $filter_event_critical, - $filter_event_warning, - $filter_event_no_validated); - - if(!empty($data[0])) { - array_push ($table->data, $data); - - $table->colspan[$next_row][0] = 3; - $next_row++; - } - - - if ($event_graph_by_user_validator) { - $data_graph = reporting_get_count_events_validated_by_user( - array('id_agent' => $content['id_agent']), $content['period'], - $report["datetime"], - $filter_event_validated, - $filter_event_critical, - $filter_event_warning, - $filter_event_no_validated); - - $table_event_graph = null; - $table_event_graph->width = '100%'; - $table_event_graph->style[0] = 'text-align: center;'; - $table_event_graph->head[0] = __('Events validated by user'); - - $table_event_graph->data[0][0] = pie3d_graph( - false, $data_graph, 500, 150, __("other"), "", - ui_get_full_url(false, false, false, false) . "/images/logo_vertical_water.png", - $config['fontpath'], $config['font_size']); - - $data[0] = html_print_table($table_event_graph, true); - - $table->colspan[$next_row][0] = 3; - $next_row++; - array_push ($table->data, $data); - } - - if ($event_graph_by_criticity) { - $data_graph = reporting_get_count_events_by_criticity( - array('id_agent' => $content['id_agent']), $content['period'], - $report["datetime"], - $filter_event_validated, - $filter_event_critical, - $filter_event_warning, - $filter_event_no_validated); - - $colors = get_criticity_pie_colors($data_graph); - - $table_event_graph = null; - $table_event_graph->width = '100%'; - $table_event_graph->style[0] = 'text-align: center;'; - $table_event_graph->head[0] = __('Events by criticity'); - - $table_event_graph->data[0][0] = pie3d_graph( - false, $data_graph, 500, 150, __("other"), "", - ui_get_full_url(false, false, false, false) . "/images/logo_vertical_water.png", - $config['fontpath'], $config['font_size'], 1, false, $colors); - - $data[0] = html_print_table($table_event_graph, true); - - $table->colspan[$next_row][0] = 3; - $next_row++; - array_push ($table->data, $data); - } - - if ($event_graph_validated_vs_unvalidated) { - $data_graph = reporting_get_count_events_validated( - array('id_agent' => $content['id_agent']), $content['period'], - $report["datetime"], - $filter_event_validated, - $filter_event_critical, - $filter_event_warning, - $filter_event_no_validated); - - $table_event_graph = null; - $table_event_graph->width = '100%'; - $table_event_graph->style[0] = 'text-align: center;'; - $table_event_graph->head[0] = __('Amount events validated'); - - $table_event_graph->data[0][0] = pie3d_graph( - false, $data_graph, 500, 150, __("other"), "", - ui_get_full_url(false, false, false, false) . "/images/logo_vertical_water.png", - $config['fontpath'], $config['font_size']); - - $data[0] = html_print_table($table_event_graph, true); - - $table->colspan[$next_row][0] = 3; - $next_row++; - array_push ($table->data, $data); - } - break; - case 'text': - if (empty($item_title)) { - $item_title = __('Text'); - } - reporting_header_content($mini, $content, $report, $table, $item_title, - "", ""); - - $next_row = 1; - - if ($content["description"] != ""){ - $data_desc = array(); - $data_desc[0] = $content["description"]; - array_push ($table->data, $data_desc); - $table->colspan[$next_row][0] = 3; - $next_row++; - } - $data[0] = html_entity_decode($content['text']); - array_push($table->data, $data); - $table->colspan[$next_row][0] = 3; - break; - case 'sql': - if (empty($item_title)) { - $item_title = __('SQL'); - } - reporting_header_content($mini, $content, $report, $table, $item_title, - "", ""); - - $next_row = 1; - // Put description at the end of the module (if exists) - if ($content["description"] != ""){ - $data_desc = array(); - $data_desc[0] = $content["description"]; - array_push ($table->data, $data_desc); - - $table->colspan[$next_row][0] = 3; - $next_row++; - } - - $table->colspan[$next_row][0] = 3; - - $table2->class = 'databox'; - $table2->width = '100%'; - - //Create the head - $table2->head = array(); - if ($content['header_definition'] != '') { - $table2->head = explode('|', $content['header_definition']); - } - - if ($content['treport_custom_sql_id'] != 0) { - switch ($config["dbtype"]) { - case "mysql": - $sql = io_safe_output (db_get_value_filter('`sql`', 'treport_custom_sql', array('id' => $content['treport_custom_sql_id']))); - break; - case "postgresql": - $sql = io_safe_output (db_get_value_filter('"sql"', 'treport_custom_sql', array('id' => $content['treport_custom_sql_id']))); - break; - case "oracle": - $sql = io_safe_output (db_get_value_filter('sql', 'treport_custom_sql', array('id' => $content['treport_custom_sql_id']))); - break; - } - } - else { - $sql = io_safe_output ($content['external_source']); - } - - // Do a security check on SQL coming from the user - $sql = check_sql ($sql); - - if ($sql != '') { - $result = db_get_all_rows_sql($sql); - if ($result === false) { - $result = array(); - } - - if (isset($result[0])) { - if (count($result[0]) > count($table2->head)) { - $table2->head = array_pad($table2->head, count($result[0]), ' '); - } - } - - $table2->data = array(); - foreach ($result as $row) { - array_push($table2->data, $row); - } - } - else { - $table2->data = array(); - array_push($table2->data, array("id_user" => "
[".__('Illegal query')."]
". - __('Due security restrictions, there are some tokens or words you cannot use'). - ': *, delete, drop, alter, modify, union, password, pass, insert '.__('or')." update.
")); - } - - $cellContent = html_print_table($table2, true); - array_push($table->data, array($cellContent)); - break; - case 'sql_graph_vbar': - case 'sql_graph_hbar': - case 'sql_graph_pie': - $sizgraph_h = 300; - - if ($content['type'] == 'sql_graph_vbar') { - $sizgraph_h = 400; - } - - if ($config['metaconsole'] == 1 && defined('METACONSOLE')) - metaconsole_restore_db(); - - if (empty($item_title)) { - $item_title = __('User defined graph') . " (".__($content["type"]) .")"; - } - reporting_header_content($mini, $content, $report, $table, $item_title, - "", ""); - - // Put description at the end of the module (if exists) - $next_row = 1; - if ($content["description"] != "") { - $data_desc = array(); - $data_desc[0] = $content["description"]; - array_push ($table->data, $data_desc); - $table->colspan[$next_row][0] = 3; - $next_row++; - } - - $table->colspan[$next_row][0] = 3; - - $table2->class = 'databox'; - $table2->width = '100%'; - - //Create the head - $table2->head = array(); - if ($content['header_definition'] != '') { - $table2->head = explode('|', $content['header_definition']); - } - - $data = array (); - - $data[0] = graph_custom_sql_graph( - $content["id_rc"], - $sizgraph_w, - $sizgraph_h, - $content["type"], - true, - ui_get_full_url(false, false, false, false)); - - array_push($table->data, $data); - break; - case 'event_report_group': - if (empty($item_title)) { - $item_title = __('Group detailed event'); - } - reporting_header_content($mini, $content, $report, $table, $item_title, - ui_print_truncate_text(groups_get_name($content['id_group'], true), 60, false)); - - $next_row = 1; - - // Put description at the end of the module (if exists) - if ($content["description"] != "") { - $data_desc = array(); - $data_desc[0] = $content["description"]; - array_push ($table->data, $data_desc); - $table->colspan[$next_row][0] = 3; - $next_row++; - } - - $data = array (); - - $style = json_decode(io_safe_output($content['style']), true); - - $filter_event_no_validated = $style['filter_event_no_validated']; - $filter_event_validated = $style['filter_event_validated']; - $filter_event_critical = $style['filter_event_critical']; - $filter_event_warning = $style['filter_event_warning']; - - $event_graph_by_agent = $style['event_graph_by_agent']; - $event_graph_by_user_validator = $style['event_graph_by_user_validator']; - $event_graph_by_criticity = $style['event_graph_by_criticity']; - $event_graph_validated_vs_unvalidated = $style['event_graph_validated_vs_unvalidated']; - - $data[0] = reporting_get_group_detailed_event( - $content['id_group'], $content['period'], - $report["datetime"], true, true, - $filter_event_validated, - $filter_event_critical, - $filter_event_warning, - $filter_event_no_validated); - if(!empty($data[0])) { - array_push ($table->data, $data); - - $table->colspan[$next_row][0] = 3; - $next_row++; - } - - if ($event_graph_by_agent) { - $data_graph = reporting_get_count_events_by_agent( - $content['id_group'], $content['period'], - $report["datetime"], - $filter_event_validated, - $filter_event_critical, - $filter_event_warning, - $filter_event_no_validated); - - $table_event_graph = null; - $table_event_graph->width = '100%'; - $table_event_graph->style[0] = 'text-align: center;'; - $table_event_graph->head[0] = __('Events by agent'); - - $table_event_graph->data[0][0] = pie3d_graph( - false, $data_graph, 500, 150, __("other"), "", - ui_get_full_url(false, false, false, false) . "/images/logo_vertical_water.png", - $config['fontpath'], $config['font_size']); - - $data[0] = html_print_table($table_event_graph, true); - - $table->colspan[$next_row][0] = 3; - $next_row++; - array_push ($table->data, $data); - } - - if ($event_graph_by_user_validator) { - $data_graph = reporting_get_count_events_validated_by_user( - array('id_group' => $content['id_group']), $content['period'], - $report["datetime"], - $filter_event_validated, - $filter_event_critical, - $filter_event_warning, - $filter_event_no_validated); - - $table_event_graph = null; - $table_event_graph->head[0] = __('Events validated by user'); - $table_event_graph->width = '100%'; - $table_event_graph->style[0] = 'text-align: center;'; - - $table_event_graph->data[0][0] = pie3d_graph( - false, $data_graph, 500, 150, __("other"), "", - ui_get_full_url(false, false, false, false) . "/images/logo_vertical_water.png", - $config['fontpath'], $config['font_size']); - - $data[0] = html_print_table($table_event_graph, true); - - $table->colspan[$next_row][0] = 3; - $next_row++; - array_push ($table->data, $data); - } - - if ($event_graph_by_criticity) { - $data_graph = reporting_get_count_events_by_criticity( - array('id_group' => $content['id_group']), $content['period'], - $report["datetime"], - $filter_event_validated, - $filter_event_critical, - $filter_event_warning, - $filter_event_no_validated); - - $colors = get_criticity_pie_colors($data_graph); - - $table_event_graph = null; - $table_event_graph->head[0] = __('Events by criticity'); - $table_event_graph->width = '100%'; - $table_event_graph->style[0] = 'text-align: center;'; - - $table_event_graph->data[0][0] = pie3d_graph( - false, $data_graph, 500, 150, __("other"), "", - ui_get_full_url(false, false, false, false) . "/images/logo_vertical_water.png", - $config['fontpath'], $config['font_size'], 1, false, $colors); - - $data[0] = html_print_table($table_event_graph, true); - - $table->colspan[$next_row][0] = 3; - $next_row++; - array_push ($table->data, $data); - } - - if ($event_graph_validated_vs_unvalidated) { - $data_graph = reporting_get_count_events_validated( - array('id_group' => $content['id_group']), $content['period'], - $report["datetime"], - $filter_event_validated, - $filter_event_critical, - $filter_event_warning, - $filter_event_no_validated); - - $table_event_graph = null; - $table_event_graph->head[0] = __('Amount events validated'); - $table_event_graph->width = '100%'; - $table_event_graph->style[0] = 'text-align: center;'; - - $table_event_graph->data[0][0] = pie3d_graph( - false, $data_graph, 500, 150, __("other"), "", - ui_get_full_url(false, false, false, false) . "/images/logo_vertical_water.png", - $config['fontpath'], $config['font_size']); - - $data[0] = html_print_table($table_event_graph, true); - - $table->colspan[$next_row][0] = 3; - $next_row++; - array_push ($table->data, $data); - } - break; - case 'event_report_module': - if (empty($item_title)) { - $item_title = __('Module detailed event'); - } - reporting_header_content($mini, $content, $report, $table, $item_title, - ui_print_truncate_text($agent_name, 'agent_medium', false) . - '
' . ui_print_truncate_text($module_name, 'module_medium', false)); - - // Put description at the end of the module (if exists) - $table->colspan[1][0] = 3; - if ($content["description"] != "") { - $data_desc = array(); - $data_desc[0] = $content["description"]; - array_push ($table->data, $data_desc); - } - - $data = array (); - $table->colspan[2][0] = 3; - $data[0] = reporting_get_module_detailed_event($content['id_agent_module'], $content['period'], $report["datetime"], true); - array_push ($table->data, $data); - break; - case 'alert_report_group': - if (empty($item_title)) { - $item_title = __('Alert report group'); - } - reporting_header_content($mini, $content, $report, $table, $item_title, - ui_print_truncate_text( - groups_get_name($content['id_group'], true), - 60, false)); - - // Put description at the end of the module (if exists) - $table->colspan[1][0] = 3; - if ($content["description"] != "") { - $data_desc = array(); - $data_desc[0] = $content["description"]; - array_push ($table->data, $data_desc); - } - - $data = array (); - $table->colspan[2][0] = 3; - $data[0] = reporting_alert_reporting_group( - $content['id_group'], $content['period'], - $report["datetime"], true); - array_push ($table->data, $data); - break; - case 'alert_report_module': - if (empty($item_title)) { - $item_title = __('Alert report module'); - } - reporting_header_content($mini, $content, $report, $table, $item_title, - ui_print_truncate_text($agent_name, 'agent_medium', false) . - '
'.ui_print_truncate_text($module_name, 'module_medium', false)); - - // Put description at the end of the module (if exists) - $table->colspan[1][0] = 3; - if ($content["description"] != "") { - $data_desc = array(); - $data_desc[0] = $content["description"]; - array_push ($table->data, $data_desc); - } - - $data = array (); - $table->colspan[2][0] = 3; - $data[0] = reporting_alert_reporting_module ($content['id_agent_module'], $content['period'], $report["datetime"], true); - array_push ($table->data, $data); - break; - case 'alert_report_agent': - if (empty($item_title)) { - $item_title = __('Alert report agent'); - } - reporting_header_content($mini, $content, $report, $table, $item_title, - ui_print_truncate_text($agent_name, 'agent_medium', false)); - - // Put description at the end of the module (if exists) - $table->colspan[1][0] = 3; - if ($content["description"] != "") { - $data_desc = array(); - $data_desc[0] = $content["description"]; - array_push ($table->data, $data_desc); - } - - $data = array (); - $table->colspan[2][0] = 3; - $data[0] = reporting_alert_reporting_agent ($content['id_agent'], $content['period'], $report["datetime"], true); - array_push ($table->data, $data); - break; - case 'url': - if (empty($item_title)) { - $item_title = __('Import text from URL'); - } - reporting_header_content($mini, $content, $report, $table, $item_title, - ui_print_truncate_text($content["external_source"], 'description', false)); - - $next_row = 1; - // Put description at the end of the module (if exists) - if ($content["description"] != "") { - $data_desc = array(); - $data_desc[0] = $content["description"]; - array_push ($table->data, $data_desc); - $table->colspan[$next_row][0] = 3; - $next_row++; - } - - $data = array(); - $table->colspan[$next_row][0] = 3; - $data[0] = ''; - // TODO: make this dynamic and get the height if the iframe to resize this item - $data[0] .= ''; - - array_push ($table->data, $data); - break; - case 'database_serialized': - if (empty($item_title)) { - $item_title = __('Serialize data'); - } - reporting_header_content($mini, $content, $report, $table, $item_title, - ui_print_truncate_text($module_name, 'module_medium', false)); - - // Put description at the end of the module (if exists) - $next_row = 1; - if ($content["description"] != "") { - $data_desc = array(); - $data_desc[0] = $content["description"]; - $table->colspan[$next_row][0] = 3; - array_push ($table->data, $data_desc); - $next_row++; - } - - $table->colspan[$next_row][0] = 3; - - $table2->class = 'databox alternate'; - $table2->width = '100%'; - - //Create the head - $table2->head = array(); - if ($content['header_definition'] != '') { - $table2->head = explode('|', $content['header_definition']); - } - else { - $table2->head[] = __('Data'); - } - array_unshift($table2->head, __('Date')); - - $datelimit = $report["datetime"] - $content['period']; - $search_in_history_db = db_search_in_history_db($datelimit); - - // This query gets information from the default and the historic database - $result = db_get_all_rows_sql('SELECT * - FROM tagente_datos - WHERE id_agente_modulo = ' . $content['id_agent_module'] . ' - AND utimestamp > ' . $datelimit . ' - AND utimestamp <= ' . $report["datetime"], $search_in_history_db); - - // Adds string data if there is no numeric data - if ((count($result) < 0) or (!$result)) { - // This query gets information from the default and the historic database - $result = db_get_all_rows_sql('SELECT * - FROM tagente_datos_string - WHERE id_agente_modulo = ' . $content['id_agent_module'] . ' - AND utimestamp > ' . $datelimit . ' - AND utimestamp <= ' . $report["datetime"], $search_in_history_db); - } - if ($result === false) { - $result = array(); - } - - $table2->data = array(); - foreach ($result as $row) { - $date = date ($config["date_format"], $row['utimestamp']); - $serialized = $row['datos']; - if (empty($content['line_separator']) || - empty($serialized)) { - $rowsUnserialize = array($row['datos']); - } - else { - $rowsUnserialize = explode($content['line_separator'], $serialized); - } - foreach ($rowsUnserialize as $rowUnser) { - if (empty($content['column_separator'])) { - $columnsUnserialize = array($rowUnser); - } - else { - $columnsUnserialize = explode($content['column_separator'], $rowUnser); - } - - array_unshift($columnsUnserialize, $date); - array_push($table2->data, $columnsUnserialize); - } - } - - $cellContent = html_print_table($table2, true); - array_push($table->data, array($cellContent)); - break; - case 'TTRT': - if (empty($item_title)) { - $item_title = __('TTRT'); - } - reporting_header_content($mini, $content, $report, $table, $item_title, - ui_print_truncate_text($agent_name, 'agent_medium', false) . - '
'.ui_print_truncate_text($module_name, 'module_medium', false)); - - // Put description at the end of the module (if exists) - $table->colspan[1][0] = 3; - if ($content["description"] != "") { - $data_desc = array(); - $data_desc[0] = $content["description"]; - array_push ($table->data, $data_desc); - } - - $data = array (); - $table->colspan[2][0] = 3; - $ttr = reporting_get_agentmodule_ttr ($content['id_agent_module'], $content['period'], $report["datetime"]); - if ($ttr === false) { - $ttr = __('Unknown'); - } - else if ($ttr != 0) { - $ttr = human_time_description_raw ($ttr); - } - - $data = array (); - $table->colspan[2][0] = 3; - $data[0] = '

'.$ttr.'

'; - array_push ($table->data, $data); - break; - case 'TTO': - if (empty($item_title)) { - $item_title = __('TTO'); - } - reporting_header_content($mini, $content, $report, $table, $item_title, - ui_print_truncate_text($agent_name, 'agent_medium', false) . - '
'.ui_print_truncate_text($module_name, 'module_medium', false)); - - // Put description at the end of the module (if exists) - $table->colspan[1][0] = 3; - if ($content["description"] != "") { - $data_desc = array(); - $data_desc[0] = $content["description"]; - array_push ($table->data, $data_desc); - } - - $data = array (); - $table->colspan[2][0] = 3; - $tto = reporting_get_agentmodule_tto ($content['id_agent_module'], - $content['period'], $report["datetime"]); - if ($tto === false) { - $tto = __('Unknown'); - } - else if ($tto != 0) { - $tto = human_time_description_raw ($tto); - } - - $data = array (); - $table->colspan[2][0] = 3; - $data[0] = '

'.$tto.'

'; - array_push ($table->data, $data); - break; - case 'MTBF': - if (empty($item_title)) { - $item_title = __('MTBF'); - } - reporting_header_content($mini, $content, $report, $table, $item_title, - ui_print_truncate_text($agent_name, 'agent_medium', false) . - '
'.ui_print_truncate_text($module_name, 'module_medium', false)); - - // Put description at the end of the module (if exists) - $table->colspan[1][0] = 3; - if ($content["description"] != "") { - $data_desc = array(); - $data_desc[0] = $content["description"]; - array_push ($table->data, $data_desc); - } - - $data = array (); - $table->colspan[2][0] = 3; - $mtbf = reporting_get_agentmodule_mtbf ($content['id_agent_module'], $content['period'], $report["datetime"]); - if ($mtbf === false) { - $mtbf = __('Unknown'); - } - else if ($mtbf != 0) { - $mtbf = human_time_description_raw ($mtbf); - } - - $data = array (); - $table->colspan[2][0] = 3; - $data[0] = '

'.$mtbf.'

'; - array_push ($table->data, $data); - break; - case 'MTTR': - if (empty($item_title)) { - $item_title = __('MTTR'); - } - reporting_header_content($mini, $content, $report, $table, $item_title, - ui_print_truncate_text($agent_name, 'agent_medium', false) . - '
'.ui_print_truncate_text($module_name, 'module_medium', false)); - - // Put description at the end of the module (if exists) - $table->colspan[1][0] = 3; - if ($content["description"] != "") { - $data_desc = array(); - $data_desc[0] = $content["description"]; - array_push ($table->data, $data_desc); - } - - $data = array (); - $table->colspan[2][0] = 3; - $mttr = reporting_get_agentmodule_mttr ($content['id_agent_module'], $content['period'], $report["datetime"]); - if ($mttr === false) { - $mttr = __('Unknown'); - } - else if ($mttr != 0) { - $mttr = human_time_description_raw ($mttr); - } - - $data = array (); - $table->colspan[2][0] = 3; - $data[0] = '

'.$mttr.'

'; - array_push ($table->data, $data); - break; - case 'group_report': - $group_name = groups_get_name($content['id_group'], true); - $group_stats = reporting_get_group_stats($content['id_group']); - // Get events of the last 8 hours - $events = events_get_group_events ($content['id_group'], 28800, $report['datetime']); - - if ($events === false) { - $events = array(); - } - - if (empty($item_title)) { - $item_title = __('Group report').': "'.$group_name.'"'; - } - reporting_header_content($mini, $content, $report, $table, $item_title); - - $table->colspan[1][0] = 3; - - if ($content["description"] != "") { - $data_desc = array(); - $data_desc[0] = $content["description"]; - array_push ($table->data, $data_desc); - } - - $table->colspan[2][0] = 3; - - $table->data[2][0] = - " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
" . - __('Total') . "
" . - __('Unknown') . "
" . - __('Agents') . "
" . - $group_stats['total_agents'] . "
" . - $group_stats['agents_unknown'] . "
" . - __('Total') . "
" . - __('Normal') . "
" . - __('Critical') . "
" . - __('Warning') . "
" . - __('Unknown') . "
" . - __('Not init') . "
" . - __('Monitors') . "
" . - $group_stats['monitor_checks'] . "
" . - $group_stats['monitor_ok'] ."
" . - $group_stats['monitor_critical'] . "
" . - $group_stats['monitor_warning'] . "
" . - $group_stats['monitor_unknown'] . "
" . - $group_stats['monitor_not_init'] . "
" . - __('Defined') . "
" . - __('Fired') . "
" . - __('Alerts') . "
" . - $group_stats['monitor_alerts'] . "
" . - $group_stats['monitor_alerts_fired'] . "
" . - __('Last 8 hours') . "
" . - __('Events') . "
" . - count($events)."
"; - - break; - case 'network_interfaces_report': - reporting_network_interfaces_table($content, $report, $mini, $item_title, $table); - break; - case 'general': - if (empty($item_title)) { - $item_title = __('General'); - } - reporting_header_content($mini, $content, $report, $table, $item_title); - - $group_by_agent = $content['group_by_agent']; - $order_uptodown = $content['order_uptodown']; - - $table->style[1] = 'text-align: right'; - - // Put description at the end of the module (if exists) - $table->colspan[1][0] = 3; - if ($content["description"] != "") { - $data_desc = array(); - $data_desc[0] = $content["description"]; - array_push($table->data, $data_desc); - } - - switch ($group_by_agent) { - //0 means not group by agent - case 0: - $sql = sprintf(" - SELECT id_agent_module, - server_name, operation - FROM treport_content_item - WHERE id_report_content = %d", - $content['id_rc']); - - $generals = db_process_sql ($sql); - if ($generals === false) { - $data = array (); - $table->colspan[2][0] = 3; - $data[0] = - __('There are no Agent/Modules defined'); - array_push ($table->data, $data); - break; - } - - $table1->width = '99%'; - $table1->data = array (); - $table1->head = array (); - $table1->head[0] = __('Agent'); - $table1->head[1] = __('Module'); - if ($content['period'] != 0) { - $table1->head[2] = __('Operation'); - } - $table1->head[3] = __('Value'); - $table1->style[0] = 'text-align: left'; - $table1->style[1] = 'text-align: left'; - $table1->style[2] = 'text-align: left'; - $table1->style[3] = 'text-align: left'; - - $data_res = array(); - - foreach ($generals as $key => $row) { - //Metaconsole connection - $server_name = $row ['server_name']; - if (($config ['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE')) { - $connection = metaconsole_get_connection($server_name); - if (metaconsole_load_external_db($connection) != NOERR) { - //ui_print_error_message ("Error connecting to ".$server_name); - continue; - } - } - - if (modules_is_disable_agent($row['id_agent_module'])) { - continue; - } - - $mod_name = modules_get_agentmodule_name ($row['id_agent_module']); - $ag_name = modules_get_agentmodule_agent_name ($row['id_agent_module']); - - if ($content['period'] == 0) { - $data_res[$key] = - modules_get_last_value($row['id_agent_module']); - } - else { - switch ($row['operation']) { - case 'sum': - $data_res[$key] = - reporting_get_agentmodule_data_sum( - $row['id_agent_module'], $content['period'], $report["datetime"]); - break; - case 'max': - $data_res[$key] = - reporting_get_agentmodule_data_max( - $row['id_agent_module'], $content['period']); - break; - case 'min': - $data_res[$key] = - reporting_get_agentmodule_data_min( - $row['id_agent_module'], $content['period']); - break; - case 'avg': - default: - $data_res[$key] = - reporting_get_agentmodule_data_average( - $row['id_agent_module'], $content['period']); - break; - } - } - - $unit = db_get_value('unit', 'tagente_modulo', - 'id_agente_modulo', - $row['id_agent_module']); - - $id_agent_module[$key] = $row['id_agent_module']; - $agent_name[$key] = $ag_name; - $module_name[$key] = $mod_name; - $units[$key] = $unit; - $operations[$key] = $row['operation']; - - //Restore dbconnection - if (($config ['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE')) { - metaconsole_restore_db(); - } - } - //Order by data descending, ascending or without order - if (($order_uptodown == 0) || ($order_uptodown == 1) - || ($order_uptodown == 2)) { - - - switch ($order_uptodown) { - //Descending - case 1: - array_multisort($data_res, SORT_DESC, - $agent_name, SORT_ASC, $module_name, - SORT_ASC, $id_agent_module, - SORT_ASC, $operations, SORT_ASC); - break; - //Ascending - case 2: - array_multisort($data_res, SORT_ASC, - $agent_name, SORT_ASC, $module_name, - SORT_ASC, $id_agent_module, - SORT_ASC, $operations, SORT_ASC); - break; - } - - - $i = 0; - foreach ($data_res as $d) { - $data = array(); - $data[0] = $agent_name[$i]; - $data[1] = $module_name[$i]; - - if ($content['period'] != 0) { - switch ($operations[$i]) { - case 'sum': - $op = __('Summatory'); - break; - case 'min': - $op = __('Minimal'); - break; - case 'max': - $op = __('Maximun'); - break; - case 'avg': - default: - $op = __('Rate'); - break; - } - $data[2] = $op; - } - - if ($d === false) { - $data[3] = '--'; - } - else { - if (!is_numeric($d)) { - $data[3] = $d; - } - else { - $data[3] = format_for_graph($d, 2) . " " . - $units[$i]; - } - } - array_push ($table1->data, $data); - $i++; - } - } - //Order by agent name - elseif ($order_uptodown == 3) { - array_multisort($agent_name, SORT_ASC, - $data_res, SORT_ASC, $module_name, SORT_ASC, - $id_agent_module, SORT_ASC, $operations, - SORT_ASC); - $i=0; - foreach ($agent_name as $a) { - $data = array(); - $data[0] = $agent_name[$i]; - $data[1] = $module_name[$i]; - - switch ($operations[$i]) { - case 'sum': - $op = __('Summatory'); - break; - case 'min': - $op = __('Minimal'); - break; - case 'max': - $op = __('Maximun'); - break; - case 'avg': - default: - $op = __('Average'); - break; - } - $data[2] = $op; - - - if ($data_res[$i] === false) { - $data[3] = '--'; - } - else { - $data[3] = - format_for_graph($data_res[$i], 2) - . " " . $units[$i]; - } - array_push ($table1->data, $data); - $i++; - } - } - - $table->colspan[2][0] = 3; - $data = array(); - $data[0] = html_print_table($table1, true); - array_push ($table->data, $data); - break; - //1 means group by agent - case 1: - //Get the data - $sql_data = sprintf("SELECT id_agent_module, - server_name, operation - FROM treport_content_item - WHERE id_report_content = %d", - $content['id_rc']); - $generals = db_process_sql ($sql_data); - - if ($generals === false) { - $data = array (); - $table->colspan[2][0] = 3; - $data[0] = __('There are no Agent/Modules defined'); - array_push ($table->data, $data); - break; - } - - $list_modules = array(); - $data = array(); - foreach ($generals as $g) { - //Metaconsole connection - $server_name = $g ['server_name']; - if (($config ['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE')) { - $connection = metaconsole_get_connection($server_name); - if (metaconsole_load_external_db($connection) != NOERR) { - //ui_print_error_message ("Error connecting to ".$server_name); - continue; - } - } - - if (modules_is_disable_agent($g['id_agent_module'])) { - continue; - } - - $agent_name = modules_get_agentmodule_agent_name ($g['id_agent_module']); - $module_name = modules_get_agentmodule_name ($g['id_agent_module']); - $unit = db_get_value('unit', 'tagente_modulo', 'id_agente_modulo', $g['id_agent_module']); - - - - - if ($content['period'] == 0) { - $value_res = - modules_get_last_value($g['id_agent_module']); - } - else { - switch ($g['operation']) { - case 'sum': - $value_res = reporting_get_agentmodule_data_sum ($g['id_agent_module'], $content['period'], $report["datetime"]); - break; - case 'max': - $value_res = reporting_get_agentmodule_data_max ($g['id_agent_module'], $content['period']); - break; - case 'min': - $value_res = reporting_get_agentmodule_data_min ($g['id_agent_module'], $content['period']); - break; - case 'avg': - default: - $value_res = reporting_get_agentmodule_data_average ($g['id_agent_module'], $content['period']); - break; - } - } - - if ($value_res === false) { - $data[$agent_name][$module_name] = '--'; - } - else { - if (!is_numeric($value_res)) { - $data[$agent_name][$module_name] = $value_res; - } - else { - $data[$agent_name][$module_name] = format_for_graph($value_res, 2) . " " . $unit; - } - } - - // Save the modules - $list_modules[$module_name] = null; - - // Restore dbconnection - if (($config ['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE')) { - metaconsole_restore_db(); - } - } - - $table2->width = '99%'; - $table2->data = array (); - $table2->head = array (); - $table2->head[0] = __('Agent'); - $table2->style[0] = 'text-align: left'; - $i = 1; - foreach (array_keys($list_modules) as $module) { - $table2->head[$i] = - ui_print_truncate_text($module, 20, false); - $table2->style[$i] = 'text-align: center'; - $i++; - } - - - - foreach ($data as $agent_name => $agent) { - $row = array(); - $row[] = $agent_name; - foreach (array_keys($list_modules) as $module_name) { - if (!isset($agent[$module_name])) { - $row[] = '--'; - } - else { - $row[] = $agent[$module_name]; - } - } - $table2->data[] = $row; - } - - $data = array(); - $data[0] = html_print_table($table2, true); - array_push ($table->data, $data); - break; - } - - if ($content['show_resume'] && count($generals) > 0) { - - //Get the first valid value and assign it to $min & $max - $min = false; - $min_name_agent_module = ''; - $max_name_agent_module = ''; - $min_unit = ''; - $max_unit = ''; - $i=0; - do { - //Metaconsole connection - $server_name = $generals[$i]['server_name']; - if (($config ['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE')) { - $connection = metaconsole_get_connection($server_name); - if (metaconsole_load_external_db($connection) != NOERR) { - //ui_print_error_message ("Error connecting to ".$server_name); - continue; - } - } - - if ($content['period'] == 0) { - $min = - modules_get_last_value($generals[$i]['id_agent_module']); - } - else { - switch ($generals[$i]['operation']) { - case 'sum': - $min = reporting_get_agentmodule_data_sum ($generals[$i]['id_agent_module'], $content['period'], $report["datetime"]); - break; - case 'max': - $min = reporting_get_agentmodule_data_max ($generals[$i]['id_agent_module'], $content['period']); - break; - case 'min': - $min = reporting_get_agentmodule_data_min ($generals[$i]['id_agent_module'], $content['period']); - break; - case 'avg': - default: - $min = reporting_get_agentmodule_data_average ($generals[$i]['id_agent_module'], $content['period']); - break; - } - } - $i++; - - $min_name_agent_module = - modules_get_agentmodule_name($generals[$i]['id_agent_module']) . - " - " . - modules_get_agentmodule_agent_name($generals[$i]['id_agent_module']) . - " (" . $generals[$i]['operation'] . ")"; - - $min_unit = db_get_value('unit', 'tagente_modulo', 'id_agente_modulo', $generals[$i]['id_agent_module']); - - //Restore dbconnection - if (($config ['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE')) { - metaconsole_restore_db(); - } - } - while ($min === false && $i < count($generals)); - - $max = $min; - $max_name_agent_module = $min_name_agent_module; - $max_unit = $min_unit; - $avg = 0; - $length = 0; - - if ($generals === false) { - $generals = array(); - } - - foreach ($generals as $g) { - //Metaconsole connection - $server_name = $g['server_name']; - if (($config ['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE')) { - $connection = metaconsole_get_connection($server_name); - if (metaconsole_load_external_db($connection) != NOERR) { - //ui_print_error_message ("Error connecting to ".$server_name); - continue; - } - } - - if ($content['period'] == 0) { - $value = - modules_get_last_value($g['id_agent_module']); - } - else { - switch ($g['operation']) { - case 'sum': - $value = reporting_get_agentmodule_data_sum ($g['id_agent_module'], $content['period'], $report["datetime"]); - break; - case 'max': - $value = reporting_get_agentmodule_data_max ($g['id_agent_module'], $content['period']); - break; - case 'min': - $value = reporting_get_agentmodule_data_min ($g['id_agent_module'], $content['period']); - break; - case 'avg': - default: - $value = reporting_get_agentmodule_data_average ($g['id_agent_module'], $content['period']); - break; - } - } - - if ($value !== false) { - if ($value > $max) { - $max = $value; - $max_name_agent_module = - modules_get_agentmodule_name($g['id_agent_module']) . - " - " . - modules_get_agentmodule_agent_name($g['id_agent_module']) . - " (" . $g['operation'] . ")"; - $max_unit = db_get_value('unit', 'tagente_modulo', 'id_agente_modulo', $g['id_agent_module']); - } - if ($value < $min ) { - $min = $value; - $min_name_agent_module = - modules_get_agentmodule_name($g['id_agent_module']) . - " - " . - modules_get_agentmodule_agent_name($g['id_agent_module']) . - " (" . $g['operation'] . ")"; - $min_unit = db_get_value('unit', 'tagente_modulo', 'id_agente_modulo', $g['id_agent_module']); - } - $avg += $value; - $length++; - } - - //Restore dbconnection - if (($config ['metaconsole'] == 1) - && $server_name != '' - && defined('METACONSOLE')) { - metaconsole_restore_db(); - } - } - if ($length == 0) { - $avg = 0; - } - else { - $avg = $avg / $length; - } - - unset($table_summary); - $table_summary->width = '99%'; - - $table_summary->data = array (); - $table_summary->head = array (); - $table_summary->head_colspan = array (); - $table_summary->align = array(); - - $table_summary->align[0] = 'left'; - $table_summary->align[1] = 'left'; - $table_summary->align[2] = 'left'; - $table_summary->align[3] = 'left'; - $table_summary->align[4] = 'left'; - - $table_summary->head_colspan[0] = 2; - $table_summary->head[0] = __('Min Value'); - $table_summary->head[1] = __('Average Value'); - $table_summary->head_colspan[2] = 2; - $table_summary->head[2] = __('Max Value'); - - $table_summary->data[0][0] = $min_name_agent_module; - $table_summary->data[0][1] = format_for_graph($min,2) . ' ' . $min_unit; - $table_summary->data[0][2] = format_for_graph($avg,2); - $table_summary->data[0][3] = $max_name_agent_module; - $table_summary->data[0][4] = format_for_graph($max,2) . ' ' . $max_unit; - - $table->colspan[3][0] = 3; - array_push ($table->data, - array('' . __('Summary') . '')); - $table->colspan[4][0] = 3; - array_push ($table->data, - array(html_print_table($table_summary, true))); - } - break; - - - case 'top_n': - $top_n = $content['top_n']; - - switch ($top_n) { - case REPORT_TOP_N_MAX: - $type_top_n = __('Max'); - break; - case REPORT_TOP_N_MIN: - $type_top_n = __('Min'); - break; - case REPORT_TOP_N_AVG: - default: - //If nothing is selected then it will be shown the average data - $type_top_n = __('Avg'); - break; - } - - if (empty($item_title)) { - $item_title = 'Top '.$content['top_n_value'] . '
' . $type_top_n; - } - reporting_header_content($mini, $content, $report, $table, $item_title); - - $order_uptodown = $content['order_uptodown']; - - $top_n_value = $content['top_n_value']; - $show_graph = $content['show_graph']; - - $table->style[0] = 'padding: 8px 5px 8px 5px;'; - $table->style[1] = 'text-align: right'; - - // Put description at the end of the module (if exists) - $table->colspan[1][0] = 3; - if ($content["description"] != "") { - $data_desc = array(); - $data_desc[0] = $content["description"]; - array_push ($table->data, $data_desc); - } - //Get all the related data - $sql = sprintf("SELECT id_agent_module, server_name - FROM treport_content_item - WHERE id_report_content = %d", $content['id_rc']); - - $tops = db_process_sql ($sql); - - if ($tops === false) { - $data = array (); - $table->colspan[2][0] = 3; - $data[0] = __('There are no Agent/Modules defined'); - array_push ($table->data, $data); - break; - } - - if ($show_graph != REPORT_TOP_N_ONLY_GRAPHS) { - $table1->width = '99%'; - $table1->data = array (); - $table1->head = array (); - $table1->head[0] = __('Agent'); - $table1->head[1] = __('Module'); - $table1->head[2] = __('Value'); - $table1->style[0] = 'text-align: left'; - $table1->style[1] = 'text-align: left'; - $table1->style[2] = 'text-align: left'; - } - - //Get data of all agents (before to slide to N values) - $data_top = array(); - - foreach ($tops as $key => $row) { - - //Metaconsole connection - $server_name = $row['server_name']; - if (($config ['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE')) { - $connection = metaconsole_get_connection($server_name); - if (metaconsole_load_external_db($connection) != NOERR) { - //ui_print_error_message ("Error connecting to ".$server_name); - continue; - } - } - - $ag_name = modules_get_agentmodule_agent_name($row ['id_agent_module']); - $mod_name = modules_get_agentmodule_name ($row ['id_agent_module']); - $unit = db_get_value('unit', 'tagente_modulo', - 'id_agente_modulo', $row ['id_agent_module']); - - - switch ($top_n) { - case REPORT_TOP_N_MAX: - $value = reporting_get_agentmodule_data_max ($row['id_agent_module'], $content['period']); - break; - case REPORT_TOP_N_MIN: - $value = reporting_get_agentmodule_data_min ($row['id_agent_module'], $content['period']); - break; - case REPORT_TOP_N_AVG: - default: - //If nothing is selected then it will be shown the average data - $value = reporting_get_agentmodule_data_average ($row['id_agent_module'], $content['period']); - break; - } - - //If the returned value from modules_get_agentmodule_data_max/min/avg is false it won't be stored. - if ($value !== false) { - $data_top[$key] = $value; - $id_agent_module[$key] = $row['id_agent_module']; - $agent_name[$key] = $ag_name; - $module_name[$key] = $mod_name; - $units[$key] = $unit; - } - - //Restore dbconnection - if (($config ['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE')) { - metaconsole_restore_db(); - } - } - - if (empty($data_top)) { - $data = array (); - $table->colspan[2][0] = 3; - $data[0] = __('Insuficient data'); - array_push ($table->data, $data); - break; - } - - //Order to show. - switch ($order_uptodown) { - //Descending - case 1: - array_multisort($data_top, SORT_DESC, $agent_name, SORT_ASC, $module_name, SORT_ASC, $id_agent_module, SORT_ASC, $units, SORT_ASC); - break; - //Ascending - case 2: - array_multisort($data_top, SORT_ASC, $agent_name, SORT_ASC, $module_name, SORT_ASC, $id_agent_module, SORT_ASC, $units, SORT_ASC); - break; - //By agent name or without selection - case 0: - case 3: - array_multisort($agent_name, SORT_ASC, $data_top, SORT_ASC, $module_name, SORT_ASC, $id_agent_module, SORT_ASC, $units, SORT_ASC); - break; - } - - array_splice ($data_top, $top_n_value); - array_splice ($agent_name, $top_n_value); - array_splice ($module_name, $top_n_value); - array_splice ($id_agent_module, $top_n_value); - array_splice ($units, $top_n_value); - - $data_top_values = array (); - $data_top_values['data_top'] = $data_top; - $data_top_values['agent_name'] = $agent_name; - $data_top_values['module_name'] = $module_name; - $data_top_values['id_agent_module'] = $id_agent_module; - $data_top_values['units'] = $units; - - // Define truncate size depends the graph width - $truncate_size = $sizgraph_w / (4 * ($config['font_size']))-1; - - if ($order_uptodown == 1 || $order_uptodown == 2) { - $i = 0; - $data_pie_graph = array(); - $data_hbar = array(); - foreach ($data_top as $dt) { - $item_name = ''; - $item_name = - ui_print_truncate_text($agent_name[$i], $truncate_size, false, true, false, "...") . - ' - ' . - ui_print_truncate_text($module_name[$i], $truncate_size, false, true, false, "..."); - - - - //Dirty hack, maybe I am going to apply a job in Apple - //https://www.imperialviolet.org/2014/02/22/applebug.html - $item_name_key_pie = $item_name; - $exist_key = true; - while ($exist_key) { - if (isset($data_pie_graph[$item_name_key_pie])) { - $item_name_key_pie .= ' '; - } - else { - $exist_key = false; - } - } - $item_name_key_hbar = $item_name; - $exist_key = true; - while ($exist_key) { - if (isset($data_hbar[$item_name_key_hbar])) { - $item_name_key_hbar = ' ' . $item_name_key_hbar; - } - else { - $exist_key = false; - } - } - - - - $data_hbar[$item_name]['g'] = $dt; - $data_pie_graph[$item_name] = $dt; - - if ($show_graph == 0 || $show_graph == 1) { - $data = array(); - $data[0] = $agent_name[$i]; - $data[1] = $module_name[$i]; - - $data[2] = format_for_graph($dt,2) . " " . $units[$i]; - array_push ($table1->data, $data); - } - $i++; - if ($i >= $top_n_value) break; - } - } - else if ($order_uptodown == 0 || $order_uptodown == 3) { - $i = 0; - $data_pie_graph = array(); - $data_hbar = array(); - foreach ($agent_name as $an) { - $item_name = ''; - $item_name = - ui_print_truncate_text($agent_name[$i], - $truncate_size, false, true, false, "...") . - ' - ' . - ui_print_truncate_text($module_name[$i], - $truncate_size, false, true, false, "..."); - - - - //Dirty hack, maybe I am going to apply a job in Apple - //https://www.imperialviolet.org/2014/02/22/applebug.html - $item_name_key_pie = $item_name; - $exist_key = true; - while ($exist_key) { - if (isset($data_pie_graph[$item_name_key_pie])) { - $item_name_key_pie .= ' '; - } - else { - $exist_key = false; - } - } - $item_name_key_hbar = $item_name; - $exist_key = true; - while ($exist_key) { - if (isset($data_hbar[$item_name_key_hbar])) { - $item_name_key_hbar = ' ' . $item_name_key_hbar; - } - else { - $exist_key = false; - } - } - - - - $data_pie_graph[$item_name] = $data_top[$i]; - $data_hbar[$item_name]['g'] = $data_top[$i]; - if ($show_graph == 0 || $show_graph == 1) { - $data = array(); - $data[0] = $an; - $data[1] = $module_name[$i]; - $data[2] = format_for_graph($data_top[$i],2) . " " . $units[$i]; - array_push ($table1->data, $data); - } - $i++; - if ($i >= $top_n_value) break; - } - } - - unset($data); - $table->colspan[2][0] = 3; - $table->style[2] = 'text-align:center'; - if ($show_graph == 0 || $show_graph == 1) { - $data = array(); - $data[0] = html_print_table($table1, true); - array_push ($table->data, $data); - } - - $table->colspan[3][0] = 3; - $data = array(); - if ($show_graph != REPORT_TOP_N_ONLY_TABLE) { - - $data[0] = pie3d_graph(false, $data_pie_graph, - $sizgraph_w, $sizgraph_h, __("other"), - ui_get_full_url(false, true, false, false) . '/', - ui_get_full_url(false, false, false, false) . "/images/logo_vertical_water.png", - $config['fontpath'], $config['font_size']); - - - array_push ($table->data, $data); - //Display bars graph - $table->colspan[4][0] = 3; - $table->style[0] .= 'text-align:center'; - $height = count($data_pie_graph)*20+35; - $data = array(); - $data[0] = hbar_graph(false, $data_hbar, $sizgraph_w, - $height, array(), array(), "", "", true, - ui_get_full_url(false, true, false, false) . '/', $config['homedir'] . "/images/logo_vertical_water.png", $config['fontpath'], $config['font_size'], true, 1, true); - - array_push ($table->data, $data); - } - - if ($content['show_resume'] && count($data_top_values) > 0) { - //Get the very first not null value - $i=0; - do { - $min = $data_top_values['data_top'][$i]; - $i++; - } - while ($min === false && $i < count($data_top_values)); - $max = $min; - $avg = 0; - - $i=0; - foreach ($data_top_values['data_top'] as $key => $dtv) { - if ($dtv < $min) $min = $dtv; - if ($dtv > $max) $max = $dtv; - $avg += $dtv; - $i++; - } - $avg = $avg / $i; - - unset($table_summary); - - $table_summary->width = '99%'; - $table_summary->data = array (); - $table_summary->head = array (); - $table_summary->head[0] = __('Min Value'); - $table_summary->head[1] = __('Average Value'); - $table_summary->head[2] = __('Max Value'); - - $table_summary->data[0][0] = format_for_graph($min, 2); - $table_summary->data[0][1] = format_for_graph($avg, 2); - $table_summary->data[0][2] = format_for_graph($max, 2); - - $table->colspan[5][0] = 3; - array_push ($table->data, array(''.__('Summary').'')); - $table->colspan[6][0] = 3; - array_push ($table->data, array(html_print_table($table_summary, true))); - } - break; - case 'exception': - $order_uptodown = $content['order_uptodown']; - $exception_condition = $content['exception_condition']; - $exception_condition_value = $content['exception_condition_value']; - $show_graph = $content['show_graph']; - - $table->style[1] = 'text-align: right'; - - switch ($exception_condition) { - case REPORT_EXCEPTION_CONDITION_EVERYTHING: - $title_exeption = __('Exception - Everything'); - break; - case REPORT_EXCEPTION_CONDITION_GE: - $title_exeption = - sprintf(__('Exception - Modules over or equal to %s'), - $exception_condition_value); - break; - case REPORT_EXCEPTION_CONDITION_LE: - $title_exeption = - sprintf(__('Exception - Modules under or equal to %s'), - $exception_condition_value); - break; - case REPORT_EXCEPTION_CONDITION_L: - $title_exeption = - sprintf(__('Exception - Modules under %s'), - $exception_condition_value); - break; - case REPORT_EXCEPTION_CONDITION_G: - $title_exeption = - sprintf(__('Exception - Modules over %s'), - $exception_condition_value); - break; - case REPORT_EXCEPTION_CONDITION_E: - $title_exeption = - sprintf(__('Exception - Equal to %s'), - $exception_condition_value); - break; - case REPORT_EXCEPTION_CONDITION_NE: - $title_exeption = - sprintf(__('Exception - Not equal to %s'), - $exception_condition_value); - break; - case REPORT_EXCEPTION_CONDITION_OK: - $title_exeption = - __('Exception - Modules at normal status'); - break; - case REPORT_EXCEPTION_CONDITION_NOT_OK: - $title_exeption = - __('Exception - Modules at critical or warning status'); - break; - } - - if (empty($item_title)) { - $item_title = $title_exeption; - } - reporting_header_content($mini, $content, $report, $table, $item_title); - - // Put description at the end of the module (if exists) - $table->colspan[1][0] = 3; - if ($content["description"] != "") { - $data_desc = array(); - $data_desc[0] = $content["description"]; - array_push ($table->data, $data_desc); - } - //Get all the related data - $sql = sprintf(" - SELECT id_agent_module, server_name, operation - FROM treport_content_item - WHERE id_report_content = %d", $content['id_rc']); - - $exceptions = db_process_sql ($sql); - if ($exceptions === false) { - $data = array (); - $table->colspan[2][0] = 3; - $data[0] = __('There are no Agent/Modules defined'); - array_push ($table->data, $data); - break; - } - - if ($show_graph == 0 || $show_graph == 1) { - $table1->width = '99%'; - $table1->data = array (); - $table1->head = array (); - $table1->head[0] = __('Agent'); - $table1->head[1] = __('Module'); - $table1->head[2] = __('Operation'); - $table1->head[3] = __('Value'); - $table1->style[0] = 'text-align: left'; - $table1->style[1] = 'text-align: left'; - $table1->style[2] = 'text-align: left'; - $table1->style[3] = 'text-align: left'; - } - - //Get the very first not null value - $i=0; - do { - //Metaconsole connection - $server_name = $exceptions[$i]['server_name']; - if (($config ['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE')) { - $connection = metaconsole_get_connection($server_name); - if (metaconsole_load_external_db($connection) != NOERR) { - //ui_print_error_message ("Error connecting to ".$server_name); - continue; - } - } - - if ($content['period'] == 0) { - $min = - modules_get_last_value($exceptions[$i]['id_agent_module']); - } - else { - switch ($exceptions[$i]['operation']) { - case 'avg': - $min = reporting_get_agentmodule_data_average( - $exceptions[$i]['id_agent_module'], $content['period']); - break; - case 'max': - $min = reporting_get_agentmodule_data_max( - $exceptions[$i]['id_agent_module'], $content['period']); - break; - case 'min': - $min = reporting_get_agentmodule_data_min( - $exceptions[$i]['id_agent_module'], $content['period']); - break; - } - } - $i++; - - //Restore dbconnection - if (($config ['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE')) { - metaconsole_restore_db(); - } - } - while ($min === false && $i < count($exceptions)); - $max = $min; - $avg = 0; - - $i=0; - foreach ($exceptions as $exc) { - //Metaconsole connection - $server_name = $exc['server_name']; - if (($config ['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE')) { - $connection = metaconsole_get_connection($server_name); - if (metaconsole_load_external_db($connection) != NOERR) { - //ui_print_error_message ("Error connecting to ".$server_name); - continue; - } - } - - $ag_name = modules_get_agentmodule_agent_name ($exc ['id_agent_module']); - $mod_name = modules_get_agentmodule_name ($exc ['id_agent_module']); - $unit = db_get_value('unit', 'tagente_modulo', - 'id_agente_modulo', $exc['id_agent_module']); - - if ($content['period'] == 0) { - $value = - modules_get_last_value($exceptions[$i]['id_agent_module']); - } - else { - switch ($exc['operation']) { - case 'avg': - $value = reporting_get_agentmodule_data_average ($exc['id_agent_module'], $content['period']); - break; - case 'max': - $value = reporting_get_agentmodule_data_max ($exc['id_agent_module'], $content['period']); - break; - case 'min': - $value = reporting_get_agentmodule_data_min ($exc['id_agent_module'], $content['period']); - break; - } - } - - if ($value !== false) { - if ($value > $max) $max = $value; - if ($value < $min) $min = $value; - $avg += $value; - - //Skips - switch ($exception_condition) { - case REPORT_EXCEPTION_CONDITION_EVERYTHING: - break; - case REPORT_EXCEPTION_CONDITION_GE: - if ($value < $exception_condition_value) { - continue 2; - } - break; - case REPORT_EXCEPTION_CONDITION_LE: - if ($value > $exception_condition_value) { - continue 2; - } - break; - case REPORT_EXCEPTION_CONDITION_L: - if ($value > $exception_condition_value) { - continue 2; - } - break; - case REPORT_EXCEPTION_CONDITION_G: - if ($value < $exception_condition_value) { - continue 2; - } - break; - case REPORT_EXCEPTION_CONDITION_E: - if ($value != $exception_condition_value) { - continue 2; - } - break; - case REPORT_EXCEPTION_CONDITION_NE: - if ($value == $exception_condition_value) { - continue 2; - } - break; - case REPORT_EXCEPTION_CONDITION_OK: - if (modules_get_agentmodule_status($exc['id_agent_module']) != 0) { - continue 2; - } - break; - case REPORT_EXCEPTION_CONDITION_NOT_OK: - if (modules_get_agentmodule_status($exc['id_agent_module']) == 0) { - continue 2; - } - break; - } - - $i++; - $data_exceptions[] = $value; - $id_agent_module[] = $exc['id_agent_module']; - $agent_name[] = $ag_name; - $module_name[] = $mod_name; - $units[] = $unit; - if ($exc['operation'] == 'avg') { - $operation[] = "rate"; - } - else { - $operation[] = $exc['operation']; - } - } - //Restore dbconnection - if (($config ['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE')) { - metaconsole_restore_db(); - } - } - - //$i <= 0 means that there are no rows on the table, therefore no modules under the conditions defined. - if ($i <= 0) { - $data = array (); - $table->colspan[2][0] = 3; - $data[0] = __('There are no'); - - switch ($exception_condition) { - case REPORT_EXCEPTION_CONDITION_EVERYTHING: - $data[0] .= ' '.__('Modules under those conditions'); - break; - case REPORT_EXCEPTION_CONDITION_GE: - $data[0] .= ' '.__('Modules over or equal to').' '.$exception_condition_value; - break; - case REPORT_EXCEPTION_CONDITION_LE: - $data[0] .= ' '.__('Modules less or equal to').' '.$exception_condition_value; - break; - case REPORT_EXCEPTION_CONDITION_L: - $data[0] .= ' '.__('Modules less').' '.$exception_condition_value; - break; - case REPORT_EXCEPTION_CONDITION_G: - $data[0] .= ' '.__('Modules over').' '.$exception_condition_value; - break; - case REPORT_EXCEPTION_CONDITION_E: - $data[0] .= ' '.__('Modules equal to').' '.$exception_condition_value; - break; - case REPORT_EXCEPTION_CONDITION_NE: - $data[0] .= ' '.__('Modules not equal to').' '.$exception_condition_value; - break; - case REPORT_EXCEPTION_CONDITION_OK: - $data[0] .= ' '.__('Modules normal status'); - break; - case REPORT_EXCEPTION_CONDITION_NOT_OK: - $data[0] .= ' '.__('Modules at critial or warning status'); - break; - } - - - array_push ($table->data, $data); - break; - } - //$i > 0 means that there is at least one row on the table - elseif ($i > 0) { - $avg = $avg / $i; - - switch ($order_uptodown) { - //Order descending - case 1: - array_multisort($data_exceptions, SORT_DESC, $agent_name, SORT_ASC, $module_name, SORT_ASC, $id_agent_module, SORT_ASC); - break; - //Order ascending - case 2: - array_multisort($data_exceptions, SORT_ASC, $agent_name, SORT_ASC, $module_name, SORT_ASC, $id_agent_module, SORT_ASC); - break; - //Order by agent name or without selection - case 0: - case 3: - array_multisort($agent_name, SORT_ASC, $data_exceptions, SORT_ASC, $module_name, SORT_ASC, $id_agent_module, SORT_ASC); - break; - } - - if ($order_uptodown == 1 || $order_uptodown == 2) { - $j = 0; - $data_pie_graph = array(); - $data_hbar = array(); - foreach ($data_exceptions as $dex) { - $data_hbar[$agent_name[$j]]['g'] = $dex; - $data_pie_graph[$agent_name[$j]] = $dex; - if ($show_graph == 0 || $show_graph == 1) { - $data = array(); - $data[0] = $agent_name[$j]; - $data[1] = $module_name[$j]; - $data[2] = __($operation[$j]); - $data[3] = format_for_graph($dex, 2) . " " . $units[$j]; - array_push ($table1->data, $data); - } - $j++; - } - } - else if ($order_uptodown == 0 || $order_uptodown == 3) { - $j = 0; - $data_pie_graph = array(); - $data_hbar = array(); - foreach ($agent_name as $an) { - $data_hbar[$an]['g'] = $data_exceptions[$j]; - $data_pie_graph[$an] = $data_exceptions[$j]; - if ($show_graph == 0 || $show_graph == 1) { - $data = array(); - $data[0] = $an; - $data[1] = $module_name[$j]; - $data[2] = __($operation[$j]); - $data[3] = format_for_graph($data_exceptions[$j], 2) . " " . $units[$j]; - array_push ($table1->data, $data); - } - $j++; - } - } - } - - $table->colspan[2][0] = 3; - $table->cellstyle[2][0] = 'text-align: center;'; - if ($show_graph == 0 || $show_graph == 1) { - $data = array(); - $data[0] = html_print_table($table1, true); - array_push ($table->data, $data); - } - - $table->colspan[3][0] = 3; - $table->cellstyle[3][0] = 'text-align: center;'; - - $data = array(); - if ($show_graph == 1 || $show_graph == 2) { - $data[0] = pie3d_graph(false, $data_pie_graph, - 600, 150, __("other"), - ui_get_full_url(false, false, false, false), - ui_get_full_url(false, false, false, false) . "/images/logo_vertical_water.png", - $config['fontpath'], $config['font_size']); - array_push ($table->data, $data); - //Display bars graph - $table->colspan[4][0] = 3; - $table->cellstyle[4][0] = 'text-align: center;'; - $height = count($data_pie_graph) * 20 + 85; - $data = array(); - - $data[0] = hbar_graph(false, $data_hbar, 600, $height, - array(), array(), "", "", true, - ui_get_full_url(false, false, false, false), - ui_get_full_url(false, false, false, false) . "/images/logo_vertical_water.png", '', '', true, 1, true); - - array_push ($table->data, $data); - } - - if ($content['show_resume'] && $i>0) { - unset($table_summary); - - $table_summary->width = '99%'; - $table_summary->data = array (); - $table_summary->head = array (); - $table_summary->head[0] = __('Min Value'); - $table_summary->head[1] = __('Average Value'); - $table_summary->head[2] = __('Max Value'); - - $table_summary->data[0][0] = format_for_graph($min,2); - $table_summary->data[0][1] = format_for_graph($avg,2); - $table_summary->data[0][2] = format_for_graph($max,2); - - $table->colspan[5][0] = 3; - $table->cellstyle[5][0] = 'text-align: center;'; - array_push ($table->data, array(''.__('Summary').'')); - $table->colspan[6][0] = 3; - array_push ($table->data, array(html_print_table($table_summary, true))); - } - break; - case 'agent_module': - $group_name = groups_get_name($content['id_group']); - if ($content['id_module_group'] == 0) { - $module_group_name = __('All'); - } - else { - $module_group_name = db_get_value('name', 'tmodule_group', - 'id_mg', $content['id_module_group']); - } - - if (empty($item_title)) { - $item_title = __('Agents/Modules'); - } - reporting_header_content($mini, $content, $report, $table, $item_title, - $group_name . ' - ' . $module_group_name); - - $id_group = $content['id_group']; - $id_module_group = $content['id_module_group']; - $offset = get_parameter('offset', 0); - $block = 20; //Maximun number of modules displayed on the table - $modulegroup = get_parameter('modulegroup', 0); - $table->style[1] = 'text-align: right'; - - // Put description at the end of the module (if exists) - $table->colspan[1][0] = 3; - if ($content["description"] != "") { - $data_desc = array(); - $data_desc[0] = $content["description"]; - array_push ($table->data, $data_desc); - } - - $agents = ''; - if ($id_group > 0) { - $agents = agents_get_group_agents($id_group); - $agents = array_keys($agents); - } - - $filter_module_groups = false; - if ($id_module_group > 0) { - $filter_module_groups['id_module_group'] = $id_module_group; - } - - $all_modules = agents_get_modules ($agents, false, $filter_module_groups, true, false); - - $modules_by_name = array(); - $name = ''; - $cont = 0; - - foreach ($all_modules as $key => $module) { - if ($module == $name) { - $modules_by_name[$cont-1]['id'][] = $key; - } - else { - $name = $module; - $modules_by_name[$cont]['name'] = $name; - $modules_by_name[$cont]['id'][] = $key; - $cont ++; - } - } - - if ($config["pure"] == 1) { - $block = count($modules_by_name); - } - - $filter_groups = array ('offset' => (int) $offset, - 'limit' => (int) $config['block_size']); - - if ($id_group > 0) { - $filter_groups['id_grupo'] = $id_group; - } - - $agents = agents_get_agents ($filter_groups); - $nagents = count($agents); - - if ($all_modules == false || $agents == false) { - $data = array (); - $table->colspan[2][0] = 3; - $data[0] = __('There are no agents with modules'); - array_push ($table->data, $data); - break; - } - $table_data = ''; - - $table_data .= ""; - - $nmodules = 0; - foreach ($modules_by_name as $module) { - $nmodules++; - - $file_name = string2image(ui_print_truncate_text($module['name'], 'module_small', false, true, false, '...'), false, false, 6, 270, '#B1B1B1', 'FFF', 4, 0); - $table_data .= '"; - } - // Dont use pagination - /*if ($block < $nmodules) { - $table_data .= ""; - }*/ - - $filter_agents = false; - if ($id_group > 0) { - $filter_agents = array('id_grupo' => $id_group); - } - // Prepare pagination - ui_pagination ((int)count(agents_get_agents ($filter_agents))); - $table_data .= "
"; - - foreach ($agents as $agent) { - // Get stats for this group - $agent_status = agents_get_status($agent['id_agente']); - - switch($agent_status) { - case 4: // Alert fired status - $rowcolor = COL_ALERTFIRED; - $textcolor = '#000'; - break; - case 1: // Critical status - $rowcolor = COL_CRITICAL; - $textcolor = '#FFF'; - break; - case 2: // Warning status - $rowcolor = COL_WARNING; - $textcolor = '#000'; - break; - case 0: // Normal status - $rowcolor = COL_NORMAL; - $textcolor = '#FFF'; - break; - case 3: - case -1: - default: // Unknown status - $rowcolor = COL_UNKNOWN; - $textcolor = '#FFF'; - break; - } - - $table_data .= ""; - - $file_name = string2image(ui_print_truncate_text($agent['nombre'], 'agent_small', false, true, false, '...'), false, false, 6, 0, $rowcolor, $textcolor, 4, 0); - $table_data .= ""; - $agent_modules = agents_get_modules($agent['id_agente']); - - $nmodules = 0; - - foreach ($modules_by_name as $module) { - $nmodules++; - // Don't use pagination - /*if ($nmodules > $block) { - continue; - }*/ - - $match = false; - foreach($module['id'] as $module_id){ - if (!$match && array_key_exists($module_id,$agent_modules)) { - $status = modules_get_agentmodule_status($module_id); - $table_data .= ""; - $match = true; - } - } - - if (!$match) { - $table_data .= ""; - } - } - - $table_data .= ""; - } - - $table_data .= "
".__("Agents")." / ".__("Modules")."' . html_print_image($file_name, true, array('title' => $module['name']))."...
".html_print_image($file_name, true, array('title' => $agent['nombre'])).""; - $win_handle = dechex(crc32($module_id.$module["name"])); - $graph_type = return_graphtype (modules_get_agentmodule_type($module_id)); - - switch ($status) { - case 0: - $table_data .= ui_print_status_image ('module_ok.png', $module['name']." in ".$agent['nombre'].": ".__('NORMAL'), true, array('width' => '20px', 'height' => '20px')); - break; - case 1: - $table_data .= ui_print_status_image ('module_critical.png', $module['name']." in ".$agent['nombre'].": ".__('CRITICAL'), true, array('width' => '20px', 'height' => '20px')); - break; - case 2: - $table_data .= ui_print_status_image ('module_warning.png', $module['name']." in ".$agent['nombre'].": ".__('WARNING'), true, array('width' => '20px', 'height' => '20px')); - break; - case 3: - $table_data .= ui_print_status_image ('module_unknown.png', $module['name']." in ".$agent['nombre'].": ".__('UNKNOWN'), true, array('width' => '20px', 'height' => '20px')); - break; - case 4: - $table_data .= ui_print_status_image ('module_alertsfired.png', $module['name']." in ".$agent['nombre'].": ".__('ALERTS FIRED'), true, array('width' => '20px', 'height' => '20px')); - break; - } - $table_data .= "
"; - - $table_data .= "
"; - - $table_data .= ""; - $table_data .= ""; - $table_data .= ""; - $table_data .= ""; - $table_data .= ""; - $table_data .= ""; - $table_data .= ""; - $table_data .= "
" . __('Legend') . "
" . __("Orange cell when the module has fired alerts") . "
" . __("Red cell when the module has a critical status") . "
" . __("Yellow cell when the module has a warning status") . "
" . __("Green cell when the module has a normal status") . "
" . __("Grey cell when the module has an unknown status") . "
"; - $table_data .= "
"; - $data = array (); - $table->colspan[2][0] = 3; - $data[0] = $table_data; - array_push ($table->data, $data); - break; - case 'inventory': - if (empty($item_title)) { - $item_title = __('Inventory'); - } - reporting_header_content($mini, $content, $report, $table, $item_title); - - $es = json_decode($content['external_source'], true); - - $id_agent = $es['id_agents']; - $module_name = $es['inventory_modules']; - if (empty($module_name)) { - $module_name = array(0 => 0); - } - $date = $es['date']; - $description = $content['description']; - - $data = array (); - $table->colspan[1][0] = 2; - $table->colspan[2][0] = 2; - if ($description != '') { - $data[0] = $description; - array_push ($table->data, $data); - } - - $inventory_data = inventory_get_data((array)$id_agent,(array)$module_name,$date,'',false); - - if ($inventory_data == ERR_NODATA) { - $inventory_data = "
".__('No data found.')."
"; - $inventory_data .= " "; - } - - $data[0] = $inventory_data; - array_push ($table->data, $data); - break; - case 'inventory_changes': - if (empty($item_title)) { - $item_title = __('Inventory changes'); - } - reporting_header_content($mini, $content, $report, $table, $item_title); - - $es = json_decode($content['external_source'], true); - - $id_agent = $es['id_agents']; - $module_name = $es['inventory_modules']; - $description = $content['description']; - - $inventory_changes = inventory_get_changes($id_agent, $module_name, $report["datetime"] - $content['period'], $report["datetime"]); - - if ($inventory_changes == ERR_NODATA) { - $inventory_changes = "
".__('No changes found.')."
"; - $inventory_changes .= " "; - } - - $data = array (); - - $table->colspan[1][0] = 2; - - if ($description != '') { - $data[0] = $description; - array_push ($table->data, $data); - } - - $data[0] = $inventory_changes; - $table->colspan[2][0] = 2; - - array_push ($table->data, $data); - break; - case 'agent_configuration': - - if (empty($item_title)) { - $item_title = __('Agent configuration: ').$agent_name; - } - reporting_header_content($mini, $content, $report, $table, $item_title); - - $agent_name = agents_get_name ($content['id_agent']); - $modules = agents_get_modules ($content['id_agent']); - - $data= array (); - $table->colspan[0][1] = 10; - - //Agent's data - $data[0] = ''.__('Agent name').''; - $data[1] = ''.__('Group').''; - $data[2] = ''.__('SO').''; - $data[3] = ''.__('IP').''; - $data[4] = ''.__('Description').''; - $data[5] = ''.__('Status').''; - - $table->colspan[1][3] = 2; - $table->colspan[1][4] = 4; - $table->colspan[1][5] = 2; - $table->colspan[1][5] = 2; - array_push ($table->data, $data); - unset($data); - - $sql = "SELECT * FROM tagente WHERE id_agente=".$content['id_agent']; - $agent_data = db_get_row_sql($sql); - - $data[0] = $agent_data['nombre']; - $data[1] = ui_print_group_icon ($agent_data['id_grupo'], true, '', '', false); - $data[2] = ui_print_os_icon ($agent_data["id_os"], true, true); - $data[3] = $agent_data['direccion']; - $agent_data_comentarios = strip_tags(ui_bbcode_to_html($agent_data['comentarios'])); - $data[4] = $agent_data_comentarios; - - if ($agent_data['disabled'] == 0) - $data[5] = __('Enabled'); - else - $data[5] = __('Disabled'); - - $table->colspan[2][3] = 2; - $table->colspan[2][4] = 4; - $table->colspan[2][5] = 2; - array_push ($table->data, $data); - unset($data); - - //Agent's modules - if ($modules == null) { - $modules = array(); - } - else { - $data[0] = ''; - $data[1] = ''.agents_get_name ($content['id_agent'], 'upper').__(' MODULES').''; - $table->colspan[3][1] = 10; - - array_push ($table->data, $data); - unset($data); - - $data[0] = ''; - $data[1] = ''.__('Name').''; - $data[2] = ''.__('Type').''; - $data[3] = ''.__('Warning').'/'.'
'.__('Critical').'
'; - $data[4] = ''.__('Threshold').''; - $data[5] = ''.__('Group').''; - $data[6] = ''.__('Description').''; - $data[7] = ''.__('Interval').''; - $data[8] = ''.__('Unit').''; - $data[9] = ''.__('Status').''; - $data[10] = ''.__('Tags').''; - - $table->style[0] = 'width:10px'; - $table->style[1] = 'text-align: left'; - $table->style[2] = 'text-align: center'; - $table->style[3] = 'text-align: center'; - $table->style[4] = 'text-align: center'; - $table->style[5] = 'text-align: center'; - $table->style[6] = 'text-align: left'; - $table->style[7] = 'text-align: center'; - $table->style[8] = 'text-align: center'; - $table->style[9] = 'text-align: left'; - $table->style[10] = 'text-align: left'; - - array_push ($table->data, $data); - } - - foreach ($modules as $id_agent_module=>$module) { - $sql = "SELECT * FROM tagente_modulo WHERE id_agente_modulo=$id_agent_module"; - $data_module = db_get_row_sql($sql); - - $data = array(); - - $data[0] = ''; - - if ($data_module['disabled'] == 0) - $disabled = ''; - else - $disabled = ' (Disabled)'; - $data[1] = $data_module['nombre'].$disabled; - $data[2] = ui_print_moduletype_icon ($data_module['id_tipo_modulo'], true); - $data[3] = $data_module['max_warning'].'/'.$data_module['min_warning'].'
'.$data_module['max_critical'].'/'.$data_module['min_critical']; - $data[4] = $data_module['module_ff_interval']; - $data[5] = groups_get_name ($content['id_group'], true); - $data[6] = $data_module['descripcion']; - - if (($data_module['module_interval'] == 0) || ($data_module['module_interval'] == '')) - $data[7] = db_get_value('intervalo', 'tagente', 'id_agente', $content['id_agent']); - else - $data[7] = $data_module['module_interval']; - - - $data[8] = $data_module['unit']; - - $module_status = db_get_row('tagente_estado', 'id_agente_modulo', $id_agent_module); - modules_get_status($id_agent_module, $module_status['estado'], $module_status['datos'], $status, $title); - $data[9] = ui_print_status_image($status, $title, true); - - $sql_tag = "SELECT name - FROM ttag - WHERE id_tag IN ( - SELECT id_tag - FROM ttag_module - WHERE id_agente_modulo = $id_agent_module)"; - $tags = db_get_all_rows_sql($sql_tag); - if ($tags === false) - $tags = ''; - else - $tags = implode (",", $tags); - - $data[10] = $tags; - array_push ($table->data, $data); - } - - break; - case 'group_configuration': - $group_name = groups_get_name($content['id_group']); - if (empty($item_title)) { - $item_title = __('Group configuration: ').$group_name; - } - reporting_header_content($mini, $content, $report, $table, $item_title); - - $sql = "SELECT * FROM tagente WHERE id_grupo=".$content['id_group']; - $agents_list = db_get_all_rows_sql($sql); - if ($agents_list === false) - $agents_list = array(); - - $table->colspan[0][1] = 10; - - $i = 1; - foreach ($agents_list as $agent) { - $data= array (); - - $table->colspan[$i][3] = 2; - $table->colspan[$i][4] = 4; - $table->colspan[$i][5] = 2; - $table->colspan[$i][5] = 2; - - $i++; - - //Agent's data - $data[0] = ''.__('Agent name').''; - $data[1] = ''.__('Group').''; - $data[2] = ''.__('SO').''; - $data[3] = ''.__('IP').''; - $data[4] = ''.__('Description').''; - $data[5] = ''.__('Status').''; - - array_push ($table->data, $data); - unset($data); - - $sql = "SELECT * FROM tagente WHERE id_agente=".$agent['id_agente']; - $agent_data = db_get_row_sql($sql); - - $data[0] = $agent_data['nombre']; - $data[1] = ui_print_group_icon ($agent_data['id_grupo'], true, '', '', false); - $data[2] = ui_print_os_icon ($agent_data["id_os"], true, true); - $data[3] = $agent_data['direccion']; - $agent_data_comentarios = strip_tags(ui_bbcode_to_html($agent_data['comentarios'])); - $data[4] = $agent_data_comentarios; - - if ($agent_data['disabled'] == 0) - $data[5] = __('Enabled'); - else - $data[5] = __('Disabled'); - - $table->colspan[$i][3] = 2; - $table->colspan[$i][4] = 4; - $table->colspan[$i][5] = 2; - $table->colspan[$i][5] = 2; - - $i++; - - array_push ($table->data, $data); - unset($data); - - - - $modules = agents_get_modules ($agent['id_agente']); - - if ($modules == null) { - $modules = array(); - } - else { - - //Agent's modules - $data[0] = ''; - $data[1] = ''.agents_get_name ($agent['id_agente'], 'upper').__(' MODULES').''; - $table->colspan[$i][1] = 10; - - $i++; - - array_push ($table->data, $data); - unset($data); - - $data[0] = ''; - $data[1] = ''.__('Name').''; - $data[2] = ''.__('Type').''; - $data[3] = ''.__('Warning').'/'.'
'.__('Critical').'
'; - $data[4] = ''.__('Threshold').''; - $data[5] = ''.__('Group').''; - $data[6] = ''.__('Description').''; - $data[7] = ''.__('Interval').''; - $data[8] = ''.__('Unit').''; - $data[9] = ''.__('Status').''; - $data[10] = ''.__('Tags').''; - - $table->style[0] = 'width:10px'; - $table->style[1] = 'text-align: left'; - $table->style[2] = 'text-align: center'; - $table->style[3] = 'text-align: center'; - $table->style[4] = 'text-align: center'; - $table->style[5] = 'text-align: center'; - $table->style[6] = 'text-align: left'; - $table->style[7] = 'text-align: center'; - $table->style[8] = 'text-align: center'; - $table->style[9] = 'text-align: left'; - $table->style[10] = 'text-align: left'; - - array_push ($table->data, $data); - - $i++; - } - - foreach ($modules as $id_agent_module=>$module) { - $sql = "SELECT * - FROM tagente_modulo - WHERE id_agente_modulo=$id_agent_module"; - $data_module = db_get_row_sql($sql); - - $data = array(); - - $data[0] = ''; - - if ($data_module['disabled'] == 0) - $disabled = ''; - else - $disabled = ' (Disabled)'; - $data[1] = $data_module['nombre'].$disabled; - $data[2] = ui_print_moduletype_icon ($data_module['id_tipo_modulo'], true); - $data[3] = $data_module['max_warning'].'/'.$data_module['min_warning'].'
'.$data_module['max_critical'].'/'.$data_module['min_critical']; - $data[4] = $data_module['module_ff_interval']; - $data[5] = groups_get_name ($content['id_group'], true); - $data[6] = $data_module['descripcion']; - - if (($data_module['module_interval'] == 0) || ($data_module['module_interval'] == '')) - $data[7] = db_get_value('intervalo', 'tagente', 'id_agente', $content['id_agent']); - else - $data[7] = $data_module['module_interval']; - - - $data[8] = $data_module['unit']; - - $module_status = db_get_row('tagente_estado', 'id_agente_modulo', $id_agent_module); - modules_get_status($id_agent_module, $module_status['estado'], $module_status['datos'], $status, $title); - $data[9] = ui_print_status_image($status, $title, true); - - $sql_tag = "SELECT name - FROM ttag - WHERE id_tag IN ( - SELECT id_tag - FROM ttag_module - WHERE id_agente_modulo = $id_agent_module)"; - $tags = db_get_all_rows_sql($sql_tag); - if ($tags === false) - $tags = ''; - else - $tags = implode (",", $tags); - - $data[10] = $tags; - array_push ($table->data, $data); - - $i++; - } - - } - break; - case 'netflow_area': - case 'netflow_pie': - case 'netflow_data': - case 'netflow_statistics': - case 'netflow_summary': - - // Read the report item - $report_id = $report['id_report']; - $content_id = $content['id_rc']; - $max_aggregates= $content['top_n_value']; - $type = $content['show_graph']; - $description = $content['description']; - $resolution = $content['top_n']; - $type = $content['type']; - $period = $content['period']; - - // Calculate the start and end dates - $end_date = $report['datetime']; - $start_date = $end_date - $period; - - // Get item filters - $filter = db_get_row_sql("SELECT * - FROM tnetflow_filter - WHERE id_sg = '" . (int)$content['text'] . "'", false, true); - if ($description == '') { - $description = $filter['id_name']; - } - - if (empty($item_title)) { - $item_title = $description; - } - - $table->colspan[0][0] = 4; - $table->data[0][0] = '

' . $item_title . '

'; - $table->colspan[1][0] = 4; - $table->data[1][0] = netflow_draw_item ($start_date, $end_date, $resolution, $type, $filter, $max_aggregates, $server_name, 'HTML'); - break; - } - //Restore dbconnection - if (($config ['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE') && $remote_connection == 1) { - metaconsole_restore_db_force(); - } -} - -/** - * Get the MTBF value of an agent module in a period of time. See - * http://en.wikipedia.org/wiki/Mean_time_between_failures - * - * @param int Agent module id - * @param int Period of time to check (in seconds) - * @param int Top date to check the values. Default current time. - * - * @return float The MTBF value in the interval. - */ -function reporting_get_agentmodule_mtbf ($id_agent_module, $period = 0, $date = 0) { - - // Initialize variables - if (empty ($date)) $date = get_system_time (); - - // Read module configuration - $datelimit = $date - $period; - $search_in_history_db = db_search_in_history_db($datelimit); - - $module = db_get_row_sql ('SELECT max_critical, min_critical, id_tipo_modulo - FROM tagente_modulo - WHERE id_agente_modulo = ' . (int) $id_agent_module); - if ($module === false) { - return false; - } - - $critical_min = $module['min_critical']; - $critical_max = $module['max_critical']; - $module_type = $module['id_tipo_modulo']; - - // Set critical_min and critical for proc modules - $module_type_str = modules_get_type_name ($module_type); - if (strstr ($module_type_str, 'proc') !== false && - ($critical_min == 0 && $critical_max == 0)) { - $critical_min = 1; - } - - // Get module data - $interval_data = db_get_all_rows_sql ('SELECT * FROM tagente_datos - WHERE id_agente_modulo = ' . (int) $id_agent_module . - ' AND utimestamp > ' . (int) $datelimit . - ' AND utimestamp < ' . (int) $date . - ' ORDER BY utimestamp ASC', $search_in_history_db); - if ($interval_data === false) $interval_data = array (); - - // Get previous data - $previous_data = modules_get_previous_data ($id_agent_module, $datelimit); - if ($previous_data !== false) { - $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) { - $next_data['utimestamp'] = $date; - array_push ($interval_data, $next_data); - } - else if (count ($interval_data) > 0) { - // Propagate the last known data to the end of the interval - $next_data = array_pop ($interval_data); - array_push ($interval_data, $next_data); - $next_data['utimestamp'] = $date; - array_push ($interval_data, $next_data); - } - - if (count ($interval_data) < 2) { - return false; - } - - // Set initial conditions - $critical_period = 0; - $first_data = array_shift ($interval_data); - $previous_utimestamp = $first_data['utimestamp']; - if ((($critical_max > $critical_min AND ($first_data['datos'] > $critical_max OR $first_data['datos'] < $critical_min))) OR - ($critical_max <= $critical_min AND $first_data['datos'] < $critical_min)) { - $previous_status = 1; - $critical_count = 1; - } - else { - $previous_status = 0; - $critical_count = 0; - } - - foreach ($interval_data as $data) { - // Previous status was critical - if ($previous_status == 1) { - $critical_period += $data['utimestamp'] - $previous_utimestamp; - } - - // Re-calculate previous status for the next data - if ((($critical_max > $critical_min AND ($data['datos'] > $critical_max OR $data['datos'] < $critical_min))) OR - ($critical_max <= $critical_min AND $data['datos'] < $critical_min)) { - if ($previous_status == 0) { - $critical_count++; - } - $previous_status = 1; - } - else { - $previous_status = 0; - } - - $previous_utimestamp = $data['utimestamp']; - } - - if ($critical_count == 0) { - return 0; - } - - return ($period - $critical_period) / $critical_count; -} - -/** - * Get the MTTR value of an agent module in a period of time. See - * http://en.wikipedia.org/wiki/Mean_time_to_recovery - * - * @param int Agent module id - * @param int Period of time to check (in seconds) - * @param int Top date to check the values. Default current time. - * - * @return float The MTTR value in the interval. - */ -function reporting_get_agentmodule_mttr ($id_agent_module, $period = 0, $date = 0) { - - // Initialize variables - if (empty ($date)) $date = get_system_time (); - - // Read module configuration - $datelimit = $date - $period; - $search_in_history_db = db_search_in_history_db($datelimit); - - $module = db_get_row_sql ('SELECT max_critical, min_critical, id_tipo_modulo - FROM tagente_modulo - WHERE id_agente_modulo = ' . (int) $id_agent_module); - if ($module === false) { - return false; - } - - $critical_min = $module['min_critical']; - $critical_max = $module['max_critical']; - $module_type = $module['id_tipo_modulo']; - - // Set critical_min and critical for proc modules - $module_type_str = modules_get_type_name ($module_type); - if (strstr ($module_type_str, 'proc') !== false && - ($critical_min == 0 && $critical_max == 0)) { - $critical_min = 1; - } - - // Get module data - $interval_data = db_get_all_rows_sql ('SELECT * FROM tagente_datos - WHERE id_agente_modulo = ' . (int) $id_agent_module . - ' AND utimestamp > ' . (int) $datelimit . - ' AND utimestamp < ' . (int) $date . - ' ORDER BY utimestamp ASC', $search_in_history_db); - if ($interval_data === false) $interval_data = array (); - - // Get previous data - $previous_data = modules_get_previous_data ($id_agent_module, $datelimit); - if ($previous_data !== false) { - $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) { - $next_data['utimestamp'] = $date; - array_push ($interval_data, $next_data); - } - else if (count ($interval_data) > 0) { - // Propagate the last known data to the end of the interval - $next_data = array_pop ($interval_data); - array_push ($interval_data, $next_data); - $next_data['utimestamp'] = $date; - array_push ($interval_data, $next_data); - } - - if (count ($interval_data) < 2) { - return false; - } - - // Set initial conditions - $critical_period = 0; - $first_data = array_shift ($interval_data); - $previous_utimestamp = $first_data['utimestamp']; - if ((($critical_max > $critical_min AND ($first_data['datos'] > $critical_max OR $first_data['datos'] < $critical_min))) OR - ($critical_max <= $critical_min AND $first_data['datos'] < $critical_min)) { - $previous_status = 1; - $critical_count = 1; - } - else { - $previous_status = 0; - $critical_count = 0; - } - - foreach ($interval_data as $data) { - // Previous status was critical - if ($previous_status == 1) { - $critical_period += $data['utimestamp'] - $previous_utimestamp; - } - - // Re-calculate previous status for the next data - if ((($critical_max > $critical_min AND ($data['datos'] > $critical_max OR $data['datos'] < $critical_min))) OR - ($critical_max <= $critical_min AND $data['datos'] < $critical_min)) { - if ($previous_status == 0) { - $critical_count++; - } - $previous_status = 1; - } - else { - $previous_status = 0; - } - - $previous_utimestamp = $data['utimestamp']; - } - - if ($critical_count == 0) { - return 0; - } - - return $critical_period / $critical_count; -} - -/** - * Get the TTO value of an agent module in a period of time. - * - * @param int Agent module id - * @param int Period of time to check (in seconds) - * @param int Top date to check the values. Default current time. - * - * @return float The TTO value in the interval. - */ -function reporting_get_agentmodule_tto ($id_agent_module, $period = 0, $date = 0) { - - // Initialize variables - if (empty ($date)) $date = get_system_time (); - - // Read module configuration - $datelimit = $date - $period; - $search_in_history_db = db_search_in_history_db($datelimit); - - $module = db_get_row_sql ('SELECT max_critical, min_critical, id_tipo_modulo - FROM tagente_modulo - WHERE id_agente_modulo = ' . (int) $id_agent_module); - if ($module === false) { - return false; - } - - $critical_min = $module['min_critical']; - $critical_max = $module['max_critical']; - $module_type = $module['id_tipo_modulo']; - - // Set critical_min and critical for proc modules - $module_type_str = modules_get_type_name ($module_type); - if (strstr ($module_type_str, 'proc') !== false && - ($critical_min == 0 && $critical_max == 0)) { - $critical_min = 1; - } - - // Get module data - $interval_data = db_get_all_rows_sql ('SELECT * FROM tagente_datos - WHERE id_agente_modulo = ' . (int) $id_agent_module . - ' AND utimestamp > ' . (int) $datelimit . - ' AND utimestamp < ' . (int) $date . - ' ORDER BY utimestamp ASC', $search_in_history_db); - if ($interval_data === false) $interval_data = array (); - - // Get previous data - $previous_data = modules_get_previous_data ($id_agent_module, $datelimit); - if ($previous_data !== false) { - $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) { - $next_data['utimestamp'] = $date; - array_push ($interval_data, $next_data); - } - else if (count ($interval_data) > 0) { - // Propagate the last known data to the end of the interval - $next_data = array_pop ($interval_data); - array_push ($interval_data, $next_data); - $next_data['utimestamp'] = $date; - array_push ($interval_data, $next_data); - } - - if (count ($interval_data) < 2) { - return false; - } - - // Set initial conditions - $critical_period = 0; - $first_data = array_shift ($interval_data); - $previous_utimestamp = $first_data['utimestamp']; - if ((($critical_max > $critical_min AND ($first_data['datos'] > $critical_max OR $first_data['datos'] < $critical_min))) OR - ($critical_max <= $critical_min AND $first_data['datos'] < $critical_min)) { - $previous_status = 1; - } - else { - $previous_status = 0; - } - - foreach ($interval_data as $data) { - // Previous status was critical - if ($previous_status == 1) { - $critical_period += $data['utimestamp'] - $previous_utimestamp; - } - - // Re-calculate previous status for the next data - if ((($critical_max > $critical_min AND ($data['datos'] > $critical_max OR $data['datos'] < $critical_min))) OR - ($critical_max <= $critical_min AND $data['datos'] < $critical_min)) { - $previous_status = 1; - } - else { - $previous_status = 0; - } - - $previous_utimestamp = $data['utimestamp']; - } - - return $period - $critical_period; -} - -/** - * Get the TTR value of an agent module in a period of time. - * - * @param int Agent module id - * @param int Period of time to check (in seconds) - * @param int Top date to check the values. Default current time. - * - * @return float The TTR value in the interval. - */ -function reporting_get_agentmodule_ttr ($id_agent_module, $period = 0, $date = 0) { - - // Initialize variables - if (empty ($date)) $date = get_system_time (); - - // Read module configuration - $datelimit = $date - $period; - $search_in_history_db = db_search_in_history_db($datelimit); - - $module = db_get_row_sql ('SELECT max_critical, min_critical, id_tipo_modulo - FROM tagente_modulo - WHERE id_agente_modulo = ' . (int) $id_agent_module); - if ($module === false) { - return false; - } - - $critical_min = $module['min_critical']; - $critical_max = $module['max_critical']; - $module_type = $module['id_tipo_modulo']; - - // Set critical_min and critical for proc modules - $module_type_str = modules_get_type_name ($module_type); - if (strstr ($module_type_str, 'proc') !== false && - ($critical_min == 0 && $critical_max == 0)) { - $critical_min = 1; - } - - // Get module data - $interval_data = db_get_all_rows_sql ('SELECT * FROM tagente_datos - WHERE id_agente_modulo = ' . (int) $id_agent_module . - ' AND utimestamp > ' . (int) $datelimit . - ' AND utimestamp < ' . (int) $date . - ' ORDER BY utimestamp ASC', $search_in_history_db); - if ($interval_data === false) $interval_data = array (); - - // Get previous data - $previous_data = modules_get_previous_data ($id_agent_module, $datelimit); - if ($previous_data !== false) { - $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) { - $next_data['utimestamp'] = $date; - array_push ($interval_data, $next_data); - } - else if (count ($interval_data) > 0) { - // Propagate the last known data to the end of the interval - $next_data = array_pop ($interval_data); - array_push ($interval_data, $next_data); - $next_data['utimestamp'] = $date; - array_push ($interval_data, $next_data); - } - - if (count ($interval_data) < 2) { - return false; - } - - // Set initial conditions - $critical_period = 0; - $first_data = array_shift ($interval_data); - $previous_utimestamp = $first_data['utimestamp']; - if ((($critical_max > $critical_min AND ($first_data['datos'] > $critical_max OR $first_data['datos'] < $critical_min))) OR - ($critical_max <= $critical_min AND $first_data['datos'] < $critical_min)) { - $previous_status = 1; - } - else { - $previous_status = 0; - } - - foreach ($interval_data as $data) { - // Previous status was critical - if ($previous_status == 1) { - $critical_period += $data['utimestamp'] - $previous_utimestamp; - } - - // Re-calculate previous status for the next data - if ((($critical_max > $critical_min AND ($data['datos'] > $critical_max OR $data['datos'] < $critical_min))) OR - ($critical_max <= $critical_min AND $data['datos'] < $critical_min)) { - $previous_status = 1; - } - else { - $previous_status = 0; - } - - $previous_utimestamp = $data['utimestamp']; - } - - return $critical_period; -} - -/** - * Get all the template graphs a user can see. - * - * @param $id_user User id to check. - * @param $only_names Wheter to return only graphs names in an associative array - * or all the values. - * @param $returnAllGroup Wheter to return graphs of group All or not. - * @param $privileges Privileges to check in user group - * - * @return template graphs of a an user. Empty array if none. - */ -function reporting_template_graphs_get_user ($id_user = 0, $only_names = false, $returnAllGroup = true, $privileges = 'RR') { - global $config; - - if (!$id_user) { - $id_user = $config['id_user']; - } - - $groups = users_get_groups ($id_user, $privileges, $returnAllGroup); - - $all_templates = db_get_all_rows_in_table ('tgraph_template', 'name'); - if ($all_templates === false) - return array (); - - $templates = array (); - foreach ($all_templates as $template) { - if (!in_array($template['id_group'], array_keys($groups))) - continue; - - if ($template["id_user"] != $id_user && $template['private']) - continue; - - if ($template["id_group"] > 0) - if (!isset($groups[$template["id_group"]])){ - continue; - } - - if ($only_names) { - $templates[$template['id_graph_template']] = $template['name']; - } - else { - $templates[$template['id_graph_template']] = $template; - $templatesCount = db_get_value_sql("SELECT COUNT(id_gs_template) FROM tgraph_source_template WHERE id_template = " . $template['id_graph_template']); - $templates[$template['id_graph_template']]['graphs_template_count'] = $templatesCount; - } - } - - return $templates; -} - -/** - * Gets a detailed reporting of groups's events. - * - * @param unknown_type $id_group Id of the group. - * @param unknown_type $period Time period of the report. - * @param unknown_type $date Date of the report. - * @param unknown_type $return Whether to return or not. - * @param unknown_type $html Whether to return HTML code or not. - * - * @return string Report of groups's events - */ -function reporting_get_count_events_by_agent ($id_group, $period = 0, - $date = 0, - $filter_event_validated = false, $filter_event_critical = false, - $filter_event_warning = false, $filter_event_no_validated = false) { - - if (!is_numeric ($date)) { - $date = strtotime ($date); - } - if (empty ($date)) { - $date = get_system_time (); - } - - return events_get_count_events_by_agent($id_group, $period, $date, - $filter_event_validated, $filter_event_critical, - $filter_event_warning, $filter_event_no_validated); -} - -/** - * Gets a detailed reporting of groups's events. - * - * @param unknown_type $filter. - * @param unknown_type $period Time period of the report. - * @param unknown_type $date Date of the report. - * @param unknown_type $return Whether to return or not. - * @param unknown_type $html Whether to return HTML code or not. - * - * @return string Report of groups's events - */ -function reporting_get_count_events_validated_by_user ($filter, $period = 0, - $date = 0, - $filter_event_validated = false, $filter_event_critical = false, - $filter_event_warning = false, $filter_event_no_validated = false) { - - if (!is_numeric ($date)) { - $date = strtotime ($date); - } - if (empty ($date)) { - $date = get_system_time (); - } - - return events_get_count_events_validated_by_user($filter, $period, $date, - $filter_event_validated, $filter_event_critical, - $filter_event_warning, $filter_event_no_validated); -} - -/** - * Gets a detailed reporting of groups's events. - * - * @param unknown_type $id_group Id of the group. - * @param unknown_type $period Time period of the report. - * @param unknown_type $date Date of the report. - * @param unknown_type $return Whether to return or not. - * @param unknown_type $html Whether to return HTML code or not. - * - * @return string Report of groups's events - */ -function reporting_get_count_events_by_criticity ($filter, $period = 0, - $date = 0, - $filter_event_validated = false, $filter_event_critical = false, - $filter_event_warning = false, $filter_event_no_validated = false) { - - if (!is_numeric ($date)) { - $date = strtotime ($date); - } - if (empty ($date)) { - $date = get_system_time (); - } - - return events_get_count_events_by_criticity($filter, $period, $date, - $filter_event_validated, $filter_event_critical, - $filter_event_warning, $filter_event_no_validated); -} - -/** - * Gets a detailed reporting of groups's events. - * - * @param unknown_type $id_group Id of the group. - * @param unknown_type $period Time period of the report. - * @param unknown_type $date Date of the report. - * @param unknown_type $return Whether to return or not. - * @param unknown_type $html Whether to return HTML code or not. - * - * @return string Report of groups's events - */ -function reporting_get_count_events_validated ($filter, $period = 0, - $date = 0, - $filter_event_validated = false, $filter_event_critical = false, - $filter_event_warning = false, $filter_event_no_validated = false) { - - if (!is_numeric ($date)) { - $date = strtotime ($date); - } - if (empty ($date)) { - $date = get_system_time (); - } - - return events_get_count_events_validated($filter, $period, $date, - $filter_event_validated, $filter_event_critical, - $filter_event_warning, $filter_event_no_validated); -} - -/** - * Print tiny statistics of the status of one agent, group, etc. - * - * @param mixed Array with the counts of the total modules, normal modules, critical modules, warning modules, unknown modules and fired alerts - * @param bool return or echo flag - * - * @return string html formatted tiny stats of modules/alerts of an agent - */ -function reporting_tiny_stats ($counts_info, $return = false, $type = 'agent', $separator = ':', $strict_user = false) { - global $config; - - $out = ''; - - // Depend the type of object, the stats will refer agents, modules... - switch ($type) { - case 'modules': - $template_title['total_count'] = __('%d Total modules'); - $template_title['normal_count'] = __('%d Normal modules'); - $template_title['critical_count'] = __('%d Critical modules'); - $template_title['warning_count'] = __('%d Warning modules'); - $template_title['unknown_count'] = __('%d Unknown modules'); - break; - case 'agent': - $template_title['total_count'] = __('%d Total modules'); - $template_title['normal_count'] = __('%d Normal modules'); - $template_title['critical_count'] = __('%d Critical modules'); - $template_title['warning_count'] = __('%d Warning modules'); - $template_title['unknown_count'] = __('%d Unknown modules'); - $template_title['fired_count'] = __('%d Fired alerts'); - break; - default: - $template_title['total_count'] = __('%d Total agents'); - $template_title['normal_count'] = __('%d Normal agents'); - $template_title['critical_count'] = __('%d Critical agents'); - $template_title['warning_count'] = __('%d Warning agents'); - $template_title['unknown_count'] = __('%d Unknown agents'); - $template_title['not_init_count'] = __('%d not init agents'); - $template_title['fired_count'] = __('%d Fired alerts'); - break; - } - - if ($strict_user && $type == 'agent') { - - $acltags = tags_get_user_module_and_tags ($config['id_user'],'AR', $strict_user); - $filter['disabled'] = 0; - $id_agent = $counts_info['id_agente']; - - $counts_info = array(); - $counts_info['normal_count'] = count(tags_get_agent_modules ($id_agent, $acltags, false, $filter, false, AGENT_MODULE_STATUS_NORMAL)); - $counts_info['warning_count'] = count(tags_get_agent_modules ($id_agent, $acltags, false, $filter, false, AGENT_MODULE_STATUS_WARNING)); - $counts_info['critical_count'] = count(tags_get_agent_modules ($id_agent, $acltags, false, $filter, false, AGENT_MODULE_STATUS_CRITICAL_BAD)); - $counts_info['notinit_count'] = count(tags_get_agent_modules ($id_agent, $acltags, false, $filter, false, AGENT_MODULE_STATUS_NOT_INIT)); - $counts_info['unknown_count'] = count(tags_get_agent_modules ($id_agent, $acltags, false, $filter, false, AGENT_MODULE_STATUS_UNKNOWN)); - $counts_info['total_count'] = $counts_info['normal_count'] + $counts_info['warning_count'] + $counts_info['critical_count'] + $counts_info['unknown_count'] + $counts_info['notinit_count']; - - $all_agent_modules = tags_get_agent_modules ($id_agent, $acltags, false, $filter); - if (!empty($all_agent_modules)) { - $mod_clause = "(".implode(',', array_keys($all_agent_modules)).")"; - - $counts_info['fired_count'] = (int) db_get_sql ("SELECT COUNT(times_fired) - FROM talert_template_modules - WHERE times_fired != 0 AND id_agent_module IN ".$mod_clause); - } - else { - $counts_info['fired_count'] = 0; - } - } - - // Store the counts in a data structure to print hidden divs with titles - $stats = array(); - - if (isset($counts_info['total_count'])) { - $not_init = isset($counts_info['notinit_count']) ? $counts_info['notinit_count'] : 0; - $total_count = $counts_info['total_count'] - $not_init; - $stats[] = array('name' => 'total_count', 'count' => $total_count, 'title' => sprintf($template_title['total_count'], $total_count)); - } - - if (isset($counts_info['normal_count'])) { - $normal_count = $counts_info['normal_count']; - $stats[] = array('name' => 'normal_count', 'count' => $normal_count, 'title' => sprintf($template_title['normal_count'], $normal_count)); - } - - if (isset($counts_info['critical_count'])) { - $critical_count = $counts_info['critical_count']; - $stats[] = array('name' => 'critical_count', 'count' => $critical_count, 'title' => sprintf($template_title['critical_count'], $critical_count)); - } - - if (isset($counts_info['warning_count'])) { - $warning_count = $counts_info['warning_count']; - $stats[] = array('name' => 'warning_count', 'count' => $warning_count, 'title' => sprintf($template_title['warning_count'], $warning_count)); - } - - if (isset($counts_info['unknown_count'])) { - $unknown_count = $counts_info['unknown_count']; - $stats[] = array('name' => 'unknown_count', 'count' => $unknown_count, 'title' => sprintf($template_title['unknown_count'], $unknown_count)); - } - - if (isset($counts_info['not_init_count'])) { - $not_init_count = $counts_info['not_init_count']; - $stats[] = array('name' => 'not_init_count', - 'count' => $not_init_count, - 'title' => sprintf($template_title['not_init_count'], $not_init_count)); - } - - if (isset($template_title['fired_count'])) { - if (isset($counts_info['fired_count'])) { - $fired_count = $counts_info['fired_count']; - $stats[] = array('name' => 'fired_count', 'count' => $fired_count, 'title' => sprintf($template_title['fired_count'], $fired_count)); - } - } - - $uniq_id = uniqid(); - - foreach ($stats as $stat) { - $params = array('id' => 'forced_title_' . $stat['name'] . '_' . $uniq_id, - 'class' => 'forced_title_layer', - 'content' => $stat['title'], - 'hidden' => true); - $out .= html_print_div($params, true); - } - - // If total count is less than 0, is an error. Never show negative numbers - if ($total_count < 0) { - $total_count = 0; - } - - $out .= '' . '' . $total_count . ''; - if (isset($fired_count) && $fired_count > 0) - $out .= ' ' . $separator . ' ' . $fired_count . ''; - if (isset($critical_count) && $critical_count > 0) - $out .= ' ' . $separator . ' ' . $critical_count . ''; - if (isset($warning_count) && $warning_count > 0) - $out .= ' ' . $separator . ' ' . $warning_count . ''; - if (isset($unknown_count) && $unknown_count > 0) - $out .= ' ' . $separator . ' ' . $unknown_count . ''; - if (isset($not_init_count) && $not_init_count > 0) - $out .= ' ' . $separator . ' ' . $not_init_count . ''; - if (isset($normal_count) && $normal_count > 0) - $out .= ' ' . $separator . ' ' . $normal_count . ''; - - $out .= ''; - - if ($return) { - return $out; - } - else { - echo $out; - } -} - - -function reporting_network_interfaces_table ($content, $report, $mini, $item_title = "", &$table = null, &$pdf = null) { - global $config; - - include_once($config['homedir'] . "/include/functions_custom_graphs.php"); - - if (empty($item_title)) { - $group_name = groups_get_name($content['id_group']); - $item_title = __('Network interfaces') . " - " . sprintf(__('Group "%s"'), $group_name); - } - - $is_html = $table !== null; - $is_pdf = $pdf !== null; - - $ttl = $is_pdf ? 2 : 1; - - $graph_width = 900; - $graph_height = 200; - - $datetime = $report['datetime']; - $period = $content['period']; - - if ($is_pdf) { - $graph_width = 800; - $graph_height = 200; - pdf_header_content($pdf, $content, $report, $item_title, false, $content["description"]); - } - else if ($is_html) { - reporting_header_content($mini, $content, $report, $table, $item_title); - - //RUNNING - $table->style[1] = 'text-align: right'; - - // Put description at the end of the module (if exists) - $table->colspan[0][1] = 2; - $next_row = 1; - if ($content["description"] != "") { - $table->colspan[$next_row][0] = 3; - $next_row++; - $data_desc = array(); - $data_desc[0] = $content["description"]; - array_push ($table->data, $data_desc); - } - } - - $filter = array( - 'id_grupo' => $content['id_group'], - 'disabled' => 0 - ); - $network_interfaces_by_agents = agents_get_network_interfaces(false, $filter); - - if (empty($network_interfaces_by_agents)) { - if ($is_pdf) { - $pdf->addHTML(__('The group has no agents or none of the agents has any network interface')); - } - else if ($is_html) { - $data = array(); - $data[0] = __('The group has no agents or none of the agents has any network interface'); - $table->colspan[$next_row][0] = 3; - array_push ($table->data, $data); - } - return; - } - else { - foreach ($network_interfaces_by_agents as $agent_id => $agent) { - - $table_agent = new StdCLass(); - $table_agent->width = '100%'; - $table_agent->data = array(); - $table_agent->head = array(); - $table_agent->head[0] = sprintf(__("Agent '%s'"), $agent['name']); - $table_agent->headstyle = array(); - $table_agent->headstyle[0] = 'font-size: 16px;'; - $table_agent->style[0] = 'text-align: center'; - - if ($is_pdf) { - $table_agent->class = 'table_sla table_beauty'; - $table_agent->headstyle[0] = 'background: #373737; color: #FFF; display: table-cell; font-size: 16px; border: 1px solid grey'; - } - - $table_agent->data['interfaces'] = ""; - - foreach ($agent['interfaces'] as $interface_name => $interface) { - $table_interface = new StdClass(); - $table_interface->width = '100%'; - $table_interface->data = array(); - $table_interface->rowstyle = array(); - $table_interface->head = array(); - $table_interface->cellstyle = array(); - $table_interface->title = sprintf(__("Interface '%s' throughput graph"), $interface_name); - $table_interface->head['ip'] = __('IP'); - $table_interface->head['mac'] = __('Mac'); - $table_interface->head['status'] = __('Actual status'); - $table_interface->style['ip'] = 'text-align: left'; - $table_interface->style['mac'] = 'text-align: left'; - $table_interface->style['status'] = 'width: 150px; text-align: center'; - - if ($is_pdf) { - $table_interface->class = 'table_sla table_beauty'; - $table_interface->titlestyle = 'background: #373737; color: #FFF; display: table-cell; font-size: 12px; border: 1px solid grey'; - - $table_interface->headstyle['ip'] = 'text-align: left; background: #666; color: #FFF; display: table-cell; font-size: 11px; border: 1px solid grey'; - $table_interface->headstyle['mac'] = 'text-align: left; background: #666; color: #FFF; display: table-cell; font-size: 11px; border: 1px solid grey'; - $table_interface->headstyle['status'] = 'background: #666; color: #FFF; display: table-cell; font-size: 11px; border: 1px solid grey'; - - $table_interface->style['ip'] = 'text-align: left; display: table-cell; font-size: 10px;'; - $table_interface->style['mac'] = 'text-align: left; display: table-cell; font-size: 10px;'; - $table_interface->style['status'] = 'text-align: center; display: table-cell; font-size: 10px;'; - } - - $data = array(); - $data['ip'] = !empty($interface['ip']) ? $interface['ip'] : "--"; - $data['mac'] = !empty($interface['mac']) ? $interface['mac'] : "--"; - $data['status'] = $interface['status_image']; - $table_interface->data['data'] = $data; - - if (!empty($interface['traffic'])) { - - $only_image = !(bool)$config['flash_charts'] || $is_pdf ? true : false; - - $graph = custom_graphs_print(0, - $graph_height, - $graph_width, - $period, - null, - true, - $date, - $only_image, - 'white', - array_values($interface['traffic']), - $config['homeurl'], - array_keys($interface['traffic']), - array_fill(0, count($interface['traffic']),"bytes/s"), - false, - true, - true, - true, - $ttl); - - $table_interface->data['graph'] = $graph; - $table_interface->colspan['graph'][0] = count($table_interface->head); - $table_interface->cellstyle['graph'][0] = 'text-align: center;'; - } - - $table_agent->data['interfaces'] .= html_print_table($table_interface, true); - $table_agent->colspan[$interface_name][0] = 3; - } - - if ($is_html) { - $table->data[$agent_id] = html_print_table($table_agent, true); - $table->colspan[$agent_id][0] = 3; - } - else if ($is_pdf) { - $html = html_print_table($table_agent, true); - $pdf->addHTML($html); - } - } - } -} - -function reporting_get_agents_by_status ($data, $graph_width = 250, $graph_height = 150, $links = false) { - global $config; - - if ($links == false) { - $links = array(); - } - - $table_agent = html_get_predefined_table(); - - $agent_data = array(); - $agent_data[0] = html_print_image('images/agent_critical.png', true, array('title' => __('Agents critical'))); - $agent_data[1] = "".format_numeric($data['agent_critical']).""; - - $agent_data[2] = html_print_image('images/agent_warning.png', true, array('title' => __('Agents warning'))); - $agent_data[3] = "".format_numeric($data['agent_warning']).""; - - $table_agent->data[] = $agent_data; - - $agent_data = array(); - $agent_data[0] = html_print_image('images/agent_ok.png', true, array('title' => __('Agents ok'))); - $agent_data[1] = "".format_numeric($data['agent_ok']).""; - - $agent_data[2] = html_print_image('images/agent_unknown.png', true, array('title' => __('Agents unknown'))); - $agent_data[3] = "".format_numeric($data['agent_unknown']).""; - - $table_agent->data[] = $agent_data; - - $agent_data = array(); - $agent_data[0] = html_print_image('images/agent_notinit.png', true, array('title' => __('Agents not init'))); - $agent_data[1] = "".format_numeric($data['agent_not_init']).""; - - $agent_data[2] = ""; - $agent_data[3] = ""; - $table_agent->data[] = $agent_data; - - - if (!defined('METACONSOLE')) { - $agents_data = '
- ' . - __('Agents by status') . - '' . - html_print_table($table_agent, true) . '
'; - } - else{ - $table_agent->style=array(); - $table_agent->class = "tactical_view"; - $agents_data = '
- ' . - __('Agents by status') . - '' . - html_print_table($table_agent, true) . '
'; - } - - return $agents_data; -} - -function reporting_get_total_agents_and_monitors ($data, $graph_width = 250, $graph_height = 150) { - global $config; - - $total_agent = $data['agent_ok'] + $data['agent_warning'] + $data['agent_critical'] + $data['gent_unknown'] + $data['agent_not_init']; - $total_module = $data['monitor_ok'] + $data['monitor_warning'] + $data['monitor_critical'] + $data['monitor_unknown'] + $data['monitor_not_init']; - - $table_total = html_get_predefined_table(); - - $total_data = array(); - $total_data[0] = html_print_image('images/agent.png', true, array('title' => __('Total agents'))); - $total_data[1] = $total_agent <= 0 ? '-' : $total_agent; - $total_data[2] = html_print_image('images/module.png', true, array('title' => __('Monitor checks'))); - $total_data[3] = $total_module <= 0 ? '-' : $total_module; - $table_total->data[] = $total_data; - $total_agent_module = '
- ' . - __('Total agents and monitors') . - '' . - html_print_table($table_total, true) . '
'; - - return $total_agent_module; -} - -function reporting_get_total_servers ($num_servers) { - global $config; - - $table_node = html_get_predefined_table(); - - $node_data = array(); - $node_data[0] = html_print_image('images/server_export.png', true, array('title' => __('Nodes'))); - $node_data[1] = "".format_numeric($num_servers).""; - $table_node->data[] = $node_data; - - if (!defined('METACONSOLE')){ - $node_overview = '
- ' . - __('Node overview') . - '' . - html_print_table($table_node, true) . '
'; - }else{ - $table_node->style = array(); - $table_node->class = "tactical_view"; - $node_overview = '
- ' . - __('Node overview') . - '' . - html_print_table($table_node, true) . '
'; - } - - return $node_overview; -} - -function reporting_get_events ($data, $links = false) { - global $config; - - $table_events->width = "100%"; - if (defined('METACONSOLE')) - $style = " vertical-align:middle;"; - else - $style = ""; - if (defined('METACONSOLE')){ - $table_events->style[0] = "background-color:#FC4444"; - $table_events->data[0][0] = html_print_image('images/module_event_critical.png', true, array('title' => __('Critical events'))); - $table_events->data[0][0] .= "   " . - "" . format_numeric($data['critical']).""; - $table_events->style[1] = "background-color:#FAD403"; - $table_events->data[0][1] = html_print_image('images/module_event_warning.png', true, array('title' => __('Warning events'))); - $table_events->data[0][1] .= "   " . - "" . format_numeric($data['warning']).""; - $table_events->style[2] = "background-color:#80BA27"; - $table_events->data[0][2] = html_print_image('images/module_event_ok.png', true, array('title' => __('OK events'))); - $table_events->data[0][2] .= "   " . - "" . format_numeric($data['normal']).""; - $table_events->style[3] = "background-color:#B2B2B2"; - $table_events->data[0][3] = html_print_image('images/module_event_unknown.png', true, array('title' => __('Unknown events'))); - $table_events->data[0][3] .= "   " . - "" . format_numeric($data['unknown']).""; - } - else{ - $table_events->data[0][0] = html_print_image('images/module_critical.png', true, array('title' => __('Critical events'))); - $table_events->data[0][0] .= "   " . - "". - format_numeric($data['critical']).""; - $table_events->data[0][1] = html_print_image('images/module_warning.png', true, array('title' => __('Warning events'))); - $table_events->data[0][1] .= "   " . - "". - format_numeric($data['warning']).""; - $table_events->data[0][2] = html_print_image('images/module_ok.png', true, array('title' => __('OK events'))); - $table_events->data[0][2] .= "   " . - "". - format_numeric($data['normal']).""; - $table_events->data[0][3] = html_print_image('images/module_unknown.png', true, array('title' => __('Unknown events'))); - $table_events->data[0][3] .= "   " . - "". - format_numeric($data['unknown']).""; - - } - if (!defined('METACONSOLE')) { - $event_view = '
- ' . - __('Events by criticity') . - '' . - html_print_table($table_events, true) . '
'; - } - else{ - $table_events->class="tactical_view"; - $table_events->styleTable="text-align:center;"; - $table_events->size[0]="10%"; - $table_events->size[1]="10%"; - $table_events->size[2]="10%"; - $table_events->size[3]="10%"; - - $event_view = '
- ' . - __('Events by criticity') . - '' . - html_print_table($table_events, true) . '
'; - } - - return $event_view; -} - -function reporting_get_last_activity() { - global $config; - - // Show last activity from this user - - $table->width = '100%'; - $table->data = array (); - $table->size = array (); - $table->size[2] = '150px'; - $table->size[3] = '130px'; - $table->size[5] = '200px'; - $table->head = array (); - $table->head[0] = __('User'); - $table->head[1] = ''; - $table->head[2] = __('Action'); - $table->head[3] = __('Date'); - $table->head[4] = __('Source IP'); - $table->head[5] = __('Comments'); - $table->title = '' . __('Last activity in Pandora FMS console') . ''; - - switch ($config["dbtype"]) { - case "mysql": - $sql = sprintf ("SELECT id_usuario,accion,fecha,ip_origen,descripcion,utimestamp - FROM tsesion - WHERE (`utimestamp` > UNIX_TIMESTAMP(NOW()) - " . SECONDS_1WEEK . ") - AND `id_usuario` = '%s' ORDER BY `utimestamp` DESC LIMIT 5", $config["id_user"]); - break; - case "postgresql": - $sql = sprintf ("SELECT \"id_usuario\", accion, fecha, \"ip_origen\", descripcion, utimestamp - FROM tsesion - WHERE (\"utimestamp\" > ceil(date_part('epoch', CURRENT_TIMESTAMP)) - " . SECONDS_1WEEK . ") - AND \"id_usuario\" = '%s' ORDER BY \"utimestamp\" DESC LIMIT 5", $config["id_user"]); - break; - case "oracle": - $sql = sprintf ("SELECT id_usuario, accion, fecha, ip_origen, descripcion, utimestamp - FROM tsesion - WHERE ((utimestamp > ceil((sysdate - to_date('19700101000000','YYYYMMDDHH24MISS')) * (" . SECONDS_1DAY . ")) - " . SECONDS_1WEEK . ") - AND id_usuario = '%s') AND rownum <= 10 ORDER BY utimestamp DESC", $config["id_user"]); - break; - } - - $sessions = db_get_all_rows_sql ($sql); - - if ($sessions === false) - $sessions = array (); - - foreach ($sessions as $session) { - $data = array (); - - switch ($config["dbtype"]) { - case "mysql": - case "oracle": - $session_id_usuario = $session['id_usuario']; - $session_ip_origen = $session['ip_origen']; - break; - case "postgresql": - $session_id_usuario = $session['id_usuario']; - $session_ip_origen = $session['ip_origen']; - break; - } - - - $data[0] = '' . $session_id_usuario . ''; - $data[1] = ui_print_session_action_icon ($session['accion'], true); - $data[2] = $session['accion']; - $data[3] = ui_print_help_tip($session['fecha'], true) . human_time_comparation($session['utimestamp'], 'tiny'); - $data[4] = $session_ip_origen; - $data[5] = io_safe_output ($session['descripcion']); - - array_push ($table->data, $data); - } - - if(defined("METACONSOLE")) - $table->class="databox_tactical"; - - return html_print_table ($table, true); - -} - -function reporting_get_event_histogram ($events) { - global $config; - include_once ('../../include/graphs/functions_gd.php'); - $max_value = count($events); - - $ttl = 1; - $urlImage = ui_get_full_url(false, true, false, false); - - $colors = array( - EVENT_CRIT_MAINTENANCE => COL_MAINTENANCE, - EVENT_CRIT_INFORMATIONAL => COL_INFORMATIONAL, - EVENT_CRIT_NORMAL => COL_MINOR, - EVENT_CRIT_MINOR => COL_NORMAL, - EVENT_CRIT_WARNING => COL_WARNING, - EVENT_CRIT_MAJOR => COL_MAJOR, - EVENT_CRIT_CRITICAL => COL_CRITICAL - ); - - foreach ($events as $data) { - - switch ($data['criticity']) { - case 0: - $color = EVENT_CRIT_MAINTENANCE; - break; - case 1: - $color = EVENT_CRIT_INFORMATIONAL; - break; - case 2: - $color = EVENT_CRIT_NORMAL; - break; - case 3: - $color = EVENT_CRIT_WARNING; - break; - case 4: - $color = EVENT_CRIT_CRITICAL; - break; - case 5: - $color = EVENT_CRIT_MINOR; - break; - case 6: - $color = EVENT_CRIT_MAJOR; - break; - case 20: - $color = EVENT_CRIT_NOT_NORMAL; - break; - case 34: - $color = EVENT_CRIT_WARNING_OR_CRITICAL; - break; - } - $graph_data[] = array( - 'data' => $color, - 'utimestamp' => 1 - ); - } - - $table->width = '100%'; - $table->data = array (); - $table->size = array (); - $table->head = array (); - $table->title = '' . __('Events info (1hr.)') . ''; - $table->data[0][0] = "" ; - - if (!empty($graph_data)) { - $slicebar = slicesbar_graph($graph_data, $max_value, 700, 25, $colors, $config['fontpath'], $config['round_corner'], $urlImage, $ttl); - $table->data[0][0] = $slicebar; - } else { - $table->data[0][0] = __('No events'); - } - - if(!defined('METACONSOLE')){ - $event_graph = '
- ' . - __('Events info (1hr)') . - '' . - html_print_table($table, true) . '
'; - } - else{ - $table->class='tactical_view'; - $event_graph = '
' . - html_print_table($table, true) . '
'; - } - - return $event_graph; +function reporting_check_structure_content($return) { + if (!isset($return['title'])) + $return['title'] = ""; + if (!isset($return['subtitle'])) + $return['subtitle'] = ""; + if (!isset($return['description'])) + $return['description'] = ""; + if (!isset($return["date"])) { + $return["date"]['date'] = ""; + $return["date"]['period'] = ""; + $return["date"]['from'] = ""; + $return["date"]['to'] = ""; + } + + + return $return; } ?> diff --git a/pandora_console/operation/reporting/reporting_viewer.php b/pandora_console/operation/reporting/reporting_viewer.php index 10c326bb57..1ddad7d549 100644 --- a/pandora_console/operation/reporting/reporting_viewer.php +++ b/pandora_console/operation/reporting/reporting_viewer.php @@ -41,6 +41,7 @@ if (empty($report) || ! check_acl ($config['id_user'], $report['id_group'], "RR" // Include with the functions to calculate each kind of report. require_once ($config['homedir'] . '/include/functions_reporting.php'); +require_once ($config['homedir'] . '/include/functions_reporting_html.php'); require_once ($config['homedir'] . '/include/functions_groups.php'); enterprise_include("include/functions_reporting.php"); @@ -136,7 +137,7 @@ $table->class = 'databox'; if (defined("METACONSOLE")){ $table->width = '100%'; $table->class = 'databox data'; - + $table->head[0] = __('View Report'); $table->head_colspan[0] = 5; $table->headstyle[0] = 'text-align: center'; @@ -172,14 +173,14 @@ if (defined("METACONSOLE")) { else { $table->data[0][1] = '
' . __("Name: ") . $report['name'] . '
'; } - + $table->data[0][1] .= '
'.__('Set initial date') . html_print_checkbox('enable_init_date', 1, $enable_init_date, true); $html_enterprise = enterprise_hook('reporting_print_button_PDF', array($id_report)); if ($html_enterprise !== ENTERPRISE_NOT_HOOK) { $table->data[0][1] .= $html_enterprise; } $table->data[0][1] .= '
'; - + $table->data[1][1] = '
' . __('From') . ': '; $table->data[1][1] .= html_print_input_text ('date_init', $date_init, '', 12, 10, true). ' '; $table->data[1][1] .= html_print_input_text ('time_init', $time_init, '', 10, 7, true). '
'; @@ -192,21 +193,21 @@ if (defined("METACONSOLE")) { $table->data[1][2] .= html_print_input_text ('time', $time, '', 10, 7, true) . ' '; $table->data[1][2] .= html_print_submit_button (__('Update'), 'date_submit', false, 'class="sub next"', true) . ' '; } -else{ +else { if ($report['description'] != '') { $table->data[0][1] = '
'.$report['description'].'
'; } else { $table->data[0][1] = '
'.$report['name'].'
'; } - + $table->data[0][1] .= '
'.__('Set initial date') . html_print_checkbox('enable_init_date', 1, $enable_init_date, true); $html_enterprise = enterprise_hook('reporting_print_button_PDF', array($id_report)); if ($html_enterprise !== ENTERPRISE_NOT_HOOK) { $table->data[0][1] .= $html_enterprise; } $table->data[0][1] .= '
'; - + $table->data[1][1] = '
' . __('From') . ':
'; $table->data[1][1] .= html_print_input_text ('date_init', $date_init, '', 12, 10, true). ' '; $table->data[1][1] .= html_print_input_text ('time_init', $time_init, '', 10, 7, true). ' '; @@ -353,7 +354,7 @@ foreach ($contents as $content) { $table->rowstyle = array (); // Calculate new inteval for all reports - if ($enable_init_date){ + if ($enable_init_date) { if ($datetime_init >= $datetime) { $datetime_init = $date_init_less; } From e7b79a0a8f71e6055c63341c3ad1c332a1364ac2 Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Mon, 23 Mar 2015 11:08:58 +0100 Subject: [PATCH 02/80] Working in the new feature. --- pandora_console/include/constants.php | 9 + .../include/functions_reporting.php | 761 +- .../include/functions_reporting_html.php | 7880 +++++++++++++++++ 3 files changed, 8643 insertions(+), 7 deletions(-) create mode 100644 pandora_console/include/functions_reporting_html.php diff --git a/pandora_console/include/constants.php b/pandora_console/include/constants.php index a265450a5a..5e1bda01cf 100755 --- a/pandora_console/include/constants.php +++ b/pandora_console/include/constants.php @@ -365,6 +365,15 @@ define ('REPORT_ITEM_ORDER_BY_AGENT_NAME', 3); define ('REPORT_ITEM_ORDER_BY_ASCENDING', 2); define ('REPORT_ITEM_ORDER_BY_DESCENDING', 1); +define('REPORT_OLD_TYPE_SIMPLE_GRAPH', 1); +define('REPORT_OLD_TYPE_CUSTOM_GRAPH', 2); +define('REPORT_OLD_TYPE_SLA', 3); +define('REPORT_OLD_TYPE_MONITOR_REPORT', 6); +define('REPORT_OLD_TYPE_AVG_VALUE', 7); +define('REPORT_OLD_TYPE_MAX_VALUE', 8); +define('REPORT_OLD_TYPE_MIN_VALUE', 9); +define('REPORT_OLD_TYPE_SUMATORY', 10); + /* POLICIES */ define("POLICY_UPDATED", 0); diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index 3d88fa8d1e..6fb994db97 100644 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -37,7 +37,38 @@ include_once($config['homedir'] . "/include/functions_forecast.php"); include_once($config['homedir'] . "/include/functions_ui.php"); include_once($config['homedir'] . "/include/functions_netflow.php"); -function reporting_make_reporting_data($id_report, $datetime) { +function reporting_get_type($content) { + switch ($content["type"]) { + case REPORT_OLD_TYPE_SIMPLE_GRAPH: + $content["type"] = 'simple_graph'; + break; + case REPORT_OLD_TYPE_CUSTOM_GRAPH: + $content["type"] = 'custom_graph'; + break; + case REPORT_OLD_TYPE_MONITOR_REPORT: + $content["type"] = 'monitor_report'; + break; + case REPORT_OLD_TYPE_SLA: + $content["type"] = 'SLA'; + break; + case REPORT_OLD_TYPE_AVG_VALUE: + $content["type"] = 'avg_value'; + break; + case REPORT_OLD_TYPE_MAX_VALUE: + $content["type"] = 'max_value'; + break; + case REPORT_OLD_TYPE_MIN_VALUE: + $content["type"] = 'min_value'; + break; + case REPORT_OLD_TYPE_SUMATORY: + $content["type"] = 'sumatory'; + break; + } + + return $content["type"]; +} + +function reporting_make_reporting_data($id_report, $date, $time, $period, $type = 'dinamic') { $return = array(); switch ($config["dbtype"]) { @@ -60,15 +91,44 @@ function reporting_make_reporting_data($id_report, $datetime) { $report["group_name"] = groups_get_name ($report['id_group']); - return $return; + $datetime = strtotime($date . ' ' . $time); + $report["datetime"] = $datetime; + + $report['period'] = $period; + + $report['contents'] = array(); + + foreach ($contents as $content) { + // Calculate new inteval for all reports + if ($enable_init_date) { + if ($datetime_init >= $datetime) { + $datetime_init = $date_init_less; + } + $new_interval = $report['datetime'] - $datetime_init; + $content['period'] = $new_interval; + } + + switch (reporting_get_type($content)) { + case 'simple_graph': + $report['contents'][] = + reporting_simple_graph( + $report, + $content, + $type); + break; + } + } + + return reporting_check_structure_report($return); } -function reporting_simple_graph($id_report, $id_report_item, $type = 'dinamic') { +function reporting_simple_graph($report, $content, $type = 'dinamic') { global $config; + //sizgraph_w ¿meter el size en la llamada general? + $return = array(); - $content = db_get_row('treport_content_item', 'id', $id_report_item); if (empty($content['name'])) { $content['name'] = __('Simple graph'); } @@ -84,13 +144,88 @@ function reporting_simple_graph($id_report, $id_report_item, $type = 'dinamic') $return['title'] = $content['name']; $return['subtitle'] = $agent_name . " - " . $module_name; $return["description"] = $content["description"]; - $return["date"] = reporting_get_date_text($id_report, $id_report_item); + $return["date"] = reporting_get_date_text( + $report['id_rc'], + $content['id']); + $only_avg = true; + // Due to database compatibility problems, the 'only_avg' value + // is stored into the json contained into the 'style' column. + if (isset($content['style'])) { + $style_json = io_safe_output($content['style']); + $style = json_decode($style_json, true); + + if (isset($style['only_avg'])) { + $only_avg = (bool) $style['only_avg']; + } + } + + $moduletype_name = modules_get_moduletype_name( + modules_get_agentmodule_type( + $content['id_agent_module'])); + + + + $return['chart'] = ''; // Get chart switch ($type) { case 'dinamic': + $only_image = false; break; case 'static': + $only_image = true; + break; + case 'data': + break; + } + + switch ($type) { + case 'dinamic': + case 'static': + if (preg_match ("/string/", $moduletype_name)) { + + $urlImage = ui_get_full_url(false, false, false, false); + + $return['chart'] = grafico_modulo_string( + $content['id_agent_module'], + $content['period'], + false, + $sizgraph_w, + $sizgraph_h, + '', + '', + false, + $only_avg, + false, + $report["datetime"], $only_image, $urlImage); + + } + else { + + $data[0] = grafico_modulo_sparse( + $content['id_agent_module'], + $content['period'], + false, + $sizgraph_w, + $sizgraph_h, + '', + '', + false, + $only_avg, + true, + $report["datetime"], + '', + 0, + 0, + true, + $only_image, + ui_get_full_url(false, false, false, false), + 1, + false, + '', + false, + true); + } break; case 'data': break; @@ -129,6 +264,22 @@ function reporting_get_date_text($id_report, $id_report_item) { return $return; } +/** + * Check the common items exits + */ +function reporting_check_structure_report($return) { + if (!isset($return['group_name'])) + $return['group_name'] = ""; + if (!isset($return['title'])) + $return['title'] = ""; + if (!isset($return['datetime'])) + $return['datetime'] = ""; + if (!isset($return['period'])) + $return['period'] = ""; + + return $return; +} + /** * Check the common items exits */ @@ -146,7 +297,603 @@ function reporting_check_structure_content($return) { $return["date"]['to'] = ""; } - return $return; } -?> + +/** + * Get general statistical info on a group + * + * @param int Group Id to get info from. 0 = all + * + * @return array Group statistics + */ +function reporting_get_group_stats ($id_group = 0, $access = 'AR') { + global $config; + + $data = array (); + $data["monitor_checks"] = 0; + $data["monitor_not_init"] = 0; + $data["monitor_unknown"] = 0; + $data["monitor_ok"] = 0; + $data["monitor_bad"] = 0; // Critical + Unknown + Warning + $data["monitor_warning"] = 0; + $data["monitor_critical"] = 0; + $data["monitor_not_normal"] = 0; + $data["monitor_alerts"] = 0; + $data["monitor_alerts_fired"] = 0; + $data["monitor_alerts_fire_count"] = 0; + $data["total_agents"] = 0; + $data["total_alerts"] = 0; + $data["total_checks"] = 0; + $data["alerts"] = 0; + $data["agents_unknown"] = 0; + $data["monitor_health"] = 100; + $data["alert_level"] = 100; + $data["module_sanity"] = 100; + $data["server_sanity"] = 100; + $data["total_not_init"] = 0; + $data["monitor_non_init"] = 0; + $data["agent_ok"] = 0; + $data["agent_warning"] = 0; + $data["agent_critical"] = 0; + $data["agent_unknown"] = 0; + $data["agent_not_init"] = 0; + + $cur_time = get_system_time (); + + //Check for access credentials using check_acl. More overhead, much safer + if (!check_acl ($config["id_user"], $id_group, $access)) { + return $data; + } + + if ($id_group == 0) { + $id_group = array_keys( + users_get_groups($config['id_user'], $access, false)); + } + + // ----------------------------------------------------------------- + // Server processed stats. NOT realtime (taken from tgroup_stat) + // ----------------------------------------------------------------- + if ($config["realtimestats"] == 0) { + + if (!is_array($id_group)){ + $my_group = $id_group; + $id_group = array(); + $id_group[0] = $my_group; + } + + foreach ($id_group as $group) { + $group_stat = db_get_all_rows_sql ("SELECT * + FROM tgroup_stat, tgrupo + WHERE tgrupo.id_grupo = tgroup_stat.id_group + AND tgroup_stat.id_group = $group + ORDER BY nombre"); + + $data["monitor_checks"] += $group_stat[0]["modules"]; + $data["agent_not_init"] += $group_stat[0]["non-init"]; + $data["agent_unknown"] += $group_stat[0]["unknown"]; + $data["agent_ok"] += $group_stat[0]["normal"]; + $data["agent_warning"] += $group_stat[0]["warning"]; + $data["agent_critical"] += $group_stat[0]["critical"]; + $data["monitor_alerts"] += $group_stat[0]["alerts"]; + $data["monitor_alerts_fired"] += $group_stat[0]["alerts_fired"]; + $data["monitor_alerts_fire_count"] += $group_stat[0]["alerts_fired"]; + $data["total_checks"] += $group_stat[0]["modules"]; + $data["total_alerts"] += $group_stat[0]["alerts"]; + $data["total_agents"] += $group_stat[0]["agents"]; + $data["agents_unknown"] += $group_stat[0]["agents_unknown"]; + $data["utimestamp"] = $group_stat[0]["utimestamp"]; + + // This fields are not in database + $data["monitor_ok"] += (int) groups_get_normal_monitors($group); + $data["monitor_warning"] += (int) groups_get_warning_monitors($group); + $data["monitor_critical"] += (int) groups_get_critical_monitors($group); + $data["monitor_unknown"] += (int) groups_get_unknown_monitors($group); + $data["monitor_not_init"] += (int) groups_get_not_init_monitors($group); + } + + // ------------------------------------------------------------------- + // Realtime stats, done by PHP Console + // ------------------------------------------------------------------- + } + else { + + if (!is_array($id_group)) { + $my_group = $id_group; + $id_group = array(); + $id_group[0] = $my_group; + } + + // Store the groups where we are quering + $covered_groups = array(); + $group_array = array(); + foreach ($id_group as $group) { + $children = groups_get_childrens($group); + + //Show empty groups only if they have children with agents + //$group_array = array(); + + foreach ($children as $sub) { + // If the group is quering previously, we ingore it + if (!in_array($sub['id_grupo'],$covered_groups)) { + array_push($covered_groups, $sub['id_grupo']); + array_push($group_array, $sub['id_grupo']); + } + + } + + // Add id of this group to create the clause + // If the group is quering previously, we ingore it + if (!in_array($group,$covered_groups)) { + array_push($covered_groups, $group); + array_push($group_array, $group); + } + + // If there are not groups to query, we jump to nextone + + if (empty($group_array)) { + continue; + } + } + + 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); + + $no_tags_restricted_groups = $group_array; + foreach ($no_tags_restricted_groups as $k => $v) { + if (in_array($v, $tags_restricted_groups)) { + unset($no_tags_restricted_groups[$k]); + } + } + */ + + if (!empty($group_array)) { + // Get monitor NOT INIT, except disabled AND async modules + $data["monitor_not_init"] += (int) groups_get_not_init_monitors ($group_array, array(), array(), false, false, true); + + // Get monitor OK, except disabled and non-init + $data["monitor_ok"] += (int) groups_get_normal_monitors ($group_array, array(), array(), false, false, true); + + // Get monitor CRITICAL, except disabled and non-init + $data["monitor_critical"] += (int) groups_get_critical_monitors ($group_array, array(), array(), false, false, true); + + // Get monitor WARNING, except disabled and non-init + $data["monitor_warning"] += (int) groups_get_warning_monitors ($group_array, array(), array(), false, false, true); + + // Get monitor UNKNOWN, except disabled and non-init + $data["monitor_unknown"] += (int) groups_get_unknown_monitors ($group_array, array(), array(), false, false, true); + + // Get alerts configured, except disabled + $data["monitor_alerts"] += groups_monitor_alerts ($group_array) ; + + // Get alert configured currently FIRED, except disabled + $data["monitor_alerts_fired"] += groups_monitor_fired_alerts ($group_array); + + // Calculate totals using partial counts from above + + // Get TOTAL non-init modules, except disabled ones and async modules + $data["total_not_init"] += $data["monitor_not_init"]; + + // Get TOTAL agents in a group + $data["total_agents"] += (int) groups_get_total_agents ($group_array, array(), array(), false, false, true); + + // Get Agents OK + $data["agent_ok"] += (int) groups_get_normal_agents ($group_array, array(), array(), false, false, true); + + // Get Agents Warning + $data["agent_warning"] += (int) groups_get_warning_agents ($group_array, array(), array(), false, false, true); + + // Get Agents Critical + $data["agent_critical"] += (int) groups_get_critical_agents ($group_array, array(), array(), false, false, true); + + // Get Agents Unknown + $data["agent_unknown"] += (int) groups_get_unknown_agents ($group_array, array(), array(), false, false, true); + + // Get Agents Not init + $data["agent_not_init"] += (int) groups_get_not_init_agents ($group_array, array(), array(), false, false, true); + } + + // 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"]; + + // Calculate not_normal monitors + $data["monitor_not_normal"] += $data["monitor_checks"] - $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"]; + + /* + Monitor health (percentage) + Data health (percentage) + Global health (percentage) + Module sanity (percentage) + Alert level (percentage) + + Server Sanity 0% Uninitialized modules + + */ + } + + if ($data["monitor_unknown"] > 0 && $data["monitor_checks"] > 0) { + $data["monitor_health"] = format_numeric (100 - ($data["monitor_not_normal"] / ($data["monitor_checks"] / 100)), 1); + } + else { + $data["monitor_health"] = 100; + } + + if ($data["monitor_not_init"] > 0 && $data["monitor_checks"] > 0) { + $data["module_sanity"] = format_numeric (100 - ($data["monitor_not_init"] / ($data["monitor_checks"] / 100)), 1); + } + else { + $data["module_sanity"] = 100; + } + + if (isset($data["alerts"])) { + if ($data["monitor_alerts_fired"] > 0 && $data["alerts"] > 0) { + $data["alert_level"] = format_numeric (100 - ($data ["monitor_alerts_fired"] / ($data["alerts"] / 100)), 1); + } + else { + $data["alert_level"] = 100; + } + } + else { + $data["alert_level"] = 100; + $data["alerts"] = 0; + } + + $data["monitor_bad"] = $data["monitor_critical"] + $data["monitor_warning"]; + + if ($data["monitor_bad"] > 0 && $data["monitor_checks"] > 0) { + $data["global_health"] = format_numeric (100 - ($data["monitor_bad"] / ($data["monitor_checks"] / 100)), 1); + } + else { + $data["global_health"] = 100; + } + + $data["server_sanity"] = format_numeric (100 - $data["module_sanity"], 1); + + + $data['alert_fired'] = 0; + if ($data["monitor_alerts_fired"] > 0) { + $data['alert_fired'] = 1; + } + + + if ($data["monitor_critical"] > 0) { + $data['status'] = 'critical'; + } + elseif ($data["monitor_warning"] > 0) { + $data['status'] = 'warning'; + } + elseif (($data["monitor_unknown"] > 0) || ($data["agents_unknown"] > 0)) { + $data['status'] = 'unknown'; + } + elseif ($data["monitor_ok"] > 0) { + $data['status'] = 'ok'; + } + elseif ($data["agent_not_init"] > 0) { + $data['status'] = 'not_init'; + } + else { + $data['status'] = 'none'; + } + + return ($data); +} + +function reporting_get_stats_indicators($data, $width = 280, $height = 20, $html = true) { + $table_ind = html_get_predefined_table(); + + $servers = array(); + $servers["all"] = (int) db_get_value ('COUNT(id_server)','tserver'); + $servers["up"] = (int) servers_check_status (); + $servers["down"] = $servers["all"] - $servers["up"]; + if ($servers["all"] == 0) { + $servers["health"] = 0; + } + else { + $servers["health"] = $servers["up"] / ($servers["all"] / 100); + } + + if ($html) { + $tdata[0] = '
+ ' . + __('Server health') . ui_print_help_tip (sprintf(__('%d Downed servers'), $servers["down"]), true) . + '' . + progress_bar($servers["health"], $width, $height, '', 0) . '
'; + $table_ind->rowclass[] = ''; + $table_ind->data[] = $tdata; + + $tdata[0] = '
+ ' . + __('Monitor health') . ui_print_help_tip (sprintf(__('%d Not Normal monitors'), $data["monitor_not_normal"]), true) . + '' . + progress_bar($data["monitor_health"], $width, $height, $data["monitor_health"].'% '.__('of monitors up'), 0) . '
'; + $table_ind->rowclass[] = ''; + $table_ind->data[] = $tdata; + + $tdata[0] = '
+ ' . + __('Module sanity') . ui_print_help_tip (sprintf(__('%d Not inited monitors'), $data["monitor_not_init"]), true) . + '' . + progress_bar($data["module_sanity"], $width, $height, $data["module_sanity"].'% '.__('of total modules inited'), 0) . '
'; + $table_ind->rowclass[] = ''; + $table_ind->data[] = $tdata; + + $tdata[0] = '
+ ' . + __('Alert level') . ui_print_help_tip (sprintf(__('%d Fired alerts'), $data["monitor_alerts_fired"]), true) . + '' . + progress_bar($data["alert_level"], $width, $height, $data["alert_level"].'% '.__('of defined alerts not fired'), 0) . '
'; + $table_ind->rowclass[] = ''; + $table_ind->data[] = $tdata; + + + return html_print_table($table_ind, true); + } + else { + $return = array(); + + $return['server_health'] = array( + 'title' => __('Server health'), + 'graph' => progress_bar($servers["health"], $width, $height, '', 0)); + $return['monitor_health'] = array( + 'title' => __('Monitor health'), + 'graph' => progress_bar($data["monitor_health"], $width, $height, $data["monitor_health"].'% '.__('of monitors up'), 0)); + $return['module_sanity'] = array( + 'title' => __('Module sanity'), + 'graph' => progress_bar($data["module_sanity"], $width, $height, $data["module_sanity"].'% '.__('of total modules inited'), 0)); + $return['alert_level'] = array( + 'title' => __('Alert level'), + 'graph' => progress_bar($data["alert_level"], $width, $height, $data["alert_level"].'% '.__('of defined alerts not fired'), 0)); + + return $return; + } +} + +function reporting_get_stats_alerts($data, $links = false) { + global $config; + + // Link URLS + $mobile = false; + if (isset($data['mobile'])) { + if ($data['mobile']) { + $mobile = true; + } + } + + if ($mobile) { + $urls = array(); + $urls['monitor_alerts'] = "index.php?page=alerts&status=all_enabled"; + $urls['monitor_alerts_fired'] = "index.php?page=alerts&status=fired"; + } + else { + $urls = array(); + if ($links) { + $urls['monitor_alerts'] = "index.php?sec=estado&sec2=operation/agentes/alerts_status&pure=" . $config['pure']; + $urls['monitor_alerts_fired'] = "index.php?sec=estado&sec2=operation/agentes/alerts_status&filter=fired&pure=" . $config['pure']; + } else { + $urls['monitor_alerts'] = "index.php?sec=estado&sec2=operation/agentes/alerts_status&refr=60"; + $urls['monitor_alerts_fired'] = "index.php?sec=estado&sec2=operation/agentes/alerts_status&refr=60&filter=fired"; + } + } + + // Alerts table + $table_al = html_get_predefined_table(); + + $tdata = array(); + $tdata[0] = html_print_image('images/bell.png', true, array('title' => __('Defined alerts'))); + $tdata[1] = $data["monitor_alerts"] <= 0 ? '-' : $data["monitor_alerts"]; + $tdata[1] = '' . $tdata[1] . ''; + + $tdata[2] = html_print_image('images/bell_error.png', true, array('title' => __('Fired alerts'))); + $tdata[3] = $data["monitor_alerts_fired"] <= 0 ? '-' : $data["monitor_alerts_fired"]; + $tdata[3] = '' . $tdata[3] . ''; + $table_al->rowclass[] = ''; + $table_al->data[] = $tdata; + + if (!defined('METACONSOLE')) { + $output = '
+ ' . + __('Defined and fired alerts') . + '' . + html_print_table($table_al, true) . '
'; + } + else { + $table_al->class = "tactical_view"; + $table_al->style = array(); + $output = '
+ ' . + __('Defined and fired alerts') . + '' . + html_print_table($table_al, true) . '
'; + } + return $output; +} + + +function reporting_get_stats_modules_status($data, $graph_width = 250, $graph_height = 150, $links = false, $data_agents=false) { + global $config; + + // Link URLS + if ($links === false) { + $urls = array(); + $urls['monitor_critical'] = "index.php?" . + "sec=estado&sec2=operation/agentes/status_monitor&" . + "refr=60&status=" . AGENT_MODULE_STATUS_CRITICAL_BAD . "&pure=" . $config['pure']; + $urls['monitor_warning'] = "index.php?" . + "sec=estado&sec2=operation/agentes/status_monitor&" . + "refr=60&status=" . AGENT_MODULE_STATUS_WARNING . "&pure=" . $config['pure']; + $urls['monitor_ok'] = "index.php?" . + "sec=estado&sec2=operation/agentes/status_monitor&" . + "refr=60&status=" . AGENT_MODULE_STATUS_NORMAL . "&pure=" . $config['pure']; + $urls['monitor_unknown'] = "index.php?" . + "sec=estado&sec2=operation/agentes/status_monitor&" . + "refr=60&status=" . AGENT_MODULE_STATUS_UNKNOWN . "&pure=" . $config['pure']; + $urls['monitor_not_init'] = "index.php?" . + "sec=estado&sec2=operation/agentes/status_monitor&" . + "refr=60&status=" . AGENT_MODULE_STATUS_NOT_INIT . "&pure=" . $config['pure']; + } + else { + $urls = array(); + $urls['monitor_critical'] = $links['monitor_critical']; + $urls['monitor_warning'] = $links['monitor_warning']; + $urls['monitor_ok'] = $links['monitor_ok']; + $urls['monitor_unknown'] = $links['monitor_unknown']; + $urls['monitor_not_init'] = $links['monitor_not_init']; + } + + // Modules by status table + $table_mbs = html_get_predefined_table(); + + $tdata = array(); + $tdata[0] = html_print_image('images/module_critical.png', true, array('title' => __('Monitor critical'))); + $tdata[1] = $data["monitor_critical"] <= 0 ? '-' : $data["monitor_critical"]; + $tdata[1] = '' . $tdata[1] . ''; + + $tdata[2] = html_print_image('images/module_warning.png', true, array('title' => __('Monitor warning'))); + $tdata[3] = $data["monitor_warning"] <= 0 ? '-' : $data["monitor_warning"]; + $tdata[3] = '' . $tdata[3] . ''; + $table_mbs->rowclass[] = ''; + $table_mbs->data[] = $tdata; + + $tdata = array(); + $tdata[0] = html_print_image('images/module_ok.png', true, array('title' => __('Monitor normal'))); + $tdata[1] = $data["monitor_ok"] <= 0 ? '-' : $data["monitor_ok"]; + $tdata[1] = '' . $tdata[1] . ''; + + $tdata[2] = html_print_image('images/module_unknown.png', true, array('title' => __('Monitor unknown'))); + $tdata[3] = $data["monitor_unknown"] <= 0 ? '-' : $data["monitor_unknown"]; + $tdata[3] = '' . $tdata[3] . ''; + $table_mbs->rowclass[] = ''; + $table_mbs->data[] = $tdata; + + $tdata = array(); + $tdata[0] = html_print_image('images/module_notinit.png', true, array('title' => __('Monitor not init'))); + $tdata[1] = $data["monitor_not_init"] <= 0 ? '-' : $data["monitor_not_init"]; + $tdata[1] = '' . $tdata[1] . ''; + + $tdata[2] = $tdata[3] = ''; + $table_mbs->rowclass[] = ''; + $table_mbs->data[] = $tdata; + + if ($data["monitor_checks"] > 0) { + $tdata = array(); + $table_mbs->colspan[count($table_mbs->data)][0] = 4; + $table_mbs->cellstyle[count($table_mbs->data)][0] = 'text-align: center;'; + $tdata[0] = '
' . + '
' . + graph_agent_status(false, $graph_width, $graph_height, true, true, $data_agents) . + '
'; + $table_mbs->rowclass[] = ''; + $table_mbs->data[] = $tdata; + } + + if (!defined("METACONSOLE")) { + $output = ' +
+ ' . + __('Monitors by status') . + '' . + html_print_table($table_mbs, true) . + '
'; + } + else { + $table_mbs->class = "tactical_view"; + $table_mbs->style=array(); + $output = ' +
+ ' . + __('Monitors by status') . + '' . + html_print_table($table_mbs, true) . + '
'; + } + + return $output; +} + +function reporting_get_stats_agents_monitors($data) { + global $config; + + // Link URLS + $mobile = false; + if (isset($data['mobile'])) { + if ($data['mobile']) { + $mobile = true; + } + } + + if ($mobile) { + $urls = array(); + $urls['total_agents'] = "index.php?page=agents"; + $urls['monitor_checks'] = "index.php?page=modules"; + } + else { + $urls = array(); + $urls['total_agents'] = "index.php?sec=estado&sec2=operation/agentes/estado_agente&refr=60"; + $urls['monitor_checks'] = "index.php?sec=estado&sec2=operation/agentes/status_monitor&refr=60&status=-1"; + } + + // Agents and modules table + $table_am = html_get_predefined_table(); + + $tdata = array(); + $tdata[0] = html_print_image('images/agent.png', true, array('title' => __('Total agents'))); + $tdata[1] = $data["total_agents"] <= 0 ? '-' : $data["total_agents"]; + $tdata[1] = '' . $tdata[1] . ''; + + $tdata[2] = html_print_image('images/module.png', true, array('title' => __('Monitor checks'))); + $tdata[3] = $data["monitor_checks"] <= 0 ? '-' : $data["monitor_checks"]; + $tdata[3] = '' . $tdata[3] . ''; + $table_am->rowclass[] = ''; + $table_am->data[] = $tdata; + + $output = '
+ ' . + __('Total agents and monitors') . + '' . + html_print_table($table_am, true) . '
'; + + return $output; +} + +function reporting_get_stats_users($data) { + global $config; + + // Link URLS + $urls = array(); + if (check_acl ($config['id_user'], 0, "UM")) { + $urls['defined_users'] = "index.php?sec=gusuarios&sec2=godmode/users/user_list"; + } + else { + $urls['defined_users'] = 'javascript:'; + } + + // Users table + $table_us = html_get_predefined_table(); + + $tdata = array(); + $tdata[0] = html_print_image('images/user_green.png', true, array('title' => __('Defined users'))); + $tdata[1] = count (get_users ()); + $tdata[1] = '' . $tdata[1] . ''; + + $tdata[2] = $tdata[3] = ' '; + $table_us->rowclass[] = ''; + $table_us->data[] = $tdata; + + $output = '
+ ' . + __('Users') . + '' . + html_print_table($table_us, true) . '
'; + + return $output; +} +?> \ No newline at end of file diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php new file mode 100644 index 0000000000..05c358befa --- /dev/null +++ b/pandora_console/include/functions_reporting_html.php @@ -0,0 +1,7880 @@ + ' . (int) $datelimit . + ' AND utimestamp < ' . (int) $date . + ' ORDER BY utimestamp ASC', $search_in_history_db); + if ($interval_data === false) $interval_data = array (); + + // Uncompressed module data + if ($uncompressed_module) { + $min_necessary = 1; + + // Compressed module data + } + else { + // Get previous data + $previous_data = modules_get_previous_data ($id_agent_module, $datelimit); + if ($previous_data !== false) { + $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) { + $next_data['utimestamp'] = $date; + array_push ($interval_data, $next_data); + } + else if (count ($interval_data) > 0) { + // Propagate the last known data to the end of the interval + $next_data = array_pop ($interval_data); + array_push ($interval_data, $next_data); + $next_data['utimestamp'] = $date; + array_push ($interval_data, $next_data); + } + + $min_necessary = 2; + } + + if (count ($interval_data) < $min_necessary) { + return false; + } + + // Set initial conditions + $total = 0; + $count = 0; + if (! $uncompressed_module) { + $previous_data = array_shift ($interval_data); + + // Do not count the empty start of an interval as 0 + if ($previous_data['utimestamp'] != $datelimit) { + $period = $date - $previous_data['utimestamp']; + } + } + foreach ($interval_data as $data) { + if (! $uncompressed_module) { + $total += $previous_data['datos'] * ($data['utimestamp'] - $previous_data['utimestamp']); + $previous_data = $data; + } + else { + $total += $data['datos']; + $count++; + } + } + + // Compressed module data + if (! $uncompressed_module) { + if ($period == 0) { + return 0; + } + + return $total / $period; + } + + // Uncompressed module data + if ($count == 0) { + return 0; + } + + return $total / $count; +} + +/** + * Get the maximum value of an agent module in a period of time. + * + * @param int Agent module id to get the maximum value. + * @param int Period of time to check (in seconds) + * @param int Top date to check the values. Default current time. + * + * @return float The maximum module value in the interval. + */ +function reporting_get_agentmodule_data_max ($id_agent_module, $period=0, $date = 0) { + global $config; + + // Initialize variables + if (empty ($date)) $date = get_system_time (); + $datelimit = $date - $period; + + $search_in_history_db = db_search_in_history_db($datelimit); + + $id_module_type = modules_get_agentmodule_type ($id_agent_module); + $module_type = modules_get_moduletype_name ($id_module_type); + $uncompressed_module = is_module_uncompressed ($module_type); + + // Get module data + $interval_data = db_get_all_rows_sql ('SELECT * + FROM tagente_datos + WHERE id_agente_modulo = ' . (int) $id_agent_module . + ' AND utimestamp > ' . (int) $datelimit . + ' AND utimestamp < ' . (int) $date . + ' ORDER BY utimestamp ASC', $search_in_history_db); + if ($interval_data === false) $interval_data = array (); + + // Uncompressed module data + if ($uncompressed_module) { + + // Compressed module data + } + else { + // Get previous data + $previous_data = modules_get_previous_data ($id_agent_module, $datelimit); + if ($previous_data !== false) { + $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) { + $next_data['utimestamp'] = $date; + array_push ($interval_data, $next_data); + } + else if (count ($interval_data) > 0) { + // Propagate the last known data to the end of the interval + $next_data = array_pop ($interval_data); + array_push ($interval_data, $next_data); + $next_data['utimestamp'] = $date; + array_push ($interval_data, $next_data); + } + } + + // Set initial conditions + if (empty($iterval_data)) { + $max = 0; + } + else { + if ($uncompressed_module || $interval_data[0]['utimestamp'] == $datelimit) { + $max = $interval_data[0]['datos']; + } + else { + $max = 0; + } + } + + foreach ($interval_data as $data) { + if ($data['datos'] > $max) { + $max = $data['datos']; + } + } + + return $max; +} + +/** + * Get the minimum value of an agent module in a period of time. + * + * @param int Agent module id to get the minimum value. + * @param int Period of time to check (in seconds) + * @param int Top date to check the values in Unix time. Default current time. + * + * @return float The minimum module value of the module + */ +function reporting_get_agentmodule_data_min ($id_agent_module, $period=0, $date = 0) { + global $config; + + // Initialize variables + if (empty ($date)) $date = get_system_time (); + $datelimit = $date - $period; + + $search_in_history_db = db_search_in_history_db($datelimit); + + $id_module_type = modules_get_agentmodule_type ($id_agent_module); + $module_type = modules_get_moduletype_name ($id_module_type); + $uncompressed_module = is_module_uncompressed ($module_type); + + // Get module data + $interval_data = db_get_all_rows_sql ('SELECT * + FROM tagente_datos + WHERE id_agente_modulo = ' . (int) $id_agent_module . + ' AND utimestamp > ' . (int) $datelimit . + ' AND utimestamp < ' . (int) $date . + ' ORDER BY utimestamp ASC', $search_in_history_db); + if ($interval_data === false) $interval_data = array (); + + // Uncompressed module data + if ($uncompressed_module) { + $min_necessary = 1; + + // Compressed module data + } + else { + // Get previous data + $previous_data = modules_get_previous_data ($id_agent_module, $datelimit); + if ($previous_data !== false) { + $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) { + $next_data['utimestamp'] = $date; + array_push ($interval_data, $next_data); + } + else if (count ($interval_data) > 0) { + // Propagate the last known data to the end of the interval + $next_data = array_pop ($interval_data); + array_push ($interval_data, $next_data); + $next_data['utimestamp'] = $date; + array_push ($interval_data, $next_data); + } + } + + if (count ($interval_data) < 1) { + return false; + } + + // Set initial conditions + $min = $interval_data[0]['datos']; + + foreach ($interval_data as $data) { + if ($data['datos'] < $min) { + $min = $data['datos']; + } + } + + return $min; +} + +/** + * Get the sum of values of an agent module in a period of time. + * + * @param int Agent module id to get the sumatory. + * @param int Period of time to check (in seconds) + * @param int Top date to check the values. Default current time. + * + * @return float The sumatory of the module values in the interval. + */ +function reporting_get_agentmodule_data_sum ($id_agent_module, + $period = 0, $date = 0) { + + global $config; + + // Initialize variables + if (empty ($date)) $date = get_system_time (); + $datelimit = $date - $period; + + $search_in_history_db = db_search_in_history_db($datelimit); + + $id_module_type = db_get_value ('id_tipo_modulo', 'tagente_modulo', + 'id_agente_modulo', $id_agent_module); + $module_name = db_get_value ('nombre', 'ttipo_modulo', 'id_tipo', + $id_module_type); + $module_interval = modules_get_interval ($id_agent_module); + $uncompressed_module = is_module_uncompressed ($module_name); + + // Wrong module type + if (is_module_data_string ($module_name)) { + return 0; + } + + // Incremental modules are treated differently + $module_inc = is_module_inc ($module_name); + + // Get module data + $interval_data = db_get_all_rows_sql(' + SELECT * FROM tagente_datos + WHERE id_agente_modulo = ' . (int) $id_agent_module . ' + AND utimestamp > ' . (int) $datelimit . ' + AND utimestamp < ' . (int) $date . ' + ORDER BY utimestamp ASC', $search_in_history_db); + if ($interval_data === false) $interval_data = array (); + + // Uncompressed module data + if ($uncompressed_module) { + $min_necessary = 1; + + // Compressed module data + } + else { + // Get previous data + $previous_data = modules_get_previous_data ($id_agent_module, $datelimit); + if ($previous_data !== false) { + $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) { + $next_data['utimestamp'] = $date; + array_push ($interval_data, $next_data); + } + else if (count ($interval_data) > 0) { + // Propagate the last known data to the end of the interval + $next_data = array_pop ($interval_data); + array_push ($interval_data, $next_data); + $next_data['utimestamp'] = $date; + array_push ($interval_data, $next_data); + } + + $min_necessary = 2; + } + + if (count ($interval_data) < $min_necessary) { + return false; + } + + // Set initial conditions + $total = 0; + if (! $uncompressed_module) { + $previous_data = array_shift ($interval_data); + } + + foreach ($interval_data as $data) { + if ($uncompressed_module) { + $total += $data['datos']; + } + else if ($module_inc) { + $total += $previous_data['datos'] * ($data['utimestamp'] - $previous_data['utimestamp']); + } + else { + $total += $previous_data['datos'] * ($data['utimestamp'] - $previous_data['utimestamp']) / $module_interval; + } + $previous_data = $data; + } + + return $total; +} + +/** + * Get SLA of a module. + * + * @param int Agent module to calculate SLA + * @param int Period to check the SLA compliance. + * @param int Minimum data value the module in the right interval + * @param int Maximum data value the module in the right interval. False will + * ignore max value + * @param int Beginning date of the report in UNIX time (current date by default). + * @param array $dayWeek Array of days week to extract as array('monday' => false, 'tuesday' => true....), and by default is null. + * @param string $timeFrom Time in the day to start to extract in mysql format, by default null. + * @param string $timeTo Time in the day to end to extract in mysql format, by default null. + * + * @return float SLA percentage of the requested module. False if no data were + * found + */ +function reporting_get_agentmodule_sla ($id_agent_module, $period = 0, $min_value = 1, $max_value = false, $date = 0, $daysWeek = null, $timeFrom = null, $timeTo = null) { + global $config; + + if (empty($id_agent_module)) + return false; + + // Initialize variables + if (empty ($date)) { + $date = get_system_time (); + } + if ($daysWeek === null) { + $daysWeek = array(); + } + // Limit date to start searching data + $datelimit = $date - $period; + + $search_in_history_db = db_search_in_history_db($datelimit); + + // Get interval data + $sql = sprintf ('SELECT * + FROM tagente_datos + 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 + if ($daysWeek) { + foreach ($daysWeek as $key => $value) { + if (!$value) { + if ($key == 'monday') { + $days[] = 2; + } + if ($key == 'tuesday') { + $days[] = 3; + } + if ($key == 'wednesday') { + $days[] = 4; + } + if ($key == 'thursday') { + $days[] = 5; + } + if ($key == 'friday') { + $days[] = 6; + } + if ($key == 'saturday') { + $days[] = 7; + } + if ($key == 'sunday') { + $days[] = 1; + } + } + } + } + + if (count($days) > 0) { + $sql .= ' AND DAYOFWEEK(FROM_UNIXTIME(utimestamp)) NOT IN (' . implode(',', $days) . ')'; + } + + if ($timeFrom < $timeTo) { + $sql .= ' AND (TIME(FROM_UNIXTIME(utimestamp)) >= "' . $timeFrom . '" AND TIME(FROM_UNIXTIME(utimestamp)) <= "'. $timeTo . '")'; + } + elseif ($timeFrom > $timeTo) { + $sql .= ' AND (TIME(FROM_UNIXTIME(utimestamp)) >= "' . $timeFrom . '" OR TIME(FROM_UNIXTIME(utimestamp)) <= "'. $timeTo . '")'; + } + $sql .= ' ORDER BY utimestamp ASC'; + $interval_data = db_get_all_rows_sql ($sql, $search_in_history_db); + + if ($interval_data === false) { + $interval_data = array (); + } + + // Calculate planned downtime dates + $downtime_dates = reporting_get_planned_downtimes_intervals($id_agent_module, $datelimit, $date); + + // Get previous data + $previous_data = modules_get_previous_data ($id_agent_module, $datelimit); + if ($previous_data !== false) { + $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) { + $next_data['utimestamp'] = $date; + array_push ($interval_data, $next_data); + } + else if (count ($interval_data) > 0) { + // Propagate the last known data to the end of the interval + $next_data = array_pop ($interval_data); + array_push ($interval_data, $next_data); + $next_data['utimestamp'] = $date; + array_push ($interval_data, $next_data); + } + + if (count ($interval_data) < 2) { + return false; + } + + // Set initial conditions + $bad_period = 0; + $first_data = array_shift ($interval_data); + + // Do not count the empty start of an interval as 0 + if ($first_data['utimestamp'] != $datelimit) { + $period = $date - $first_data['utimestamp']; + } + + $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; + } + } + } + else { + $previous_status = 0; + } + + foreach ($interval_data as $data) { + // Previous status was critical + if ($previous_status == 1) { + $bad_period += $data['utimestamp'] - $previous_utimestamp; + } + + if (array_key_exists('datos', $data)) { + // Re-calculate previous status for the next data + if ((($max_value > $min_value AND ($data['datos'] > $max_value OR $data['datos'] < $min_value))) OR + ($max_value <= $min_value AND $data['datos'] < $min_value)) { + + $previous_status = 1; + foreach ($downtime_dates as $date_dt) { + if (($date_dt['date_from'] <= $data['utimestamp']) AND ($date_dt['date_to'] >= $data['utimestamp'])) { + $previous_status = 0; + } + } + } + else { + $previous_status = 0; + } + } + + $previous_utimestamp = $data['utimestamp']; + } + + // Return the percentage of SLA compliance + return (float) (100 - ($bad_period / $period) * 100); +} +/** + * Get several SLA data for an agentmodule within a period divided on subperiods + * + * @param int Agent module to calculate SLA + * @param int Period to check the SLA compliance. + * @param int Minimum data value the module in the right interval + * @param int Maximum data value the module in the right interval. False will + * ignore max value + * @param array $days Array of days week to extract as array('monday' => false, 'tuesday' => true....), and by default is null. + * @param string $timeFrom Time in the day to start to extract in mysql format, by default null. + * @param string $timeTo Time in the day to end to extract in mysql format, by default null. + * + * @return Array with values either 1, 2, 3 or 4 depending if the SLA percentage for this subperiod + * is within the sla limits, on the edge, outside or with an unknown value. + */ +function reporting_get_agentmodule_sla_array ($id_agent_module, $period = 0, $min_value = 1, $max_value = false, $date = 0, $daysWeek = null, $timeFrom = null, $timeTo = null) { + global $config; + + if (empty($id_agent_module)) + return false; + + // Initialize variables + if (empty ($date)) { + $date = get_system_time (); + } + if ($daysWeek === null) { + $daysWeek = array(); + } + + // Hotfix: The edge values are confuse to the users + $percent = 0; + + // Limit date to start searching data + $datelimit = $date - $period; + + $search_in_history_db = db_search_in_history_db($datelimit); + + // Get interval data + $sql = sprintf ('SELECT * FROM tagente_datos + 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 + + if ($daysWeek) { + foreach ($daysWeek as $key => $value) { + if (!$value) { + if ($key == 'monday') { + $days[] = 2; + } + if ($key == 'tuesday') { + $days[] = 3; + } + if ($key == 'wednesday') { + $days[] = 4; + } + if ($key == 'thursday') { + $days[] = 5; + } + if ($key == 'friday') { + $days[] = 6; + } + if ($key == 'saturday') { + $days[] = 7; + } + if ($key == 'sunday') { + $days[] = 1; + } + } + } + } + + if (count($days) > 0) { + $sql .= ' AND DAYOFWEEK(FROM_UNIXTIME(utimestamp)) NOT IN (' . implode(',', $days) . ')'; + } + + if ($timeFrom != $timeTo) { + if ($timeFrom < $timeTo) { + $sql .= ' AND (TIME(FROM_UNIXTIME(utimestamp)) >= "' . $timeFrom . '" AND TIME(FROM_UNIXTIME(utimestamp)) <= "'. $timeTo . '")'; + } + elseif ($timeFrom > $timeTo) { + $sql .= ' AND (TIME(FROM_UNIXTIME(utimestamp)) >= "' . $timeFrom . '" OR TIME(FROM_UNIXTIME(utimestamp)) <= "'. $timeTo . '")'; + } + } + + $sql .= ' ORDER BY utimestamp ASC'; + $interval_data = db_get_all_rows_sql ($sql, $search_in_history_db); + + if ($interval_data === false) { + $interval_data = array (); + } + + + // Indexing data + $interval_data_indexed = array(); + 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, + "utimestamp > $datelimit", + "utimestamp < $date", + 'order' => 'utimestamp ASC'), + array ('id_evento', 'evento', 'timestamp', 'utimestamp', 'event_type')); + + if ($events_unknown === false) { + $events_unknown = array (); + } + + // Add unknown periods to data + for ($i = 0; isset($events_unknown[$i]); $i++) { + $eu = $events_unknown[$i]; + + if ($eu['event_type'] == 'going_unknown') { + $interval_data_indexed[$eu['utimestamp']]['data'] = 0; + $interval_data_indexed[$eu['utimestamp']]['status'] = 4; + + // Search the corresponding recovery event. + for ($j = $i+1; isset($events_unknown[$j]); $j++) { + $eu = $events_unknown[$j]; + + if ($eu['event_type'] != 'going_unknown' && substr ($eu['event_type'], 0, 5) == 'going') { + $interval_data_indexed[$eu['utimestamp']]['data'] = 0; + $interval_data_indexed[$eu['utimestamp']]['status'] = 6; + + // Do not process read events again. + $i = $j; + break; + } + } + } + } + + // 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, + "utimestamp <= $datelimit", + 'order' => 'utimestamp DESC')); + if (isset($prev_event['event_type']) && $prev_event['event_type'] == 'going_unknown') { + $start_unknown = true; + } + else { + $start_unknown = false; + } + //------------------------------------------------------------------ + + //-----------------Set limits of the interval----------------------- + // 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 ) { + $previous_value = $previous_data['datos']; + // if ((($previous_value > ($min_value - $percent)) && ($previous_value < ($min_value + $percent))) || + // (($previous_value > ($max_value - $percent)) && ($previous_value < ($max_value + $percent)))) {//2 when value is within the edges + // $previous_known_status = 2; + // } + // else + if (($previous_value >= ($min_value + $percent)) && ($previous_value <= ($max_value - $percent))) { //1 when value is OK + $previous_known_status = 1; + } + elseif (($previous_value <= ($min_value - $percent)) || ($previous_value >= ($max_value + $percent))) { //3 when value is Wrong + $previous_known_status = 3; + } + } + + // If the starting of the graph is unknown we set it + if ($start_unknown) { + $interval_data_indexed[$datelimit]['data'] = 0; + $interval_data_indexed[$datelimit]['status'] = 4; + } + else { + if ($previous_data !== false ) { + $interval_data_indexed[$datelimit]['data'] = $previous_data['datos']; + } + else { // If there are not data befor interval set unknown + $interval_data_indexed[$datelimit]['data'] = 0; + $interval_data_indexed[$datelimit]['status'] = 4; + $previous_known_status = 1; // Assume the module was in normal status if there is no previous data. + } + } + + // 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) { + $interval_data_indexed[$date]['data'] = $previous_data['datos']; + } + else if (count ($interval_data_indexed) > 0) { + // Propagate the last known data to the end of the interval (if there is no module data at the end point) + ksort($interval_data_indexed); + $last_data = end($interval_data_indexed); + $interval_data_indexed[$date] = $last_data; + } + + //------------------------------------------------------------------ + + //--------Calculate planned downtime dates-------------------------- + $downtime_dates = reporting_get_planned_downtimes_intervals($id_agent_module, $datelimit, $date); + + foreach ($downtime_dates as $downtime_date) { + // Delete data of the planned downtime and put the last data on the upper limit + $interval_data_indexed[$downtime_date['date_from']]['data'] = 0; + $interval_data_indexed[$downtime_date['date_from']]['status'] = 5; + $interval_data_indexed[$downtime_date['date_to']]['data'] = 0; + $interval_data_indexed[$downtime_date['date_to']]['status'] = 4; + + $last_downtime_data = false; + foreach ($interval_data_indexed as $idi_timestamp => $idi) { + if ($idi_timestamp != $downtime_date['date_from'] && $idi_timestamp != $downtime_date['date_to'] && + $idi_timestamp >= $downtime_date['date_from'] && $idi_timestamp <= $downtime_date['date_to']) { + $last_downtime_data = $idi['data']; + unset($interval_data_indexed[$idi_timestamp]); + } + } + + // Set the last data of the interval as limit + if ($last_downtime_data !== false) { + $interval_data_indexed[$downtime_date['date_to']]['data'] = $last_downtime_data; + } + } + //------------------------------------------------------------------ + + // Sort the array + ksort($interval_data_indexed); + + // We need more or equal two points + if (count ($interval_data_indexed) < 2) { + return false; + } + + //Get the percentage for the limits + $diff = $max_value - $min_value; + + // Get module type + $id_module_type = db_get_value('id_tipo_modulo', 'tagente_modulo', 'id_agente_modulo', $id_agent_module); + // If module is boolean don't create translation intervals (on the edge intervals) + // if ($id_module_type == 2 or $id_module_type == 6 or $id_module_type == 9 or $id_module_type == 18){ + // $percent = 0; + // } + // else { + // // Getting 10% of $diff --> $percent = ($diff/100)*10, so... + // $percent = $diff / 10; + // } + + //Set initial conditions + $first_data = array_shift ($interval_data); + $previous_utimestamp = $date - $period; + + $previous_value = $first_data ['datos']; + $previous_status = 0; + + if (isset($first_data['status'])) { + // 4 for the Unknown value and 5 for planned downtime + $previous_status = $first_data['status']; + } + // elseif ((($previous_value > ($min_value - $percent)) && ($previous_value < ($min_value + $percent))) || + // (($previous_value > ($max_value - $percent)) && ($previous_value < ($max_value + $percent)))) {//2 when value is within the edges + // $previous_status = 2; + // } + elseif (($previous_value >= ($min_value + $percent)) && ($previous_value <= ($max_value - $percent))) { //1 when value is OK + $previous_status = 1; + } + elseif (($previous_value <= ($min_value - $percent)) || ($previous_value >= ($max_value + $percent))) { //3 when value is Wrong + $previous_status = 3; + } + + $data_colors = array(); + $i = 0; + + foreach ($interval_data_indexed as $utimestamp => $data) { + $change = false; + $value = $data['data']; + if (isset($data['status'])) { + // Leaving unkown status. + if ($data['status'] == 6) { + $status = $previous_known_status; + } + // 4 unknown, 5 planned downtime. + else { + $status = $data['status']; + } + } + // elseif ((($value > ($min_value - $percent)) && ($value < ($min_value + $percent))) || + // (($value > ($max_value - $percent)) && ($value < ($max_value + $percent)))) { //2 when value is within the edges + // $status = 2; + // } + elseif (($value >= ($min_value + $percent)) && ($value <= ($max_value - $percent))) { //1 when value is OK + $status = 1; + } + elseif (($value <= ($min_value - $percent)) || ($value >= ($max_value + $percent))) { //3 when value is Wrong + $status = 3; + } + + if ($status != $previous_status) { + $change = true; + $data_colors[$i]['data'] = $previous_status; + $data_colors[$i]['utimestamp'] = $utimestamp - $previous_utimestamp; + $i++; + $previous_status = $status; + $previous_utimestamp = $utimestamp; + } + + // Save the last known status. + if ($status <= 3) { + $previous_known_status = $status; + } + } + if ($change == false) { + $data_colors[$i]['data'] = $previous_status; + $data_colors[$i]['utimestamp'] = $date - $previous_utimestamp; + } + + return $data_colors; +} + +/** + * Get the time intervals where an agentmodule is affected by the planned downtimes. + * + * @param int Agent module to calculate planned downtimes intervals. + * @param int Start date in utimestamp. + * @param int End date in utimestamp. + * @param bool Whether ot not to get the planned downtimes that affect the service associated with the agentmodule. + * + * @return Array with time intervals. + */ +function reporting_get_planned_downtimes_intervals ($id_agent_module, $start_date, $end_date, $check_services = false) { + global $config; + + if (empty($id_agent_module)) + return false; + + require_once ($config['homedir'] . '/include/functions_planned_downtimes.php'); + + $malformed_planned_downtimes = planned_downtimes_get_malformed(); + if (empty($malformed_planned_downtimes)) + $malformed_planned_downtimes = array(); + + $sql_downtime = "SELECT DISTINCT(tpdr.id), tpdr.* + FROM ( + SELECT tpd.* + FROM tplanned_downtime tpd, tplanned_downtime_agents tpda, tagente_modulo tam + WHERE tpd.id = tpda.id_downtime + AND tpda.all_modules = 1 + AND tpda.id_agent = tam.id_agente + AND tam.id_agente_modulo = $id_agent_module + UNION ALL + SELECT tpd.* + FROM tplanned_downtime tpd, tplanned_downtime_modules tpdm + WHERE tpd.id = tpdm.id_downtime + AND tpdm.id_agent_module = $id_agent_module + ) tpdr + ORDER BY tpdr.id"; + + $downtimes = db_get_all_rows_sql($sql_downtime); + + if ($downtimes == false) { + $downtimes = array(); + } + $downtime_dates = array(); + foreach ($downtimes as $downtime) { + $downtime_id = $downtime['id']; + $downtime_type = $downtime['type_execution']; + $downtime_periodicity = $downtime['type_periodicity']; + + if ($downtime_type == 'once') { + $dates = array(); + $dates['date_from'] = $downtime['date_from']; + $dates['date_to'] = $downtime['date_to']; + $downtime_dates[] = $dates; + } + else if ($downtime_type == 'periodically') { + + // If a planned downtime have malformed dates, its intervals aren't taken account + $downtime_malformed = false; + foreach ($malformed_planned_downtimes as $malformed_planned_downtime) { + if ($downtime_id == $malformed_planned_downtime['id']) { + $downtime_malformed = true; + break; + } + } + if ($downtime_malformed == true) { + continue; + } + // If a planned downtime have malformed dates, its intervals aren't taken account + + $downtime_time_from = $downtime['periodically_time_from']; + $downtime_time_to = $downtime['periodically_time_to']; + + $downtime_hour_from = date("H", strtotime($downtime_time_from)); + $downtime_minute_from = date("i", strtotime($downtime_time_from)); + $downtime_second_from = date("s", strtotime($downtime_time_from)); + $downtime_hour_to = date("H", strtotime($downtime_time_to)); + $downtime_minute_to = date("i", strtotime($downtime_time_to)); + $downtime_second_to = date("s", strtotime($downtime_time_to)); + + if ($downtime_periodicity == "monthly") { + $downtime_day_from = $downtime['periodically_day_from']; + $downtime_day_to = $downtime['periodically_day_to']; + + $date_aux = strtotime(date("Y-m-01", $start_date)); + $year_aux = date("Y", $date_aux); + $month_aux = date("m", $date_aux); + + $end_year = date("Y", $end_date); + $end_month = date("m", $end_date); + + while ($year_aux < $end_year || ($year_aux == $end_year && $month_aux <= $end_month)) { + + if ($downtime_day_from > $downtime_day_to) { + $dates = array(); + $dates['date_from'] = strtotime("$year_aux-$month_aux-$downtime_day_from $downtime_hour_from:$downtime_minute_from:$downtime_second_from"); + $dates['date_to'] = strtotime(date("Y-m-t H:i:s", strtotime("$year_aux-$month_aux-28 23:59:59"))); + $downtime_dates[] = $dates; + + $dates = array(); + if ($month_aux + 1 <= 12) { + $dates['date_from'] = strtotime("$year_aux-".($month_aux + 1)."-01 00:00:00"); + $dates['date_to'] = strtotime("$year_aux-".($month_aux + 1)."-$downtime_day_to $downtime_hour_to:$downtime_minute_to:$downtime_second_to"); + } + else { + $dates['date_from'] = strtotime(($year_aux + 1)."-01-01 00:00:00"); + $dates['date_to'] = strtotime(($year_aux + 1)."-01-$downtime_day_to $downtime_hour_to:$downtime_minute_to:$downtime_second_to"); + } + $downtime_dates[] = $dates; + } + else { + if ($downtime_day_from == $downtime_day_to && strtotime($downtime_time_from) > strtotime($downtime_time_to)) { + $date_aux_from = strtotime("$year_aux-$month_aux-$downtime_day_from $downtime_hour_from:$downtime_minute_from:$downtime_second_from"); + $max_day_num = date('t', $date_aux); + + $dates = array(); + $dates['date_from'] = strtotime("$year_aux-$month_aux-$downtime_day_from $downtime_hour_from:$downtime_minute_from:$downtime_second_from"); + $dates['date_to'] = strtotime("$year_aux-$month_aux-$downtime_day_from 23:59:59"); + $downtime_dates[] = $dates; + + if ($downtime_day_to + 1 > $max_day_num) { + + $dates = array(); + if ($month_aux + 1 <= 12) { + $dates['date_from'] = strtotime("$year_aux-".($month_aux + 1)."-01 00:00:00"); + $dates['date_to'] = strtotime("$year_aux-".($month_aux + 1)."-01 $downtime_hour_to:$downtime_minute_to:$downtime_second_to"); + } + else { + $dates['date_from'] = strtotime(($year_aux + 1)."-01-01 00:00:00"); + $dates['date_to'] = strtotime(($year_aux + 1)."-01-01 $downtime_hour_to:$downtime_minute_to:$downtime_second_to"); + } + $downtime_dates[] = $dates; + } + else { + $dates = array(); + $dates['date_from'] = strtotime("$year_aux-$month_aux-".($downtime_day_to + 1)." 00:00:00"); + $dates['date_to'] = strtotime("$year_aux-$month_aux-".($downtime_day_to + 1)." $downtime_hour_to:$downtime_minute_to:$downtime_second_to"); + $downtime_dates[] = $dates; + } + } + else { + $dates = array(); + $dates['date_from'] = strtotime("$year_aux-$month_aux-$downtime_day_from $downtime_hour_from:$downtime_minute_from:$downtime_second_from"); + $dates['date_to'] = strtotime("$year_aux-$month_aux-$downtime_day_to $downtime_hour_to:$downtime_minute_to:$downtime_second_to"); + $downtime_dates[] = $dates; + } + } + + $month_aux++; + if ($month_aux > 12) { + $month_aux = 1; + $year_aux++; + } + } + } + else if ($downtime_periodicity == "weekly") { + $date_aux = $start_date; + $active_days = array(); + $active_days[0] = ($downtime['sunday'] == 1) ? true : false; + $active_days[1] = ($downtime['monday'] == 1) ? true : false; + $active_days[2] = ($downtime['tuesday'] == 1) ? true : false; + $active_days[3] = ($downtime['wednesday'] == 1) ? true : false; + $active_days[4] = ($downtime['thursday'] == 1) ? true : false; + $active_days[5] = ($downtime['friday'] == 1) ? true : false; + $active_days[6] = ($downtime['saturday'] == 1) ? true : false; + + while ($date_aux <= $end_date) { + $weekday_num = date('w', $date_aux); + + if ($active_days[$weekday_num]) { + $day_num = date('d', $date_aux); + $month_num = date('m', $date_aux); + $year_num = date('Y', $date_aux); + + $max_day_num = date('t', $date_aux); + + if (strtotime($downtime_time_from) > strtotime($downtime_time_to)) { + $dates = array(); + $dates['date_from'] = strtotime("$year_num-$month_num-$day_num $downtime_hour_from:$downtime_minute_from:$downtime_second_from"); + $dates['date_to'] = strtotime("$year_num-$month_num-$day_num 23:59:59"); + $downtime_dates[] = $dates; + + $dates = array(); + if ($day_num + 1 > $max_day_num) { + if ($month_num + 1 > 12) { + $dates['date_from'] = strtotime(($year_num + 1)."-01-01 00:00:00"); + $dates['date_to'] = strtotime(($year_num + 1)."-01-01 $downtime_hour_to:$downtime_minute_to:$downtime_second_to"); + } + else { + $dates['date_from'] = strtotime("$year_num-".($month_num + 1)."-01 00:00:00"); + $dates['date_to'] = strtotime("$year_num-".($month_num + 1)."-01 $downtime_hour_to:$downtime_minute_to:$downtime_second_to"); + } + } + else { + $dates['date_from'] = strtotime("$year_num-$month_num-".($day_num + 1)." 00:00:00"); + $dates['date_to'] = strtotime("$year_num-$month_num-".($day_num + 1)." $downtime_hour_to:$downtime_minute_to:$downtime_second_to"); + } + $downtime_dates[] = $dates; + } + else { + $dates = array(); + $dates['date_from'] = strtotime("$year_num-$month_num-$day_num $downtime_hour_from:$downtime_minute_from:$downtime_second_from"); + $dates['date_to'] = strtotime("$year_num-$month_num-$day_num $downtime_hour_to:$downtime_minute_to:$downtime_second_to"); + $downtime_dates[] = $dates; + } + } + + $date_aux += SECONDS_1DAY; + } + } + } + } + + if ($check_services) { + enterprise_include_once("include/functions_services.php"); + if (function_exists("services_get_planned_downtimes_intervals")) { + services_get_planned_downtimes_intervals($downtime_dates, $start_date, $end_date, false, $id_agent_module); + } + } + + return $downtime_dates; +} + +/** + * Get the planned downtimes that affect the passed modules on an specific datetime range. + * + * @param int Start date in utimestamp. + * @param int End date in utimestamp. + * @param array The agent modules ids. + * + * @return Array with the planned downtimes that are executed in any moment of the range selected and affect the + * agent modules selected. + */ +function reporting_get_planned_downtimes ($start_date, $end_date, $id_agent_modules = false) { + $start_time = date("H:i:s", $start_date); + $end_time = date("H:i:s", $end_date); + + $start_day = date("d", $start_date); + $end_day = date("d", $end_date); + + $start_month = date("m", $start_date); + $end_month = date("m", $end_date); + + if ($start_date > $end_date) { + return false; + } + + if ($end_date - $start_date >= SECONDS_1MONTH) { + // If the date range is larger than 1 month, every monthly planned downtime will be inside + $periodically_monthly_w = "type_periodicity = 'monthly'"; + } + else { + // Check if the range is larger than the planned downtime execution, or if its start or end + // is inside the planned downtime execution. + // The start and end time is very important. + $periodically_monthly_w = "type_periodicity = 'monthly' + AND (((periodically_day_from > '$start_day' + OR (periodically_day_from = '$start_day' + AND periodically_time_from >= '$start_time')) + AND (periodically_day_to < '$end_day' + OR (periodically_day_to = '$end_day' + AND periodically_time_to <= '$end_time'))) + OR ((periodically_day_from < '$start_day' + OR (periodically_day_from = '$start_day' + AND periodically_time_from <= '$start_time')) + AND (periodically_day_to > '$start_day' + OR (periodically_day_to = '$start_day' + AND periodically_time_to >= '$start_time'))) + OR ((periodically_day_from < '$end_day' + OR (periodically_day_from = '$end_day' + AND periodically_time_from <= '$end_time')) + AND (periodically_day_to > '$end_day' + OR (periodically_day_to = '$end_day' + AND periodically_time_to >= '$end_time'))))"; + } + + $periodically_weekly_days = array(); + $date_aux = $start_date; + $i = 0; + + if (($end_date - $start_date) >= SECONDS_1WEEK) { + // If the date range is larger than 7 days, every weekly planned downtime will be inside. + for ($i = 0; $i < 7; $i++) { + $weekday_actual = strtolower(date('l', $date_aux)); + $periodically_weekly_days[] = "($weekday_actual = 1)"; + $date_aux += SECONDS_1DAY; + } + } + else if (($end_date - $start_date) <= SECONDS_1DAY && $start_day == $end_day) { + // If the date range is smaller than 1 day, the start and end days can be equal or consecutive. + // If they are equal, the execution times have to be contained in the date range times or contain + // the start or end time of the date range. + $weekday_actual = strtolower(date('l', $start_date)); + $periodically_weekly_days[] = "($weekday_actual = 1 + AND ((periodically_time_from > '$start_time' AND periodically_time_to < '$end_time') + OR (periodically_time_from = '$start_time' + OR (periodically_time_from < '$start_time' + AND periodically_time_to >= '$start_time')) + OR (periodically_time_from = '$end_time' + OR (periodically_time_from < '$end_time' + AND periodically_time_to >= '$end_time'))))"; + } + else { + while ($date_aux <= $end_date && $i < 7) { + + $weekday_actual = strtolower(date('l', $date_aux)); + $day_num_actual = date('d', $date_aux); + + if ($date_aux == $start_date) { + $periodically_weekly_days[] = "($weekday_actual = 1 AND periodically_time_to >= '$start_time')"; + } + else if ($day_num_actual == $end_day) { + $periodically_weekly_days[] = "($weekday_actual = 1 AND periodically_time_from <= '$end_time')"; + } + else { + $periodically_weekly_days[] = "($weekday_actual = 1)"; + } + + $date_aux += SECONDS_1DAY; + $i++; + } + } + + if (!empty($periodically_weekly_days)) { + $periodically_weekly_w = "type_periodicity = 'weekly' AND (".implode(" OR ", $periodically_weekly_days).")"; + $periodically_condition = "(($periodically_monthly_w) OR ($periodically_weekly_w))"; + } + else { + $periodically_condition = "($periodically_monthly_w)"; + } + + if ($id_agent_modules !== false) { + if (empty($id_agent_modules)) + return array(); + + $id_agent_modules_str = implode(",", $id_agent_modules); + + $sql_downtime = "SELECT DISTINCT(tpdr.id), tpdr.* + FROM ( + SELECT tpd.* + FROM tplanned_downtime tpd, tplanned_downtime_agents tpda, tagente_modulo tam + WHERE (tpd.id = tpda.id_downtime + AND tpda.all_modules = 1 + AND tpda.id_agent = tam.id_agente + AND tam.id_agente_modulo IN ($id_agent_modules_str)) + AND ((type_execution = 'periodically' + AND $periodically_condition) + OR (type_execution = 'once' + AND ((date_from >= '$start_date' AND date_to <= '$end_date') + OR (date_from <= '$start_date' AND date_to >= '$end_date') + OR (date_from <= '$start_date' AND date_to >= '$start_date') + OR (date_from <= '$end_date' AND date_to >= '$end_date')))) + UNION ALL + SELECT tpd.* + FROM tplanned_downtime tpd, tplanned_downtime_modules tpdm + WHERE (tpd.id = tpdm.id_downtime + AND tpdm.id_agent_module IN ($id_agent_modules_str)) + AND ((type_execution = 'periodically' + AND $periodically_condition) + OR (type_execution = 'once' + AND ((date_from >= '$start_date' AND date_to <= '$end_date') + OR (date_from <= '$start_date' AND date_to >= '$end_date') + OR (date_from <= '$start_date' AND date_to >= '$start_date') + OR (date_from <= '$end_date' AND date_to >= '$end_date')))) + ) tpdr + ORDER BY tpdr.id"; + } + else { + $sql_downtime = "SELECT * + FROM tplanned_downtime tpd, tplanned_downtime_modules tpdm + WHERE (type_execution = 'periodically' + AND $periodically_condition) + OR (type_execution = 'once' + AND ((date_from >= '$start_date' AND date_to <= '$end_date') + OR (date_from <= '$start_date' AND date_to >= '$end_date') + OR (date_from <= '$start_date' AND date_to >= '$start_date') + OR (date_from <= '$end_date' AND date_to >= '$end_date')))"; + } + + $downtimes = db_get_all_rows_sql($sql_downtime); + if ($downtimes == false) { + $downtimes = array(); + } + + return $downtimes; +} + +function reporting_get_stats_servers($tiny = true) { + global $config; + + $server_performance = servers_get_performance(); + + // Alerts table + $table_srv = html_get_predefined_table(); + + $table_srv->style[0] = $table_srv->style[2] = 'text-align: right; padding: 5px;'; + $table_srv->style[1] = $table_srv->style[3] = 'text-align: left; padding: 5px;'; + + $tdata = array(); + $tdata[0] = html_print_image('images/module.png', true, array('title' => __('Total running modules'), 'width' => '25px')); + $tdata[1] = '' . format_numeric($server_performance ["total_modules"]) . ''; + + $tdata[2] = '' . format_numeric($server_performance ["total_modules_rate"], 2) . ''; + $tdata[3] = html_print_image('images/module.png', true, array('title' => __('Ratio') . ': ' . __('Modules by second'), 'width' => '16px')) . '/sec
'; + + $table_srv->rowclass[] = ''; + $table_srv->data[] = $tdata; + + $tdata = array(); + $tdata[0] = '
'; + $table_srv->colspan[count($table_srv->data)][0] = 4; + $table_srv->rowclass[] = ''; + $table_srv->data[] = $tdata; + + $tdata = array(); + $tdata[0] = html_print_image('images/database.png', true, array('title' => __('Local modules'), 'width' => '25px')); + $tdata[1] = '' . format_numeric($server_performance ["total_local_modules"]) . ''; + + $tdata[2] = '' . + format_numeric($server_performance ["local_modules_rate"], 2) . ''; + $tdata[3] = html_print_image('images/module.png', true, array('title' => __('Ratio') . ': ' . __('Modules by second'), 'width' => '16px')) . '/sec
'; + + $table_srv->rowclass[] = ''; + $table_srv->data[] = $tdata; + + if ($tiny) { + $tdata = array(); + $tdata[0] = html_print_image('images/network.png', true, array('title' => __('Remote modules'), 'width' => '25px')); + $tdata[1] = '' . format_numeric($server_performance ["total_remote_modules"]) . ''; + + $tdata[2] = '' . format_numeric($server_performance ["remote_modules_rate"], 2) . ''; + $tdata[3] = html_print_image('images/module.png', true, array('title' => __('Ratio') . ': ' . __('Modules by second'), 'width' => '16px')) . '/sec '; + + $table_srv->rowclass[] = ''; + $table_srv->data[] = $tdata; + } + else { + if (isset($server_performance ["total_network_modules"])) { + $tdata = array(); + $tdata[0] = html_print_image('images/network.png', true, array('title' => __('Network modules'), 'width' => '25px')); + $tdata[1] = '' . format_numeric($server_performance ["total_network_modules"]) . ''; + + $tdata[2] = '' . + format_numeric($server_performance["network_modules_rate"], 2) . + ''; + $tdata[3] = html_print_image('images/module.png', true, array('title' => __('Ratio') . ': ' . __('Modules by second'), 'width' => '16px')) . '/sec '; + + $table_srv->rowclass[] = ''; + $table_srv->data[] = $tdata; + } + + if (isset($server_performance ["total_plugin_modules"])) { + $tdata = array(); + $tdata[0] = html_print_image('images/plugin.png', true, array('title' => __('Plugin modules'), 'width' => '25px')); + $tdata[1] = '' . format_numeric($server_performance ["total_plugin_modules"]) . ''; + + $tdata[2] = '' . format_numeric($server_performance ["plugin_modules_rate"], 2) . ''; + $tdata[3] = html_print_image('images/module.png', true, array('title' => __('Ratio') . ': ' . __('Modules by second'), 'width' => '16px')) . '/sec '; + + $table_srv->rowclass[] = ''; + $table_srv->data[] = $tdata; + } + + if (isset($server_performance ["total_prediction_modules"])) { + $tdata = array(); + $tdata[0] = html_print_image('images/chart_bar.png', true, array('title' => __('Prediction modules'), 'width' => '25px')); + $tdata[1] = '' . format_numeric($server_performance ["total_prediction_modules"]) . ''; + + $tdata[2] = '' . format_numeric($server_performance ["prediction_modules_rate"], 2) . ''; + $tdata[3] = html_print_image('images/module.png', true, array('title' => __('Ratio') . ': ' . __('Modules by second'), 'width' => '16px')) . '/sec '; + + $table_srv->rowclass[] = ''; + $table_srv->data[] = $tdata; + } + + if (isset($server_performance ["total_wmi_modules"])) { + $tdata = array(); + $tdata[0] = html_print_image('images/wmi.png', true, array('title' => __('WMI modules'), 'width' => '25px')); + $tdata[1] = '' . format_numeric($server_performance ["total_wmi_modules"]) . ''; + + $tdata[2] = '' . format_numeric($server_performance ["wmi_modules_rate"], 2) . ''; + $tdata[3] = html_print_image('images/module.png', true, array('title' => __('Ratio') . ': ' . __('Modules by second'), 'width' => '16px')) . '/sec '; + + $table_srv->rowclass[] = ''; + $table_srv->data[] = $tdata; + } + + if (isset($server_performance ["total_web_modules"])) { + $tdata = array(); + $tdata[0] = html_print_image('images/world.png', true, array('title' => __('Web modules'), 'width' => '25px')); + $tdata[1] = '' . + format_numeric($server_performance ["total_web_modules"]) . + ''; + + $tdata[2] = '' . + format_numeric($server_performance ["web_modules_rate"], 2) . + ''; + $tdata[3] = html_print_image('images/module.png', true, array('title' => __('Ratio') . ': ' . __('Modules by second'), 'width' => '16px')) . '/sec '; + + $table_srv->rowclass[] = ''; + $table_srv->data[] = $tdata; + } + + $tdata = array(); + $tdata[0] = '
'; + $table_srv->colspan[count($table_srv->data)][0] = 4; + $table_srv->rowclass[] = ''; + $table_srv->data[] = $tdata; + + + switch ($config["dbtype"]) { + case "mysql": + $system_events = db_get_value_sql( + 'SELECT SQL_NO_CACHE COUNT(id_evento) + FROM tevento'); + break; + case "postgresql": + case "oracle": + $system_events = db_get_value_sql( + 'SELECT COUNT(id_evento) + FROM tevento'); + break; + } + + + + $tdata = array(); + $tdata[0] = html_print_image('images/lightning_go.png', true, + array('title' => __('Total events'), 'width' => '25px')); + $tdata[1] = '' . + format_numeric($system_events) . ''; + + $table_srv->colspan[count($table_srv->data)][1] = 3; + $table_srv->rowclass[] = ''; + $table_srv->data[] = $tdata; + } + + $output = '
+ ' . + __('Server performance') . + '' . + html_print_table($table_srv, true) . '
'; + + return $output; +} + + +function reporting_get_stats_summary($data, $graph_width, $graph_height) { + global $config; + + // Alerts table + $table_sum = html_get_predefined_table(); + + $tdata = array(); + $table_sum->colspan[count($table_sum->data)][0] = 2; + $table_sum->colspan[count($table_sum->data)][2] = 2; + $table_sum->cellstyle[count($table_sum->data)][0] = 'text-align: center;'; + $table_sum->cellstyle[count($table_sum->data)][2] = 'text-align: center;'; + $tdata[0] = '' . __('Module status') . ''; + $tdata[2] = '' . __('Alert level') . ''; + $table_sum->rowclass[] = ''; + $table_sum->data[] = $tdata; + + $tdata = array(); + $table_sum->colspan[count($table_sum->data)][0] = 2; + $table_sum->colspan[count($table_sum->data)][2] = 2; + $table_sum->cellstyle[count($table_sum->data)][0] = 'text-align: center;'; + $table_sum->cellstyle[count($table_sum->data)][2] = 'text-align: center;'; + + if ($data["monitor_checks"] > 0) { + $tdata[0] = '
' . graph_agent_status (false, $graph_width, $graph_height, true, true) . '
'; + } + else { + $tdata[2] = html_print_image('images/image_problem.png', true, array('width' => $graph_width)); + } + if ($data["monitor_alerts"] > 0) { + $tdata[2] = '
' . graph_alert_status ($data["monitor_alerts"], $data["monitor_alerts_fired"], $graph_width, $graph_height, true, true) . '
'; + } + else { + $tdata[2] = html_print_image('images/image_problem.png', true, array('width' => $graph_width)); + } + $table_sum->rowclass[] = ''; + $table_sum->data[] = $tdata; + + $output = '
+ ' . + __('Summary') . + '' . + html_print_table($table_sum, true) . '
'; + + return $output; +} + + + + + + +/** + * Get an event reporting table. + * + * It construct a table object with all the events happened in a group + * during a period of time. + * + * @param int Group id to get the report. + * @param int Period of time to get the report. + * @param int Beginning date of the report + * @param int Flag to return or echo the report table (echo by default). + * + * @return object A table object + */ +function reporting_event_reporting ($id_group, $period, $date = 0, $return = false) { + if (empty ($date)) { + $date = get_system_time (); + } + elseif (!is_numeric ($date)) { + $date = strtotime ($date); + } + + $table->data = array (); + $table->head = array (); + $table->head[0] = __('Status'); + $table->head[1] = __('Event name'); + $table->head[2] = __('User ID'); + $table->head[3] = __('Timestamp'); + + $events = events_get_group_events ($id_group, $period, $date); + if (empty ($events)) { + $events = array (); + } + foreach ($events as $event) { + $data = array (); + if ($event["estado"] == 0) + $data[0] = html_print_image("images/dot_red.png", true); + else + $data[0] = html_print_image("images/dot_green.png", true); + $data[1] = $event['evento']; + $data[2] = $event['id_usuario'] != '0' ? $event['id_usuario'] : ''; + $data[3] = $event["timestamp"]; + array_push ($table->data, $data); + } + + if (empty ($return)) + html_print_table ($table); + + return $table; +} + +/** + * Get a table report from a alerts fired array. + * + * @param array Alerts fired array. + * @see function get_alerts_fired () + * + * @return object A table object with a report of the fired alerts. + */ +function reporting_get_fired_alerts_table ($alerts_fired) { + $agents = array (); + global $config; + + require_once ($config["homedir"].'/include/functions_alerts.php'); + + foreach (array_keys ($alerts_fired) as $id_alert) { + $alert_module = alerts_get_alert_agent_module ($id_alert); + $template = alerts_get_alert_template ($id_alert); + + /* Add alerts fired to $agents_fired_alerts indexed by id_agent */ + $id_agent = db_get_value ('id_agente', 'tagente_modulo', + 'id_agente_modulo', $alert_module['id_agent_module']); + if (!isset ($agents[$id_agent])) { + $agents[$id_agent] = array (); + } + array_push ($agents[$id_agent], array ($alert_module, $template)); + } + + $table->data = array (); + $table->head = array (); + $table->head[0] = __('Agent'); + $table->head[1] = __('Alert description'); + $table->head[2] = __('Times fired'); + $table->head[3] = __('Priority'); + + foreach ($agents as $id_agent => $alerts) { + $data = array (); + foreach ($alerts as $tuple) { + $alert_module = $tuple[0]; + $template = $tuple[1]; + if (! isset ($data[0])) + $data[0] = agents_get_name ($id_agent); + else + $data[0] = ''; + $data[1] = $template['name']; + $data[2] = $alerts_fired[$alert_module['id']]; + $data[3] = get_alert_priority ($alert_module['priority']); + array_push ($table->data, $data); + } + } + + return $table; +} + +/** + * Get a report for alerts of agent. + * + * It prints the numbers of alerts defined, fired and not fired of agent. + * + * @param int $id_agent Agent to get info of the alerts. + * @param int $period Period of time of the desired alert report. + * @param int $date Beggining date of the report (current date by default). + * @param bool $return Flag to return or echo the report (echo by default). + * @param bool Flag to return the html or table object, by default html. + * + * @return mixed A table object (XHTML) or object table is false the html. + */ +function reporting_alert_reporting_agent ($id_agent, $period = 0, $date = 0, $return = true, $html = true) { + if (!is_numeric ($date)) { + $date = strtotime ($date); + } + if (empty ($date)) { + $date = get_system_time (); + } + $table->width = '99%'; + $table->data = array (); + $table->head = array (); + $table->head[0] = __('Module'); + $table->head[1] = __('Template'); + $table->head[2] = __('Actions'); + $table->head[3] = __('Fired'); + + $alerts = agents_get_alerts ($id_agent); + + if (isset($alerts['simple'])) { + $i = 0; + if ($alerts['simple'] === false) + $alerts['simple'] = array(); + + foreach ($alerts['simple'] as $alert) { + $data = array(); + $data[0] = db_get_value_filter('nombre', 'tagente_modulo', array('id_agente_modulo' => $alert['id_agent_module'])); + $data[1] = db_get_value_filter('name', 'talert_templates', array('id' => $alert['id_alert_template'])); + $actions = db_get_all_rows_sql('SELECT name + FROM talert_actions + WHERE id IN (SELECT id_alert_action + FROM talert_template_module_actions + WHERE id_alert_template_module = ' . $alert['id'] . ');'); + $data[2] = ''; + + $data[3] = ''; + + if ($alert['disabled']) { + $table->rowstyle[$i] = 'color: grey; font-style: italic;'; + } + $i++; + + array_push ($table->data, $data); + } + } + + if ($html) { + return html_print_table ($table, $return); + } + else { + return $table; + } +} + +/** + * Get a report for alerts of group. + * + * It prints the numbers of alerts defined, fired and not fired of agent. + * + * @param int $id_agent_module Module to get info of the alerts. + * @param int $period Period of time of the desired alert report. + * @param int $date Beggining date of the report (current date by default). + * @param bool $return Flag to return or echo the report (echo by default). + * @param bool Flag to return the html or table object, by default html. + * + * @return mixed A table object (XHTML) or object table is false the html. + */ +function reporting_alert_reporting_group ($id_group, $period = 0, $date = 0, $return = true, $html = true) { + if (!is_numeric ($date)) { + $date = strtotime ($date); + } + if (empty ($date)) { + $date = get_system_time (); + } + + $table->width = '99%'; + $table->data = array (); + $table->head = array (); + + $table->head[0] = __('Agent'); + $table->head[1] = __('Module'); + $table->head[2] = __('Template'); + $table->head[3] = __('Actions'); + $table->head[4] = __('Fired'); + + if ($id_group == 0) { + $alerts = db_get_all_rows_sql(' + SELECT * + FROM talert_template_modules + WHERE disabled = 0 + AND id_agent_module IN ( + SELECT id_agente_modulo + FROM tagente_modulo)'); + } + else { + $alerts = db_get_all_rows_sql(' + SELECT * + FROM talert_template_modules + WHERE disabled = 0 + AND id_agent_module IN ( + SELECT id_agente_modulo + FROM tagente_modulo + WHERE id_agente IN ( + SELECT id_agente + FROM tagente WHERE id_grupo = ' . $id_group . '))'); + } + + if ($alerts === false) { + $alerts = array(); + } + + $i = 0; + foreach ($alerts as $alert) { + $data = array(); + + $data[] = io_safe_output( + agents_get_name( + agents_get_agent_id_by_module_id( + $alert['id_agent_module']))); + + $data[] = io_safe_output( + modules_get_agentmodule_name($alert['id_agent_module'])); + + $data[] = db_get_value_filter('name', + 'talert_templates', + array('id' => $alert['id_alert_template'])); + + $actions = db_get_all_rows_sql('SELECT name + FROM talert_actions + WHERE id IN (SELECT id_alert_action + FROM talert_template_module_actions + WHERE id_alert_template_module = ' . $alert['id_agent_module'] . ');'); + $list = ''; + $data[] = $list; + + $list = ''; + + if ($alert['disabled']) { + $table->rowstyle[$i] = 'color: grey; font-style: italic;'; + } + $i++; + $data[] = $list; + + array_push ($table->data, $data); + } + + if ($html) { + return html_print_table ($table, $return); + } + else { + return $table; + } +} + +/** + * Get a report for alerts of module. + * + * It prints the numbers of alerts defined, fired and not fired of agent. + * + * @param int $id_agent_module Module to get info of the alerts. + * @param int $period Period of time of the desired alert report. + * @param int $date Beggining date of the report (current date by default). + * @param bool $return Flag to return or echo the report (echo by default). + * @param bool Flag to return the html or table object, by default html. + * + * @return mixed A table object (XHTML) or object table is false the html. + */ +function reporting_alert_reporting_module ($id_agent_module, $period = 0, $date = 0, $return = true, $html = true) { + if (!is_numeric ($date)) { + $date = strtotime ($date); + } + if (empty ($date)) { + $date = get_system_time (); + } + + $table->width = '99%'; + $table->data = array (); + $table->head = array (); + $table->head[1] = __('Template'); + $table->head[2] = __('Actions'); + $table->head[3] = __('Fired'); + + + $alerts = db_get_all_rows_sql('SELECT *, t1.id as id_alert_template_module + FROM talert_template_modules AS t1 + INNER JOIN talert_templates AS t2 ON t1.id_alert_template = t2.id + WHERE id_agent_module = ' . $id_agent_module); + + if ($alerts === false) { + $alerts = array(); + } + + $i = 0; + foreach ($alerts as $alert) { + $data = array(); + $data[1] = db_get_value_filter('name', 'talert_templates', array('id' => $alert['id_alert_template'])); + $actions = db_get_all_rows_sql('SELECT name + FROM talert_actions + WHERE id IN (SELECT id_alert_action + FROM talert_template_module_actions + WHERE id_alert_template_module = ' . $alert['id_alert_template_module'] . ');'); + $data[2] = ''; + + $data[3] = ''; + + if ($alert['disabled']) { + $table->rowstyle[$i] = 'color: grey; font-style: italic;'; + } + $i++; + + array_push ($table->data, $data); + } + + if ($html) { + return html_print_table ($table, $return); + } + else { + return $table; + } +} + +/** + * Get a report for alerts in a group of agents. + * + * It prints the numbers of alerts defined, fired and not fired in a group. + * It also prints all the alerts that were fired grouped by agents. + * + * @param int $id_group Group to get info of the alerts. + * @param int $period Period of time of the desired alert report. + * @param int $date Beggining date of the report (current date by default). + * @param bool $return Flag to return or echo the report (echo by default). + * + * @return string + */ +function reporting_alert_reporting ($id_group, $period = 0, $date = 0, $return = false) { + global $config; + + $output = ''; + $alerts = get_group_alerts ($id_group); + $alerts_fired = get_alerts_fired ($alerts, $period, $date); + + $fired_percentage = 0; + if (sizeof ($alerts) > 0) + $fired_percentage = round (sizeof ($alerts_fired) / sizeof ($alerts) * 100, 2); + $not_fired_percentage = 100 - $fired_percentage; + + $data = array (); + $data[__('Alerts fired')] = $fired_percentage; + $data[__('Alerts not fired')] = $not_fired_percentage; + + $output .= pie3d_graph(false, $data, 280, 150, + __("other"), + ui_get_full_url(false, false, false, false) . '/', + ui_get_full_url(false, false, false, false) . "/images/logo_vertical_water.png", + $config['fontpath'], $config['font_size']); + + $output .= ''.__('Alerts fired').': '.sizeof ($alerts_fired).'
'; + $output .= ''.__('Total alerts monitored').': '.sizeof ($alerts).'
'; + + if (! sizeof ($alerts_fired)) { + if (!$return) + echo $output; + + return $output; + } + $table = reporting_get_fired_alerts_table ($alerts_fired); + $table->width = '100%'; + $table->class = 'databox'; + $table->size = array (); + $table->size[0] = '100px'; + $table->style = array (); + $table->style[0] = 'font-weight: bold'; + + $output .= html_print_table ($table, true); + + if (!$return) + echo $output; + + return $output; +} + +/** + * Get a report for monitors modules in a group of agents. + * + * It prints the numbers of monitors defined, showing those which went up and down, in a group. + * It also prints all the down monitors in the group. + * + * @param int $id_group Group to get info of the monitors. + * @param int $period Period of time of the desired monitor report. + * @param int $date Beginning date of the report in UNIX time (current date by default). + * @param bool $return Flag to return or echo the report (by default). + * + * @return string + */ +function reporting_monitor_health ($id_group, $period = 0, $date = 0, $return = false) { + if (empty ($date)) //If date is 0, false or empty + $date = get_system_time (); + + $datelimit = $date - $period; + $output = ''; + + $monitors = modules_get_monitors_in_group ($id_group); + if (empty ($monitors)) //If monitors has returned false or an empty array + return; + $monitors_down = modules_get_monitors_down ($monitors, $period, $date); + $down_percentage = round (count ($monitors_down) / count ($monitors) * 100, 2); + $not_down_percentage = 100 - $down_percentage; + + $output .= ''.__('Total monitors').': '.count ($monitors).'
'; + $output .= ''.__('Monitors down on period').': '.count ($monitors_down).'
'; + + $table = reporting_get_monitors_down_table ($monitors_down); + $table->width = '100%'; + $table->class = 'databox'; + $table->size = array (); + $table->size[0] = '100px'; + $table->style = array (); + $table->style[0] = 'font-weight: bold'; + + $table->size = array (); + $table->size[0] = '100px'; + + $output .= html_print_table ($table, true); + + $data = array(); + $data[__('Monitors OK')] = $down_percentage; + $data[__('Monitors BAD')] = $not_down_percentage; + + $output .= pie3d_graph(false, $data, 280, 150, + __("other"), + ui_get_full_url(false, false, false, false) . '/', + ui_get_full_url(false, false, false, false) . "/images/logo_vertical_water.png", + $config['fontpath'], $config['font_size']); + + if (!$return) + echo $output; + + return $output; +} + +/** + * Get a report table with all the monitors down. + * + * @param array An array with all the monitors down + * @see function modules_get_monitors_down() + * + * @return object A table object with a monitors down report. + */ +function reporting_get_monitors_down_table ($monitors_down) { + $table->data = array (); + $table->head = array (); + $table->head[0] = __('Agent'); + $table->head[1] = __('Monitor'); + + $agents = array (); + if ($monitors_down) { + foreach ($monitors_down as $monitor) { + /* Add monitors fired to $agents_fired_alerts indexed by id_agent */ + $id_agent = $monitor['id_agente']; + if (!isset ($agents[$id_agent])) { + $agents[$id_agent] = array (); + } + array_push ($agents[$id_agent], $monitor); + + $monitors_down++; + } + foreach ($agents as $id_agent => $monitors) { + $data = array (); + foreach ($monitors as $monitor) { + if (! isset ($data[0])) + $data[0] = agents_get_name ($id_agent); + else + $data[0] = ''; + if ($monitor['descripcion'] != '') { + $data[1] = $monitor['descripcion']; + } + else { + $data[1] = $monitor['nombre']; + } + array_push ($table->data, $data); + } + } + } + + return $table; +} + +/** + * Get a general report of a group of agents. + * + * It shows the number of agents and no more things right now. + * + * @param int Group to get the report + * @param bool Flag to return or echo the report (by default). + * + * @return HTML string with group report + */ +function reporting_print_group_reporting ($id_group, $return = false) { + $agents = agents_get_group_agents ($id_group, false, "none"); + $output = '' . + sprintf(__('Agents in group: %s'), count($agents)) . + '
'; + + if ($return === false) + echo $output; + + return $output; +} + +/** + * Get a report table of the fired alerts group by agents. + * + * @param int Agent id to generate the report. + * @param int Period of time of the report. + * @param int Beginning date of the report in UNIX time (current date by default). + * + * @return object A table object with the alert reporting.. + */ +function reporting_get_agent_alerts_table ($id_agent, $period = 0, $date = 0) { + global $config; + $table->data = array (); + $table->head = array (); + $table->head[0] = __('Type'); + $table->head[1] = __('Description'); + $table->head[2] = __('Value'); + $table->head[3] = __('Threshold'); + $table->head[4] = __('Last fired'); + $table->head[5] = __('Times fired'); + + require_once ($config["homedir"].'/include/functions_alerts.php'); + + $alerts = agents_get_alerts ($id_agent); + + foreach ($alerts['simple'] as $alert) { + $fires = get_alert_fires_in_period ($alert['id'], $period, $date); + if (! $fires) { + continue; + } + + $template = alerts_get_alert_template ($alert['id_alert_template']); + $data = array (); + $data[0] = alerts_get_alert_templates_type_name ($template['type']); + $data[1] = $template['name']; + + switch ($template['type']) { + case 'regex': + if ($template['matches_value']) + $data[2] = '≃ "'.$template['value'].'"'; + else + $data[2] = '≄ "'.$template['value'].'"'; + break; + case 'equal': + case 'not_equal': + $data[2] = $template['value']; + + break; + case 'max-min': + $data[2] = __('Min.').': '.$template['min_value']. ' '; + $data[2] .= __('Max.').': '.$template['max_value']. ' '; + + break; + case 'max': + $data[2] = $template['max_value']; + + break; + case 'min': + $data[2] = $template['min_value']; + + break; + } + $data[3] = $template['time_threshold']; + $data[4] = ui_print_timestamp (get_alert_last_fire_timestamp_in_period ($alert['id'], $period, $date), true); + $data[5] = $fires; + + array_push ($table->data, $data); + } + + return $table; +} + +/** + * Get a report of monitors in an agent. + * + * @param int Agent id to get the report + * @param int Period of time of the report. + * @param int Beginning date of the report in UNIX time (current date by default). + * + * @return object A table object with the report. + */ +function reporting_get_agent_monitors_table ($id_agent, $period = 0, $date = 0) { + $n_a_string = __('N/A').'(*)'; + $table->head = array (); + $table->head[0] = __('Monitor'); + $table->head[1] = __('Last failure'); + $table->data = array (); + $monitors = modules_get_monitors_in_agent ($id_agent); + + if ($monitors === false) { + return $table; + } + foreach ($monitors as $monitor) { + $downs = modules_get_monitor_downs_in_period ($monitor['id_agente_modulo'], $period, $date); + if (! $downs) { + continue; + } + $data = array (); + if ($monitor['descripcion'] != $n_a_string && $monitor['descripcion'] != '') + $data[0] = $monitor['descripcion']; + else + $data[0] = $monitor['nombre']; + $data[1] = modules_get_last_down_timestamp_in_period ($monitor['id_agente_modulo'], $period, $date); + array_push ($table->data, $data); + } + + return $table; +} + +/** + * Get a report of all the modules in an agent. + * + * @param int Agent id to get the report. + * @param int Period of time of the report + * @param int Beginning date of the report in UNIX time (current date by default). + * + * @return object + */ +function reporting_get_agent_modules_table ($id_agent, $period = 0, $date = 0) { + $table->data = array (); + $n_a_string = __('N/A').'(*)'; + $modules = agents_get_modules ($id_agent, array ("nombre", "descripcion")); + if ($modules === false) + $modules = array(); + $data = array (); + + foreach ($modules as $module) { + if ($module['descripcion'] != $n_a_string && $module['descripcion'] != '') + $data[0] = $module['descripcion']; + else + $data[0] = $module['nombre']; + array_push ($table->data, $data); + } + + return $table; +} + +/** + * Get a detailed report of an agent + * + * @param int Agent to get the report. + * @param int Period of time of the desired report. + * @param int Beginning date of the report in UNIX time (current date by default). + * @param bool Flag to return or echo the report (by default). + * + * @return string + */ +function reporting_get_agent_detailed ($id_agent, $period = 0, $date = 0, $return = false) { + $output = ''; + $n_a_string = __('N/A(*)'); + + /* Show modules in agent */ + $output .= '
'; + $output .= '

' . + __('Agent') . ' - ' . agents_get_name ($id_agent) . '

'; + $output .= '

'.__('Modules').'

'; + $table_modules = reporting_get_agent_modules_table ($id_agent, $period, $date); + $table_modules->width = '99%'; + $output .= html_print_table ($table_modules, true); + + /* Show alerts in agent */ + $table_alerts = reporting_get_agent_alerts_table ($id_agent, $period, $date); + $table_alerts->width = '99%'; + if (sizeof ($table_alerts->data)) { + $output .= '

'.__('Alerts').'

'; + $output .= html_print_table ($table_alerts, true); + } + + /* Show monitor status in agent (if any) */ + $table_monitors = reporting_get_agent_monitors_table ($id_agent, $period, $date); + if (sizeof ($table_monitors->data) == 0) { + $output .= '
'; + if (! $return) + echo $output; + return $output; + } + $table_monitors->width = '99%'; + $table_monitors->align = array (); + $table_monitors->align[1] = 'right'; + $table_monitors->size = array (); + $table_monitors->align[1] = '10%'; + $output .= '

'.__('Monitors').'

'; + $output .= html_print_table ($table_monitors, true); + + $output .= ''; + + if (! $return) + echo $output; + return $output; +} + +/** + * Get a detailed report of agents in a group. + * + * @param mixed Group(s) to get the report + * @param int Period + * @param int Timestamp to start from + * @param bool Flag to return or echo the report (by default). + * + * @return string + */ +function reporting_agents_get_group_agents_detailed ($id_group, $period = 0, $date = 0, $return = false) { + $agents = agents_get_group_agents ($id_group, false, "none"); + + $output = ''; + foreach ($agents as $agent_id => $agent_name) { + $output .= reporting_get_agent_detailed ($agent_id, $period, $date, true); + } + + if ($return === false) + echo $output; + + return $output; +} + + +/** + * Get a detailed report of summarized events per agent + * + * It construct a table object with all the grouped events happened in an agent + * during a period of time. + * + * @param mixed Agent id(s) to get the report from. + * @param int Period of time (in seconds) to get the report. + * @param int Beginning date (unixtime) of the report + * @param bool Flag to return or echo the report table (echo by default). + * + * @return A table object (XHTML) + */ +function reporting_get_agents_detailed_event ($id_agents, $period = 0, + $date = 0, $return = false, $filter_event_validated = false, + $filter_event_critical = false, $filter_event_warning = false, $filter_event_no_validated = false) { + + global $config; + + $id_agents = (array)safe_int ($id_agents, 1); + + if (!is_numeric ($date)) { + $date = strtotime ($date); + } + if (empty ($date)) { + $date = get_system_time (); + } + + $table->width = '99%'; + + $table->align = array(); + $table->align[0] = 'center'; + $table->align[1] = 'center'; + $table->align[3] = 'center'; + + $table->data = array (); + + $table->head = array (); + $table->head[0] = __('Status'); + $table->head[1] = __('Count'); + $table->head[2] = __('Name'); + $table->head[3] = __('Type'); + $table->head[4] = __('Criticity'); + $table->head[5] = __('Val. by'); + $table->head[6] = __('Timestamp'); + + $events = array (); + + foreach ($id_agents as $id_agent) { + $event = events_get_agent ($id_agent, + (int)$period, + (int)$date, + $filter_event_validated, $filter_event_critical, + $filter_event_warning, $filter_event_no_validated); + + if (!empty ($event)) { + array_push ($events, $event); + } + } + + if ($events) { + $note = ''; + if (count($events) >= 1000) { + $note .= '* ' . __('Maximum of events shown') . ' (1000)
'; + } + foreach ($events as $eventRow) { + foreach ($eventRow as $k => $event) { + //First pass along the class of this row + $table->cellclass[$k][1] = $table->cellclass[$k][2] = + $table->cellclass[$k][4] = $table->cellclass[$k][5] = + $table->cellclass[$k][6] = + 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, + "title" => $title_st)); + + $data[] = $event['event_rep']; + + $data[] = ui_print_truncate_text( + io_safe_output($event['evento']), + 140, false, true); + //$data[] = $event['event_type']; + $data[] = events_print_type_img ($event["event_type"], true); + + $data[] = get_priority_name ($event['criticity']); + if (empty($event['id_usuario']) && $event['estado'] == EVENT_VALIDATE) { + $data[] = '' . __('System') . ''; + } + else { + $user_name = db_get_value ('fullname', 'tusuario', 'id_user', $event['id_usuario']); + $data[] = io_safe_output($user_name); + } + $data[] = '' . + date($config['date_format'], $event['timestamp_rep']) . ''; + array_push ($table->data, $data); + } + } + } + + if ($events) + return html_print_table ($table, $return) . $note; +} + +/** + * Gets a detailed reporting of groups's events. + * + * @param unknown_type $id_group Id of the group. + * @param unknown_type $period Time period of the report. + * @param unknown_type $date Date of the report. + * @param unknown_type $return Whether to return or not. + * @param unknown_type $html Whether to return HTML code or not. + * + * @return string Report of groups's events + */ +function reporting_get_group_detailed_event ($id_group, $period = 0, + $date = 0, $return = false, $html = true, + $filter_event_validated = false, $filter_event_critical = false, + $filter_event_warning = false, $filter_event_no_validated = false) { + + global $config; + + if (!is_numeric ($date)) { + $date = strtotime ($date); + } + if (empty ($date)) { + $date = get_system_time (); + } + + $table->width = '99%'; + + $table->align = array(); + $table->align[0] = 'center'; + $table->align[2] = 'center'; + + $table->data = array (); + + $table->head = array (); + $table->head[0] = __('Status'); + $table->head[1] = __('Name'); + $table->head[2] = __('Type'); + $table->head[3] = __('Agent'); + $table->head[4] = __('Criticity'); + $table->head[5] = __('Val. by'); + $table->head[6] = __('Timestamp'); + + $events = events_get_group_events($id_group, $period, $date, + $filter_event_validated, $filter_event_critical, + $filter_event_warning, $filter_event_no_validated); + + if ($events) { + $note = ''; + if (count($events) >= 1000) { + $note .= '* ' . __('Maximum of events shown') . ' (1000)
'; + } + foreach ($events as $k => $event) { + //First pass along the class of this row + $table->cellclass[$k][1] = $table->cellclass[$k][3] = + $table->cellclass[$k][4] = $table->cellclass[$k][5] = + $table->cellclass[$k][6] = + 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, + "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['id_agente'])) + $data[] = agents_get_name($event['id_agente']); + else + $data[] = __('Pandora System'); + $data[] = get_priority_name ($event['criticity']); + if (empty($event['id_usuario']) && $event['estado'] == EVENT_VALIDATE) { + $data[] = '' . __('System') . ''; + } + else { + $user_name = db_get_value ('fullname', 'tusuario', 'id_user', $event['id_usuario']); + $data[] = io_safe_output($user_name); + } + $data[] = '' . + date($config['date_format'], $event['timestamp_rep']) . + ''; + array_push ($table->data, $data); + } + + if ($html) { + return html_print_table ($table, $return) . $note; + } + else { + return $table; + } + } + else { + return false; + } +} + + +/** + * Get a detailed report of summarized events per agent + * + * It construct a table object with all the grouped events happened in an agent + * during a period of time. + * + * @param mixed Module id to get the report from. + * @param int Period of time (in seconds) to get the report. + * @param int Beginning date (unixtime) of the report + * @param bool Flag to return or echo the report table (echo by default). + * @param bool Flag to return the html or table object, by default html. + * + * @return mixed A table object (XHTML) or object table is false the html. + */ +function reporting_get_module_detailed_event ($id_modules, $period = 0, $date = 0, $return = false, $html = true) { + global $config; + + $id_modules = (array)safe_int ($id_modules, 1); + + if (!is_numeric ($date)) { + $date = strtotime ($date); + } + if (empty ($date)) { + $date = get_system_time (); + } + + $table->width = '99%'; + $table->data = array (); + $table->head = array (); + $table->head[0] = __('Status'); + $table->head[1] = __('Event name'); + $table->head[2] = __('Event type'); + $table->head[3] = __('Criticity'); + $table->head[4] = __('Count'); + $table->head[5] = __('Timestamp'); + $table->style[0] = 'text-align: center;'; + $table->style[4] = 'text-align: center;'; + + $events = array (); + + foreach ($id_modules as $id_module) { + $event = events_get_module ($id_module, (int) $period, (int) $date); + if (!empty ($event)) { + array_push ($events, $event); + } + } + + if ($events) { + $note = ''; + if (count($events) >= 1000) { + $note .= '* ' . __('Maximum of events shown') . ' (1000)
'; + } + foreach ($events as $eventRow) { + foreach ($eventRow as $k => $event) { + //$k = count($table->data); + $table->cellclass[$k][1] = $table->cellclass[$k][2] = + $table->cellclass[$k][3] = $table->cellclass[$k][4] = + $table->cellclass[$k][5] = 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[0] = html_print_image ($img_st, true, + array ("class" => "image_status", + "width" => 16, + "title" => $title_st, + "id" => 'status_img_' . $event["id_evento"])); + + $data[1] = io_safe_output($event['evento']); + $data[2] = $event['event_type']; + $data[3] = get_priority_name ($event['criticity']); + $data[4] = $event['event_rep']; + $data[5] = date($config['date_format'], $event['timestamp_rep']); + array_push ($table->data, $data); + } + } + + if ($html) { + return html_print_table ($table, $return) . $note; + } + else { + return $table; + } + } + else { + return false; + } +} + +/** + * Get a detailed report of the modules of the agent + * + * @param int $id_agent Agent id to get the report for. + * @param string $filter filter for get partial modules. + * + * @return array An array + */ +function reporting_get_agent_module_info ($id_agent, $filter = false) { + global $config; + + $return = array (); + $return["last_contact"] = 0; //Last agent contact + $return["status"] = STATUS_AGENT_NO_DATA; + $return["status_img"] = ui_print_status_image (STATUS_AGENT_NO_DATA, __('Agent without data'), true); + $return["alert_status"] = "notfired"; + $return["alert_value"] = STATUS_ALERT_NOT_FIRED; + $return["alert_img"] = ui_print_status_image (STATUS_ALERT_NOT_FIRED, __('Alert not fired'), true); + $return["agent_group"] = agents_get_agent_group ($id_agent); + + if (!check_acl ($config["id_user"], $return["agent_group"], "AR")) { + return $return; + } + + if ($filter != '') { + $filter = 'AND '; + } + + $filter = 'disabled = 0'; + + $modules = agents_get_modules($id_agent, false, $filter, true, false); + + if ($modules === false) { + return $return; + } + + $now = get_system_time (); + + // Get modules status for this agent + + $agent = db_get_row ("tagente", "id_agente", $id_agent); + + $return["total_count"] = $agent["total_count"]; + $return["normal_count"] = $agent["normal_count"]; + $return["warning_count"] = $agent["warning_count"]; + $return["critical_count"] = $agent["critical_count"]; + $return["unknown_count"] = $agent["unknown_count"]; + $return["fired_count"] = $agent["fired_count"]; + $return["notinit_count"] = $agent["notinit_count"]; + + if ($return["total_count"] > 0) { + if ($return["critical_count"] > 0) { + $return["status"] = STATUS_AGENT_CRITICAL; + $return["status_img"] = ui_print_status_image (STATUS_AGENT_CRITICAL, __('At least one module in CRITICAL status'), true); + } + else if ($return["warning_count"] > 0) { + $return["status"] = STATUS_AGENT_WARNING; + $return["status_img"] = ui_print_status_image (STATUS_AGENT_WARNING, __('At least one module in WARNING status'), true); + } + else if ($return["unknown_count"] > 0) { + $return["status"] = STATUS_AGENT_DOWN; + $return["status_img"] = ui_print_status_image (STATUS_AGENT_DOWN, __('At least one module is in UKNOWN status'), true); + } + else { + $return["status"] = STATUS_AGENT_OK; + $return["status_img"] = ui_print_status_image (STATUS_AGENT_OK, __('All Monitors OK'), true); + } + } + + //Alert not fired is by default + if ($return["fired_count"] > 0) { + $return["alert_status"] = "fired"; + $return["alert_img"] = ui_print_status_image (STATUS_ALERT_FIRED, __('Alert fired'), true); + $return["alert_value"] = STATUS_ALERT_FIRED; + } + elseif (groups_give_disabled_group ($return["agent_group"])) { + $return["alert_status"] = "disabled"; + $return["alert_value"] = STATUS_ALERT_DISABLED; + $return["alert_img"] = ui_print_status_image (STATUS_ALERT_DISABLED, __('Alert disabled'), true); + } + + return $return; +} + +/** + * This is the callback sorting function for SLA values descending + * + * @param array $a Array element 1 to compare + * @param array $b Array element 2 to compare + * + */ +function sla_value_desc_cmp($a, $b) { + // This makes 'Unknown' values the lastest + if (preg_match('/^(.)*Unknown(.)*$/', $a[5])) + $a[6] = -1; + + if (preg_match('/^(.)*Unknown(.)*$/', $b[5])) + $b[6] = -1; + + return ($a[6] < $b[6])? 1 : 0; +} + +/** + * This is the callback sorting function for SLA values ascending + * + * @param array $a Array element 1 to compare + * @param array $b Array element 2 to compare + * + */ +function sla_value_asc_cmp($a, $b) { + // This makes 'Unknown' values the lastest + if (preg_match('/^(.)*Unknown(.)*$/', $a[5])) + $a[6] = -1; + + if (preg_match('/^(.)*Unknown(.)*$/', $b[5])) + $b[6] = -1; + + return ($a[6] > $b[6])? 1 : 0; +} + +/** + * Make the header for each content. + */ +function reporting_header_content($mini, $content, $report, &$table, $title = false, $name = false, $period = false) { + global $config; + + if ($mini) { + $sizh = ''; + $sizhfin = ''; + } + else { + $sizh = '

'; + $sizhfin = '

'; + } + + $data = array(); + + $count_empty = 0; + + if ($title !== false) { + $data[] = $sizh . $title . $sizhfin; + } + else $count_empty++; + + if ($name !== false) { + $data[] = $sizh . $name . $sizhfin; + } + else $count_empty++; + + if ($period !== false && $content['period'] > 0) { + $data[] = $sizh . $period . $sizhfin; + } + else if ($content['period'] == 0) { + $es = json_decode($content['external_source'], true); + if ($es['date'] == 0) { + $date = __('Last data'); + } + else { + $date = date($config["date_format"], $es['date']); + } + + $data[] = "
" . $sizh . $date . $sizhfin . "
"; + } + else { + $data[] = "
" . $sizh . + "(" . human_time_description_raw ($content['period']) . ") " . + __("From:") . " " . date($config["date_format"], $report["datetime"] - $content['period']) . "
" . + __("To:") . " " . date($config["date_format"], $report["datetime"]) . "
" . + $sizhfin . "
"; + } + + $table->colspan[0][2 - $count_empty] = 1 + $count_empty; + + array_push ($table->data, $data); +} + +/** + * This function is used once, in reporting_viewer.php, the HTML report render + * file. This function proccess each report item and write the render in the + * table record. + * + * @param array $content Record of treport_content table for current item + * @param array $table HTML Table row + * @param array $report Report contents, with some added fields. + * @param array $mini Mini flag for reduce the size. + * + */ + +function reporting_render_report_html_item ($content, $table, $report, $mini = false) { + global $config; + global $graphic_type; + + $only_image = (bool)$config['flash_charts'] ? false : true; + + if ($mini) { + $sizem = '1.5'; + $sizgraph_w = '450'; + $sizgraph_h = '100'; + } + else { + $sizem = '3'; + $sizgraph_w = '900'; + $sizgraph_h = '230'; + } + + // Disable remote connections for netflow report items + if ($content['type'] != 'netflow_area' && + $content['type'] != 'netflow_pie' && + $content['type'] != 'netflow_data' && + $content['type'] != 'netflow_statistics' && + $content['type'] != 'netflow_summary') { + + $remote_connection = 1; + } + else { + $remote_connection = 0; + } + + $server_name = $content ['server_name']; + if (($config ['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE') && $remote_connection == 1) { + $connection = metaconsole_get_connection($server_name); + if (metaconsole_load_external_db($connection) != NOERR) { + //ui_print_error_message ("Error connecting to ".$server_name); + } + } + + $module_name = db_get_value ('nombre', 'tagente_modulo', 'id_agente_modulo', $content['id_agent_module']); + if ($content['id_agent_module'] != 0) { + $agent_name = modules_get_agentmodule_agent_name ($content['id_agent_module']); + } + else { + $agent_name = agents_get_name($content['id_agent']); + } + + $item_title = $content['name']; + + switch ($content["type"]) { + case 1: + case 'simple_graph': + if (empty($item_title)) { + $item_title = __('Simple graph'); + } + reporting_header_content($mini, $content, $report, $table, + $item_title, + ui_print_truncate_text($agent_name, 'agent_medium', false).'
' . + ui_print_truncate_text($module_name, 'module_medium', false)); + + //RUNNING + + $next_row = 1; + + // Put description at the end of the module (if exists) + if ($content["description"] != "") { + $data_desc = array(); + $data_desc[0] = $content["description"]; + array_push ($table->data, $data_desc); + $table->colspan[$next_row][0] = 3; + $next_row++; + } + + $table->colspan[$next_row][0] = 3; + $table->cellstyle[$next_row][0] = 'text-align: center;'; + + $data = array (); + + $moduletype_name = modules_get_moduletype_name( + modules_get_agentmodule_type( + $content['id_agent_module'])); + + $only_avg = true; + // Due to database compatibility problems, the 'only_avg' value + // is stored into the json contained into the 'style' column. + if (isset($content['style'])) { + $style_json = io_safe_output($content['style']); + $style = json_decode($style_json, true); + + if (isset($style['only_avg'])) { + $only_avg = (bool) $style['only_avg']; + } + } + + if (preg_match ("/string/", $moduletype_name)) { + + $urlImage = ui_get_full_url(false, false, false, false); + + $data[0] = grafico_modulo_string ($content['id_agent_module'], $content['period'], + false, $sizgraph_w, $sizgraph_h, '', '', false, $only_avg, false, + $report["datetime"], $only_image, $urlImage); + + } + else { + + $data[0] = grafico_modulo_sparse( + $content['id_agent_module'], + $content['period'], + false, + $sizgraph_w, + $sizgraph_h, + '', + '', + false, + $only_avg, + true, + $report["datetime"], + '', + 0, + 0, + true, + $only_image, + ui_get_full_url(false, false, false, false), + 1, + false, + '', + false, + true); + } + + array_push ($table->data, $data); + break; + case 'projection_graph': + if (empty($item_title)) { + $item_title = __('Projection graph'); + } + reporting_header_content($mini, $content, $report, $table, $item_title, + ui_print_truncate_text($agent_name, 'agent_medium', false).'
' . + ui_print_truncate_text($module_name, 'module_medium', false)); + + //RUNNING + $table->colspan[1][0] = 4; + + set_time_limit(500); + + $next_row = 1; + // Put description at the end of the module (if exists) + if ($content["description"] != "") { + $data_desc = array(); + $data_desc[0] = $content["description"]; + array_push ($table->data, $data_desc); + $table->colspan[$next_row][0] = 3; + $next_row++; + } + + $table->colspan[$next_row][0] = 3; + $table->cellstyle[$next_row][0] = 'text-align: center;'; + $data = array (); + + $output_projection = forecast_projection_graph($content['id_agent_module'], $content['period'], $content['top_n_value']); + + // If projection doesn't have data then don't draw graph + if ($output_projection == NULL) { + $output_projection = false; + } + + $modules = array($content['id_agent_module']); + $weights = array(); + $data[0] = graphic_combined_module( + $modules, + $weights, + $content['period'], + $sizgraph_w, $sizgraph_h, + 'Projection%20Sample%20Graph', + '', + 0, + 0, + 0, + 0, + $report["datetime"], + true, + ui_get_full_url(false, false, false, false) . '/', + 1, + // Important parameter, this tell to graphic_combined_module function that is a projection graph + $output_projection, + $content['top_n_value'] + ); + array_push ($table->data, $data); + break; + case 'prediction_date': + if (empty($item_title)) { + $item_title = __('Prediction date'); + } + reporting_header_content($mini, $content, $report, $table, $item_title, + ui_print_truncate_text($agent_name, 'agent_medium', false).'
' . + ui_print_truncate_text($module_name, 'module_medium', false)); + + //RUNNING + $table->colspan[1][0] = 4; + + set_time_limit(500); + + // Put description at the end of the module (if exists) + $table->colspan[2][0] = 4; + if ($content["description"] != ""){ + $data_desc = array(); + $data_desc[0] = $content["description"]; + array_push ($table->data, $data_desc); + } + + $data = array (); + $table->colspan[2][0] = 3; + $intervals_text = $content['text']; + $max_interval = substr($intervals_text, 0, strpos($intervals_text, ';')); + $min_interval = substr($intervals_text, strpos($intervals_text, ';') + 1); + $value = forecast_prediction_date ($content['id_agent_module'], $content['period'], $max_interval, $min_interval); + + if ($value === false) { + $value = __('Unknown'); + } + else { + $value = date ('d M Y H:i:s', $value); + } + $data[0] = '

'.$value.'

'; + array_push ($table->data, $data); + break; + case 'simple_baseline_graph': + if (empty($item_title)) { + $item_title = __('Simple baseline graph'); + } + reporting_header_content($mini, $content, $report, $table, $item_title, + ui_print_truncate_text($agent_name, 'agent_medium', false).'
' . + ui_print_truncate_text($module_name, 'module_medium', false)); + + //RUNNING + $table->colspan[1][0] = 4; + + // Put description at the end of the module (if exists) + $table->colspan[2][0] = 4; + if ($content["description"] != "") { + $data_desc = array(); + $data_desc[0] = $content["description"]; + array_push ($table->data, $data_desc); + } + + $data = array (); + $data[0] = grafico_modulo_sparse($content['id_agent_module'], $content['period'], + false, $sizgraph_w, $sizgraph_h, '', '', false, true, true, + $report["datetime"], '', true, 0, true, $only_image, + ui_get_full_url(false, false, false, false)); + + /*$data[0] = graphic_combined_module( + $modules, + $weights, + $content['period'], + $sizgraph_w, $sizgraph_h, + 'Combined%20Sample%20Graph', + '', + 0, + 0, + 0, + $graph["stacked"], + $report["datetime"]); */ + + array_push ($table->data, $data); + + break; + + case 2: + case 'custom_graph': + case 'automatic_custom_graph': + $graph = db_get_row ("tgraph", "id_graph", $content['id_gs']); + + if (empty($item_title)) { + $item_title = __('Custom graph'); + } + reporting_header_content($mini, $content, $report, $table, $item_title, + ui_print_truncate_text($graph['name'], 'item_title', false)); + + //RUNNING + // Put description at the end of the module (if exists) + + $table->colspan[2][0] = 3; + if ($content["description"] != "") { + $data_desc = array(); + $data_desc[0] = $content["description"]; + array_push ($table->data, $data_desc); + } + + $result = db_get_all_rows_field_filter ("tgraph_source", + "id_graph", $content['id_gs']); + $modules = array (); + $weights = array (); + if ($result === false) + $result = array(); + + foreach ($result as $content2) { + array_push ($modules, $content2['id_agent_module']); + array_push ($weights, $content2["weight"]); + } + + // Increase the height to fix the leyend rise + $sizgraph_h += count($modules) * 15; + + $table->colspan[1][0] = 3; + $data = array(); + + require_once ($config["homedir"] . '/include/functions_graph.php'); + $data[0] = graphic_combined_module( + $modules, + $weights, + $content['period'], + $sizgraph_w, $sizgraph_h, + 'Combined%20Sample%20Graph', + '', + 0, + 0, + 0, + $graph["stacked"], + $report["datetime"], + $only_image, + ui_get_full_url(false, false, false, false)); + array_push ($table->data, $data); + + break; + case 'SLA_monthly': + if (function_exists("reporting_enterprise_sla_monthly")) + reporting_enterprise_sla_monthly($mini, $content, $report, $table, $item_title); + break; + case 'SLA_services': + if (function_exists("reporting_enterprise_sla_services")) + reporting_enterprise_sla_services($mini, $content, $report, $table, $item_title); + break; + case 3: + case 'SLA': + if (empty($item_title)) { + $item_title = __('S.L.A.'); + } + reporting_header_content($mini, $content, $report, $table, $item_title); + + $edge_interval = 10; + + // What show? + $show_table = $content['show_graph'] == 0 || $content['show_graph'] == 1; + $show_graphs = $content['show_graph'] == 1 || $content['show_graph'] == 2; + + //RUNNING + $table->style[1] = 'text-align: right'; + + // Put description at the end of the module (if exists) + + $table->colspan[0][1] = 2; + $next_row = 1; + if ($content["description"] != "") { + $table->colspan[$next_row][0] = 3; + $next_row++; + $data_desc = array(); + $data_desc[0] = $content["description"]; + array_push ($table->data, $data_desc); + } + + $slas = db_get_all_rows_field_filter ('treport_content_sla_combined', + 'id_report_content', $content['id_rc']); + + if ($slas === false) { + $data = array (); + $table->colspan[$next_row][0] = 3; + $next_row++; + $data[0] = __('There are no SLAs defined'); + array_push ($table->data, $data); + $slas = array (); + break; + } + elseif ($show_table) { + $table1->width = '99%'; + $table1->data = array (); + $table1->head = array (); + $table1->head[0] = __('Agent'); + $table1->head[1] = __('Module'); + $table1->head[2] = __('Max/Min Values'); + $table1->head[3] = __('SLA Limit'); + $table1->head[4] = __('SLA Compliance'); + $table1->head[5] = __('Status'); + // $table1->head[6] = __('Criticity'); + $table1->style[0] = 'text-align: left'; + $table1->style[1] = 'text-align: left'; + $table1->style[2] = 'text-align: right'; + $table1->style[3] = 'text-align: right'; + $table1->style[4] = 'text-align: right'; + $table1->style[5] = 'text-align: right'; + // $table1->style[6] = 'text-align: center'; + } + + // Table Planned Downtimes + require_once ($config['homedir'] . '/include/functions_planned_downtimes.php'); + $metaconsole_on = ($config['metaconsole'] == 1) && defined('METACONSOLE'); + $downtime_malformed = false; + + $planned_downtimes_empty = true; + $malformed_planned_downtimes_empty = true; + + if ($metaconsole_on) { + $id_agent_modules_by_server = array(); + + foreach ($slas as $sla) { + $server = $sla['server_name']; + if (empty($server)) + continue; + + if (!isset($id_agent_modules_by_server[$server])) + $id_agent_modules_by_server[$server] = array(); + + $id_agent_modules_by_server[$server][] = $sla['id_agent_module']; + } + + $planned_downtimes_by_server = array(); + $malformed_planned_downtimes_by_server = array(); + foreach ($id_agent_modules_by_server as $server => $id_agent_modules) { + //Metaconsole connection + if (!empty($server)) { + $connection = metaconsole_get_connection($server); + if (!metaconsole_load_external_db($connection)) { + continue; + } + + $planned_downtimes_by_server[$server] = reporting_get_planned_downtimes(($report['datetime']-$content['period']), $report['datetime'], $id_agent_modules); + $malformed_planned_downtimes_by_server[$server] = planned_downtimes_get_malformed(); + + if (!empty($planned_downtimes_by_server[$server])) + $planned_downtimes_empty = false; + if (!empty($malformed_planned_downtimes_by_server[$server])) + $malformed_planned_downtimes_empty = false; + + //Restore db connection + metaconsole_restore_db(); + } + } + + if (!$planned_downtimes_empty) { + $table_planned_downtimes = new StdClass(); + $table_planned_downtimes->width = '100%'; + $table_planned_downtimes->title = __('This SLA has been affected by the following planned downtimes'); + $table_planned_downtimes->head = array(); + $table_planned_downtimes->head[0] = __('Server'); + $table_planned_downtimes->head[1] = __('Name'); + $table_planned_downtimes->head[2] = __('Description'); + $table_planned_downtimes->head[3] = __('Execution'); + $table_planned_downtimes->head[4] = __('Dates'); + $table_planned_downtimes->headstyle = array(); + $table_planned_downtimes->style = array(); + $table_planned_downtimes->cellstyle = array(); + $table_planned_downtimes->data = array(); + + foreach ($planned_downtimes_by_server as $server => $planned_downtimes) { + foreach ($planned_downtimes as $planned_downtime) { + $data = array(); + $data[0] = $server; + $data[1] = $planned_downtime['name']; + $data[2] = $planned_downtime['description']; + $data[3] = ucfirst($planned_downtime['type_execution']); + $data[4] = ""; + switch ($planned_downtime['type_execution']) { + case 'once': + $data[3] = date ("Y-m-d H:i", $planned_downtime['date_from']) . + " " . __('to') . " ". + date ("Y-m-d H:i", $planned_downtime['date_to']); + break; + case 'periodically': + switch ($planned_downtime['type_periodicity']) { + case 'weekly': + $data[4] = __('Weekly:'); + $data[4] .= " "; + if ($planned_downtime['monday']) { + $data[4] .= __('Mon'); + $data[4] .= " "; + } + if ($planned_downtime['tuesday']) { + $data[4] .= __('Tue'); + $data[4] .= " "; + } + if ($planned_downtime['wednesday']) { + $data[4] .= __('Wed'); + $data[4] .= " "; + } + if ($planned_downtime['thursday']) { + $data[4] .= __('Thu'); + $data[4] .= " "; + } + if ($planned_downtime['friday']) { + $data[4] .= __('Fri'); + $data[4] .= " "; + } + if ($planned_downtime['saturday']) { + $data[4] .= __('Sat'); + $data[4] .= " "; + } + if ($planned_downtime['sunday']) { + $data[4] .= __('Sun'); + $data[4] .= " "; + } + $data[4] .= " (" . $planned_downtime['periodically_time_from']; + $data[4] .= "-" . $planned_downtime['periodically_time_to'] . ")"; + break; + case 'monthly': + $data[4] = __('Monthly:') . " "; + $data[4] .= __('From day') . " " . $planned_downtime['periodically_day_from']; + $data[4] .= " " . strtolower(__('To day')) . " "; + $data[4] .= $planned_downtime['periodically_day_to']; + $data[4] .= " (" . $planned_downtime['periodically_time_from']; + $data[4] .= "-" . $planned_downtime['periodically_time_to'] . ")"; + break; + } + break; + } + + if (!$malformed_planned_downtimes_empty + && isset($malformed_planned_downtimes_by_server[$server]) + && isset($malformed_planned_downtimes_by_server[$server][$planned_downtime['id']])) { + $next_row_num = count($table_planned_downtimes->data); + $table_planned_downtimes->cellstyle[$next_row_num][0] = 'color: red'; + $table_planned_downtimes->cellstyle[$next_row_num][1] = 'color: red'; + $table_planned_downtimes->cellstyle[$next_row_num][2] = 'color: red'; + $table_planned_downtimes->cellstyle[$next_row_num][3] = 'color: red'; + $table_planned_downtimes->cellstyle[$next_row_num][4] = 'color: red'; + + if (!$downtime_malformed) + $downtime_malformed = true; + } + + $table_planned_downtimes->data[] = $data; + } + } + } + } + else { + $id_agent_modules = array(); + foreach ($slas as $sla) { + if (!empty($sla['id_agent_module'])) + $id_agent_modules[] = $sla['id_agent_module']; + } + + $planned_downtimes = reporting_get_planned_downtimes(($report['datetime']-$content['period']), $report['datetime'], $id_agent_modules); + $malformed_planned_downtimes = planned_downtimes_get_malformed(); + + if (!empty($planned_downtimes)) + $planned_downtimes_empty = false; + if (!empty($malformed_planned_downtimes)) + $malformed_planned_downtimes_empty = false; + + if (!$planned_downtimes_empty) { + $table_planned_downtimes = new StdClass(); + $table_planned_downtimes->width = '100%'; + $table_planned_downtimes->title = __('This SLA has been affected by the following planned downtimes'); + $table_planned_downtimes->head = array(); + $table_planned_downtimes->head[0] = __('Name'); + $table_planned_downtimes->head[1] = __('Description'); + $table_planned_downtimes->head[2] = __('Execution'); + $table_planned_downtimes->head[3] = __('Dates'); + $table_planned_downtimes->headstyle = array(); + $table_planned_downtimes->style = array(); + $table_planned_downtimes->cellstyle = array(); + $table_planned_downtimes->data = array(); + + foreach ($planned_downtimes as $planned_downtime) { + + $data = array(); + $data[0] = $planned_downtime['name']; + $data[1] = $planned_downtime['description']; + $data[2] = ucfirst($planned_downtime['type_execution']); + $data[3] = ""; + switch ($planned_downtime['type_execution']) { + case 'once': + $data[3] = date ("Y-m-d H:i", $planned_downtime['date_from']) . + " " . __('to') . " ". + date ("Y-m-d H:i", $planned_downtime['date_to']); + break; + case 'periodically': + switch ($planned_downtime['type_periodicity']) { + case 'weekly': + $data[3] = __('Weekly:'); + $data[3] .= " "; + if ($planned_downtime['monday']) { + $data[3] .= __('Mon'); + $data[3] .= " "; + } + if ($planned_downtime['tuesday']) { + $data[3] .= __('Tue'); + $data[3] .= " "; + } + if ($planned_downtime['wednesday']) { + $data[3] .= __('Wed'); + $data[3] .= " "; + } + if ($planned_downtime['thursday']) { + $data[3] .= __('Thu'); + $data[3] .= " "; + } + if ($planned_downtime['friday']) { + $data[3] .= __('Fri'); + $data[3] .= " "; + } + if ($planned_downtime['saturday']) { + $data[3] .= __('Sat'); + $data[3] .= " "; + } + if ($planned_downtime['sunday']) { + $data[3] .= __('Sun'); + $data[3] .= " "; + } + $data[3] .= " (" . $planned_downtime['periodically_time_from']; + $data[3] .= "-" . $planned_downtime['periodically_time_to'] . ")"; + break; + case 'monthly': + $data[3] = __('Monthly:') . " "; + $data[3] .= __('From day') . " " . $planned_downtime['periodically_day_from']; + $data[3] .= " " . strtolower(__('To day')) . " "; + $data[3] .= $planned_downtime['periodically_day_to']; + $data[3] .= " (" . $planned_downtime['periodically_time_from']; + $data[3] .= "-" . $planned_downtime['periodically_time_to'] . ")"; + break; + } + break; + } + + if (!$malformed_planned_downtimes_empty && isset($malformed_planned_downtimes[$planned_downtime['id']])) { + $next_row_num = count($table_planned_downtimes->data); + $table_planned_downtimes->cellstyle[$next_row_num][0] = 'color: red'; + $table_planned_downtimes->cellstyle[$next_row_num][1] = 'color: red'; + $table_planned_downtimes->cellstyle[$next_row_num][2] = 'color: red'; + $table_planned_downtimes->cellstyle[$next_row_num][3] = 'color: red'; + + if (!$downtime_malformed) + $downtime_malformed = true; + } + + $table_planned_downtimes->data[] = $data; + } + } + } + + if ($downtime_malformed) { + $info_malformed = ui_print_error_message( + __('This item is affected by a malformed planned downtime') . ". " . + __('Go to the planned downtimes section to solve this') . ".", '', true); + + $data = array(); + $data[0] = $info_malformed; + $data[0] .= html_print_table($table_planned_downtimes, true); + $table->colspan[$next_row][0] = 3; + $next_row++; + array_push ($table->data, $data); + break; + } + + $data_graph = array (); + // $data_horin_graph = array(); + $data_graph[__('Inside limits')] = 0; + $data_graph[__('Out of limits')] = 0; + $data_graph[__('On the edge')] = 0; + $data_graph[__('Unknown')] = 0; + // $data_horin_graph[__('Inside limits')] = 0; + // $data_horin_graph[__('Out of limits')] = 0; + // $data_horin_graph[__('On the edge')] = 0; + // $data_horin_graph[__('Unknown')] = 0; + + $data_graph[__('Plannified downtime')] = 0; + + $urlImage = ui_get_full_url(false, true, false, false); + + $sla_failed = false; + $total_SLA = 0; + $total_result_SLA = 'ok'; + $sla_showed = array(); + $sla_showed_values = array(); + + foreach ($slas as $sla) { + $server_name = $sla ['server_name']; + //Metaconsole connection + if (($config ['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE')) { + $connection = metaconsole_get_connection($server_name); + if (!metaconsole_load_external_db($connection)) { + //ui_print_error_message ("Error connecting to ".$server_name); + continue; + } + } + + if (modules_is_disable_agent($sla['id_agent_module'])) { + continue; + } + + //Get the sla_value in % and store it on $sla_value + $sla_value = reporting_get_agentmodule_sla( + $sla['id_agent_module'], $content['period'], + $sla['sla_min'], $sla['sla_max'], + $report["datetime"], $content, + $content['time_from'], $content['time_to']); + + if (($config ['metaconsole'] == 1) && defined('METACONSOLE')) { + //Restore db connection + metaconsole_restore_db(); + } + + //Do not show right modules if 'only_display_wrong' is active + if ($content['only_display_wrong'] == 1 && + $sla_value >= $sla['sla_limit']) { + + continue; + } + + $sla_showed[] = $sla; + $sla_showed_values[] = $sla_value; + + } + + // SLA items sorted descending () + if ($content['top_n'] == 2) { + arsort($sla_showed_values); + } + // SLA items sorted ascending + else if ($content['top_n'] == 1) { + asort($sla_showed_values); + } + + // Slice graphs calculation + if ($show_graphs && !empty($slas)) { + $tableslice->width = '99%'; + $tableslice->style[0] = 'text-align: right'; + $tableslice->data = array (); + } + + foreach ($sla_showed_values as $k => $sla_value) { + $sla = $sla_showed[$k]; + + $server_name = $sla ['server_name']; + //Metaconsole connection + if (($config ['metaconsole'] == 1) && ($server_name != '') && defined('METACONSOLE')) { + $connection = metaconsole_get_connection($server_name); + if (metaconsole_connect($connection) != NOERR) { + //ui_print_error_message ("Error connecting to ".$server_name); + continue; + } + } + + //Fill the array data_graph for the pie graph + // if ($sla_value === false) { + // $data_graph[__('Unknown')]++; + // // $data_horin_graph[__('Unknown')]['g']++; + // } + // # Fix : 100% accurance is 'inside limits' although 10% was not overrun + // else if (($sla_value == 100 && $sla_value >= $sla['sla_limit']) ) { + // $data_graph[__('Inside limits')]++; + // $data_horin_graph[__('Inside limits')]['g']++; + // } + // else if ($sla_value <= ($sla['sla_limit']+10) && $sla_value >= ($sla['sla_limit']-10)) { + // $data_graph[__('On the edge')]++; + // $data_horin_graph[__('On the edge')]['g']++; + // } + // else if ($sla_value > ($sla['sla_limit']+10)) { + // $data_graph[__('Inside limits')]++; + // $data_horin_graph[__('Inside limits')]['g']++; + // } + // else if ($sla_value < ($sla['sla_limit']-10)) { + // $data_graph[__('Out of limits')]++; + // $data_horin_graph[__('Out of limits')]['g']++; + // } + + // if ($sla_value === false) { + // if ($total_result_SLA != 'fail') + // $total_result_SLA = 'unknown'; + // } + // else if ($sla_value < $sla['sla_limit']) { + // $total_result_SLA = 'fail'; + // } + + $total_SLA += $sla_value; + + if ($show_table) { + $data = array (); + $data[0] = modules_get_agentmodule_agent_name ($sla['id_agent_module']); + $data[1] = modules_get_agentmodule_name ($sla['id_agent_module']); + $data[2] = $sla['sla_max'].'/'; + $data[2] .= $sla['sla_min']; + $data[3] = $sla['sla_limit'].'%'; + + if ($sla_value === false) { + $data[4] = ''; + $data[5] = ''.__('Unknown').''; + // $data[6] = html_print_image('images/status_sets/default/severity_maintenance.png',true,array('title'=>__('Unknown'))); + } + else { + $data[4] = ''; + $data[5] = ''; + // $data[6] = ''; + + if ($sla_value >= $sla['sla_limit']) { + $data[4] = ''; + $data[5] = ''.__('OK').''; + } + else { + $sla_failed = true; + $data[4] = ''; + $data[5] = ''.__('Fail').''; + } + + // Print icon with status including edge + # Fix : 100% accurance is 'inside limits' although 10% was not overrun + // if (($sla_value == 100 && $sla_value >= $sla['sla_limit']) || ($sla_value > ($sla['sla_limit'] + $edge_interval))) { + // $data[6] = html_print_image('images/status_sets/default/severity_normal.png',true,array('title'=>__('Inside limits'))); + // } + // elseif (($sla_value <= $sla['sla_limit'] + $edge_interval) + // && ($sla_value >= $sla['sla_limit'] - $edge_interval)) { + // $data[6] = html_print_image('images/status_sets/default/severity_warning.png',true,array('title'=>__('On the edge'))); + // } + // else { + // $data[6] = html_print_image('images/status_sets/default/severity_critical.png',true,array('title'=>__('Out of limits'))); + // } + + $data[4] .= format_numeric ($sla_value, 2). "%"; + } + $data[4] .= ""; + + array_push ($table1->data, $data); + } + + // Slice graphs calculation + if ($show_graphs) { + $dataslice = array(); + $dataslice[0] = modules_get_agentmodule_agent_name ($sla['id_agent_module']); + $dataslice[0] .= "
"; + $dataslice[0] .= modules_get_agentmodule_name ($sla['id_agent_module']); + + $dataslice[1] = graph_sla_slicebar ($sla['id_agent_module'], $content['period'], + $sla['sla_min'], $sla['sla_max'], $report['datetime'], $content, $content['time_from'], + $content['time_to'], 650, 25, $urlImage, 1, false, false); + + array_push ($tableslice->data, $dataslice); + } + + if ($config ['metaconsole'] == 1 && defined('METACONSOLE')) { + //Restore db connection + metaconsole_restore_db(); + } + } + + if ($show_table) { + $data = array(); + $data[0] = html_print_table($table1, true); + $table->colspan[$next_row][0] = 3; + $next_row++; + array_push ($table->data, $data); + } + + // $data = array(); + // $data_pie_graph = json_encode ($data_graph); + if ($show_graphs && !empty($slas)) { + $table->colspan[$next_row][0] = 3; + $next_row++; + $data = array(); + $data[0] = html_print_table($tableslice, true); + array_push ($table->data, $data); + } + + if (!empty($table_planned_downtimes)) { + $data = array(); + $data[0] = html_print_table($table_planned_downtimes, true); + $table->colspan[$next_row][0] = 3; + $next_row++; + array_push ($table->data, $data); + } + break; + case 6: + case 'monitor_report': + if (empty($item_title)) { + $item_title = __('Monitor report'); + } + reporting_header_content($mini, $content, $report, $table, $item_title, + ui_print_truncate_text($agent_name, 'agent_medium', false) . + '
'.ui_print_truncate_text($module_name, 'module_medium', false)); + + //RUNNING + $next_row = 1; + + // Put description at the end of the module (if exists) + if ($content["description"] != "") { + $table->colspan[1][0] = 3; + $data_desc = array(); + $data_desc[0] = $content["description"]; + array_push ($table->data, $data_desc); + $next_row++; + } + + $data = array (); + $monitor_value = reporting_get_agentmodule_sla ($content['id_agent_module'], $content['period'], 1, false, $report["datetime"]); + if ($monitor_value === false) { + $monitor_value = __('Unknown'); + } + else { + $monitor_value = format_numeric ($monitor_value); + } + + $table->colspan[$next_row][0] = 2; + $data[0] = '

'; + $data[0] .= html_print_image("images/module_ok.png", true) . ' ' . __('OK') . ': ' . $monitor_value.' %

'; + if ($monitor_value !== __('Unknown')) { + $monitor_value = format_numeric (100 - $monitor_value, 2) ; + } + $data[1] = '

'; + $data[1] .= html_print_image("images/module_critical.png", true) . ' ' .__('Not OK') . ': ' .$monitor_value.' % ' . '

'; + array_push ($table->data, $data); + + break; + case 7: + case 'avg_value': + if (empty($item_title)) { + $item_title = __('Avg. Value'); + } + reporting_header_content($mini, $content, $report, $table, $item_title, + ui_print_truncate_text($agent_name, 'agent_medium', false) . + '
'.ui_print_truncate_text($module_name, 'module_medium', false)); + + //RUNNING + + // Put description at the end of the module (if exists) + $table->colspan[1][0] = 3; + if ($content["description"] != "") { + $data_desc = array(); + $data_desc[0] = $content["description"]; + array_push ($table->data, $data_desc); + } + + $data = array (); + $table->colspan[2][0] = 3; + $unit = db_get_value('unit', 'tagente_modulo', 'id_agente_modulo', $content['id_agent_module']); + $value = reporting_get_agentmodule_data_average ($content['id_agent_module'], $content['period'], $report["datetime"]); + if ($value === false) { + $value = __('Unknown'); + } + else { + $value = format_for_graph($value, 2) . " " . $unit; + } + $data[0] = '

'.$value.'

'; + array_push ($table->data, $data); + + break; + case 8: + case 'max_value': + if (empty($item_title)) { + $item_title = __('Max. Value'); + } + reporting_header_content($mini, $content, $report, $table, $item_title, + ui_print_truncate_text($agent_name, 'agent_medium', false) . + '
' . ui_print_truncate_text($module_name, 'module_medium', false)); + + //RUNNING + + // Put description at the end of the module (if exists) + $table->colspan[1][0] = 3; + if ($content["description"] != ""){ + $data_desc = array(); + $data_desc[0] = $content["description"]; + array_push ($table->data, $data_desc); + } + + $data = array (); + $table->colspan[2][0] = 3; + + $value = reporting_get_agentmodule_data_max ($content['id_agent_module'], $content['period'], $report["datetime"]); + + $unit = db_get_value('unit', 'tagente_modulo', 'id_agente_modulo', $content ['id_agent_module']); + $data[0] = '

' . + format_for_graph($value, 2) . " " . $unit .'

'; + array_push ($table->data, $data); + + break; + case 9: + case 'min_value': + if (empty($item_title)) { + $item_title = __('Min. Value'); + } + reporting_header_content($mini, $content, $report, $table, $item_title, + ui_print_truncate_text($agent_name, 'agent_medium', false) . + '
'.ui_print_truncate_text($module_name, 'module_medium', false)); + + //RUNNING + + // Put description at the end of the module (if exists) + $table->colspan[1][0] = 3; + if ($content["description"] != "") { + $data_desc = array(); + $data_desc[0] = $content["description"]; + array_push ($table->data, $data_desc); + } + + $data = array (); + $table->colspan[2][0] = 3; + + $value = reporting_get_agentmodule_data_min ($content['id_agent_module'], $content['period'], $report["datetime"]); + $unit = db_get_value('unit', 'tagente_modulo', 'id_agente_modulo', $content ['id_agent_module']); + if ($value === false) { + $value = __('Unknown'); + } + else { + $value = format_for_graph($value, 2) . " " . $unit; + } + $data[0] = '

'.$value.'

'; + array_push ($table->data, $data); + + break; + case 10: + case 'sumatory': + if (empty($item_title)) { + $item_title = __('Summatory'); + } + reporting_header_content($mini, $content, $report, $table, $item_title, + ui_print_truncate_text($agent_name, 'agent_medium', false) . + '
' . ui_print_truncate_text($module_name, 'module_medium', false)); + + //RUNNING + + $next_row = 1; + + // Put description at the end of the module (if exists) + if ($content["description"] != "") { + $data_desc = array(); + $data_desc[0] = $content["description"]; + array_push ($table->data, $data_desc); + $table->colspan[$next_row][0] = 3; + $next_row++; + } + + $table->colspan[$next_row][0] = 3; + + $data = array (); + $unit = db_get_value('unit', 'tagente_modulo', 'id_agente_modulo', $content['id_agent_module']); + + $value = reporting_get_agentmodule_data_sum ($content['id_agent_module'], $content['period'], $report["datetime"]); + if ($value === false) { + $value = __('Unknown'); + } + else { + $value = format_for_graph($value, 2) . " " . $unit; + } + + $data[0] = '

'.$value.'

'; + array_push ($table->data, $data); + + break; + case 'agent_detailed_event': + case 'event_report_agent': + if (empty($item_title)) { + $item_title = __('Agent detailed event'); + } + reporting_header_content($mini, $content, $report, $table, $item_title, + ui_print_truncate_text(agents_get_name($content['id_agent']), 'agent_medium', false)); + + $style = json_decode(io_safe_output($content['style']), true); + + $filter_event_no_validated = $style['filter_event_no_validated']; + $filter_event_validated = $style['filter_event_validated']; + $filter_event_critical = $style['filter_event_critical']; + $filter_event_warning = $style['filter_event_warning']; + + $event_graph_by_agent = $style['event_graph_by_agent']; + $event_graph_by_user_validator = $style['event_graph_by_user_validator']; + $event_graph_by_criticity = $style['event_graph_by_criticity']; + $event_graph_validated_vs_unvalidated = $style['event_graph_validated_vs_unvalidated']; + + $next_row = 1; + + // Put description at the end of the module (if exists) + if ($content["description"] != "") { + $data_desc = array(); + $data_desc[0] = $content["description"]; + array_push ($table->data, $data_desc); + $table->colspan[$next_row][0] = 3; + $next_row++; + } + + $data = array (); + $table->colspan[$next_row][0] = 3; + $next_row++; + $data[0] = reporting_get_agents_detailed_event( + $content['id_agent'], $content['period'], + $report["datetime"], true, + $filter_event_validated, + $filter_event_critical, + $filter_event_warning, + $filter_event_no_validated); + + if(!empty($data[0])) { + array_push ($table->data, $data); + + $table->colspan[$next_row][0] = 3; + $next_row++; + } + + + if ($event_graph_by_user_validator) { + $data_graph = reporting_get_count_events_validated_by_user( + array('id_agent' => $content['id_agent']), $content['period'], + $report["datetime"], + $filter_event_validated, + $filter_event_critical, + $filter_event_warning, + $filter_event_no_validated); + + $table_event_graph = null; + $table_event_graph->width = '100%'; + $table_event_graph->style[0] = 'text-align: center;'; + $table_event_graph->head[0] = __('Events validated by user'); + + $table_event_graph->data[0][0] = pie3d_graph( + false, $data_graph, 500, 150, __("other"), "", + ui_get_full_url(false, false, false, false) . "/images/logo_vertical_water.png", + $config['fontpath'], $config['font_size']); + + $data[0] = html_print_table($table_event_graph, true); + + $table->colspan[$next_row][0] = 3; + $next_row++; + array_push ($table->data, $data); + } + + if ($event_graph_by_criticity) { + $data_graph = reporting_get_count_events_by_criticity( + array('id_agent' => $content['id_agent']), $content['period'], + $report["datetime"], + $filter_event_validated, + $filter_event_critical, + $filter_event_warning, + $filter_event_no_validated); + + $colors = get_criticity_pie_colors($data_graph); + + $table_event_graph = null; + $table_event_graph->width = '100%'; + $table_event_graph->style[0] = 'text-align: center;'; + $table_event_graph->head[0] = __('Events by criticity'); + + $table_event_graph->data[0][0] = pie3d_graph( + false, $data_graph, 500, 150, __("other"), "", + ui_get_full_url(false, false, false, false) . "/images/logo_vertical_water.png", + $config['fontpath'], $config['font_size'], 1, false, $colors); + + $data[0] = html_print_table($table_event_graph, true); + + $table->colspan[$next_row][0] = 3; + $next_row++; + array_push ($table->data, $data); + } + + if ($event_graph_validated_vs_unvalidated) { + $data_graph = reporting_get_count_events_validated( + array('id_agent' => $content['id_agent']), $content['period'], + $report["datetime"], + $filter_event_validated, + $filter_event_critical, + $filter_event_warning, + $filter_event_no_validated); + + $table_event_graph = null; + $table_event_graph->width = '100%'; + $table_event_graph->style[0] = 'text-align: center;'; + $table_event_graph->head[0] = __('Amount events validated'); + + $table_event_graph->data[0][0] = pie3d_graph( + false, $data_graph, 500, 150, __("other"), "", + ui_get_full_url(false, false, false, false) . "/images/logo_vertical_water.png", + $config['fontpath'], $config['font_size']); + + $data[0] = html_print_table($table_event_graph, true); + + $table->colspan[$next_row][0] = 3; + $next_row++; + array_push ($table->data, $data); + } + break; + case 'text': + if (empty($item_title)) { + $item_title = __('Text'); + } + reporting_header_content($mini, $content, $report, $table, $item_title, + "", ""); + + $next_row = 1; + + if ($content["description"] != ""){ + $data_desc = array(); + $data_desc[0] = $content["description"]; + array_push ($table->data, $data_desc); + $table->colspan[$next_row][0] = 3; + $next_row++; + } + $data[0] = html_entity_decode($content['text']); + array_push($table->data, $data); + $table->colspan[$next_row][0] = 3; + break; + case 'sql': + if (empty($item_title)) { + $item_title = __('SQL'); + } + reporting_header_content($mini, $content, $report, $table, $item_title, + "", ""); + + $next_row = 1; + // Put description at the end of the module (if exists) + if ($content["description"] != ""){ + $data_desc = array(); + $data_desc[0] = $content["description"]; + array_push ($table->data, $data_desc); + + $table->colspan[$next_row][0] = 3; + $next_row++; + } + + $table->colspan[$next_row][0] = 3; + + $table2->class = 'databox'; + $table2->width = '100%'; + + //Create the head + $table2->head = array(); + if ($content['header_definition'] != '') { + $table2->head = explode('|', $content['header_definition']); + } + + if ($content['treport_custom_sql_id'] != 0) { + switch ($config["dbtype"]) { + case "mysql": + $sql = io_safe_output (db_get_value_filter('`sql`', 'treport_custom_sql', array('id' => $content['treport_custom_sql_id']))); + break; + case "postgresql": + $sql = io_safe_output (db_get_value_filter('"sql"', 'treport_custom_sql', array('id' => $content['treport_custom_sql_id']))); + break; + case "oracle": + $sql = io_safe_output (db_get_value_filter('sql', 'treport_custom_sql', array('id' => $content['treport_custom_sql_id']))); + break; + } + } + else { + $sql = io_safe_output ($content['external_source']); + } + + // Do a security check on SQL coming from the user + $sql = check_sql ($sql); + + if ($sql != '') { + $result = db_get_all_rows_sql($sql); + if ($result === false) { + $result = array(); + } + + if (isset($result[0])) { + if (count($result[0]) > count($table2->head)) { + $table2->head = array_pad($table2->head, count($result[0]), ' '); + } + } + + $table2->data = array(); + foreach ($result as $row) { + array_push($table2->data, $row); + } + } + else { + $table2->data = array(); + array_push($table2->data, array("id_user" => "
[".__('Illegal query')."]
". + __('Due security restrictions, there are some tokens or words you cannot use'). + ': *, delete, drop, alter, modify, union, password, pass, insert '.__('or')." update.
")); + } + + $cellContent = html_print_table($table2, true); + array_push($table->data, array($cellContent)); + break; + case 'sql_graph_vbar': + case 'sql_graph_hbar': + case 'sql_graph_pie': + $sizgraph_h = 300; + + if ($content['type'] == 'sql_graph_vbar') { + $sizgraph_h = 400; + } + + if ($config['metaconsole'] == 1 && defined('METACONSOLE')) + metaconsole_restore_db(); + + if (empty($item_title)) { + $item_title = __('User defined graph') . " (".__($content["type"]) .")"; + } + reporting_header_content($mini, $content, $report, $table, $item_title, + "", ""); + + // Put description at the end of the module (if exists) + $next_row = 1; + if ($content["description"] != "") { + $data_desc = array(); + $data_desc[0] = $content["description"]; + array_push ($table->data, $data_desc); + $table->colspan[$next_row][0] = 3; + $next_row++; + } + + $table->colspan[$next_row][0] = 3; + + $table2->class = 'databox'; + $table2->width = '100%'; + + //Create the head + $table2->head = array(); + if ($content['header_definition'] != '') { + $table2->head = explode('|', $content['header_definition']); + } + + $data = array (); + + $data[0] = graph_custom_sql_graph( + $content["id_rc"], + $sizgraph_w, + $sizgraph_h, + $content["type"], + true, + ui_get_full_url(false, false, false, false)); + + array_push($table->data, $data); + break; + case 'event_report_group': + if (empty($item_title)) { + $item_title = __('Group detailed event'); + } + reporting_header_content($mini, $content, $report, $table, $item_title, + ui_print_truncate_text(groups_get_name($content['id_group'], true), 60, false)); + + $next_row = 1; + + // Put description at the end of the module (if exists) + if ($content["description"] != "") { + $data_desc = array(); + $data_desc[0] = $content["description"]; + array_push ($table->data, $data_desc); + $table->colspan[$next_row][0] = 3; + $next_row++; + } + + $data = array (); + + $style = json_decode(io_safe_output($content['style']), true); + + $filter_event_no_validated = $style['filter_event_no_validated']; + $filter_event_validated = $style['filter_event_validated']; + $filter_event_critical = $style['filter_event_critical']; + $filter_event_warning = $style['filter_event_warning']; + + $event_graph_by_agent = $style['event_graph_by_agent']; + $event_graph_by_user_validator = $style['event_graph_by_user_validator']; + $event_graph_by_criticity = $style['event_graph_by_criticity']; + $event_graph_validated_vs_unvalidated = $style['event_graph_validated_vs_unvalidated']; + + $data[0] = reporting_get_group_detailed_event( + $content['id_group'], $content['period'], + $report["datetime"], true, true, + $filter_event_validated, + $filter_event_critical, + $filter_event_warning, + $filter_event_no_validated); + if(!empty($data[0])) { + array_push ($table->data, $data); + + $table->colspan[$next_row][0] = 3; + $next_row++; + } + + if ($event_graph_by_agent) { + $data_graph = reporting_get_count_events_by_agent( + $content['id_group'], $content['period'], + $report["datetime"], + $filter_event_validated, + $filter_event_critical, + $filter_event_warning, + $filter_event_no_validated); + + $table_event_graph = null; + $table_event_graph->width = '100%'; + $table_event_graph->style[0] = 'text-align: center;'; + $table_event_graph->head[0] = __('Events by agent'); + + $table_event_graph->data[0][0] = pie3d_graph( + false, $data_graph, 500, 150, __("other"), "", + ui_get_full_url(false, false, false, false) . "/images/logo_vertical_water.png", + $config['fontpath'], $config['font_size']); + + $data[0] = html_print_table($table_event_graph, true); + + $table->colspan[$next_row][0] = 3; + $next_row++; + array_push ($table->data, $data); + } + + if ($event_graph_by_user_validator) { + $data_graph = reporting_get_count_events_validated_by_user( + array('id_group' => $content['id_group']), $content['period'], + $report["datetime"], + $filter_event_validated, + $filter_event_critical, + $filter_event_warning, + $filter_event_no_validated); + + $table_event_graph = null; + $table_event_graph->head[0] = __('Events validated by user'); + $table_event_graph->width = '100%'; + $table_event_graph->style[0] = 'text-align: center;'; + + $table_event_graph->data[0][0] = pie3d_graph( + false, $data_graph, 500, 150, __("other"), "", + ui_get_full_url(false, false, false, false) . "/images/logo_vertical_water.png", + $config['fontpath'], $config['font_size']); + + $data[0] = html_print_table($table_event_graph, true); + + $table->colspan[$next_row][0] = 3; + $next_row++; + array_push ($table->data, $data); + } + + if ($event_graph_by_criticity) { + $data_graph = reporting_get_count_events_by_criticity( + array('id_group' => $content['id_group']), $content['period'], + $report["datetime"], + $filter_event_validated, + $filter_event_critical, + $filter_event_warning, + $filter_event_no_validated); + + $colors = get_criticity_pie_colors($data_graph); + + $table_event_graph = null; + $table_event_graph->head[0] = __('Events by criticity'); + $table_event_graph->width = '100%'; + $table_event_graph->style[0] = 'text-align: center;'; + + $table_event_graph->data[0][0] = pie3d_graph( + false, $data_graph, 500, 150, __("other"), "", + ui_get_full_url(false, false, false, false) . "/images/logo_vertical_water.png", + $config['fontpath'], $config['font_size'], 1, false, $colors); + + $data[0] = html_print_table($table_event_graph, true); + + $table->colspan[$next_row][0] = 3; + $next_row++; + array_push ($table->data, $data); + } + + if ($event_graph_validated_vs_unvalidated) { + $data_graph = reporting_get_count_events_validated( + array('id_group' => $content['id_group']), $content['period'], + $report["datetime"], + $filter_event_validated, + $filter_event_critical, + $filter_event_warning, + $filter_event_no_validated); + + $table_event_graph = null; + $table_event_graph->head[0] = __('Amount events validated'); + $table_event_graph->width = '100%'; + $table_event_graph->style[0] = 'text-align: center;'; + + $table_event_graph->data[0][0] = pie3d_graph( + false, $data_graph, 500, 150, __("other"), "", + ui_get_full_url(false, false, false, false) . "/images/logo_vertical_water.png", + $config['fontpath'], $config['font_size']); + + $data[0] = html_print_table($table_event_graph, true); + + $table->colspan[$next_row][0] = 3; + $next_row++; + array_push ($table->data, $data); + } + break; + case 'event_report_module': + if (empty($item_title)) { + $item_title = __('Module detailed event'); + } + reporting_header_content($mini, $content, $report, $table, $item_title, + ui_print_truncate_text($agent_name, 'agent_medium', false) . + '
' . ui_print_truncate_text($module_name, 'module_medium', false)); + + // Put description at the end of the module (if exists) + $table->colspan[1][0] = 3; + if ($content["description"] != "") { + $data_desc = array(); + $data_desc[0] = $content["description"]; + array_push ($table->data, $data_desc); + } + + $data = array (); + $table->colspan[2][0] = 3; + $data[0] = reporting_get_module_detailed_event($content['id_agent_module'], $content['period'], $report["datetime"], true); + array_push ($table->data, $data); + break; + case 'alert_report_group': + if (empty($item_title)) { + $item_title = __('Alert report group'); + } + reporting_header_content($mini, $content, $report, $table, $item_title, + ui_print_truncate_text( + groups_get_name($content['id_group'], true), + 60, false)); + + // Put description at the end of the module (if exists) + $table->colspan[1][0] = 3; + if ($content["description"] != "") { + $data_desc = array(); + $data_desc[0] = $content["description"]; + array_push ($table->data, $data_desc); + } + + $data = array (); + $table->colspan[2][0] = 3; + $data[0] = reporting_alert_reporting_group( + $content['id_group'], $content['period'], + $report["datetime"], true); + array_push ($table->data, $data); + break; + case 'alert_report_module': + if (empty($item_title)) { + $item_title = __('Alert report module'); + } + reporting_header_content($mini, $content, $report, $table, $item_title, + ui_print_truncate_text($agent_name, 'agent_medium', false) . + '
'.ui_print_truncate_text($module_name, 'module_medium', false)); + + // Put description at the end of the module (if exists) + $table->colspan[1][0] = 3; + if ($content["description"] != "") { + $data_desc = array(); + $data_desc[0] = $content["description"]; + array_push ($table->data, $data_desc); + } + + $data = array (); + $table->colspan[2][0] = 3; + $data[0] = reporting_alert_reporting_module ($content['id_agent_module'], $content['period'], $report["datetime"], true); + array_push ($table->data, $data); + break; + case 'alert_report_agent': + if (empty($item_title)) { + $item_title = __('Alert report agent'); + } + reporting_header_content($mini, $content, $report, $table, $item_title, + ui_print_truncate_text($agent_name, 'agent_medium', false)); + + // Put description at the end of the module (if exists) + $table->colspan[1][0] = 3; + if ($content["description"] != "") { + $data_desc = array(); + $data_desc[0] = $content["description"]; + array_push ($table->data, $data_desc); + } + + $data = array (); + $table->colspan[2][0] = 3; + $data[0] = reporting_alert_reporting_agent ($content['id_agent'], $content['period'], $report["datetime"], true); + array_push ($table->data, $data); + break; + case 'url': + if (empty($item_title)) { + $item_title = __('Import text from URL'); + } + reporting_header_content($mini, $content, $report, $table, $item_title, + ui_print_truncate_text($content["external_source"], 'description', false)); + + $next_row = 1; + // Put description at the end of the module (if exists) + if ($content["description"] != "") { + $data_desc = array(); + $data_desc[0] = $content["description"]; + array_push ($table->data, $data_desc); + $table->colspan[$next_row][0] = 3; + $next_row++; + } + + $data = array(); + $table->colspan[$next_row][0] = 3; + $data[0] = ''; + // TODO: make this dynamic and get the height if the iframe to resize this item + $data[0] .= ''; + + array_push ($table->data, $data); + break; + case 'database_serialized': + if (empty($item_title)) { + $item_title = __('Serialize data'); + } + reporting_header_content($mini, $content, $report, $table, $item_title, + ui_print_truncate_text($module_name, 'module_medium', false)); + + // Put description at the end of the module (if exists) + $next_row = 1; + if ($content["description"] != "") { + $data_desc = array(); + $data_desc[0] = $content["description"]; + $table->colspan[$next_row][0] = 3; + array_push ($table->data, $data_desc); + $next_row++; + } + + $table->colspan[$next_row][0] = 3; + + $table2->class = 'databox alternate'; + $table2->width = '100%'; + + //Create the head + $table2->head = array(); + if ($content['header_definition'] != '') { + $table2->head = explode('|', $content['header_definition']); + } + else { + $table2->head[] = __('Data'); + } + array_unshift($table2->head, __('Date')); + + $datelimit = $report["datetime"] - $content['period']; + $search_in_history_db = db_search_in_history_db($datelimit); + + // This query gets information from the default and the historic database + $result = db_get_all_rows_sql('SELECT * + FROM tagente_datos + WHERE id_agente_modulo = ' . $content['id_agent_module'] . ' + AND utimestamp > ' . $datelimit . ' + AND utimestamp <= ' . $report["datetime"], $search_in_history_db); + + // Adds string data if there is no numeric data + if ((count($result) < 0) or (!$result)) { + // This query gets information from the default and the historic database + $result = db_get_all_rows_sql('SELECT * + FROM tagente_datos_string + WHERE id_agente_modulo = ' . $content['id_agent_module'] . ' + AND utimestamp > ' . $datelimit . ' + AND utimestamp <= ' . $report["datetime"], $search_in_history_db); + } + if ($result === false) { + $result = array(); + } + + $table2->data = array(); + foreach ($result as $row) { + $date = date ($config["date_format"], $row['utimestamp']); + $serialized = $row['datos']; + if (empty($content['line_separator']) || + empty($serialized)) { + $rowsUnserialize = array($row['datos']); + } + else { + $rowsUnserialize = explode($content['line_separator'], $serialized); + } + foreach ($rowsUnserialize as $rowUnser) { + if (empty($content['column_separator'])) { + $columnsUnserialize = array($rowUnser); + } + else { + $columnsUnserialize = explode($content['column_separator'], $rowUnser); + } + + array_unshift($columnsUnserialize, $date); + array_push($table2->data, $columnsUnserialize); + } + } + + $cellContent = html_print_table($table2, true); + array_push($table->data, array($cellContent)); + break; + case 'TTRT': + if (empty($item_title)) { + $item_title = __('TTRT'); + } + reporting_header_content($mini, $content, $report, $table, $item_title, + ui_print_truncate_text($agent_name, 'agent_medium', false) . + '
'.ui_print_truncate_text($module_name, 'module_medium', false)); + + // Put description at the end of the module (if exists) + $table->colspan[1][0] = 3; + if ($content["description"] != "") { + $data_desc = array(); + $data_desc[0] = $content["description"]; + array_push ($table->data, $data_desc); + } + + $data = array (); + $table->colspan[2][0] = 3; + $ttr = reporting_get_agentmodule_ttr ($content['id_agent_module'], $content['period'], $report["datetime"]); + if ($ttr === false) { + $ttr = __('Unknown'); + } + else if ($ttr != 0) { + $ttr = human_time_description_raw ($ttr); + } + + $data = array (); + $table->colspan[2][0] = 3; + $data[0] = '

'.$ttr.'

'; + array_push ($table->data, $data); + break; + case 'TTO': + if (empty($item_title)) { + $item_title = __('TTO'); + } + reporting_header_content($mini, $content, $report, $table, $item_title, + ui_print_truncate_text($agent_name, 'agent_medium', false) . + '
'.ui_print_truncate_text($module_name, 'module_medium', false)); + + // Put description at the end of the module (if exists) + $table->colspan[1][0] = 3; + if ($content["description"] != "") { + $data_desc = array(); + $data_desc[0] = $content["description"]; + array_push ($table->data, $data_desc); + } + + $data = array (); + $table->colspan[2][0] = 3; + $tto = reporting_get_agentmodule_tto ($content['id_agent_module'], + $content['period'], $report["datetime"]); + if ($tto === false) { + $tto = __('Unknown'); + } + else if ($tto != 0) { + $tto = human_time_description_raw ($tto); + } + + $data = array (); + $table->colspan[2][0] = 3; + $data[0] = '

'.$tto.'

'; + array_push ($table->data, $data); + break; + case 'MTBF': + if (empty($item_title)) { + $item_title = __('MTBF'); + } + reporting_header_content($mini, $content, $report, $table, $item_title, + ui_print_truncate_text($agent_name, 'agent_medium', false) . + '
'.ui_print_truncate_text($module_name, 'module_medium', false)); + + // Put description at the end of the module (if exists) + $table->colspan[1][0] = 3; + if ($content["description"] != "") { + $data_desc = array(); + $data_desc[0] = $content["description"]; + array_push ($table->data, $data_desc); + } + + $data = array (); + $table->colspan[2][0] = 3; + $mtbf = reporting_get_agentmodule_mtbf ($content['id_agent_module'], $content['period'], $report["datetime"]); + if ($mtbf === false) { + $mtbf = __('Unknown'); + } + else if ($mtbf != 0) { + $mtbf = human_time_description_raw ($mtbf); + } + + $data = array (); + $table->colspan[2][0] = 3; + $data[0] = '

'.$mtbf.'

'; + array_push ($table->data, $data); + break; + case 'MTTR': + if (empty($item_title)) { + $item_title = __('MTTR'); + } + reporting_header_content($mini, $content, $report, $table, $item_title, + ui_print_truncate_text($agent_name, 'agent_medium', false) . + '
'.ui_print_truncate_text($module_name, 'module_medium', false)); + + // Put description at the end of the module (if exists) + $table->colspan[1][0] = 3; + if ($content["description"] != "") { + $data_desc = array(); + $data_desc[0] = $content["description"]; + array_push ($table->data, $data_desc); + } + + $data = array (); + $table->colspan[2][0] = 3; + $mttr = reporting_get_agentmodule_mttr ($content['id_agent_module'], $content['period'], $report["datetime"]); + if ($mttr === false) { + $mttr = __('Unknown'); + } + else if ($mttr != 0) { + $mttr = human_time_description_raw ($mttr); + } + + $data = array (); + $table->colspan[2][0] = 3; + $data[0] = '

'.$mttr.'

'; + array_push ($table->data, $data); + break; + case 'group_report': + $group_name = groups_get_name($content['id_group'], true); + $group_stats = reporting_get_group_stats($content['id_group']); + // Get events of the last 8 hours + $events = events_get_group_events ($content['id_group'], 28800, $report['datetime']); + + if ($events === false) { + $events = array(); + } + + if (empty($item_title)) { + $item_title = __('Group report').': "'.$group_name.'"'; + } + reporting_header_content($mini, $content, $report, $table, $item_title); + + $table->colspan[1][0] = 3; + + if ($content["description"] != "") { + $data_desc = array(); + $data_desc[0] = $content["description"]; + array_push ($table->data, $data_desc); + } + + $table->colspan[2][0] = 3; + + $table->data[2][0] = + " + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
" . + __('Total') . "
" . + __('Unknown') . "
" . + __('Agents') . "
" . + $group_stats['total_agents'] . "
" . + $group_stats['agents_unknown'] . "
" . + __('Total') . "
" . + __('Normal') . "
" . + __('Critical') . "
" . + __('Warning') . "
" . + __('Unknown') . "
" . + __('Not init') . "
" . + __('Monitors') . "
" . + $group_stats['monitor_checks'] . "
" . + $group_stats['monitor_ok'] ."
" . + $group_stats['monitor_critical'] . "
" . + $group_stats['monitor_warning'] . "
" . + $group_stats['monitor_unknown'] . "
" . + $group_stats['monitor_not_init'] . "
" . + __('Defined') . "
" . + __('Fired') . "
" . + __('Alerts') . "
" . + $group_stats['monitor_alerts'] . "
" . + $group_stats['monitor_alerts_fired'] . "
" . + __('Last 8 hours') . "
" . + __('Events') . "
" . + count($events)."
"; + + break; + case 'network_interfaces_report': + reporting_network_interfaces_table($content, $report, $mini, $item_title, $table); + break; + case 'general': + if (empty($item_title)) { + $item_title = __('General'); + } + reporting_header_content($mini, $content, $report, $table, $item_title); + + $group_by_agent = $content['group_by_agent']; + $order_uptodown = $content['order_uptodown']; + + $table->style[1] = 'text-align: right'; + + // Put description at the end of the module (if exists) + $table->colspan[1][0] = 3; + if ($content["description"] != "") { + $data_desc = array(); + $data_desc[0] = $content["description"]; + array_push($table->data, $data_desc); + } + + switch ($group_by_agent) { + //0 means not group by agent + case 0: + $sql = sprintf(" + SELECT id_agent_module, + server_name, operation + FROM treport_content_item + WHERE id_report_content = %d", + $content['id_rc']); + + $generals = db_process_sql ($sql); + if ($generals === false) { + $data = array (); + $table->colspan[2][0] = 3; + $data[0] = + __('There are no Agent/Modules defined'); + array_push ($table->data, $data); + break; + } + + $table1->width = '99%'; + $table1->data = array (); + $table1->head = array (); + $table1->head[0] = __('Agent'); + $table1->head[1] = __('Module'); + if ($content['period'] != 0) { + $table1->head[2] = __('Operation'); + } + $table1->head[3] = __('Value'); + $table1->style[0] = 'text-align: left'; + $table1->style[1] = 'text-align: left'; + $table1->style[2] = 'text-align: left'; + $table1->style[3] = 'text-align: left'; + + $data_res = array(); + + foreach ($generals as $key => $row) { + //Metaconsole connection + $server_name = $row ['server_name']; + if (($config ['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE')) { + $connection = metaconsole_get_connection($server_name); + if (metaconsole_load_external_db($connection) != NOERR) { + //ui_print_error_message ("Error connecting to ".$server_name); + continue; + } + } + + if (modules_is_disable_agent($row['id_agent_module'])) { + continue; + } + + $mod_name = modules_get_agentmodule_name ($row['id_agent_module']); + $ag_name = modules_get_agentmodule_agent_name ($row['id_agent_module']); + + if ($content['period'] == 0) { + $data_res[$key] = + modules_get_last_value($row['id_agent_module']); + } + else { + switch ($row['operation']) { + case 'sum': + $data_res[$key] = + reporting_get_agentmodule_data_sum( + $row['id_agent_module'], $content['period'], $report["datetime"]); + break; + case 'max': + $data_res[$key] = + reporting_get_agentmodule_data_max( + $row['id_agent_module'], $content['period']); + break; + case 'min': + $data_res[$key] = + reporting_get_agentmodule_data_min( + $row['id_agent_module'], $content['period']); + break; + case 'avg': + default: + $data_res[$key] = + reporting_get_agentmodule_data_average( + $row['id_agent_module'], $content['period']); + break; + } + } + + $unit = db_get_value('unit', 'tagente_modulo', + 'id_agente_modulo', + $row['id_agent_module']); + + $id_agent_module[$key] = $row['id_agent_module']; + $agent_name[$key] = $ag_name; + $module_name[$key] = $mod_name; + $units[$key] = $unit; + $operations[$key] = $row['operation']; + + //Restore dbconnection + if (($config ['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE')) { + metaconsole_restore_db(); + } + } + //Order by data descending, ascending or without order + if (($order_uptodown == 0) || ($order_uptodown == 1) + || ($order_uptodown == 2)) { + + + switch ($order_uptodown) { + //Descending + case 1: + array_multisort($data_res, SORT_DESC, + $agent_name, SORT_ASC, $module_name, + SORT_ASC, $id_agent_module, + SORT_ASC, $operations, SORT_ASC); + break; + //Ascending + case 2: + array_multisort($data_res, SORT_ASC, + $agent_name, SORT_ASC, $module_name, + SORT_ASC, $id_agent_module, + SORT_ASC, $operations, SORT_ASC); + break; + } + + + $i = 0; + foreach ($data_res as $d) { + $data = array(); + $data[0] = $agent_name[$i]; + $data[1] = $module_name[$i]; + + if ($content['period'] != 0) { + switch ($operations[$i]) { + case 'sum': + $op = __('Summatory'); + break; + case 'min': + $op = __('Minimal'); + break; + case 'max': + $op = __('Maximun'); + break; + case 'avg': + default: + $op = __('Rate'); + break; + } + $data[2] = $op; + } + + if ($d === false) { + $data[3] = '--'; + } + else { + if (!is_numeric($d)) { + $data[3] = $d; + } + else { + $data[3] = format_for_graph($d, 2) . " " . + $units[$i]; + } + } + array_push ($table1->data, $data); + $i++; + } + } + //Order by agent name + elseif ($order_uptodown == 3) { + array_multisort($agent_name, SORT_ASC, + $data_res, SORT_ASC, $module_name, SORT_ASC, + $id_agent_module, SORT_ASC, $operations, + SORT_ASC); + $i=0; + foreach ($agent_name as $a) { + $data = array(); + $data[0] = $agent_name[$i]; + $data[1] = $module_name[$i]; + + switch ($operations[$i]) { + case 'sum': + $op = __('Summatory'); + break; + case 'min': + $op = __('Minimal'); + break; + case 'max': + $op = __('Maximun'); + break; + case 'avg': + default: + $op = __('Average'); + break; + } + $data[2] = $op; + + + if ($data_res[$i] === false) { + $data[3] = '--'; + } + else { + $data[3] = + format_for_graph($data_res[$i], 2) + . " " . $units[$i]; + } + array_push ($table1->data, $data); + $i++; + } + } + + $table->colspan[2][0] = 3; + $data = array(); + $data[0] = html_print_table($table1, true); + array_push ($table->data, $data); + break; + //1 means group by agent + case 1: + //Get the data + $sql_data = sprintf("SELECT id_agent_module, + server_name, operation + FROM treport_content_item + WHERE id_report_content = %d", + $content['id_rc']); + $generals = db_process_sql ($sql_data); + + if ($generals === false) { + $data = array (); + $table->colspan[2][0] = 3; + $data[0] = __('There are no Agent/Modules defined'); + array_push ($table->data, $data); + break; + } + + $list_modules = array(); + $data = array(); + foreach ($generals as $g) { + //Metaconsole connection + $server_name = $g ['server_name']; + if (($config ['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE')) { + $connection = metaconsole_get_connection($server_name); + if (metaconsole_load_external_db($connection) != NOERR) { + //ui_print_error_message ("Error connecting to ".$server_name); + continue; + } + } + + if (modules_is_disable_agent($g['id_agent_module'])) { + continue; + } + + $agent_name = modules_get_agentmodule_agent_name ($g['id_agent_module']); + $module_name = modules_get_agentmodule_name ($g['id_agent_module']); + $unit = db_get_value('unit', 'tagente_modulo', 'id_agente_modulo', $g['id_agent_module']); + + + + + if ($content['period'] == 0) { + $value_res = + modules_get_last_value($g['id_agent_module']); + } + else { + switch ($g['operation']) { + case 'sum': + $value_res = reporting_get_agentmodule_data_sum ($g['id_agent_module'], $content['period'], $report["datetime"]); + break; + case 'max': + $value_res = reporting_get_agentmodule_data_max ($g['id_agent_module'], $content['period']); + break; + case 'min': + $value_res = reporting_get_agentmodule_data_min ($g['id_agent_module'], $content['period']); + break; + case 'avg': + default: + $value_res = reporting_get_agentmodule_data_average ($g['id_agent_module'], $content['period']); + break; + } + } + + if ($value_res === false) { + $data[$agent_name][$module_name] = '--'; + } + else { + if (!is_numeric($value_res)) { + $data[$agent_name][$module_name] = $value_res; + } + else { + $data[$agent_name][$module_name] = format_for_graph($value_res, 2) . " " . $unit; + } + } + + // Save the modules + $list_modules[$module_name] = null; + + // Restore dbconnection + if (($config ['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE')) { + metaconsole_restore_db(); + } + } + + $table2->width = '99%'; + $table2->data = array (); + $table2->head = array (); + $table2->head[0] = __('Agent'); + $table2->style[0] = 'text-align: left'; + $i = 1; + foreach (array_keys($list_modules) as $module) { + $table2->head[$i] = + ui_print_truncate_text($module, 20, false); + $table2->style[$i] = 'text-align: center'; + $i++; + } + + + + foreach ($data as $agent_name => $agent) { + $row = array(); + $row[] = $agent_name; + foreach (array_keys($list_modules) as $module_name) { + if (!isset($agent[$module_name])) { + $row[] = '--'; + } + else { + $row[] = $agent[$module_name]; + } + } + $table2->data[] = $row; + } + + $data = array(); + $data[0] = html_print_table($table2, true); + array_push ($table->data, $data); + break; + } + + if ($content['show_resume'] && count($generals) > 0) { + + //Get the first valid value and assign it to $min & $max + $min = false; + $min_name_agent_module = ''; + $max_name_agent_module = ''; + $min_unit = ''; + $max_unit = ''; + $i=0; + do { + //Metaconsole connection + $server_name = $generals[$i]['server_name']; + if (($config ['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE')) { + $connection = metaconsole_get_connection($server_name); + if (metaconsole_load_external_db($connection) != NOERR) { + //ui_print_error_message ("Error connecting to ".$server_name); + continue; + } + } + + if ($content['period'] == 0) { + $min = + modules_get_last_value($generals[$i]['id_agent_module']); + } + else { + switch ($generals[$i]['operation']) { + case 'sum': + $min = reporting_get_agentmodule_data_sum ($generals[$i]['id_agent_module'], $content['period'], $report["datetime"]); + break; + case 'max': + $min = reporting_get_agentmodule_data_max ($generals[$i]['id_agent_module'], $content['period']); + break; + case 'min': + $min = reporting_get_agentmodule_data_min ($generals[$i]['id_agent_module'], $content['period']); + break; + case 'avg': + default: + $min = reporting_get_agentmodule_data_average ($generals[$i]['id_agent_module'], $content['period']); + break; + } + } + $i++; + + $min_name_agent_module = + modules_get_agentmodule_name($generals[$i]['id_agent_module']) . + " - " . + modules_get_agentmodule_agent_name($generals[$i]['id_agent_module']) . + " (" . $generals[$i]['operation'] . ")"; + + $min_unit = db_get_value('unit', 'tagente_modulo', 'id_agente_modulo', $generals[$i]['id_agent_module']); + + //Restore dbconnection + if (($config ['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE')) { + metaconsole_restore_db(); + } + } + while ($min === false && $i < count($generals)); + + $max = $min; + $max_name_agent_module = $min_name_agent_module; + $max_unit = $min_unit; + $avg = 0; + $length = 0; + + if ($generals === false) { + $generals = array(); + } + + foreach ($generals as $g) { + //Metaconsole connection + $server_name = $g['server_name']; + if (($config ['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE')) { + $connection = metaconsole_get_connection($server_name); + if (metaconsole_load_external_db($connection) != NOERR) { + //ui_print_error_message ("Error connecting to ".$server_name); + continue; + } + } + + if ($content['period'] == 0) { + $value = + modules_get_last_value($g['id_agent_module']); + } + else { + switch ($g['operation']) { + case 'sum': + $value = reporting_get_agentmodule_data_sum ($g['id_agent_module'], $content['period'], $report["datetime"]); + break; + case 'max': + $value = reporting_get_agentmodule_data_max ($g['id_agent_module'], $content['period']); + break; + case 'min': + $value = reporting_get_agentmodule_data_min ($g['id_agent_module'], $content['period']); + break; + case 'avg': + default: + $value = reporting_get_agentmodule_data_average ($g['id_agent_module'], $content['period']); + break; + } + } + + if ($value !== false) { + if ($value > $max) { + $max = $value; + $max_name_agent_module = + modules_get_agentmodule_name($g['id_agent_module']) . + " - " . + modules_get_agentmodule_agent_name($g['id_agent_module']) . + " (" . $g['operation'] . ")"; + $max_unit = db_get_value('unit', 'tagente_modulo', 'id_agente_modulo', $g['id_agent_module']); + } + if ($value < $min ) { + $min = $value; + $min_name_agent_module = + modules_get_agentmodule_name($g['id_agent_module']) . + " - " . + modules_get_agentmodule_agent_name($g['id_agent_module']) . + " (" . $g['operation'] . ")"; + $min_unit = db_get_value('unit', 'tagente_modulo', 'id_agente_modulo', $g['id_agent_module']); + } + $avg += $value; + $length++; + } + + //Restore dbconnection + if (($config ['metaconsole'] == 1) + && $server_name != '' + && defined('METACONSOLE')) { + metaconsole_restore_db(); + } + } + if ($length == 0) { + $avg = 0; + } + else { + $avg = $avg / $length; + } + + unset($table_summary); + $table_summary->width = '99%'; + + $table_summary->data = array (); + $table_summary->head = array (); + $table_summary->head_colspan = array (); + $table_summary->align = array(); + + $table_summary->align[0] = 'left'; + $table_summary->align[1] = 'left'; + $table_summary->align[2] = 'left'; + $table_summary->align[3] = 'left'; + $table_summary->align[4] = 'left'; + + $table_summary->head_colspan[0] = 2; + $table_summary->head[0] = __('Min Value'); + $table_summary->head[1] = __('Average Value'); + $table_summary->head_colspan[2] = 2; + $table_summary->head[2] = __('Max Value'); + + $table_summary->data[0][0] = $min_name_agent_module; + $table_summary->data[0][1] = format_for_graph($min,2) . ' ' . $min_unit; + $table_summary->data[0][2] = format_for_graph($avg,2); + $table_summary->data[0][3] = $max_name_agent_module; + $table_summary->data[0][4] = format_for_graph($max,2) . ' ' . $max_unit; + + $table->colspan[3][0] = 3; + array_push ($table->data, + array('' . __('Summary') . '')); + $table->colspan[4][0] = 3; + array_push ($table->data, + array(html_print_table($table_summary, true))); + } + break; + + + case 'top_n': + $top_n = $content['top_n']; + + switch ($top_n) { + case REPORT_TOP_N_MAX: + $type_top_n = __('Max'); + break; + case REPORT_TOP_N_MIN: + $type_top_n = __('Min'); + break; + case REPORT_TOP_N_AVG: + default: + //If nothing is selected then it will be shown the average data + $type_top_n = __('Avg'); + break; + } + + if (empty($item_title)) { + $item_title = 'Top '.$content['top_n_value'] . '
' . $type_top_n; + } + reporting_header_content($mini, $content, $report, $table, $item_title); + + $order_uptodown = $content['order_uptodown']; + + $top_n_value = $content['top_n_value']; + $show_graph = $content['show_graph']; + + $table->style[0] = 'padding: 8px 5px 8px 5px;'; + $table->style[1] = 'text-align: right'; + + // Put description at the end of the module (if exists) + $table->colspan[1][0] = 3; + if ($content["description"] != "") { + $data_desc = array(); + $data_desc[0] = $content["description"]; + array_push ($table->data, $data_desc); + } + //Get all the related data + $sql = sprintf("SELECT id_agent_module, server_name + FROM treport_content_item + WHERE id_report_content = %d", $content['id_rc']); + + $tops = db_process_sql ($sql); + + if ($tops === false) { + $data = array (); + $table->colspan[2][0] = 3; + $data[0] = __('There are no Agent/Modules defined'); + array_push ($table->data, $data); + break; + } + + if ($show_graph != REPORT_TOP_N_ONLY_GRAPHS) { + $table1->width = '99%'; + $table1->data = array (); + $table1->head = array (); + $table1->head[0] = __('Agent'); + $table1->head[1] = __('Module'); + $table1->head[2] = __('Value'); + $table1->style[0] = 'text-align: left'; + $table1->style[1] = 'text-align: left'; + $table1->style[2] = 'text-align: left'; + } + + //Get data of all agents (before to slide to N values) + $data_top = array(); + + foreach ($tops as $key => $row) { + + //Metaconsole connection + $server_name = $row['server_name']; + if (($config ['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE')) { + $connection = metaconsole_get_connection($server_name); + if (metaconsole_load_external_db($connection) != NOERR) { + //ui_print_error_message ("Error connecting to ".$server_name); + continue; + } + } + + $ag_name = modules_get_agentmodule_agent_name($row ['id_agent_module']); + $mod_name = modules_get_agentmodule_name ($row ['id_agent_module']); + $unit = db_get_value('unit', 'tagente_modulo', + 'id_agente_modulo', $row ['id_agent_module']); + + + switch ($top_n) { + case REPORT_TOP_N_MAX: + $value = reporting_get_agentmodule_data_max ($row['id_agent_module'], $content['period']); + break; + case REPORT_TOP_N_MIN: + $value = reporting_get_agentmodule_data_min ($row['id_agent_module'], $content['period']); + break; + case REPORT_TOP_N_AVG: + default: + //If nothing is selected then it will be shown the average data + $value = reporting_get_agentmodule_data_average ($row['id_agent_module'], $content['period']); + break; + } + + //If the returned value from modules_get_agentmodule_data_max/min/avg is false it won't be stored. + if ($value !== false) { + $data_top[$key] = $value; + $id_agent_module[$key] = $row['id_agent_module']; + $agent_name[$key] = $ag_name; + $module_name[$key] = $mod_name; + $units[$key] = $unit; + } + + //Restore dbconnection + if (($config ['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE')) { + metaconsole_restore_db(); + } + } + + if (empty($data_top)) { + $data = array (); + $table->colspan[2][0] = 3; + $data[0] = __('Insuficient data'); + array_push ($table->data, $data); + break; + } + + //Order to show. + switch ($order_uptodown) { + //Descending + case 1: + array_multisort($data_top, SORT_DESC, $agent_name, SORT_ASC, $module_name, SORT_ASC, $id_agent_module, SORT_ASC, $units, SORT_ASC); + break; + //Ascending + case 2: + array_multisort($data_top, SORT_ASC, $agent_name, SORT_ASC, $module_name, SORT_ASC, $id_agent_module, SORT_ASC, $units, SORT_ASC); + break; + //By agent name or without selection + case 0: + case 3: + array_multisort($agent_name, SORT_ASC, $data_top, SORT_ASC, $module_name, SORT_ASC, $id_agent_module, SORT_ASC, $units, SORT_ASC); + break; + } + + array_splice ($data_top, $top_n_value); + array_splice ($agent_name, $top_n_value); + array_splice ($module_name, $top_n_value); + array_splice ($id_agent_module, $top_n_value); + array_splice ($units, $top_n_value); + + $data_top_values = array (); + $data_top_values['data_top'] = $data_top; + $data_top_values['agent_name'] = $agent_name; + $data_top_values['module_name'] = $module_name; + $data_top_values['id_agent_module'] = $id_agent_module; + $data_top_values['units'] = $units; + + // Define truncate size depends the graph width + $truncate_size = $sizgraph_w / (4 * ($config['font_size']))-1; + + if ($order_uptodown == 1 || $order_uptodown == 2) { + $i = 0; + $data_pie_graph = array(); + $data_hbar = array(); + foreach ($data_top as $dt) { + $item_name = ''; + $item_name = + ui_print_truncate_text($agent_name[$i], $truncate_size, false, true, false, "...") . + ' - ' . + ui_print_truncate_text($module_name[$i], $truncate_size, false, true, false, "..."); + + + + //Dirty hack, maybe I am going to apply a job in Apple + //https://www.imperialviolet.org/2014/02/22/applebug.html + $item_name_key_pie = $item_name; + $exist_key = true; + while ($exist_key) { + if (isset($data_pie_graph[$item_name_key_pie])) { + $item_name_key_pie .= ' '; + } + else { + $exist_key = false; + } + } + $item_name_key_hbar = $item_name; + $exist_key = true; + while ($exist_key) { + if (isset($data_hbar[$item_name_key_hbar])) { + $item_name_key_hbar = ' ' . $item_name_key_hbar; + } + else { + $exist_key = false; + } + } + + + + $data_hbar[$item_name]['g'] = $dt; + $data_pie_graph[$item_name] = $dt; + + if ($show_graph == 0 || $show_graph == 1) { + $data = array(); + $data[0] = $agent_name[$i]; + $data[1] = $module_name[$i]; + + $data[2] = format_for_graph($dt,2) . " " . $units[$i]; + array_push ($table1->data, $data); + } + $i++; + if ($i >= $top_n_value) break; + } + } + else if ($order_uptodown == 0 || $order_uptodown == 3) { + $i = 0; + $data_pie_graph = array(); + $data_hbar = array(); + foreach ($agent_name as $an) { + $item_name = ''; + $item_name = + ui_print_truncate_text($agent_name[$i], + $truncate_size, false, true, false, "...") . + ' - ' . + ui_print_truncate_text($module_name[$i], + $truncate_size, false, true, false, "..."); + + + + //Dirty hack, maybe I am going to apply a job in Apple + //https://www.imperialviolet.org/2014/02/22/applebug.html + $item_name_key_pie = $item_name; + $exist_key = true; + while ($exist_key) { + if (isset($data_pie_graph[$item_name_key_pie])) { + $item_name_key_pie .= ' '; + } + else { + $exist_key = false; + } + } + $item_name_key_hbar = $item_name; + $exist_key = true; + while ($exist_key) { + if (isset($data_hbar[$item_name_key_hbar])) { + $item_name_key_hbar = ' ' . $item_name_key_hbar; + } + else { + $exist_key = false; + } + } + + + + $data_pie_graph[$item_name] = $data_top[$i]; + $data_hbar[$item_name]['g'] = $data_top[$i]; + if ($show_graph == 0 || $show_graph == 1) { + $data = array(); + $data[0] = $an; + $data[1] = $module_name[$i]; + $data[2] = format_for_graph($data_top[$i],2) . " " . $units[$i]; + array_push ($table1->data, $data); + } + $i++; + if ($i >= $top_n_value) break; + } + } + + unset($data); + $table->colspan[2][0] = 3; + $table->style[2] = 'text-align:center'; + if ($show_graph == 0 || $show_graph == 1) { + $data = array(); + $data[0] = html_print_table($table1, true); + array_push ($table->data, $data); + } + + $table->colspan[3][0] = 3; + $data = array(); + if ($show_graph != REPORT_TOP_N_ONLY_TABLE) { + + $data[0] = pie3d_graph(false, $data_pie_graph, + $sizgraph_w, $sizgraph_h, __("other"), + ui_get_full_url(false, true, false, false) . '/', + ui_get_full_url(false, false, false, false) . "/images/logo_vertical_water.png", + $config['fontpath'], $config['font_size']); + + + array_push ($table->data, $data); + //Display bars graph + $table->colspan[4][0] = 3; + $table->style[0] .= 'text-align:center'; + $height = count($data_pie_graph)*20+35; + $data = array(); + $data[0] = hbar_graph(false, $data_hbar, $sizgraph_w, + $height, array(), array(), "", "", true, + ui_get_full_url(false, true, false, false) . '/', $config['homedir'] . "/images/logo_vertical_water.png", $config['fontpath'], $config['font_size'], true, 1, true); + + array_push ($table->data, $data); + } + + if ($content['show_resume'] && count($data_top_values) > 0) { + //Get the very first not null value + $i=0; + do { + $min = $data_top_values['data_top'][$i]; + $i++; + } + while ($min === false && $i < count($data_top_values)); + $max = $min; + $avg = 0; + + $i=0; + foreach ($data_top_values['data_top'] as $key => $dtv) { + if ($dtv < $min) $min = $dtv; + if ($dtv > $max) $max = $dtv; + $avg += $dtv; + $i++; + } + $avg = $avg / $i; + + unset($table_summary); + + $table_summary->width = '99%'; + $table_summary->data = array (); + $table_summary->head = array (); + $table_summary->head[0] = __('Min Value'); + $table_summary->head[1] = __('Average Value'); + $table_summary->head[2] = __('Max Value'); + + $table_summary->data[0][0] = format_for_graph($min, 2); + $table_summary->data[0][1] = format_for_graph($avg, 2); + $table_summary->data[0][2] = format_for_graph($max, 2); + + $table->colspan[5][0] = 3; + array_push ($table->data, array(''.__('Summary').'')); + $table->colspan[6][0] = 3; + array_push ($table->data, array(html_print_table($table_summary, true))); + } + break; + case 'exception': + $order_uptodown = $content['order_uptodown']; + $exception_condition = $content['exception_condition']; + $exception_condition_value = $content['exception_condition_value']; + $show_graph = $content['show_graph']; + + $table->style[1] = 'text-align: right'; + + switch ($exception_condition) { + case REPORT_EXCEPTION_CONDITION_EVERYTHING: + $title_exeption = __('Exception - Everything'); + break; + case REPORT_EXCEPTION_CONDITION_GE: + $title_exeption = + sprintf(__('Exception - Modules over or equal to %s'), + $exception_condition_value); + break; + case REPORT_EXCEPTION_CONDITION_LE: + $title_exeption = + sprintf(__('Exception - Modules under or equal to %s'), + $exception_condition_value); + break; + case REPORT_EXCEPTION_CONDITION_L: + $title_exeption = + sprintf(__('Exception - Modules under %s'), + $exception_condition_value); + break; + case REPORT_EXCEPTION_CONDITION_G: + $title_exeption = + sprintf(__('Exception - Modules over %s'), + $exception_condition_value); + break; + case REPORT_EXCEPTION_CONDITION_E: + $title_exeption = + sprintf(__('Exception - Equal to %s'), + $exception_condition_value); + break; + case REPORT_EXCEPTION_CONDITION_NE: + $title_exeption = + sprintf(__('Exception - Not equal to %s'), + $exception_condition_value); + break; + case REPORT_EXCEPTION_CONDITION_OK: + $title_exeption = + __('Exception - Modules at normal status'); + break; + case REPORT_EXCEPTION_CONDITION_NOT_OK: + $title_exeption = + __('Exception - Modules at critical or warning status'); + break; + } + + if (empty($item_title)) { + $item_title = $title_exeption; + } + reporting_header_content($mini, $content, $report, $table, $item_title); + + // Put description at the end of the module (if exists) + $table->colspan[1][0] = 3; + if ($content["description"] != "") { + $data_desc = array(); + $data_desc[0] = $content["description"]; + array_push ($table->data, $data_desc); + } + //Get all the related data + $sql = sprintf(" + SELECT id_agent_module, server_name, operation + FROM treport_content_item + WHERE id_report_content = %d", $content['id_rc']); + + $exceptions = db_process_sql ($sql); + if ($exceptions === false) { + $data = array (); + $table->colspan[2][0] = 3; + $data[0] = __('There are no Agent/Modules defined'); + array_push ($table->data, $data); + break; + } + + if ($show_graph == 0 || $show_graph == 1) { + $table1->width = '99%'; + $table1->data = array (); + $table1->head = array (); + $table1->head[0] = __('Agent'); + $table1->head[1] = __('Module'); + $table1->head[2] = __('Operation'); + $table1->head[3] = __('Value'); + $table1->style[0] = 'text-align: left'; + $table1->style[1] = 'text-align: left'; + $table1->style[2] = 'text-align: left'; + $table1->style[3] = 'text-align: left'; + } + + //Get the very first not null value + $i=0; + do { + //Metaconsole connection + $server_name = $exceptions[$i]['server_name']; + if (($config ['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE')) { + $connection = metaconsole_get_connection($server_name); + if (metaconsole_load_external_db($connection) != NOERR) { + //ui_print_error_message ("Error connecting to ".$server_name); + continue; + } + } + + if ($content['period'] == 0) { + $min = + modules_get_last_value($exceptions[$i]['id_agent_module']); + } + else { + switch ($exceptions[$i]['operation']) { + case 'avg': + $min = reporting_get_agentmodule_data_average( + $exceptions[$i]['id_agent_module'], $content['period']); + break; + case 'max': + $min = reporting_get_agentmodule_data_max( + $exceptions[$i]['id_agent_module'], $content['period']); + break; + case 'min': + $min = reporting_get_agentmodule_data_min( + $exceptions[$i]['id_agent_module'], $content['period']); + break; + } + } + $i++; + + //Restore dbconnection + if (($config ['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE')) { + metaconsole_restore_db(); + } + } + while ($min === false && $i < count($exceptions)); + $max = $min; + $avg = 0; + + $i=0; + foreach ($exceptions as $exc) { + //Metaconsole connection + $server_name = $exc['server_name']; + if (($config ['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE')) { + $connection = metaconsole_get_connection($server_name); + if (metaconsole_load_external_db($connection) != NOERR) { + //ui_print_error_message ("Error connecting to ".$server_name); + continue; + } + } + + $ag_name = modules_get_agentmodule_agent_name ($exc ['id_agent_module']); + $mod_name = modules_get_agentmodule_name ($exc ['id_agent_module']); + $unit = db_get_value('unit', 'tagente_modulo', + 'id_agente_modulo', $exc['id_agent_module']); + + if ($content['period'] == 0) { + $value = + modules_get_last_value($exceptions[$i]['id_agent_module']); + } + else { + switch ($exc['operation']) { + case 'avg': + $value = reporting_get_agentmodule_data_average ($exc['id_agent_module'], $content['period']); + break; + case 'max': + $value = reporting_get_agentmodule_data_max ($exc['id_agent_module'], $content['period']); + break; + case 'min': + $value = reporting_get_agentmodule_data_min ($exc['id_agent_module'], $content['period']); + break; + } + } + + if ($value !== false) { + if ($value > $max) $max = $value; + if ($value < $min) $min = $value; + $avg += $value; + + //Skips + switch ($exception_condition) { + case REPORT_EXCEPTION_CONDITION_EVERYTHING: + break; + case REPORT_EXCEPTION_CONDITION_GE: + if ($value < $exception_condition_value) { + continue 2; + } + break; + case REPORT_EXCEPTION_CONDITION_LE: + if ($value > $exception_condition_value) { + continue 2; + } + break; + case REPORT_EXCEPTION_CONDITION_L: + if ($value > $exception_condition_value) { + continue 2; + } + break; + case REPORT_EXCEPTION_CONDITION_G: + if ($value < $exception_condition_value) { + continue 2; + } + break; + case REPORT_EXCEPTION_CONDITION_E: + if ($value != $exception_condition_value) { + continue 2; + } + break; + case REPORT_EXCEPTION_CONDITION_NE: + if ($value == $exception_condition_value) { + continue 2; + } + break; + case REPORT_EXCEPTION_CONDITION_OK: + if (modules_get_agentmodule_status($exc['id_agent_module']) != 0) { + continue 2; + } + break; + case REPORT_EXCEPTION_CONDITION_NOT_OK: + if (modules_get_agentmodule_status($exc['id_agent_module']) == 0) { + continue 2; + } + break; + } + + $i++; + $data_exceptions[] = $value; + $id_agent_module[] = $exc['id_agent_module']; + $agent_name[] = $ag_name; + $module_name[] = $mod_name; + $units[] = $unit; + if ($exc['operation'] == 'avg') { + $operation[] = "rate"; + } + else { + $operation[] = $exc['operation']; + } + } + //Restore dbconnection + if (($config ['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE')) { + metaconsole_restore_db(); + } + } + + //$i <= 0 means that there are no rows on the table, therefore no modules under the conditions defined. + if ($i <= 0) { + $data = array (); + $table->colspan[2][0] = 3; + $data[0] = __('There are no'); + + switch ($exception_condition) { + case REPORT_EXCEPTION_CONDITION_EVERYTHING: + $data[0] .= ' '.__('Modules under those conditions'); + break; + case REPORT_EXCEPTION_CONDITION_GE: + $data[0] .= ' '.__('Modules over or equal to').' '.$exception_condition_value; + break; + case REPORT_EXCEPTION_CONDITION_LE: + $data[0] .= ' '.__('Modules less or equal to').' '.$exception_condition_value; + break; + case REPORT_EXCEPTION_CONDITION_L: + $data[0] .= ' '.__('Modules less').' '.$exception_condition_value; + break; + case REPORT_EXCEPTION_CONDITION_G: + $data[0] .= ' '.__('Modules over').' '.$exception_condition_value; + break; + case REPORT_EXCEPTION_CONDITION_E: + $data[0] .= ' '.__('Modules equal to').' '.$exception_condition_value; + break; + case REPORT_EXCEPTION_CONDITION_NE: + $data[0] .= ' '.__('Modules not equal to').' '.$exception_condition_value; + break; + case REPORT_EXCEPTION_CONDITION_OK: + $data[0] .= ' '.__('Modules normal status'); + break; + case REPORT_EXCEPTION_CONDITION_NOT_OK: + $data[0] .= ' '.__('Modules at critial or warning status'); + break; + } + + + array_push ($table->data, $data); + break; + } + //$i > 0 means that there is at least one row on the table + elseif ($i > 0) { + $avg = $avg / $i; + + switch ($order_uptodown) { + //Order descending + case 1: + array_multisort($data_exceptions, SORT_DESC, $agent_name, SORT_ASC, $module_name, SORT_ASC, $id_agent_module, SORT_ASC); + break; + //Order ascending + case 2: + array_multisort($data_exceptions, SORT_ASC, $agent_name, SORT_ASC, $module_name, SORT_ASC, $id_agent_module, SORT_ASC); + break; + //Order by agent name or without selection + case 0: + case 3: + array_multisort($agent_name, SORT_ASC, $data_exceptions, SORT_ASC, $module_name, SORT_ASC, $id_agent_module, SORT_ASC); + break; + } + + if ($order_uptodown == 1 || $order_uptodown == 2) { + $j = 0; + $data_pie_graph = array(); + $data_hbar = array(); + foreach ($data_exceptions as $dex) { + $data_hbar[$agent_name[$j]]['g'] = $dex; + $data_pie_graph[$agent_name[$j]] = $dex; + if ($show_graph == 0 || $show_graph == 1) { + $data = array(); + $data[0] = $agent_name[$j]; + $data[1] = $module_name[$j]; + $data[2] = __($operation[$j]); + $data[3] = format_for_graph($dex, 2) . " " . $units[$j]; + array_push ($table1->data, $data); + } + $j++; + } + } + else if ($order_uptodown == 0 || $order_uptodown == 3) { + $j = 0; + $data_pie_graph = array(); + $data_hbar = array(); + foreach ($agent_name as $an) { + $data_hbar[$an]['g'] = $data_exceptions[$j]; + $data_pie_graph[$an] = $data_exceptions[$j]; + if ($show_graph == 0 || $show_graph == 1) { + $data = array(); + $data[0] = $an; + $data[1] = $module_name[$j]; + $data[2] = __($operation[$j]); + $data[3] = format_for_graph($data_exceptions[$j], 2) . " " . $units[$j]; + array_push ($table1->data, $data); + } + $j++; + } + } + } + + $table->colspan[2][0] = 3; + $table->cellstyle[2][0] = 'text-align: center;'; + if ($show_graph == 0 || $show_graph == 1) { + $data = array(); + $data[0] = html_print_table($table1, true); + array_push ($table->data, $data); + } + + $table->colspan[3][0] = 3; + $table->cellstyle[3][0] = 'text-align: center;'; + + $data = array(); + if ($show_graph == 1 || $show_graph == 2) { + $data[0] = pie3d_graph(false, $data_pie_graph, + 600, 150, __("other"), + ui_get_full_url(false, false, false, false), + ui_get_full_url(false, false, false, false) . "/images/logo_vertical_water.png", + $config['fontpath'], $config['font_size']); + array_push ($table->data, $data); + //Display bars graph + $table->colspan[4][0] = 3; + $table->cellstyle[4][0] = 'text-align: center;'; + $height = count($data_pie_graph) * 20 + 85; + $data = array(); + + $data[0] = hbar_graph(false, $data_hbar, 600, $height, + array(), array(), "", "", true, + ui_get_full_url(false, false, false, false), + ui_get_full_url(false, false, false, false) . "/images/logo_vertical_water.png", '', '', true, 1, true); + + array_push ($table->data, $data); + } + + if ($content['show_resume'] && $i>0) { + unset($table_summary); + + $table_summary->width = '99%'; + $table_summary->data = array (); + $table_summary->head = array (); + $table_summary->head[0] = __('Min Value'); + $table_summary->head[1] = __('Average Value'); + $table_summary->head[2] = __('Max Value'); + + $table_summary->data[0][0] = format_for_graph($min,2); + $table_summary->data[0][1] = format_for_graph($avg,2); + $table_summary->data[0][2] = format_for_graph($max,2); + + $table->colspan[5][0] = 3; + $table->cellstyle[5][0] = 'text-align: center;'; + array_push ($table->data, array(''.__('Summary').'')); + $table->colspan[6][0] = 3; + array_push ($table->data, array(html_print_table($table_summary, true))); + } + break; + case 'agent_module': + $group_name = groups_get_name($content['id_group']); + if ($content['id_module_group'] == 0) { + $module_group_name = __('All'); + } + else { + $module_group_name = db_get_value('name', 'tmodule_group', + 'id_mg', $content['id_module_group']); + } + + if (empty($item_title)) { + $item_title = __('Agents/Modules'); + } + reporting_header_content($mini, $content, $report, $table, $item_title, + $group_name . ' - ' . $module_group_name); + + $id_group = $content['id_group']; + $id_module_group = $content['id_module_group']; + $offset = get_parameter('offset', 0); + $block = 20; //Maximun number of modules displayed on the table + $modulegroup = get_parameter('modulegroup', 0); + $table->style[1] = 'text-align: right'; + + // Put description at the end of the module (if exists) + $table->colspan[1][0] = 3; + if ($content["description"] != "") { + $data_desc = array(); + $data_desc[0] = $content["description"]; + array_push ($table->data, $data_desc); + } + + $agents = ''; + if ($id_group > 0) { + $agents = agents_get_group_agents($id_group); + $agents = array_keys($agents); + } + + $filter_module_groups = false; + if ($id_module_group > 0) { + $filter_module_groups['id_module_group'] = $id_module_group; + } + + $all_modules = agents_get_modules ($agents, false, $filter_module_groups, true, false); + + $modules_by_name = array(); + $name = ''; + $cont = 0; + + foreach ($all_modules as $key => $module) { + if ($module == $name) { + $modules_by_name[$cont-1]['id'][] = $key; + } + else { + $name = $module; + $modules_by_name[$cont]['name'] = $name; + $modules_by_name[$cont]['id'][] = $key; + $cont ++; + } + } + + if ($config["pure"] == 1) { + $block = count($modules_by_name); + } + + $filter_groups = array ('offset' => (int) $offset, + 'limit' => (int) $config['block_size']); + + if ($id_group > 0) { + $filter_groups['id_grupo'] = $id_group; + } + + $agents = agents_get_agents ($filter_groups); + $nagents = count($agents); + + if ($all_modules == false || $agents == false) { + $data = array (); + $table->colspan[2][0] = 3; + $data[0] = __('There are no agents with modules'); + array_push ($table->data, $data); + break; + } + $table_data = ''; + + $table_data .= ""; + + $nmodules = 0; + foreach ($modules_by_name as $module) { + $nmodules++; + + $file_name = string2image(ui_print_truncate_text($module['name'], 'module_small', false, true, false, '...'), false, false, 6, 270, '#B1B1B1', 'FFF', 4, 0); + $table_data .= '"; + } + // Dont use pagination + /*if ($block < $nmodules) { + $table_data .= ""; + }*/ + + $filter_agents = false; + if ($id_group > 0) { + $filter_agents = array('id_grupo' => $id_group); + } + // Prepare pagination + ui_pagination ((int)count(agents_get_agents ($filter_agents))); + $table_data .= "
"; + + foreach ($agents as $agent) { + // Get stats for this group + $agent_status = agents_get_status($agent['id_agente']); + + switch($agent_status) { + case 4: // Alert fired status + $rowcolor = COL_ALERTFIRED; + $textcolor = '#000'; + break; + case 1: // Critical status + $rowcolor = COL_CRITICAL; + $textcolor = '#FFF'; + break; + case 2: // Warning status + $rowcolor = COL_WARNING; + $textcolor = '#000'; + break; + case 0: // Normal status + $rowcolor = COL_NORMAL; + $textcolor = '#FFF'; + break; + case 3: + case -1: + default: // Unknown status + $rowcolor = COL_UNKNOWN; + $textcolor = '#FFF'; + break; + } + + $table_data .= ""; + + $file_name = string2image(ui_print_truncate_text($agent['nombre'], 'agent_small', false, true, false, '...'), false, false, 6, 0, $rowcolor, $textcolor, 4, 0); + $table_data .= ""; + $agent_modules = agents_get_modules($agent['id_agente']); + + $nmodules = 0; + + foreach ($modules_by_name as $module) { + $nmodules++; + // Don't use pagination + /*if ($nmodules > $block) { + continue; + }*/ + + $match = false; + foreach($module['id'] as $module_id){ + if (!$match && array_key_exists($module_id,$agent_modules)) { + $status = modules_get_agentmodule_status($module_id); + $table_data .= ""; + $match = true; + } + } + + if (!$match) { + $table_data .= ""; + } + } + + $table_data .= ""; + } + + $table_data .= "
".__("Agents")." / ".__("Modules")."' . html_print_image($file_name, true, array('title' => $module['name']))."...
".html_print_image($file_name, true, array('title' => $agent['nombre'])).""; + $win_handle = dechex(crc32($module_id.$module["name"])); + $graph_type = return_graphtype (modules_get_agentmodule_type($module_id)); + + switch ($status) { + case 0: + $table_data .= ui_print_status_image ('module_ok.png', $module['name']." in ".$agent['nombre'].": ".__('NORMAL'), true, array('width' => '20px', 'height' => '20px')); + break; + case 1: + $table_data .= ui_print_status_image ('module_critical.png', $module['name']." in ".$agent['nombre'].": ".__('CRITICAL'), true, array('width' => '20px', 'height' => '20px')); + break; + case 2: + $table_data .= ui_print_status_image ('module_warning.png', $module['name']." in ".$agent['nombre'].": ".__('WARNING'), true, array('width' => '20px', 'height' => '20px')); + break; + case 3: + $table_data .= ui_print_status_image ('module_unknown.png', $module['name']." in ".$agent['nombre'].": ".__('UNKNOWN'), true, array('width' => '20px', 'height' => '20px')); + break; + case 4: + $table_data .= ui_print_status_image ('module_alertsfired.png', $module['name']." in ".$agent['nombre'].": ".__('ALERTS FIRED'), true, array('width' => '20px', 'height' => '20px')); + break; + } + $table_data .= "
"; + + $table_data .= "
"; + + $table_data .= ""; + $table_data .= ""; + $table_data .= ""; + $table_data .= ""; + $table_data .= ""; + $table_data .= ""; + $table_data .= ""; + $table_data .= "
" . __('Legend') . "
" . __("Orange cell when the module has fired alerts") . "
" . __("Red cell when the module has a critical status") . "
" . __("Yellow cell when the module has a warning status") . "
" . __("Green cell when the module has a normal status") . "
" . __("Grey cell when the module has an unknown status") . "
"; + $table_data .= "
"; + $data = array (); + $table->colspan[2][0] = 3; + $data[0] = $table_data; + array_push ($table->data, $data); + break; + case 'inventory': + if (empty($item_title)) { + $item_title = __('Inventory'); + } + reporting_header_content($mini, $content, $report, $table, $item_title); + + $es = json_decode($content['external_source'], true); + + $id_agent = $es['id_agents']; + $module_name = $es['inventory_modules']; + if (empty($module_name)) { + $module_name = array(0 => 0); + } + $date = $es['date']; + $description = $content['description']; + + $data = array (); + $table->colspan[1][0] = 2; + $table->colspan[2][0] = 2; + if ($description != '') { + $data[0] = $description; + array_push ($table->data, $data); + } + + $inventory_data = inventory_get_data((array)$id_agent,(array)$module_name,$date,'',false); + + if ($inventory_data == ERR_NODATA) { + $inventory_data = "
".__('No data found.')."
"; + $inventory_data .= " "; + } + + $data[0] = $inventory_data; + array_push ($table->data, $data); + break; + case 'inventory_changes': + if (empty($item_title)) { + $item_title = __('Inventory changes'); + } + reporting_header_content($mini, $content, $report, $table, $item_title); + + $es = json_decode($content['external_source'], true); + + $id_agent = $es['id_agents']; + $module_name = $es['inventory_modules']; + $description = $content['description']; + + $inventory_changes = inventory_get_changes($id_agent, $module_name, $report["datetime"] - $content['period'], $report["datetime"]); + + if ($inventory_changes == ERR_NODATA) { + $inventory_changes = "
".__('No changes found.')."
"; + $inventory_changes .= " "; + } + + $data = array (); + + $table->colspan[1][0] = 2; + + if ($description != '') { + $data[0] = $description; + array_push ($table->data, $data); + } + + $data[0] = $inventory_changes; + $table->colspan[2][0] = 2; + + array_push ($table->data, $data); + break; + case 'agent_configuration': + + if (empty($item_title)) { + $item_title = __('Agent configuration: ').$agent_name; + } + reporting_header_content($mini, $content, $report, $table, $item_title); + + $agent_name = agents_get_name ($content['id_agent']); + $modules = agents_get_modules ($content['id_agent']); + + $data= array (); + $table->colspan[0][1] = 10; + + //Agent's data + $data[0] = ''.__('Agent name').''; + $data[1] = ''.__('Group').''; + $data[2] = ''.__('SO').''; + $data[3] = ''.__('IP').''; + $data[4] = ''.__('Description').''; + $data[5] = ''.__('Status').''; + + $table->colspan[1][3] = 2; + $table->colspan[1][4] = 4; + $table->colspan[1][5] = 2; + $table->colspan[1][5] = 2; + array_push ($table->data, $data); + unset($data); + + $sql = "SELECT * FROM tagente WHERE id_agente=".$content['id_agent']; + $agent_data = db_get_row_sql($sql); + + $data[0] = $agent_data['nombre']; + $data[1] = ui_print_group_icon ($agent_data['id_grupo'], true, '', '', false); + $data[2] = ui_print_os_icon ($agent_data["id_os"], true, true); + $data[3] = $agent_data['direccion']; + $agent_data_comentarios = strip_tags(ui_bbcode_to_html($agent_data['comentarios'])); + $data[4] = $agent_data_comentarios; + + if ($agent_data['disabled'] == 0) + $data[5] = __('Enabled'); + else + $data[5] = __('Disabled'); + + $table->colspan[2][3] = 2; + $table->colspan[2][4] = 4; + $table->colspan[2][5] = 2; + array_push ($table->data, $data); + unset($data); + + //Agent's modules + if ($modules == null) { + $modules = array(); + } + else { + $data[0] = ''; + $data[1] = ''.agents_get_name ($content['id_agent'], 'upper').__(' MODULES').''; + $table->colspan[3][1] = 10; + + array_push ($table->data, $data); + unset($data); + + $data[0] = ''; + $data[1] = ''.__('Name').''; + $data[2] = ''.__('Type').''; + $data[3] = ''.__('Warning').'/'.'
'.__('Critical').'
'; + $data[4] = ''.__('Threshold').''; + $data[5] = ''.__('Group').''; + $data[6] = ''.__('Description').''; + $data[7] = ''.__('Interval').''; + $data[8] = ''.__('Unit').''; + $data[9] = ''.__('Status').''; + $data[10] = ''.__('Tags').''; + + $table->style[0] = 'width:10px'; + $table->style[1] = 'text-align: left'; + $table->style[2] = 'text-align: center'; + $table->style[3] = 'text-align: center'; + $table->style[4] = 'text-align: center'; + $table->style[5] = 'text-align: center'; + $table->style[6] = 'text-align: left'; + $table->style[7] = 'text-align: center'; + $table->style[8] = 'text-align: center'; + $table->style[9] = 'text-align: left'; + $table->style[10] = 'text-align: left'; + + array_push ($table->data, $data); + } + + foreach ($modules as $id_agent_module=>$module) { + $sql = "SELECT * FROM tagente_modulo WHERE id_agente_modulo=$id_agent_module"; + $data_module = db_get_row_sql($sql); + + $data = array(); + + $data[0] = ''; + + if ($data_module['disabled'] == 0) + $disabled = ''; + else + $disabled = ' (Disabled)'; + $data[1] = $data_module['nombre'].$disabled; + $data[2] = ui_print_moduletype_icon ($data_module['id_tipo_modulo'], true); + $data[3] = $data_module['max_warning'].'/'.$data_module['min_warning'].'
'.$data_module['max_critical'].'/'.$data_module['min_critical']; + $data[4] = $data_module['module_ff_interval']; + $data[5] = groups_get_name ($content['id_group'], true); + $data[6] = $data_module['descripcion']; + + if (($data_module['module_interval'] == 0) || ($data_module['module_interval'] == '')) + $data[7] = db_get_value('intervalo', 'tagente', 'id_agente', $content['id_agent']); + else + $data[7] = $data_module['module_interval']; + + + $data[8] = $data_module['unit']; + + $module_status = db_get_row('tagente_estado', 'id_agente_modulo', $id_agent_module); + modules_get_status($id_agent_module, $module_status['estado'], $module_status['datos'], $status, $title); + $data[9] = ui_print_status_image($status, $title, true); + + $sql_tag = "SELECT name + FROM ttag + WHERE id_tag IN ( + SELECT id_tag + FROM ttag_module + WHERE id_agente_modulo = $id_agent_module)"; + $tags = db_get_all_rows_sql($sql_tag); + if ($tags === false) + $tags = ''; + else + $tags = implode (",", $tags); + + $data[10] = $tags; + array_push ($table->data, $data); + } + + break; + case 'group_configuration': + $group_name = groups_get_name($content['id_group']); + if (empty($item_title)) { + $item_title = __('Group configuration: ').$group_name; + } + reporting_header_content($mini, $content, $report, $table, $item_title); + + $sql = "SELECT * FROM tagente WHERE id_grupo=".$content['id_group']; + $agents_list = db_get_all_rows_sql($sql); + if ($agents_list === false) + $agents_list = array(); + + $table->colspan[0][1] = 10; + + $i = 1; + foreach ($agents_list as $agent) { + $data= array (); + + $table->colspan[$i][3] = 2; + $table->colspan[$i][4] = 4; + $table->colspan[$i][5] = 2; + $table->colspan[$i][5] = 2; + + $i++; + + //Agent's data + $data[0] = ''.__('Agent name').''; + $data[1] = ''.__('Group').''; + $data[2] = ''.__('SO').''; + $data[3] = ''.__('IP').''; + $data[4] = ''.__('Description').''; + $data[5] = ''.__('Status').''; + + array_push ($table->data, $data); + unset($data); + + $sql = "SELECT * FROM tagente WHERE id_agente=".$agent['id_agente']; + $agent_data = db_get_row_sql($sql); + + $data[0] = $agent_data['nombre']; + $data[1] = ui_print_group_icon ($agent_data['id_grupo'], true, '', '', false); + $data[2] = ui_print_os_icon ($agent_data["id_os"], true, true); + $data[3] = $agent_data['direccion']; + $agent_data_comentarios = strip_tags(ui_bbcode_to_html($agent_data['comentarios'])); + $data[4] = $agent_data_comentarios; + + if ($agent_data['disabled'] == 0) + $data[5] = __('Enabled'); + else + $data[5] = __('Disabled'); + + $table->colspan[$i][3] = 2; + $table->colspan[$i][4] = 4; + $table->colspan[$i][5] = 2; + $table->colspan[$i][5] = 2; + + $i++; + + array_push ($table->data, $data); + unset($data); + + + + $modules = agents_get_modules ($agent['id_agente']); + + if ($modules == null) { + $modules = array(); + } + else { + + //Agent's modules + $data[0] = ''; + $data[1] = ''.agents_get_name ($agent['id_agente'], 'upper').__(' MODULES').''; + $table->colspan[$i][1] = 10; + + $i++; + + array_push ($table->data, $data); + unset($data); + + $data[0] = ''; + $data[1] = ''.__('Name').''; + $data[2] = ''.__('Type').''; + $data[3] = ''.__('Warning').'/'.'
'.__('Critical').'
'; + $data[4] = ''.__('Threshold').''; + $data[5] = ''.__('Group').''; + $data[6] = ''.__('Description').''; + $data[7] = ''.__('Interval').''; + $data[8] = ''.__('Unit').''; + $data[9] = ''.__('Status').''; + $data[10] = ''.__('Tags').''; + + $table->style[0] = 'width:10px'; + $table->style[1] = 'text-align: left'; + $table->style[2] = 'text-align: center'; + $table->style[3] = 'text-align: center'; + $table->style[4] = 'text-align: center'; + $table->style[5] = 'text-align: center'; + $table->style[6] = 'text-align: left'; + $table->style[7] = 'text-align: center'; + $table->style[8] = 'text-align: center'; + $table->style[9] = 'text-align: left'; + $table->style[10] = 'text-align: left'; + + array_push ($table->data, $data); + + $i++; + } + + foreach ($modules as $id_agent_module=>$module) { + $sql = "SELECT * + FROM tagente_modulo + WHERE id_agente_modulo=$id_agent_module"; + $data_module = db_get_row_sql($sql); + + $data = array(); + + $data[0] = ''; + + if ($data_module['disabled'] == 0) + $disabled = ''; + else + $disabled = ' (Disabled)'; + $data[1] = $data_module['nombre'].$disabled; + $data[2] = ui_print_moduletype_icon ($data_module['id_tipo_modulo'], true); + $data[3] = $data_module['max_warning'].'/'.$data_module['min_warning'].'
'.$data_module['max_critical'].'/'.$data_module['min_critical']; + $data[4] = $data_module['module_ff_interval']; + $data[5] = groups_get_name ($content['id_group'], true); + $data[6] = $data_module['descripcion']; + + if (($data_module['module_interval'] == 0) || ($data_module['module_interval'] == '')) + $data[7] = db_get_value('intervalo', 'tagente', 'id_agente', $content['id_agent']); + else + $data[7] = $data_module['module_interval']; + + + $data[8] = $data_module['unit']; + + $module_status = db_get_row('tagente_estado', 'id_agente_modulo', $id_agent_module); + modules_get_status($id_agent_module, $module_status['estado'], $module_status['datos'], $status, $title); + $data[9] = ui_print_status_image($status, $title, true); + + $sql_tag = "SELECT name + FROM ttag + WHERE id_tag IN ( + SELECT id_tag + FROM ttag_module + WHERE id_agente_modulo = $id_agent_module)"; + $tags = db_get_all_rows_sql($sql_tag); + if ($tags === false) + $tags = ''; + else + $tags = implode (",", $tags); + + $data[10] = $tags; + array_push ($table->data, $data); + + $i++; + } + + } + break; + case 'netflow_area': + case 'netflow_pie': + case 'netflow_data': + case 'netflow_statistics': + case 'netflow_summary': + + // Read the report item + $report_id = $report['id_report']; + $content_id = $content['id_rc']; + $max_aggregates= $content['top_n_value']; + $type = $content['show_graph']; + $description = $content['description']; + $resolution = $content['top_n']; + $type = $content['type']; + $period = $content['period']; + + // Calculate the start and end dates + $end_date = $report['datetime']; + $start_date = $end_date - $period; + + // Get item filters + $filter = db_get_row_sql("SELECT * + FROM tnetflow_filter + WHERE id_sg = '" . (int)$content['text'] . "'", false, true); + if ($description == '') { + $description = $filter['id_name']; + } + + if (empty($item_title)) { + $item_title = $description; + } + + $table->colspan[0][0] = 4; + $table->data[0][0] = '

' . $item_title . '

'; + $table->colspan[1][0] = 4; + $table->data[1][0] = netflow_draw_item ($start_date, $end_date, $resolution, $type, $filter, $max_aggregates, $server_name, 'HTML'); + break; + } + //Restore dbconnection + if (($config ['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE') && $remote_connection == 1) { + metaconsole_restore_db_force(); + } +} + +/** + * Get the MTBF value of an agent module in a period of time. See + * http://en.wikipedia.org/wiki/Mean_time_between_failures + * + * @param int Agent module id + * @param int Period of time to check (in seconds) + * @param int Top date to check the values. Default current time. + * + * @return float The MTBF value in the interval. + */ +function reporting_get_agentmodule_mtbf ($id_agent_module, $period = 0, $date = 0) { + + // Initialize variables + if (empty ($date)) $date = get_system_time (); + + // Read module configuration + $datelimit = $date - $period; + $search_in_history_db = db_search_in_history_db($datelimit); + + $module = db_get_row_sql ('SELECT max_critical, min_critical, id_tipo_modulo + FROM tagente_modulo + WHERE id_agente_modulo = ' . (int) $id_agent_module); + if ($module === false) { + return false; + } + + $critical_min = $module['min_critical']; + $critical_max = $module['max_critical']; + $module_type = $module['id_tipo_modulo']; + + // Set critical_min and critical for proc modules + $module_type_str = modules_get_type_name ($module_type); + if (strstr ($module_type_str, 'proc') !== false && + ($critical_min == 0 && $critical_max == 0)) { + $critical_min = 1; + } + + // Get module data + $interval_data = db_get_all_rows_sql ('SELECT * FROM tagente_datos + WHERE id_agente_modulo = ' . (int) $id_agent_module . + ' AND utimestamp > ' . (int) $datelimit . + ' AND utimestamp < ' . (int) $date . + ' ORDER BY utimestamp ASC', $search_in_history_db); + if ($interval_data === false) $interval_data = array (); + + // Get previous data + $previous_data = modules_get_previous_data ($id_agent_module, $datelimit); + if ($previous_data !== false) { + $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) { + $next_data['utimestamp'] = $date; + array_push ($interval_data, $next_data); + } + else if (count ($interval_data) > 0) { + // Propagate the last known data to the end of the interval + $next_data = array_pop ($interval_data); + array_push ($interval_data, $next_data); + $next_data['utimestamp'] = $date; + array_push ($interval_data, $next_data); + } + + if (count ($interval_data) < 2) { + return false; + } + + // Set initial conditions + $critical_period = 0; + $first_data = array_shift ($interval_data); + $previous_utimestamp = $first_data['utimestamp']; + if ((($critical_max > $critical_min AND ($first_data['datos'] > $critical_max OR $first_data['datos'] < $critical_min))) OR + ($critical_max <= $critical_min AND $first_data['datos'] < $critical_min)) { + $previous_status = 1; + $critical_count = 1; + } + else { + $previous_status = 0; + $critical_count = 0; + } + + foreach ($interval_data as $data) { + // Previous status was critical + if ($previous_status == 1) { + $critical_period += $data['utimestamp'] - $previous_utimestamp; + } + + // Re-calculate previous status for the next data + if ((($critical_max > $critical_min AND ($data['datos'] > $critical_max OR $data['datos'] < $critical_min))) OR + ($critical_max <= $critical_min AND $data['datos'] < $critical_min)) { + if ($previous_status == 0) { + $critical_count++; + } + $previous_status = 1; + } + else { + $previous_status = 0; + } + + $previous_utimestamp = $data['utimestamp']; + } + + if ($critical_count == 0) { + return 0; + } + + return ($period - $critical_period) / $critical_count; +} + +/** + * Get the MTTR value of an agent module in a period of time. See + * http://en.wikipedia.org/wiki/Mean_time_to_recovery + * + * @param int Agent module id + * @param int Period of time to check (in seconds) + * @param int Top date to check the values. Default current time. + * + * @return float The MTTR value in the interval. + */ +function reporting_get_agentmodule_mttr ($id_agent_module, $period = 0, $date = 0) { + + // Initialize variables + if (empty ($date)) $date = get_system_time (); + + // Read module configuration + $datelimit = $date - $period; + $search_in_history_db = db_search_in_history_db($datelimit); + + $module = db_get_row_sql ('SELECT max_critical, min_critical, id_tipo_modulo + FROM tagente_modulo + WHERE id_agente_modulo = ' . (int) $id_agent_module); + if ($module === false) { + return false; + } + + $critical_min = $module['min_critical']; + $critical_max = $module['max_critical']; + $module_type = $module['id_tipo_modulo']; + + // Set critical_min and critical for proc modules + $module_type_str = modules_get_type_name ($module_type); + if (strstr ($module_type_str, 'proc') !== false && + ($critical_min == 0 && $critical_max == 0)) { + $critical_min = 1; + } + + // Get module data + $interval_data = db_get_all_rows_sql ('SELECT * FROM tagente_datos + WHERE id_agente_modulo = ' . (int) $id_agent_module . + ' AND utimestamp > ' . (int) $datelimit . + ' AND utimestamp < ' . (int) $date . + ' ORDER BY utimestamp ASC', $search_in_history_db); + if ($interval_data === false) $interval_data = array (); + + // Get previous data + $previous_data = modules_get_previous_data ($id_agent_module, $datelimit); + if ($previous_data !== false) { + $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) { + $next_data['utimestamp'] = $date; + array_push ($interval_data, $next_data); + } + else if (count ($interval_data) > 0) { + // Propagate the last known data to the end of the interval + $next_data = array_pop ($interval_data); + array_push ($interval_data, $next_data); + $next_data['utimestamp'] = $date; + array_push ($interval_data, $next_data); + } + + if (count ($interval_data) < 2) { + return false; + } + + // Set initial conditions + $critical_period = 0; + $first_data = array_shift ($interval_data); + $previous_utimestamp = $first_data['utimestamp']; + if ((($critical_max > $critical_min AND ($first_data['datos'] > $critical_max OR $first_data['datos'] < $critical_min))) OR + ($critical_max <= $critical_min AND $first_data['datos'] < $critical_min)) { + $previous_status = 1; + $critical_count = 1; + } + else { + $previous_status = 0; + $critical_count = 0; + } + + foreach ($interval_data as $data) { + // Previous status was critical + if ($previous_status == 1) { + $critical_period += $data['utimestamp'] - $previous_utimestamp; + } + + // Re-calculate previous status for the next data + if ((($critical_max > $critical_min AND ($data['datos'] > $critical_max OR $data['datos'] < $critical_min))) OR + ($critical_max <= $critical_min AND $data['datos'] < $critical_min)) { + if ($previous_status == 0) { + $critical_count++; + } + $previous_status = 1; + } + else { + $previous_status = 0; + } + + $previous_utimestamp = $data['utimestamp']; + } + + if ($critical_count == 0) { + return 0; + } + + return $critical_period / $critical_count; +} + +/** + * Get the TTO value of an agent module in a period of time. + * + * @param int Agent module id + * @param int Period of time to check (in seconds) + * @param int Top date to check the values. Default current time. + * + * @return float The TTO value in the interval. + */ +function reporting_get_agentmodule_tto ($id_agent_module, $period = 0, $date = 0) { + + // Initialize variables + if (empty ($date)) $date = get_system_time (); + + // Read module configuration + $datelimit = $date - $period; + $search_in_history_db = db_search_in_history_db($datelimit); + + $module = db_get_row_sql ('SELECT max_critical, min_critical, id_tipo_modulo + FROM tagente_modulo + WHERE id_agente_modulo = ' . (int) $id_agent_module); + if ($module === false) { + return false; + } + + $critical_min = $module['min_critical']; + $critical_max = $module['max_critical']; + $module_type = $module['id_tipo_modulo']; + + // Set critical_min and critical for proc modules + $module_type_str = modules_get_type_name ($module_type); + if (strstr ($module_type_str, 'proc') !== false && + ($critical_min == 0 && $critical_max == 0)) { + $critical_min = 1; + } + + // Get module data + $interval_data = db_get_all_rows_sql ('SELECT * FROM tagente_datos + WHERE id_agente_modulo = ' . (int) $id_agent_module . + ' AND utimestamp > ' . (int) $datelimit . + ' AND utimestamp < ' . (int) $date . + ' ORDER BY utimestamp ASC', $search_in_history_db); + if ($interval_data === false) $interval_data = array (); + + // Get previous data + $previous_data = modules_get_previous_data ($id_agent_module, $datelimit); + if ($previous_data !== false) { + $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) { + $next_data['utimestamp'] = $date; + array_push ($interval_data, $next_data); + } + else if (count ($interval_data) > 0) { + // Propagate the last known data to the end of the interval + $next_data = array_pop ($interval_data); + array_push ($interval_data, $next_data); + $next_data['utimestamp'] = $date; + array_push ($interval_data, $next_data); + } + + if (count ($interval_data) < 2) { + return false; + } + + // Set initial conditions + $critical_period = 0; + $first_data = array_shift ($interval_data); + $previous_utimestamp = $first_data['utimestamp']; + if ((($critical_max > $critical_min AND ($first_data['datos'] > $critical_max OR $first_data['datos'] < $critical_min))) OR + ($critical_max <= $critical_min AND $first_data['datos'] < $critical_min)) { + $previous_status = 1; + } + else { + $previous_status = 0; + } + + foreach ($interval_data as $data) { + // Previous status was critical + if ($previous_status == 1) { + $critical_period += $data['utimestamp'] - $previous_utimestamp; + } + + // Re-calculate previous status for the next data + if ((($critical_max > $critical_min AND ($data['datos'] > $critical_max OR $data['datos'] < $critical_min))) OR + ($critical_max <= $critical_min AND $data['datos'] < $critical_min)) { + $previous_status = 1; + } + else { + $previous_status = 0; + } + + $previous_utimestamp = $data['utimestamp']; + } + + return $period - $critical_period; +} + +/** + * Get the TTR value of an agent module in a period of time. + * + * @param int Agent module id + * @param int Period of time to check (in seconds) + * @param int Top date to check the values. Default current time. + * + * @return float The TTR value in the interval. + */ +function reporting_get_agentmodule_ttr ($id_agent_module, $period = 0, $date = 0) { + + // Initialize variables + if (empty ($date)) $date = get_system_time (); + + // Read module configuration + $datelimit = $date - $period; + $search_in_history_db = db_search_in_history_db($datelimit); + + $module = db_get_row_sql ('SELECT max_critical, min_critical, id_tipo_modulo + FROM tagente_modulo + WHERE id_agente_modulo = ' . (int) $id_agent_module); + if ($module === false) { + return false; + } + + $critical_min = $module['min_critical']; + $critical_max = $module['max_critical']; + $module_type = $module['id_tipo_modulo']; + + // Set critical_min and critical for proc modules + $module_type_str = modules_get_type_name ($module_type); + if (strstr ($module_type_str, 'proc') !== false && + ($critical_min == 0 && $critical_max == 0)) { + $critical_min = 1; + } + + // Get module data + $interval_data = db_get_all_rows_sql ('SELECT * FROM tagente_datos + WHERE id_agente_modulo = ' . (int) $id_agent_module . + ' AND utimestamp > ' . (int) $datelimit . + ' AND utimestamp < ' . (int) $date . + ' ORDER BY utimestamp ASC', $search_in_history_db); + if ($interval_data === false) $interval_data = array (); + + // Get previous data + $previous_data = modules_get_previous_data ($id_agent_module, $datelimit); + if ($previous_data !== false) { + $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) { + $next_data['utimestamp'] = $date; + array_push ($interval_data, $next_data); + } + else if (count ($interval_data) > 0) { + // Propagate the last known data to the end of the interval + $next_data = array_pop ($interval_data); + array_push ($interval_data, $next_data); + $next_data['utimestamp'] = $date; + array_push ($interval_data, $next_data); + } + + if (count ($interval_data) < 2) { + return false; + } + + // Set initial conditions + $critical_period = 0; + $first_data = array_shift ($interval_data); + $previous_utimestamp = $first_data['utimestamp']; + if ((($critical_max > $critical_min AND ($first_data['datos'] > $critical_max OR $first_data['datos'] < $critical_min))) OR + ($critical_max <= $critical_min AND $first_data['datos'] < $critical_min)) { + $previous_status = 1; + } + else { + $previous_status = 0; + } + + foreach ($interval_data as $data) { + // Previous status was critical + if ($previous_status == 1) { + $critical_period += $data['utimestamp'] - $previous_utimestamp; + } + + // Re-calculate previous status for the next data + if ((($critical_max > $critical_min AND ($data['datos'] > $critical_max OR $data['datos'] < $critical_min))) OR + ($critical_max <= $critical_min AND $data['datos'] < $critical_min)) { + $previous_status = 1; + } + else { + $previous_status = 0; + } + + $previous_utimestamp = $data['utimestamp']; + } + + return $critical_period; +} + +/** + * Get all the template graphs a user can see. + * + * @param $id_user User id to check. + * @param $only_names Wheter to return only graphs names in an associative array + * or all the values. + * @param $returnAllGroup Wheter to return graphs of group All or not. + * @param $privileges Privileges to check in user group + * + * @return template graphs of a an user. Empty array if none. + */ +function reporting_template_graphs_get_user ($id_user = 0, $only_names = false, $returnAllGroup = true, $privileges = 'RR') { + global $config; + + if (!$id_user) { + $id_user = $config['id_user']; + } + + $groups = users_get_groups ($id_user, $privileges, $returnAllGroup); + + $all_templates = db_get_all_rows_in_table ('tgraph_template', 'name'); + if ($all_templates === false) + return array (); + + $templates = array (); + foreach ($all_templates as $template) { + if (!in_array($template['id_group'], array_keys($groups))) + continue; + + if ($template["id_user"] != $id_user && $template['private']) + continue; + + if ($template["id_group"] > 0) + if (!isset($groups[$template["id_group"]])){ + continue; + } + + if ($only_names) { + $templates[$template['id_graph_template']] = $template['name']; + } + else { + $templates[$template['id_graph_template']] = $template; + $templatesCount = db_get_value_sql("SELECT COUNT(id_gs_template) FROM tgraph_source_template WHERE id_template = " . $template['id_graph_template']); + $templates[$template['id_graph_template']]['graphs_template_count'] = $templatesCount; + } + } + + return $templates; +} + +/** + * Gets a detailed reporting of groups's events. + * + * @param unknown_type $id_group Id of the group. + * @param unknown_type $period Time period of the report. + * @param unknown_type $date Date of the report. + * @param unknown_type $return Whether to return or not. + * @param unknown_type $html Whether to return HTML code or not. + * + * @return string Report of groups's events + */ +function reporting_get_count_events_by_agent ($id_group, $period = 0, + $date = 0, + $filter_event_validated = false, $filter_event_critical = false, + $filter_event_warning = false, $filter_event_no_validated = false) { + + if (!is_numeric ($date)) { + $date = strtotime ($date); + } + if (empty ($date)) { + $date = get_system_time (); + } + + return events_get_count_events_by_agent($id_group, $period, $date, + $filter_event_validated, $filter_event_critical, + $filter_event_warning, $filter_event_no_validated); +} + +/** + * Gets a detailed reporting of groups's events. + * + * @param unknown_type $filter. + * @param unknown_type $period Time period of the report. + * @param unknown_type $date Date of the report. + * @param unknown_type $return Whether to return or not. + * @param unknown_type $html Whether to return HTML code or not. + * + * @return string Report of groups's events + */ +function reporting_get_count_events_validated_by_user ($filter, $period = 0, + $date = 0, + $filter_event_validated = false, $filter_event_critical = false, + $filter_event_warning = false, $filter_event_no_validated = false) { + + if (!is_numeric ($date)) { + $date = strtotime ($date); + } + if (empty ($date)) { + $date = get_system_time (); + } + + return events_get_count_events_validated_by_user($filter, $period, $date, + $filter_event_validated, $filter_event_critical, + $filter_event_warning, $filter_event_no_validated); +} + +/** + * Gets a detailed reporting of groups's events. + * + * @param unknown_type $id_group Id of the group. + * @param unknown_type $period Time period of the report. + * @param unknown_type $date Date of the report. + * @param unknown_type $return Whether to return or not. + * @param unknown_type $html Whether to return HTML code or not. + * + * @return string Report of groups's events + */ +function reporting_get_count_events_by_criticity ($filter, $period = 0, + $date = 0, + $filter_event_validated = false, $filter_event_critical = false, + $filter_event_warning = false, $filter_event_no_validated = false) { + + if (!is_numeric ($date)) { + $date = strtotime ($date); + } + if (empty ($date)) { + $date = get_system_time (); + } + + return events_get_count_events_by_criticity($filter, $period, $date, + $filter_event_validated, $filter_event_critical, + $filter_event_warning, $filter_event_no_validated); +} + +/** + * Gets a detailed reporting of groups's events. + * + * @param unknown_type $id_group Id of the group. + * @param unknown_type $period Time period of the report. + * @param unknown_type $date Date of the report. + * @param unknown_type $return Whether to return or not. + * @param unknown_type $html Whether to return HTML code or not. + * + * @return string Report of groups's events + */ +function reporting_get_count_events_validated ($filter, $period = 0, + $date = 0, + $filter_event_validated = false, $filter_event_critical = false, + $filter_event_warning = false, $filter_event_no_validated = false) { + + if (!is_numeric ($date)) { + $date = strtotime ($date); + } + if (empty ($date)) { + $date = get_system_time (); + } + + return events_get_count_events_validated($filter, $period, $date, + $filter_event_validated, $filter_event_critical, + $filter_event_warning, $filter_event_no_validated); +} + +/** + * Print tiny statistics of the status of one agent, group, etc. + * + * @param mixed Array with the counts of the total modules, normal modules, critical modules, warning modules, unknown modules and fired alerts + * @param bool return or echo flag + * + * @return string html formatted tiny stats of modules/alerts of an agent + */ +function reporting_tiny_stats ($counts_info, $return = false, $type = 'agent', $separator = ':', $strict_user = false) { + global $config; + + $out = ''; + + // Depend the type of object, the stats will refer agents, modules... + switch ($type) { + case 'modules': + $template_title['total_count'] = __('%d Total modules'); + $template_title['normal_count'] = __('%d Normal modules'); + $template_title['critical_count'] = __('%d Critical modules'); + $template_title['warning_count'] = __('%d Warning modules'); + $template_title['unknown_count'] = __('%d Unknown modules'); + break; + case 'agent': + $template_title['total_count'] = __('%d Total modules'); + $template_title['normal_count'] = __('%d Normal modules'); + $template_title['critical_count'] = __('%d Critical modules'); + $template_title['warning_count'] = __('%d Warning modules'); + $template_title['unknown_count'] = __('%d Unknown modules'); + $template_title['fired_count'] = __('%d Fired alerts'); + break; + default: + $template_title['total_count'] = __('%d Total agents'); + $template_title['normal_count'] = __('%d Normal agents'); + $template_title['critical_count'] = __('%d Critical agents'); + $template_title['warning_count'] = __('%d Warning agents'); + $template_title['unknown_count'] = __('%d Unknown agents'); + $template_title['not_init_count'] = __('%d not init agents'); + $template_title['fired_count'] = __('%d Fired alerts'); + break; + } + + if ($strict_user && $type == 'agent') { + + $acltags = tags_get_user_module_and_tags ($config['id_user'],'AR', $strict_user); + $filter['disabled'] = 0; + $id_agent = $counts_info['id_agente']; + + $counts_info = array(); + $counts_info['normal_count'] = count(tags_get_agent_modules ($id_agent, $acltags, false, $filter, false, AGENT_MODULE_STATUS_NORMAL)); + $counts_info['warning_count'] = count(tags_get_agent_modules ($id_agent, $acltags, false, $filter, false, AGENT_MODULE_STATUS_WARNING)); + $counts_info['critical_count'] = count(tags_get_agent_modules ($id_agent, $acltags, false, $filter, false, AGENT_MODULE_STATUS_CRITICAL_BAD)); + $counts_info['notinit_count'] = count(tags_get_agent_modules ($id_agent, $acltags, false, $filter, false, AGENT_MODULE_STATUS_NOT_INIT)); + $counts_info['unknown_count'] = count(tags_get_agent_modules ($id_agent, $acltags, false, $filter, false, AGENT_MODULE_STATUS_UNKNOWN)); + $counts_info['total_count'] = $counts_info['normal_count'] + $counts_info['warning_count'] + $counts_info['critical_count'] + $counts_info['unknown_count'] + $counts_info['notinit_count']; + + $all_agent_modules = tags_get_agent_modules ($id_agent, $acltags, false, $filter); + if (!empty($all_agent_modules)) { + $mod_clause = "(".implode(',', array_keys($all_agent_modules)).")"; + + $counts_info['fired_count'] = (int) db_get_sql ("SELECT COUNT(times_fired) + FROM talert_template_modules + WHERE times_fired != 0 AND id_agent_module IN ".$mod_clause); + } + else { + $counts_info['fired_count'] = 0; + } + } + + // Store the counts in a data structure to print hidden divs with titles + $stats = array(); + + if (isset($counts_info['total_count'])) { + $not_init = isset($counts_info['notinit_count']) ? $counts_info['notinit_count'] : 0; + $total_count = $counts_info['total_count'] - $not_init; + $stats[] = array('name' => 'total_count', 'count' => $total_count, 'title' => sprintf($template_title['total_count'], $total_count)); + } + + if (isset($counts_info['normal_count'])) { + $normal_count = $counts_info['normal_count']; + $stats[] = array('name' => 'normal_count', 'count' => $normal_count, 'title' => sprintf($template_title['normal_count'], $normal_count)); + } + + if (isset($counts_info['critical_count'])) { + $critical_count = $counts_info['critical_count']; + $stats[] = array('name' => 'critical_count', 'count' => $critical_count, 'title' => sprintf($template_title['critical_count'], $critical_count)); + } + + if (isset($counts_info['warning_count'])) { + $warning_count = $counts_info['warning_count']; + $stats[] = array('name' => 'warning_count', 'count' => $warning_count, 'title' => sprintf($template_title['warning_count'], $warning_count)); + } + + if (isset($counts_info['unknown_count'])) { + $unknown_count = $counts_info['unknown_count']; + $stats[] = array('name' => 'unknown_count', 'count' => $unknown_count, 'title' => sprintf($template_title['unknown_count'], $unknown_count)); + } + + if (isset($counts_info['not_init_count'])) { + $not_init_count = $counts_info['not_init_count']; + $stats[] = array('name' => 'not_init_count', + 'count' => $not_init_count, + 'title' => sprintf($template_title['not_init_count'], $not_init_count)); + } + + if (isset($template_title['fired_count'])) { + if (isset($counts_info['fired_count'])) { + $fired_count = $counts_info['fired_count']; + $stats[] = array('name' => 'fired_count', 'count' => $fired_count, 'title' => sprintf($template_title['fired_count'], $fired_count)); + } + } + + $uniq_id = uniqid(); + + foreach ($stats as $stat) { + $params = array('id' => 'forced_title_' . $stat['name'] . '_' . $uniq_id, + 'class' => 'forced_title_layer', + 'content' => $stat['title'], + 'hidden' => true); + $out .= html_print_div($params, true); + } + + // If total count is less than 0, is an error. Never show negative numbers + if ($total_count < 0) { + $total_count = 0; + } + + $out .= '' . '' . $total_count . ''; + if (isset($fired_count) && $fired_count > 0) + $out .= ' ' . $separator . ' ' . $fired_count . ''; + if (isset($critical_count) && $critical_count > 0) + $out .= ' ' . $separator . ' ' . $critical_count . ''; + if (isset($warning_count) && $warning_count > 0) + $out .= ' ' . $separator . ' ' . $warning_count . ''; + if (isset($unknown_count) && $unknown_count > 0) + $out .= ' ' . $separator . ' ' . $unknown_count . ''; + if (isset($not_init_count) && $not_init_count > 0) + $out .= ' ' . $separator . ' ' . $not_init_count . ''; + if (isset($normal_count) && $normal_count > 0) + $out .= ' ' . $separator . ' ' . $normal_count . ''; + + $out .= ''; + + if ($return) { + return $out; + } + else { + echo $out; + } +} + + +function reporting_network_interfaces_table ($content, $report, $mini, $item_title = "", &$table = null, &$pdf = null) { + global $config; + + include_once($config['homedir'] . "/include/functions_custom_graphs.php"); + + if (empty($item_title)) { + $group_name = groups_get_name($content['id_group']); + $item_title = __('Network interfaces') . " - " . sprintf(__('Group "%s"'), $group_name); + } + + $is_html = $table !== null; + $is_pdf = $pdf !== null; + + $ttl = $is_pdf ? 2 : 1; + + $graph_width = 900; + $graph_height = 200; + + $datetime = $report['datetime']; + $period = $content['period']; + + if ($is_pdf) { + $graph_width = 800; + $graph_height = 200; + pdf_header_content($pdf, $content, $report, $item_title, false, $content["description"]); + } + else if ($is_html) { + reporting_header_content($mini, $content, $report, $table, $item_title); + + //RUNNING + $table->style[1] = 'text-align: right'; + + // Put description at the end of the module (if exists) + $table->colspan[0][1] = 2; + $next_row = 1; + if ($content["description"] != "") { + $table->colspan[$next_row][0] = 3; + $next_row++; + $data_desc = array(); + $data_desc[0] = $content["description"]; + array_push ($table->data, $data_desc); + } + } + + $filter = array( + 'id_grupo' => $content['id_group'], + 'disabled' => 0 + ); + $network_interfaces_by_agents = agents_get_network_interfaces(false, $filter); + + if (empty($network_interfaces_by_agents)) { + if ($is_pdf) { + $pdf->addHTML(__('The group has no agents or none of the agents has any network interface')); + } + else if ($is_html) { + $data = array(); + $data[0] = __('The group has no agents or none of the agents has any network interface'); + $table->colspan[$next_row][0] = 3; + array_push ($table->data, $data); + } + return; + } + else { + foreach ($network_interfaces_by_agents as $agent_id => $agent) { + + $table_agent = new StdCLass(); + $table_agent->width = '100%'; + $table_agent->data = array(); + $table_agent->head = array(); + $table_agent->head[0] = sprintf(__("Agent '%s'"), $agent['name']); + $table_agent->headstyle = array(); + $table_agent->headstyle[0] = 'font-size: 16px;'; + $table_agent->style[0] = 'text-align: center'; + + if ($is_pdf) { + $table_agent->class = 'table_sla table_beauty'; + $table_agent->headstyle[0] = 'background: #373737; color: #FFF; display: table-cell; font-size: 16px; border: 1px solid grey'; + } + + $table_agent->data['interfaces'] = ""; + + foreach ($agent['interfaces'] as $interface_name => $interface) { + $table_interface = new StdClass(); + $table_interface->width = '100%'; + $table_interface->data = array(); + $table_interface->rowstyle = array(); + $table_interface->head = array(); + $table_interface->cellstyle = array(); + $table_interface->title = sprintf(__("Interface '%s' throughput graph"), $interface_name); + $table_interface->head['ip'] = __('IP'); + $table_interface->head['mac'] = __('Mac'); + $table_interface->head['status'] = __('Actual status'); + $table_interface->style['ip'] = 'text-align: left'; + $table_interface->style['mac'] = 'text-align: left'; + $table_interface->style['status'] = 'width: 150px; text-align: center'; + + if ($is_pdf) { + $table_interface->class = 'table_sla table_beauty'; + $table_interface->titlestyle = 'background: #373737; color: #FFF; display: table-cell; font-size: 12px; border: 1px solid grey'; + + $table_interface->headstyle['ip'] = 'text-align: left; background: #666; color: #FFF; display: table-cell; font-size: 11px; border: 1px solid grey'; + $table_interface->headstyle['mac'] = 'text-align: left; background: #666; color: #FFF; display: table-cell; font-size: 11px; border: 1px solid grey'; + $table_interface->headstyle['status'] = 'background: #666; color: #FFF; display: table-cell; font-size: 11px; border: 1px solid grey'; + + $table_interface->style['ip'] = 'text-align: left; display: table-cell; font-size: 10px;'; + $table_interface->style['mac'] = 'text-align: left; display: table-cell; font-size: 10px;'; + $table_interface->style['status'] = 'text-align: center; display: table-cell; font-size: 10px;'; + } + + $data = array(); + $data['ip'] = !empty($interface['ip']) ? $interface['ip'] : "--"; + $data['mac'] = !empty($interface['mac']) ? $interface['mac'] : "--"; + $data['status'] = $interface['status_image']; + $table_interface->data['data'] = $data; + + if (!empty($interface['traffic'])) { + + $only_image = !(bool)$config['flash_charts'] || $is_pdf ? true : false; + + $graph = custom_graphs_print(0, + $graph_height, + $graph_width, + $period, + null, + true, + $date, + $only_image, + 'white', + array_values($interface['traffic']), + $config['homeurl'], + array_keys($interface['traffic']), + array_fill(0, count($interface['traffic']),"bytes/s"), + false, + true, + true, + true, + $ttl); + + $table_interface->data['graph'] = $graph; + $table_interface->colspan['graph'][0] = count($table_interface->head); + $table_interface->cellstyle['graph'][0] = 'text-align: center;'; + } + + $table_agent->data['interfaces'] .= html_print_table($table_interface, true); + $table_agent->colspan[$interface_name][0] = 3; + } + + if ($is_html) { + $table->data[$agent_id] = html_print_table($table_agent, true); + $table->colspan[$agent_id][0] = 3; + } + else if ($is_pdf) { + $html = html_print_table($table_agent, true); + $pdf->addHTML($html); + } + } + } +} + +function reporting_get_agents_by_status ($data, $graph_width = 250, $graph_height = 150, $links = false) { + global $config; + + if ($links == false) { + $links = array(); + } + + $table_agent = html_get_predefined_table(); + + $agent_data = array(); + $agent_data[0] = html_print_image('images/agent_critical.png', true, array('title' => __('Agents critical'))); + $agent_data[1] = "".format_numeric($data['agent_critical']).""; + + $agent_data[2] = html_print_image('images/agent_warning.png', true, array('title' => __('Agents warning'))); + $agent_data[3] = "".format_numeric($data['agent_warning']).""; + + $table_agent->data[] = $agent_data; + + $agent_data = array(); + $agent_data[0] = html_print_image('images/agent_ok.png', true, array('title' => __('Agents ok'))); + $agent_data[1] = "".format_numeric($data['agent_ok']).""; + + $agent_data[2] = html_print_image('images/agent_unknown.png', true, array('title' => __('Agents unknown'))); + $agent_data[3] = "".format_numeric($data['agent_unknown']).""; + + $table_agent->data[] = $agent_data; + + $agent_data = array(); + $agent_data[0] = html_print_image('images/agent_notinit.png', true, array('title' => __('Agents not init'))); + $agent_data[1] = "".format_numeric($data['agent_not_init']).""; + + $agent_data[2] = ""; + $agent_data[3] = ""; + $table_agent->data[] = $agent_data; + + + if (!defined('METACONSOLE')) { + $agents_data = '
+ ' . + __('Agents by status') . + '' . + html_print_table($table_agent, true) . '
'; + } + else{ + $table_agent->style=array(); + $table_agent->class = "tactical_view"; + $agents_data = '
+ ' . + __('Agents by status') . + '' . + html_print_table($table_agent, true) . '
'; + } + + return $agents_data; +} + +function reporting_get_total_agents_and_monitors ($data, $graph_width = 250, $graph_height = 150) { + global $config; + + $total_agent = $data['agent_ok'] + $data['agent_warning'] + $data['agent_critical'] + $data['gent_unknown'] + $data['agent_not_init']; + $total_module = $data['monitor_ok'] + $data['monitor_warning'] + $data['monitor_critical'] + $data['monitor_unknown'] + $data['monitor_not_init']; + + $table_total = html_get_predefined_table(); + + $total_data = array(); + $total_data[0] = html_print_image('images/agent.png', true, array('title' => __('Total agents'))); + $total_data[1] = $total_agent <= 0 ? '-' : $total_agent; + $total_data[2] = html_print_image('images/module.png', true, array('title' => __('Monitor checks'))); + $total_data[3] = $total_module <= 0 ? '-' : $total_module; + $table_total->data[] = $total_data; + $total_agent_module = '
+ ' . + __('Total agents and monitors') . + '' . + html_print_table($table_total, true) . '
'; + + return $total_agent_module; +} + +function reporting_get_total_servers ($num_servers) { + global $config; + + $table_node = html_get_predefined_table(); + + $node_data = array(); + $node_data[0] = html_print_image('images/server_export.png', true, array('title' => __('Nodes'))); + $node_data[1] = "".format_numeric($num_servers).""; + $table_node->data[] = $node_data; + + if (!defined('METACONSOLE')){ + $node_overview = '
+ ' . + __('Node overview') . + '' . + html_print_table($table_node, true) . '
'; + }else{ + $table_node->style = array(); + $table_node->class = "tactical_view"; + $node_overview = '
+ ' . + __('Node overview') . + '' . + html_print_table($table_node, true) . '
'; + } + + return $node_overview; +} + +function reporting_get_events ($data, $links = false) { + global $config; + + $table_events->width = "100%"; + if (defined('METACONSOLE')) + $style = " vertical-align:middle;"; + else + $style = ""; + if (defined('METACONSOLE')){ + $table_events->style[0] = "background-color:#FC4444"; + $table_events->data[0][0] = html_print_image('images/module_event_critical.png', true, array('title' => __('Critical events'))); + $table_events->data[0][0] .= "   " . + "" . format_numeric($data['critical']).""; + $table_events->style[1] = "background-color:#FAD403"; + $table_events->data[0][1] = html_print_image('images/module_event_warning.png', true, array('title' => __('Warning events'))); + $table_events->data[0][1] .= "   " . + "" . format_numeric($data['warning']).""; + $table_events->style[2] = "background-color:#80BA27"; + $table_events->data[0][2] = html_print_image('images/module_event_ok.png', true, array('title' => __('OK events'))); + $table_events->data[0][2] .= "   " . + "" . format_numeric($data['normal']).""; + $table_events->style[3] = "background-color:#B2B2B2"; + $table_events->data[0][3] = html_print_image('images/module_event_unknown.png', true, array('title' => __('Unknown events'))); + $table_events->data[0][3] .= "   " . + "" . format_numeric($data['unknown']).""; + } + else{ + $table_events->data[0][0] = html_print_image('images/module_critical.png', true, array('title' => __('Critical events'))); + $table_events->data[0][0] .= "   " . + "". + format_numeric($data['critical']).""; + $table_events->data[0][1] = html_print_image('images/module_warning.png', true, array('title' => __('Warning events'))); + $table_events->data[0][1] .= "   " . + "". + format_numeric($data['warning']).""; + $table_events->data[0][2] = html_print_image('images/module_ok.png', true, array('title' => __('OK events'))); + $table_events->data[0][2] .= "   " . + "". + format_numeric($data['normal']).""; + $table_events->data[0][3] = html_print_image('images/module_unknown.png', true, array('title' => __('Unknown events'))); + $table_events->data[0][3] .= "   " . + "". + format_numeric($data['unknown']).""; + + } + if (!defined('METACONSOLE')) { + $event_view = '
+ ' . + __('Events by criticity') . + '' . + html_print_table($table_events, true) . '
'; + } + else{ + $table_events->class="tactical_view"; + $table_events->styleTable="text-align:center;"; + $table_events->size[0]="10%"; + $table_events->size[1]="10%"; + $table_events->size[2]="10%"; + $table_events->size[3]="10%"; + + $event_view = '
+ ' . + __('Events by criticity') . + '' . + html_print_table($table_events, true) . '
'; + } + + return $event_view; +} + +function reporting_get_last_activity() { + global $config; + + // Show last activity from this user + + $table->width = '100%'; + $table->data = array (); + $table->size = array (); + $table->size[2] = '150px'; + $table->size[3] = '130px'; + $table->size[5] = '200px'; + $table->head = array (); + $table->head[0] = __('User'); + $table->head[1] = ''; + $table->head[2] = __('Action'); + $table->head[3] = __('Date'); + $table->head[4] = __('Source IP'); + $table->head[5] = __('Comments'); + $table->title = '' . __('Last activity in Pandora FMS console') . ''; + + switch ($config["dbtype"]) { + case "mysql": + $sql = sprintf ("SELECT id_usuario,accion,fecha,ip_origen,descripcion,utimestamp + FROM tsesion + WHERE (`utimestamp` > UNIX_TIMESTAMP(NOW()) - " . SECONDS_1WEEK . ") + AND `id_usuario` = '%s' ORDER BY `utimestamp` DESC LIMIT 5", $config["id_user"]); + break; + case "postgresql": + $sql = sprintf ("SELECT \"id_usuario\", accion, fecha, \"ip_origen\", descripcion, utimestamp + FROM tsesion + WHERE (\"utimestamp\" > ceil(date_part('epoch', CURRENT_TIMESTAMP)) - " . SECONDS_1WEEK . ") + AND \"id_usuario\" = '%s' ORDER BY \"utimestamp\" DESC LIMIT 5", $config["id_user"]); + break; + case "oracle": + $sql = sprintf ("SELECT id_usuario, accion, fecha, ip_origen, descripcion, utimestamp + FROM tsesion + WHERE ((utimestamp > ceil((sysdate - to_date('19700101000000','YYYYMMDDHH24MISS')) * (" . SECONDS_1DAY . ")) - " . SECONDS_1WEEK . ") + AND id_usuario = '%s') AND rownum <= 10 ORDER BY utimestamp DESC", $config["id_user"]); + break; + } + + $sessions = db_get_all_rows_sql ($sql); + + if ($sessions === false) + $sessions = array (); + + foreach ($sessions as $session) { + $data = array (); + + switch ($config["dbtype"]) { + case "mysql": + case "oracle": + $session_id_usuario = $session['id_usuario']; + $session_ip_origen = $session['ip_origen']; + break; + case "postgresql": + $session_id_usuario = $session['id_usuario']; + $session_ip_origen = $session['ip_origen']; + break; + } + + + $data[0] = '' . $session_id_usuario . ''; + $data[1] = ui_print_session_action_icon ($session['accion'], true); + $data[2] = $session['accion']; + $data[3] = ui_print_help_tip($session['fecha'], true) . human_time_comparation($session['utimestamp'], 'tiny'); + $data[4] = $session_ip_origen; + $data[5] = io_safe_output ($session['descripcion']); + + array_push ($table->data, $data); + } + + if(defined("METACONSOLE")) + $table->class="databox_tactical"; + + return html_print_table ($table, true); + +} + +function reporting_get_event_histogram ($events) { + global $config; + include_once ('../../include/graphs/functions_gd.php'); + $max_value = count($events); + + $ttl = 1; + $urlImage = ui_get_full_url(false, true, false, false); + + $colors = array( + EVENT_CRIT_MAINTENANCE => COL_MAINTENANCE, + EVENT_CRIT_INFORMATIONAL => COL_INFORMATIONAL, + EVENT_CRIT_NORMAL => COL_MINOR, + EVENT_CRIT_MINOR => COL_NORMAL, + EVENT_CRIT_WARNING => COL_WARNING, + EVENT_CRIT_MAJOR => COL_MAJOR, + EVENT_CRIT_CRITICAL => COL_CRITICAL + ); + + foreach ($events as $data) { + + switch ($data['criticity']) { + case 0: + $color = EVENT_CRIT_MAINTENANCE; + break; + case 1: + $color = EVENT_CRIT_INFORMATIONAL; + break; + case 2: + $color = EVENT_CRIT_NORMAL; + break; + case 3: + $color = EVENT_CRIT_WARNING; + break; + case 4: + $color = EVENT_CRIT_CRITICAL; + break; + case 5: + $color = EVENT_CRIT_MINOR; + break; + case 6: + $color = EVENT_CRIT_MAJOR; + break; + case 20: + $color = EVENT_CRIT_NOT_NORMAL; + break; + case 34: + $color = EVENT_CRIT_WARNING_OR_CRITICAL; + break; + } + $graph_data[] = array( + 'data' => $color, + 'utimestamp' => 1 + ); + } + + $table->width = '100%'; + $table->data = array (); + $table->size = array (); + $table->head = array (); + $table->title = '' . __('Events info (1hr.)') . ''; + $table->data[0][0] = "" ; + + if (!empty($graph_data)) { + $slicebar = slicesbar_graph($graph_data, $max_value, 700, 25, $colors, $config['fontpath'], $config['round_corner'], $urlImage, $ttl); + $table->data[0][0] = $slicebar; + } else { + $table->data[0][0] = __('No events'); + } + + if(!defined('METACONSOLE')){ + $event_graph = '
+ ' . + __('Events info (1hr)') . + '' . + html_print_table($table, true) . '
'; + } + else{ + $table->class='tactical_view'; + $event_graph = '
' . + html_print_table($table, true) . '
'; + } + + return $event_graph; +} +?> From fdaa8865b2a0706d968cdcf8d869956f9b526b35 Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Tue, 24 Mar 2015 11:01:19 +0100 Subject: [PATCH 03/80] Working in the code refactoring. --- pandora_console/include/constants.php | 40 +- .../include/functions_reporting.php | 371 +++++++++++++++--- .../operation/reporting/reporting_viewer.php | 43 +- 3 files changed, 386 insertions(+), 68 deletions(-) diff --git a/pandora_console/include/constants.php b/pandora_console/include/constants.php index 5e1bda01cf..71349caf48 100755 --- a/pandora_console/include/constants.php +++ b/pandora_console/include/constants.php @@ -343,27 +343,28 @@ define('SERVER_TYPE_ENTERPRISE_ICMP', 11); define('SERVER_TYPE_ENTERPRISE_SNMP', 12); /* REPORTS */ -define ('REPORT_TOP_N_MAX', 1); -define ('REPORT_TOP_N_MIN', 2); -define ('REPORT_TOP_N_AVG', 0); +define('REPORT_TOP_N_MAX', 1); +define('REPORT_TOP_N_MIN', 2); +define('REPORT_TOP_N_AVG', 0); -define ('REPORT_TOP_N_ONLY_GRAPHS', 2); -define ('REPORT_TOP_N_SHOW_TABLE_GRAPS', 1); -define ('REPORT_TOP_N_ONLY_TABLE', 0); +define('REPORT_TOP_N_ONLY_GRAPHS', 2); +define('REPORT_TOP_N_SHOW_TABLE_GRAPS', 1); +define('REPORT_TOP_N_ONLY_TABLE', 0); -define ('REPORT_EXCEPTION_CONDITION_EVERYTHING', 0); -define ('REPORT_EXCEPTION_CONDITION_GE', 1); -define ('REPORT_EXCEPTION_CONDITION_LE', 5); -define ('REPORT_EXCEPTION_CONDITION_L', 2); -define ('REPORT_EXCEPTION_CONDITION_G', 6); -define ('REPORT_EXCEPTION_CONDITION_E', 7); -define ('REPORT_EXCEPTION_CONDITION_NE', 8); -define ('REPORT_EXCEPTION_CONDITION_OK', 3); -define ('REPORT_EXCEPTION_CONDITION_NOT_OK', 4); +define('REPORT_EXCEPTION_CONDITION_EVERYTHING', 0); +define('REPORT_EXCEPTION_CONDITION_GE', 1); +define('REPORT_EXCEPTION_CONDITION_LE', 5); +define('REPORT_EXCEPTION_CONDITION_L', 2); +define('REPORT_EXCEPTION_CONDITION_G', 6); +define('REPORT_EXCEPTION_CONDITION_E', 7); +define('REPORT_EXCEPTION_CONDITION_NE', 8); +define('REPORT_EXCEPTION_CONDITION_OK', 3); +define('REPORT_EXCEPTION_CONDITION_NOT_OK', 4); -define ('REPORT_ITEM_ORDER_BY_AGENT_NAME', 3); -define ('REPORT_ITEM_ORDER_BY_ASCENDING', 2); -define ('REPORT_ITEM_ORDER_BY_DESCENDING', 1); +define('REPORT_ITEM_ORDER_BY_AGENT_NAME', 3); +define('REPORT_ITEM_ORDER_BY_ASCENDING', 2); +define('REPORT_ITEM_ORDER_BY_DESCENDING', 1); +define('REPORT_ITEM_ORDER_BY_UNSORT', 0); define('REPORT_OLD_TYPE_SIMPLE_GRAPH', 1); define('REPORT_OLD_TYPE_CUSTOM_GRAPH', 2); @@ -374,6 +375,9 @@ define('REPORT_OLD_TYPE_MAX_VALUE', 8); define('REPORT_OLD_TYPE_MIN_VALUE', 9); define('REPORT_OLD_TYPE_SUMATORY', 10); +define('REPORT_GENERAL_NOT_GROUP_BY_AGENT', 0); +define('REPORT_GENERAL_GROUP_BY_AGENT', 1); + /* POLICIES */ define("POLICY_UPDATED", 0); diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index 93573f2282..7edcb5cfc7 100644 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -37,6 +37,24 @@ include_once($config['homedir'] . "/include/functions_forecast.php"); include_once($config['homedir'] . "/include/functions_ui.php"); include_once($config['homedir'] . "/include/functions_netflow.php"); +function reporting_user_can_see_report($id_report, $id_user = null) { + global $config; + + if (empty($id_user)) { + $id_user = $config['id_user']; + } + + // Get Report record (to get id_group) + $report = db_get_row ('treport', 'id_report', $id_report); + + // Check ACL on the report to see if user has access to the report. + if (empty($report) || !check_acl ($config['id_user'], $report['id_group'], "RR")) { + return false; + } + + return true; +} + function reporting_get_type($content) { switch ($content["type"]) { case REPORT_OLD_TYPE_SIMPLE_GRAPH: @@ -68,9 +86,16 @@ function reporting_get_type($content) { return $content["type"]; } -function reporting_make_reporting_data($id_report, $date, $time, $period, $type = 'dinamic') { +function reporting_make_reporting_data($id_report, $date, $time, + $period = null, $type = 'dinamic', $force_width_chart = null, + $force_height_chart = null) { + + global $config; + $return = array(); + $report = db_get_row ('treport', 'id_report', $id_report); + switch ($config["dbtype"]) { case "mysql": $contents = db_get_all_rows_field_filter ("treport_content", @@ -94,24 +119,29 @@ function reporting_make_reporting_data($id_report, $date, $time, $period, $type $datetime = strtotime($date . ' ' . $time); $report["datetime"] = $datetime; - $report['period'] = $period; - $report['contents'] = array(); foreach ($contents as $content) { - // Calculate new inteval for all reports - if ($enable_init_date) { - if ($datetime_init >= $datetime) { - $datetime_init = $date_init_less; - } - $new_interval = $report['datetime'] - $datetime_init; - $content['period'] = $new_interval; + if (!empty($period)) { + $content['period'] = $period; } + $content['style'] = json_decode( + io_safe_output($content['style']), true); + switch (reporting_get_type($content)) { case 'simple_graph': $report['contents'][] = reporting_simple_graph( + $report, + $content, + $type, + $force_width_chart, + $force_height_chart); + break; + case 'general': + $report['contents'][] = + reporting_general( $report, $content, $type); @@ -119,13 +149,249 @@ function reporting_make_reporting_data($id_report, $date, $time, $period, $type } } - return reporting_check_structure_report($return); + return reporting_check_structure_report($report); } -function reporting_simple_graph($report, $content, $type = 'dinamic') { +function reporting_general($report, $content, $type = 'dinamic') { + global $config; - //sizgraph_w ¿meter el size en la llamada general? + $return = array(); + + if (empty($content['name'])) { + $content['name'] = __('General'); + } + + $return['title'] = $content['name']; + $return["description"] = $content["description"]; + $return["date"] = reporting_get_date_text( + $report, + $content); + + switch ($content['group_by_agent']) { + case REPORT_GENERAL_NOT_GROUP_BY_AGENT: + $sql = sprintf(" + SELECT id_agent_module, + server_name, operation + FROM treport_content_item + WHERE id_report_content = %d", + $content['id_rc']); + $generals = db_process_sql ($sql); + $generals = db_get_all_rows_filter( + 'treport_content_item', + array('id_report_content' => $content['id_rc'])); + if (empty($generals)) { + $generals = array(); + } + + foreach ($generals as $key => $row) { + //Metaconsole connection + $server_name = $row ['server_name']; + if (($config ['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE')) { + $connection = metaconsole_get_connection($server_name); + if (metaconsole_load_external_db($connection) != NOERR) { + //ui_print_error_message ("Error connecting to ".$server_name); + continue; + } + } + + if (modules_is_disable_agent($row['id_agent_module'])) { + continue; + } + + $mod_name = modules_get_agentmodule_name ($row['id_agent_module']); + $ag_name = modules_get_agentmodule_agent_name ($row['id_agent_module']); + $unit = db_get_value('unit', 'tagente_modulo', + 'id_agente_modulo', + $row['id_agent_module']); + + if ($content['period'] == 0) { + $data_res[$key] = + modules_get_last_value($row['id_agent_module']); + } + else { + switch ($row['operation']) { + case 'sum': + $data_res[$key] = + reporting_get_agentmodule_data_sum( + $row['id_agent_module'], $content['period'], $report["datetime"]); + break; + case 'max': + $data_res[$key] = + reporting_get_agentmodule_data_max( + $row['id_agent_module'], $content['period']); + break; + case 'min': + $data_res[$key] = + reporting_get_agentmodule_data_min( + $row['id_agent_module'], $content['period']); + break; + case 'avg': + default: + $data_res[$key] = + reporting_get_agentmodule_data_average( + $row['id_agent_module'], $content['period']); + break; + } + } + + $id_agent_module[$key] = $row['id_agent_module']; + $agent_name[$key] = $ag_name; + $module_name[$key] = $mod_name; + $units[$key] = $unit; + $operations[$key] = $row['operation']; + + //Restore dbconnection + if (($config ['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE')) { + metaconsole_restore_db(); + } + } + + + + switch ($content['order_uptodown']) { + case REPORT_ITEM_ORDER_BY_AGENT_NAME: + array_multisort($agent_name, SORT_ASC, + $data_res, SORT_ASC, $module_name, SORT_ASC, + $id_agent_module, SORT_ASC, $operations, + SORT_ASC); + break; + case REPORT_ITEM_ORDER_BY_ASCENDING: + array_multisort($data_res, SORT_ASC, + $agent_name, SORT_ASC, $module_name, + SORT_ASC, $id_agent_module, + SORT_ASC, $operations, SORT_ASC); + break; + case REPORT_ITEM_ORDER_BY_DESCENDING: + array_multisort($data_res, SORT_DESC, + $agent_name, SORT_ASC, $module_name, + SORT_ASC, $id_agent_module, + SORT_ASC, $operations, SORT_ASC); + break; + case REPORT_ITEM_ORDER_BY_UNSORT: + break; + } + + $return["data"] = array(); + $return["avg_value"] = 0; + $return["min"] = array(); + $return["min"]["value"] = null; + $return["min"]["formated_value"] = null; + $return["min"]["agent"] = null; + $return["min"]["module"] = null; + $return["max"] = array(); + $return["max"]["value"] = null; + $return["max"]["formated_value"] = null; + $return["max"]["agent"] = null; + $return["max"]["module"] = null; + $i = 0; + foreach ($data_res as $d) { + $data = array(); + $data['agent'] = $agent_name[$i]; + $data['module'] = $module_name[$i]; + + + $data['operator'] = ""; + if ($content['period'] != 0) { + switch ($operations[$i]) { + case 'sum': + $data['operator'] = __('Summatory'); + break; + case 'min': + $data['operator'] = __('Minimal'); + break; + case 'max': + $data['operator'] = __('Maximun'); + break; + case 'avg': + default: + $data['operator'] = __('Rate'); + break; + } + } + + if ($d === false) { + $data['value'] = '--'; + } + else { + if (!is_numeric($d)) { + $data['value'] = $d; + } + else { + $data['value'] = format_for_graph($d, 2) . " " . + $units[$i]; + + $change_min = false; + if (is_null($return["min"]["value"])) { + $change_min = true; + } + else { + if ($return["min"]["value"] > $d) { + $change_min = true; + } + } + if ($change_min) { + $return["min"]["value"] = $d; + $return["min"]["formated_value"] = + $data['value']; + $return["min"]["agent"] = $agent_name[$i]; + $return["min"]["module"] = $module_name[$i]; + } + + $change_max = false; + if (is_null($return["max"]["value"])) { + $change_max = true; + } + else { + if ($return["max"]["value"] < $d) { + $change_max = true; + } + } + + if ($change_max) { + $return["max"]["value"] = $d; + $return["max"]["formated_value"] = + $data['value']; + $return["max"]["agent"] = $agent_name[$i]; + $return["max"]["module"] = $module_name[$i]; + } + + if ($i == 0) { + $return["avg_value"] = $d; + } + else { + $return["avg_value"] = + (($return["avg_value"] * $i) / ($i + 1)) + + + ($d / ($i + 1)); + } + } + } + $return["data"][] = $data; + + if ($return["avg_value"] > 0) { + $return["avg_value"] = format_for_graph( + $return["avg_value"], 2); + } + + $i++; + } + break; + case REPORT_GENERAL_GROUP_BY_AGENT: + break; + } + + if ($content['show_resume'] && count($return["data"]) > 0) { + + } + + return reporting_check_structure_content($return); +} + +function reporting_simple_graph($report, $content, $type = 'dinamic', + $force_width_chart = null, $force_height_chart = null) { + + global $config; $return = array(); @@ -139,25 +405,18 @@ function reporting_simple_graph($report, $content, $type = 'dinamic') { modules_get_agentmodule_agent_name ($content['id_agent_module'])); - - $return['title'] = $content['name']; $return['subtitle'] = $agent_name . " - " . $module_name; $return["description"] = $content["description"]; $return["date"] = reporting_get_date_text( - $report['id_rc'], - $content['id']); + $report, + $content); $only_avg = true; // Due to database compatibility problems, the 'only_avg' value // is stored into the json contained into the 'style' column. - if (isset($content['style'])) { - $style_json = io_safe_output($content['style']); - $style = json_decode($style_json, true); - - if (isset($style['only_avg'])) { - $only_avg = (bool) $style['only_avg']; - } + if (isset($style['only_avg'])) { + $only_avg = (bool) $style['only_avg']; } $moduletype_name = modules_get_moduletype_name( @@ -171,14 +430,32 @@ function reporting_simple_graph($report, $content, $type = 'dinamic') { switch ($type) { case 'dinamic': $only_image = false; + $width = 900; + $height = 230; break; case 'static': $only_image = true; + if ($content['style']['show_in_landscape']) { + $height = 1100; + $width = 1700; + } + else { + $height = 360; + $width = 780; + } break; case 'data': break; } + if (!empty($force_width_chart)) { + $width = $force_width_chart; + } + + if (!empty($force_height_chart)) { + $height = $force_height_chart; + } + switch ($type) { case 'dinamic': case 'static': @@ -190,8 +467,8 @@ function reporting_simple_graph($report, $content, $type = 'dinamic') { $content['id_agent_module'], $content['period'], false, - $sizgraph_w, - $sizgraph_h, + $width, + $height, '', '', false, @@ -201,13 +478,12 @@ function reporting_simple_graph($report, $content, $type = 'dinamic') { } else { - - $data[0] = grafico_modulo_sparse( + $return['chart'] = grafico_modulo_sparse( $content['id_agent_module'], $content['period'], false, - $sizgraph_w, - $sizgraph_h, + $width, + $height, '', '', false, @@ -234,7 +510,7 @@ function reporting_simple_graph($report, $content, $type = 'dinamic') { return reporting_check_structure_content($return); } -function reporting_get_date_text($id_report, $id_report_item) { +function reporting_get_date_text($report, $content) { global $config; $return = array(); @@ -243,9 +519,6 @@ function reporting_get_date_text($id_report, $id_report_item) { $return['from'] = ""; $return['to'] = ""; - $report = db_get_row('treport_content_item', 'id', $id_report_item); - $content = db_get_row('treport', 'id_report', $id_report); - if ($content['period'] == 0) { $es = json_decode($content['external_source'], true); if ($es['date'] == 0) { @@ -283,23 +556,25 @@ function reporting_check_structure_report($return) { /** * Check the common items exits */ -function reporting_check_structure_content($return) { - if (!isset($return['title'])) - $return['title'] = ""; - if (!isset($return['subtitle'])) - $return['subtitle'] = ""; - if (!isset($return['description'])) - $return['description'] = ""; - if (!isset($return["date"])) { - $return["date"]['date'] = ""; - $return["date"]['period'] = ""; - $return["date"]['from'] = ""; - $return["date"]['to'] = ""; +function reporting_check_structure_content($report) { + if (!isset($report['title'])) + $report['title'] = ""; + if (!isset($report['subtitle'])) + $report['subtitle'] = ""; + if (!isset($report['description'])) + $report['description'] = ""; + if (!isset($report["date"])) { + $report["date"]['date'] = ""; + $report["date"]['period'] = ""; + $report["date"]['from'] = ""; + $report["date"]['to'] = ""; } - return $return; + return $report; } +//////////////////////////////////////////////////////////////////////// + /** * Get general statistical info on a group * @@ -950,4 +1225,4 @@ function reporting_get_stats_users($data) { return $output; } -?> +?> \ No newline at end of file diff --git a/pandora_console/operation/reporting/reporting_viewer.php b/pandora_console/operation/reporting/reporting_viewer.php index 1ddad7d549..da8f1b539d 100644 --- a/pandora_console/operation/reporting/reporting_viewer.php +++ b/pandora_console/operation/reporting/reporting_viewer.php @@ -24,11 +24,50 @@ $id_report = (int) get_parameter ('id'); if (! $id_report) { db_pandora_audit("HACK Attempt", - "Trying to access graph viewer withoud ID"); + "Trying to access report viewer withoud ID"); include ("general/noaccess.php"); return; } +// Include with the functions to calculate each kind of report. +require_once ($config['homedir'] . '/include/functions_reporting.php'); +require_once ($config['homedir'] . '/include/functions_reporting_html.php'); +require_once ($config['homedir'] . '/include/functions_groups.php'); + + +if (!reporting_user_can_see_report($id_report)) { + db_pandora_audit("ACL Violation", "Trying to access report viewer"); + include ("general/noaccess.php"); + exit; +} + +// Get different date to search the report. +$date = (string) get_parameter ('date', date(DATE_FORMAT)); +$time = (string) get_parameter ('time', date(TIME_FORMAT)); + +$datetime = strtotime ($date . ' ' . $time); + +// Calculations in order to modify init date of the report +$date_init_less = strtotime(date('Y-m-j')) - SECONDS_1DAY; +$date_init = get_parameter('date_init', date(DATE_FORMAT, $date_init_less)); +$time_init = get_parameter('time_init', date(TIME_FORMAT, $date_init_less)); +$datetime_init = strtotime ($date_init.' '.$time_init); +$enable_init_date = get_parameter('enable_init_date', 0); + +$period = null; +// Calculate new inteval for all reports +if ($enable_init_date) { + if ($datetime_init >= $datetime) { + $datetime_init = $date_init_less; + } + $period = $datetime - $datetime_init; +} + +$report = reporting_make_reporting_data($id_report, $date, $time, $period, 'dinamic'); +html_debug_print($report); +//---------------------------------------------------------------------- + + // Get Report record (to get id_group) $report = db_get_row ('treport', 'id_report', $id_report); @@ -44,7 +83,7 @@ require_once ($config['homedir'] . '/include/functions_reporting.php'); require_once ($config['homedir'] . '/include/functions_reporting_html.php'); require_once ($config['homedir'] . '/include/functions_groups.php'); -enterprise_include("include/functions_reporting.php"); +enterprise_include_once("include/functions_reporting.php"); $pure = get_parameter('pure',0); From 0cadefa2f04d8dd18647016a5672cf73ef3752db Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Tue, 24 Mar 2015 11:36:40 +0100 Subject: [PATCH 04/80] Fixed the previous merge with the 'develop' branch. --- .../include/functions_reporting.php | 200 +++++++----------- 1 file changed, 72 insertions(+), 128 deletions(-) diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index 7edcb5cfc7..0f7f2168fa 100644 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -959,39 +959,8 @@ function reporting_get_stats_alerts($data, $links = false) { } } - $table_agent = html_get_predefined_table(); - - $agent_data = array(); - $agent_data[0] = html_print_image('images/agent_critical.png', true, array('title' => __('Agents critical'))); - $agent_data[1] = ""; - $agent_data[1] .= format_numeric($data["agent_critical"]) <= 0 ? '-' : format_numeric($data['agent_critical']); - $agent_data[1] .= ""; - - $agent_data[2] = html_print_image('images/agent_warning.png', true, array('title' => __('Agents warning'))); - $agent_data[3] = ""; - $agent_data[3] .= $data["agent_warning"] <= 0 ? '-' : format_numeric($data['agent_warning']); - $agent_data[3] .= ""; - - $table_agent->data[] = $agent_data; - - $agent_data = array(); - $agent_data[0] = html_print_image('images/agent_ok.png', true, array('title' => __('Agents ok'))); - $agent_data[1] = ""; - $agent_data[1] .= $data["agent_ok"] <= 0 ? '-' : format_numeric($data['agent_ok']); - $agent_data[1] .= ""; - - $agent_data[2] = html_print_image('images/agent_unknown.png', true, array('title' => __('Agents unknown'))); - $agent_data[3] = ""; - $agent_data[3] .= $data["agent_unknown"] <= 0 ? '-' : format_numeric($data['agent_unknown']); - $agent_data[3] .= ""; - - $table_agent->data[] = $agent_data; - - $agent_data = array(); - $agent_data[0] = html_print_image('images/agent_notinit.png', true, array('title' => __('Agents not init'))); - $agent_data[1] = ""; - $agent_data[1] .= $data["agent_not_init"] <= 0 ? '-' : format_numeric($data['agent_not_init']); - $agent_data[1] .= ""; + // Alerts table + $table_al = html_get_predefined_table(); $tdata = array(); $tdata[0] = html_print_image('images/bell.png', true, array('title' => __('Defined alerts'))); @@ -1004,14 +973,13 @@ function reporting_get_stats_alerts($data, $links = false) { $table_al->rowclass[] = ''; $table_al->data[] = $tdata; - if (!defined('METACONSOLE')) { + if(!defined('METACONSOLE')){ $output = '
' . __('Defined and fired alerts') . '' . html_print_table($table_al, true) . '
'; - } - else { + }else{ $table_al->class = "tactical_view"; $table_al->style = array(); $output = '
@@ -1027,86 +995,81 @@ function reporting_get_stats_alerts($data, $links = false) { function reporting_get_stats_modules_status($data, $graph_width = 250, $graph_height = 150, $links = false, $data_agents=false) { global $config; - $table_node = html_get_predefined_table(); - - $node_data = array(); - $node_data[0] = html_print_image('images/server_export.png', true, array('title' => __('Nodes'))); - $node_data[1] = ""; - $node_data[1] .= $num_servers <= 0 ? '-' : format_numeric($num_servers); - $node_data[1] .= ""; - $table_node->data[] = $node_data; - - if (!defined('METACONSOLE')){ - $node_overview = '
- ' . - __('Node overview') . - '' . - html_print_table($table_node, true) . '
'; - }else{ - $table_node->style = array(); - $table_node->class = "tactical_view"; - $node_overview = '
- ' . - __('Node overview') . - '' . - html_print_table($table_node, true) . '
'; + // Link URLS + if ($links === false) { + $urls = array(); + $urls['monitor_critical'] = "index.php?" . + "sec=estado&sec2=operation/agentes/status_monitor&" . + "refr=60&status=" . AGENT_MODULE_STATUS_CRITICAL_BAD . "&pure=" . $config['pure']; + $urls['monitor_warning'] = "index.php?" . + "sec=estado&sec2=operation/agentes/status_monitor&" . + "refr=60&status=" . AGENT_MODULE_STATUS_WARNING . "&pure=" . $config['pure']; + $urls['monitor_ok'] = "index.php?" . + "sec=estado&sec2=operation/agentes/status_monitor&" . + "refr=60&status=" . AGENT_MODULE_STATUS_NORMAL . "&pure=" . $config['pure']; + $urls['monitor_unknown'] = "index.php?" . + "sec=estado&sec2=operation/agentes/status_monitor&" . + "refr=60&status=" . AGENT_MODULE_STATUS_UNKNOWN . "&pure=" . $config['pure']; + $urls['monitor_not_init'] = "index.php?" . + "sec=estado&sec2=operation/agentes/status_monitor&" . + "refr=60&status=" . AGENT_MODULE_STATUS_NOT_INIT . "&pure=" . $config['pure']; + } + else { + $urls = array(); + $urls['monitor_critical'] = $links['monitor_critical']; + $urls['monitor_warning'] = $links['monitor_warning']; + $urls['monitor_ok'] = $links['monitor_ok']; + $urls['monitor_unknown'] = $links['monitor_unknown']; + $urls['monitor_not_init'] = $links['monitor_not_init']; } // Modules by status table $table_mbs = html_get_predefined_table(); - $table_events->width = "100%"; - if (defined('METACONSOLE')) - $style = " vertical-align:middle;"; - else - $style = ""; - if (defined('METACONSOLE')){ - $table_events->style[0] = "background-color:#FC4444"; - $table_events->data[0][0] = html_print_image('images/module_event_critical.png', true, array('title' => __('Critical events'))); - $table_events->data[0][0] .= "   " . - ""; - $table_events->data[0][0] .= format_numeric($data['critical']) <= 0 ? ' -' : format_numeric($data['critical']); - $table_events->data[0][0] .= ""; - $table_events->style[1] = "background-color:#FAD403"; - $table_events->data[0][1] = html_print_image('images/module_event_warning.png', true, array('title' => __('Warning events'))); - $table_events->data[0][1] .= "   " . - ""; - $table_events->data[0][1] .= format_numeric($data['warning']) <= 0 ? ' -' : format_numeric($data['warning']); - $table_events->data[0][1] .= ""; - $table_events->style[2] = "background-color:#80BA27"; - $table_events->data[0][2] = html_print_image('images/module_event_ok.png', true, array('title' => __('OK events'))); - $table_events->data[0][2] .= "   " . - ""; - $table_events->data[0][2] .= format_numeric($data['normal']) <= 0 ? ' -' : format_numeric($data['normal']); - $table_events->data[0][2] .= ""; - $table_events->style[3] = "background-color:#B2B2B2"; - $table_events->data[0][3] = html_print_image('images/module_event_unknown.png', true, array('title' => __('Unknown events'))); - $table_events->data[0][3] .= "   " . - ""; - $table_events->data[0][3] .=format_numeric($data['unknown']) <= 0 ? ' -' : format_numeric($data['unknown']); - $table_events->data[0][3] .=""; - } - else{ - $table_events->data[0][0] = html_print_image('images/module_critical.png', true, array('title' => __('Critical events'))); - $table_events->data[0][0] .= "   " . - "". - format_numeric($data['critical']).""; - $table_events->data[0][1] = html_print_image('images/module_warning.png', true, array('title' => __('Warning events'))); - $table_events->data[0][1] .= "   " . - "". - format_numeric($data['warning']).""; - $table_events->data[0][2] = html_print_image('images/module_ok.png', true, array('title' => __('OK events'))); - $table_events->data[0][2] .= "   " . - "". - format_numeric($data['normal']).""; - $table_events->data[0][3] = html_print_image('images/module_unknown.png', true, array('title' => __('Unknown events'))); - $table_events->data[0][3] .= "   " . - "". - format_numeric($data['unknown']).""; + $tdata = array(); + $tdata[0] = html_print_image('images/module_critical.png', true, array('title' => __('Monitor critical'))); + $tdata[1] = $data["monitor_critical"] <= 0 ? '-' : $data["monitor_critical"]; + $tdata[1] = '' . $tdata[1] . ''; + + $tdata[2] = html_print_image('images/module_warning.png', true, array('title' => __('Monitor warning'))); + $tdata[3] = $data["monitor_warning"] <= 0 ? '-' : $data["monitor_warning"]; + $tdata[3] = '' . $tdata[3] . ''; + $table_mbs->rowclass[] = ''; + $table_mbs->data[] = $tdata; + + $tdata = array(); + $tdata[0] = html_print_image('images/module_ok.png', true, array('title' => __('Monitor normal'))); + $tdata[1] = $data["monitor_ok"] <= 0 ? '-' : $data["monitor_ok"]; + $tdata[1] = '' . $tdata[1] . ''; + + $tdata[2] = html_print_image('images/module_unknown.png', true, array('title' => __('Monitor unknown'))); + $tdata[3] = $data["monitor_unknown"] <= 0 ? '-' : $data["monitor_unknown"]; + $tdata[3] = '' . $tdata[3] . ''; + $table_mbs->rowclass[] = ''; + $table_mbs->data[] = $tdata; + + $tdata = array(); + $tdata[0] = html_print_image('images/module_notinit.png', true, array('title' => __('Monitor not init'))); + $tdata[1] = $data["monitor_not_init"] <= 0 ? '-' : $data["monitor_not_init"]; + $tdata[1] = '' . $tdata[1] . ''; + + $tdata[2] = $tdata[3] = ''; + $table_mbs->rowclass[] = ''; + $table_mbs->data[] = $tdata; + if ($data["monitor_checks"] > 0) { + $tdata = array(); + $table_mbs->colspan[count($table_mbs->data)][0] = 4; + $table_mbs->cellstyle[count($table_mbs->data)][0] = 'text-align: center;'; + $tdata[0] = '
' . + '
' . + graph_agent_status(false, $graph_width, $graph_height, true, true, $data_agents) . + '
'; + $table_mbs->rowclass[] = ''; + $table_mbs->data[] = $tdata; } - if (!defined("METACONSOLE")) { + if(!defined("METACONSOLE")){ $output = '
' . @@ -1115,7 +1078,7 @@ function reporting_get_stats_modules_status($data, $graph_width = 250, $graph_he html_print_table($table_mbs, true) . '
'; } - else { + else{ $table_mbs->class = "tactical_view"; $table_mbs->style=array(); $output = ' @@ -1126,7 +1089,6 @@ function reporting_get_stats_modules_status($data, $graph_width = 250, $graph_he html_print_table($table_mbs, true) . '
'; } - return $output; } @@ -1178,24 +1140,6 @@ function reporting_get_stats_agents_monitors($data) { function reporting_get_stats_users($data) { global $config; - include_once ('../../include/graphs/functions_gd.php'); - $max_value = count($events); - - $ttl = 1; - $urlImage = ui_get_full_url(false, true, false, false); - - $colors = array( - EVENT_CRIT_MAINTENANCE => COL_MAINTENANCE, - EVENT_CRIT_INFORMATIONAL => COL_INFORMATIONAL, - EVENT_CRIT_NORMAL => COL_NORMAL, - EVENT_CRIT_MINOR => COL_MINOR, - EVENT_CRIT_WARNING => COL_WARNING, - EVENT_CRIT_MAJOR => COL_MAJOR, - EVENT_CRIT_CRITICAL => COL_CRITICAL - ); - - foreach ($events as $data) { - // Link URLS $urls = array(); if (check_acl ($config['id_user'], 0, "UM")) { From 34caeb13c23a0056a81236fd26d73a0257f43cfe Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Tue, 24 Mar 2015 11:47:39 +0100 Subject: [PATCH 05/80] Working in the new feature. --- .../include/functions_reporting.php | 25 ++++++------------- 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index 0f7f2168fa..a9d0861710 100644 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -168,22 +168,15 @@ function reporting_general($report, $content, $type = 'dinamic') { $report, $content); + $generals = db_get_all_rows_filter( + 'treport_content_item', + array('id_report_content' => $content['id_rc'])); + if (empty($generals)) { + $generals = array(); + } + switch ($content['group_by_agent']) { case REPORT_GENERAL_NOT_GROUP_BY_AGENT: - $sql = sprintf(" - SELECT id_agent_module, - server_name, operation - FROM treport_content_item - WHERE id_report_content = %d", - $content['id_rc']); - $generals = db_process_sql ($sql); - $generals = db_get_all_rows_filter( - 'treport_content_item', - array('id_report_content' => $content['id_rc'])); - if (empty($generals)) { - $generals = array(); - } - foreach ($generals as $key => $row) { //Metaconsole connection $server_name = $row ['server_name']; @@ -381,10 +374,6 @@ function reporting_general($report, $content, $type = 'dinamic') { break; } - if ($content['show_resume'] && count($return["data"]) > 0) { - - } - return reporting_check_structure_content($return); } From a5eaeb3ec92a575df38f0bab0717a100114c853d Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Tue, 24 Mar 2015 15:06:10 +0100 Subject: [PATCH 06/80] Working in this feature (refactoring code of reporting) --- .../include/functions_reporting.php | 349 +++++++++++------- .../include/functions_reporting_html.php | 2 +- 2 files changed, 225 insertions(+), 126 deletions(-) diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index a9d0861710..6c2f1bd706 100644 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -143,8 +143,12 @@ function reporting_make_reporting_data($id_report, $date, $time, $report['contents'][] = reporting_general( $report, - $content, - $type); + $content); + break; + case 'sql': + $report['contents'][] = reporting_sql( + $report, + $content); break; } } @@ -152,7 +156,84 @@ function reporting_make_reporting_data($id_report, $date, $time, return reporting_check_structure_report($report); } -function reporting_general($report, $content, $type = 'dinamic') { +function reporting_sql($report, $content) { + + global $config; + + $return = array(); + + if (empty($content['name'])) { + $content['name'] = __('SQL'); + } + + $return['title'] = $content['name']; + $return["description"] = $content["description"]; + $return["date"] = reporting_get_date_text( + $report, + $content); + + if ($content['treport_custom_sql_id'] != 0) { + switch ($config["dbtype"]) { + case "mysql": + $sql = io_safe_output (db_get_value_filter('`sql`', 'treport_custom_sql', array('id' => $content['treport_custom_sql_id']))); + break; + case "postgresql": + $sql = io_safe_output (db_get_value_filter('"sql"', 'treport_custom_sql', array('id' => $content['treport_custom_sql_id']))); + break; + case "oracle": + $sql = io_safe_output (db_get_value_filter('sql', 'treport_custom_sql', array('id' => $content['treport_custom_sql_id']))); + break; + } + } + else { + $sql = io_safe_output ($content['external_source']); + } + + // Do a security check on SQL coming from the user + $sql = check_sql ($sql); + + $return['sql'] = $sql; + $return['correct'] = 1; + $return['error'] = ""; + $return['data'] = array(); + if ($sql != '') { + $header = array(); + if ($content['header_definition'] != '') { + $header = explode('|', $content['header_definition']); + } + + $result = db_get_all_rows_sql($sql); + if ($result !== false) { + + foreach ($result as $row) { + $data_row = array(); + + $i = 0; + foreach ($row as $dbkey => $field) { + if (isset($header[$i])) { + $key = $header[$i]; + } + else { + $key = $dbkey; + } + $data_row[$key] = $field; + + $i++; + } + + $return['data'][] = $data_row; + } + } + } + else { + $return['correct'] = 0; + $return['error'] = __('Illegal query: Due security restrictions, there are some tokens or words you cannot use: *, delete, drop, alter, modify, union, password, pass, insert or update.'); + } + + return reporting_check_structure_content($return); +} + +function reporting_general($report, $content) { global $config; @@ -168,6 +249,19 @@ function reporting_general($report, $content, $type = 'dinamic') { $report, $content); + $return["data"] = array(); + $return["avg_value"] = 0; + $return["min"] = array(); + $return["min"]["value"] = null; + $return["min"]["formated_value"] = null; + $return["min"]["agent"] = null; + $return["min"]["module"] = null; + $return["max"] = array(); + $return["max"]["value"] = null; + $return["max"]["formated_value"] = null; + $return["max"]["agent"] = null; + $return["max"]["module"] = null; + $generals = db_get_all_rows_filter( 'treport_content_item', array('id_report_content' => $content['id_rc'])); @@ -175,73 +269,140 @@ function reporting_general($report, $content, $type = 'dinamic') { $generals = array(); } - switch ($content['group_by_agent']) { - case REPORT_GENERAL_NOT_GROUP_BY_AGENT: - foreach ($generals as $key => $row) { - //Metaconsole connection - $server_name = $row ['server_name']; - if (($config ['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE')) { - $connection = metaconsole_get_connection($server_name); - if (metaconsole_load_external_db($connection) != NOERR) { - //ui_print_error_message ("Error connecting to ".$server_name); - continue; - } - } - - if (modules_is_disable_agent($row['id_agent_module'])) { - continue; - } - - $mod_name = modules_get_agentmodule_name ($row['id_agent_module']); - $ag_name = modules_get_agentmodule_agent_name ($row['id_agent_module']); - $unit = db_get_value('unit', 'tagente_modulo', - 'id_agente_modulo', - $row['id_agent_module']); - - if ($content['period'] == 0) { + $i = 0; + foreach ($generals as $key => $row) { + //Metaconsole connection + $server_name = $row ['server_name']; + if (($config ['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE')) { + $connection = metaconsole_get_connection($server_name); + if (metaconsole_load_external_db($connection) != NOERR) { + //ui_print_error_message ("Error connecting to ".$server_name); + continue; + } + } + + if (modules_is_disable_agent($row['id_agent_module'])) { + continue; + } + + $mod_name = modules_get_agentmodule_name ($row['id_agent_module']); + $ag_name = modules_get_agentmodule_agent_name ($row['id_agent_module']); + $unit = db_get_value('unit', 'tagente_modulo', + 'id_agente_modulo', + $row['id_agent_module']); + + if ($content['period'] == 0) { + $data_res[$key] = + modules_get_last_value($row['id_agent_module']); + } + else { + switch ($row['operation']) { + case 'sum': $data_res[$key] = - modules_get_last_value($row['id_agent_module']); - } - else { - switch ($row['operation']) { - case 'sum': - $data_res[$key] = - reporting_get_agentmodule_data_sum( - $row['id_agent_module'], $content['period'], $report["datetime"]); - break; - case 'max': - $data_res[$key] = - reporting_get_agentmodule_data_max( - $row['id_agent_module'], $content['period']); - break; - case 'min': - $data_res[$key] = - reporting_get_agentmodule_data_min( - $row['id_agent_module'], $content['period']); - break; - case 'avg': - default: - $data_res[$key] = - reporting_get_agentmodule_data_average( - $row['id_agent_module'], $content['period']); - break; - } - } - + reporting_get_agentmodule_data_sum( + $row['id_agent_module'], $content['period'], $report["datetime"]); + break; + case 'max': + $data_res[$key] = + reporting_get_agentmodule_data_max( + $row['id_agent_module'], $content['period']); + break; + case 'min': + $data_res[$key] = + reporting_get_agentmodule_data_min( + $row['id_agent_module'], $content['period']); + break; + case 'avg': + default: + $data_res[$key] = + reporting_get_agentmodule_data_average( + $row['id_agent_module'], $content['period']); + break; + } + } + + switch ($content['group_by_agent']) { + case REPORT_GENERAL_NOT_GROUP_BY_AGENT: $id_agent_module[$key] = $row['id_agent_module']; $agent_name[$key] = $ag_name; $module_name[$key] = $mod_name; $units[$key] = $unit; $operations[$key] = $row['operation']; - - //Restore dbconnection - if (($config ['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE')) { - metaconsole_restore_db(); + break; + case REPORT_GENERAL_GROUP_BY_AGENT: + if ($data_res[$key] === false) { + $return["data"][$ag_name][$mod_name] = null; + } + else { + if (!is_numeric($value_res)) { + $return["data"][$ag_name][$mod_name] = $data_res[$key]; + } + else { + $return["data"][$ag_name][$mod_name] = + format_for_graph($data_res[$key], 2) . " " . $unit; + } + } + break; + } + + // Calculate the avg, min and max + if (is_numeric($data_res[$key])) { + $change_min = false; + if (is_null($return["min"]["value"])) { + $change_min = true; + } + else { + if ($return["min"]["value"] > $data_res[$key]) { + $change_min = true; + } + } + if ($change_min) { + $return["min"]["value"] = $data_res[$key]; + $return["min"]["formated_value"] = + format_for_graph($data_res[$key], 2) . " " . $unit; + $return["min"]["agent"] = $ag_name; + $return["min"]["module"] = $mod_name; + } + + $change_max = false; + if (is_null($return["max"]["value"])) { + $change_max = true; + } + else { + if ($return["max"]["value"] < $data_res[$key]) { + $change_max = true; } } + if ($change_max) { + $return["max"]["value"] = $data_res[$key]; + $return["max"]["formated_value"] = + format_for_graph($data_res[$key], 2) . " " . $unit; + $return["max"]["agent"] = $ag_name; + $return["max"]["module"] = $mod_name; + } - + if ($i == 0) { + $return["avg_value"] = $data_res[$key]; + } + else { + $return["avg_value"] = + (($return["avg_value"] * $i) / ($i + 1)) + + + ($data_res[$key] / ($i + 1)); + } + } + + $i++; + + //Restore dbconnection + if (($config ['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE')) { + metaconsole_restore_db(); + } + } + + switch ($content['group_by_agent']) { + case REPORT_GENERAL_NOT_GROUP_BY_AGENT: switch ($content['order_uptodown']) { case REPORT_ITEM_ORDER_BY_AGENT_NAME: array_multisort($agent_name, SORT_ASC, @@ -265,18 +426,8 @@ function reporting_general($report, $content, $type = 'dinamic') { break; } - $return["data"] = array(); - $return["avg_value"] = 0; - $return["min"] = array(); - $return["min"]["value"] = null; - $return["min"]["formated_value"] = null; - $return["min"]["agent"] = null; - $return["min"]["module"] = null; - $return["max"] = array(); - $return["max"]["value"] = null; - $return["max"]["formated_value"] = null; - $return["max"]["agent"] = null; - $return["max"]["module"] = null; + + $i = 0; foreach ($data_res as $d) { $data = array(); @@ -304,7 +455,7 @@ function reporting_general($report, $content, $type = 'dinamic') { } if ($d === false) { - $data['value'] = '--'; + $data['value'] = null; } else { if (!is_numeric($d)) { @@ -313,65 +464,13 @@ function reporting_general($report, $content, $type = 'dinamic') { else { $data['value'] = format_for_graph($d, 2) . " " . $units[$i]; - - $change_min = false; - if (is_null($return["min"]["value"])) { - $change_min = true; - } - else { - if ($return["min"]["value"] > $d) { - $change_min = true; - } - } - if ($change_min) { - $return["min"]["value"] = $d; - $return["min"]["formated_value"] = - $data['value']; - $return["min"]["agent"] = $agent_name[$i]; - $return["min"]["module"] = $module_name[$i]; - } - - $change_max = false; - if (is_null($return["max"]["value"])) { - $change_max = true; - } - else { - if ($return["max"]["value"] < $d) { - $change_max = true; - } - } - - if ($change_max) { - $return["max"]["value"] = $d; - $return["max"]["formated_value"] = - $data['value']; - $return["max"]["agent"] = $agent_name[$i]; - $return["max"]["module"] = $module_name[$i]; - } - - if ($i == 0) { - $return["avg_value"] = $d; - } - else { - $return["avg_value"] = - (($return["avg_value"] * $i) / ($i + 1)) - + - ($d / ($i + 1)); - } } } $return["data"][] = $data; - if ($return["avg_value"] > 0) { - $return["avg_value"] = format_for_graph( - $return["avg_value"], 2); - } - $i++; } break; - case REPORT_GENERAL_GROUP_BY_AGENT: - break; } return reporting_check_structure_content($return); diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index 05c358befa..a8f53d2d3c 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -4233,7 +4233,7 @@ function reporting_render_report_html_item ($content, $table, $report, $mini = f $filter_event_no_validated); if(!empty($data[0])) { array_push ($table->data, $data); - + $table->colspan[$next_row][0] = 3; $next_row++; } From ceca482158cd98a07cd4168751399ce567944356 Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Tue, 24 Mar 2015 17:52:57 +0100 Subject: [PATCH 07/80] Working in the refactoring code of reporting. --- .../include/functions_reporting.php | 48 +++++--- .../include/functions_reporting_html.php | 113 +++++++++++++++++- 2 files changed, 142 insertions(+), 19 deletions(-) diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index 6c2f1bd706..1c2c5f220f 100644 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -86,6 +86,14 @@ function reporting_get_type($content) { return $content["type"]; } +function reporting_get_description($id_report) { + return db_get_value('description', 'treport', 'id_report', $id_report); +} + +function reporting_get_name($id_report) { + return db_get_value('name', 'treport', 'id_report', $id_report); +} + function reporting_make_reporting_data($id_report, $date, $time, $period = null, $type = 'dinamic', $force_width_chart = null, $force_height_chart = null) { @@ -161,6 +169,7 @@ function reporting_sql($report, $content) { global $config; $return = array(); + $return['type'] = 'sql'; if (empty($content['name'])) { $content['name'] = __('SQL'); @@ -168,9 +177,7 @@ function reporting_sql($report, $content) { $return['title'] = $content['name']; $return["description"] = $content["description"]; - $return["date"] = reporting_get_date_text( - $report, - $content); + $return["date"] = reporting_get_date_text(); if ($content['treport_custom_sql_id'] != 0) { switch ($config["dbtype"]) { @@ -238,6 +245,7 @@ function reporting_general($report, $content) { global $config; $return = array(); + $return['type'] = 'general'; if (empty($content['name'])) { $content['name'] = __('General'); @@ -482,6 +490,7 @@ function reporting_simple_graph($report, $content, $type = 'dinamic', global $config; $return = array(); + $return['type'] = 'simple_graph'; if (empty($content['name'])) { $content['name'] = __('Simple graph'); @@ -598,29 +607,32 @@ function reporting_simple_graph($report, $content, $type = 'dinamic', return reporting_check_structure_content($return); } -function reporting_get_date_text($report, $content) { +function reporting_get_date_text($report = null, $content = null) { global $config; $return = array(); - $return['date'] = ""; - $return['period'] = ""; - $return['from'] = ""; - $return['to'] = ""; + $return['date'] = null; + $return['period'] = null; + $return['from'] = null; + $return['to'] = null; - if ($content['period'] == 0) { - $es = json_decode($content['external_source'], true); - if ($es['date'] == 0) { - $return['date'] = __('Last data'); + if (!empty($report) && !empty($content)) { + + if ($content['period'] == 0) { + $es = json_decode($content['external_source'], true); + if ($es['date'] == 0) { + $return['period'] = 0; + } + else { + $return['date'] = $es['date']; + } } else { - $return['date'] = date($config["date_format"], $es['date']); + $return['period'] = $content['period']; + $return['from'] = $report["datetime"] - $content['period']; + $return['to'] = $report["datetime"]; } } - else { - $return['period'] = human_time_description_raw ($content['period']); - $return['from'] = date($config["date_format"], $report["datetime"] - $content['period']); - $return['from'] = date($config["date_format"], $report["datetime"]); - } return $return; } diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index a8f53d2d3c..031af34b35 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -37,6 +37,115 @@ include_once($config['homedir'] . "/include/functions_forecast.php"); include_once($config['homedir'] . "/include/functions_ui.php"); include_once($config['homedir'] . "/include/functions_netflow.php"); +function reporting_html_header(&$table, $mini, $title, $subtitle, + $period, $date, $from, $to) { + + global $config; + + + if ($mini) { + $sizh = ''; + $sizhfin = ''; + } + else { + $sizh = '

'; + $sizhfin = '

'; + } + + + $date_text = ""; + if (!empty($date)) { + $date_text = date($config["date_format"], $date); + } + else if (!empty($from) && !empty($to)) { + $date_text = + "(" . human_time_description_raw ($period) . ") " . + __("From:") . " " . date($config["date_format"], $from) . "
" . + __("To:") . " " . date($config["date_format"], $to); + } + else if ($period > 0) { + $date_text = human_time_description_raw($period); + } + else if ($period === 0) { + $date_text = __('Last data'); + } + + + $data = array(); + if (empty($subtitle) && (empty($date_text))) { + $data[] = $sizh . $title . $sizhfin; + $table->colspan[0][0] = 3; + } + else if (empty($subtitle)) { + $data[] = $sizh . $title . $sizhfin; + $data[] = "
" . $sizh . $date_text . $sizhfin . "
"; + $table->colspan[0][1] = 2; + } + else if (empty($date_text)) { + $data[] = $sizh . $title . $sizhfin; + $data[] = $sizh . $subtitle . $sizhfin; + $table->colspan[0][1] = 2; + } + else { + $data[] = $sizh . $title . $sizhfin; + $data[] = $sizh . $subtitle . $sizhfin; + $data[] = "
" . $sizh . $date_text . $sizhfin . "
"; + } + + array_push ($table->data, $data); +} + +function reporting_html_print_report($report, $mini = false) { + + foreach ($report['contents'] as $item) { + $table->size = array (); + $table->style = array (); + $table->width = '98%'; + $table->class = 'databox'; + $table->rowclass = array (); + $table->rowclass[0] = 'datos3'; + $table->data = array (); + $table->head = array (); + $table->style = array (); + $table->colspan = array (); + $table->rowstyle = array (); + + + reporting_html_header($table, + $mini, $item['title'], + $item['subtitle'], + $item['date']['period'], + $item['date']['date'], + $item['date']['from'], + $item['date']['to']); + + if ($item["description"] != "") { + $table->data['description_row']['description'] = $item["description"]; + $table->colspan['description_row']['description'] = 3; + } + + switch ($item['type']) { + case 'general': + break; + case 'sql': + break; + case 'simple_graph': + $table->colspan['chart']['cell'] = 3; + $table->cellstyle['chart']['cell'] = 'text-align: center;'; + $table->data['chart']['cell'] = $item['chart']; + break; + } + + if ($item['type'] == 'agent_module') + echo '
'; + + html_print_table ($table); + + if ($item['type'] == 'agent_module') + echo '
'; + } +} + /** * Get the average value of an agent module in a period of time. * @@ -2804,7 +2913,9 @@ function sla_value_asc_cmp($a, $b) { /** * Make the header for each content. */ -function reporting_header_content($mini, $content, $report, &$table, $title = false, $name = false, $period = false) { +function reporting_header_content($mini, $content, $report, &$table, + $title = false, $name = false, $period = false) { + global $config; if ($mini) { From 62c5d57ca68799a411d108acfb72da6db497338d Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Tue, 24 Mar 2015 18:03:08 +0100 Subject: [PATCH 08/80] Working in the refactoring code of reporting. Added some items in html --- .../include/functions_reporting_html.php | 41 ++++++- .../operation/reporting/reporting_viewer.php | 101 +++++++++--------- 2 files changed, 89 insertions(+), 53 deletions(-) diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index 031af34b35..b38b75af84 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -128,11 +128,10 @@ function reporting_html_print_report($report, $mini = false) { case 'general': break; case 'sql': + reporting_html_sql($table, $item); break; case 'simple_graph': - $table->colspan['chart']['cell'] = 3; - $table->cellstyle['chart']['cell'] = 'text-align: center;'; - $table->data['chart']['cell'] = $item['chart']; + reporting_html_simple_graph($table, $item); break; } @@ -146,6 +145,42 @@ function reporting_html_print_report($report, $mini = false) { } } +function reporting_html_sql(&$table, $item) { + if (!$item['correct']) { + $table->colspan['chart']['cell'] = 3; + $table->data['chart']['cell'] = $item['error']; + } + else { + $first = true; + + $table2->class = 'databox'; + $table2->width = '100%'; + + foreach ($item['data'] as $row) { + if ($first) { + $first = false; + + // Print the header + foreach ($row as $key => $value) { + $table2->head[] = $key; + } + } + + $table2->data[] = $row; + } + + $table->colspan['chart']['cell'] = 3; + $table->cellstyle['chart']['cell'] = 'text-align: center;'; + $table->data['chart']['cell'] = html_print_table($table2, true); + } +} + +function reporting_html_simple_graph(&$table, $item) { + $table->colspan['chart']['cell'] = 3; + $table->cellstyle['chart']['cell'] = 'text-align: center;'; + $table->data['chart']['cell'] = $item['chart']; +} + /** * Get the average value of an agent module in a period of time. * diff --git a/pandora_console/operation/reporting/reporting_viewer.php b/pandora_console/operation/reporting/reporting_viewer.php index da8f1b539d..4d333eb3f3 100644 --- a/pandora_console/operation/reporting/reporting_viewer.php +++ b/pandora_console/operation/reporting/reporting_viewer.php @@ -33,6 +33,7 @@ if (! $id_report) { require_once ($config['homedir'] . '/include/functions_reporting.php'); require_once ($config['homedir'] . '/include/functions_reporting_html.php'); require_once ($config['homedir'] . '/include/functions_groups.php'); +enterprise_include_once("include/functions_reporting.php"); if (!reporting_user_can_see_report($id_report)) { @@ -51,8 +52,9 @@ $datetime = strtotime ($date . ' ' . $time); $date_init_less = strtotime(date('Y-m-j')) - SECONDS_1DAY; $date_init = get_parameter('date_init', date(DATE_FORMAT, $date_init_less)); $time_init = get_parameter('time_init', date(TIME_FORMAT, $date_init_less)); -$datetime_init = strtotime ($date_init.' '.$time_init); +$datetime_init = strtotime ($date_init . ' ' . $time_init); $enable_init_date = get_parameter('enable_init_date', 0); +$pure = (int)get_parameter('pure', 0); $period = null; // Calculate new inteval for all reports @@ -63,46 +65,8 @@ if ($enable_init_date) { $period = $datetime - $datetime_init; } -$report = reporting_make_reporting_data($id_report, $date, $time, $period, 'dinamic'); -html_debug_print($report); -//---------------------------------------------------------------------- - - -// Get Report record (to get id_group) -$report = db_get_row ('treport', 'id_report', $id_report); - -// Check ACL on the report to see if user has access to the report. -if (empty($report) || ! check_acl ($config['id_user'], $report['id_group'], "RR")) { - db_pandora_audit("ACL Violation","Trying to access graph reader"); - include ("general/noaccess.php"); - exit; -} - -// Include with the functions to calculate each kind of report. -require_once ($config['homedir'] . '/include/functions_reporting.php'); -require_once ($config['homedir'] . '/include/functions_reporting_html.php'); -require_once ($config['homedir'] . '/include/functions_groups.php'); - -enterprise_include_once("include/functions_reporting.php"); - -$pure = get_parameter('pure',0); - -// Get different date to search the report. -$date = (string) get_parameter ('date', date(DATE_FORMAT)); -$time = (string) get_parameter ('time', date(TIME_FORMAT)); - -$datetime = strtotime ($date . ' ' . $time); -$report["datetime"] = $datetime; - -// Calculations in order to modify init date of the report -$date_init_less = strtotime(date('Y-m-j')) - SECONDS_1DAY; -$date_init = get_parameter('date_init', date(DATE_FORMAT, $date_init_less)); -$time_init = get_parameter('time_init', date(TIME_FORMAT, $date_init_less)); -$datetime_init = strtotime ($date_init.' '.$time_init); -$enable_init_date = get_parameter('enable_init_date', 0); - -// Standard header +//------------------- INIT HEADER -------------------------------------- $url = "index.php?sec=reporting&sec2=operation/reporting/reporting_viewer&id=$id_report&date=$date&time=$time&pure=$pure"; $options = array(); @@ -160,20 +124,27 @@ if ($config['metaconsole'] == 1 and defined('METACONSOLE')) { ui_meta_print_header(__('Reporting'), "", $options); } else { - ui_print_page_header (__('Reporting'). " » ". __('Custom reporting'). " - ".$report["name"], + ui_print_page_header ( + __('Reporting') . + " » " . + __('Custom reporting') . + " - " . + reporting_get_name($id_report), "images/op_reporting.png", false, "", false, $options); } +//------------------- END HEADER --------------------------------------- -if ($enable_init_date) { - if ($datetime_init > $datetime) { - ui_print_error_message ("Invalid date selected. Initial date must be before end date."); - } -} + + + + + +//------------------------ INIT FORM ----------------------------------- $table->id = 'controls_table'; $table->width = '99%'; $table->class = 'databox'; -if (defined("METACONSOLE")){ +if (defined("METACONSOLE")) { $table->width = '100%'; $table->class = 'databox data'; @@ -233,11 +204,13 @@ if (defined("METACONSOLE")) { $table->data[1][2] .= html_print_submit_button (__('Update'), 'date_submit', false, 'class="sub next"', true) . ' '; } else { - if ($report['description'] != '') { - $table->data[0][1] = '
'.$report['description'].'
'; + if (reporting_get_description($id_report)) { + $table->data[0][1] = '
' . + reporting_get_description($id_report) . '
'; } else { - $table->data[0][1] = '
'.$report['name'].'
'; + $table->data[0][1] = '
' . + reporting_get_name($id_report) . '
'; } $table->data[0][1] .= '
'.__('Set initial date') . html_print_checkbox('enable_init_date', 1, $enable_init_date, true); @@ -262,6 +235,34 @@ echo '
"; + + +//---------------------------------------------------------------------- + + +// Get Report record (to get id_group) +$report = db_get_row ('treport', 'id_report', $id_report); +$report["datetime"] = $datetime; + + + + + + // The rowspan of the first row is only 2 in controls table. Why is used the same code here and in the items?? $table->rowspan[0][0] = 1; From 085c4521d0a2c892676413a7cc81a23ca882177e Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Wed, 25 Mar 2015 11:22:22 +0100 Subject: [PATCH 09/80] Fixed the style of status message when edit a filter and added more information in the messages. --- .../operation/events/events_list.php | 102 +++++++++++++----- 1 file changed, 78 insertions(+), 24 deletions(-) diff --git a/pandora_console/operation/events/events_list.php b/pandora_console/operation/events/events_list.php index 071bc3c1ce..103ca95919 100644 --- a/pandora_console/operation/events/events_list.php +++ b/pandora_console/operation/events/events_list.php @@ -86,7 +86,7 @@ if (is_ajax()) { 'id_filter', 'tevent_filter', $values); if ($exists) { - echo 'error'; + echo 'duplicate'; } else { $result = db_process_sql_insert('tevent_filter', $values); @@ -664,8 +664,25 @@ else ui_toggle($events_filter, __('Event control filter'), '', !$open_filter); // Error div for ajax messages -echo "
"; +echo ""; +?> + +", - {"page" : "operation/events/events_list", - "save_event_filter" : 1, - "id_name" : $("#text-id_name").val(), - "id_group" : $("#id_group").val(), - "event_type" : $("#event_type").val(), - "severity" : $("#severity").val(), - "status" : $("#status").val(), - "search" : $("#text-search").val(), - "text_agent" : $("#text_id_agent").val(), - "pagination" : $("#pagination").val(), - "event_view_hr" : $("#text-event_view_hr").val(), - "id_user_ack" : $("#id_user_ack").val(), - "group_rep" : $("#group_rep").val(), - "tag_with": Base64.decode($("#hidden-tag_with").val()), - "tag_without": Base64.decode($("#hidden-tag_without").val()), - "filter_only_alert" : $("#filter_only_alert").val(), - "id_group_filter": $("#id_group").val() + { + "page" : "operation/events/events_list", + "save_event_filter" : 1, + "id_name" : $("#text-id_name").val(), + "id_group" : $("#id_group").val(), + "event_type" : $("#event_type").val(), + "severity" : $("#severity").val(), + "status" : $("#status").val(), + "search" : $("#text-search").val(), + "text_agent" : $("#text_id_agent").val(), + "pagination" : $("#pagination").val(), + "event_view_hr" : $("#text-event_view_hr").val(), + "id_user_ack" : $("#id_user_ack").val(), + "group_rep" : $("#group_rep").val(), + "tag_with": Base64.decode($("#hidden-tag_with").val()), + "tag_without": Base64.decode($("#hidden-tag_without").val()), + "filter_only_alert" : $("#filter_only_alert").val(), + "id_group_filter": $("#id_group").val() }, function (data) { + $(".info_box").hide(); if (data == 'error') { - $('#show_filter_error').html('

'); + $(".info_box").filter(function(i, item) { + if ($(item).data('type_info_box') == "error_create_filter") { + return true; + } + else + return false; + }).show(); + } + else if (data == 'duplicate') { + $(".info_box").filter(function(i, item) { + if ($(item).data('type_info_box') == "duplicate_create_filter") { + return true; + } + else + return false; + }).show(); } else { id_filter_save = data; - $('#show_filter_error').html('

'); + + $(".info_box").filter(function(i, item) { + if ($(item).data('type_info_box') == "success_create_filter") { + return true; + } + else + return false; + }).show(); } }); @@ -978,7 +1019,7 @@ $(document).ready( function() { // Update the info with the loaded filter $("#hidden-id_name").val($('#text-id_name').val()); $('#filter_loaded_span').html($('#filter_loaded_text').html() + ': ' + $('#text-id_name').val()); - + return false; }); @@ -1007,11 +1048,24 @@ $(document).ready( function() { "id_group_filter": $("#id_group").val() }, function (data) { + $(".info_box").hide(); if (data == 'ok') { - $('#show_filter_error').html('

'); + $(".info_box").filter(function(i, item) { + if ($(item).data('type_info_box') == "success_update_filter") { + return true; + } + else + return false; + }).show(); } else { - $('#show_filter_error').html('

'); + $(".info_box").filter(function(i, item) { + if ($(item).data('type_info_box') == "error_create_filter") { + return true; + } + else + return false; + }).show(); } }); From 9d18fd691058ba54d283bce10d17d5dba854d5d6 Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Wed, 25 Mar 2015 13:04:11 +0100 Subject: [PATCH 10/80] Fixed lost variable. --- pandora_console/include/functions_reporting.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index 1c2c5f220f..a1d91fcf2e 100644 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -246,6 +246,8 @@ function reporting_general($report, $content) { $return = array(); $return['type'] = 'general'; + $return['subtype'] = $content['group_by_agent']; + $return['resume'] = $content['show_resume']; if (empty($content['name'])) { $content['name'] = __('General'); @@ -342,7 +344,7 @@ function reporting_general($report, $content) { $return["data"][$ag_name][$mod_name] = null; } else { - if (!is_numeric($value_res)) { + if (!is_numeric($data_res[$key])) { $return["data"][$ag_name][$mod_name] = $data_res[$key]; } else { From b49b67be4da57c8738bd7310adf50ed56d81b6f7 Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Wed, 25 Mar 2015 15:25:21 +0100 Subject: [PATCH 11/80] Working in the refactoring the code of reports. --- .../include/functions_reporting_html.php | 272 +++++++----------- 1 file changed, 108 insertions(+), 164 deletions(-) diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index b38b75af84..0e2938ae0e 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -126,6 +126,7 @@ function reporting_html_print_report($report, $mini = false) { switch ($item['type']) { case 'general': + reporting_html_general($table, $item); break; case 'sql': reporting_html_sql($table, $item); @@ -138,17 +139,117 @@ function reporting_html_print_report($report, $mini = false) { if ($item['type'] == 'agent_module') echo '
'; - html_print_table ($table); + html_print_table($table); if ($item['type'] == 'agent_module') echo '
'; } } +function reporting_html_general(&$table, $item) { + + if (!empty($item["data"])) { + switch ($item['subtype']) { + case REPORT_GENERAL_NOT_GROUP_BY_AGENT: + $table1->width = '99%'; + $table1->data = array (); + $table1->head = array (); + $table1->head[0] = __('Agent'); + $table1->head[1] = __('Module'); + if ($item['date']['period'] != 0) { + $table1->head[2] = __('Operation'); + } + $table1->head[3] = __('Value'); + $table1->style[0] = 'text-align: left'; + $table1->style[1] = 'text-align: left'; + $table1->style[2] = 'text-align: left'; + $table1->style[3] = 'text-align: left'; + + foreach ($item['data'] as $row) { + $table1->data[] = array( + $row['agent'], + $row['module'], + $row['value']); + } + break; + case REPORT_GENERAL_GROUP_BY_AGENT: + $list_modules = array(); + foreach ($item['data'] as $modules) { + foreach ($modules as $name => $value) { + $list_modules[$name] = null; + } + } + $list_modules = array_keys($list_modules); + + $table1->width = '99%'; + $table1->data = array (); + $table1->head = array_merge(array(__('Agent')), $list_modules); + foreach ($item['data'] as $agent => $modules) { + $row = array(); + + $row['agent'] = $agent; + $table1->style['agent'] = 'text-align: left;'; + foreach ($list_modules as $name) { + $table1->style[$name] = 'text-align: right;'; + if (isset($modules[$name])) { + $row[$name] = $value; + } + else { + $row[$name] = "--"; + } + } + $table1->data[] = $row; + } + break; + } + + $table->colspan['data']['cell'] = 3; + $table->cellstyle['data']['cell'] = 'text-align: center;'; + $table->data['data']['cell'] = html_print_table($table1, true); + } + else { + $table->colspan['error']['cell'] = 3; + $table->data['error']['cell'] = + __('There are no Agent/Modules defined'); + } + + if ($item['resume'] && !empty($item["data"])) { + $table_summary->width = '99%'; + + $table_summary->data = array (); + $table_summary->head = array (); + $table_summary->head_colspan = array (); + $table_summary->align = array(); + + $table_summary->align[0] = 'left'; + $table_summary->align[1] = 'right'; + $table_summary->align[2] = 'right'; + $table_summary->align[3] = 'left'; + $table_summary->align[4] = 'right'; + + $table_summary->head_colspan[0] = 2; + $table_summary->head[0] = __('Min Value'); + $table_summary->head[1] = __('Average Value'); + $table_summary->head_colspan[2] = 2; + $table_summary->head[2] = __('Max Value'); + + $table_summary->data[0][0] = $item['min']['agent'] . ' - ' . $item['min']['module']; + $table_summary->data[0][1] = $item['min']['formated_value']; + $table_summary->data[0][2] = format_for_graph($item['avg_value'], 2); + $table_summary->data[0][3] = $item['max']['agent'] . ' - ' . $item['max']['module']; + $table_summary->data[0][4] = $item['max']['formated_value']; + + $table->colspan['summary_title']['cell'] = 3; + $table->data['summary_title']['cell'] = '' . __('Summary') . ''; + $table->colspan['summary_table']['cell'] = 3; + $table->data['summary_table']['cell'] = html_print_table($table_summary, true); + } +} + function reporting_html_sql(&$table, $item) { if (!$item['correct']) { - $table->colspan['chart']['cell'] = 3; - $table->data['chart']['cell'] = $item['error']; + $table->colspan['error']['cell'] = 3; + $table->data['error']['cell'] = $item['error']; } else { $first = true; @@ -169,9 +270,9 @@ function reporting_html_sql(&$table, $item) { $table2->data[] = $row; } - $table->colspan['chart']['cell'] = 3; - $table->cellstyle['chart']['cell'] = 'text-align: center;'; - $table->data['chart']['cell'] = html_print_table($table2, true); + $table->colspan['data']['cell'] = 3; + $table->cellstyle['data']['cell'] = 'text-align: center;'; + $table->data['data']['cell'] = html_print_table($table2, true); } } @@ -3064,88 +3165,6 @@ function reporting_render_report_html_item ($content, $table, $report, $mini = f $item_title = $content['name']; switch ($content["type"]) { - case 1: - case 'simple_graph': - if (empty($item_title)) { - $item_title = __('Simple graph'); - } - reporting_header_content($mini, $content, $report, $table, - $item_title, - ui_print_truncate_text($agent_name, 'agent_medium', false).'
' . - ui_print_truncate_text($module_name, 'module_medium', false)); - - //RUNNING - - $next_row = 1; - - // Put description at the end of the module (if exists) - if ($content["description"] != "") { - $data_desc = array(); - $data_desc[0] = $content["description"]; - array_push ($table->data, $data_desc); - $table->colspan[$next_row][0] = 3; - $next_row++; - } - - $table->colspan[$next_row][0] = 3; - $table->cellstyle[$next_row][0] = 'text-align: center;'; - - $data = array (); - - $moduletype_name = modules_get_moduletype_name( - modules_get_agentmodule_type( - $content['id_agent_module'])); - - $only_avg = true; - // Due to database compatibility problems, the 'only_avg' value - // is stored into the json contained into the 'style' column. - if (isset($content['style'])) { - $style_json = io_safe_output($content['style']); - $style = json_decode($style_json, true); - - if (isset($style['only_avg'])) { - $only_avg = (bool) $style['only_avg']; - } - } - - if (preg_match ("/string/", $moduletype_name)) { - - $urlImage = ui_get_full_url(false, false, false, false); - - $data[0] = grafico_modulo_string ($content['id_agent_module'], $content['period'], - false, $sizgraph_w, $sizgraph_h, '', '', false, $only_avg, false, - $report["datetime"], $only_image, $urlImage); - - } - else { - - $data[0] = grafico_modulo_sparse( - $content['id_agent_module'], - $content['period'], - false, - $sizgraph_w, - $sizgraph_h, - '', - '', - false, - $only_avg, - true, - $report["datetime"], - '', - 0, - 0, - true, - $only_image, - ui_get_full_url(false, false, false, false), - 1, - false, - '', - false, - true); - } - - array_push ($table->data, $data); - break; case 'projection_graph': if (empty($item_title)) { $item_title = __('Projection graph'); @@ -4211,82 +4230,7 @@ function reporting_render_report_html_item ($content, $table, $report, $mini = f array_push($table->data, $data); $table->colspan[$next_row][0] = 3; break; - case 'sql': - if (empty($item_title)) { - $item_title = __('SQL'); - } - reporting_header_content($mini, $content, $report, $table, $item_title, - "", ""); - - $next_row = 1; - // Put description at the end of the module (if exists) - if ($content["description"] != ""){ - $data_desc = array(); - $data_desc[0] = $content["description"]; - array_push ($table->data, $data_desc); - - $table->colspan[$next_row][0] = 3; - $next_row++; - } - - $table->colspan[$next_row][0] = 3; - - $table2->class = 'databox'; - $table2->width = '100%'; - - //Create the head - $table2->head = array(); - if ($content['header_definition'] != '') { - $table2->head = explode('|', $content['header_definition']); - } - - if ($content['treport_custom_sql_id'] != 0) { - switch ($config["dbtype"]) { - case "mysql": - $sql = io_safe_output (db_get_value_filter('`sql`', 'treport_custom_sql', array('id' => $content['treport_custom_sql_id']))); - break; - case "postgresql": - $sql = io_safe_output (db_get_value_filter('"sql"', 'treport_custom_sql', array('id' => $content['treport_custom_sql_id']))); - break; - case "oracle": - $sql = io_safe_output (db_get_value_filter('sql', 'treport_custom_sql', array('id' => $content['treport_custom_sql_id']))); - break; - } - } - else { - $sql = io_safe_output ($content['external_source']); - } - - // Do a security check on SQL coming from the user - $sql = check_sql ($sql); - - if ($sql != '') { - $result = db_get_all_rows_sql($sql); - if ($result === false) { - $result = array(); - } - - if (isset($result[0])) { - if (count($result[0]) > count($table2->head)) { - $table2->head = array_pad($table2->head, count($result[0]), ' '); - } - } - - $table2->data = array(); - foreach ($result as $row) { - array_push($table2->data, $row); - } - } - else { - $table2->data = array(); - array_push($table2->data, array("id_user" => "
[".__('Illegal query')."]
". - __('Due security restrictions, there are some tokens or words you cannot use'). - ': *, delete, drop, alter, modify, union, password, pass, insert '.__('or')." update.
")); - } - - $cellContent = html_print_table($table2, true); - array_push($table->data, array($cellContent)); - break; + case 'sql_graph_vbar': case 'sql_graph_hbar': case 'sql_graph_pie': From d17fbbc3a9c4217bc889d5f2f22ad336b1fc5721 Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Wed, 25 Mar 2015 15:30:36 +0100 Subject: [PATCH 12/80] Working in the refactoring the code of reports. --- .../include/functions_reporting_html.php | 524 ------------------ 1 file changed, 524 deletions(-) diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index 0e2938ae0e..8796910dfd 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -4860,530 +4860,6 @@ function reporting_render_report_html_item ($content, $table, $report, $mini = f case 'network_interfaces_report': reporting_network_interfaces_table($content, $report, $mini, $item_title, $table); break; - case 'general': - if (empty($item_title)) { - $item_title = __('General'); - } - reporting_header_content($mini, $content, $report, $table, $item_title); - - $group_by_agent = $content['group_by_agent']; - $order_uptodown = $content['order_uptodown']; - - $table->style[1] = 'text-align: right'; - - // Put description at the end of the module (if exists) - $table->colspan[1][0] = 3; - if ($content["description"] != "") { - $data_desc = array(); - $data_desc[0] = $content["description"]; - array_push($table->data, $data_desc); - } - - switch ($group_by_agent) { - //0 means not group by agent - case 0: - $sql = sprintf(" - SELECT id_agent_module, - server_name, operation - FROM treport_content_item - WHERE id_report_content = %d", - $content['id_rc']); - - $generals = db_process_sql ($sql); - if ($generals === false) { - $data = array (); - $table->colspan[2][0] = 3; - $data[0] = - __('There are no Agent/Modules defined'); - array_push ($table->data, $data); - break; - } - - $table1->width = '99%'; - $table1->data = array (); - $table1->head = array (); - $table1->head[0] = __('Agent'); - $table1->head[1] = __('Module'); - if ($content['period'] != 0) { - $table1->head[2] = __('Operation'); - } - $table1->head[3] = __('Value'); - $table1->style[0] = 'text-align: left'; - $table1->style[1] = 'text-align: left'; - $table1->style[2] = 'text-align: left'; - $table1->style[3] = 'text-align: left'; - - $data_res = array(); - - foreach ($generals as $key => $row) { - //Metaconsole connection - $server_name = $row ['server_name']; - if (($config ['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE')) { - $connection = metaconsole_get_connection($server_name); - if (metaconsole_load_external_db($connection) != NOERR) { - //ui_print_error_message ("Error connecting to ".$server_name); - continue; - } - } - - if (modules_is_disable_agent($row['id_agent_module'])) { - continue; - } - - $mod_name = modules_get_agentmodule_name ($row['id_agent_module']); - $ag_name = modules_get_agentmodule_agent_name ($row['id_agent_module']); - - if ($content['period'] == 0) { - $data_res[$key] = - modules_get_last_value($row['id_agent_module']); - } - else { - switch ($row['operation']) { - case 'sum': - $data_res[$key] = - reporting_get_agentmodule_data_sum( - $row['id_agent_module'], $content['period'], $report["datetime"]); - break; - case 'max': - $data_res[$key] = - reporting_get_agentmodule_data_max( - $row['id_agent_module'], $content['period']); - break; - case 'min': - $data_res[$key] = - reporting_get_agentmodule_data_min( - $row['id_agent_module'], $content['period']); - break; - case 'avg': - default: - $data_res[$key] = - reporting_get_agentmodule_data_average( - $row['id_agent_module'], $content['period']); - break; - } - } - - $unit = db_get_value('unit', 'tagente_modulo', - 'id_agente_modulo', - $row['id_agent_module']); - - $id_agent_module[$key] = $row['id_agent_module']; - $agent_name[$key] = $ag_name; - $module_name[$key] = $mod_name; - $units[$key] = $unit; - $operations[$key] = $row['operation']; - - //Restore dbconnection - if (($config ['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE')) { - metaconsole_restore_db(); - } - } - //Order by data descending, ascending or without order - if (($order_uptodown == 0) || ($order_uptodown == 1) - || ($order_uptodown == 2)) { - - - switch ($order_uptodown) { - //Descending - case 1: - array_multisort($data_res, SORT_DESC, - $agent_name, SORT_ASC, $module_name, - SORT_ASC, $id_agent_module, - SORT_ASC, $operations, SORT_ASC); - break; - //Ascending - case 2: - array_multisort($data_res, SORT_ASC, - $agent_name, SORT_ASC, $module_name, - SORT_ASC, $id_agent_module, - SORT_ASC, $operations, SORT_ASC); - break; - } - - - $i = 0; - foreach ($data_res as $d) { - $data = array(); - $data[0] = $agent_name[$i]; - $data[1] = $module_name[$i]; - - if ($content['period'] != 0) { - switch ($operations[$i]) { - case 'sum': - $op = __('Summatory'); - break; - case 'min': - $op = __('Minimal'); - break; - case 'max': - $op = __('Maximun'); - break; - case 'avg': - default: - $op = __('Rate'); - break; - } - $data[2] = $op; - } - - if ($d === false) { - $data[3] = '--'; - } - else { - if (!is_numeric($d)) { - $data[3] = $d; - } - else { - $data[3] = format_for_graph($d, 2) . " " . - $units[$i]; - } - } - array_push ($table1->data, $data); - $i++; - } - } - //Order by agent name - elseif ($order_uptodown == 3) { - array_multisort($agent_name, SORT_ASC, - $data_res, SORT_ASC, $module_name, SORT_ASC, - $id_agent_module, SORT_ASC, $operations, - SORT_ASC); - $i=0; - foreach ($agent_name as $a) { - $data = array(); - $data[0] = $agent_name[$i]; - $data[1] = $module_name[$i]; - - switch ($operations[$i]) { - case 'sum': - $op = __('Summatory'); - break; - case 'min': - $op = __('Minimal'); - break; - case 'max': - $op = __('Maximun'); - break; - case 'avg': - default: - $op = __('Average'); - break; - } - $data[2] = $op; - - - if ($data_res[$i] === false) { - $data[3] = '--'; - } - else { - $data[3] = - format_for_graph($data_res[$i], 2) - . " " . $units[$i]; - } - array_push ($table1->data, $data); - $i++; - } - } - - $table->colspan[2][0] = 3; - $data = array(); - $data[0] = html_print_table($table1, true); - array_push ($table->data, $data); - break; - //1 means group by agent - case 1: - //Get the data - $sql_data = sprintf("SELECT id_agent_module, - server_name, operation - FROM treport_content_item - WHERE id_report_content = %d", - $content['id_rc']); - $generals = db_process_sql ($sql_data); - - if ($generals === false) { - $data = array (); - $table->colspan[2][0] = 3; - $data[0] = __('There are no Agent/Modules defined'); - array_push ($table->data, $data); - break; - } - - $list_modules = array(); - $data = array(); - foreach ($generals as $g) { - //Metaconsole connection - $server_name = $g ['server_name']; - if (($config ['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE')) { - $connection = metaconsole_get_connection($server_name); - if (metaconsole_load_external_db($connection) != NOERR) { - //ui_print_error_message ("Error connecting to ".$server_name); - continue; - } - } - - if (modules_is_disable_agent($g['id_agent_module'])) { - continue; - } - - $agent_name = modules_get_agentmodule_agent_name ($g['id_agent_module']); - $module_name = modules_get_agentmodule_name ($g['id_agent_module']); - $unit = db_get_value('unit', 'tagente_modulo', 'id_agente_modulo', $g['id_agent_module']); - - - - - if ($content['period'] == 0) { - $value_res = - modules_get_last_value($g['id_agent_module']); - } - else { - switch ($g['operation']) { - case 'sum': - $value_res = reporting_get_agentmodule_data_sum ($g['id_agent_module'], $content['period'], $report["datetime"]); - break; - case 'max': - $value_res = reporting_get_agentmodule_data_max ($g['id_agent_module'], $content['period']); - break; - case 'min': - $value_res = reporting_get_agentmodule_data_min ($g['id_agent_module'], $content['period']); - break; - case 'avg': - default: - $value_res = reporting_get_agentmodule_data_average ($g['id_agent_module'], $content['period']); - break; - } - } - - if ($value_res === false) { - $data[$agent_name][$module_name] = '--'; - } - else { - if (!is_numeric($value_res)) { - $data[$agent_name][$module_name] = $value_res; - } - else { - $data[$agent_name][$module_name] = format_for_graph($value_res, 2) . " " . $unit; - } - } - - // Save the modules - $list_modules[$module_name] = null; - - // Restore dbconnection - if (($config ['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE')) { - metaconsole_restore_db(); - } - } - - $table2->width = '99%'; - $table2->data = array (); - $table2->head = array (); - $table2->head[0] = __('Agent'); - $table2->style[0] = 'text-align: left'; - $i = 1; - foreach (array_keys($list_modules) as $module) { - $table2->head[$i] = - ui_print_truncate_text($module, 20, false); - $table2->style[$i] = 'text-align: center'; - $i++; - } - - - - foreach ($data as $agent_name => $agent) { - $row = array(); - $row[] = $agent_name; - foreach (array_keys($list_modules) as $module_name) { - if (!isset($agent[$module_name])) { - $row[] = '--'; - } - else { - $row[] = $agent[$module_name]; - } - } - $table2->data[] = $row; - } - - $data = array(); - $data[0] = html_print_table($table2, true); - array_push ($table->data, $data); - break; - } - - if ($content['show_resume'] && count($generals) > 0) { - - //Get the first valid value and assign it to $min & $max - $min = false; - $min_name_agent_module = ''; - $max_name_agent_module = ''; - $min_unit = ''; - $max_unit = ''; - $i=0; - do { - //Metaconsole connection - $server_name = $generals[$i]['server_name']; - if (($config ['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE')) { - $connection = metaconsole_get_connection($server_name); - if (metaconsole_load_external_db($connection) != NOERR) { - //ui_print_error_message ("Error connecting to ".$server_name); - continue; - } - } - - if ($content['period'] == 0) { - $min = - modules_get_last_value($generals[$i]['id_agent_module']); - } - else { - switch ($generals[$i]['operation']) { - case 'sum': - $min = reporting_get_agentmodule_data_sum ($generals[$i]['id_agent_module'], $content['period'], $report["datetime"]); - break; - case 'max': - $min = reporting_get_agentmodule_data_max ($generals[$i]['id_agent_module'], $content['period']); - break; - case 'min': - $min = reporting_get_agentmodule_data_min ($generals[$i]['id_agent_module'], $content['period']); - break; - case 'avg': - default: - $min = reporting_get_agentmodule_data_average ($generals[$i]['id_agent_module'], $content['period']); - break; - } - } - $i++; - - $min_name_agent_module = - modules_get_agentmodule_name($generals[$i]['id_agent_module']) . - " - " . - modules_get_agentmodule_agent_name($generals[$i]['id_agent_module']) . - " (" . $generals[$i]['operation'] . ")"; - - $min_unit = db_get_value('unit', 'tagente_modulo', 'id_agente_modulo', $generals[$i]['id_agent_module']); - - //Restore dbconnection - if (($config ['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE')) { - metaconsole_restore_db(); - } - } - while ($min === false && $i < count($generals)); - - $max = $min; - $max_name_agent_module = $min_name_agent_module; - $max_unit = $min_unit; - $avg = 0; - $length = 0; - - if ($generals === false) { - $generals = array(); - } - - foreach ($generals as $g) { - //Metaconsole connection - $server_name = $g['server_name']; - if (($config ['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE')) { - $connection = metaconsole_get_connection($server_name); - if (metaconsole_load_external_db($connection) != NOERR) { - //ui_print_error_message ("Error connecting to ".$server_name); - continue; - } - } - - if ($content['period'] == 0) { - $value = - modules_get_last_value($g['id_agent_module']); - } - else { - switch ($g['operation']) { - case 'sum': - $value = reporting_get_agentmodule_data_sum ($g['id_agent_module'], $content['period'], $report["datetime"]); - break; - case 'max': - $value = reporting_get_agentmodule_data_max ($g['id_agent_module'], $content['period']); - break; - case 'min': - $value = reporting_get_agentmodule_data_min ($g['id_agent_module'], $content['period']); - break; - case 'avg': - default: - $value = reporting_get_agentmodule_data_average ($g['id_agent_module'], $content['period']); - break; - } - } - - if ($value !== false) { - if ($value > $max) { - $max = $value; - $max_name_agent_module = - modules_get_agentmodule_name($g['id_agent_module']) . - " - " . - modules_get_agentmodule_agent_name($g['id_agent_module']) . - " (" . $g['operation'] . ")"; - $max_unit = db_get_value('unit', 'tagente_modulo', 'id_agente_modulo', $g['id_agent_module']); - } - if ($value < $min ) { - $min = $value; - $min_name_agent_module = - modules_get_agentmodule_name($g['id_agent_module']) . - " - " . - modules_get_agentmodule_agent_name($g['id_agent_module']) . - " (" . $g['operation'] . ")"; - $min_unit = db_get_value('unit', 'tagente_modulo', 'id_agente_modulo', $g['id_agent_module']); - } - $avg += $value; - $length++; - } - - //Restore dbconnection - if (($config ['metaconsole'] == 1) - && $server_name != '' - && defined('METACONSOLE')) { - metaconsole_restore_db(); - } - } - if ($length == 0) { - $avg = 0; - } - else { - $avg = $avg / $length; - } - - unset($table_summary); - $table_summary->width = '99%'; - - $table_summary->data = array (); - $table_summary->head = array (); - $table_summary->head_colspan = array (); - $table_summary->align = array(); - - $table_summary->align[0] = 'left'; - $table_summary->align[1] = 'left'; - $table_summary->align[2] = 'left'; - $table_summary->align[3] = 'left'; - $table_summary->align[4] = 'left'; - - $table_summary->head_colspan[0] = 2; - $table_summary->head[0] = __('Min Value'); - $table_summary->head[1] = __('Average Value'); - $table_summary->head_colspan[2] = 2; - $table_summary->head[2] = __('Max Value'); - - $table_summary->data[0][0] = $min_name_agent_module; - $table_summary->data[0][1] = format_for_graph($min,2) . ' ' . $min_unit; - $table_summary->data[0][2] = format_for_graph($avg,2); - $table_summary->data[0][3] = $max_name_agent_module; - $table_summary->data[0][4] = format_for_graph($max,2) . ' ' . $max_unit; - - $table->colspan[3][0] = 3; - array_push ($table->data, - array('' . __('Summary') . '')); - $table->colspan[4][0] = 3; - array_push ($table->data, - array(html_print_table($table_summary, true))); - } - break; - - case 'top_n': $top_n = $content['top_n']; From 803c03956df66da04edf323d1f7b644297cf9856 Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Wed, 25 Mar 2015 16:44:39 +0100 Subject: [PATCH 13/80] Working in the refactoring the code of reports (custom_graph). --- pandora_console/include/constants.php | 2 + .../include/functions_reporting.php | 228 ++++++++++++++++-- .../include/functions_reporting_html.php | 171 +------------ 3 files changed, 219 insertions(+), 182 deletions(-) diff --git a/pandora_console/include/constants.php b/pandora_console/include/constants.php index 71349caf48..1e9b45791a 100755 --- a/pandora_console/include/constants.php +++ b/pandora_console/include/constants.php @@ -378,6 +378,8 @@ define('REPORT_OLD_TYPE_SUMATORY', 10); define('REPORT_GENERAL_NOT_GROUP_BY_AGENT', 0); define('REPORT_GENERAL_GROUP_BY_AGENT', 1); +define('REPORTING_CUSTOM_GRAPH_LEGEND_EACH_MODULE_VERTICAL_SIZE', 15); + /* POLICIES */ define("POLICY_UPDATED", 0); diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index a1d91fcf2e..7060a974a8 100644 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -158,6 +158,16 @@ function reporting_make_reporting_data($id_report, $date, $time, $report, $content); break; + case 'custom_graph': + case 'automatic_custom_graph': + $report['contents'][] = + reporting_custom_graph( + $report, + $content, + $type, + $force_width_chart, + $force_height_chart); + break; } } @@ -486,6 +496,72 @@ function reporting_general($report, $content) { return reporting_check_structure_content($return); } +function reporting_custom_graph($report, $content, $type = 'dinamic', + $force_width_chart = null, $force_height_chart = null) { + + global $config; + + require_once ($config["homedir"] . '/include/functions_graph.php'); + + $graph = db_get_row ("tgraph", "id_graph", $content['id_gs']); + + $return = array(); + $return['type'] = 'custom_graph'; + + if (empty($content['name'])) { + $content['name'] = __('Simple graph'); + } + + $return['title'] = $content['name']; + $return['subtitle'] = $graph['name']; + $return["description"] = $content["description"]; + $return["date"] = reporting_get_date_text( + $report, + $content); + + $graphs = db_get_all_rows_field_filter ("tgraph_source", + "id_graph", $content['id_gs']); + $modules = array (); + $weights = array (); + if ($graphs === false) + $graphs = array(); + + foreach ($graphs as $graph_item) { + array_push ($modules, $graph_item['id_agent_module']); + array_push ($weights, $graph_item["weight"]); + } + + $return['chart'] = ''; + // Get chart + reporting_set_conf_charts($width, $height, $only_image, $type, $content); + + $height += count($modules) * REPORTING_CUSTOM_GRAPH_LEGEND_EACH_MODULE_VERTICAL_SIZE; + + switch ($type) { + case 'dinamic': + case 'static': + $return['chart'] = graphic_combined_module( + $modules, + $weights, + $content['period'], + $width, $height, + 'Combined%20Sample%20Graph', + '', + 0, + 0, + 0, + $graph["stacked"], + $report["datetime"], + $only_image, + ui_get_full_url(false, false, false, false)); + break; + case 'data': + break; + } + + return reporting_check_structure_content($return); +} + function reporting_simple_graph($report, $content, $type = 'dinamic', $force_width_chart = null, $force_height_chart = null) { @@ -526,26 +602,7 @@ function reporting_simple_graph($report, $content, $type = 'dinamic', $return['chart'] = ''; // Get chart - switch ($type) { - case 'dinamic': - $only_image = false; - $width = 900; - $height = 230; - break; - case 'static': - $only_image = true; - if ($content['style']['show_in_landscape']) { - $height = 1100; - $width = 1700; - } - else { - $height = 360; - $width = 780; - } - break; - case 'data': - break; - } + reporting_set_conf_charts($width, $height, $only_image, $type, $content); if (!empty($force_width_chart)) { $width = $force_width_chart; @@ -675,6 +732,32 @@ function reporting_check_structure_content($report) { return $report; } +function reporting_set_conf_charts(&$width, &$height, &$only_image, $type, $content) { + switch ($type) { + case 'dinamic': + $only_image = false; + $width = 900; + $height = 230; + break; + case 'static': + $only_image = true; + if ($content['style']['show_in_landscape']) { + $height = 1100; + $width = 1700; + } + else { + $height = 360; + $width = 780; + } + break; + case 'data': + break; + } +} + +//////////////////////////////////////////////////////////////////////// +// MAYBE MOVE THE NEXT FUNCTIONS TO A FILE NAMED AS FUNCTION_REPORTING.UTILS.PHP // +//////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// /** @@ -1271,4 +1354,109 @@ function reporting_get_stats_users($data) { return $output; } + +/** + * Get the average value of an agent module in a period of time. + * + * @param int Agent module id + * @param int Period of time to check (in seconds) + * @param int Top date to check the values. Default current time. + * + * @return float The average module value in the interval. + */ +function reporting_get_agentmodule_data_average ($id_agent_module, $period=0, $date = 0) { + global $config; + + // Initialize variables + if (empty ($date)) $date = get_system_time (); + $datelimit = $date - $period; + + $search_in_history_db = db_search_in_history_db($datelimit); + + $id_module_type = modules_get_agentmodule_type ($id_agent_module); + $module_type = modules_get_moduletype_name ($id_module_type); + $uncompressed_module = is_module_uncompressed ($module_type); + + // Get module data + $interval_data = db_get_all_rows_sql ('SELECT * + FROM tagente_datos + WHERE id_agente_modulo = ' . (int) $id_agent_module . + ' AND utimestamp > ' . (int) $datelimit . + ' AND utimestamp < ' . (int) $date . + ' ORDER BY utimestamp ASC', $search_in_history_db); + if ($interval_data === false) $interval_data = array (); + + // Uncompressed module data + if ($uncompressed_module) { + $min_necessary = 1; + + // Compressed module data + } + else { + // Get previous data + $previous_data = modules_get_previous_data ($id_agent_module, $datelimit); + if ($previous_data !== false) { + $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) { + $next_data['utimestamp'] = $date; + array_push ($interval_data, $next_data); + } + else if (count ($interval_data) > 0) { + // Propagate the last known data to the end of the interval + $next_data = array_pop ($interval_data); + array_push ($interval_data, $next_data); + $next_data['utimestamp'] = $date; + array_push ($interval_data, $next_data); + } + + $min_necessary = 2; + } + + if (count ($interval_data) < $min_necessary) { + return false; + } + + // Set initial conditions + $total = 0; + $count = 0; + if (! $uncompressed_module) { + $previous_data = array_shift ($interval_data); + + // Do not count the empty start of an interval as 0 + if ($previous_data['utimestamp'] != $datelimit) { + $period = $date - $previous_data['utimestamp']; + } + } + foreach ($interval_data as $data) { + if (! $uncompressed_module) { + $total += $previous_data['datos'] * ($data['utimestamp'] - $previous_data['utimestamp']); + $previous_data = $data; + } + else { + $total += $data['datos']; + $count++; + } + } + + // Compressed module data + if (! $uncompressed_module) { + if ($period == 0) { + return 0; + } + + return $total / $period; + } + + // Uncompressed module data + if ($count == 0) { + return 0; + } + + return $total / $count; +} ?> \ No newline at end of file diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index 8796910dfd..1866fa4b9c 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -134,6 +134,9 @@ function reporting_html_print_report($report, $mini = false) { case 'simple_graph': reporting_html_simple_graph($table, $item); break; + case 'custom_graph': + reporting_html_custom_graph($table, $item); + break; } if ($item['type'] == 'agent_module') @@ -276,116 +279,18 @@ function reporting_html_sql(&$table, $item) { } } +function reporting_html_custom_graph(&$table, $item) { + $table->colspan['chart']['cell'] = 3; + $table->cellstyle['chart']['cell'] = 'text-align: center;'; + $table->data['chart']['cell'] = $item['chart']; +} + function reporting_html_simple_graph(&$table, $item) { $table->colspan['chart']['cell'] = 3; $table->cellstyle['chart']['cell'] = 'text-align: center;'; $table->data['chart']['cell'] = $item['chart']; } -/** - * Get the average value of an agent module in a period of time. - * - * @param int Agent module id - * @param int Period of time to check (in seconds) - * @param int Top date to check the values. Default current time. - * - * @return float The average module value in the interval. - */ -function reporting_get_agentmodule_data_average ($id_agent_module, $period=0, $date = 0) { - global $config; - - // Initialize variables - if (empty ($date)) $date = get_system_time (); - $datelimit = $date - $period; - - $search_in_history_db = db_search_in_history_db($datelimit); - - $id_module_type = modules_get_agentmodule_type ($id_agent_module); - $module_type = modules_get_moduletype_name ($id_module_type); - $uncompressed_module = is_module_uncompressed ($module_type); - - // Get module data - $interval_data = db_get_all_rows_sql ('SELECT * - FROM tagente_datos - WHERE id_agente_modulo = ' . (int) $id_agent_module . - ' AND utimestamp > ' . (int) $datelimit . - ' AND utimestamp < ' . (int) $date . - ' ORDER BY utimestamp ASC', $search_in_history_db); - if ($interval_data === false) $interval_data = array (); - - // Uncompressed module data - if ($uncompressed_module) { - $min_necessary = 1; - - // Compressed module data - } - else { - // Get previous data - $previous_data = modules_get_previous_data ($id_agent_module, $datelimit); - if ($previous_data !== false) { - $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) { - $next_data['utimestamp'] = $date; - array_push ($interval_data, $next_data); - } - else if (count ($interval_data) > 0) { - // Propagate the last known data to the end of the interval - $next_data = array_pop ($interval_data); - array_push ($interval_data, $next_data); - $next_data['utimestamp'] = $date; - array_push ($interval_data, $next_data); - } - - $min_necessary = 2; - } - - if (count ($interval_data) < $min_necessary) { - return false; - } - - // Set initial conditions - $total = 0; - $count = 0; - if (! $uncompressed_module) { - $previous_data = array_shift ($interval_data); - - // Do not count the empty start of an interval as 0 - if ($previous_data['utimestamp'] != $datelimit) { - $period = $date - $previous_data['utimestamp']; - } - } - foreach ($interval_data as $data) { - if (! $uncompressed_module) { - $total += $previous_data['datos'] * ($data['utimestamp'] - $previous_data['utimestamp']); - $previous_data = $data; - } - else { - $total += $data['datos']; - $count++; - } - } - - // Compressed module data - if (! $uncompressed_module) { - if ($period == 0) { - return 0; - } - - return $total / $period; - } - - // Uncompressed module data - if ($count == 0) { - return 0; - } - - return $total / $count; -} /** * Get the maximum value of an agent module in a period of time. @@ -3299,64 +3204,6 @@ function reporting_render_report_html_item ($content, $table, $report, $mini = f array_push ($table->data, $data); - break; - - case 2: - case 'custom_graph': - case 'automatic_custom_graph': - $graph = db_get_row ("tgraph", "id_graph", $content['id_gs']); - - if (empty($item_title)) { - $item_title = __('Custom graph'); - } - reporting_header_content($mini, $content, $report, $table, $item_title, - ui_print_truncate_text($graph['name'], 'item_title', false)); - - //RUNNING - // Put description at the end of the module (if exists) - - $table->colspan[2][0] = 3; - if ($content["description"] != "") { - $data_desc = array(); - $data_desc[0] = $content["description"]; - array_push ($table->data, $data_desc); - } - - $result = db_get_all_rows_field_filter ("tgraph_source", - "id_graph", $content['id_gs']); - $modules = array (); - $weights = array (); - if ($result === false) - $result = array(); - - foreach ($result as $content2) { - array_push ($modules, $content2['id_agent_module']); - array_push ($weights, $content2["weight"]); - } - - // Increase the height to fix the leyend rise - $sizgraph_h += count($modules) * 15; - - $table->colspan[1][0] = 3; - $data = array(); - - require_once ($config["homedir"] . '/include/functions_graph.php'); - $data[0] = graphic_combined_module( - $modules, - $weights, - $content['period'], - $sizgraph_w, $sizgraph_h, - 'Combined%20Sample%20Graph', - '', - 0, - 0, - 0, - $graph["stacked"], - $report["datetime"], - $only_image, - ui_get_full_url(false, false, false, false)); - array_push ($table->data, $data); - break; case 'SLA_monthly': if (function_exists("reporting_enterprise_sla_monthly")) From bc791ad3be871dff0b68f1504e7c785a0da7f3e5 Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Wed, 25 Mar 2015 16:58:53 +0100 Subject: [PATCH 14/80] Working in the refactoring the code of reports (text). --- .../include/functions_reporting.php | 25 ++++++++++++++++ .../include/functions_reporting_html.php | 29 ++++++------------- 2 files changed, 34 insertions(+), 20 deletions(-) diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index 7060a974a8..c0ea835def 100644 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -168,12 +168,37 @@ function reporting_make_reporting_data($id_report, $date, $time, $force_width_chart, $force_height_chart); break; + case 'text': + $report['contents'][] = reporting_text( + $report, + $content); + break; } } return reporting_check_structure_report($report); } +function reporting_text($report, $content) { + + global $config; + + $return = array(); + $return['type'] = 'text'; + + if (empty($content['name'])) { + $content['name'] = __('Text'); + } + + $return['title'] = $content['name']; + $return["description"] = $content["description"]; + $return["date"] = reporting_get_date_text(); + + $return["data"] = html_entity_decode($content['text']); + + return reporting_check_structure_content($return); +} + function reporting_sql($report, $content) { global $config; diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index 1866fa4b9c..41292da094 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -137,6 +137,9 @@ function reporting_html_print_report($report, $mini = false) { case 'custom_graph': reporting_html_custom_graph($table, $item); break; + case 'text': + reporting_html_text($table, $item); + break; } if ($item['type'] == 'agent_module') @@ -149,6 +152,12 @@ function reporting_html_print_report($report, $mini = false) { } } +function reporting_html_text(&$table, $item) { + $table->colspan['data']['cell'] = 3; + $table->cellstyle['data']['cell'] = 'text-align: left;'; + $table->data['data']['cell'] = $item['data']; +} + function reporting_html_general(&$table, $item) { if (!empty($item["data"])) { @@ -4057,26 +4066,6 @@ function reporting_render_report_html_item ($content, $table, $report, $mini = f array_push ($table->data, $data); } break; - case 'text': - if (empty($item_title)) { - $item_title = __('Text'); - } - reporting_header_content($mini, $content, $report, $table, $item_title, - "", ""); - - $next_row = 1; - - if ($content["description"] != ""){ - $data_desc = array(); - $data_desc[0] = $content["description"]; - array_push ($table->data, $data_desc); - $table->colspan[$next_row][0] = 3; - $next_row++; - } - $data[0] = html_entity_decode($content['text']); - array_push($table->data, $data); - $table->colspan[$next_row][0] = 3; - break; case 'sql_graph_vbar': case 'sql_graph_hbar': From 958b9c8ce37a059da2b0464faef751390e8ea5b6 Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Wed, 25 Mar 2015 17:19:13 +0100 Subject: [PATCH 15/80] Working in the refactoring the code of reports (url). --- .../include/functions_reporting.php | 40 +++++++++++++++ .../include/functions_reporting_html.php | 49 ++++++++----------- 2 files changed, 60 insertions(+), 29 deletions(-) diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index c0ea835def..f362bddaef 100644 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -173,12 +173,52 @@ function reporting_make_reporting_data($id_report, $date, $time, $report, $content); break; + case 'url': + $report['contents'][] = reporting_url( + $report, + $content, + $type); + break; } } return reporting_check_structure_report($report); } +function reporting_url($report, $content, $type = 'dinamic') { + global $config; + + $return = array(); + $return['type'] = 'url'; + + if (empty($content['name'])) { + $content['name'] = __('Url'); + } + + $return['title'] = $content['name']; + $return["description"] = $content["description"]; + $return["date"] = reporting_get_date_text(); + + $return["url"] = $content["external_source"]; + + switch ($type) { + case 'dinamic': + $return["data"] = null; + break; + case 'data': + case 'static': + $curlObj = curl_init(); + curl_setopt($curlObj, CURLOPT_URL, $content['external_source']); + curl_setopt($curlObj, CURLOPT_RETURNTRANSFER, 1); + $output = curl_exec($curlObj); + curl_close($curlObj); + $return["data"] = $output; + break; + } + + return reporting_check_structure_content($return); +} + function reporting_text($report, $content) { global $config; diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index 41292da094..6ec0ee794c 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -97,7 +97,7 @@ function reporting_html_header(&$table, $mini, $title, $subtitle, function reporting_html_print_report($report, $mini = false) { - foreach ($report['contents'] as $item) { + foreach ($report['contents'] as $key => $item) { $table->size = array (); $table->style = array (); $table->width = '98%'; @@ -140,6 +140,9 @@ function reporting_html_print_report($report, $mini = false) { case 'text': reporting_html_text($table, $item); break; + case 'url': + reporting_html_url($table, $item, $key); + break; } if ($item['type'] == 'agent_module') @@ -152,6 +155,21 @@ function reporting_html_print_report($report, $mini = false) { } } +function reporting_html_url(&$table, $item, $key) { + $table->colspan['data']['cell'] = 3; + $table->cellstyle['data']['cell'] = 'text-align: left;'; + $table->data['data']['cell'] = ' + '; + // TODO: make this dynamic and get the height if the iframe to resize this item + $table->data['data']['cell'] .= ' + '; +} + function reporting_html_text(&$table, $item) { $table->colspan['data']['cell'] = 3; $table->cellstyle['data']['cell'] = 'text-align: left;'; @@ -4356,34 +4374,7 @@ function reporting_render_report_html_item ($content, $table, $report, $mini = f $data[0] = reporting_alert_reporting_agent ($content['id_agent'], $content['period'], $report["datetime"], true); array_push ($table->data, $data); break; - case 'url': - if (empty($item_title)) { - $item_title = __('Import text from URL'); - } - reporting_header_content($mini, $content, $report, $table, $item_title, - ui_print_truncate_text($content["external_source"], 'description', false)); - - $next_row = 1; - // Put description at the end of the module (if exists) - if ($content["description"] != "") { - $data_desc = array(); - $data_desc[0] = $content["description"]; - array_push ($table->data, $data_desc); - $table->colspan[$next_row][0] = 3; - $next_row++; - } - - $data = array(); - $table->colspan[$next_row][0] = 3; - $data[0] = ''; - // TODO: make this dynamic and get the height if the iframe to resize this item - $data[0] .= ''; - - array_push ($table->data, $data); - break; + case 'database_serialized': if (empty($item_title)) { $item_title = __('Serialize data'); From 13e78e44eb5fa888058c478ae29e7f44ae59b178 Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Wed, 25 Mar 2015 18:14:05 +0100 Subject: [PATCH 16/80] Working in the refactoring the code of reports (max_value). --- .../include/functions_reporting.php | 30 +++++++++++ .../include/functions_reporting_html.php | 50 ++++++++----------- 2 files changed, 50 insertions(+), 30 deletions(-) diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index f362bddaef..880fe0ef97 100644 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -179,12 +179,42 @@ function reporting_make_reporting_data($id_report, $date, $time, $content, $type); break; + case 'max_value': + $report['contents'][] = reporting_max_value( + $report, + $content); + break; } } return reporting_check_structure_report($report); } +function reporting_max_value($report, $content) { + global $config; + + $return = array(); + $return['type'] = 'max_value'; + + if (empty($content['name'])) { + $content['name'] = __('Max. Value'); + } + + $return['title'] = $content['name']; + $return["description"] = $content["description"]; + $return["date"] = reporting_get_date_text(); + + $value = reporting_get_agentmodule_data_max ($content['id_agent_module'], $content['period'], $report["datetime"]); + + $unit = db_get_value('unit', 'tagente_modulo', 'id_agente_modulo', $content ['id_agent_module']); + + $return['data'] = array( + 'value' => $value, + 'formated_value' => format_for_graph($value, 2) . " " . $unit); + + return reporting_check_structure_content($return); +} + function reporting_url($report, $content, $type = 'dinamic') { global $config; diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index 6ec0ee794c..c10aab2016 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -143,6 +143,9 @@ function reporting_html_print_report($report, $mini = false) { case 'url': reporting_html_url($table, $item, $key); break; + case 'max_value': + reporting_html_max_value($table, $item, $mini); + break; } if ($item['type'] == 'agent_module') @@ -155,6 +158,22 @@ function reporting_html_print_report($report, $mini = false) { } } +function reporting_html_max_value($table, $item, $mini) { + if ($mini) { + $font_size = '1.5'; + } + else { + $font_size = '3'; + } + + $table->colspan['data']['cell'] = 3; + $table->cellstyle['data']['cell'] = 'text-align: left;'; + $table->data['data']['cell'] = + '

' . + $item['data']['formated_value'] . + '

'; +} + function reporting_html_url(&$table, $item, $key) { $table->colspan['data']['cell'] = 3; $table->cellstyle['data']['cell'] = 'text-align: left;'; @@ -3851,36 +3870,7 @@ function reporting_render_report_html_item ($content, $table, $report, $mini = f array_push ($table->data, $data); break; - case 8: - case 'max_value': - if (empty($item_title)) { - $item_title = __('Max. Value'); - } - reporting_header_content($mini, $content, $report, $table, $item_title, - ui_print_truncate_text($agent_name, 'agent_medium', false) . - '
' . ui_print_truncate_text($module_name, 'module_medium', false)); - - //RUNNING - - // Put description at the end of the module (if exists) - $table->colspan[1][0] = 3; - if ($content["description"] != ""){ - $data_desc = array(); - $data_desc[0] = $content["description"]; - array_push ($table->data, $data_desc); - } - - $data = array (); - $table->colspan[2][0] = 3; - - $value = reporting_get_agentmodule_data_max ($content['id_agent_module'], $content['period'], $report["datetime"]); - - $unit = db_get_value('unit', 'tagente_modulo', 'id_agente_modulo', $content ['id_agent_module']); - $data[0] = '

' . - format_for_graph($value, 2) . " " . $unit .'

'; - array_push ($table->data, $data); - - break; + case 9: case 'min_value': if (empty($item_title)) { From 4924556a2163bbc92917d8851de548dd93b42dbb Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Wed, 25 Mar 2015 18:28:58 +0100 Subject: [PATCH 17/80] Working in the refactoring the code of reports (fixed max_value, added min_value and avg_value). --- .../include/functions_reporting.php | 75 +++++++++++++--- .../include/functions_reporting_html.php | 87 ++++--------------- 2 files changed, 83 insertions(+), 79 deletions(-) diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index 880fe0ef97..e2823d7cf4 100644 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -180,9 +180,22 @@ function reporting_make_reporting_data($id_report, $date, $time, $type); break; case 'max_value': - $report['contents'][] = reporting_max_value( + $report['contents'][] = reporting_value( $report, - $content); + $content, + 'max'); + break; + case 'avg_value': + $report['contents'][] = reporting_value( + $report, + $content, + 'avg'); + break; + case 'min_value': + $report['contents'][] = reporting_value( + $report, + $content, + 'min'); break; } } @@ -190,21 +203,61 @@ function reporting_make_reporting_data($id_report, $date, $time, return reporting_check_structure_report($report); } -function reporting_max_value($report, $content) { +function reporting_value($report, $content, $type) { global $config; $return = array(); - $return['type'] = 'max_value'; - - if (empty($content['name'])) { - $content['name'] = __('Max. Value'); + switch ($type) { + case 'max': + $return['type'] = 'max_value'; + break; + case 'min': + $return['type'] = 'min_value'; + break; + case 'avg': + $return['type'] = 'avg_value'; + break; } - $return['title'] = $content['name']; - $return["description"] = $content["description"]; - $return["date"] = reporting_get_date_text(); - $value = reporting_get_agentmodule_data_max ($content['id_agent_module'], $content['period'], $report["datetime"]); + if (empty($content['name'])) { + switch ($type) { + case 'max': + $content['name'] = __('Max. Value'); + break; + case 'min': + $content['name'] = __('Min. Value'); + break; + case 'avg': + $content['name'] = __('AVG. Value'); + break; + } + } + + $module_name = io_safe_output( + modules_get_agentmodule_name($content['id_agent_module'])); + $agent_name = io_safe_output( + modules_get_agentmodule_agent_name ($content['id_agent_module'])); + + $return['title'] = $content['name']; + $return['subtitle'] = $agent_name . " - " . $module_name; + $return["description"] = $content["description"]; + $return["date"] = reporting_get_date_text($report, $content); + + switch ($type) { + case 'max': + $value = reporting_get_agentmodule_data_max( + $content['id_agent_module'], $content['period'], $report["datetime"]); + break; + case 'min': + $value = reporting_get_agentmodule_data_min( + $content['id_agent_module'], $content['period'], $report["datetime"]); + break; + case 'avg': + $value = reporting_get_agentmodule_data_average( + $content['id_agent_module'], $content['period'], $report["datetime"]); + break; + } $unit = db_get_value('unit', 'tagente_modulo', 'id_agente_modulo', $content ['id_agent_module']); diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index c10aab2016..26b530878c 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -146,6 +146,12 @@ function reporting_html_print_report($report, $mini = false) { case 'max_value': reporting_html_max_value($table, $item, $mini); break; + case 'avg_value': + reporting_html_avg_value($table, $item, $mini); + break; + case 'min_value': + reporting_html_min_value($table, $item, $mini); + break; } if ($item['type'] == 'agent_module') @@ -158,7 +164,19 @@ function reporting_html_print_report($report, $mini = false) { } } -function reporting_html_max_value($table, $item, $mini) { +function reporting_html_avg_value(&$table, $item, $mini) { + reporting_html_value($table, $item, $mini); +} + +function reporting_html_max_value(&$table, $item, $mini) { + reporting_html_value($table, $item, $mini); +} + +function reporting_html_min_value(&$table, $item, $mini) { + reporting_html_value($table, $item, $mini); +} + +function reporting_html_value(&$table, $item, $mini) { if ($mini) { $font_size = '1.5'; } @@ -3836,75 +3854,8 @@ function reporting_render_report_html_item ($content, $table, $report, $mini = f $data[1] .= html_print_image("images/module_critical.png", true) . ' ' .__('Not OK') . ': ' .$monitor_value.' % ' . '

'; array_push ($table->data, $data); - break; - case 7: - case 'avg_value': - if (empty($item_title)) { - $item_title = __('Avg. Value'); - } - reporting_header_content($mini, $content, $report, $table, $item_title, - ui_print_truncate_text($agent_name, 'agent_medium', false) . - '
'.ui_print_truncate_text($module_name, 'module_medium', false)); - - //RUNNING - - // Put description at the end of the module (if exists) - $table->colspan[1][0] = 3; - if ($content["description"] != "") { - $data_desc = array(); - $data_desc[0] = $content["description"]; - array_push ($table->data, $data_desc); - } - - $data = array (); - $table->colspan[2][0] = 3; - $unit = db_get_value('unit', 'tagente_modulo', 'id_agente_modulo', $content['id_agent_module']); - $value = reporting_get_agentmodule_data_average ($content['id_agent_module'], $content['period'], $report["datetime"]); - if ($value === false) { - $value = __('Unknown'); - } - else { - $value = format_for_graph($value, 2) . " " . $unit; - } - $data[0] = '

'.$value.'

'; - array_push ($table->data, $data); - break; - case 9: - case 'min_value': - if (empty($item_title)) { - $item_title = __('Min. Value'); - } - reporting_header_content($mini, $content, $report, $table, $item_title, - ui_print_truncate_text($agent_name, 'agent_medium', false) . - '
'.ui_print_truncate_text($module_name, 'module_medium', false)); - - //RUNNING - - // Put description at the end of the module (if exists) - $table->colspan[1][0] = 3; - if ($content["description"] != "") { - $data_desc = array(); - $data_desc[0] = $content["description"]; - array_push ($table->data, $data_desc); - } - - $data = array (); - $table->colspan[2][0] = 3; - - $value = reporting_get_agentmodule_data_min ($content['id_agent_module'], $content['period'], $report["datetime"]); - $unit = db_get_value('unit', 'tagente_modulo', 'id_agente_modulo', $content ['id_agent_module']); - if ($value === false) { - $value = __('Unknown'); - } - else { - $value = format_for_graph($value, 2) . " " . $unit; - } - $data[0] = '

'.$value.'

'; - array_push ($table->data, $data); - - break; case 10: case 'sumatory': if (empty($item_title)) { From 1a6a5539c1a6b41bff11bfc2f7c3575f33c04ce6 Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Thu, 26 Mar 2015 11:29:10 +0100 Subject: [PATCH 18/80] Working in the refactoring the code of reports (summatory). --- .../include/functions_reporting.php | 16 +++++++ .../include/functions_reporting_html.php | 46 +++---------------- 2 files changed, 23 insertions(+), 39 deletions(-) diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index e2823d7cf4..8b82ba881d 100644 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -197,6 +197,12 @@ function reporting_make_reporting_data($id_report, $date, $time, $content, 'min'); break; + case 'sumatory': + $report['contents'][] = reporting_value( + $report, + $content, + 'sum'); + break; } } @@ -217,6 +223,9 @@ function reporting_value($report, $content, $type) { case 'avg': $return['type'] = 'avg_value'; break; + case 'sum': + $return['type'] = 'sumatory'; + break; } @@ -231,6 +240,9 @@ function reporting_value($report, $content, $type) { case 'avg': $content['name'] = __('AVG. Value'); break; + case 'sum': + $content['name'] = __('Summatory'); + break; } } @@ -257,6 +269,10 @@ function reporting_value($report, $content, $type) { $value = reporting_get_agentmodule_data_average( $content['id_agent_module'], $content['period'], $report["datetime"]); break; + case 'sum': + $value = reporting_get_agentmodule_data_sum( + $content['id_agent_module'], $content['period'], $report["datetime"]); + break; } $unit = db_get_value('unit', 'tagente_modulo', 'id_agente_modulo', $content ['id_agent_module']); diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index 26b530878c..869e4b94ed 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -152,6 +152,9 @@ function reporting_html_print_report($report, $mini = false) { case 'min_value': reporting_html_min_value($table, $item, $mini); break; + case 'sumatory': + reporting_html_sum_value($table, $item, $mini); + break; } if ($item['type'] == 'agent_module') @@ -164,6 +167,10 @@ function reporting_html_print_report($report, $mini = false) { } } +function reporting_html_sum_value(&$table, $item, $mini) { + reporting_html_value($table, $item, $mini); +} + function reporting_html_avg_value(&$table, $item, $mini) { reporting_html_value($table, $item, $mini); } @@ -3856,45 +3863,6 @@ function reporting_render_report_html_item ($content, $table, $report, $mini = f break; - case 10: - case 'sumatory': - if (empty($item_title)) { - $item_title = __('Summatory'); - } - reporting_header_content($mini, $content, $report, $table, $item_title, - ui_print_truncate_text($agent_name, 'agent_medium', false) . - '
' . ui_print_truncate_text($module_name, 'module_medium', false)); - - //RUNNING - - $next_row = 1; - - // Put description at the end of the module (if exists) - if ($content["description"] != "") { - $data_desc = array(); - $data_desc[0] = $content["description"]; - array_push ($table->data, $data_desc); - $table->colspan[$next_row][0] = 3; - $next_row++; - } - - $table->colspan[$next_row][0] = 3; - - $data = array (); - $unit = db_get_value('unit', 'tagente_modulo', 'id_agente_modulo', $content['id_agent_module']); - - $value = reporting_get_agentmodule_data_sum ($content['id_agent_module'], $content['period'], $report["datetime"]); - if ($value === false) { - $value = __('Unknown'); - } - else { - $value = format_for_graph($value, 2) . " " . $unit; - } - - $data[0] = '

'.$value.'

'; - array_push ($table->data, $data); - - break; case 'agent_detailed_event': case 'event_report_agent': if (empty($item_title)) { From 6d07408af8f9fb829dacfaa3890727e01b9d34e1 Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Thu, 26 Mar 2015 19:29:43 +0100 Subject: [PATCH 19/80] Manual (by hand) cherry pick of commit f450d95278f3f9b4d4e4d6566ace493071dd6a40 --- pandora_console/include/functions_reporting_html.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index 869e4b94ed..5e36f9c650 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -7008,7 +7008,7 @@ function reporting_get_events ($data, $links = false) { $event_view = '
' . - __('Events by criticity') . + __('Important Events by Criticity') . '' . html_print_table($table_events, true) . '
'; } From 99247f7286f476ac1b6a1ddb6bda2705a4365853 Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Thu, 26 Mar 2015 19:39:11 +0100 Subject: [PATCH 20/80] Manual (by hand) cherry pick of commit c7fa8710ec64fb90f77736bfc25d432bb7777dc2 --- .../include/functions_reporting_html.php | 45 ++++++++++++++----- 1 file changed, 35 insertions(+), 10 deletions(-) diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index 5e36f9c650..a4908f920d 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -7099,10 +7099,14 @@ function reporting_get_event_histogram ($events) { global $config; include_once ('../../include/graphs/functions_gd.php'); $max_value = count($events); - + + if (defined("METACONSOLE")) + $max_value = SECONDS_1HOUR; + + $ttl = 1; $urlImage = ui_get_full_url(false, true, false, false); - + $colors = array( EVENT_CRIT_MAINTENANCE => COL_MAINTENANCE, EVENT_CRIT_INFORMATIONAL => COL_INFORMATIONAL, @@ -7113,6 +7117,11 @@ function reporting_get_event_histogram ($events) { EVENT_CRIT_CRITICAL => COL_CRITICAL ); + if (defined("METACONSOLE")) { + $full_legend = array(); + $cont = 0; + } + foreach ($events as $data) { switch ($data['criticity']) { @@ -7144,12 +7153,23 @@ function reporting_get_event_histogram ($events) { $color = EVENT_CRIT_WARNING_OR_CRITICAL; break; } - $graph_data[] = array( - 'data' => $color, - 'utimestamp' => 1 - ); + + if (defined("METACONSOLE")) { + $full_legend[$cont] = $data['timestamp']; + $graph_data[] = array( + 'data' => $color, + 'utimestamp' => $data['utimestamp'] - get_system_time () + ); + $cont++; + } + else { + $graph_data[] = array( + 'data' => $color, + 'utimestamp' => 1 + ); + } } - + $table->width = '100%'; $table->data = array (); $table->size = array (); @@ -7158,13 +7178,18 @@ function reporting_get_event_histogram ($events) { $table->data[0][0] = "" ; if (!empty($graph_data)) { - $slicebar = slicesbar_graph($graph_data, $max_value, 700, 25, $colors, $config['fontpath'], $config['round_corner'], $urlImage, $ttl); + if (defined("METACONSOLE")) + $slicebar = flot_slicesbar_graph($graph_data, $max_value, "100%", 35, $full_legend, $colors, $config['fontpath'], $config['round_corner'], $urlI + else + $slicebar = slicesbar_graph($graph_data, $max_value, 700, 25, $colors, $config['fontpath'], $config['round_corner'], $urlImage, $ttl); + $table->data[0][0] = $slicebar; - } else { + } + else { $table->data[0][0] = __('No events'); } - if(!defined('METACONSOLE')){ + if (!defined('METACONSOLE')) { $event_graph = '
' . __('Events info (1hr)') . From 54916a800242bb8a875cbbfa3700b3a1415c8360 Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Fri, 27 Mar 2015 10:24:44 +0100 Subject: [PATCH 21/80] Working in the refactoring the code of reports (MTTR, MTBF, TTO). --- .../include/functions_reporting.php | 68 ++++++++- .../include/functions_reporting_html.php | 141 +++++------------- 2 files changed, 104 insertions(+), 105 deletions(-) diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index b7004e9a5e..99a859e1e6 100644 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -203,6 +203,24 @@ function reporting_make_reporting_data($id_report, $date, $time, $content, 'sum'); break; + case 'MTTR': + $report['contents'][] = reporting_value( + $report, + $content, + 'MTTR'); + break; + case 'MTBF': + $report['contents'][] = reporting_value( + $report, + $content, + 'MTBF'); + break; + case 'TTO': + $report['contents'][] = reporting_value( + $report, + $content, + 'TTO'); + break; } } @@ -226,6 +244,15 @@ function reporting_value($report, $content, $type) { case 'sum': $return['type'] = 'sumatory'; break; + case 'MTTR': + $return['type'] = 'MTTR'; + break; + case 'MTBF': + $return['type'] = 'MTBF'; + break; + case 'TTO': + $return['type'] = 'TTO'; + break; } @@ -243,6 +270,15 @@ function reporting_value($report, $content, $type) { case 'sum': $content['name'] = __('Summatory'); break; + case 'MTTR': + $content['name'] = __('MTTR'); + break; + case 'MTBF': + $content['name'] = __('MTBF'); + break; + case 'TTO': + $content['name'] = __('TTO'); + break; } } @@ -250,6 +286,8 @@ function reporting_value($report, $content, $type) { modules_get_agentmodule_name($content['id_agent_module'])); $agent_name = io_safe_output( modules_get_agentmodule_agent_name ($content['id_agent_module'])); + $unit = db_get_value('unit', 'tagente_modulo', 'id_agente_modulo', + $content ['id_agent_module']); $return['title'] = $content['name']; $return['subtitle'] = $agent_name . " - " . $module_name; @@ -260,26 +298,48 @@ function reporting_value($report, $content, $type) { case 'max': $value = reporting_get_agentmodule_data_max( $content['id_agent_module'], $content['period'], $report["datetime"]); + $formated_value = format_for_graph($value, 2) . " " . $unit; break; case 'min': $value = reporting_get_agentmodule_data_min( $content['id_agent_module'], $content['period'], $report["datetime"]); + $formated_value = format_for_graph($value, 2) . " " . $unit; break; case 'avg': $value = reporting_get_agentmodule_data_average( $content['id_agent_module'], $content['period'], $report["datetime"]); + $formated_value = format_for_graph($value, 2) . " " . $unit; break; case 'sum': $value = reporting_get_agentmodule_data_sum( $content['id_agent_module'], $content['period'], $report["datetime"]); + $formated_value = format_for_graph($value, 2) . " " . $unit; + break; + case 'MTTR': + $value = reporting_get_agentmodule_mttr( + $content['id_agent_module'], $content['period'], $report["datetime"]); + $formated_value = null; + break; + case 'MTBF': + $value = reporting_get_agentmodule_mtbf( + $content['id_agent_module'], $content['period'], $report["datetime"]); + $formated_value = null; + break; + case 'TTO': + $value = reporting_get_agentmodule_tto( + $content['id_agent_module'], $content['period'], $report["datetime"]); + if ($value == 0) { + $formated_value = null; + } + else { + $formated_value = human_time_description_raw ($value); + } break; } - $unit = db_get_value('unit', 'tagente_modulo', 'id_agente_modulo', $content ['id_agent_module']); - $return['data'] = array( 'value' => $value, - 'formated_value' => format_for_graph($value, 2) . " " . $unit); + 'formated_value' => $formated_value); return reporting_check_structure_content($return); } @@ -1623,4 +1683,4 @@ function reporting_get_agentmodule_data_average ($id_agent_module, $period=0, $d return $total / $count; } -?> +?> \ No newline at end of file diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index a4908f920d..4c7c147fff 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -155,6 +155,15 @@ function reporting_html_print_report($report, $mini = false) { case 'sumatory': reporting_html_sum_value($table, $item, $mini); break; + case 'MTTR': + reporting_html_MTTR_value($table, $item, $mini, true, true); + break; + case 'MTBF': + reporting_html_MTBF_value($table, $item, $mini, true, true); + break; + case 'TTO': + reporting_html_TTO_value($table, $item, $mini, false, true); + break; } if ($item['type'] == 'agent_module') @@ -167,6 +176,18 @@ function reporting_html_print_report($report, $mini = false) { } } +function reporting_html_TTO_value(&$table, $item, $mini, $only_value = false, $check_empty = false) { + reporting_html_value($table, $item, $mini); +} + +function reporting_html_MTBF_value(&$table, $item, $mini, $only_value = false, $check_empty = false) { + reporting_html_value($table, $item, $mini); +} + +function reporting_html_MTTR_value(&$table, $item, $mini, $only_value = false, $check_empty = false) { + reporting_html_value($table, $item, $mini); +} + function reporting_html_sum_value(&$table, $item, $mini) { reporting_html_value($table, $item, $mini); } @@ -180,10 +201,10 @@ function reporting_html_max_value(&$table, $item, $mini) { } function reporting_html_min_value(&$table, $item, $mini) { - reporting_html_value($table, $item, $mini); + reporting_html_value($table, $item, $mini, $only_value, $check_empty); } -function reporting_html_value(&$table, $item, $mini) { +function reporting_html_value(&$table, $item, $mini, $only_value = false, $check_empty = false) { if ($mini) { $font_size = '1.5'; } @@ -193,10 +214,21 @@ function reporting_html_value(&$table, $item, $mini) { $table->colspan['data']['cell'] = 3; $table->cellstyle['data']['cell'] = 'text-align: left;'; - $table->data['data']['cell'] = - '

' . - $item['data']['formated_value'] . - '

'; + + + $table->data['data']['cell'] = '

'; + + if ($check_empty && empty($item['data']['value'])) { + $table->data['data']['cell'] .= __('Unknown'); + } + elseif ($only_value) { + $table->data['data']['cell'] .= $item['data']['value']; + } + else { + $table->data['data']['cell'] .= $item['data']['formated_value']; + } + + $table->data['data']['cell'] .= '

'; } function reporting_html_url(&$table, $item, $key) { @@ -4397,100 +4429,7 @@ function reporting_render_report_html_item ($content, $table, $report, $mini = f $data[0] = '

'.$ttr.'

'; array_push ($table->data, $data); break; - case 'TTO': - if (empty($item_title)) { - $item_title = __('TTO'); - } - reporting_header_content($mini, $content, $report, $table, $item_title, - ui_print_truncate_text($agent_name, 'agent_medium', false) . - '
'.ui_print_truncate_text($module_name, 'module_medium', false)); - - // Put description at the end of the module (if exists) - $table->colspan[1][0] = 3; - if ($content["description"] != "") { - $data_desc = array(); - $data_desc[0] = $content["description"]; - array_push ($table->data, $data_desc); - } - - $data = array (); - $table->colspan[2][0] = 3; - $tto = reporting_get_agentmodule_tto ($content['id_agent_module'], - $content['period'], $report["datetime"]); - if ($tto === false) { - $tto = __('Unknown'); - } - else if ($tto != 0) { - $tto = human_time_description_raw ($tto); - } - - $data = array (); - $table->colspan[2][0] = 3; - $data[0] = '

'.$tto.'

'; - array_push ($table->data, $data); - break; - case 'MTBF': - if (empty($item_title)) { - $item_title = __('MTBF'); - } - reporting_header_content($mini, $content, $report, $table, $item_title, - ui_print_truncate_text($agent_name, 'agent_medium', false) . - '
'.ui_print_truncate_text($module_name, 'module_medium', false)); - - // Put description at the end of the module (if exists) - $table->colspan[1][0] = 3; - if ($content["description"] != "") { - $data_desc = array(); - $data_desc[0] = $content["description"]; - array_push ($table->data, $data_desc); - } - - $data = array (); - $table->colspan[2][0] = 3; - $mtbf = reporting_get_agentmodule_mtbf ($content['id_agent_module'], $content['period'], $report["datetime"]); - if ($mtbf === false) { - $mtbf = __('Unknown'); - } - else if ($mtbf != 0) { - $mtbf = human_time_description_raw ($mtbf); - } - - $data = array (); - $table->colspan[2][0] = 3; - $data[0] = '

'.$mtbf.'

'; - array_push ($table->data, $data); - break; - case 'MTTR': - if (empty($item_title)) { - $item_title = __('MTTR'); - } - reporting_header_content($mini, $content, $report, $table, $item_title, - ui_print_truncate_text($agent_name, 'agent_medium', false) . - '
'.ui_print_truncate_text($module_name, 'module_medium', false)); - - // Put description at the end of the module (if exists) - $table->colspan[1][0] = 3; - if ($content["description"] != "") { - $data_desc = array(); - $data_desc[0] = $content["description"]; - array_push ($table->data, $data_desc); - } - - $data = array (); - $table->colspan[2][0] = 3; - $mttr = reporting_get_agentmodule_mttr ($content['id_agent_module'], $content['period'], $report["datetime"]); - if ($mttr === false) { - $mttr = __('Unknown'); - } - else if ($mttr != 0) { - $mttr = human_time_description_raw ($mttr); - } - - $data = array (); - $table->colspan[2][0] = 3; - $data[0] = '

'.$mttr.'

'; - array_push ($table->data, $data); - break; + case 'group_report': $group_name = groups_get_name($content['id_group'], true); $group_stats = reporting_get_group_stats($content['id_group']); @@ -7179,7 +7118,7 @@ function reporting_get_event_histogram ($events) { if (!empty($graph_data)) { if (defined("METACONSOLE")) - $slicebar = flot_slicesbar_graph($graph_data, $max_value, "100%", 35, $full_legend, $colors, $config['fontpath'], $config['round_corner'], $urlI + $slicebar = flot_slicesbar_graph($graph_data, $max_value, "100%", 35, $full_legend, $colors, $config['fontpath'], $config['round_corner'], $url); else $slicebar = slicesbar_graph($graph_data, $max_value, 700, 25, $colors, $config['fontpath'], $config['round_corner'], $urlImage, $ttl); From cf09a85cd208f85e310142a90594b87cefb26ff9 Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Fri, 27 Mar 2015 13:03:15 +0100 Subject: [PATCH 22/80] Workin in the refactoring the code of reports, move some functions from functions_repoting_html.php to functions_reporting.php --- .../include/functions_reporting.php | 453 +++++++++++++++++ .../include/functions_reporting_html.php | 459 +----------------- 2 files changed, 456 insertions(+), 456 deletions(-) diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index 99a859e1e6..43e29667d9 100644 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -221,6 +221,12 @@ function reporting_make_reporting_data($id_report, $date, $time, $content, 'TTO'); break; + case 'TTRT': + $report['contents'][] = reporting_value( + $report, + $content, + 'TTRT'); + break; } } @@ -253,6 +259,9 @@ function reporting_value($report, $content, $type) { case 'TTO': $return['type'] = 'TTO'; break; + case 'TTRT': + $return['type'] = 'TTRT'; + break; } @@ -279,6 +288,9 @@ function reporting_value($report, $content, $type) { case 'TTO': $content['name'] = __('TTO'); break; + case 'TTRT': + $return['type'] = __('TTRT'); + break; } } @@ -335,6 +347,16 @@ function reporting_value($report, $content, $type) { $formated_value = human_time_description_raw ($value); } break; + case 'TTRT': + $value = reporting_get_agentmodule_ttr( + $content['id_agent_module'], $content['period'], $report["datetime"]); + if ($value == 0) { + $formated_value = null; + } + else { + $formated_value = human_time_description_raw ($value); + } + break; } $return['data'] = array( @@ -1683,4 +1705,435 @@ function reporting_get_agentmodule_data_average ($id_agent_module, $period=0, $d return $total / $count; } + + +/** + * Get the MTTR value of an agent module in a period of time. See + * http://en.wikipedia.org/wiki/Mean_time_to_recovery + * + * @param int Agent module id + * @param int Period of time to check (in seconds) + * @param int Top date to check the values. Default current time. + * + * @return float The MTTR value in the interval. + */ +function reporting_get_agentmodule_mttr ($id_agent_module, $period = 0, $date = 0) { + + // Initialize variables + if (empty ($date)) $date = get_system_time (); + + // Read module configuration + $datelimit = $date - $period; + $search_in_history_db = db_search_in_history_db($datelimit); + + $module = db_get_row_sql ('SELECT max_critical, min_critical, id_tipo_modulo + FROM tagente_modulo + WHERE id_agente_modulo = ' . (int) $id_agent_module); + if ($module === false) { + return false; + } + + $critical_min = $module['min_critical']; + $critical_max = $module['max_critical']; + $module_type = $module['id_tipo_modulo']; + + // Set critical_min and critical for proc modules + $module_type_str = modules_get_type_name ($module_type); + if (strstr ($module_type_str, 'proc') !== false && + ($critical_min == 0 && $critical_max == 0)) { + $critical_min = 1; + } + + // Get module data + $interval_data = db_get_all_rows_sql ('SELECT * FROM tagente_datos + WHERE id_agente_modulo = ' . (int) $id_agent_module . + ' AND utimestamp > ' . (int) $datelimit . + ' AND utimestamp < ' . (int) $date . + ' ORDER BY utimestamp ASC', $search_in_history_db); + if ($interval_data === false) $interval_data = array (); + + // Get previous data + $previous_data = modules_get_previous_data ($id_agent_module, $datelimit); + if ($previous_data !== false) { + $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) { + $next_data['utimestamp'] = $date; + array_push ($interval_data, $next_data); + } + else if (count ($interval_data) > 0) { + // Propagate the last known data to the end of the interval + $next_data = array_pop ($interval_data); + array_push ($interval_data, $next_data); + $next_data['utimestamp'] = $date; + array_push ($interval_data, $next_data); + } + + if (count ($interval_data) < 2) { + return false; + } + + // Set initial conditions + $critical_period = 0; + $first_data = array_shift ($interval_data); + $previous_utimestamp = $first_data['utimestamp']; + if ((($critical_max > $critical_min AND ($first_data['datos'] > $critical_max OR $first_data['datos'] < $critical_min))) OR + ($critical_max <= $critical_min AND $first_data['datos'] < $critical_min)) { + $previous_status = 1; + $critical_count = 1; + } + else { + $previous_status = 0; + $critical_count = 0; + } + + foreach ($interval_data as $data) { + // Previous status was critical + if ($previous_status == 1) { + $critical_period += $data['utimestamp'] - $previous_utimestamp; + } + + // Re-calculate previous status for the next data + if ((($critical_max > $critical_min AND ($data['datos'] > $critical_max OR $data['datos'] < $critical_min))) OR + ($critical_max <= $critical_min AND $data['datos'] < $critical_min)) { + if ($previous_status == 0) { + $critical_count++; + } + $previous_status = 1; + } + else { + $previous_status = 0; + } + + $previous_utimestamp = $data['utimestamp']; + } + + if ($critical_count == 0) { + return 0; + } + + return $critical_period / $critical_count; +} + + +/** + * Get the MTBF value of an agent module in a period of time. See + * http://en.wikipedia.org/wiki/Mean_time_between_failures + * + * @param int Agent module id + * @param int Period of time to check (in seconds) + * @param int Top date to check the values. Default current time. + * + * @return float The MTBF value in the interval. + */ +function reporting_get_agentmodule_mtbf ($id_agent_module, $period = 0, $date = 0) { + + // Initialize variables + if (empty ($date)) $date = get_system_time (); + + // Read module configuration + $datelimit = $date - $period; + $search_in_history_db = db_search_in_history_db($datelimit); + + $module = db_get_row_sql ('SELECT max_critical, min_critical, id_tipo_modulo + FROM tagente_modulo + WHERE id_agente_modulo = ' . (int) $id_agent_module); + if ($module === false) { + return false; + } + + $critical_min = $module['min_critical']; + $critical_max = $module['max_critical']; + $module_type = $module['id_tipo_modulo']; + + // Set critical_min and critical for proc modules + $module_type_str = modules_get_type_name ($module_type); + if (strstr ($module_type_str, 'proc') !== false && + ($critical_min == 0 && $critical_max == 0)) { + $critical_min = 1; + } + + // Get module data + $interval_data = db_get_all_rows_sql ('SELECT * FROM tagente_datos + WHERE id_agente_modulo = ' . (int) $id_agent_module . + ' AND utimestamp > ' . (int) $datelimit . + ' AND utimestamp < ' . (int) $date . + ' ORDER BY utimestamp ASC', $search_in_history_db); + if ($interval_data === false) $interval_data = array (); + + // Get previous data + $previous_data = modules_get_previous_data ($id_agent_module, $datelimit); + if ($previous_data !== false) { + $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) { + $next_data['utimestamp'] = $date; + array_push ($interval_data, $next_data); + } + else if (count ($interval_data) > 0) { + // Propagate the last known data to the end of the interval + $next_data = array_pop ($interval_data); + array_push ($interval_data, $next_data); + $next_data['utimestamp'] = $date; + array_push ($interval_data, $next_data); + } + + if (count ($interval_data) < 2) { + return false; + } + + // Set initial conditions + $critical_period = 0; + $first_data = array_shift ($interval_data); + $previous_utimestamp = $first_data['utimestamp']; + if ((($critical_max > $critical_min AND ($first_data['datos'] > $critical_max OR $first_data['datos'] < $critical_min))) OR + ($critical_max <= $critical_min AND $first_data['datos'] < $critical_min)) { + $previous_status = 1; + $critical_count = 1; + } + else { + $previous_status = 0; + $critical_count = 0; + } + + foreach ($interval_data as $data) { + // Previous status was critical + if ($previous_status == 1) { + $critical_period += $data['utimestamp'] - $previous_utimestamp; + } + + // Re-calculate previous status for the next data + if ((($critical_max > $critical_min AND ($data['datos'] > $critical_max OR $data['datos'] < $critical_min))) OR + ($critical_max <= $critical_min AND $data['datos'] < $critical_min)) { + if ($previous_status == 0) { + $critical_count++; + } + $previous_status = 1; + } + else { + $previous_status = 0; + } + + $previous_utimestamp = $data['utimestamp']; + } + + if ($critical_count == 0) { + return 0; + } + + return ($period - $critical_period) / $critical_count; +} + + +/** + * Get the TTO value of an agent module in a period of time. + * + * @param int Agent module id + * @param int Period of time to check (in seconds) + * @param int Top date to check the values. Default current time. + * + * @return float The TTO value in the interval. + */ +function reporting_get_agentmodule_tto ($id_agent_module, $period = 0, $date = 0) { + + // Initialize variables + if (empty ($date)) $date = get_system_time (); + + // Read module configuration + $datelimit = $date - $period; + $search_in_history_db = db_search_in_history_db($datelimit); + + $module = db_get_row_sql ('SELECT max_critical, min_critical, id_tipo_modulo + FROM tagente_modulo + WHERE id_agente_modulo = ' . (int) $id_agent_module); + if ($module === false) { + return false; + } + + $critical_min = $module['min_critical']; + $critical_max = $module['max_critical']; + $module_type = $module['id_tipo_modulo']; + + // Set critical_min and critical for proc modules + $module_type_str = modules_get_type_name ($module_type); + if (strstr ($module_type_str, 'proc') !== false && + ($critical_min == 0 && $critical_max == 0)) { + $critical_min = 1; + } + + // Get module data + $interval_data = db_get_all_rows_sql ('SELECT * FROM tagente_datos + WHERE id_agente_modulo = ' . (int) $id_agent_module . + ' AND utimestamp > ' . (int) $datelimit . + ' AND utimestamp < ' . (int) $date . + ' ORDER BY utimestamp ASC', $search_in_history_db); + if ($interval_data === false) $interval_data = array (); + + // Get previous data + $previous_data = modules_get_previous_data ($id_agent_module, $datelimit); + if ($previous_data !== false) { + $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) { + $next_data['utimestamp'] = $date; + array_push ($interval_data, $next_data); + } + else if (count ($interval_data) > 0) { + // Propagate the last known data to the end of the interval + $next_data = array_pop ($interval_data); + array_push ($interval_data, $next_data); + $next_data['utimestamp'] = $date; + array_push ($interval_data, $next_data); + } + + if (count ($interval_data) < 2) { + return false; + } + + // Set initial conditions + $critical_period = 0; + $first_data = array_shift ($interval_data); + $previous_utimestamp = $first_data['utimestamp']; + if ((($critical_max > $critical_min AND ($first_data['datos'] > $critical_max OR $first_data['datos'] < $critical_min))) OR + ($critical_max <= $critical_min AND $first_data['datos'] < $critical_min)) { + $previous_status = 1; + } + else { + $previous_status = 0; + } + + foreach ($interval_data as $data) { + // Previous status was critical + if ($previous_status == 1) { + $critical_period += $data['utimestamp'] - $previous_utimestamp; + } + + // Re-calculate previous status for the next data + if ((($critical_max > $critical_min AND ($data['datos'] > $critical_max OR $data['datos'] < $critical_min))) OR + ($critical_max <= $critical_min AND $data['datos'] < $critical_min)) { + $previous_status = 1; + } + else { + $previous_status = 0; + } + + $previous_utimestamp = $data['utimestamp']; + } + + return $period - $critical_period; +} + +/** + * Get the TTR value of an agent module in a period of time. + * + * @param int Agent module id + * @param int Period of time to check (in seconds) + * @param int Top date to check the values. Default current time. + * + * @return float The TTR value in the interval. + */ +function reporting_get_agentmodule_ttr ($id_agent_module, $period = 0, $date = 0) { + + // Initialize variables + if (empty ($date)) $date = get_system_time (); + + // Read module configuration + $datelimit = $date - $period; + $search_in_history_db = db_search_in_history_db($datelimit); + + $module = db_get_row_sql ('SELECT max_critical, min_critical, id_tipo_modulo + FROM tagente_modulo + WHERE id_agente_modulo = ' . (int) $id_agent_module); + if ($module === false) { + return false; + } + + $critical_min = $module['min_critical']; + $critical_max = $module['max_critical']; + $module_type = $module['id_tipo_modulo']; + + // Set critical_min and critical for proc modules + $module_type_str = modules_get_type_name ($module_type); + if (strstr ($module_type_str, 'proc') !== false && + ($critical_min == 0 && $critical_max == 0)) { + $critical_min = 1; + } + + // Get module data + $interval_data = db_get_all_rows_sql ('SELECT * FROM tagente_datos + WHERE id_agente_modulo = ' . (int) $id_agent_module . + ' AND utimestamp > ' . (int) $datelimit . + ' AND utimestamp < ' . (int) $date . + ' ORDER BY utimestamp ASC', $search_in_history_db); + if ($interval_data === false) $interval_data = array (); + + // Get previous data + $previous_data = modules_get_previous_data ($id_agent_module, $datelimit); + if ($previous_data !== false) { + $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) { + $next_data['utimestamp'] = $date; + array_push ($interval_data, $next_data); + } + else if (count ($interval_data) > 0) { + // Propagate the last known data to the end of the interval + $next_data = array_pop ($interval_data); + array_push ($interval_data, $next_data); + $next_data['utimestamp'] = $date; + array_push ($interval_data, $next_data); + } + + if (count ($interval_data) < 2) { + return false; + } + + // Set initial conditions + $critical_period = 0; + $first_data = array_shift ($interval_data); + $previous_utimestamp = $first_data['utimestamp']; + if ((($critical_max > $critical_min AND ($first_data['datos'] > $critical_max OR $first_data['datos'] < $critical_min))) OR + ($critical_max <= $critical_min AND $first_data['datos'] < $critical_min)) { + $previous_status = 1; + } + else { + $previous_status = 0; + } + + foreach ($interval_data as $data) { + // Previous status was critical + if ($previous_status == 1) { + $critical_period += $data['utimestamp'] - $previous_utimestamp; + } + + // Re-calculate previous status for the next data + if ((($critical_max > $critical_min AND ($data['datos'] > $critical_max OR $data['datos'] < $critical_min))) OR + ($critical_max <= $critical_min AND $data['datos'] < $critical_min)) { + $previous_status = 1; + } + else { + $previous_status = 0; + } + + $previous_utimestamp = $data['utimestamp']; + } + + return $critical_period; +} ?> \ No newline at end of file diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index 4c7c147fff..3711909e9c 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -164,6 +164,9 @@ function reporting_html_print_report($report, $mini = false) { case 'TTO': reporting_html_TTO_value($table, $item, $mini, false, true); break; + case 'TTRT': + reporting_html_TTRT_value($table, $item, $mini, false, true); + break; } if ($item['type'] == 'agent_module') @@ -4398,37 +4401,6 @@ function reporting_render_report_html_item ($content, $table, $report, $mini = f $cellContent = html_print_table($table2, true); array_push($table->data, array($cellContent)); break; - case 'TTRT': - if (empty($item_title)) { - $item_title = __('TTRT'); - } - reporting_header_content($mini, $content, $report, $table, $item_title, - ui_print_truncate_text($agent_name, 'agent_medium', false) . - '
'.ui_print_truncate_text($module_name, 'module_medium', false)); - - // Put description at the end of the module (if exists) - $table->colspan[1][0] = 3; - if ($content["description"] != "") { - $data_desc = array(); - $data_desc[0] = $content["description"]; - array_push ($table->data, $data_desc); - } - - $data = array (); - $table->colspan[2][0] = 3; - $ttr = reporting_get_agentmodule_ttr ($content['id_agent_module'], $content['period'], $report["datetime"]); - if ($ttr === false) { - $ttr = __('Unknown'); - } - else if ($ttr != 0) { - $ttr = human_time_description_raw ($ttr); - } - - $data = array (); - $table->colspan[2][0] = 3; - $data[0] = '

'.$ttr.'

'; - array_push ($table->data, $data); - break; case 'group_report': $group_name = groups_get_name($content['id_group'], true); @@ -5877,433 +5849,8 @@ function reporting_render_report_html_item ($content, $table, $report, $mini = f } } -/** - * Get the MTBF value of an agent module in a period of time. See - * http://en.wikipedia.org/wiki/Mean_time_between_failures - * - * @param int Agent module id - * @param int Period of time to check (in seconds) - * @param int Top date to check the values. Default current time. - * - * @return float The MTBF value in the interval. - */ -function reporting_get_agentmodule_mtbf ($id_agent_module, $period = 0, $date = 0) { - - // Initialize variables - if (empty ($date)) $date = get_system_time (); - - // Read module configuration - $datelimit = $date - $period; - $search_in_history_db = db_search_in_history_db($datelimit); - $module = db_get_row_sql ('SELECT max_critical, min_critical, id_tipo_modulo - FROM tagente_modulo - WHERE id_agente_modulo = ' . (int) $id_agent_module); - if ($module === false) { - return false; - } - - $critical_min = $module['min_critical']; - $critical_max = $module['max_critical']; - $module_type = $module['id_tipo_modulo']; - - // Set critical_min and critical for proc modules - $module_type_str = modules_get_type_name ($module_type); - if (strstr ($module_type_str, 'proc') !== false && - ($critical_min == 0 && $critical_max == 0)) { - $critical_min = 1; - } - - // Get module data - $interval_data = db_get_all_rows_sql ('SELECT * FROM tagente_datos - WHERE id_agente_modulo = ' . (int) $id_agent_module . - ' AND utimestamp > ' . (int) $datelimit . - ' AND utimestamp < ' . (int) $date . - ' ORDER BY utimestamp ASC', $search_in_history_db); - if ($interval_data === false) $interval_data = array (); - - // Get previous data - $previous_data = modules_get_previous_data ($id_agent_module, $datelimit); - if ($previous_data !== false) { - $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) { - $next_data['utimestamp'] = $date; - array_push ($interval_data, $next_data); - } - else if (count ($interval_data) > 0) { - // Propagate the last known data to the end of the interval - $next_data = array_pop ($interval_data); - array_push ($interval_data, $next_data); - $next_data['utimestamp'] = $date; - array_push ($interval_data, $next_data); - } - - if (count ($interval_data) < 2) { - return false; - } - - // Set initial conditions - $critical_period = 0; - $first_data = array_shift ($interval_data); - $previous_utimestamp = $first_data['utimestamp']; - if ((($critical_max > $critical_min AND ($first_data['datos'] > $critical_max OR $first_data['datos'] < $critical_min))) OR - ($critical_max <= $critical_min AND $first_data['datos'] < $critical_min)) { - $previous_status = 1; - $critical_count = 1; - } - else { - $previous_status = 0; - $critical_count = 0; - } - - foreach ($interval_data as $data) { - // Previous status was critical - if ($previous_status == 1) { - $critical_period += $data['utimestamp'] - $previous_utimestamp; - } - - // Re-calculate previous status for the next data - if ((($critical_max > $critical_min AND ($data['datos'] > $critical_max OR $data['datos'] < $critical_min))) OR - ($critical_max <= $critical_min AND $data['datos'] < $critical_min)) { - if ($previous_status == 0) { - $critical_count++; - } - $previous_status = 1; - } - else { - $previous_status = 0; - } - - $previous_utimestamp = $data['utimestamp']; - } - - if ($critical_count == 0) { - return 0; - } - - return ($period - $critical_period) / $critical_count; -} -/** - * Get the MTTR value of an agent module in a period of time. See - * http://en.wikipedia.org/wiki/Mean_time_to_recovery - * - * @param int Agent module id - * @param int Period of time to check (in seconds) - * @param int Top date to check the values. Default current time. - * - * @return float The MTTR value in the interval. - */ -function reporting_get_agentmodule_mttr ($id_agent_module, $period = 0, $date = 0) { - - // Initialize variables - if (empty ($date)) $date = get_system_time (); - - // Read module configuration - $datelimit = $date - $period; - $search_in_history_db = db_search_in_history_db($datelimit); - - $module = db_get_row_sql ('SELECT max_critical, min_critical, id_tipo_modulo - FROM tagente_modulo - WHERE id_agente_modulo = ' . (int) $id_agent_module); - if ($module === false) { - return false; - } - - $critical_min = $module['min_critical']; - $critical_max = $module['max_critical']; - $module_type = $module['id_tipo_modulo']; - - // Set critical_min and critical for proc modules - $module_type_str = modules_get_type_name ($module_type); - if (strstr ($module_type_str, 'proc') !== false && - ($critical_min == 0 && $critical_max == 0)) { - $critical_min = 1; - } - - // Get module data - $interval_data = db_get_all_rows_sql ('SELECT * FROM tagente_datos - WHERE id_agente_modulo = ' . (int) $id_agent_module . - ' AND utimestamp > ' . (int) $datelimit . - ' AND utimestamp < ' . (int) $date . - ' ORDER BY utimestamp ASC', $search_in_history_db); - if ($interval_data === false) $interval_data = array (); - - // Get previous data - $previous_data = modules_get_previous_data ($id_agent_module, $datelimit); - if ($previous_data !== false) { - $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) { - $next_data['utimestamp'] = $date; - array_push ($interval_data, $next_data); - } - else if (count ($interval_data) > 0) { - // Propagate the last known data to the end of the interval - $next_data = array_pop ($interval_data); - array_push ($interval_data, $next_data); - $next_data['utimestamp'] = $date; - array_push ($interval_data, $next_data); - } - - if (count ($interval_data) < 2) { - return false; - } - - // Set initial conditions - $critical_period = 0; - $first_data = array_shift ($interval_data); - $previous_utimestamp = $first_data['utimestamp']; - if ((($critical_max > $critical_min AND ($first_data['datos'] > $critical_max OR $first_data['datos'] < $critical_min))) OR - ($critical_max <= $critical_min AND $first_data['datos'] < $critical_min)) { - $previous_status = 1; - $critical_count = 1; - } - else { - $previous_status = 0; - $critical_count = 0; - } - - foreach ($interval_data as $data) { - // Previous status was critical - if ($previous_status == 1) { - $critical_period += $data['utimestamp'] - $previous_utimestamp; - } - - // Re-calculate previous status for the next data - if ((($critical_max > $critical_min AND ($data['datos'] > $critical_max OR $data['datos'] < $critical_min))) OR - ($critical_max <= $critical_min AND $data['datos'] < $critical_min)) { - if ($previous_status == 0) { - $critical_count++; - } - $previous_status = 1; - } - else { - $previous_status = 0; - } - - $previous_utimestamp = $data['utimestamp']; - } - - if ($critical_count == 0) { - return 0; - } - - return $critical_period / $critical_count; -} - -/** - * Get the TTO value of an agent module in a period of time. - * - * @param int Agent module id - * @param int Period of time to check (in seconds) - * @param int Top date to check the values. Default current time. - * - * @return float The TTO value in the interval. - */ -function reporting_get_agentmodule_tto ($id_agent_module, $period = 0, $date = 0) { - - // Initialize variables - if (empty ($date)) $date = get_system_time (); - - // Read module configuration - $datelimit = $date - $period; - $search_in_history_db = db_search_in_history_db($datelimit); - - $module = db_get_row_sql ('SELECT max_critical, min_critical, id_tipo_modulo - FROM tagente_modulo - WHERE id_agente_modulo = ' . (int) $id_agent_module); - if ($module === false) { - return false; - } - - $critical_min = $module['min_critical']; - $critical_max = $module['max_critical']; - $module_type = $module['id_tipo_modulo']; - - // Set critical_min and critical for proc modules - $module_type_str = modules_get_type_name ($module_type); - if (strstr ($module_type_str, 'proc') !== false && - ($critical_min == 0 && $critical_max == 0)) { - $critical_min = 1; - } - - // Get module data - $interval_data = db_get_all_rows_sql ('SELECT * FROM tagente_datos - WHERE id_agente_modulo = ' . (int) $id_agent_module . - ' AND utimestamp > ' . (int) $datelimit . - ' AND utimestamp < ' . (int) $date . - ' ORDER BY utimestamp ASC', $search_in_history_db); - if ($interval_data === false) $interval_data = array (); - - // Get previous data - $previous_data = modules_get_previous_data ($id_agent_module, $datelimit); - if ($previous_data !== false) { - $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) { - $next_data['utimestamp'] = $date; - array_push ($interval_data, $next_data); - } - else if (count ($interval_data) > 0) { - // Propagate the last known data to the end of the interval - $next_data = array_pop ($interval_data); - array_push ($interval_data, $next_data); - $next_data['utimestamp'] = $date; - array_push ($interval_data, $next_data); - } - - if (count ($interval_data) < 2) { - return false; - } - - // Set initial conditions - $critical_period = 0; - $first_data = array_shift ($interval_data); - $previous_utimestamp = $first_data['utimestamp']; - if ((($critical_max > $critical_min AND ($first_data['datos'] > $critical_max OR $first_data['datos'] < $critical_min))) OR - ($critical_max <= $critical_min AND $first_data['datos'] < $critical_min)) { - $previous_status = 1; - } - else { - $previous_status = 0; - } - - foreach ($interval_data as $data) { - // Previous status was critical - if ($previous_status == 1) { - $critical_period += $data['utimestamp'] - $previous_utimestamp; - } - - // Re-calculate previous status for the next data - if ((($critical_max > $critical_min AND ($data['datos'] > $critical_max OR $data['datos'] < $critical_min))) OR - ($critical_max <= $critical_min AND $data['datos'] < $critical_min)) { - $previous_status = 1; - } - else { - $previous_status = 0; - } - - $previous_utimestamp = $data['utimestamp']; - } - - return $period - $critical_period; -} - -/** - * Get the TTR value of an agent module in a period of time. - * - * @param int Agent module id - * @param int Period of time to check (in seconds) - * @param int Top date to check the values. Default current time. - * - * @return float The TTR value in the interval. - */ -function reporting_get_agentmodule_ttr ($id_agent_module, $period = 0, $date = 0) { - - // Initialize variables - if (empty ($date)) $date = get_system_time (); - - // Read module configuration - $datelimit = $date - $period; - $search_in_history_db = db_search_in_history_db($datelimit); - - $module = db_get_row_sql ('SELECT max_critical, min_critical, id_tipo_modulo - FROM tagente_modulo - WHERE id_agente_modulo = ' . (int) $id_agent_module); - if ($module === false) { - return false; - } - - $critical_min = $module['min_critical']; - $critical_max = $module['max_critical']; - $module_type = $module['id_tipo_modulo']; - - // Set critical_min and critical for proc modules - $module_type_str = modules_get_type_name ($module_type); - if (strstr ($module_type_str, 'proc') !== false && - ($critical_min == 0 && $critical_max == 0)) { - $critical_min = 1; - } - - // Get module data - $interval_data = db_get_all_rows_sql ('SELECT * FROM tagente_datos - WHERE id_agente_modulo = ' . (int) $id_agent_module . - ' AND utimestamp > ' . (int) $datelimit . - ' AND utimestamp < ' . (int) $date . - ' ORDER BY utimestamp ASC', $search_in_history_db); - if ($interval_data === false) $interval_data = array (); - - // Get previous data - $previous_data = modules_get_previous_data ($id_agent_module, $datelimit); - if ($previous_data !== false) { - $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) { - $next_data['utimestamp'] = $date; - array_push ($interval_data, $next_data); - } - else if (count ($interval_data) > 0) { - // Propagate the last known data to the end of the interval - $next_data = array_pop ($interval_data); - array_push ($interval_data, $next_data); - $next_data['utimestamp'] = $date; - array_push ($interval_data, $next_data); - } - - if (count ($interval_data) < 2) { - return false; - } - - // Set initial conditions - $critical_period = 0; - $first_data = array_shift ($interval_data); - $previous_utimestamp = $first_data['utimestamp']; - if ((($critical_max > $critical_min AND ($first_data['datos'] > $critical_max OR $first_data['datos'] < $critical_min))) OR - ($critical_max <= $critical_min AND $first_data['datos'] < $critical_min)) { - $previous_status = 1; - } - else { - $previous_status = 0; - } - - foreach ($interval_data as $data) { - // Previous status was critical - if ($previous_status == 1) { - $critical_period += $data['utimestamp'] - $previous_utimestamp; - } - - // Re-calculate previous status for the next data - if ((($critical_max > $critical_min AND ($data['datos'] > $critical_max OR $data['datos'] < $critical_min))) OR - ($critical_max <= $critical_min AND $data['datos'] < $critical_min)) { - $previous_status = 1; - } - else { - $previous_status = 0; - } - - $previous_utimestamp = $data['utimestamp']; - } - - return $critical_period; -} /** * Get all the template graphs a user can see. From cc8305429e7fdd7317d9a645cea6f8eda9cb1264 Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Mon, 30 Mar 2015 10:52:58 +0200 Subject: [PATCH 23/80] Manual (by hand) cherry pick from the commit 63d322244dd9ca51ee35c1f7cd38b4c3755ef9e0 --- pandora_console/include/functions_reporting_html.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index 3711909e9c..33536abdae 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -6062,14 +6062,14 @@ function reporting_tiny_stats ($counts_info, $return = false, $type = 'agent', $ $id_agent = $counts_info['id_agente']; $counts_info = array(); - $counts_info['normal_count'] = count(tags_get_agent_modules ($id_agent, $acltags, false, $filter, false, AGENT_MODULE_STATUS_NORMAL)); - $counts_info['warning_count'] = count(tags_get_agent_modules ($id_agent, $acltags, false, $filter, false, AGENT_MODULE_STATUS_WARNING)); - $counts_info['critical_count'] = count(tags_get_agent_modules ($id_agent, $acltags, false, $filter, false, AGENT_MODULE_STATUS_CRITICAL_BAD)); - $counts_info['notinit_count'] = count(tags_get_agent_modules ($id_agent, $acltags, false, $filter, false, AGENT_MODULE_STATUS_NOT_INIT)); - $counts_info['unknown_count'] = count(tags_get_agent_modules ($id_agent, $acltags, false, $filter, false, AGENT_MODULE_STATUS_UNKNOWN)); + $counts_info['normal_count'] = count(tags_get_agent_modules ($id_agent, false, $acltags, false, $filter, false, AGENT_MODULE_STATUS_NORMAL)); + $counts_info['warning_count'] = count(tags_get_agent_modules ($id_agent, false, $acltags, false, $filter, false, AGENT_MODULE_STATUS_WARNING)); + $counts_info['critical_count'] = count(tags_get_agent_modules ($id_agent, false, $acltags, false, $filter, false, AGENT_MODULE_STATUS_CRITICAL_BAD)); + $counts_info['notinit_count'] = count(tags_get_agent_modules ($id_agent, false, $acltags, false, $filter, false, AGENT_MODULE_STATUS_NOT_INIT)); + $counts_info['unknown_count'] = count(tags_get_agent_modules ($id_agent, false, $acltags, false, $filter, false, AGENT_MODULE_STATUS_UNKNOWN)); $counts_info['total_count'] = $counts_info['normal_count'] + $counts_info['warning_count'] + $counts_info['critical_count'] + $counts_info['unknown_count'] + $counts_info['notinit_count']; - $all_agent_modules = tags_get_agent_modules ($id_agent, $acltags, false, $filter); + $all_agent_modules = tags_get_agent_modules ($id_agent, false, $acltags, false, $filter); if (!empty($all_agent_modules)) { $mod_clause = "(".implode(',', array_keys($all_agent_modules)).")"; From aabec6784e1e2d2bf648581adddbb17fec01a37f Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Mon, 30 Mar 2015 11:33:26 +0200 Subject: [PATCH 24/80] Rever some changes from the previous merge. --- .../include/functions_reporting.php | 855 ------------------ 1 file changed, 855 deletions(-) diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index d2a32f9cd1..43e29667d9 100644 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -2136,859 +2136,4 @@ function reporting_get_agentmodule_ttr ($id_agent_module, $period = 0, $date = 0 return $critical_period; } - -/** - * Get all the template graphs a user can see. - * - * @param $id_user User id to check. - * @param $only_names Wheter to return only graphs names in an associative array - * or all the values. - * @param $returnAllGroup Wheter to return graphs of group All or not. - * @param $privileges Privileges to check in user group - * - * @return template graphs of a an user. Empty array if none. - */ -function reporting_template_graphs_get_user ($id_user = 0, $only_names = false, $returnAllGroup = true, $privileges = 'RR') { - global $config; - - if (!$id_user) { - $id_user = $config['id_user']; - } - - $groups = users_get_groups ($id_user, $privileges, $returnAllGroup); - - $all_templates = db_get_all_rows_in_table ('tgraph_template', 'name'); - if ($all_templates === false) - return array (); - - $templates = array (); - foreach ($all_templates as $template) { - if (!in_array($template['id_group'], array_keys($groups))) - continue; - - if ($template["id_user"] != $id_user && $template['private']) - continue; - - if ($template["id_group"] > 0) - if (!isset($groups[$template["id_group"]])){ - continue; - } - - if ($only_names) { - $templates[$template['id_graph_template']] = $template['name']; - } - else { - $templates[$template['id_graph_template']] = $template; - $templatesCount = db_get_value_sql("SELECT COUNT(id_gs_template) FROM tgraph_source_template WHERE id_template = " . $template['id_graph_template']); - $templates[$template['id_graph_template']]['graphs_template_count'] = $templatesCount; - } - } - - return $templates; -} - -/** - * Gets a detailed reporting of groups's events. - * - * @param unknown_type $id_group Id of the group. - * @param unknown_type $period Time period of the report. - * @param unknown_type $date Date of the report. - * @param unknown_type $return Whether to return or not. - * @param unknown_type $html Whether to return HTML code or not. - * - * @return string Report of groups's events - */ -function reporting_get_count_events_by_agent ($id_group, $period = 0, - $date = 0, - $filter_event_validated = false, $filter_event_critical = false, - $filter_event_warning = false, $filter_event_no_validated = false) { - - if (!is_numeric ($date)) { - $date = strtotime ($date); - } - if (empty ($date)) { - $date = get_system_time (); - } - - return events_get_count_events_by_agent($id_group, $period, $date, - $filter_event_validated, $filter_event_critical, - $filter_event_warning, $filter_event_no_validated); -} - -/** - * Gets a detailed reporting of groups's events. - * - * @param unknown_type $filter. - * @param unknown_type $period Time period of the report. - * @param unknown_type $date Date of the report. - * @param unknown_type $return Whether to return or not. - * @param unknown_type $html Whether to return HTML code or not. - * - * @return string Report of groups's events - */ -function reporting_get_count_events_validated_by_user ($filter, $period = 0, - $date = 0, - $filter_event_validated = false, $filter_event_critical = false, - $filter_event_warning = false, $filter_event_no_validated = false) { - - if (!is_numeric ($date)) { - $date = strtotime ($date); - } - if (empty ($date)) { - $date = get_system_time (); - } - - return events_get_count_events_validated_by_user($filter, $period, $date, - $filter_event_validated, $filter_event_critical, - $filter_event_warning, $filter_event_no_validated); -} - -/** - * Gets a detailed reporting of groups's events. - * - * @param unknown_type $id_group Id of the group. - * @param unknown_type $period Time period of the report. - * @param unknown_type $date Date of the report. - * @param unknown_type $return Whether to return or not. - * @param unknown_type $html Whether to return HTML code or not. - * - * @return string Report of groups's events - */ -function reporting_get_count_events_by_criticity ($filter, $period = 0, - $date = 0, - $filter_event_validated = false, $filter_event_critical = false, - $filter_event_warning = false, $filter_event_no_validated = false) { - - if (!is_numeric ($date)) { - $date = strtotime ($date); - } - if (empty ($date)) { - $date = get_system_time (); - } - - return events_get_count_events_by_criticity($filter, $period, $date, - $filter_event_validated, $filter_event_critical, - $filter_event_warning, $filter_event_no_validated); -} - -/** - * Gets a detailed reporting of groups's events. - * - * @param unknown_type $id_group Id of the group. - * @param unknown_type $period Time period of the report. - * @param unknown_type $date Date of the report. - * @param unknown_type $return Whether to return or not. - * @param unknown_type $html Whether to return HTML code or not. - * - * @return string Report of groups's events - */ -function reporting_get_count_events_validated ($filter, $period = 0, - $date = 0, - $filter_event_validated = false, $filter_event_critical = false, - $filter_event_warning = false, $filter_event_no_validated = false) { - - if (!is_numeric ($date)) { - $date = strtotime ($date); - } - if (empty ($date)) { - $date = get_system_time (); - } - - return events_get_count_events_validated($filter, $period, $date, - $filter_event_validated, $filter_event_critical, - $filter_event_warning, $filter_event_no_validated); -} - -/** - * Print tiny statistics of the status of one agent, group, etc. - * - * @param mixed Array with the counts of the total modules, normal modules, critical modules, warning modules, unknown modules and fired alerts - * @param bool return or echo flag - * - * @return string html formatted tiny stats of modules/alerts of an agent - */ -function reporting_tiny_stats ($counts_info, $return = false, $type = 'agent', $separator = ':', $strict_user = false) { - global $config; - - $out = ''; - - // Depend the type of object, the stats will refer agents, modules... - switch ($type) { - case 'modules': - $template_title['total_count'] = __('%d Total modules'); - $template_title['normal_count'] = __('%d Normal modules'); - $template_title['critical_count'] = __('%d Critical modules'); - $template_title['warning_count'] = __('%d Warning modules'); - $template_title['unknown_count'] = __('%d Unknown modules'); - break; - case 'agent': - $template_title['total_count'] = __('%d Total modules'); - $template_title['normal_count'] = __('%d Normal modules'); - $template_title['critical_count'] = __('%d Critical modules'); - $template_title['warning_count'] = __('%d Warning modules'); - $template_title['unknown_count'] = __('%d Unknown modules'); - $template_title['fired_count'] = __('%d Fired alerts'); - break; - default: - $template_title['total_count'] = __('%d Total agents'); - $template_title['normal_count'] = __('%d Normal agents'); - $template_title['critical_count'] = __('%d Critical agents'); - $template_title['warning_count'] = __('%d Warning agents'); - $template_title['unknown_count'] = __('%d Unknown agents'); - $template_title['not_init_count'] = __('%d not init agents'); - $template_title['fired_count'] = __('%d Fired alerts'); - break; - } - - if ($strict_user && $type == 'agent') { - - $acltags = tags_get_user_module_and_tags ($config['id_user'],'AR', $strict_user); - $filter['disabled'] = 0; - $id_agent = $counts_info['id_agente']; - - $counts_info = array(); - $counts_info['normal_count'] = count(tags_get_agent_modules ($id_agent, $acltags, false, $filter, false, AGENT_MODULE_STATUS_NORMAL)); - $counts_info['warning_count'] = count(tags_get_agent_modules ($id_agent, $acltags, false, $filter, false, AGENT_MODULE_STATUS_WARNING)); - $counts_info['critical_count'] = count(tags_get_agent_modules ($id_agent, $acltags, false, $filter, false, AGENT_MODULE_STATUS_CRITICAL_BAD)); - $counts_info['notinit_count'] = count(tags_get_agent_modules ($id_agent, $acltags, false, $filter, false, AGENT_MODULE_STATUS_NOT_INIT)); - $counts_info['unknown_count'] = count(tags_get_agent_modules ($id_agent, $acltags, false, $filter, false, AGENT_MODULE_STATUS_UNKNOWN)); - $counts_info['total_count'] = $counts_info['normal_count'] + $counts_info['warning_count'] + $counts_info['critical_count'] + $counts_info['unknown_count'] + $counts_info['notinit_count']; - - $all_agent_modules = tags_get_agent_modules ($id_agent, $acltags, false, $filter); - if (!empty($all_agent_modules)) { - $mod_clause = "(".implode(',', array_keys($all_agent_modules)).")"; - - $counts_info['fired_count'] = (int) db_get_sql ("SELECT COUNT(times_fired) - FROM talert_template_modules - WHERE times_fired != 0 AND id_agent_module IN ".$mod_clause); - } - else { - $counts_info['fired_count'] = 0; - } - } - - // Store the counts in a data structure to print hidden divs with titles - $stats = array(); - - if (isset($counts_info['total_count'])) { - $not_init = isset($counts_info['notinit_count']) ? $counts_info['notinit_count'] : 0; - $total_count = $counts_info['total_count'] - $not_init; - $stats[] = array('name' => 'total_count', 'count' => $total_count, 'title' => sprintf($template_title['total_count'], $total_count)); - } - - if (isset($counts_info['normal_count'])) { - $normal_count = $counts_info['normal_count']; - $stats[] = array('name' => 'normal_count', 'count' => $normal_count, 'title' => sprintf($template_title['normal_count'], $normal_count)); - } - - if (isset($counts_info['critical_count'])) { - $critical_count = $counts_info['critical_count']; - $stats[] = array('name' => 'critical_count', 'count' => $critical_count, 'title' => sprintf($template_title['critical_count'], $critical_count)); - } - - if (isset($counts_info['warning_count'])) { - $warning_count = $counts_info['warning_count']; - $stats[] = array('name' => 'warning_count', 'count' => $warning_count, 'title' => sprintf($template_title['warning_count'], $warning_count)); - } - - if (isset($counts_info['unknown_count'])) { - $unknown_count = $counts_info['unknown_count']; - $stats[] = array('name' => 'unknown_count', 'count' => $unknown_count, 'title' => sprintf($template_title['unknown_count'], $unknown_count)); - } - - if (isset($counts_info['not_init_count'])) { - $not_init_count = $counts_info['not_init_count']; - $stats[] = array('name' => 'not_init_count', - 'count' => $not_init_count, - 'title' => sprintf($template_title['not_init_count'], $not_init_count)); - } - - if (isset($template_title['fired_count'])) { - if (isset($counts_info['fired_count'])) { - $fired_count = $counts_info['fired_count']; - $stats[] = array('name' => 'fired_count', 'count' => $fired_count, 'title' => sprintf($template_title['fired_count'], $fired_count)); - } - } - - $uniq_id = uniqid(); - - foreach ($stats as $stat) { - $params = array('id' => 'forced_title_' . $stat['name'] . '_' . $uniq_id, - 'class' => 'forced_title_layer', - 'content' => $stat['title'], - 'hidden' => true); - $out .= html_print_div($params, true); - } - - // If total count is less than 0, is an error. Never show negative numbers - if ($total_count < 0) { - $total_count = 0; - } - - $out .= '' . '' . $total_count . ''; - if (isset($fired_count) && $fired_count > 0) - $out .= ' ' . $separator . ' ' . $fired_count . ''; - if (isset($critical_count) && $critical_count > 0) - $out .= ' ' . $separator . ' ' . $critical_count . ''; - if (isset($warning_count) && $warning_count > 0) - $out .= ' ' . $separator . ' ' . $warning_count . ''; - if (isset($unknown_count) && $unknown_count > 0) - $out .= ' ' . $separator . ' ' . $unknown_count . ''; - if (isset($not_init_count) && $not_init_count > 0) - $out .= ' ' . $separator . ' ' . $not_init_count . ''; - if (isset($normal_count) && $normal_count > 0) - $out .= ' ' . $separator . ' ' . $normal_count . ''; - - $out .= ''; - - if ($return) { - return $out; - } - else { - echo $out; - } -} - - -function reporting_network_interfaces_table ($content, $report, $mini, $item_title = "", &$table = null, &$pdf = null) { - global $config; - - include_once($config['homedir'] . "/include/functions_custom_graphs.php"); - - if (empty($item_title)) { - $group_name = groups_get_name($content['id_group']); - $item_title = __('Network interfaces') . " - " . sprintf(__('Group "%s"'), $group_name); - } - - $is_html = $table !== null; - $is_pdf = $pdf !== null; - - $ttl = $is_pdf ? 2 : 1; - - $graph_width = 900; - $graph_height = 200; - - $datetime = $report['datetime']; - $period = $content['period']; - - if ($is_pdf) { - $graph_width = 800; - $graph_height = 200; - pdf_header_content($pdf, $content, $report, $item_title, false, $content["description"]); - } - else if ($is_html) { - reporting_header_content($mini, $content, $report, $table, $item_title); - - //RUNNING - $table->style[1] = 'text-align: right'; - - // Put description at the end of the module (if exists) - $table->colspan[0][1] = 2; - $next_row = 1; - if ($content["description"] != "") { - $table->colspan[$next_row][0] = 3; - $next_row++; - $data_desc = array(); - $data_desc[0] = $content["description"]; - array_push ($table->data, $data_desc); - } - } - - $filter = array( - 'id_grupo' => $content['id_group'], - 'disabled' => 0 - ); - $network_interfaces_by_agents = agents_get_network_interfaces(false, $filter); - - if (empty($network_interfaces_by_agents)) { - if ($is_pdf) { - $pdf->addHTML(__('The group has no agents or none of the agents has any network interface')); - } - else if ($is_html) { - $data = array(); - $data[0] = __('The group has no agents or none of the agents has any network interface'); - $table->colspan[$next_row][0] = 3; - array_push ($table->data, $data); - } - return; - } - else { - foreach ($network_interfaces_by_agents as $agent_id => $agent) { - - $table_agent = new StdCLass(); - $table_agent->width = '100%'; - $table_agent->data = array(); - $table_agent->head = array(); - $table_agent->head[0] = sprintf(__("Agent '%s'"), $agent['name']); - $table_agent->headstyle = array(); - $table_agent->headstyle[0] = 'font-size: 16px;'; - $table_agent->style[0] = 'text-align: center'; - - if ($is_pdf) { - $table_agent->class = 'table_sla table_beauty'; - $table_agent->headstyle[0] = 'background: #373737; color: #FFF; display: table-cell; font-size: 16px; border: 1px solid grey'; - } - - $table_agent->data['interfaces'] = ""; - - foreach ($agent['interfaces'] as $interface_name => $interface) { - $table_interface = new StdClass(); - $table_interface->width = '100%'; - $table_interface->data = array(); - $table_interface->rowstyle = array(); - $table_interface->head = array(); - $table_interface->cellstyle = array(); - $table_interface->title = sprintf(__("Interface '%s' throughput graph"), $interface_name); - $table_interface->head['ip'] = __('IP'); - $table_interface->head['mac'] = __('Mac'); - $table_interface->head['status'] = __('Actual status'); - $table_interface->style['ip'] = 'text-align: left'; - $table_interface->style['mac'] = 'text-align: left'; - $table_interface->style['status'] = 'width: 150px; text-align: center'; - - if ($is_pdf) { - $table_interface->class = 'table_sla table_beauty'; - $table_interface->titlestyle = 'background: #373737; color: #FFF; display: table-cell; font-size: 12px; border: 1px solid grey'; - - $table_interface->headstyle['ip'] = 'text-align: left; background: #666; color: #FFF; display: table-cell; font-size: 11px; border: 1px solid grey'; - $table_interface->headstyle['mac'] = 'text-align: left; background: #666; color: #FFF; display: table-cell; font-size: 11px; border: 1px solid grey'; - $table_interface->headstyle['status'] = 'background: #666; color: #FFF; display: table-cell; font-size: 11px; border: 1px solid grey'; - - $table_interface->style['ip'] = 'text-align: left; display: table-cell; font-size: 10px;'; - $table_interface->style['mac'] = 'text-align: left; display: table-cell; font-size: 10px;'; - $table_interface->style['status'] = 'text-align: center; display: table-cell; font-size: 10px;'; - } - - $data = array(); - $data['ip'] = !empty($interface['ip']) ? $interface['ip'] : "--"; - $data['mac'] = !empty($interface['mac']) ? $interface['mac'] : "--"; - $data['status'] = $interface['status_image']; - $table_interface->data['data'] = $data; - - if (!empty($interface['traffic'])) { - - $only_image = !(bool)$config['flash_charts'] || $is_pdf ? true : false; - - $graph = custom_graphs_print(0, - $graph_height, - $graph_width, - $period, - null, - true, - $date, - $only_image, - 'white', - array_values($interface['traffic']), - $config['homeurl'], - array_keys($interface['traffic']), - array_fill(0, count($interface['traffic']),"bytes/s"), - false, - true, - true, - true, - $ttl); - - $table_interface->data['graph'] = $graph; - $table_interface->colspan['graph'][0] = count($table_interface->head); - $table_interface->cellstyle['graph'][0] = 'text-align: center;'; - } - - $table_agent->data['interfaces'] .= html_print_table($table_interface, true); - $table_agent->colspan[$interface_name][0] = 3; - } - - if ($is_html) { - $table->data[$agent_id] = html_print_table($table_agent, true); - $table->colspan[$agent_id][0] = 3; - } - else if ($is_pdf) { - $html = html_print_table($table_agent, true); - $pdf->addHTML($html); - } - } - } -} - -function reporting_get_agents_by_status ($data, $graph_width = 250, $graph_height = 150, $links = false) { - global $config; - - if ($links == false) { - $links = array(); - } - - $table_agent = html_get_predefined_table(); - - $agent_data = array(); - $agent_data[0] = html_print_image('images/agent_critical.png', true, array('title' => __('Agents critical'))); - $agent_data[1] = ""; - $agent_data[1] .= format_numeric($data["agent_critical"]) <= 0 ? '-' : format_numeric($data['agent_critical']); - $agent_data[1] .= ""; - - $agent_data[2] = html_print_image('images/agent_warning.png', true, array('title' => __('Agents warning'))); - $agent_data[3] = ""; - $agent_data[3] .= $data["agent_warning"] <= 0 ? '-' : format_numeric($data['agent_warning']); - $agent_data[3] .= ""; - - $table_agent->data[] = $agent_data; - - $agent_data = array(); - $agent_data[0] = html_print_image('images/agent_ok.png', true, array('title' => __('Agents ok'))); - $agent_data[1] = ""; - $agent_data[1] .= $data["agent_ok"] <= 0 ? '-' : format_numeric($data['agent_ok']); - $agent_data[1] .= ""; - - $agent_data[2] = html_print_image('images/agent_unknown.png', true, array('title' => __('Agents unknown'))); - $agent_data[3] = ""; - $agent_data[3] .= $data["agent_unknown"] <= 0 ? '-' : format_numeric($data['agent_unknown']); - $agent_data[3] .= ""; - - $table_agent->data[] = $agent_data; - - $agent_data = array(); - $agent_data[0] = html_print_image('images/agent_notinit.png', true, array('title' => __('Agents not init'))); - $agent_data[1] = ""; - $agent_data[1] .= $data["agent_not_init"] <= 0 ? '-' : format_numeric($data['agent_not_init']); - $agent_data[1] .= ""; - - $agent_data[2] = ""; - $agent_data[3] = ""; - $table_agent->data[] = $agent_data; - - - if (!defined('METACONSOLE')) { - $agents_data = '
- ' . - __('Agents by status') . - '' . - html_print_table($table_agent, true) . '
'; - } - else{ - $table_agent->style=array(); - $table_agent->class = "tactical_view"; - $agents_data = '
- ' . - __('Agents by status') . - '' . - html_print_table($table_agent, true) . '
'; - } - - return $agents_data; -} - -function reporting_get_total_agents_and_monitors ($data, $graph_width = 250, $graph_height = 150) { - global $config; - - $total_agent = $data['agent_ok'] + $data['agent_warning'] + $data['agent_critical'] + $data['gent_unknown'] + $data['agent_not_init']; - $total_module = $data['monitor_ok'] + $data['monitor_warning'] + $data['monitor_critical'] + $data['monitor_unknown'] + $data['monitor_not_init']; - - $table_total = html_get_predefined_table(); - - $total_data = array(); - $total_data[0] = html_print_image('images/agent.png', true, array('title' => __('Total agents'))); - $total_data[1] = $total_agent <= 0 ? '-' : $total_agent; - $total_data[2] = html_print_image('images/module.png', true, array('title' => __('Monitor checks'))); - $total_data[3] = $total_module <= 0 ? '-' : $total_module; - $table_total->data[] = $total_data; - $total_agent_module = '
- ' . - __('Total agents and monitors') . - '' . - html_print_table($table_total, true) . '
'; - - return $total_agent_module; -} - -function reporting_get_total_servers ($num_servers) { - global $config; - - $table_node = html_get_predefined_table(); - - $node_data = array(); - $node_data[0] = html_print_image('images/server_export.png', true, array('title' => __('Nodes'))); - $node_data[1] = ""; - $node_data[1] .= $num_servers <= 0 ? '-' : format_numeric($num_servers); - $node_data[1] .= ""; - $table_node->data[] = $node_data; - - if (!defined('METACONSOLE')){ - $node_overview = '
- ' . - __('Node overview') . - '' . - html_print_table($table_node, true) . '
'; - }else{ - $table_node->style = array(); - $table_node->class = "tactical_view"; - $node_overview = '
- ' . - __('Node overview') . - '' . - html_print_table($table_node, true) . '
'; - } - - return $node_overview; -} - -function reporting_get_events ($data, $links = false) { - global $config; - - $table_events->width = "100%"; - if (defined('METACONSOLE')) - $style = " vertical-align:middle;"; - else - $style = ""; - if (defined('METACONSOLE')){ - $table_events->style[0] = "background-color:#FC4444"; - $table_events->data[0][0] = html_print_image('images/module_event_critical.png', true, array('title' => __('Critical events'))); - $table_events->data[0][0] .= "   " . - ""; - $table_events->data[0][0] .= format_numeric($data['critical']) <= 0 ? ' -' : format_numeric($data['critical']); - $table_events->data[0][0] .= ""; - $table_events->style[1] = "background-color:#FAD403"; - $table_events->data[0][1] = html_print_image('images/module_event_warning.png', true, array('title' => __('Warning events'))); - $table_events->data[0][1] .= "   " . - ""; - $table_events->data[0][1] .= format_numeric($data['warning']) <= 0 ? ' -' : format_numeric($data['warning']); - $table_events->data[0][1] .= ""; - $table_events->style[2] = "background-color:#80BA27"; - $table_events->data[0][2] = html_print_image('images/module_event_ok.png', true, array('title' => __('OK events'))); - $table_events->data[0][2] .= "   " . - ""; - $table_events->data[0][2] .= format_numeric($data['normal']) <= 0 ? ' -' : format_numeric($data['normal']); - $table_events->data[0][2] .= ""; - $table_events->style[3] = "background-color:#B2B2B2"; - $table_events->data[0][3] = html_print_image('images/module_event_unknown.png', true, array('title' => __('Unknown events'))); - $table_events->data[0][3] .= "   " . - ""; - $table_events->data[0][3] .=format_numeric($data['unknown']) <= 0 ? ' -' : format_numeric($data['unknown']); - $table_events->data[0][3] .=""; - } - else{ - $table_events->data[0][0] = html_print_image('images/module_critical.png', true, array('title' => __('Critical events'))); - $table_events->data[0][0] .= "   " . - "". - format_numeric($data['critical']).""; - $table_events->data[0][1] = html_print_image('images/module_warning.png', true, array('title' => __('Warning events'))); - $table_events->data[0][1] .= "   " . - "". - format_numeric($data['warning']).""; - $table_events->data[0][2] = html_print_image('images/module_ok.png', true, array('title' => __('OK events'))); - $table_events->data[0][2] .= "   " . - "". - format_numeric($data['normal']).""; - $table_events->data[0][3] = html_print_image('images/module_unknown.png', true, array('title' => __('Unknown events'))); - $table_events->data[0][3] .= "   " . - "". - format_numeric($data['unknown']).""; - - } - if (!defined('METACONSOLE')) { - $event_view = '
- ' . - __('Events by criticity') . - '' . - html_print_table($table_events, true) . '
'; - } - else{ - $table_events->class="tactical_view"; - $table_events->styleTable="text-align:center;"; - $table_events->size[0]="10%"; - $table_events->size[1]="10%"; - $table_events->size[2]="10%"; - $table_events->size[3]="10%"; - - $event_view = '
- ' . - __('Important Events by Criticity') . - '' . - html_print_table($table_events, true) . '
'; - } - - return $event_view; -} - -function reporting_get_last_activity() { - global $config; - - // Show last activity from this user - - $table->width = '100%'; - $table->data = array (); - $table->size = array (); - $table->size[2] = '150px'; - $table->size[3] = '130px'; - $table->size[5] = '200px'; - $table->head = array (); - $table->head[0] = __('User'); - $table->head[1] = ''; - $table->head[2] = __('Action'); - $table->head[3] = __('Date'); - $table->head[4] = __('Source IP'); - $table->head[5] = __('Comments'); - $table->title = '' . __('Last activity in Pandora FMS console') . ''; - - switch ($config["dbtype"]) { - case "mysql": - $sql = sprintf ("SELECT id_usuario,accion,fecha,ip_origen,descripcion,utimestamp - FROM tsesion - WHERE (`utimestamp` > UNIX_TIMESTAMP(NOW()) - " . SECONDS_1WEEK . ") - AND `id_usuario` = '%s' ORDER BY `utimestamp` DESC LIMIT 5", $config["id_user"]); - break; - case "postgresql": - $sql = sprintf ("SELECT \"id_usuario\", accion, fecha, \"ip_origen\", descripcion, utimestamp - FROM tsesion - WHERE (\"utimestamp\" > ceil(date_part('epoch', CURRENT_TIMESTAMP)) - " . SECONDS_1WEEK . ") - AND \"id_usuario\" = '%s' ORDER BY \"utimestamp\" DESC LIMIT 5", $config["id_user"]); - break; - case "oracle": - $sql = sprintf ("SELECT id_usuario, accion, fecha, ip_origen, descripcion, utimestamp - FROM tsesion - WHERE ((utimestamp > ceil((sysdate - to_date('19700101000000','YYYYMMDDHH24MISS')) * (" . SECONDS_1DAY . ")) - " . SECONDS_1WEEK . ") - AND id_usuario = '%s') AND rownum <= 10 ORDER BY utimestamp DESC", $config["id_user"]); - break; - } - - $sessions = db_get_all_rows_sql ($sql); - - if ($sessions === false) - $sessions = array (); - - foreach ($sessions as $session) { - $data = array (); - - switch ($config["dbtype"]) { - case "mysql": - case "oracle": - $session_id_usuario = $session['id_usuario']; - $session_ip_origen = $session['ip_origen']; - break; - case "postgresql": - $session_id_usuario = $session['id_usuario']; - $session_ip_origen = $session['ip_origen']; - break; - } - - - $data[0] = '' . $session_id_usuario . ''; - $data[1] = ui_print_session_action_icon ($session['accion'], true); - $data[2] = $session['accion']; - $data[3] = ui_print_help_tip($session['fecha'], true) . human_time_comparation($session['utimestamp'], 'tiny'); - $data[4] = $session_ip_origen; - $data[5] = io_safe_output ($session['descripcion']); - - array_push ($table->data, $data); - } - - if(defined("METACONSOLE")) - $table->class="databox_tactical"; - - return html_print_table ($table, true); - -} - -function reporting_get_event_histogram ($events) { - global $config; - include_once ('../../include/graphs/functions_gd.php'); - $max_value = count($events); - if (defined("METACONSOLE")) - $max_value = SECONDS_1HOUR; - - $ttl = 1; - $urlImage = ui_get_full_url(false, true, false, false); - - $colors = array( - EVENT_CRIT_MAINTENANCE => COL_MAINTENANCE, - EVENT_CRIT_INFORMATIONAL => COL_INFORMATIONAL, - EVENT_CRIT_NORMAL => COL_NORMAL, - EVENT_CRIT_MINOR => COL_MINOR, - EVENT_CRIT_WARNING => COL_WARNING, - EVENT_CRIT_MAJOR => COL_MAJOR, - EVENT_CRIT_CRITICAL => COL_CRITICAL - ); - if(defined("METACONSOLE")){ - $full_legend = array(); - $cont = 0; - } - - foreach ($events as $data) { - - switch ($data['criticity']) { - case 0: - $color = EVENT_CRIT_MAINTENANCE; - break; - case 1: - $color = EVENT_CRIT_INFORMATIONAL; - break; - case 2: - $color = EVENT_CRIT_NORMAL; - break; - case 3: - $color = EVENT_CRIT_WARNING; - break; - case 4: - $color = EVENT_CRIT_CRITICAL; - break; - case 5: - $color = EVENT_CRIT_MINOR; - break; - case 6: - $color = EVENT_CRIT_MAJOR; - break; - case 20: - $color = EVENT_CRIT_NOT_NORMAL; - break; - case 34: - $color = EVENT_CRIT_WARNING_OR_CRITICAL; - break; - } - - if(defined("METACONSOLE")){ - $full_legend[$cont] = $data['timestamp']; - $graph_data[] = array( - 'data' => $color, - 'utimestamp' => $data['utimestamp'] - get_system_time () - ); - $cont++; - } - else{ - $graph_data[] = array( - 'data' => $color, - 'utimestamp' => 1 - ); - } - } - - $table->width = '100%'; - $table->data = array (); - $table->size = array (); - $table->head = array (); - $table->title = '' . __('Events info (1hr.)') . ''; - $table->data[0][0] = "" ; - - if (!empty($graph_data)) { - if (defined("METACONSOLE")) - $slicebar = flot_slicesbar_graph($graph_data, $max_value, "100%", 35, $full_legend, $colors, $config['fontpath'], $config['round_corner'], $urlImage); - else - $slicebar = slicesbar_graph($graph_data, $max_value, 700, 25, $colors, $config['fontpath'], $config['round_corner'], $urlImage, $ttl); - - $table->data[0][0] = $slicebar; - } else { - $table->data[0][0] = __('No events'); - } - - if(!defined('METACONSOLE')){ - $event_graph = '
- ' . - __('Events info (1hr)') . - '' . - html_print_table($table, true) . '
'; - } - else{ - $table->class='tactical_view'; - $event_graph = '
' . - html_print_table($table, true) . '
'; - } - - return $event_graph; -} ?> \ No newline at end of file From 62c7ac463d8e100f4d0df69dee27bb53573e9f97 Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Mon, 30 Mar 2015 17:07:57 +0200 Subject: [PATCH 25/80] Working in the refactoring the code of reports (agent_configuration). --- .../include/functions_reporting.php | 112 +++++++++ .../include/functions_reporting_html.php | 228 +++++++----------- 2 files changed, 203 insertions(+), 137 deletions(-) diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index 43e29667d9..db326bada3 100644 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -36,6 +36,7 @@ enterprise_include_once('include/functions_inventory.php'); include_once($config['homedir'] . "/include/functions_forecast.php"); include_once($config['homedir'] . "/include/functions_ui.php"); include_once($config['homedir'] . "/include/functions_netflow.php"); +include_once($config['homedir'] . "/include/functions_os.php"); function reporting_user_can_see_report($id_report, $id_user = null) { global $config; @@ -122,6 +123,7 @@ function reporting_make_reporting_data($id_report, $date, $time, return $return; } + $report["group"] = $report['id_group']; $report["group_name"] = groups_get_name ($report['id_group']); $datetime = strtotime($date . ' ' . $time); @@ -227,12 +229,122 @@ function reporting_make_reporting_data($id_report, $date, $time, $content, 'TTRT'); break; + case 'agent_configuration': + $report['contents'][] = reporting_agent_configuration( + $report, + $content); + break; } } return reporting_check_structure_report($report); } +function reporting_agent_configuration($report, $content) { + global $config; + + $return['type'] = 'agent_configuration'; + + if (empty($content['name'])) { + $content['name'] = __('Agent configuration'); + } + + $return['title'] = $content['name']; + $return["description"] = $content["description"]; + $return["date"] = reporting_get_date_text($report, $content); + + + $sql = " + SELECT * + FROM tagente + WHERE id_agente=" . $content['id_agent']; + $agent_data = db_get_row_sql($sql); + + $agent_configuration = array(); + $agent_configuration['name'] = $agent_data['nombre']; + $agent_configuration['group'] = groups_get_name($agent_data['id_grupo']); + $agent_configuration['group_icon'] = + ui_print_group_icon ($agent_data['id_grupo'], true, '', '', false); + $agent_configuration['os'] = os_get_name($agent_data["id_os"]); + $agent_configuration['os_icon'] = ui_print_os_icon($agent_data["id_os"], true, true); + $agent_configuration['address'] = $agent_data['direccion']; + $agent_configuration['description'] = + strip_tags(ui_bbcode_to_html($agent_data['comentarios'])); + $agent_configuration['enabled'] = (int)!$agent_data['disabled']; + $agent_configuration['group'] = $report["group"]; + + $modules = agents_get_modules ($content['id_agent']); + + $agent_configuration['modules'] = array(); + //Agent's modules + if (!empty($modules)) { + foreach ($modules as $id_agent_module => $module) { + $sql = " + SELECT * + FROM tagente_modulo + WHERE id_agente_modulo = $id_agent_module"; + $module_db = db_get_row_sql($sql); + + + $data_module = array(); + $data_module['name'] = $module_db['nombre']; + if ($module_db['disabled']) { + $data_module['name'] .= " (" . __('Disabled') . ")"; + } + $data_module['type_icon'] = + ui_print_moduletype_icon($module_db['id_tipo_modulo'], true); + $data_module['type'] = + modules_get_type_name($module_db['id_tipo_modulo']); + $data_module['max_warning'] = + $module_db['max_warning']; + $data_module['min_warning'] = + $module_db['min_warning']; + $data_module['max_critical'] = + $module_db['max_critical']; + $data_module['min_critical'] = + $module_db['min_critical']; + $data_module['threshold'] = $module_db['module_ff_interval']; + $data_module['description'] = $module_db['descripcion']; + if (($module_db['module_interval'] == 0) || + ($module_db['module_interval'] == '')) { + + $data_module['interval'] = db_get_value('intervalo', + 'tagente', 'id_agente', $content['id_agent']); + } + else { + $data_module['interval'] = $module_db['module_interval']; + } + $data_module['unit'] = $module_db['unit']; + $module_status = db_get_row( + 'tagente_estado', 'id_agente_modulo', $id_agent_module); + modules_get_status($id_agent_module, + $module_status['estado'], + $module_status['datos'], $status, $title); + $data_module['status_icon'] = + ui_print_status_image($status, $title, true); + $data_module['status'] = $title; + $sql_tag = " + SELECT name + FROM ttag + WHERE id_tag IN ( + SELECT id_tag + FROM ttag_module + WHERE id_agente_modulo = $id_agent_module)"; + $tags = db_get_all_rows_sql($sql_tag); + if ($tags === false) + $data_module['tags'] = array(); + else + $data_module['tags'] = $tags; + + $agent_configuration['modules'][] = $data_module; + } + } + + $return['data'] = $agent_configuration; + + return reporting_check_structure_content($return); +} + function reporting_value($report, $content, $type) { global $config; diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index 33536abdae..207d7499a6 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -167,6 +167,9 @@ function reporting_html_print_report($report, $mini = false) { case 'TTRT': reporting_html_TTRT_value($table, $item, $mini, false, true); break; + case 'agent_configuration': + reporting_html_agent_configuration($table, $item); + break; } if ($item['type'] == 'agent_module') @@ -179,6 +182,91 @@ function reporting_html_print_report($report, $mini = false) { } } +function reporting_html_agent_configuration(&$table, $item) { + $table->colspan['agent']['cell'] = 3; + $table->cellstyle['agent']['cell'] = 'text-align: left;'; + + $table1->width = '99%'; + $table1->head = array (); + $table1->head['name'] = __('Agent name'); + $table1->head['group'] = __('Group'); + $table1->head['os'] = __('OS'); + $table1->head['address'] = __('IP'); + $table1->head['description'] = __('Description'); + $table1->head['status'] = __('Status'); + $table1->data = array (); + $row = array(); + $row['name'] = $item['data']['name']; + $row['group'] = $item['data']['group_icon']; + $row['address'] = $item['data']['os_icon']; + $row['os'] = $item['data']['address']; + $row['description'] = $item['data']['description']; + if ($item['data']['enabled']) { + $row['status'] = __('Enabled'); + } + else { + $row['status'] = __('Disabled'); + } + $table1->data[] = $row; + $table->data['agent']['cell'] = html_print_table($table1, true); + + + $table->colspan['modules']['cell'] = 3; + $table->cellstyle['modules']['cell'] = 'text-align: left;'; + + if (empty($item['data']['modules'])) { + $table->data['modules']['cell'] = __('Empty modules'); + } + else { + $table1->width = '99%'; + $table1->head = array (); + $table1->head['name'] = __('Name'); + $table1->head['type'] = __('Type'); + $table1->head['warning_critical'] = __('Warning
Critical'); + $table1->head['threshold'] = __('Threshold'); + $table1->head['group_icon'] = __('Group'); + $table1->head['description'] = __('Description'); + $table1->head['interval'] = __('Interval'); + $table1->head['unit'] = __('Unit'); + $table1->head['status'] = __('Status'); + $table1->head['tags'] = __('Tags'); + $table1->align = array(); + $table1->align['name'] = 'left'; + $table1->align['type'] = 'center'; + $table1->align['warning_critical'] = 'right'; + $table1->align['threshold'] = 'right'; + $table1->align['group_icon'] = 'center'; + $table1->align['description'] = 'left'; + $table1->align['interval'] = 'right'; + $table1->align['unit'] = 'left'; + $table1->align['status'] = 'center'; + $table1->align['tags'] = 'left'; + $table1->data = array (); + + foreach ($item['data']['modules'] as $module) { + $row = array(); + + $row['name'] = $module['name']; + $row['type'] = $module['type_icon']; + $row['warning_critical'] = + $module['max_warning'] . " / " . $module['min_warning'] . + "
" . + $module['max_critical'] . " / " . $module['min_critical']; + $row['threshold'] = $module['threshold']; + $row['group_icon'] = ui_print_group_icon($item['data']['group'], true); + $row['description'] = $module['description']; + $row['interval'] = $module['interval']; + $row['unit'] = $module['unit']; + $row['status'] = $module['status_icon']; + $row['tags'] = implode(",", $module['tags']); + + $table1->data[] = $row; + } + + $table->data['modules']['cell'] = html_print_table($table1, true); + } +} + function reporting_html_TTO_value(&$table, $item, $mini, $only_value = false, $check_empty = false) { reporting_html_value($table, $item, $mini); } @@ -204,7 +292,7 @@ function reporting_html_max_value(&$table, $item, $mini) { } function reporting_html_min_value(&$table, $item, $mini) { - reporting_html_value($table, $item, $mini, $only_value, $check_empty); + reporting_html_value($table, $item, $mini); } function reporting_html_value(&$table, $item, $mini, $only_value = false, $check_empty = false) { @@ -5507,142 +5595,8 @@ function reporting_render_report_html_item ($content, $table, $report, $mini = f array_push ($table->data, $data); break; - case 'agent_configuration': - - if (empty($item_title)) { - $item_title = __('Agent configuration: ').$agent_name; - } - reporting_header_content($mini, $content, $report, $table, $item_title); - - $agent_name = agents_get_name ($content['id_agent']); - $modules = agents_get_modules ($content['id_agent']); - - $data= array (); - $table->colspan[0][1] = 10; - - //Agent's data - $data[0] = ''.__('Agent name').''; - $data[1] = ''.__('Group').''; - $data[2] = ''.__('SO').''; - $data[3] = ''.__('IP').''; - $data[4] = ''.__('Description').''; - $data[5] = ''.__('Status').''; - - $table->colspan[1][3] = 2; - $table->colspan[1][4] = 4; - $table->colspan[1][5] = 2; - $table->colspan[1][5] = 2; - array_push ($table->data, $data); - unset($data); - - $sql = "SELECT * FROM tagente WHERE id_agente=".$content['id_agent']; - $agent_data = db_get_row_sql($sql); - - $data[0] = $agent_data['nombre']; - $data[1] = ui_print_group_icon ($agent_data['id_grupo'], true, '', '', false); - $data[2] = ui_print_os_icon ($agent_data["id_os"], true, true); - $data[3] = $agent_data['direccion']; - $agent_data_comentarios = strip_tags(ui_bbcode_to_html($agent_data['comentarios'])); - $data[4] = $agent_data_comentarios; - - if ($agent_data['disabled'] == 0) - $data[5] = __('Enabled'); - else - $data[5] = __('Disabled'); - - $table->colspan[2][3] = 2; - $table->colspan[2][4] = 4; - $table->colspan[2][5] = 2; - array_push ($table->data, $data); - unset($data); - - //Agent's modules - if ($modules == null) { - $modules = array(); - } - else { - $data[0] = ''; - $data[1] = ''.agents_get_name ($content['id_agent'], 'upper').__(' MODULES').''; - $table->colspan[3][1] = 10; - - array_push ($table->data, $data); - unset($data); - - $data[0] = ''; - $data[1] = ''.__('Name').''; - $data[2] = ''.__('Type').''; - $data[3] = ''.__('Warning').'/'.'
'.__('Critical').'
'; - $data[4] = ''.__('Threshold').''; - $data[5] = ''.__('Group').''; - $data[6] = ''.__('Description').''; - $data[7] = ''.__('Interval').''; - $data[8] = ''.__('Unit').''; - $data[9] = ''.__('Status').''; - $data[10] = ''.__('Tags').''; - - $table->style[0] = 'width:10px'; - $table->style[1] = 'text-align: left'; - $table->style[2] = 'text-align: center'; - $table->style[3] = 'text-align: center'; - $table->style[4] = 'text-align: center'; - $table->style[5] = 'text-align: center'; - $table->style[6] = 'text-align: left'; - $table->style[7] = 'text-align: center'; - $table->style[8] = 'text-align: center'; - $table->style[9] = 'text-align: left'; - $table->style[10] = 'text-align: left'; - - array_push ($table->data, $data); - } - - foreach ($modules as $id_agent_module=>$module) { - $sql = "SELECT * FROM tagente_modulo WHERE id_agente_modulo=$id_agent_module"; - $data_module = db_get_row_sql($sql); - - $data = array(); - - $data[0] = ''; - - if ($data_module['disabled'] == 0) - $disabled = ''; - else - $disabled = ' (Disabled)'; - $data[1] = $data_module['nombre'].$disabled; - $data[2] = ui_print_moduletype_icon ($data_module['id_tipo_modulo'], true); - $data[3] = $data_module['max_warning'].'/'.$data_module['min_warning'].'
'.$data_module['max_critical'].'/'.$data_module['min_critical']; - $data[4] = $data_module['module_ff_interval']; - $data[5] = groups_get_name ($content['id_group'], true); - $data[6] = $data_module['descripcion']; - - if (($data_module['module_interval'] == 0) || ($data_module['module_interval'] == '')) - $data[7] = db_get_value('intervalo', 'tagente', 'id_agente', $content['id_agent']); - else - $data[7] = $data_module['module_interval']; - - - $data[8] = $data_module['unit']; - - $module_status = db_get_row('tagente_estado', 'id_agente_modulo', $id_agent_module); - modules_get_status($id_agent_module, $module_status['estado'], $module_status['datos'], $status, $title); - $data[9] = ui_print_status_image($status, $title, true); - - $sql_tag = "SELECT name - FROM ttag - WHERE id_tag IN ( - SELECT id_tag - FROM ttag_module - WHERE id_agente_modulo = $id_agent_module)"; - $tags = db_get_all_rows_sql($sql_tag); - if ($tags === false) - $tags = ''; - else - $tags = implode (",", $tags); - - $data[10] = $tags; - array_push ($table->data, $data); - } - - break; + + case 'group_configuration': $group_name = groups_get_name($content['id_group']); if (empty($item_title)) { From f84863540f0616ee23c6d7a5822e5f349832375e Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Fri, 10 Apr 2015 00:58:24 +0200 Subject: [PATCH 26/80] Merge from the pandora_5.1 branch to feature/#1978-REESCRITURA_DEL_MOTOR_DE_INFORMES branch the new report items (availability and time overlaped in the simple graphs). --- pandora_console/general/header.php | 1 + .../godmode/agentes/configurar_agente.php | 2 +- .../godmode/agentes/modificar_agente.php | 2 + .../godmode/agentes/module_manager_editor.php | 2 +- .../godmode/alerts/alert_commands.php | 2 +- .../godmode/alerts/configure_alert_action.php | 2 +- .../alerts/configure_alert_template.php | 4 +- pandora_console/godmode/category/category.php | 3 +- .../godmode/events/custom_events.php | 1 + .../godmode/events/event_edit_filter.php | 7 +- .../godmode/events/event_responses.editor.php | 2 +- .../godmode/events/event_responses.list.php | 4 +- .../massive/massive_add_action_alerts.php | 2 +- .../reporting_builder.item_editor.php | 188 +++++++++++--- .../godmode/reporting/reporting_builder.php | 71 ++++-- pandora_console/include/functions_modules.php | 128 +++++++++- .../include/functions_reporting.php | 240 +++++++++++++++++- .../include/functions_reporting_html.php | 90 +++++++ pandora_console/include/functions_reports.php | 3 +- .../operation/reporting/reporting_viewer.php | 2 +- 20 files changed, 683 insertions(+), 73 deletions(-) diff --git a/pandora_console/general/header.php b/pandora_console/general/header.php index f0e69a6ae3..920cd76295 100644 --- a/pandora_console/general/header.php +++ b/pandora_console/general/header.php @@ -227,6 +227,7 @@ config_check(); } $table->data[0][3] = $maintenance_img; + // Main help icon $table->data[0][4] = ui_print_help_icon ("main_help", true, '', 'images/header_help.png'); diff --git a/pandora_console/godmode/agentes/configurar_agente.php b/pandora_console/godmode/agentes/configurar_agente.php index be8db775eb..6700e82a81 100644 --- a/pandora_console/godmode/agentes/configurar_agente.php +++ b/pandora_console/godmode/agentes/configurar_agente.php @@ -918,7 +918,7 @@ if ($update_module || $create_module) { $plugin_parameter = (string) get_parameter ('plugin_parameter'); } - + $ip_target = (string) get_parameter ('ip_target'); $custom_id = (string) get_parameter ('custom_id'); $history_data = (int) get_parameter('history_data'); diff --git a/pandora_console/godmode/agentes/modificar_agente.php b/pandora_console/godmode/agentes/modificar_agente.php index e79a653d6b..ea2127f59e 100644 --- a/pandora_console/godmode/agentes/modificar_agente.php +++ b/pandora_console/godmode/agentes/modificar_agente.php @@ -139,6 +139,7 @@ if (!$own_info['is_admin'] && !check_acl ($config['id_user'], 0, "PM")) else $return_all_group = true; html_print_select_groups(false, "AR", $return_all_group, "ag_group", $ag_group, 'this.form.submit();', '', 0, false, false, true, '', false, 'width:100px;'); + echo ""; echo __('Show Agents') . ' '; $fields = array( @@ -406,6 +407,7 @@ else { } } + $agents = db_get_all_rows_sql ($sql); // Delete rnum row generated by oracle_recode_query() function diff --git a/pandora_console/godmode/agentes/module_manager_editor.php b/pandora_console/godmode/agentes/module_manager_editor.php index ccff4f36b5..14d7e8ed77 100644 --- a/pandora_console/godmode/agentes/module_manager_editor.php +++ b/pandora_console/godmode/agentes/module_manager_editor.php @@ -31,7 +31,7 @@ if (is_ajax ()) { $component['throw_unknown_events'] = !network_components_is_disable_type_event($id_component, EVENTS_GOING_UNKNOWN); - + // Decrypt passwords in the component. $component['plugin_pass'] = io_output_password($component['plugin_pass']); diff --git a/pandora_console/godmode/alerts/alert_commands.php b/pandora_console/godmode/alerts/alert_commands.php index 40c00406da..9552e12827 100644 --- a/pandora_console/godmode/alerts/alert_commands.php +++ b/pandora_console/godmode/alerts/alert_commands.php @@ -140,7 +140,7 @@ if (is_ajax ()) { $rfield = html_print_select($fields_value_select, 'field'.$i.'_recovery_value', '', '', '', 0, true, false, false, 'fields_recovery'); } - else{ + else { $ffield = html_print_textarea ('field' . $i . '_value',1, 1, $fv[0], 'style="min-height:40px" class="fields"', true); $rfield = html_print_textarea ('field' . $i . '_recovery_value', 1, 1, $fv[0], diff --git a/pandora_console/godmode/alerts/configure_alert_action.php b/pandora_console/godmode/alerts/configure_alert_action.php index 1dfdbb2200..77fe5bbfa3 100644 --- a/pandora_console/godmode/alerts/configure_alert_action.php +++ b/pandora_console/godmode/alerts/configure_alert_action.php @@ -306,7 +306,7 @@ $(document).ready (function () { $("[name=field" + i + "_value]").val(old_value); $("[name=field" + i + "_recovery_value]").val(old_recovery_value); } - else{ + else { $("[name=field" + i + "_value]").val($("[name=field" + i + "_value]").val()); $("[name=field" + i + "_recovery_value]").val($("[name=field" + i + "_recovery_value]").val()); } diff --git a/pandora_console/godmode/alerts/configure_alert_template.php b/pandora_console/godmode/alerts/configure_alert_template.php index 26bad3f89a..176a6623ac 100644 --- a/pandora_console/godmode/alerts/configure_alert_template.php +++ b/pandora_console/godmode/alerts/configure_alert_template.php @@ -471,7 +471,7 @@ print_alert_template_steps ($step, $id); $table->id = 'template'; $table->width = '98%'; -if(defined("METACONSOLE")){ +if(defined("METACONSOLE")) { $table->width = '100%'; $table->class = 'databox data'; $table->head[0] = __('Create Template'); @@ -479,7 +479,7 @@ if(defined("METACONSOLE")){ $table->headstyle[0] = 'text-align: center'; } $table->style = array (); -if(!defined("METACONSOLE")){ +if(!defined("METACONSOLE")) { $table->style[0] = 'font-weight: bold; vertical-align: top'; $table->style[2] = 'font-weight: bold; vertical-align: top'; } diff --git a/pandora_console/godmode/category/category.php b/pandora_console/godmode/category/category.php index d6129a11e3..dfe354aad3 100755 --- a/pandora_console/godmode/category/category.php +++ b/pandora_console/godmode/category/category.php @@ -43,7 +43,7 @@ if(defined('METACONSOLE')) { 'text' => '' . html_print_image ("images/list.png", true, array ("title" => __('List categories'))) .'')); } -else{ +else { $buttons = array( 'list' => array( 'active' => false, @@ -132,6 +132,7 @@ if (!empty($result)) { $iterator++; $data = array (); + if(defined('METACONSOLE')){ $data[0] = "" . $category["name"] . ""; $data[1] = "" . html_print_image("images/config.png", true, array("title" => "Edit")) . "  "; diff --git a/pandora_console/godmode/events/custom_events.php b/pandora_console/godmode/events/custom_events.php index e0cceddebc..2382378e6b 100644 --- a/pandora_console/godmode/events/custom_events.php +++ b/pandora_console/godmode/events/custom_events.php @@ -28,6 +28,7 @@ if (! check_acl($config['id_user'], 0, "EW")) { $update = get_parameter('upd_button', ''); $default = (int) get_parameter('default', 0); + if ($default != 0) { $event_fields = io_safe_input('evento,id_agente,estado,timestamp'); $fields_selected = explode (',', $event_fields); diff --git a/pandora_console/godmode/events/event_edit_filter.php b/pandora_console/godmode/events/event_edit_filter.php index af44c2a72a..5891fd4db3 100644 --- a/pandora_console/godmode/events/event_edit_filter.php +++ b/pandora_console/godmode/events/event_edit_filter.php @@ -157,7 +157,8 @@ $table->class = "databox"; $table->style[0] = 'vertical-align: top;'; $table->valign[1] = 'top'; -if (defined('METACONSOLE')){ + +if (defined('METACONSOLE')) { $table->width = '100%'; $table->border = 0; $table->cellspacing = 3; @@ -285,7 +286,7 @@ $add_without_tag_disabled = empty($tags_select_without); $remove_without_tag_disabled = empty($tag_without_temp); -if (defined("METACONSOLE")){ +if (defined("METACONSOLE")) { $table->data[13][0] = '' . __('Events with following tags') . ''; $table->data[13][0] .= '
' . html_print_select ($tags_select_with, 'select_with', @@ -537,4 +538,4 @@ function replace_hidden_tags(what_button) { $(id_hidden).val(Base64.encode(jQuery.toJSON(value_store))); } /* ]]> */ - + \ No newline at end of file diff --git a/pandora_console/godmode/events/event_responses.editor.php b/pandora_console/godmode/events/event_responses.editor.php index 1bca27e8c7..4f5da16a6b 100644 --- a/pandora_console/godmode/events/event_responses.editor.php +++ b/pandora_console/godmode/events/event_responses.editor.php @@ -57,7 +57,7 @@ else { $table->width = '90%'; -if(defined('METACONSOLE')){ +if(defined('METACONSOLE')) { $table->width = '100%'; $table->class = 'databox data'; $table->head[0] = __('Edit event responses'); diff --git a/pandora_console/godmode/events/event_responses.list.php b/pandora_console/godmode/events/event_responses.list.php index 687c8e81a4..174b60288e 100644 --- a/pandora_console/godmode/events/event_responses.list.php +++ b/pandora_console/godmode/events/event_responses.list.php @@ -25,7 +25,7 @@ if (! check_acl($config['id_user'], 0, "PM")) { return; } -if(!defined('METACONSOLE')){ +if(!defined('METACONSOLE')) { echo '

'; echo ''; html_print_submit_button(__('Create response'), 'create_response_button', false, array('class' => 'sub next')); @@ -78,7 +78,7 @@ foreach($event_responses as $response) { html_print_table($table); -if(defined('METACONSOLE')){ +if(defined('METACONSOLE')) { echo '

'; echo ''; html_print_submit_button(__('Create response'), 'create_response_button', false, array('class' => 'sub next')); diff --git a/pandora_console/godmode/massive/massive_add_action_alerts.php b/pandora_console/godmode/massive/massive_add_action_alerts.php index 85d32ae932..7262fce4f3 100755 --- a/pandora_console/godmode/massive/massive_add_action_alerts.php +++ b/pandora_console/godmode/massive/massive_add_action_alerts.php @@ -176,7 +176,7 @@ $agents_with_templates_json = json_encode($agents_with_templates_json); echo ""; -echo '
'; +echo '
'; html_print_input_hidden ('add', 1); html_print_submit_button (__('Add'), 'go', false, 'class="sub add"'); echo '
'; diff --git a/pandora_console/godmode/reporting/reporting_builder.item_editor.php b/pandora_console/godmode/reporting/reporting_builder.item_editor.php index 5cc76ae83a..3737e6b3a3 100644 --- a/pandora_console/godmode/reporting/reporting_builder.item_editor.php +++ b/pandora_console/godmode/reporting/reporting_builder.item_editor.php @@ -58,6 +58,7 @@ $group = 0; $group_by_agent = 0; $order_uptodown = 0; $show_resume = 0; +$show_address_agent = 0; $top_n = 0; $top_n_value = 10; $exception_condition = REPORT_EXCEPTION_CONDITION_EVERYTHING; @@ -87,6 +88,7 @@ $inventory_modules = array(); $date = null; // Only avg is selected by default for the simple graphs $only_avg = true; +$time_compare_overlapped = false; //Added for events items $filter_event_validated = false; @@ -187,6 +189,9 @@ switch ($action) { $projection_period = $item['top_n_value']; $period_pg = $item['period']; } + + // HACK it is saved in show_graph field. + $time_compare_overlapped = $item['show_graph']; break; case 'prediction_date': $description = $item['description']; @@ -419,7 +424,15 @@ switch ($action) { $period = $item['period']; $order_uptodown = $item['order_uptodown']; $show_resume = $item['show_resume']; - $show_graph = $item['show_graph']; + break; + case 'availability': + $description = $item['description']; + $period = $item['period']; + $order_uptodown = $item['order_uptodown']; + $show_resume = $item['show_resume']; + // HACK it is saved in show_graph field. + // Show interfaces instead the modules + $show_address_agent = $item['show_graph']; break; case 'group_report': $description = $item['description']; @@ -498,7 +511,8 @@ switch ($action) { break; } -$urlForm = $config['homeurl'] . 'index.php?sec=reporting&sec2=godmode/reporting/reporting_builder&tab=item_editor&action=' . $actionParameter . '&id_report=' . $idReport; +$urlForm = $config['homeurl'] . + 'index.php?sec=reporting&sec2=godmode/reporting/reporting_builder&tab=item_editor&action=' . $actionParameter . '&id_report=' . $idReport; echo ''; html_print_input_hidden('id_item', $idItem); @@ -518,7 +532,7 @@ else " . __('Item Editor') . " - "; + "; } ?> @@ -552,8 +566,8 @@ else - + + + + + + + @@ -1080,9 +1102,28 @@ else + + + + + + + + - + + + @@ -1144,7 +1185,7 @@ else
'; if ($action == 'new') { html_print_submit_button(__('Create item'), 'create_item', false, 'class="sub wand"'); @@ -1170,7 +1211,8 @@ function print_SLA_list($width, $action, $idItem = null) { global $config; global $meta; - $report_item_type = db_get_value ('type', 'treport_content', 'id_rc', $idItem); + $report_item_type = db_get_value('type', 'treport_content', 'id_rc', + $idItem); ?> @@ -1222,17 +1264,17 @@ function print_SLA_list($width, $action, $idItem = null) { $server_name_element = ''; if ($meta && $server_name != '') $server_name_element .= ' (' . $server_name . ')'; - + echo ''; echo ''; echo ''; - + if (enterprise_installed() && $report_item_type == 'SLA_services') { enterprise_include_once("include/functions_services.php"); $nameService = enterprise_hook('services_get_name', array($item['id_agent_module'])); echo ''; echo ''; echo ''; @@ -1322,9 +1364,10 @@ function print_SLA_list($width, $action, $idItem = null) { - - - - + + + + + + + + + + '; - $itemsGeneral = db_get_all_rows_filter('treport_content_item', array('id_report_content' => $idItem)); + $itemsGeneral = db_get_all_rows_filter( + 'treport_content_item', + array('id_report_content' => $idItem)); if ($itemsGeneral === false) { $itemsGeneral = array(); } + foreach ($itemsGeneral as $item) { $server_name = $item ['server_name']; // Metaconsole db connection @@ -1373,22 +1432,41 @@ function print_General_list($width, $action, $idItem = null) { continue; } } - $idAgent = db_get_value_filter('id_agente', 'tagente_modulo', array('id_agente_modulo' => $item['id_agent_module'])); + $idAgent = db_get_value_filter( + 'id_agente', 'tagente_modulo', + array('id_agente_modulo' => $item['id_agent_module'])); + $nameAgent = agents_get_name ($idAgent); $nameModule = db_get_value_filter('nombre', 'tagente_modulo', array('id_agente_modulo' => $item['id_agent_module'])); $server_name_element = ''; if ($meta && $server_name != '') - $server_name_element .= ' (' . $server_name . ')'; + $server_name_element .= ' (' . $server_name . ')'; - echo ' + + if ($type == "availability") { + echo ' - '; + } + else { + echo ' + + + + + '; + } + + if ($meta) { //Restore db connection metaconsole_restore_db(); @@ -1400,7 +1478,13 @@ function print_General_list($width, $action, $idItem = null) { - + + + @@ -1427,8 +1511,25 @@ function print_General_list($width, $action, $idItem = null) { ui_print_agent_autocomplete_input($params); ?> - - + + + + @@ -1460,7 +1561,8 @@ $(document).ready (function () { minuteText: '', secondText: '', currentText: '', - closeText: ''}); + closeText: '' + }); }); function create_custom_graph() { @@ -1699,13 +1801,13 @@ function addSLARow() { var slaMin = $("input[name=sla_min]").val(); var slaMax = $("input[name=sla_max]").val(); var slaLimit = $("input[name=sla_limit]").val(); - + var serviceId = $("select#id_service>option:selected").val(); var serviceName = $("select#id_service>option:selected").text(); if (((idAgent != '') && (slaMin != '') && (slaMax != '') && (slaLimit != '')) || serviceId != '') { - + if (nameAgent != '') { //Truncate nameAgent var params = []; @@ -1722,7 +1824,7 @@ function addSLARow() { nameAgent = data; } }); - + //Truncate nameModule var params = []; params.push("truncate_text=1"); @@ -1748,7 +1850,7 @@ function addSLARow() { params.push("sla_max=" + slaMax); params.push("sla_limit=" + slaLimit); params.push("server_id=" + serverId); - + if (serviceId != '') { params.push("id_service=" + serviceId); } @@ -1800,7 +1902,13 @@ function addGeneralRow() { var idAgent = $("input[name=id_agent_general]").val(); var serverId = $("input[name=id_server]").val(); var idModule = $("#id_agent_module_general").val(); - var operation = $("#id_operation_module_general").val(); + var operation; + if ($("#id_operation_module_general").length) { + operation = $("#id_operation_module_general").val(); + } + else { + operation = ""; + } var nameModule = $("#id_agent_module_general :selected").text(); var nameOperation = $("#id_operation_module_general :selected").text(); @@ -1835,6 +1943,7 @@ function addGeneralRow() { nameModule = data; } }); + //Truncate nameOperation var params = []; params.push("truncate_text=1"); @@ -1850,6 +1959,7 @@ function addGeneralRow() { nameOperation = data; } }); + var params = []; params.push("add_general=1"); params.push("id=" + $("input[name=id_item]").val()); @@ -1919,9 +2029,11 @@ function chooseType() { $("#general_list").hide(); $("#row_order_uptodown").hide(); $("#row_show_resume").hide(); + $("#row_show_address_agent").hide(); $("#row_show_graph").hide(); $("#row_max_min_avg").hide(); $("#row_only_avg").hide(); + $("#row_time_compare_overlapped").hide(); $("#row_quantity").hide(); $("#row_exception_condition_value").hide(); $("#row_exception_condition").hide(); @@ -1965,6 +2077,7 @@ function chooseType() { $("#row_event_graphs").show(); break; case 'simple_graph': + $("#row_time_compare_overlapped").show(); $("#row_only_avg").show(); // The break hasn't be forgotten, this element // only should be shown on the simple graphs. @@ -1975,6 +2088,7 @@ function chooseType() { $("#row_period").show(); $("#row_show_in_two_columns").show(); $("#row_show_in_landscape").show(); + $("#row_time_compare_overlapped").show(); break; case 'projection_graph': $("#row_description").show(); @@ -2024,7 +2138,7 @@ function chooseType() { $("#row_only_display_wrong").show(); $("#row_working_time").show(); $("#row_sort").show(); - + $(".sla_list_agent_col").hide(); $(".sla_list_module_col").hide(); $(".sla_list_service_col").show(); @@ -2178,7 +2292,7 @@ function chooseType() { $("#row_event_filter").show(); $("#row_event_graphs").show(); $("#row_event_graph_by_agent").hide(); - + $('#agent_autocomplete').hide(); $('#agent_autocomplete_events').show(); break; @@ -2207,6 +2321,14 @@ function chooseType() { $("input[name='last_value']").prop("checked", true); } break; + case 'availability': + $("#row_description").show(); + $("#row_period").show(); + $("#general_list").show(); + $("#row_order_uptodown").show(); + $("#row_show_address_agent").show(); + $("#row_show_in_two_columns").show(); + break; case 'group_report': $("#row_group").show(); $("#row_servers").show(); diff --git a/pandora_console/godmode/reporting/reporting_builder.php b/pandora_console/godmode/reporting/reporting_builder.php index c1e06300d2..2850deb5db 100644 --- a/pandora_console/godmode/reporting/reporting_builder.php +++ b/pandora_console/godmode/reporting/reporting_builder.php @@ -97,11 +97,11 @@ if ($idReport != 0) { $edit = true; break; } - + if (! $edit) { // The user that created the report should can delete it. Despite its permissions. $delete_report_bypass = false; - + if ($action == 'delete_report') { if ($config['id_user'] == $report['id_user'] || is_user_admin ($config["id_user"])) { $delete_report_bypass = true; @@ -342,14 +342,14 @@ switch ($action) { } break; } - + if (! $delete) { db_pandora_audit("ACL Violation", "Trying to access report builder deletion"); require ("general/noaccess.php"); exit; } - + $result = reports_delete_report ($idReport); if ($result !== false) db_pandora_audit("Report management", "Delete report #$idReport"); @@ -399,7 +399,7 @@ switch ($action) { html_print_table($table_aux); echo ""; } - + ui_require_jquery_file ('pandora.controls'); ui_require_jquery_file ('ajaxqueue'); @@ -450,8 +450,14 @@ switch ($action) { $filter['metaconsole'] = 0; $reports = reports_get_reports ($filter, - array ('name', 'id_report', 'description', 'private', - 'id_user', 'id_group', 'non_interactive'), $return_all_group, 'RR', $group, $strict_user); + array ( + 'name', + 'id_report', + 'description', + 'private', + 'id_user', + 'id_group', + 'non_interactive'), $return_all_group, 'RR', $group, $strict_user); $table->width = '0px'; if (sizeof ($reports)) { @@ -541,7 +547,8 @@ switch ($action) { if (enterprise_hook ('load_custom_reporting_2') !== ENTERPRISE_NOT_HOOK) { $next = 7; } - + + //Admin options only for RM flag if (check_acl ($config['id_user'], 0, "RM")) { @@ -673,7 +680,7 @@ switch ($action) { } break; case 'update': - case 'save': + case 'save': switch ($activeTab) { case 'main': $reportName = get_parameter('name'); @@ -753,12 +760,13 @@ switch ($action) { $first_page = $config['custom_report_front_firstpage']; $footer = $config['custom_report_front_footer']; - } else { - + } + else { + $start_url = ui_get_full_url(false, false, false, false); $first_page = "<p style="text-align: center;">&nbsp;</p> <p style="text-align: center;">&nbsp;</p> <p style="text-align: center;">&nbsp;</p> <p style="text-align: center;">&nbsp;</p> <p style="text-align: center;">&nbsp;</p> <p style="text-align: center;">&nbsp;</p> <p style="text-align: center;">&nbsp;</p> <p style="text-align: center;"><img src="" . $start_url . "/images/pandora_report_logo.png" alt="" width="800" /></p> <p style="text-align: center;">&nbsp;</p> <p style="text-align: center;"><span style="font-size: xx-large;">(_REPORT_NAME_)</span></p> <p style="text-align: center;"><span style="font-size: large;">(_DATETIME_)</span></p>"; $logo = $header = $footer = null; - + } $idOrResult = db_process_sql_insert('treport', @@ -798,7 +806,8 @@ switch ($action) { break; case 'item_editor': $resultOperationDB = null; - $report = db_get_row_filter('treport', array('id_report' => $idReport)); + $report = db_get_row_filter('treport', + array('id_report' => $idReport)); $reportName = $report['name']; $idGroupReport = $report['id_group']; @@ -871,11 +880,27 @@ switch ($action) { $values['top_n_value'] = get_parameter('max_values'); $good_format = true; break; + case 'availability': + // HACK it is saved in show_graph field. + // Show interfaces instead the modules + $values['show_graph'] = + get_parameter('checkbox_show_address_agent'); + $good_format = true; + break; + case 'simple_graph': + case 'simple_baseline_graph': + // HACK it is saved in show_graph field. + $values['show_graph'] = + (int)get_parameter('time_compare_overlapped'); + $values['period'] = get_parameter('period'); + $good_format = true; + break; default: $values['period'] = get_parameter('period'); $values['top_n'] = get_parameter('radiobutton_max_min_avg',0); $values['top_n_value'] = get_parameter('quantity'); $values['text'] = get_parameter('text'); + $values['show_graph'] = get_parameter('combo_graph_options'); $good_format = true; } @@ -907,7 +932,6 @@ switch ($action) { $values['order_uptodown'] = get_parameter ('radiobutton_order_uptodown'); $values['exception_condition'] = (int)get_parameter('exception_condition', 0); $values['exception_condition_value'] = get_parameter('exception_condition_value'); - $values['show_graph'] = get_parameter('combo_graph_options'); $values['id_module_group'] = get_parameter('combo_modulegroup'); $values['id_group'] = get_parameter ('combo_group'); $values['server_name'] = get_parameter ('server_name'); @@ -1087,11 +1111,27 @@ switch ($action) { $values['top_n_value'] = get_parameter('max_values'); $good_format = true; break; + case 'availability': + // HACK it is saved in show_graph field. + // Show interfaces instead the modules + $values['show_graph'] = + get_parameter('checkbox_show_address_agent'); + $good_format = true; + break; + case 'simple_graph': + case 'simple_baseline_graph': + // HACK it is saved in show_graph field. + $values['show_graph'] = + (int)get_parameter('time_compare_overlapped'); + $values['period'] = get_parameter('period'); + $good_format = true; + break; default: $values['period'] = get_parameter('period'); $values['top_n'] = get_parameter('radiobutton_max_min_avg',0); $values['top_n_value'] = get_parameter('quantity'); $values['text'] = get_parameter('text'); + $values['show_graph'] = get_parameter('combo_graph_options'); $good_format = true; } @@ -1139,7 +1179,6 @@ switch ($action) { $values['order_uptodown'] = get_parameter ('radiobutton_order_uptodown',0); $values['exception_condition'] = (int)get_parameter('radiobutton_exception_condition', 0); $values['exception_condition_value'] = get_parameter('exception_condition_value'); - $values['show_graph'] = get_parameter('combo_graph_options'); $values['id_module_group'] = get_parameter('combo_modulegroup'); $values['id_group'] = get_parameter ('combo_group'); $values['server_name'] = get_parameter ('server_name'); @@ -1577,7 +1616,7 @@ switch ($action) { switch ($activeTab) { case 'main': $buttons['list_reports']['active'] = true; - $subsection = ' » '.__('Custom reporting'); + $subsection = ' » ' . __('Custom reporting'); break; default: $subsection = reporting_enterprise_add_subsection_main($activeTab, $buttons); diff --git a/pandora_console/include/functions_modules.php b/pandora_console/include/functions_modules.php index a867dff6f6..9b52588a0b 100755 --- a/pandora_console/include/functions_modules.php +++ b/pandora_console/include/functions_modules.php @@ -2031,7 +2031,7 @@ function modules_relation_exists ($id_module, $id_module_other = false) { */ function modules_add_relation ($id_module_a, $id_module_b) { $result = false; - + if (!modules_relation_exists($id_module_a, $id_module_b) && $id_module_a > 0 && $id_module_b > 0) { $values = array( 'module_a' => $id_module_a, @@ -2039,7 +2039,7 @@ function modules_add_relation ($id_module_a, $id_module_b) { ); $result = db_process_sql_insert('tmodule_relationship', $values); } - + return $result; } @@ -2052,7 +2052,7 @@ function modules_add_relation ($id_module_a, $id_module_b) { */ function modules_delete_relation ($id_relation) { $result = db_process_sql_delete('tmodule_relationship', array('id' => $id_relation)); - + return $result; } @@ -2067,11 +2067,125 @@ function modules_change_relation_lock ($id_relation) { $old_value = (int) db_get_value('disable_update', 'tmodule_relationship', 'id', $id_relation); $new_value = $old_value === 1 ? 0 : 1; - $result = db_process_sql_update('tmodule_relationship', - array('disable_update' => $new_value), - array('id' => $id_relation)); - + $result = db_process_sql_update( + 'tmodule_relationship', + array('disable_update' => $new_value), + array('id' => $id_relation)); + return ($result !== false ? $new_value : $old_value); } + + +function modules_get_count_datas($id_agent_module, $date_init, $date_end) { + $interval = modules_get_interval ($id_agent_module); + + // TODO REMOVE THE TIME IN PLANNED DOWNTIME + + if (!is_numeric($date_init)) { + $date_init = strtotime($date_init); + } + + if (!is_numeric($date_end)) { + $date_end = strtotime($date_end); + } + + $first_date = modules_get_first_contact_date($id_agent_module); + + if ($date_init < $first_date) { + $date_init = $first_date; + } + + $diff = $date_end - $date_init; + + return ($diff / $interval); +} + +function modules_get_data_with_value($id_agent_module, $date_init, + $date_end, $value, $split_interval = false) { + + global $config; + + // TODO REMOVE THE TIME IN PLANNED DOWNTIME + + // TODO FOR OTHER KIND OF DATA + + if (!is_numeric($date_init)) { + $date_init = strtotime($date_init); + } + + if (!is_numeric($date_end)) { + $date_end = strtotime($date_end); + } + + $sql = " + SELECT * + FROM tagente_datos + WHERE + datos = " . (int)$value . " + AND id_agente_modulo = " . (int)$id_agent_module . " + AND (utimestamp >= " . $date_init . " AND utimestamp <= " . $date_end . ")"; + + $data = db_get_all_rows_sql($sql, + $config['history_db_enabled']); + + if (empty($data)) { + $data = array(); + } + + if ($split_interval) { + $temp = array(); + $previous_utimestamp = false; + foreach ($data as $row) { + if ($previous_utimestamp === false) { + $previous_utimestamp = $row['utimestamp']; + + $temp[] = $row; + } + else { + $diff = $row['utimestamp'] - $previous_utimestamp; + + $interval = modules_get_interval($id_agent_module); + + if ($diff > $interval) { + $fake_count = (int)($diff / $interval); + + $fake = $row; + for ($iterator = 1; $iterator <= $fake_count; $iterator++) { + $fake['utimestamp'] = $previous_utimestamp + ($iterator * $interval); + $temp[] = $fake; + } + } + else { + $temp[] = $row; + } + + $previous_utimestamp = $row['utimestamp']; + + $data = $temp; + } + } + } + + return $data; +} + +function modules_get_first_contact_date($id_agent_module) { + global $config; + + // TODO REMOVE THE TIME IN PLANNED DOWNTIME + + // TODO FOR OTHER KIND OF DATA + + $sql = " + SELECT utimestamp + FROM tagente_datos + WHERE id_agente_modulo = " . (int)($id_agent_module) . " + ORDER BY utimestamp ASC + LIMIT 1"; + + $first_date = db_get_sql($sql, 0, $config['history_db_enabled']); + + return $first_date; +} ?> diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index db326bada3..f0047e953d 100644 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -155,6 +155,12 @@ function reporting_make_reporting_data($id_report, $date, $time, $report, $content); break; + case 'availability': + $report['contents'][] = + reporting_availability( + $report, + $content); + break; case 'sql': $report['contents'][] = reporting_sql( $report, @@ -608,6 +614,232 @@ function reporting_sql($report, $content) { return reporting_check_structure_content($return); } +function reporting_availability($report, $content) { + + global $config; + + $return = array(); + $return['type'] = 'availability'; + $return['subtype'] = $content['group_by_agent']; + $return['resume'] = $content['show_resume']; + + if (empty($content['name'])) { + $content['name'] = __('Availability'); + } + + $return['title'] = $content['name']; + $return["description"] = $content["description"]; + $return["date"] = reporting_get_date_text( + $report, + $content); + + if ($content['show_graph']) { + $return['kind_availability'] = "address"; + } + else { + $return['kind_availability'] = "module"; + } + + + $sql = sprintf(" + SELECT id_agent_module, + server_name, operation + FROM treport_content_item + WHERE id_report_content = %d", + $content['id_rc']); + + $items = db_process_sql ($sql); + + + $data = array(); + + $avg = 0; + $min = null; + $min_text = ""; + $max = null; + $max_text = ""; + $count = 0; + foreach ($items as $item) { + //aaMetaconsole connection + $server_name = $item ['server_name']; + if (($config ['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE')) { + $connection = metaconsole_get_connection($server_name); + if (metaconsole_load_external_db($connection) != NOERR) { + //ui_print_error_message ("Error connecting to ".$server_name); + continue; + } + } + + if (modules_is_disable_agent($item['id_agent_module'])) { + continue; + } + + $row = array(); + + $text = ""; + + // HACK it is saved in show_graph field. + // Show interfaces instead the modules + if ($content['show_graph']) { + $text = $row['availability_item'] = agents_get_address( + modules_get_agentmodule_agent($item['id_agent_module'])); + + if (empty($text)) { + $text = $row['availability_item'] = __('No Address'); + } + } + else { + $text = $row['availability_item'] = modules_get_agentmodule_name( + $item['id_agent_module']); + } + $row['agent'] = modules_get_agentmodule_agent_name( + $item['id_agent_module']); + + $text = $row['agent'] . " (" . $text . ")"; + + $count_checks = modules_get_count_datas( + $item['id_agent_module'], + $report["datetime"] - $content['period'], + $report["datetime"]); + + + if (empty($count_checks)) { + $row['checks'] = __('Unknown'); + $row['failed'] = __('Unknown'); + $row['fail'] = __('Unknown'); + $row['poling_time'] = __('Unknown'); + $row['time_unavaliable'] = __('Unknown'); + $row['ok'] = __('Unknown'); + + $percent_ok = 0; + } + else { + $count_fails = count( + modules_get_data_with_value( + $item['id_agent_module'], + $report["datetime"] - $content['period'], + $report["datetime"], + 0, true)); + $percent_ok = (($count_checks - $count_fails) * 100) / $count_checks; + $percent_fail = 100 - $percent_ok; + + $row['ok'] = format_numeric($percent_ok, 2) . " %"; + $row['fail'] = format_numeric($percent_fail, 2) . " %"; + $row['checks'] = format_numeric($count_checks, 2); + $row['failed'] = format_numeric($count_fails ,2); + $row['poling_time'] = human_time_description_raw( + ($count_checks - $count_fails) * modules_get_interval($item['id_agent_module']), + true); + $row['time_unavaliable'] = "-"; + if ($count_fails > 0) { + $row['time_unavaliable'] = human_time_description_raw( + $count_fails * modules_get_interval($item['id_agent_module']), + true); + } + } + + $data[] = $row; + + + $avg = (($avg * $count) + $percent_ok) / ($count + 1); + if (is_null($min)) { + $min = $percent_ok; + $min_text = $text; + } + else { + if ($min > $percent_ok) { + $min = $percent_ok; + $min_text = $text; + } + } + if (is_null($max)) { + $max = $percent_ok; + $max_text = $text; + } + else { + if ($max < $percent_ok) { + $max = $percent_ok; + $max_text = $text; + } + } + + //Restore dbconnection + if (($config ['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE')) { + metaconsole_restore_db(); + } + + $count++; + } + + + switch ($content['order_uptodown']) { + case REPORT_ITEM_ORDER_BY_AGENT_NAME: + $temp = array(); + foreach ($data as $row) { + $i = 0; + foreach ($temp as $t_row) { + if (strcmp($row['agent'], $t_row['agent']) < 0) { + break; + } + + $i++; + } + + array_splice($temp, $i, 0, array($row)); + } + + $data = $temp; + break; + case REPORT_ITEM_ORDER_BY_ASCENDING: + $temp = array(); + foreach ($data as $row) { + $i = 0; + foreach ($temp as $t_row) { + if (strcmp($row['availability_item'], $t_row['availability_item']) < 0) { + break; + } + + $i++; + } + + array_splice($temp, $i, 0, array($row)); + } + + $data = $temp; + break; + case REPORT_ITEM_ORDER_BY_DESCENDING: + $temp = array(); + foreach ($data as $row) { + $i = 0; + foreach ($temp as $t_row) { + + if (strcmp($row['availability_item'], $t_row['availability_item']) > 0) { + break; + } + + $i++; + } + + array_splice($temp, $i, 0, array($row)); + } + + $data = $temp; + break; + } + + + $return["data"] = $data; + $return["resume"] = array(); + $return["resume"]['min_text'] = $min_text; + $return["resume"]['min'] = $min; + $return["resume"]['avg'] = $avg; + $return["resume"]['max_text'] = $max_text; + $return["resume"]['max'] = $max; + + + return reporting_check_structure_content($return); +} + function reporting_general($report, $content) { global $config; @@ -992,6 +1224,12 @@ function reporting_simple_graph($report, $content, $type = 'dinamic', } else { + // HACK it is saved in show_graph field. + $time_compare_overlapped = false; + if ($content['show_graph']) { + $time_compare_overlapped = 'overlapped'; + } + $return['chart'] = grafico_modulo_sparse( $content['id_agent_module'], $content['period'], @@ -1013,7 +1251,7 @@ function reporting_simple_graph($report, $content, $type = 'dinamic', 1, false, '', - false, + $time_compare_overlapped, true); } break; diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index 207d7499a6..c45d7b99f4 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -125,6 +125,9 @@ function reporting_html_print_report($report, $mini = false) { } switch ($item['type']) { + case 'availability': + reporting_html_availability($table, $item); + break; case 'general': reporting_html_general($table, $item); break; @@ -343,6 +346,93 @@ function reporting_html_text(&$table, $item) { $table->data['data']['cell'] = $item['data']; } +function reporting_html_availability(&$table, $item) { + + if (!empty($item["data"])) { + $table1->width = '99%'; + $table1->data = array (); + $table1->head = array (); + $table1->head[0] = __('Agent'); + // HACK it is saved in show_graph field. + // Show interfaces instead the modules + if ($item['kind_availability'] == 'address') { + $table1->head[1] = __('IP Address'); + } + else { + $table1->head[1] = __('Module'); + } + $table1->head[2] = __('# Checks'); + $table1->head[3] = __('# Failed'); + $table1->head[4] = __('% Fail'); + $table1->head[5] = __('Poling time'); + $table1->head[6] = __('Time unavailable'); + $table1->head[7] = __('% Ok'); + + $table1->style[0] = 'text-align: left'; + $table1->style[1] = 'text-align: left'; + $table1->style[2] = 'text-align: right'; + $table1->style[3] = 'text-align: right'; + $table1->style[4] = 'text-align: right'; + $table1->style[5] = 'text-align: right'; + $table1->style[6] = 'text-align: right'; + $table1->style[7] = 'text-align: right'; + + foreach ($item['data'] as $row) { + $table_row = array(); + $table_row[] = $row['agent']; + $table_row[] = $row['availability_item']; + $table_row[] = $row['checks']; + $table_row[] = $row['failed']; + $table_row[] = $row['fail']; + $table_row[] = $row['poling_time']; + $table_row[] = $row['time_unavaliable']; + $table_row[] = $row['ok']; + + $table1->data[] = $table_row; + } + } + else { + $table->colspan['error']['cell'] = 3; + $table->data['error']['cell'] = + __('There are no Agent/Modules defined'); + } + + $table->colspan[1][0] = 3; + $data = array(); + $data[0] = html_print_table($table1, true); + array_push ($table->data, $data); + + if ($item['resume'] && !empty($item["data"])) { + $table1->width = '99%'; + $table1->data = array (); + $table1->head = array (); + $table1->style = array(); + $table1->head['min_text'] = ''; + $table1->head['min'] = __('Min Value'); + $table1->head['avg'] = __('Average Value'); + $table1->head['max_text'] = ''; + $table1->head['max'] = __('Max Value'); + $table1->style['min_text'] = 'text-align: left'; + $table1->style['min'] = 'text-align: right'; + $table1->style['avg'] = 'text-align: right'; + $table1->style['max_text'] = 'text-align: left'; + $table1->style['max'] = 'text-align: right'; + + $table1->data[] = array( + 'min_text' => $item['resume']['min_text'], + 'min' => format_numeric($item['resume']['min'], 2) . "%", + 'avg' => format_numeric($item['resume']['avg'], 2) . "%", + 'max_text' => $item['resume']['max_text'], + 'max' => format_numeric($item['resume']['max'], 2) . "%" + ); + + $table->colspan[2][0] = 3; + $data = array(); + $data[0] = html_print_table($table1, true); + array_push ($table->data, $data); + } +} + function reporting_html_general(&$table, $item) { if (!empty($item["data"])) { diff --git a/pandora_console/include/functions_reports.php b/pandora_console/include/functions_reports.php index 083d60f195..4b366b92e7 100644 --- a/pandora_console/include/functions_reports.php +++ b/pandora_console/include/functions_reports.php @@ -578,7 +578,8 @@ function reports_get_report_types ($template = false, $not_editor = false) { 'name' => __('Top n')); $types['network_interfaces_report'] = array('optgroup' => __('Grouped'), 'name' => __('Network interfaces')); - + $types['availability'] = array('optgroup' => __('Grouped'), + 'name' => __('Availability')); $types['text'] = array('optgroup' => __('Text/HTML '), diff --git a/pandora_console/operation/reporting/reporting_viewer.php b/pandora_console/operation/reporting/reporting_viewer.php index 4d333eb3f3..448300a64b 100644 --- a/pandora_console/operation/reporting/reporting_viewer.php +++ b/pandora_console/operation/reporting/reporting_viewer.php @@ -231,7 +231,7 @@ else { } -echo ''; +echo ''; html_print_table ($table); html_print_input_hidden ('id_report', $id_report); echo ''; From b3ef77931977ac085cd67175ba5e8f0eddbcf68d Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Mon, 13 Apr 2015 16:37:10 +0200 Subject: [PATCH 27/80] Working in the refactoring the code of reports (projection_graph). --- .../include/functions_reporting.php | 76 +++++++++++++++++++ .../include/functions_reporting_html.php | 66 +++------------- 2 files changed, 85 insertions(+), 57 deletions(-) diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index f0047e953d..b0c6667d2f 100644 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -240,12 +240,88 @@ function reporting_make_reporting_data($id_report, $date, $time, $report, $content); break; + case 'projection_graph': + $report['contents'][] = reporting_projection_graph( + $report, + $content, + $type, + $force_width_chart, + $force_height_chart); + break; } } return reporting_check_structure_report($report); } +function reporting_projection_graph($report, $content, + $type = 'dinamic', $force_width_chart = null, + $force_height_chart = null) { + + global $config; + + $return['type'] = 'projection_graph'; + + if (empty($content['name'])) { + $content['name'] = __('Agent configuration'); + } + + $return['title'] = $content['name']; + $return["description"] = $content["description"]; + $return["date"] = reporting_get_date_text($report, $content); + + set_time_limit(500); + + $output_projection = forecast_projection_graph( + $content['id_agent_module'], $content['period'], $content['top_n_value']); + + // If projection doesn't have data then don't draw graph + if ($output_projection == NULL) { + $output_projection = false; + } + + // Get chart + reporting_set_conf_charts($width, $height, $only_image, $type, $content); + + if (!empty($force_width_chart)) { + $width = $force_width_chart; + } + + if (!empty($force_height_chart)) { + $height = $force_height_chart; + } + + switch ($type) { + case 'dinamic': + case 'static': + $return['chart'] = graphic_combined_module( + array($content['id_agent_module']), + array(), + $content['period'], + $width, + $height, + 'Projection%20Sample%20Graph', + '', + 0, + 0, + 0, + 0, + $report["datetime"], + true, + ui_get_full_url(false, false, false, false) . '/', + 1, + // Important parameter, this tell to graphic_combined_module function that is a projection graph + $output_projection, + $content['top_n_value'] + ); + break; + case 'data': + break; + } + + return reporting_check_structure_content($return); +} + function reporting_agent_configuration($report, $content) { global $config; diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index c45d7b99f4..cb238ba715 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -173,6 +173,9 @@ function reporting_html_print_report($report, $mini = false) { case 'agent_configuration': reporting_html_agent_configuration($table, $item); break; + case 'projection_graph': + reporting_html_projection_graph($table, $item); + break; } if ($item['type'] == 'agent_module') @@ -185,6 +188,12 @@ function reporting_html_print_report($report, $mini = false) { } } +function reporting_html_projection_graph(&$table, $item) { + $table->colspan['chart']['cell'] = 3; + $table->cellstyle['chart']['cell'] = 'text-align: center;'; + $table->data['chart']['cell'] = $item['chart']; +} + function reporting_html_agent_configuration(&$table, $item) { $table->colspan['agent']['cell'] = 3; $table->cellstyle['agent']['cell'] = 'text-align: left;'; @@ -3354,63 +3363,6 @@ function reporting_render_report_html_item ($content, $table, $report, $mini = f $item_title = $content['name']; switch ($content["type"]) { - case 'projection_graph': - if (empty($item_title)) { - $item_title = __('Projection graph'); - } - reporting_header_content($mini, $content, $report, $table, $item_title, - ui_print_truncate_text($agent_name, 'agent_medium', false).'
' . - ui_print_truncate_text($module_name, 'module_medium', false)); - - //RUNNING - $table->colspan[1][0] = 4; - - set_time_limit(500); - - $next_row = 1; - // Put description at the end of the module (if exists) - if ($content["description"] != "") { - $data_desc = array(); - $data_desc[0] = $content["description"]; - array_push ($table->data, $data_desc); - $table->colspan[$next_row][0] = 3; - $next_row++; - } - - $table->colspan[$next_row][0] = 3; - $table->cellstyle[$next_row][0] = 'text-align: center;'; - $data = array (); - - $output_projection = forecast_projection_graph($content['id_agent_module'], $content['period'], $content['top_n_value']); - - // If projection doesn't have data then don't draw graph - if ($output_projection == NULL) { - $output_projection = false; - } - - $modules = array($content['id_agent_module']); - $weights = array(); - $data[0] = graphic_combined_module( - $modules, - $weights, - $content['period'], - $sizgraph_w, $sizgraph_h, - 'Projection%20Sample%20Graph', - '', - 0, - 0, - 0, - 0, - $report["datetime"], - true, - ui_get_full_url(false, false, false, false) . '/', - 1, - // Important parameter, this tell to graphic_combined_module function that is a projection graph - $output_projection, - $content['top_n_value'] - ); - array_push ($table->data, $data); - break; case 'prediction_date': if (empty($item_title)) { $item_title = __('Prediction date'); From e5332924b1195697bc304ab10ce184cb219d8160 Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Mon, 13 Apr 2015 18:15:02 +0200 Subject: [PATCH 28/80] Working in the refactoring the code of reports (prediction_date). --- .../include/functions_reporting.php | 38 +++++++++++++++- .../include/functions_reporting_html.php | 44 +++---------------- 2 files changed, 44 insertions(+), 38 deletions(-) diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index b0c6667d2f..35af131c09 100644 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -248,12 +248,48 @@ function reporting_make_reporting_data($id_report, $date, $time, $force_width_chart, $force_height_chart); break; + case 'prediction_date': + $report['contents'][] = reporting_prediction_date( + $report, + $content); + break; } } return reporting_check_structure_report($report); } +function reporting_prediction_date($report, $content) { + + global $config; + + $return['type'] = 'prediction_date'; + + if (empty($content['name'])) { + $content['name'] = __('Prediction Date'); + } + + $return['title'] = $content['name']; + $return["description"] = $content["description"]; + $return["date"] = reporting_get_date_text($report, $content); + + set_time_limit(500); + + $intervals_text = $content['text']; + $max_interval = substr($intervals_text, 0, strpos($intervals_text, ';')); + $min_interval = substr($intervals_text, strpos($intervals_text, ';') + 1); + $value = forecast_prediction_date ($content['id_agent_module'], $content['period'], $max_interval, $min_interval); + + if ($value === false) { + $return["data"]['value'] = __('Unknown'); + } + else { + $return["data"]['value'] = date ('d M Y H:i:s', $value); + } + + return reporting_check_structure_content($return); +} + function reporting_projection_graph($report, $content, $type = 'dinamic', $force_width_chart = null, $force_height_chart = null) { @@ -263,7 +299,7 @@ function reporting_projection_graph($report, $content, $return['type'] = 'projection_graph'; if (empty($content['name'])) { - $content['name'] = __('Agent configuration'); + $content['name'] = __('Projection Graph'); } $return['title'] = $content['name']; diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index cb238ba715..102ee38e33 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -176,6 +176,9 @@ function reporting_html_print_report($report, $mini = false) { case 'projection_graph': reporting_html_projection_graph($table, $item); break; + case 'prediction_date': + reporting_html_prediction_date($table, $item, $mini); + break; } if ($item['type'] == 'agent_module') @@ -188,6 +191,10 @@ function reporting_html_print_report($report, $mini = false) { } } +function reporting_html_prediction_date($table, $item, $mini) { + reporting_html_value($table, $item, $mini, true); +} + function reporting_html_projection_graph(&$table, $item) { $table->colspan['chart']['cell'] = 3; $table->cellstyle['chart']['cell'] = 'text-align: center;'; @@ -3363,43 +3370,6 @@ function reporting_render_report_html_item ($content, $table, $report, $mini = f $item_title = $content['name']; switch ($content["type"]) { - case 'prediction_date': - if (empty($item_title)) { - $item_title = __('Prediction date'); - } - reporting_header_content($mini, $content, $report, $table, $item_title, - ui_print_truncate_text($agent_name, 'agent_medium', false).'
' . - ui_print_truncate_text($module_name, 'module_medium', false)); - - //RUNNING - $table->colspan[1][0] = 4; - - set_time_limit(500); - - // Put description at the end of the module (if exists) - $table->colspan[2][0] = 4; - if ($content["description"] != ""){ - $data_desc = array(); - $data_desc[0] = $content["description"]; - array_push ($table->data, $data_desc); - } - - $data = array (); - $table->colspan[2][0] = 3; - $intervals_text = $content['text']; - $max_interval = substr($intervals_text, 0, strpos($intervals_text, ';')); - $min_interval = substr($intervals_text, strpos($intervals_text, ';') + 1); - $value = forecast_prediction_date ($content['id_agent_module'], $content['period'], $max_interval, $min_interval); - - if ($value === false) { - $value = __('Unknown'); - } - else { - $value = date ('d M Y H:i:s', $value); - } - $data[0] = '

'.$value.'

'; - array_push ($table->data, $data); - break; case 'simple_baseline_graph': if (empty($item_title)) { $item_title = __('Simple baseline graph'); From ab09716cd424d298290a478f7cf25c1a9a0c2bd4 Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Mon, 13 Apr 2015 18:42:35 +0200 Subject: [PATCH 29/80] Working in the refactoring the code of reports (simple_baseline_graph). --- .../include/functions_reporting.php | 64 +++++++++++++++++++ .../include/functions_reporting_html.php | 50 +++------------ 2 files changed, 73 insertions(+), 41 deletions(-) diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index 35af131c09..311c120bfc 100644 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -253,12 +253,76 @@ function reporting_make_reporting_data($id_report, $date, $time, $report, $content); break; + case 'simple_baseline_graph': + $report['contents'][] = reporting_simple_baseline_graph( + $report, + $content, + $type, + $force_width_chart, + $force_height_chart); + break; } } return reporting_check_structure_report($report); } +function reporting_simple_baseline_graph($report, $content, + $type = 'dinamic', $force_width_chart = null, + $force_height_chart = null) { + + global $config; + + $return['type'] = 'simple_baseline_graph'; + + if (empty($content['name'])) { + $content['name'] = __('Simple baseline graph'); + } + + $return['title'] = $content['name']; + $return["description"] = $content["description"]; + $return["date"] = reporting_get_date_text($report, $content); + + // Get chart + reporting_set_conf_charts($width, $height, $only_image, $type, $content); + + if (!empty($force_width_chart)) { + $width = $force_width_chart; + } + + if (!empty($force_height_chart)) { + $height = $force_height_chart; + } + + switch ($type) { + case 'dinamic': + case 'static': + $return['chart'] = grafico_modulo_sparse( + $content['id_agent_module'], + $content['period'], + false, + $width, + $height, + '', + '', + false, + true, + true, + $report["datetime"], + '', + true, + 0, + true, + false, + ui_get_full_url(false, false, false, false)); + break; + case 'data': + break; + } + + return reporting_check_structure_content($return); +} + function reporting_prediction_date($report, $content) { global $config; diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index 102ee38e33..f3d652acc3 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -179,6 +179,9 @@ function reporting_html_print_report($report, $mini = false) { case 'prediction_date': reporting_html_prediction_date($table, $item, $mini); break; + case 'simple_baseline_graph': + reporting_html_simple_baseline_graph($table, $item); + break; } if ($item['type'] == 'agent_module') @@ -191,6 +194,12 @@ function reporting_html_print_report($report, $mini = false) { } } +function reporting_html_simple_baseline_graph($table, $item) { + $table->colspan['chart']['cell'] = 3; + $table->cellstyle['chart']['cell'] = 'text-align: center;'; + $table->data['chart']['cell'] = $item['chart']; +} + function reporting_html_prediction_date($table, $item, $mini) { reporting_html_value($table, $item, $mini, true); } @@ -3370,47 +3379,6 @@ function reporting_render_report_html_item ($content, $table, $report, $mini = f $item_title = $content['name']; switch ($content["type"]) { - case 'simple_baseline_graph': - if (empty($item_title)) { - $item_title = __('Simple baseline graph'); - } - reporting_header_content($mini, $content, $report, $table, $item_title, - ui_print_truncate_text($agent_name, 'agent_medium', false).'
' . - ui_print_truncate_text($module_name, 'module_medium', false)); - - //RUNNING - $table->colspan[1][0] = 4; - - // Put description at the end of the module (if exists) - $table->colspan[2][0] = 4; - if ($content["description"] != "") { - $data_desc = array(); - $data_desc[0] = $content["description"]; - array_push ($table->data, $data_desc); - } - - $data = array (); - $data[0] = grafico_modulo_sparse($content['id_agent_module'], $content['period'], - false, $sizgraph_w, $sizgraph_h, '', '', false, true, true, - $report["datetime"], '', true, 0, true, $only_image, - ui_get_full_url(false, false, false, false)); - - /*$data[0] = graphic_combined_module( - $modules, - $weights, - $content['period'], - $sizgraph_w, $sizgraph_h, - 'Combined%20Sample%20Graph', - '', - 0, - 0, - 0, - $graph["stacked"], - $report["datetime"]); */ - - array_push ($table->data, $data); - - break; case 'SLA_monthly': if (function_exists("reporting_enterprise_sla_monthly")) reporting_enterprise_sla_monthly($mini, $content, $report, $table, $item_title); From 6ee2ea02d4394c465b6ad9f946252d8b301535b5 Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Tue, 14 Apr 2015 12:58:26 +0200 Subject: [PATCH 30/80] Working in the refactoring the code of reports (netflow_area, netflow_pie, netflow_data, netflow_statistics, netflow_summary). --- .../include/functions_reporting.php | 123 ++++++++++++++++++ .../include/functions_reporting_html.php | 82 +++--------- 2 files changed, 144 insertions(+), 61 deletions(-) diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index 311c120bfc..46ff78b348 100644 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -261,12 +261,135 @@ function reporting_make_reporting_data($id_report, $date, $time, $force_width_chart, $force_height_chart); break; + case 'netflow_area': + $report['contents'][] = reporting_simple_baseline_graph( + $report, + $content, + $type, + $force_width_chart, + $force_height_chart); + break; + case 'netflow_pie': + $report['contents'][] = reporting_netflow_pie( + $report, + $content, + $type, + $force_width_chart, + $force_height_chart); + break; + case 'netflow_data': + $report['contents'][] = reporting_netflow_data( + $report, + $content, + $type, + $force_width_chart, + $force_height_chart); + break; + case 'netflow_statistics': + $report['contents'][] = reporting_netflow_statistics( + $report, + $content, + $type, + $force_width_chart, + $force_height_chart); + break; + case 'netflow_summary': + $report['contents'][] = reporting_netflow_summary( + $report, + $content, + $type, + $force_width_chart, + $force_height_chart); + break; } } return reporting_check_structure_report($report); } +function reporting_netflow($report, $content, $type, + $force_width_chart, $force_height_chart, $type_netflow = null) { + + global $config; + + switch ($type_netflow) { + case 'netflow_area': + $return['type'] = 'netflow_area'; + break; + case 'netflow_pie': + $return['type'] = 'netflow_pie'; + break; + case 'netflow_data': + $return['type'] = 'netflow_data'; + break; + case 'netflow_statistics': + $return['type'] = 'netflow_statistics'; + break; + case 'netflow_summary': + $return['type'] = 'netflow_summary'; + break; + } + + if (empty($content['name'])) { + switch ($type_netflow) { + case 'netflow_area': + $return['name'] = __('Netflow Area'); + break; + case 'netflow_pie': + $return['name'] = __('Netflow Pie'); + break; + case 'netflow_data': + $return['name'] = __('Netflow Data'); + break; + case 'netflow_statistics': + $return['name'] = __('Netflow Statistics'); + break; + case 'netflow_summary': + $return['name'] = __('Netflow Summary'); + break; + } + } + + $return['title'] = $content['name']; + $return["description"] = $content["description"]; + $return["date"] = reporting_get_date_text($report, $content); + + // Get chart + reporting_set_conf_charts($width, $height, $only_image, $type, $content); + + if (!empty($force_width_chart)) { + $width = $force_width_chart; + } + + if (!empty($force_height_chart)) { + $height = $force_height_chart; + } + + // Get item filters + $filter = db_get_row_sql("SELECT * + FROM tnetflow_filter + WHERE id_sg = '" . (int)$content['text'] . "'", false, true); + + switch ($type) { + case 'dinamic': + case 'static': + $return['chart'] = netflow_draw_item ( + $report['datetime'] - $content['period'], + $report['datetime'], + $content['top_n'], + $type_netflow, + $filter, + $content['top_n_value'], + $content ['server_name'], + 'HTML'); + break; + case 'data': + break; + } + + return reporting_check_structure_content($return); +} + function reporting_simple_baseline_graph($report, $content, $type = 'dinamic', $force_width_chart = null, $force_height_chart = null) { diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index f3d652acc3..779dc490b7 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -135,10 +135,10 @@ function reporting_html_print_report($report, $mini = false) { reporting_html_sql($table, $item); break; case 'simple_graph': - reporting_html_simple_graph($table, $item); + reporting_html_graph($table, $item); break; case 'custom_graph': - reporting_html_custom_graph($table, $item); + reporting_html_graph($table, $item); break; case 'text': reporting_html_text($table, $item); @@ -174,13 +174,28 @@ function reporting_html_print_report($report, $mini = false) { reporting_html_agent_configuration($table, $item); break; case 'projection_graph': - reporting_html_projection_graph($table, $item); + reporting_html_graph($table, $item); break; case 'prediction_date': reporting_html_prediction_date($table, $item, $mini); break; case 'simple_baseline_graph': - reporting_html_simple_baseline_graph($table, $item); + reporting_html_graph($table, $item); + break; + case 'netflow_area': + reporting_html_graph($table, $item); + break; + case 'netflow_pie': + reporting_html_graph($table, $item); + break; + case 'netflow_data': + reporting_html_graph($table, $item); + break; + case 'netflow_statistics': + reporting_html_graph($table, $item); + break; + case 'netflow_summary': + reporting_html_graph($table, $item); break; } @@ -194,7 +209,7 @@ function reporting_html_print_report($report, $mini = false) { } } -function reporting_html_simple_baseline_graph($table, $item) { +function reporting_html_graph($table, $item) { $table->colspan['chart']['cell'] = 3; $table->cellstyle['chart']['cell'] = 'text-align: center;'; $table->data['chart']['cell'] = $item['chart']; @@ -204,12 +219,6 @@ function reporting_html_prediction_date($table, $item, $mini) { reporting_html_value($table, $item, $mini, true); } -function reporting_html_projection_graph(&$table, $item) { - $table->colspan['chart']['cell'] = 3; - $table->cellstyle['chart']['cell'] = 'text-align: center;'; - $table->data['chart']['cell'] = $item['chart']; -} - function reporting_html_agent_configuration(&$table, $item) { $table->colspan['agent']['cell'] = 3; $table->cellstyle['agent']['cell'] = 'text-align: left;'; @@ -588,18 +597,6 @@ function reporting_html_sql(&$table, $item) { } } -function reporting_html_custom_graph(&$table, $item) { - $table->colspan['chart']['cell'] = 3; - $table->cellstyle['chart']['cell'] = 'text-align: center;'; - $table->data['chart']['cell'] = $item['chart']; -} - -function reporting_html_simple_graph(&$table, $item) { - $table->colspan['chart']['cell'] = 3; - $table->cellstyle['chart']['cell'] = 'text-align: center;'; - $table->data['chart']['cell'] = $item['chart']; -} - /** * Get the maximum value of an agent module in a period of time. @@ -5493,7 +5490,7 @@ function reporting_render_report_html_item ($content, $table, $report, $mini = f $table_data .= "
' . printSmallFont($nameAgent) . $server_name_element . '' . printSmallFont($nameModule) . '' . printSmallFont($nameService) . ''; } - + echo '' . $item['sla_min'] . '' . $item['sla_max'] . '' . $item['sla_limit'] . '
' . printSmallFont($nameAgent) . $server_name_element . ' ' . printSmallFont($nameModule) . '' . printSmallFont($operation[$item['operation']]) . ' ' . html_print_image("images/cross.png", true) . '
' . printSmallFont($nameAgent) . $server_name_element . '' . printSmallFont($nameModule) . '' . + printSmallFont($operation[$item['operation']]) . + ' + ' . html_print_image("images/cross.png", true) . ' +
+ + + +
"; $table_data .= "
"; - + $table_data .= ""; $table_data .= ""; $table_data .= ""; @@ -5739,43 +5736,6 @@ function reporting_render_report_html_item ($content, $table, $report, $mini = f } break; - case 'netflow_area': - case 'netflow_pie': - case 'netflow_data': - case 'netflow_statistics': - case 'netflow_summary': - - // Read the report item - $report_id = $report['id_report']; - $content_id = $content['id_rc']; - $max_aggregates= $content['top_n_value']; - $type = $content['show_graph']; - $description = $content['description']; - $resolution = $content['top_n']; - $type = $content['type']; - $period = $content['period']; - - // Calculate the start and end dates - $end_date = $report['datetime']; - $start_date = $end_date - $period; - - // Get item filters - $filter = db_get_row_sql("SELECT * - FROM tnetflow_filter - WHERE id_sg = '" . (int)$content['text'] . "'", false, true); - if ($description == '') { - $description = $filter['id_name']; - } - - if (empty($item_title)) { - $item_title = $description; - } - - $table->colspan[0][0] = 4; - $table->data[0][0] = '

' . $item_title . '

'; - $table->colspan[1][0] = 4; - $table->data[1][0] = netflow_draw_item ($start_date, $end_date, $resolution, $type, $filter, $max_aggregates, $server_name, 'HTML'); - break; } //Restore dbconnection if (($config ['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE') && $remote_connection == 1) { From c24d8f22e7e99650a1a03e44578f8af5e7d71522 Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Tue, 14 Apr 2015 16:21:44 +0200 Subject: [PATCH 31/80] Working in the refactoring the code of reports (monitor_report). --- .../include/functions_reporting.php | 42 ++++++++++ .../include/functions_reporting_html.php | 80 +++++++++---------- 2 files changed, 81 insertions(+), 41 deletions(-) diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index 46ff78b348..0ae6240968 100644 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -301,12 +301,54 @@ function reporting_make_reporting_data($id_report, $date, $time, $force_width_chart, $force_height_chart); break; + case 'monitor_report': + $report['contents'][] = reporting_monitor_report( + $report, + $content); + break; } } return reporting_check_structure_report($report); } +function reporting_monitor_report($report, $content) { + global $config; + + + $return['type'] = 'monitor_report'; + + if (empty($content['name'])) { + $content['name'] = __('Monitor Report'); + } + + $return['title'] = $content['name']; + $return["description"] = $content["description"]; + $return["date"] = reporting_get_date_text($report, $content); + + $value = reporting_get_agentmodule_sla( + $content['id_agent_module'], + $content['period'], + 1, + false, + $report["datetime"]); + + if ($value === __('Unknown')) { + $return['data']['unknown'] = 1; + } + else { + $return['data']['unknown'] = 0; + + $return["data"]["ok"]["value"] = $value; + $return["data"]["ok"]["formated_value"] = format_numeric($value, 2); + + $return["data"]["fail"]["value"] = 100 - $return["data"]["ok"]["value"]; + $return["data"]["fail"]["formated_value"] = (100 - $return["data"]["ok"]["formated_value"]); + } + + return reporting_check_structure_content($return); +} + function reporting_netflow($report, $content, $type, $force_width_chart, $force_height_chart, $type_netflow = null) { diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index 779dc490b7..368884d3c2 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -197,6 +197,9 @@ function reporting_html_print_report($report, $mini = false) { case 'netflow_summary': reporting_html_graph($table, $item); break; + case 'monitor_report': + reporting_html_monitor_report($table, $item, $mini); + break; } if ($item['type'] == 'agent_module') @@ -209,6 +212,42 @@ function reporting_html_print_report($report, $mini = false) { } } +function reporting_html_monitor_report($table, $item, $mini) { + if ($mini) { + $font_size = '1.5'; + } + else { + $font_size = '3'; + } + + $table->colspan['module']['cell'] = 3; + $table->cellstyle['module']['cell'] = 'text-align: center;'; + + $table1->width = '99%'; + $table1->head = array (); + $table1->data = array (); + if ($item['data']['unknown'] == 1) { + $table1->data['data']['unknown'] = + '

'; + $table1->data['data']['unknown'] .= __('Unknown') . "

"; + } + else { + $table1->data['data']['ok'] = + '

'; + $table1->data['data']['ok'] .= + html_print_image("images/module_ok.png", true) . ' ' . + __('OK') . ': ' . $item['data']["ok"]["formated_value"].' %

'; + + $table1->data['data']['fail'] = + '

'; + $table1->data['data']['fail'] .= + html_print_image("images/module_critical.png", true) . ' ' . + __('Not OK') . ': ' . $item['data']["fail"]["formated_value"] . ' % ' . '

'; + } + + $table->data['module']['cell'] = html_print_table($table1, true); +} + function reporting_html_graph($table, $item) { $table->colspan['chart']['cell'] = 3; $table->cellstyle['chart']['cell'] = 'text-align: center;'; @@ -3921,47 +3960,6 @@ function reporting_render_report_html_item ($content, $table, $report, $mini = f array_push ($table->data, $data); } break; - case 6: - case 'monitor_report': - if (empty($item_title)) { - $item_title = __('Monitor report'); - } - reporting_header_content($mini, $content, $report, $table, $item_title, - ui_print_truncate_text($agent_name, 'agent_medium', false) . - '
'.ui_print_truncate_text($module_name, 'module_medium', false)); - - //RUNNING - $next_row = 1; - - // Put description at the end of the module (if exists) - if ($content["description"] != "") { - $table->colspan[1][0] = 3; - $data_desc = array(); - $data_desc[0] = $content["description"]; - array_push ($table->data, $data_desc); - $next_row++; - } - - $data = array (); - $monitor_value = reporting_get_agentmodule_sla ($content['id_agent_module'], $content['period'], 1, false, $report["datetime"]); - if ($monitor_value === false) { - $monitor_value = __('Unknown'); - } - else { - $monitor_value = format_numeric ($monitor_value); - } - - $table->colspan[$next_row][0] = 2; - $data[0] = '

'; - $data[0] .= html_print_image("images/module_ok.png", true) . ' ' . __('OK') . ': ' . $monitor_value.' %

'; - if ($monitor_value !== __('Unknown')) { - $monitor_value = format_numeric (100 - $monitor_value, 2) ; - } - $data[1] = '

'; - $data[1] .= html_print_image("images/module_critical.png", true) . ' ' .__('Not OK') . ': ' .$monitor_value.' % ' . '

'; - array_push ($table->data, $data); - - break; case 'agent_detailed_event': case 'event_report_agent': From 2b665f8117db6b7f41a6d59abc8b5d41596d2a71 Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Tue, 14 Apr 2015 17:04:18 +0200 Subject: [PATCH 32/80] Working in the refactoring the code of reports (sql_graph_vbar, sql_graph_hbar, sql_graph_pie). --- .../include/functions_reporting.php | 91 +++++++++++++++++++ .../include/functions_reporting_html.php | 66 +++----------- 2 files changed, 106 insertions(+), 51 deletions(-) diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index 0ae6240968..ceda0c7c0a 100644 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -306,12 +306,103 @@ function reporting_make_reporting_data($id_report, $date, $time, $report, $content); break; + case 'sql_graph_vbar': + $report['contents'][] = reporting_sql_graph( + $report, + $content, + $type, + $force_width_chart, + $force_height_chart, + 'sql_graph_vbar'); + break; + case 'sql_graph_hbar': + $report['contents'][] = reporting_sql_graph( + $report, + $content, + $type, + $force_width_chart, + $force_height_chart, + 'sql_graph_hbar'); + break; + case 'sql_graph_pie': + $report['contents'][] = reporting_sql_graph( + $report, + $content, + $type, + $force_width_chart, + $force_height_chart, + 'sql_graph_pie'); + break; } } return reporting_check_structure_report($report); } +function reporting_sql_graph($report, $content, $type, + $force_width_chart, $force_height_chart, $type_sql_graph) { + + global $config; + + switch ($type_sql_graph) { + case 'netflow_area': + $return['type'] = 'sql_graph_vbar'; + break; + case 'sql_graph_hbar': + $return['type'] = 'sql_graph_hbar'; + break; + case 'sql_graph_pie': + $return['type'] = 'sql_graph_pie'; + break; + } + + if (empty($content['name'])) { + switch ($type_sql_graph) { + case 'sql_graph_vbar': + $return['name'] = __('SQL Graph Vertical Bars'); + break; + case 'sql_graph_hbar': + $return['name'] = __('SQL Graph Horizontal Bars'); + break; + case 'sql_graph_pie': + $return['name'] = __('SQL Graph Pie'); + break; + } + } + + // Get chart + reporting_set_conf_charts($width, $height, $only_image, $type, $content); + + if (!empty($force_width_chart)) { + $width = $force_width_chart; + } + + if (!empty($force_height_chart)) { + $height = $force_height_chart; + } + + $return['title'] = $content['name']; + $return["description"] = $content["description"]; + $return["date"] = reporting_get_date_text(); + + switch ($type) { + case 'dinamic': + case 'static': + $return['chart'] = graph_custom_sql_graph( + $content["id_rc"], + $width, + $height, + $content["type"], + true, + ui_get_full_url(false, false, false, false)); + break; + case 'data': + break; + } + + return reporting_check_structure_content($return); +} + function reporting_monitor_report($report, $content) { global $config; diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index 368884d3c2..1afe06c768 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -200,6 +200,15 @@ function reporting_html_print_report($report, $mini = false) { case 'monitor_report': reporting_html_monitor_report($table, $item, $mini); break; + case 'sql_graph_vbar': + reporting_html_sql_graph($table, $item); + break; + case 'sql_graph_hbar': + reporting_html_sql_graph($table, $item); + break; + case 'sql_graph_pie': + reporting_html_sql_graph($table, $item); + break; } if ($item['type'] == 'agent_module') @@ -212,6 +221,12 @@ function reporting_html_print_report($report, $mini = false) { } } +function reporting_html_sql_graph($table, $item) { + $table->colspan['chart']['cell'] = 3; + $table->cellstyle['chart']['cell'] = 'text-align: center;'; + $table->data['chart']['cell'] = $item['chart']; +} + function reporting_html_monitor_report($table, $item, $mini) { if ($mini) { $font_size = '1.5'; @@ -4092,57 +4107,6 @@ function reporting_render_report_html_item ($content, $table, $report, $mini = f } break; - case 'sql_graph_vbar': - case 'sql_graph_hbar': - case 'sql_graph_pie': - $sizgraph_h = 300; - - if ($content['type'] == 'sql_graph_vbar') { - $sizgraph_h = 400; - } - - if ($config['metaconsole'] == 1 && defined('METACONSOLE')) - metaconsole_restore_db(); - - if (empty($item_title)) { - $item_title = __('User defined graph') . " (".__($content["type"]) .")"; - } - reporting_header_content($mini, $content, $report, $table, $item_title, - "", ""); - - // Put description at the end of the module (if exists) - $next_row = 1; - if ($content["description"] != "") { - $data_desc = array(); - $data_desc[0] = $content["description"]; - array_push ($table->data, $data_desc); - $table->colspan[$next_row][0] = 3; - $next_row++; - } - - $table->colspan[$next_row][0] = 3; - - $table2->class = 'databox'; - $table2->width = '100%'; - - //Create the head - $table2->head = array(); - if ($content['header_definition'] != '') { - $table2->head = explode('|', $content['header_definition']); - } - - $data = array (); - - $data[0] = graph_custom_sql_graph( - $content["id_rc"], - $sizgraph_w, - $sizgraph_h, - $content["type"], - true, - ui_get_full_url(false, false, false, false)); - - array_push($table->data, $data); - break; case 'event_report_group': if (empty($item_title)) { $item_title = __('Group detailed event'); From f0d30f105747bb9bb26d4bb76e4c4df415ce5c5f Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Tue, 14 Apr 2015 17:13:12 +0200 Subject: [PATCH 33/80] Moved some the functions to 'functions_reporting.php' --- .../include/functions_reporting.php | 236 ++++++++++++++++++ .../include/functions_reporting_html.php | 232 ----------------- 2 files changed, 236 insertions(+), 232 deletions(-) diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index ceda0c7c0a..133d80711e 100644 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -2918,4 +2918,240 @@ function reporting_get_agentmodule_ttr ($id_agent_module, $period = 0, $date = 0 return $critical_period; } + + +/** + * Get a detailed report of the modules of the agent + * + * @param int $id_agent Agent id to get the report for. + * @param string $filter filter for get partial modules. + * + * @return array An array + */ +function reporting_get_agent_module_info ($id_agent, $filter = false) { + global $config; + + $return = array (); + $return["last_contact"] = 0; //Last agent contact + $return["status"] = STATUS_AGENT_NO_DATA; + $return["status_img"] = ui_print_status_image (STATUS_AGENT_NO_DATA, __('Agent without data'), true); + $return["alert_status"] = "notfired"; + $return["alert_value"] = STATUS_ALERT_NOT_FIRED; + $return["alert_img"] = ui_print_status_image (STATUS_ALERT_NOT_FIRED, __('Alert not fired'), true); + $return["agent_group"] = agents_get_agent_group ($id_agent); + + if (!check_acl ($config["id_user"], $return["agent_group"], "AR")) { + return $return; + } + + if ($filter != '') { + $filter = 'AND '; + } + + $filter = 'disabled = 0'; + + $modules = agents_get_modules($id_agent, false, $filter, true, false); + + if ($modules === false) { + return $return; + } + + $now = get_system_time (); + + // Get modules status for this agent + + $agent = db_get_row ("tagente", "id_agente", $id_agent); + + $return["total_count"] = $agent["total_count"]; + $return["normal_count"] = $agent["normal_count"]; + $return["warning_count"] = $agent["warning_count"]; + $return["critical_count"] = $agent["critical_count"]; + $return["unknown_count"] = $agent["unknown_count"]; + $return["fired_count"] = $agent["fired_count"]; + $return["notinit_count"] = $agent["notinit_count"]; + + if ($return["total_count"] > 0) { + if ($return["critical_count"] > 0) { + $return["status"] = STATUS_AGENT_CRITICAL; + $return["status_img"] = ui_print_status_image (STATUS_AGENT_CRITICAL, __('At least one module in CRITICAL status'), true); + } + else if ($return["warning_count"] > 0) { + $return["status"] = STATUS_AGENT_WARNING; + $return["status_img"] = ui_print_status_image (STATUS_AGENT_WARNING, __('At least one module in WARNING status'), true); + } + else if ($return["unknown_count"] > 0) { + $return["status"] = STATUS_AGENT_DOWN; + $return["status_img"] = ui_print_status_image (STATUS_AGENT_DOWN, __('At least one module is in UKNOWN status'), true); + } + else { + $return["status"] = STATUS_AGENT_OK; + $return["status_img"] = ui_print_status_image (STATUS_AGENT_OK, __('All Monitors OK'), true); + } + } + + //Alert not fired is by default + if ($return["fired_count"] > 0) { + $return["alert_status"] = "fired"; + $return["alert_img"] = ui_print_status_image (STATUS_ALERT_FIRED, __('Alert fired'), true); + $return["alert_value"] = STATUS_ALERT_FIRED; + } + elseif (groups_give_disabled_group ($return["agent_group"])) { + $return["alert_status"] = "disabled"; + $return["alert_value"] = STATUS_ALERT_DISABLED; + $return["alert_img"] = ui_print_status_image (STATUS_ALERT_DISABLED, __('Alert disabled'), true); + } + + return $return; +} + + +/** + * Print tiny statistics of the status of one agent, group, etc. + * + * @param mixed Array with the counts of the total modules, normal modules, critical modules, warning modules, unknown modules and fired alerts + * @param bool return or echo flag + * + * @return string html formatted tiny stats of modules/alerts of an agent + */ +function reporting_tiny_stats ($counts_info, $return = false, $type = 'agent', $separator = ':', $strict_user = false) { + global $config; + + $out = ''; + + // Depend the type of object, the stats will refer agents, modules... + switch ($type) { + case 'modules': + $template_title['total_count'] = __('%d Total modules'); + $template_title['normal_count'] = __('%d Normal modules'); + $template_title['critical_count'] = __('%d Critical modules'); + $template_title['warning_count'] = __('%d Warning modules'); + $template_title['unknown_count'] = __('%d Unknown modules'); + break; + case 'agent': + $template_title['total_count'] = __('%d Total modules'); + $template_title['normal_count'] = __('%d Normal modules'); + $template_title['critical_count'] = __('%d Critical modules'); + $template_title['warning_count'] = __('%d Warning modules'); + $template_title['unknown_count'] = __('%d Unknown modules'); + $template_title['fired_count'] = __('%d Fired alerts'); + break; + default: + $template_title['total_count'] = __('%d Total agents'); + $template_title['normal_count'] = __('%d Normal agents'); + $template_title['critical_count'] = __('%d Critical agents'); + $template_title['warning_count'] = __('%d Warning agents'); + $template_title['unknown_count'] = __('%d Unknown agents'); + $template_title['not_init_count'] = __('%d not init agents'); + $template_title['fired_count'] = __('%d Fired alerts'); + break; + } + + if ($strict_user && $type == 'agent') { + + $acltags = tags_get_user_module_and_tags ($config['id_user'],'AR', $strict_user); + $filter['disabled'] = 0; + $id_agent = $counts_info['id_agente']; + + $counts_info = array(); + $counts_info['normal_count'] = count(tags_get_agent_modules ($id_agent, false, $acltags, false, $filter, false, AGENT_MODULE_STATUS_NORMAL)); + $counts_info['warning_count'] = count(tags_get_agent_modules ($id_agent, false, $acltags, false, $filter, false, AGENT_MODULE_STATUS_WARNING)); + $counts_info['critical_count'] = count(tags_get_agent_modules ($id_agent, false, $acltags, false, $filter, false, AGENT_MODULE_STATUS_CRITICAL_BAD)); + $counts_info['notinit_count'] = count(tags_get_agent_modules ($id_agent, false, $acltags, false, $filter, false, AGENT_MODULE_STATUS_NOT_INIT)); + $counts_info['unknown_count'] = count(tags_get_agent_modules ($id_agent, false, $acltags, false, $filter, false, AGENT_MODULE_STATUS_UNKNOWN)); + $counts_info['total_count'] = $counts_info['normal_count'] + $counts_info['warning_count'] + $counts_info['critical_count'] + $counts_info['unknown_count'] + $counts_info['notinit_count']; + + $all_agent_modules = tags_get_agent_modules ($id_agent, false, $acltags, false, $filter); + if (!empty($all_agent_modules)) { + $mod_clause = "(".implode(',', array_keys($all_agent_modules)).")"; + + $counts_info['fired_count'] = (int) db_get_sql ("SELECT COUNT(times_fired) + FROM talert_template_modules + WHERE times_fired != 0 AND id_agent_module IN ".$mod_clause); + } + else { + $counts_info['fired_count'] = 0; + } + } + + // Store the counts in a data structure to print hidden divs with titles + $stats = array(); + + if (isset($counts_info['total_count'])) { + $not_init = isset($counts_info['notinit_count']) ? $counts_info['notinit_count'] : 0; + $total_count = $counts_info['total_count'] - $not_init; + $stats[] = array('name' => 'total_count', 'count' => $total_count, 'title' => sprintf($template_title['total_count'], $total_count)); + } + + if (isset($counts_info['normal_count'])) { + $normal_count = $counts_info['normal_count']; + $stats[] = array('name' => 'normal_count', 'count' => $normal_count, 'title' => sprintf($template_title['normal_count'], $normal_count)); + } + + if (isset($counts_info['critical_count'])) { + $critical_count = $counts_info['critical_count']; + $stats[] = array('name' => 'critical_count', 'count' => $critical_count, 'title' => sprintf($template_title['critical_count'], $critical_count)); + } + + if (isset($counts_info['warning_count'])) { + $warning_count = $counts_info['warning_count']; + $stats[] = array('name' => 'warning_count', 'count' => $warning_count, 'title' => sprintf($template_title['warning_count'], $warning_count)); + } + + if (isset($counts_info['unknown_count'])) { + $unknown_count = $counts_info['unknown_count']; + $stats[] = array('name' => 'unknown_count', 'count' => $unknown_count, 'title' => sprintf($template_title['unknown_count'], $unknown_count)); + } + + if (isset($counts_info['not_init_count'])) { + $not_init_count = $counts_info['not_init_count']; + $stats[] = array('name' => 'not_init_count', + 'count' => $not_init_count, + 'title' => sprintf($template_title['not_init_count'], $not_init_count)); + } + + if (isset($template_title['fired_count'])) { + if (isset($counts_info['fired_count'])) { + $fired_count = $counts_info['fired_count']; + $stats[] = array('name' => 'fired_count', 'count' => $fired_count, 'title' => sprintf($template_title['fired_count'], $fired_count)); + } + } + + $uniq_id = uniqid(); + + foreach ($stats as $stat) { + $params = array('id' => 'forced_title_' . $stat['name'] . '_' . $uniq_id, + 'class' => 'forced_title_layer', + 'content' => $stat['title'], + 'hidden' => true); + $out .= html_print_div($params, true); + } + + // If total count is less than 0, is an error. Never show negative numbers + if ($total_count < 0) { + $total_count = 0; + } + + $out .= '' . '' . $total_count . ''; + if (isset($fired_count) && $fired_count > 0) + $out .= ' ' . $separator . ' ' . $fired_count . ''; + if (isset($critical_count) && $critical_count > 0) + $out .= ' ' . $separator . ' ' . $critical_count . ''; + if (isset($warning_count) && $warning_count > 0) + $out .= ' ' . $separator . ' ' . $warning_count . ''; + if (isset($unknown_count) && $unknown_count > 0) + $out .= ' ' . $separator . ' ' . $unknown_count . ''; + if (isset($not_init_count) && $not_init_count > 0) + $out .= ' ' . $separator . ' ' . $not_init_count . ''; + if (isset($normal_count) && $normal_count > 0) + $out .= ' ' . $separator . ' ' . $normal_count . ''; + + $out .= ''; + + if ($return) { + return $out; + } + else { + echo $out; + } +} ?> \ No newline at end of file diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index 1afe06c768..db4b5e109a 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -3191,89 +3191,6 @@ function reporting_get_module_detailed_event ($id_modules, $period = 0, $date = } } -/** - * Get a detailed report of the modules of the agent - * - * @param int $id_agent Agent id to get the report for. - * @param string $filter filter for get partial modules. - * - * @return array An array - */ -function reporting_get_agent_module_info ($id_agent, $filter = false) { - global $config; - - $return = array (); - $return["last_contact"] = 0; //Last agent contact - $return["status"] = STATUS_AGENT_NO_DATA; - $return["status_img"] = ui_print_status_image (STATUS_AGENT_NO_DATA, __('Agent without data'), true); - $return["alert_status"] = "notfired"; - $return["alert_value"] = STATUS_ALERT_NOT_FIRED; - $return["alert_img"] = ui_print_status_image (STATUS_ALERT_NOT_FIRED, __('Alert not fired'), true); - $return["agent_group"] = agents_get_agent_group ($id_agent); - - if (!check_acl ($config["id_user"], $return["agent_group"], "AR")) { - return $return; - } - - if ($filter != '') { - $filter = 'AND '; - } - - $filter = 'disabled = 0'; - - $modules = agents_get_modules($id_agent, false, $filter, true, false); - - if ($modules === false) { - return $return; - } - - $now = get_system_time (); - - // Get modules status for this agent - - $agent = db_get_row ("tagente", "id_agente", $id_agent); - - $return["total_count"] = $agent["total_count"]; - $return["normal_count"] = $agent["normal_count"]; - $return["warning_count"] = $agent["warning_count"]; - $return["critical_count"] = $agent["critical_count"]; - $return["unknown_count"] = $agent["unknown_count"]; - $return["fired_count"] = $agent["fired_count"]; - $return["notinit_count"] = $agent["notinit_count"]; - - if ($return["total_count"] > 0) { - if ($return["critical_count"] > 0) { - $return["status"] = STATUS_AGENT_CRITICAL; - $return["status_img"] = ui_print_status_image (STATUS_AGENT_CRITICAL, __('At least one module in CRITICAL status'), true); - } - else if ($return["warning_count"] > 0) { - $return["status"] = STATUS_AGENT_WARNING; - $return["status_img"] = ui_print_status_image (STATUS_AGENT_WARNING, __('At least one module in WARNING status'), true); - } - else if ($return["unknown_count"] > 0) { - $return["status"] = STATUS_AGENT_DOWN; - $return["status_img"] = ui_print_status_image (STATUS_AGENT_DOWN, __('At least one module is in UKNOWN status'), true); - } - else { - $return["status"] = STATUS_AGENT_OK; - $return["status_img"] = ui_print_status_image (STATUS_AGENT_OK, __('All Monitors OK'), true); - } - } - - //Alert not fired is by default - if ($return["fired_count"] > 0) { - $return["alert_status"] = "fired"; - $return["alert_img"] = ui_print_status_image (STATUS_ALERT_FIRED, __('Alert fired'), true); - $return["alert_value"] = STATUS_ALERT_FIRED; - } - elseif (groups_give_disabled_group ($return["agent_group"])) { - $return["alert_status"] = "disabled"; - $return["alert_value"] = STATUS_ALERT_DISABLED; - $return["alert_img"] = ui_print_status_image (STATUS_ALERT_DISABLED, __('Alert disabled'), true); - } - - return $return; -} /** * This is the callback sorting function for SLA values descending @@ -5870,155 +5787,6 @@ function reporting_get_count_events_validated ($filter, $period = 0, $filter_event_warning, $filter_event_no_validated); } -/** - * Print tiny statistics of the status of one agent, group, etc. - * - * @param mixed Array with the counts of the total modules, normal modules, critical modules, warning modules, unknown modules and fired alerts - * @param bool return or echo flag - * - * @return string html formatted tiny stats of modules/alerts of an agent - */ -function reporting_tiny_stats ($counts_info, $return = false, $type = 'agent', $separator = ':', $strict_user = false) { - global $config; - - $out = ''; - - // Depend the type of object, the stats will refer agents, modules... - switch ($type) { - case 'modules': - $template_title['total_count'] = __('%d Total modules'); - $template_title['normal_count'] = __('%d Normal modules'); - $template_title['critical_count'] = __('%d Critical modules'); - $template_title['warning_count'] = __('%d Warning modules'); - $template_title['unknown_count'] = __('%d Unknown modules'); - break; - case 'agent': - $template_title['total_count'] = __('%d Total modules'); - $template_title['normal_count'] = __('%d Normal modules'); - $template_title['critical_count'] = __('%d Critical modules'); - $template_title['warning_count'] = __('%d Warning modules'); - $template_title['unknown_count'] = __('%d Unknown modules'); - $template_title['fired_count'] = __('%d Fired alerts'); - break; - default: - $template_title['total_count'] = __('%d Total agents'); - $template_title['normal_count'] = __('%d Normal agents'); - $template_title['critical_count'] = __('%d Critical agents'); - $template_title['warning_count'] = __('%d Warning agents'); - $template_title['unknown_count'] = __('%d Unknown agents'); - $template_title['not_init_count'] = __('%d not init agents'); - $template_title['fired_count'] = __('%d Fired alerts'); - break; - } - - if ($strict_user && $type == 'agent') { - - $acltags = tags_get_user_module_and_tags ($config['id_user'],'AR', $strict_user); - $filter['disabled'] = 0; - $id_agent = $counts_info['id_agente']; - - $counts_info = array(); - $counts_info['normal_count'] = count(tags_get_agent_modules ($id_agent, false, $acltags, false, $filter, false, AGENT_MODULE_STATUS_NORMAL)); - $counts_info['warning_count'] = count(tags_get_agent_modules ($id_agent, false, $acltags, false, $filter, false, AGENT_MODULE_STATUS_WARNING)); - $counts_info['critical_count'] = count(tags_get_agent_modules ($id_agent, false, $acltags, false, $filter, false, AGENT_MODULE_STATUS_CRITICAL_BAD)); - $counts_info['notinit_count'] = count(tags_get_agent_modules ($id_agent, false, $acltags, false, $filter, false, AGENT_MODULE_STATUS_NOT_INIT)); - $counts_info['unknown_count'] = count(tags_get_agent_modules ($id_agent, false, $acltags, false, $filter, false, AGENT_MODULE_STATUS_UNKNOWN)); - $counts_info['total_count'] = $counts_info['normal_count'] + $counts_info['warning_count'] + $counts_info['critical_count'] + $counts_info['unknown_count'] + $counts_info['notinit_count']; - - $all_agent_modules = tags_get_agent_modules ($id_agent, false, $acltags, false, $filter); - if (!empty($all_agent_modules)) { - $mod_clause = "(".implode(',', array_keys($all_agent_modules)).")"; - - $counts_info['fired_count'] = (int) db_get_sql ("SELECT COUNT(times_fired) - FROM talert_template_modules - WHERE times_fired != 0 AND id_agent_module IN ".$mod_clause); - } - else { - $counts_info['fired_count'] = 0; - } - } - - // Store the counts in a data structure to print hidden divs with titles - $stats = array(); - - if (isset($counts_info['total_count'])) { - $not_init = isset($counts_info['notinit_count']) ? $counts_info['notinit_count'] : 0; - $total_count = $counts_info['total_count'] - $not_init; - $stats[] = array('name' => 'total_count', 'count' => $total_count, 'title' => sprintf($template_title['total_count'], $total_count)); - } - - if (isset($counts_info['normal_count'])) { - $normal_count = $counts_info['normal_count']; - $stats[] = array('name' => 'normal_count', 'count' => $normal_count, 'title' => sprintf($template_title['normal_count'], $normal_count)); - } - - if (isset($counts_info['critical_count'])) { - $critical_count = $counts_info['critical_count']; - $stats[] = array('name' => 'critical_count', 'count' => $critical_count, 'title' => sprintf($template_title['critical_count'], $critical_count)); - } - - if (isset($counts_info['warning_count'])) { - $warning_count = $counts_info['warning_count']; - $stats[] = array('name' => 'warning_count', 'count' => $warning_count, 'title' => sprintf($template_title['warning_count'], $warning_count)); - } - - if (isset($counts_info['unknown_count'])) { - $unknown_count = $counts_info['unknown_count']; - $stats[] = array('name' => 'unknown_count', 'count' => $unknown_count, 'title' => sprintf($template_title['unknown_count'], $unknown_count)); - } - - if (isset($counts_info['not_init_count'])) { - $not_init_count = $counts_info['not_init_count']; - $stats[] = array('name' => 'not_init_count', - 'count' => $not_init_count, - 'title' => sprintf($template_title['not_init_count'], $not_init_count)); - } - - if (isset($template_title['fired_count'])) { - if (isset($counts_info['fired_count'])) { - $fired_count = $counts_info['fired_count']; - $stats[] = array('name' => 'fired_count', 'count' => $fired_count, 'title' => sprintf($template_title['fired_count'], $fired_count)); - } - } - - $uniq_id = uniqid(); - - foreach ($stats as $stat) { - $params = array('id' => 'forced_title_' . $stat['name'] . '_' . $uniq_id, - 'class' => 'forced_title_layer', - 'content' => $stat['title'], - 'hidden' => true); - $out .= html_print_div($params, true); - } - - // If total count is less than 0, is an error. Never show negative numbers - if ($total_count < 0) { - $total_count = 0; - } - - $out .= '' . '' . $total_count . ''; - if (isset($fired_count) && $fired_count > 0) - $out .= ' ' . $separator . ' ' . $fired_count . ''; - if (isset($critical_count) && $critical_count > 0) - $out .= ' ' . $separator . ' ' . $critical_count . ''; - if (isset($warning_count) && $warning_count > 0) - $out .= ' ' . $separator . ' ' . $warning_count . ''; - if (isset($unknown_count) && $unknown_count > 0) - $out .= ' ' . $separator . ' ' . $unknown_count . ''; - if (isset($not_init_count) && $not_init_count > 0) - $out .= ' ' . $separator . ' ' . $not_init_count . ''; - if (isset($normal_count) && $normal_count > 0) - $out .= ' ' . $separator . ' ' . $normal_count . ''; - - $out .= ''; - - if ($return) { - return $out; - } - else { - echo $out; - } -} function reporting_network_interfaces_table ($content, $report, $mini, $item_title = "", &$table = null, &$pdf = null) { From a3f602d1143e7d3d7cc51724f22992abfd7a5cde Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Tue, 14 Apr 2015 19:13:31 +0200 Subject: [PATCH 34/80] Working in the refactoring the code of reports (alert_report_module). --- .../include/functions_reporting.php | 92 ++++++++++ .../include/functions_reporting_html.php | 162 ++++-------------- 2 files changed, 130 insertions(+), 124 deletions(-) diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index 133d80711e..02a807a337 100644 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -333,12 +333,104 @@ function reporting_make_reporting_data($id_report, $date, $time, $force_height_chart, 'sql_graph_pie'); break; + case 'alert_report_module': + $report['contents'][] = reporting_alert_report_module( + $report, + $content); + break; } } return reporting_check_structure_report($report); } +function reporting_alert_report_module($report, $content) { + + global $config; + + $return['type'] = 'alert_report_module'; + + if (empty($content['name'])) { + $content['name'] = __('Alert Report Module'); + } + + $return['title'] = $content['name']; + $return["description"] = $content["description"]; + $return["date"] = reporting_get_date_text($report, $content); + + $alerts = db_get_all_rows_sql('SELECT *, t1.id as id_alert_template_module + FROM talert_template_modules AS t1 + INNER JOIN talert_templates AS t2 ON t1.id_alert_template = t2.id + WHERE id_agent_module = ' . $content['id_agent_module']); + + if ($alerts === false) { + $alerts = array(); + } + + $data = array(); + foreach ($alerts as $alert) { + $data_row = array(); + + $data_row['disabled'] = $alert['disabled']; + + $data_row['template'] = db_get_value_filter('name', + 'talert_templates', array('id' => $alert['id_alert_template'])); + $actions = db_get_all_rows_sql('SELECT name + FROM talert_actions + WHERE id IN (SELECT id_alert_action + FROM talert_template_module_actions + WHERE id_alert_template_module = ' . $alert['id_alert_template_module'] . ');'); + + if (!empty($actions)) { + $row = db_get_row_sql('SELECT id_alert_action + FROM talert_templates + WHERE id IN (SELECT id_alert_template + FROM talert_template_modules + WHERE id = ' . $alert['id_alert_template_module'] . ')'); + + $id_action = 0; + if (!empty($row)) + $id_action = $row['id_alert_action']; + + // Prevent from void action + if (empty($id_action)) + $id_action = 0; + + $actions = db_get_all_rows_sql('SELECT name + FROM talert_actions + WHERE id = ' . $id_action); + + if (empty($actions)) { + $actions = array(); + } + } + + $data_row['action'] = array(); + foreach ($actions as $action) { + $data_row['action'][] = $action['name']; + } + + $data_row['fired'] = array(); + $firedTimes = get_module_alert_fired( + $content['id_agent_module'], + $alert['id_alert_template_module'], + (int) $content['period'], + (int) $report["datetime"]); + if (empty($firedTimes)) { + $firedTimes = array(); + } + foreach ($firedTimes as $fireTime) { + $data_row['fired'][] = $fireTime['timestamp']; + } + + $data[] = $data_row; + } + + $return['data'] = $data; + + return reporting_check_structure_content($return); +} + function reporting_sql_graph($report, $content, $type, $force_width_chart, $force_height_chart, $type_sql_graph) { diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index db4b5e109a..5b4e757fb7 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -209,6 +209,9 @@ function reporting_html_print_report($report, $mini = false) { case 'sql_graph_pie': reporting_html_sql_graph($table, $item); break; + case 'alert_report_module': + reporting_html_alert_report_module($table, $item); + break; } if ($item['type'] == 'agent_module') @@ -221,6 +224,40 @@ function reporting_html_print_report($report, $mini = false) { } } +function reporting_html_alert_report_module($table, $item) { + $table->colspan['alerts']['cell'] = 3; + $table->cellstyle['alerts']['cell'] = 'text-align: left;'; + + $table1->width = '99%'; + $table1->head = array (); + $table1->head['template'] = __('Template'); + $table1->head['actions'] = __('Actions'); + $table1->head['fired'] = __('Fired'); + $table1->data = array (); + foreach ($item['data'] as $alert) { + $row = array(); + + $row['template'] = $alert['template']; + $row['actions'] = $alert['template']; + + $row['actions'] = '
    ' . "\n"; + foreach ($alert['action'] as $action) { + $row['actions'] .= '
  • ' . $action . '
  • ' . "\n"; + } + $row['actions'] .= '
'; + + $row['fired'] = '
    ' . "\n"; + foreach ($alert['fired'] as $fired) { + $row['fired'] .= '
  • ' . $fired . '
  • ' . "\n"; + } + $row['fired'] .= '
'; + + $table1->data[] = $row; + } + + $table->data['alerts']['cell'] = html_print_table($table1, true); +} + function reporting_html_sql_graph($table, $item) { $table->colspan['chart']['cell'] = 3; $table->cellstyle['chart']['cell'] = 'text-align: center;'; @@ -2342,109 +2379,6 @@ function reporting_alert_reporting_group ($id_group, $period = 0, $date = 0, $re } } -/** - * Get a report for alerts of module. - * - * It prints the numbers of alerts defined, fired and not fired of agent. - * - * @param int $id_agent_module Module to get info of the alerts. - * @param int $period Period of time of the desired alert report. - * @param int $date Beggining date of the report (current date by default). - * @param bool $return Flag to return or echo the report (echo by default). - * @param bool Flag to return the html or table object, by default html. - * - * @return mixed A table object (XHTML) or object table is false the html. - */ -function reporting_alert_reporting_module ($id_agent_module, $period = 0, $date = 0, $return = true, $html = true) { - if (!is_numeric ($date)) { - $date = strtotime ($date); - } - if (empty ($date)) { - $date = get_system_time (); - } - - $table->width = '99%'; - $table->data = array (); - $table->head = array (); - $table->head[1] = __('Template'); - $table->head[2] = __('Actions'); - $table->head[3] = __('Fired'); - - - $alerts = db_get_all_rows_sql('SELECT *, t1.id as id_alert_template_module - FROM talert_template_modules AS t1 - INNER JOIN talert_templates AS t2 ON t1.id_alert_template = t2.id - WHERE id_agent_module = ' . $id_agent_module); - - if ($alerts === false) { - $alerts = array(); - } - - $i = 0; - foreach ($alerts as $alert) { - $data = array(); - $data[1] = db_get_value_filter('name', 'talert_templates', array('id' => $alert['id_alert_template'])); - $actions = db_get_all_rows_sql('SELECT name - FROM talert_actions - WHERE id IN (SELECT id_alert_action - FROM talert_template_module_actions - WHERE id_alert_template_module = ' . $alert['id_alert_template_module'] . ');'); - $data[2] = '
    '; - - if ($actions === false) { - $row = db_get_row_sql('SELECT id_alert_action - FROM talert_templates - WHERE id IN (SELECT id_alert_template - FROM talert_template_modules - WHERE id = ' . $alert['id_alert_template_module'] . ')'); - $id_action = 0; - if (!empty($row)) - $id_action = $row['id_alert_action']; - - // Prevent from void action - if (empty($id_action)) - $id_action = 0; - - $actions = db_get_all_rows_sql('SELECT name - FROM talert_actions - WHERE id = ' . $id_action); - } - - if ($actions === false) { - $actions = array(); - } - - foreach ($actions as $action) { - $data[2] .= '
  • ' . $action['name'] . '
  • '; - } - $data[2] .= '
'; - - $data[3] = '
    '; - $firedTimes = get_module_alert_fired($id_agent_module, $alert['id_alert_template_module'], (int) $period, (int) $date); - if ($firedTimes === false) { - $firedTimes = array(); - } - foreach ($firedTimes as $fireTime) { - $data[3] .= '
  • ' . $fireTime['timestamp'] . '
  • '; - } - $data[3] .= '
'; - - if ($alert['disabled']) { - $table->rowstyle[$i] = 'color: grey; font-style: italic;'; - } - $i++; - - array_push ($table->data, $data); - } - - if ($html) { - return html_print_table ($table, $return); - } - else { - return $table; - } -} - /** * Get a report for alerts in a group of agents. * @@ -4221,27 +4155,7 @@ function reporting_render_report_html_item ($content, $table, $report, $mini = f $report["datetime"], true); array_push ($table->data, $data); break; - case 'alert_report_module': - if (empty($item_title)) { - $item_title = __('Alert report module'); - } - reporting_header_content($mini, $content, $report, $table, $item_title, - ui_print_truncate_text($agent_name, 'agent_medium', false) . - '
'.ui_print_truncate_text($module_name, 'module_medium', false)); - - // Put description at the end of the module (if exists) - $table->colspan[1][0] = 3; - if ($content["description"] != "") { - $data_desc = array(); - $data_desc[0] = $content["description"]; - array_push ($table->data, $data_desc); - } - - $data = array (); - $table->colspan[2][0] = 3; - $data[0] = reporting_alert_reporting_module ($content['id_agent_module'], $content['period'], $report["datetime"], true); - array_push ($table->data, $data); - break; + case 'alert_report_agent': if (empty($item_title)) { $item_title = __('Alert report agent'); From 906d6c5fe3d3ae80e5d9b9eb59e3967369888db6 Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Tue, 14 Apr 2015 20:10:20 +0200 Subject: [PATCH 35/80] Working in the refactoring the code of reports (alert_report_agent). --- .../include/functions_reporting.php | 106 +++++++++++ .../include/functions_reporting_html.php | 164 +++++------------- 2 files changed, 145 insertions(+), 125 deletions(-) diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index 02a807a337..44b3173d02 100644 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -338,12 +338,112 @@ function reporting_make_reporting_data($id_report, $date, $time, $report, $content); break; + case 'alert_report_agent': + $report['contents'][] = reporting_alert_report_agent( + $report, + $content); + break; } } return reporting_check_structure_report($report); } +function reporting_alert_report_agent($report, $content) { + + global $config; + + $return['type'] = 'alert_report_agent'; + + if (empty($content['name'])) { + $content['name'] = __('Alert Report Agent'); + } + + $agent_name = agents_get_name($content['id_agent']); + + $return['title'] = $content['name']; + $return['subtitle'] = $agent_name; + $return["description"] = $content["description"]; + $return["date"] = reporting_get_date_text($report, $content); + + $alerts = agents_get_alerts($content['id_agent']); + + if (isset($alerts['simple'])) { + $alerts = $alerts['simple']; + } + else { + $alerts = array(); + } + + $data = array(); + + foreach ($alerts as $alert) { + $data_row = array(); + + $data_row['disabled'] = $alert['disabled']; + + $data_row['module'] = db_get_value_filter('nombre', 'tagente_modulo', + array('id_agente_modulo' => $alert['id_agent_module'])); + $data_row['template'] = db_get_value_filter('name', 'talert_templates', + array('id' => $alert['id_alert_template'])); + + + $actions = db_get_all_rows_sql('SELECT name + FROM talert_actions + WHERE id IN (SELECT id_alert_action + FROM talert_template_module_actions + WHERE id_alert_template_module = ' . $alert['id_alert_template'] . ');'); + + if (!empty($actions)) { + $row = db_get_row_sql('SELECT id_alert_action + FROM talert_templates + WHERE id IN (SELECT id_alert_template + FROM talert_template_modules + WHERE id = ' . $alert['id_alert_template'] . ')'); + + $id_action = 0; + if (!empty($row)) + $id_action = $row['id_alert_action']; + + // Prevent from void action + if (empty($id_action)) + $id_action = 0; + + $actions = db_get_all_rows_sql('SELECT name + FROM talert_actions + WHERE id = ' . $id_action); + + if (empty($actions)) { + $actions = array(); + } + } + + $data_row['action'] = array(); + foreach ($actions as $action) { + $data_row['action'][] = $action['name']; + } + + $data_row['fired'] = array(); + $firedTimes = get_module_alert_fired( + $content['id_agent_module'], + $alert['id_alert_template'], + (int) $content['period'], + (int) $report["datetime"]); + if (empty($firedTimes)) { + $firedTimes = array(); + } + foreach ($firedTimes as $fireTime) { + $data_row['fired'][] = $fireTime['timestamp']; + } + + $data[] = $data_row; + } + + $return['data'] = $data; + + return reporting_check_structure_content($return); +} + function reporting_alert_report_module($report, $content) { global $config; @@ -354,7 +454,13 @@ function reporting_alert_report_module($report, $content) { $content['name'] = __('Alert Report Module'); } + $module_name = io_safe_output( + modules_get_agentmodule_name($content['id_agent_module'])); + $agent_name = io_safe_output( + modules_get_agentmodule_agent_name ($content['id_agent_module'])); + $return['title'] = $content['name']; + $return['subtitle'] = $agent_name . " - " . $module_name; $return["description"] = $content["description"]; $return["date"] = reporting_get_date_text($report, $content); diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index 5b4e757fb7..de3b9eb209 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -212,6 +212,9 @@ function reporting_html_print_report($report, $mini = false) { case 'alert_report_module': reporting_html_alert_report_module($table, $item); break; + case 'alert_report_agent': + reporting_html_alert_report_agent($table, $item); + break; } if ($item['type'] == 'agent_module') @@ -224,6 +227,42 @@ function reporting_html_print_report($report, $mini = false) { } } +function reporting_html_alert_report_agent($table, $item) { + $table->colspan['alerts']['cell'] = 3; + $table->cellstyle['alerts']['cell'] = 'text-align: left;'; + + $table1->width = '99%'; + $table1->head = array (); + $table1->head['module'] = __('Module'); + $table1->head['template'] = __('Template'); + $table1->head['actions'] = __('Actions'); + $table1->head['fired'] = __('Fired'); + $table1->data = array (); + foreach ($item['data'] as $alert) { + $row = array(); + + $row['module'] = $alert['module']; + $row['template'] = $alert['template']; + $row['actions'] = $alert['template']; + + $row['actions'] = '
    ' . "\n"; + foreach ($alert['action'] as $action) { + $row['actions'] .= '
  • ' . $action . '
  • ' . "\n"; + } + $row['actions'] .= '
'; + + $row['fired'] = '
    ' . "\n"; + foreach ($alert['fired'] as $fired) { + $row['fired'] .= '
  • ' . $fired . '
  • ' . "\n"; + } + $row['fired'] .= '
'; + + $table1->data[] = $row; + } + + $table->data['alerts']['cell'] = html_print_table($table1, true); +} + function reporting_html_alert_report_module($table, $item) { $table->colspan['alerts']['cell'] = 3; $table->cellstyle['alerts']['cell'] = 'text-align: left;'; @@ -2137,110 +2176,6 @@ function reporting_get_fired_alerts_table ($alerts_fired) { return $table; } -/** - * Get a report for alerts of agent. - * - * It prints the numbers of alerts defined, fired and not fired of agent. - * - * @param int $id_agent Agent to get info of the alerts. - * @param int $period Period of time of the desired alert report. - * @param int $date Beggining date of the report (current date by default). - * @param bool $return Flag to return or echo the report (echo by default). - * @param bool Flag to return the html or table object, by default html. - * - * @return mixed A table object (XHTML) or object table is false the html. - */ -function reporting_alert_reporting_agent ($id_agent, $period = 0, $date = 0, $return = true, $html = true) { - if (!is_numeric ($date)) { - $date = strtotime ($date); - } - if (empty ($date)) { - $date = get_system_time (); - } - $table->width = '99%'; - $table->data = array (); - $table->head = array (); - $table->head[0] = __('Module'); - $table->head[1] = __('Template'); - $table->head[2] = __('Actions'); - $table->head[3] = __('Fired'); - - $alerts = agents_get_alerts ($id_agent); - - if (isset($alerts['simple'])) { - $i = 0; - if ($alerts['simple'] === false) - $alerts['simple'] = array(); - - foreach ($alerts['simple'] as $alert) { - $data = array(); - $data[0] = db_get_value_filter('nombre', 'tagente_modulo', array('id_agente_modulo' => $alert['id_agent_module'])); - $data[1] = db_get_value_filter('name', 'talert_templates', array('id' => $alert['id_alert_template'])); - $actions = db_get_all_rows_sql('SELECT name - FROM talert_actions - WHERE id IN (SELECT id_alert_action - FROM talert_template_module_actions - WHERE id_alert_template_module = ' . $alert['id'] . ');'); - $data[2] = '
    '; - if ($actions === false) { - $row = db_get_row_sql('SELECT id_alert_action - FROM talert_templates - WHERE id IN (SELECT id_alert_template - FROM talert_template_modules - WHERE id = ' . $alert['id'] . ')'); - $id_action = 0; - if (!empty($row)) - $id_action = $row['id_alert_action']; - - // Prevent from void action - if (empty($id_action)) - $id_action = 0; - - $actions = db_get_all_rows_sql('SELECT name - FROM talert_actions - WHERE id = ' . $id_action); - } - - if ($actions === false) - $actions = array(); - - foreach ($actions as $action) { - $data[2] .= '
  • ' . $action['name'] . '
  • '; - } - $data[2] .= '
'; - - $data[3] = '
    '; - - $firedTimes = get_agent_alert_fired($id_agent, $alert['id'], (int) $period, (int) $date); - if ($firedTimes === false) { - $firedTimes = array(); - } - - if ($firedTimes === false) - $firedTimes = array(); - - foreach ($firedTimes as $fireTime) { - $data[3] .= '
  • ' . $fireTime['timestamp'] . '
  • '; - } - $data[3] .= '
'; - - if ($alert['disabled']) { - $table->rowstyle[$i] = 'color: grey; font-style: italic;'; - } - $i++; - - array_push ($table->data, $data); - } - } - - if ($html) { - return html_print_table ($table, $return); - } - else { - return $table; - } -} - /** * Get a report for alerts of group. * @@ -4156,27 +4091,6 @@ function reporting_render_report_html_item ($content, $table, $report, $mini = f array_push ($table->data, $data); break; - case 'alert_report_agent': - if (empty($item_title)) { - $item_title = __('Alert report agent'); - } - reporting_header_content($mini, $content, $report, $table, $item_title, - ui_print_truncate_text($agent_name, 'agent_medium', false)); - - // Put description at the end of the module (if exists) - $table->colspan[1][0] = 3; - if ($content["description"] != "") { - $data_desc = array(); - $data_desc[0] = $content["description"]; - array_push ($table->data, $data_desc); - } - - $data = array (); - $table->colspan[2][0] = 3; - $data[0] = reporting_alert_reporting_agent ($content['id_agent'], $content['period'], $report["datetime"], true); - array_push ($table->data, $data); - break; - case 'database_serialized': if (empty($item_title)) { $item_title = __('Serialize data'); From befd3bedbf3a3c57203f43dab963c1b22f118ddc Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Wed, 15 Apr 2015 11:26:08 +0200 Subject: [PATCH 36/80] Working in the refactoring the code of reports (alert_report_group). --- .../include/functions_reporting.php | 120 +++++++++++ .../include/functions_reporting_html.php | 203 ++++-------------- 2 files changed, 161 insertions(+), 162 deletions(-) diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index 44b3173d02..33cfbc7ed9 100644 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -343,12 +343,132 @@ function reporting_make_reporting_data($id_report, $date, $time, $report, $content); break; + case 'alert_report_group': + $report['contents'][] = reporting_alert_report_group( + $report, + $content); + break; } } return reporting_check_structure_report($report); } +function reporting_alert_report_group($report, $content) { + + global $config; + + $return['type'] = 'alert_report_group'; + + if (empty($content['name'])) { + $content['name'] = __('Alert Report Group'); + } + + $group_name = groups_get_name($content['id_group'], true); + + $return['title'] = $content['name']; + $return['subtitle'] = $group_name; + $return["description"] = $content["description"]; + $return["date"] = reporting_get_date_text($report, $content); + + if ($content['id_group'] == 0) { + $alerts = db_get_all_rows_sql(' + SELECT * + FROM talert_template_modules + WHERE disabled = 0 + AND id_agent_module IN ( + SELECT id_agente_modulo + FROM tagente_modulo)'); + } + else { + $alerts = db_get_all_rows_sql(' + SELECT * + FROM talert_template_modules + WHERE disabled = 0 + AND id_agent_module IN ( + SELECT id_agente_modulo + FROM tagente_modulo + WHERE id_agente IN ( + SELECT id_agente + FROM tagente WHERE id_grupo = ' . $content['id_group'] . '))'); + } + + if (empty($alerts)) { + $alerts = array(); + } + + + $data = array(); + + foreach ($alerts as $alert) { + $data_row = array(); + + $data_row['disabled'] = $alert['disabled']; + + $data_row['agent'] = io_safe_output(agents_get_name( + agents_get_agent_id_by_module_id($alert['id_agent_module']))); + $data_row['module'] = db_get_value_filter('nombre', 'tagente_modulo', + array('id_agente_modulo' => $alert['id_agent_module'])); + $data_row['template'] = db_get_value_filter('name', 'talert_templates', + array('id' => $alert['id_alert_template'])); + + + $actions = db_get_all_rows_sql('SELECT name + FROM talert_actions + WHERE id IN (SELECT id_alert_action + FROM talert_template_module_actions + WHERE id_alert_template_module = ' . $alert['id_alert_template'] . ');'); + + if (!empty($actions)) { + $row = db_get_row_sql('SELECT id_alert_action + FROM talert_templates + WHERE id IN (SELECT id_alert_template + FROM talert_template_modules + WHERE id = ' . $alert['id_alert_template'] . ')'); + + $id_action = 0; + if (!empty($row)) + $id_action = $row['id_alert_action']; + + // Prevent from void action + if (empty($id_action)) + $id_action = 0; + + $actions = db_get_all_rows_sql('SELECT name + FROM talert_actions + WHERE id = ' . $id_action); + + if (empty($actions)) { + $actions = array(); + } + } + + $data_row['action'] = array(); + foreach ($actions as $action) { + $data_row['action'][] = $action['name']; + } + + $data_row['fired'] = array(); + $firedTimes = get_module_alert_fired( + $content['id_agent_module'], + $alert['id_alert_template'], + (int) $content['period'], + (int) $report["datetime"]); + if (empty($firedTimes)) { + $firedTimes = array(); + } + foreach ($firedTimes as $fireTime) { + $data_row['fired'][] = $fireTime['timestamp']; + } + + $data[] = $data_row; + } + + $return['data'] = $data; + + return reporting_check_structure_content($return); +} + function reporting_alert_report_agent($report, $content) { global $config; diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index de3b9eb209..25efd1e672 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -215,6 +215,9 @@ function reporting_html_print_report($report, $mini = false) { case 'alert_report_agent': reporting_html_alert_report_agent($table, $item); break; + case 'alert_report_group': + reporting_html_alert_report_group($table, $item); + break; } if ($item['type'] == 'agent_module') @@ -227,6 +230,44 @@ function reporting_html_print_report($report, $mini = false) { } } +function reporting_html_alert_report_group($table, $item) { + $table->colspan['alerts']['cell'] = 3; + $table->cellstyle['alerts']['cell'] = 'text-align: left;'; + + $table1->width = '99%'; + $table1->head = array (); + $table1->head['agent'] = __('Agent'); + $table1->head['module'] = __('Module'); + $table1->head['template'] = __('Template'); + $table1->head['actions'] = __('Actions'); + $table1->head['fired'] = __('Fired'); + $table1->data = array (); + foreach ($item['data'] as $alert) { + $row = array(); + + $row['agent'] = $alert['agent']; + $row['module'] = $alert['module']; + $row['template'] = $alert['template']; + $row['actions'] = $alert['template']; + + $row['actions'] = '
    ' . "\n"; + foreach ($alert['action'] as $action) { + $row['actions'] .= '
  • ' . $action . '
  • ' . "\n"; + } + $row['actions'] .= '
'; + + $row['fired'] = '
    ' . "\n"; + foreach ($alert['fired'] as $fired) { + $row['fired'] .= '
  • ' . $fired . '
  • ' . "\n"; + } + $row['fired'] .= '
'; + + $table1->data[] = $row; + } + + $table->data['alerts']['cell'] = html_print_table($table1, true); +} + function reporting_html_alert_report_agent($table, $item) { $table->colspan['alerts']['cell'] = 3; $table->cellstyle['alerts']['cell'] = 'text-align: left;'; @@ -2176,144 +2217,6 @@ function reporting_get_fired_alerts_table ($alerts_fired) { return $table; } -/** - * Get a report for alerts of group. - * - * It prints the numbers of alerts defined, fired and not fired of agent. - * - * @param int $id_agent_module Module to get info of the alerts. - * @param int $period Period of time of the desired alert report. - * @param int $date Beggining date of the report (current date by default). - * @param bool $return Flag to return or echo the report (echo by default). - * @param bool Flag to return the html or table object, by default html. - * - * @return mixed A table object (XHTML) or object table is false the html. - */ -function reporting_alert_reporting_group ($id_group, $period = 0, $date = 0, $return = true, $html = true) { - if (!is_numeric ($date)) { - $date = strtotime ($date); - } - if (empty ($date)) { - $date = get_system_time (); - } - - $table->width = '99%'; - $table->data = array (); - $table->head = array (); - - $table->head[0] = __('Agent'); - $table->head[1] = __('Module'); - $table->head[2] = __('Template'); - $table->head[3] = __('Actions'); - $table->head[4] = __('Fired'); - - if ($id_group == 0) { - $alerts = db_get_all_rows_sql(' - SELECT * - FROM talert_template_modules - WHERE disabled = 0 - AND id_agent_module IN ( - SELECT id_agente_modulo - FROM tagente_modulo)'); - } - else { - $alerts = db_get_all_rows_sql(' - SELECT * - FROM talert_template_modules - WHERE disabled = 0 - AND id_agent_module IN ( - SELECT id_agente_modulo - FROM tagente_modulo - WHERE id_agente IN ( - SELECT id_agente - FROM tagente WHERE id_grupo = ' . $id_group . '))'); - } - - if ($alerts === false) { - $alerts = array(); - } - - $i = 0; - foreach ($alerts as $alert) { - $data = array(); - - $data[] = io_safe_output( - agents_get_name( - agents_get_agent_id_by_module_id( - $alert['id_agent_module']))); - - $data[] = io_safe_output( - modules_get_agentmodule_name($alert['id_agent_module'])); - - $data[] = db_get_value_filter('name', - 'talert_templates', - array('id' => $alert['id_alert_template'])); - - $actions = db_get_all_rows_sql('SELECT name - FROM talert_actions - WHERE id IN (SELECT id_alert_action - FROM talert_template_module_actions - WHERE id_alert_template_module = ' . $alert['id_agent_module'] . ');'); - $list = '
    '; - if ($actions === false) { - $row = db_get_row_sql('SELECT id_alert_action - FROM talert_templates - WHERE id IN (SELECT id_alert_template - FROM talert_template_modules - WHERE id = ' . $alert['id'] . ')'); - $id_action = 0; - if (!empty($row)) - $id_action = $row['id_alert_action']; - - // Prevent from void action - if (empty($id_action)) - $id_action = 0; - - $actions = db_get_all_rows_sql('SELECT name - FROM talert_actions - WHERE id = ' . $id_action); - } - - if ($actions == false) - $actions = array(); - - foreach ($actions as $action) { - $list .= '
  • ' . $action['name'] . '
  • '; - } - $list .= '
'; - $data[] = $list; - - $list = '
    '; - - $firedTimes = get_module_alert_fired( - $alert['id_agent_module'], - $alert['id'], (int) $period, (int) $date); - - if ($firedTimes === false) { - $firedTimes = array(); - } - foreach ($firedTimes as $fireTime) { - $list .= '
  • ' . $fireTime['timestamp'] . '
  • '; - } - $list .= '
'; - - if ($alert['disabled']) { - $table->rowstyle[$i] = 'color: grey; font-style: italic;'; - } - $i++; - $data[] = $list; - - array_push ($table->data, $data); - } - - if ($html) { - return html_print_table ($table, $return); - } - else { - return $table; - } -} - /** * Get a report for alerts in a group of agents. * @@ -4066,30 +3969,6 @@ function reporting_render_report_html_item ($content, $table, $report, $mini = f $data[0] = reporting_get_module_detailed_event($content['id_agent_module'], $content['period'], $report["datetime"], true); array_push ($table->data, $data); break; - case 'alert_report_group': - if (empty($item_title)) { - $item_title = __('Alert report group'); - } - reporting_header_content($mini, $content, $report, $table, $item_title, - ui_print_truncate_text( - groups_get_name($content['id_group'], true), - 60, false)); - - // Put description at the end of the module (if exists) - $table->colspan[1][0] = 3; - if ($content["description"] != "") { - $data_desc = array(); - $data_desc[0] = $content["description"]; - array_push ($table->data, $data_desc); - } - - $data = array (); - $table->colspan[2][0] = 3; - $data[0] = reporting_alert_reporting_group( - $content['id_group'], $content['period'], - $report["datetime"], true); - array_push ($table->data, $data); - break; case 'database_serialized': if (empty($item_title)) { From 1d0bab4b646f6dbb872eacbd1ebfed5d76b5c35d Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Wed, 15 Apr 2015 19:05:52 +0200 Subject: [PATCH 37/80] Working in the refactoring the code of reports (network_interfaces_report). --- .../include/functions_reporting.php | 107 +++++++- .../include/functions_reporting_html.php | 230 +++++------------- 2 files changed, 172 insertions(+), 165 deletions(-) diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index 33cfbc7ed9..fbd6cc4f35 100644 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -348,12 +348,115 @@ function reporting_make_reporting_data($id_report, $date, $time, $report, $content); break; + case 'network_interfaces_report': + $report['contents'][] = reporting_network_interfaces_report( + $report, + $content); + break; } } return reporting_check_structure_report($report); } +function reporting_network_interfaces_report($report, $content, + $type = 'dinamic', $force_width_chart = null, $force_height_chart = null) { + + global $config; + + $return['type'] = 'network_interfaces_report'; + + if (empty($content['name'])) { + $content['name'] = __('Network interfaces report'); + } + + $group_name = groups_get_name($content['id_group']); + + $return['title'] = $content['name']; + $return['subtitle'] = $group_name; + $return["description"] = $content["description"]; + $return["date"] = reporting_get_date_text($report, $content); + + include_once($config['homedir'] . "/include/functions_custom_graphs.php"); + + $filter = array( + 'id_grupo' => $content['id_group'], + 'disabled' => 0); + $network_interfaces_by_agents = agents_get_network_interfaces(false, $filter); + + if (empty($network_interfaces_by_agents)) { + $return['error'] = 1; + $return['data'] = array(); + } + else { + $return['error'] = 0; + $return['data'] = array(); + + foreach ($network_interfaces_by_agents as $agent_id => $agent) { + $row_data = array(); + + $row_data['agent'] = $agent['name']; + + $row_data['interfaces'] = array(); + foreach ($agent['interfaces'] as $interface_name => $interface) { + $row_interface = array(); + + $row_interface['name'] = $interface_name; + $row_interface['ip'] = $interface['ip']; + $row_interface['mac'] = $interface['mac']; + $row_interface['status'] = $interface['status_image']; + $row_interface['chart'] = null; + + // Get chart + reporting_set_conf_charts($width, $height, $only_image, + $type, $content, $ttl); + + if (!empty($force_width_chart)) { + $width = $force_width_chart; + } + + if (!empty($force_height_chart)) { + $height = $force_height_chart; + } + + switch ($type) { + case 'dinamic': + case 'static': + if (!empty($interface['traffic'])) { + $row_interface['chart'] = custom_graphs_print(0, + $height, + $width, + $content['period'], + null, + true, + $report["datetime"], + $only_image, + 'white', + array_values($interface['traffic']), + $config['homeurl'], + array_keys($interface['traffic']), + array_fill(0, count($interface['traffic']), __("bytes/s")), + false, + true, + true, + true, + $ttl); + } + break; + case 'data': + break; + } + + $row_data['interfaces'][] = $row_interface; + } + + $return['data'][] = $row_data; + } + } + + return reporting_check_structure_content($return); +} + function reporting_alert_report_group($report, $content) { global $config; @@ -2078,14 +2181,16 @@ function reporting_check_structure_content($report) { return $report; } -function reporting_set_conf_charts(&$width, &$height, &$only_image, $type, $content) { +function reporting_set_conf_charts(&$width, &$height, &$only_image, $type, $content, &$ttl) { switch ($type) { case 'dinamic': $only_image = false; $width = 900; $height = 230; + $ttl = 1; break; case 'static': + $ttl = 2; $only_image = true; if ($content['style']['show_in_landscape']) { $height = 1100; diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index 25efd1e672..2b933c97c9 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -218,6 +218,9 @@ function reporting_html_print_report($report, $mini = false) { case 'alert_report_group': reporting_html_alert_report_group($table, $item); break; + case 'network_interfaces_report': + reporting_html_network_interfaces_report($table, $item); + break; } if ($item['type'] == 'agent_module') @@ -230,6 +233,68 @@ function reporting_html_print_report($report, $mini = false) { } } +function reporting_html_network_interfaces_report($table, $item) { + + if ($item['error']) { + $table->colspan['interfaces']['cell'] = 3; + $table->cellstyle['interfaces']['cell'] = 'text-align: left;'; + $table->data['interfaces']['cell'] = + __('The group has no agents or none of the agents has any network interface'); + } + else { + + foreach ($item['data'] as $agent) { + $table_agent = new StdCLass(); + $table_agent->width = '100%'; + $table_agent->data = array(); + $table_agent->head = array(); + $table_agent->head[0] = sprintf(__("Agent '%s'"), $agent['name']); + $table_agent->headstyle = array(); + $table_agent->headstyle[0] = 'font-size: 16px;'; + $table_agent->style[0] = 'text-align: center'; + + $table_agent->data['interfaces'] = ""; + + foreach ($agent['interfaces'] as $interface) { + $table_interface = new StdClass(); + $table_interface->width = '100%'; + $table_interface->data = array(); + $table_interface->rowstyle = array(); + $table_interface->head = array(); + $table_interface->cellstyle = array(); + $table_interface->title = sprintf(__("Interface '%s' throughput graph"), + $interface['name']); + $table_interface->head['ip'] = __('IP'); + $table_interface->head['mac'] = __('Mac'); + $table_interface->head['status'] = __('Actual status'); + $table_interface->style['ip'] = 'text-align: left'; + $table_interface->style['mac'] = 'text-align: left'; + $table_interface->style['status'] = 'width: 150px; text-align: center'; + + $data = array(); + $data['ip'] = !empty($interface['ip']) ? $interface['ip'] : "--"; + $data['mac'] = !empty($interface['mac']) ? $interface['mac'] : "--"; + $data['status'] = $interface['status_image']; + $table_interface->data['data'] = $data; + + if (!empty($interface['chart'])) { + $table_interface->data['graph'] = $interface['chart']; + $table_interface->colspan['graph'][0] = 3; + $table_interface->cellstyle['graph'][0] = 'text-align: center;'; + } + + $table_agent->data['interfaces'] .= html_print_table($table_interface, true); + $table_agent->colspan[$interface_name][0] = 3; + } + + $id = uniq_id(); + + $table->data['agents'][$id] = html_print_table($table_agent, true); + $table->colspan[$id][0] = 3; + } + } +} + function reporting_html_alert_report_group($table, $item) { $table->colspan['alerts']['cell'] = 3; $table->cellstyle['alerts']['cell'] = 'text-align: left;'; @@ -4155,9 +4220,7 @@ function reporting_render_report_html_item ($content, $table, $report, $mini = f
" . __('Legend') . "
" . __("Orange cell when the module has fired alerts") . "
"; break; - case 'network_interfaces_report': - reporting_network_interfaces_table($content, $report, $mini, $item_title, $table); - break; + case 'top_n': $top_n = $content['top_n']; @@ -5494,167 +5557,6 @@ function reporting_get_count_events_validated ($filter, $period = 0, $filter_event_warning, $filter_event_no_validated); } - - -function reporting_network_interfaces_table ($content, $report, $mini, $item_title = "", &$table = null, &$pdf = null) { - global $config; - - include_once($config['homedir'] . "/include/functions_custom_graphs.php"); - - if (empty($item_title)) { - $group_name = groups_get_name($content['id_group']); - $item_title = __('Network interfaces') . " - " . sprintf(__('Group "%s"'), $group_name); - } - - $is_html = $table !== null; - $is_pdf = $pdf !== null; - - $ttl = $is_pdf ? 2 : 1; - - $graph_width = 900; - $graph_height = 200; - - $datetime = $report['datetime']; - $period = $content['period']; - - if ($is_pdf) { - $graph_width = 800; - $graph_height = 200; - pdf_header_content($pdf, $content, $report, $item_title, false, $content["description"]); - } - else if ($is_html) { - reporting_header_content($mini, $content, $report, $table, $item_title); - - //RUNNING - $table->style[1] = 'text-align: right'; - - // Put description at the end of the module (if exists) - $table->colspan[0][1] = 2; - $next_row = 1; - if ($content["description"] != "") { - $table->colspan[$next_row][0] = 3; - $next_row++; - $data_desc = array(); - $data_desc[0] = $content["description"]; - array_push ($table->data, $data_desc); - } - } - - $filter = array( - 'id_grupo' => $content['id_group'], - 'disabled' => 0 - ); - $network_interfaces_by_agents = agents_get_network_interfaces(false, $filter); - - if (empty($network_interfaces_by_agents)) { - if ($is_pdf) { - $pdf->addHTML(__('The group has no agents or none of the agents has any network interface')); - } - else if ($is_html) { - $data = array(); - $data[0] = __('The group has no agents or none of the agents has any network interface'); - $table->colspan[$next_row][0] = 3; - array_push ($table->data, $data); - } - return; - } - else { - foreach ($network_interfaces_by_agents as $agent_id => $agent) { - - $table_agent = new StdCLass(); - $table_agent->width = '100%'; - $table_agent->data = array(); - $table_agent->head = array(); - $table_agent->head[0] = sprintf(__("Agent '%s'"), $agent['name']); - $table_agent->headstyle = array(); - $table_agent->headstyle[0] = 'font-size: 16px;'; - $table_agent->style[0] = 'text-align: center'; - - if ($is_pdf) { - $table_agent->class = 'table_sla table_beauty'; - $table_agent->headstyle[0] = 'background: #373737; color: #FFF; display: table-cell; font-size: 16px; border: 1px solid grey'; - } - - $table_agent->data['interfaces'] = ""; - - foreach ($agent['interfaces'] as $interface_name => $interface) { - $table_interface = new StdClass(); - $table_interface->width = '100%'; - $table_interface->data = array(); - $table_interface->rowstyle = array(); - $table_interface->head = array(); - $table_interface->cellstyle = array(); - $table_interface->title = sprintf(__("Interface '%s' throughput graph"), $interface_name); - $table_interface->head['ip'] = __('IP'); - $table_interface->head['mac'] = __('Mac'); - $table_interface->head['status'] = __('Actual status'); - $table_interface->style['ip'] = 'text-align: left'; - $table_interface->style['mac'] = 'text-align: left'; - $table_interface->style['status'] = 'width: 150px; text-align: center'; - - if ($is_pdf) { - $table_interface->class = 'table_sla table_beauty'; - $table_interface->titlestyle = 'background: #373737; color: #FFF; display: table-cell; font-size: 12px; border: 1px solid grey'; - - $table_interface->headstyle['ip'] = 'text-align: left; background: #666; color: #FFF; display: table-cell; font-size: 11px; border: 1px solid grey'; - $table_interface->headstyle['mac'] = 'text-align: left; background: #666; color: #FFF; display: table-cell; font-size: 11px; border: 1px solid grey'; - $table_interface->headstyle['status'] = 'background: #666; color: #FFF; display: table-cell; font-size: 11px; border: 1px solid grey'; - - $table_interface->style['ip'] = 'text-align: left; display: table-cell; font-size: 10px;'; - $table_interface->style['mac'] = 'text-align: left; display: table-cell; font-size: 10px;'; - $table_interface->style['status'] = 'text-align: center; display: table-cell; font-size: 10px;'; - } - - $data = array(); - $data['ip'] = !empty($interface['ip']) ? $interface['ip'] : "--"; - $data['mac'] = !empty($interface['mac']) ? $interface['mac'] : "--"; - $data['status'] = $interface['status_image']; - $table_interface->data['data'] = $data; - - if (!empty($interface['traffic'])) { - - $only_image = !(bool)$config['flash_charts'] || $is_pdf ? true : false; - - $graph = custom_graphs_print(0, - $graph_height, - $graph_width, - $period, - null, - true, - $date, - $only_image, - 'white', - array_values($interface['traffic']), - $config['homeurl'], - array_keys($interface['traffic']), - array_fill(0, count($interface['traffic']),"bytes/s"), - false, - true, - true, - true, - $ttl); - - $table_interface->data['graph'] = $graph; - $table_interface->colspan['graph'][0] = count($table_interface->head); - $table_interface->cellstyle['graph'][0] = 'text-align: center;'; - } - - $table_agent->data['interfaces'] .= html_print_table($table_interface, true); - $table_agent->colspan[$interface_name][0] = 3; - } - - if ($is_html) { - $table->data[$agent_id] = html_print_table($table_agent, true); - $table->colspan[$agent_id][0] = 3; - } - else if ($is_pdf) { - $html = html_print_table($table_agent, true); - $pdf->addHTML($html); - } - } - } -} - function reporting_get_agents_by_status ($data, $graph_width = 250, $graph_height = 150, $links = false) { global $config; From 713988d6743ac1170d88083fea2ed44e98c81228 Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Wed, 15 Apr 2015 21:00:17 +0200 Subject: [PATCH 38/80] Working in the refactoring the code of reports (group_configuration). --- .../include/functions_reporting.php | 53 ++++- .../include/functions_reporting_html.php | 186 +++--------------- 2 files changed, 73 insertions(+), 166 deletions(-) diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index fbd6cc4f35..1ab370370d 100644 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -353,12 +353,58 @@ function reporting_make_reporting_data($id_report, $date, $time, $report, $content); break; + case 'group_configuration': + $report['contents'][] = reporting_group_configuration( + $report, + $content); + break; } } return reporting_check_structure_report($report); } +function reporting_group_configuration($report, $content) { + global $config; + + $return['type'] = 'group_configuration'; + + if (empty($content['name'])) { + $content['name'] = __('Group configuration'); + } + + $group_name = groups_get_name($content['id_group'], true); + + $return['title'] = $content['name']; + $return['subtitle'] = $group_name; + $return["description"] = $content["description"]; + $return["date"] = reporting_get_date_text($report, $content); + $return['id_group'] = $content['id_group']; + + + if ($content['id_group'] == 0) { + $sql = "SELECT * FROM tagente;"; + } + else { + $sql = "SELECT * FROM tagente WHERE id_grupo=" . $content['id_group']; + } + + $agents_list = db_get_all_rows_sql($sql); + if ($agents_list === false) + $agents_list = array(); + + $return['data'] = array(); + foreach ($agents_list as $agent) { + $content_agent = $content; + $content_agent['id_agent'] = $agent['id_agente']; + $agent_report = reporting_agent_configuration($report, $content_agent); + + $return['data'][] = $agent_report['data']; + } + + return reporting_check_structure_content($return); +} + function reporting_network_interfaces_report($report, $content, $type = 'dinamic', $force_width_chart = null, $force_height_chart = null) { @@ -1192,8 +1238,11 @@ function reporting_agent_configuration($report, $content) { $tags = db_get_all_rows_sql($sql_tag); if ($tags === false) $data_module['tags'] = array(); - else - $data_module['tags'] = $tags; + else { + foreach ($tags as $tag) { + $data_module['tags'][] = $tag['name']; + } + } $agent_configuration['modules'][] = $data_module; } diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index 2b933c97c9..5ebf7e46b1 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -221,6 +221,9 @@ function reporting_html_print_report($report, $mini = false) { case 'network_interfaces_report': reporting_html_network_interfaces_report($table, $item); break; + case 'group_configuration': + reporting_html_group_configuration($table, $item); + break; } if ($item['type'] == 'agent_module') @@ -233,6 +236,25 @@ function reporting_html_print_report($report, $mini = false) { } } +function reporting_html_group_configuration($table, $item) { + + $table1->width = '100%'; + $table1->head = array (); + $table1->data = array (); + $cell = ""; + foreach ($item['data'] as $agent) { + $table2->width = '100%'; + $table2->data = array (); + reporting_html_agent_configuration(&$table2, array('data' => $agent)); + + $cell .= html_print_table($table2, true); + } + + $table->colspan['group_configuration']['cell'] = 3; + $table->cellstyle['group_configuration']['cell'] = 'text-align: center;'; + $table->data['group_configuration']['cell'] = $cell; +} + function reporting_html_network_interfaces_report($table, $item) { if ($item['error']) { @@ -5221,170 +5243,6 @@ function reporting_render_report_html_item ($content, $table, $report, $mini = f array_push ($table->data, $data); break; - - - case 'group_configuration': - $group_name = groups_get_name($content['id_group']); - if (empty($item_title)) { - $item_title = __('Group configuration: ').$group_name; - } - reporting_header_content($mini, $content, $report, $table, $item_title); - - $sql = "SELECT * FROM tagente WHERE id_grupo=".$content['id_group']; - $agents_list = db_get_all_rows_sql($sql); - if ($agents_list === false) - $agents_list = array(); - - $table->colspan[0][1] = 10; - - $i = 1; - foreach ($agents_list as $agent) { - $data= array (); - - $table->colspan[$i][3] = 2; - $table->colspan[$i][4] = 4; - $table->colspan[$i][5] = 2; - $table->colspan[$i][5] = 2; - - $i++; - - //Agent's data - $data[0] = ''.__('Agent name').''; - $data[1] = ''.__('Group').''; - $data[2] = ''.__('SO').''; - $data[3] = ''.__('IP').''; - $data[4] = ''.__('Description').''; - $data[5] = ''.__('Status').''; - - array_push ($table->data, $data); - unset($data); - - $sql = "SELECT * FROM tagente WHERE id_agente=".$agent['id_agente']; - $agent_data = db_get_row_sql($sql); - - $data[0] = $agent_data['nombre']; - $data[1] = ui_print_group_icon ($agent_data['id_grupo'], true, '', '', false); - $data[2] = ui_print_os_icon ($agent_data["id_os"], true, true); - $data[3] = $agent_data['direccion']; - $agent_data_comentarios = strip_tags(ui_bbcode_to_html($agent_data['comentarios'])); - $data[4] = $agent_data_comentarios; - - if ($agent_data['disabled'] == 0) - $data[5] = __('Enabled'); - else - $data[5] = __('Disabled'); - - $table->colspan[$i][3] = 2; - $table->colspan[$i][4] = 4; - $table->colspan[$i][5] = 2; - $table->colspan[$i][5] = 2; - - $i++; - - array_push ($table->data, $data); - unset($data); - - - - $modules = agents_get_modules ($agent['id_agente']); - - if ($modules == null) { - $modules = array(); - } - else { - - //Agent's modules - $data[0] = ''; - $data[1] = ''.agents_get_name ($agent['id_agente'], 'upper').__(' MODULES').''; - $table->colspan[$i][1] = 10; - - $i++; - - array_push ($table->data, $data); - unset($data); - - $data[0] = ''; - $data[1] = ''.__('Name').''; - $data[2] = ''.__('Type').''; - $data[3] = ''.__('Warning').'/'.'
'.__('Critical').'
'; - $data[4] = ''.__('Threshold').''; - $data[5] = ''.__('Group').''; - $data[6] = ''.__('Description').''; - $data[7] = ''.__('Interval').''; - $data[8] = ''.__('Unit').''; - $data[9] = ''.__('Status').''; - $data[10] = ''.__('Tags').''; - - $table->style[0] = 'width:10px'; - $table->style[1] = 'text-align: left'; - $table->style[2] = 'text-align: center'; - $table->style[3] = 'text-align: center'; - $table->style[4] = 'text-align: center'; - $table->style[5] = 'text-align: center'; - $table->style[6] = 'text-align: left'; - $table->style[7] = 'text-align: center'; - $table->style[8] = 'text-align: center'; - $table->style[9] = 'text-align: left'; - $table->style[10] = 'text-align: left'; - - array_push ($table->data, $data); - - $i++; - } - - foreach ($modules as $id_agent_module=>$module) { - $sql = "SELECT * - FROM tagente_modulo - WHERE id_agente_modulo=$id_agent_module"; - $data_module = db_get_row_sql($sql); - - $data = array(); - - $data[0] = ''; - - if ($data_module['disabled'] == 0) - $disabled = ''; - else - $disabled = ' (Disabled)'; - $data[1] = $data_module['nombre'].$disabled; - $data[2] = ui_print_moduletype_icon ($data_module['id_tipo_modulo'], true); - $data[3] = $data_module['max_warning'].'/'.$data_module['min_warning'].'
'.$data_module['max_critical'].'/'.$data_module['min_critical']; - $data[4] = $data_module['module_ff_interval']; - $data[5] = groups_get_name ($content['id_group'], true); - $data[6] = $data_module['descripcion']; - - if (($data_module['module_interval'] == 0) || ($data_module['module_interval'] == '')) - $data[7] = db_get_value('intervalo', 'tagente', 'id_agente', $content['id_agent']); - else - $data[7] = $data_module['module_interval']; - - - $data[8] = $data_module['unit']; - - $module_status = db_get_row('tagente_estado', 'id_agente_modulo', $id_agent_module); - modules_get_status($id_agent_module, $module_status['estado'], $module_status['datos'], $status, $title); - $data[9] = ui_print_status_image($status, $title, true); - - $sql_tag = "SELECT name - FROM ttag - WHERE id_tag IN ( - SELECT id_tag - FROM ttag_module - WHERE id_agente_modulo = $id_agent_module)"; - $tags = db_get_all_rows_sql($sql_tag); - if ($tags === false) - $tags = ''; - else - $tags = implode (",", $tags); - - $data[10] = $tags; - array_push ($table->data, $data); - - $i++; - } - - } - break; } //Restore dbconnection if (($config ['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE') && $remote_connection == 1) { From 8182edb9fa43c792405103c68c61bca925b170ed Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Thu, 16 Apr 2015 19:23:55 +0200 Subject: [PATCH 39/80] Fixed the SLA with a period have a setted a time slots. (MANUAL cherry picked from commit c5b5d60d4ccdd93a06655cf0e4ee67bb634b2a2d) --- .../include/functions_reporting_html.php | 227 +++++++++++++++++- 1 file changed, 226 insertions(+), 1 deletion(-) diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index 5ebf7e46b1..47e1bf59ef 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -1130,7 +1130,7 @@ function reporting_get_agentmodule_data_sum ($id_agent_module, * @return float SLA percentage of the requested module. False if no data were * found */ -function reporting_get_agentmodule_sla ($id_agent_module, $period = 0, $min_value = 1, $max_value = false, $date = 0, $daysWeek = null, $timeFrom = null, $timeTo = null) { +function reporting_get_agentmodule_sla_day ($id_agent_module, $period = 0, $min_value = 1, $max_value = false, $date = 0, $daysWeek = null, $timeFrom = null, $timeTo = null) { global $config; if (empty($id_agent_module)) @@ -1208,6 +1208,7 @@ function reporting_get_agentmodule_sla ($id_agent_module, $period = 0, $min_valu // Get previous data $previous_data = modules_get_previous_data ($id_agent_module, $datelimit); + if ($previous_data !== false) { $previous_data['utimestamp'] = $datelimit; array_unshift ($interval_data, $previous_data); @@ -1215,6 +1216,7 @@ function reporting_get_agentmodule_sla ($id_agent_module, $period = 0, $min_valu // Get next data $next_data = modules_get_next_data ($id_agent_module, $date); + if ($next_data !== false) { $next_data['utimestamp'] = $date; array_push ($interval_data, $next_data); @@ -1255,6 +1257,8 @@ function reporting_get_agentmodule_sla ($id_agent_module, $period = 0, $min_valu $previous_status = 0; } + + foreach ($interval_data as $data) { // Previous status was critical if ($previous_status == 1) { @@ -1284,6 +1288,227 @@ function reporting_get_agentmodule_sla ($id_agent_module, $period = 0, $min_valu // Return the percentage of SLA compliance return (float) (100 - ($bad_period / $period) * 100); } + +/** + * Get SLA of a module. + * + * @param int Agent module to calculate SLA + * @param int Period to check the SLA compliance. + * @param int Minimum data value the module in the right interval + * @param int Maximum data value the module in the right interval. False will + * ignore max value + * @param int Beginning date of the report in UNIX time (current date by default). + * @param array $dayWeek Array of days week to extract as array('monday' => false, 'tuesday' => true....), and by default is null. + * @param string $timeFrom Time in the day to start to extract in mysql format, by default null. + * @param string $timeTo Time in the day to end to extract in mysql format, by default null. + * + * @return float SLA percentage of the requested module. False if no data were + * found + */ +function reporting_get_agentmodule_sla ($id_agent_module, $period = 0, + $min_value = 1, $max_value = false, $date = 0, $daysWeek = null, + $timeFrom = null, $timeTo = null) { + + global $config; + + if (empty($id_agent_module)) + return false; + + // Set initial conditions + $bad_period = 0; + // Limit date to start searching data + $datelimit = $date - $period; + $search_in_history_db = db_search_in_history_db($datelimit); + + // Initialize variables + if (empty ($date)) { + $date = get_system_time (); + } + if ($daysWeek === null) { + $daysWeek = array(); + } + + + // Calculate the SLA for large time without hours + if ($timeFrom == $timeTo) { + // Get interval data + $sql = sprintf ('SELECT * + FROM tagente_datos + 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 + if ($daysWeek) { + foreach ($daysWeek as $key => $value) { + if (!$value) { + if ($key == 'monday') { + $days[] = 2; + } + if ($key == 'tuesday') { + $days[] = 3; + } + if ($key == 'wednesday') { + $days[] = 4; + } + if ($key == 'thursday') { + $days[] = 5; + } + if ($key == 'friday') { + $days[] = 6; + } + if ($key == 'saturday') { + $days[] = 7; + } + if ($key == 'sunday') { + $days[] = 1; + } + } + } + } + + if (count($days) > 0) { + $sql .= ' AND DAYOFWEEK(FROM_UNIXTIME(utimestamp)) NOT IN (' . implode(',', $days) . ')'; + } + + $sql .= "\n"; + $sql .= ' ORDER BY utimestamp ASC'; + $interval_data = db_get_all_rows_sql ($sql, $search_in_history_db); + + if ($interval_data === false) { + $interval_data = array (); + } + + // Calculate planned downtime dates + $downtime_dates = reporting_get_planned_downtimes_intervals($id_agent_module, $datelimit, $date); + + // Get previous data + $previous_data = modules_get_previous_data ($id_agent_module, $datelimit); + + if ($previous_data !== false) { + $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) { + $next_data['utimestamp'] = $date; + array_push ($interval_data, $next_data); + } + else if (count ($interval_data) > 0) { + // Propagate the last known data to the end of the interval + $next_data = array_pop ($interval_data); + array_push ($interval_data, $next_data); + $next_data['utimestamp'] = $date; + array_push ($interval_data, $next_data); + } + + if (count ($interval_data) < 2) { + return false; + } + + + $first_data = array_shift ($interval_data); + + // Do not count the empty start of an interval as 0 + if ($first_data['utimestamp'] != $datelimit) { + $period = $date - $first_data['utimestamp']; + } + + $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; + } + } + } + else { + $previous_status = 0; + } + + + + + + foreach ($interval_data as $data) { + // Previous status was critical + if ($previous_status == 1) { + $bad_period += $data['utimestamp'] - $previous_utimestamp; + } + + if (array_key_exists('datos', $data)) { + // Re-calculate previous status for the next data + if ((($max_value > $min_value AND ($data['datos'] > $max_value OR $data['datos'] < $min_value))) OR + ($max_value <= $min_value AND $data['datos'] < $min_value)) { + + $previous_status = 1; + foreach ($downtime_dates as $date_dt) { + if (($date_dt['date_from'] <= $data['utimestamp']) AND ($date_dt['date_to'] >= $data['utimestamp'])) { + $previous_status = 0; + } + } + } + else { + $previous_status = 0; + } + } + + $previous_utimestamp = $data['utimestamp']; + } + + // Return the percentage of SLA compliance + return (float) (100 - ($bad_period / $period) * 100); + } + elseif ($period <= SECONDS_1DAY) { + + + return reporting_get_agentmodule_sla_day( + $id_agent_module, + $period, + $min_value, + $max_value, + $date, + $daysWeek, + $timeFrom, + $timeTo); + } + else { + // Extract the data each day + + $sla = 0; + + $i = 0; + for ($interval = 0; $interval <= $period; $interval = $interval + SECONDS_1DAY) { + $datelimit = $date - $interval; + + $sla_day = reporting_get_agentmodule_sla( + $id_agent_module, + SECONDS_1DAY, + $min_value, + $max_value, + $datelimit + $interval, + $daysWeek, + $timeFrom, $timeTo); + + + $sla += $sla_day; + $i++; + } + + $sla = $sla / $i; + + return $sla; + } +} + /** * Get several SLA data for an agentmodule within a period divided on subperiods * From 1993dae68242c200e98a3685a8b5c26f1a2b2f91 Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Fri, 17 Apr 2015 19:24:07 +0200 Subject: [PATCH 40/80] Working in the refactoring the code of reports (database_serialized). --- .../include/functions_reporting.php | 107 +++++++++++++++++ .../include/functions_reporting_html.php | 109 +++++------------- 2 files changed, 133 insertions(+), 83 deletions(-) diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index 1ab370370d..3869454424 100644 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -358,12 +358,119 @@ function reporting_make_reporting_data($id_report, $date, $time, $report, $content); break; + case 'database_serialized': + $report['contents'][] = reporting_database_serialized( + $report, + $content); + break; } } return reporting_check_structure_report($report); } +function reporting_database_serialized($report, $content) { + global $config; + + $return['type'] = 'database_serialized'; + + if (empty($content['name'])) { + $content['name'] = __('Database Serialized'); + } + + $return['title'] = $content['name']; + $return["description"] = $content["description"]; + $return["date"] = reporting_get_date_text($report, $content); + + $keys = array(); + if ($content['header_definition'] != '') { + $keys = explode('|', $content['header_definition']); + } + + $return['keys'] = $keys; + + + $datelimit = $report["datetime"] - $content['period']; + $search_in_history_db = db_search_in_history_db($datelimit); + + // This query gets information from the default and the historic database + $result = db_get_all_rows_sql('SELECT * + FROM tagente_datos + WHERE id_agente_modulo = ' . $content['id_agent_module'] . ' + AND utimestamp > ' . $datelimit . ' + AND utimestamp <= ' . $report["datetime"], $search_in_history_db); + + // Adds string data if there is no numeric data + if ((count($result) < 0) or (!$result)) { + // This query gets information from the default and the historic database + $result = db_get_all_rows_sql('SELECT * + FROM tagente_datos_string + WHERE id_agente_modulo = ' . $content['id_agent_module'] . ' + AND utimestamp > ' . $datelimit . ' + AND utimestamp <= ' . $report["datetime"], $search_in_history_db); + } + if ($result === false) { + $result = array(); + } + + $data = array(); + foreach ($result as $row) { + $date = date($config["date_format"], $row['utimestamp']); + $serialized_data = $row['datos']; + + // Cut line by line + if (empty($content['line_separator']) || + empty($serialized_data)) { + + $rowsUnserialize = array($row['datos']); + } + else { + $rowsUnserialize = explode($content['line_separator'], $serialized_data); + } + + + foreach ($rowsUnserialize as $rowUnser) { + $row = array(); + + $row['date'] = $date; + $row['data'] = array(); + + if (empty($content['column_separator'])) { + if (empty($keys)) { + $row['data'][][] = $rowUnser; + } + else { + $row['data'][][$keys[0]] = $rowUnser; + } + } + else { + $columnsUnserialize = explode($content['column_separator'], $rowUnser); + + + $i = 0; + $temp_row = array(); + foreach ($columnsUnserialize as $cell) { + if (isset($keys[$i])) { + $temp_row[$keys[$i]] = $cell; + } + else { + $temp_row[] = $cell; + } + $i++; + } + + $row['data'][] = $temp_row; + } + + $data[] = $row; + } + } + + $return["data"] = $data; + + return reporting_check_structure_content($return); +} + function reporting_group_configuration($report, $content) { global $config; diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index 47e1bf59ef..dc0e37e7e9 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -224,6 +224,9 @@ function reporting_html_print_report($report, $mini = false) { case 'group_configuration': reporting_html_group_configuration($table, $item); break; + case 'database_serialized': + reporting_html_database_serialized($table, $item); + break; } if ($item['type'] == 'agent_module') @@ -236,6 +239,29 @@ function reporting_html_print_report($report, $mini = false) { } } +function reporting_html_database_serialized($table, $item) { + + $table1->width = '100%'; + $table1->head = array (__('Date')); + if (!empty($item['keys'])) { + $table1->head = array_merge($table1->head, $item['keys']); + } + $table1->style[0] = 'text-align: left'; + + $table1->data = array (); + foreach ($item['data'] as $data) { + foreach ($data['data'] as $data_unserialied) { + $row = array($data['date']); + $row = array_merge($row, $data_unserialied); + $table1->data[] = $row; + } + } + + $table->colspan['database_serialized']['cell'] = 3; + $table->cellstyle['database_serialized']['cell'] = 'text-align: center;'; + $table->data['database_serialized']['cell'] = html_print_table($table1, true); +} + function reporting_html_group_configuration($table, $item) { $table1->width = '100%'; @@ -4282,89 +4308,6 @@ function reporting_render_report_html_item ($content, $table, $report, $mini = f array_push ($table->data, $data); break; - case 'database_serialized': - if (empty($item_title)) { - $item_title = __('Serialize data'); - } - reporting_header_content($mini, $content, $report, $table, $item_title, - ui_print_truncate_text($module_name, 'module_medium', false)); - - // Put description at the end of the module (if exists) - $next_row = 1; - if ($content["description"] != "") { - $data_desc = array(); - $data_desc[0] = $content["description"]; - $table->colspan[$next_row][0] = 3; - array_push ($table->data, $data_desc); - $next_row++; - } - - $table->colspan[$next_row][0] = 3; - - $table2->class = 'databox alternate'; - $table2->width = '100%'; - - //Create the head - $table2->head = array(); - if ($content['header_definition'] != '') { - $table2->head = explode('|', $content['header_definition']); - } - else { - $table2->head[] = __('Data'); - } - array_unshift($table2->head, __('Date')); - - $datelimit = $report["datetime"] - $content['period']; - $search_in_history_db = db_search_in_history_db($datelimit); - - // This query gets information from the default and the historic database - $result = db_get_all_rows_sql('SELECT * - FROM tagente_datos - WHERE id_agente_modulo = ' . $content['id_agent_module'] . ' - AND utimestamp > ' . $datelimit . ' - AND utimestamp <= ' . $report["datetime"], $search_in_history_db); - - // Adds string data if there is no numeric data - if ((count($result) < 0) or (!$result)) { - // This query gets information from the default and the historic database - $result = db_get_all_rows_sql('SELECT * - FROM tagente_datos_string - WHERE id_agente_modulo = ' . $content['id_agent_module'] . ' - AND utimestamp > ' . $datelimit . ' - AND utimestamp <= ' . $report["datetime"], $search_in_history_db); - } - if ($result === false) { - $result = array(); - } - - $table2->data = array(); - foreach ($result as $row) { - $date = date ($config["date_format"], $row['utimestamp']); - $serialized = $row['datos']; - if (empty($content['line_separator']) || - empty($serialized)) { - $rowsUnserialize = array($row['datos']); - } - else { - $rowsUnserialize = explode($content['line_separator'], $serialized); - } - foreach ($rowsUnserialize as $rowUnser) { - if (empty($content['column_separator'])) { - $columnsUnserialize = array($rowUnser); - } - else { - $columnsUnserialize = explode($content['column_separator'], $rowUnser); - } - - array_unshift($columnsUnserialize, $date); - array_push($table2->data, $columnsUnserialize); - } - } - - $cellContent = html_print_table($table2, true); - array_push($table->data, array($cellContent)); - break; - case 'group_report': $group_name = groups_get_name($content['id_group'], true); $group_stats = reporting_get_group_stats($content['id_group']); From 5572b885745a3cd7522c3e39961044e5d92b1451 Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Tue, 21 Apr 2015 13:18:29 +0200 Subject: [PATCH 41/80] Fixed the lost checkbox to show graphs in the event items in the report --- .../reporting_builder.item_editor.php | 32 +++++++++++++++++-- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/pandora_console/godmode/reporting/reporting_builder.item_editor.php b/pandora_console/godmode/reporting/reporting_builder.item_editor.php index 3737e6b3a3..9b200eaaa8 100644 --- a/pandora_console/godmode/reporting/reporting_builder.item_editor.php +++ b/pandora_console/godmode/reporting/reporting_builder.item_editor.php @@ -1150,14 +1150,24 @@ else html_print_checkbox ('event_graph_by_agent', true, $event_graph_by_agent); ?> - + + + + + + + + @@ -2047,7 +2057,10 @@ function chooseType() { $("#row_module_multi").hide(); $("#row_event_filter").hide(); $("#row_event_graphs").hide(); - $("#row_event_graph_by_agent").show(); + $("#row_event_graph_by_agent").hide(); + $("#row_event_graph_by_user").hide(); + $("#row_event_graph_by_criticity").hide(); + $("#row_event_graph_by_validated").hide(); $("#row_netflow_filter").hide(); $("#row_max_values").hide(); $("#row_resolution").hide(); @@ -2075,6 +2088,11 @@ function chooseType() { $("#row_show_in_two_columns").show(); $("#row_event_filter").show(); $("#row_event_graphs").show(); + + $("#row_event_graph_by_agent").show(); + $("#row_event_graph_by_user").show(); + $("#row_event_graph_by_criticity").show(); + $("#row_event_graph_by_validated").show(); break; case 'simple_graph': $("#row_time_compare_overlapped").show(); @@ -2291,7 +2309,10 @@ function chooseType() { $("#row_show_in_two_columns").show(); $("#row_event_filter").show(); $("#row_event_graphs").show(); - $("#row_event_graph_by_agent").hide(); + + $("#row_event_graph_by_user").show(); + $("#row_event_graph_by_criticity").show(); + $("#row_event_graph_by_validated").show(); $('#agent_autocomplete').hide(); $('#agent_autocomplete_events').show(); @@ -2303,6 +2324,11 @@ function chooseType() { $("#row_period").show(); $("#row_show_in_two_columns").show(); + $("#row_event_graph_by_agent").show(); + $("#row_event_graph_by_user").show(); + $("#row_event_graph_by_criticity").show(); + $("#row_event_graph_by_validated").show(); + $('#agent_autocomplete').hide(); $('#agent_autocomplete_events').show(); break; From 1a41cc4973e872185728ebbf7c80fd54033a6ffb Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Tue, 21 Apr 2015 17:27:21 +0200 Subject: [PATCH 42/80] Working in the refactoring the code of reports (group_report). --- .../include/functions_reporting.php | 292 +++++++++ .../include/functions_reporting_html.php | 554 +++++++----------- 2 files changed, 492 insertions(+), 354 deletions(-) diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index 3869454424..cf48d108fb 100644 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -363,12 +363,153 @@ function reporting_make_reporting_data($id_report, $date, $time, $report, $content); break; + case 'agent_detailed_event': + case 'event_report_agent': + $report['contents'][] = reporting_event_report_agent( + $report, + $content); + break; + case 'group_report': + $report['contents'][] = reporting_group_report( + $report, + $content); + break; } } return reporting_check_structure_report($report); } +function reporting_group_report($report, $content) { + global $config; + + $return['type'] = 'group_report'; + + + if (empty($content['name'])) { + $content['name'] = __('Group Report'); + } + + $return['title'] = $content['name']; + $return['subtitle'] = groups_get_name($content['id_group'], true); + $return["description"] = $content["description"]; + $return["date"] = reporting_get_date_text($report, $content); + + $return["data"] = array(); + + $events = events_get_group_events( + $content['id_group'], + $content['period'], + $report['datetime']); + if (empty($events)) { + $events = array(); + } + $return["data"]["count_events"] = count($events); + + $return["data"]["group_stats"] = reporting_get_group_stats($content['id_group']); + + return reporting_check_structure_content($return); +} + +function reporting_event_report_agent($report, $content) { + global $config; + + $return['type'] = 'event_report_agent'; + + if (empty($content['name'])) { + $content['name'] = __('Event Report Agent'); + } + + $return['title'] = $content['name']; + $return['subtitle'] = agents_get_name($content['id_agent']); + $return["description"] = $content["description"]; + $return["date"] = reporting_get_date_text($report, $content); + + $style = $content['style']; + + $filter_event_no_validated = $style['filter_event_no_validated']; + $filter_event_validated = $style['filter_event_validated']; + $filter_event_critical = $style['filter_event_critical']; + $filter_event_warning = $style['filter_event_warning']; + + $event_graph_by_user_validator = $style['event_graph_by_user_validator']; + $event_graph_by_criticity = $style['event_graph_by_criticity']; + $event_graph_validated_vs_unvalidated = $style['event_graph_validated_vs_unvalidated']; + + $return['data'] = reporting_get_agents_detailed_event( + $content['id_agent'], + $content['period'], + $report["datetime"], + true, + $filter_event_validated, + $filter_event_critical, + $filter_event_warning, + $filter_event_no_validated, + true); + + $return["chart"]["by_user_validator"] = null; + $return["chart"]["by_criticity"] = null; + $return["chart"]["validated_vs_unvalidated"] = null; + + if ($event_graph_by_user_validator) { + $data_chart = + reporting_get_count_events_validated_by_user( + array('id_agent' => $content['id_agent']), + $content['period'], + $report["datetime"], + $filter_event_validated, + $filter_event_critical, + $filter_event_warning, + $filter_event_no_validated); + + $return["chart"]["by_user_validator"] = pie3d_graph( + false, + $data_chart, + 500, + 150, + __("other"), + "", + ui_get_full_url(false, false, false, false) . "/images/logo_vertical_water.png", + $config['fontpath'], + $config['font_size']); + } + + if ($event_graph_by_criticity) { + $data_graph = reporting_get_count_events_by_criticity( + array('id_agent' => $content['id_agent']), $content['period'], + $report["datetime"], + $filter_event_validated, + $filter_event_critical, + $filter_event_warning, + $filter_event_no_validated); + + $colors = get_criticity_pie_colors($data_graph); + + $return["chart"]["by_criticity"] = pie3d_graph( + false, $data_graph, 500, 150, __("other"), "", + ui_get_full_url(false, false, false, false) . "/images/logo_vertical_water.png", + $config['fontpath'], $config['font_size'], 1, false, $colors); + } + + if ($event_graph_validated_vs_unvalidated) { + $data_graph = reporting_get_count_events_validated( + array('id_agent' => $content['id_agent']), $content['period'], + $report["datetime"], + $filter_event_validated, + $filter_event_critical, + $filter_event_warning, + $filter_event_no_validated); + + $return["chart"]["validated_vs_unvalidated"] = pie3d_graph( + false, $data_graph, 500, 150, __("other"), "", + ui_get_full_url(false, false, false, false) . "/images/logo_vertical_water.png", + $config['fontpath'], $config['font_size']); + } + + return reporting_check_structure_content($return); +} + + function reporting_database_serialized($report, $content) { global $config; @@ -2367,6 +2508,157 @@ function reporting_set_conf_charts(&$width, &$height, &$only_image, $type, $cont //////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// + + +/** + * Get a detailed report of summarized events per agent + * + * It construct a table object with all the grouped events happened in an agent + * during a period of time. + * + * @param mixed Agent id(s) to get the report from. + * @param int Period of time (in seconds) to get the report. + * @param int Beginning date (unixtime) of the report + * @param bool Flag to return or echo the report table (echo by default). + * + * @return A table object (XHTML) + */ +function reporting_get_agents_detailed_event ($id_agents, $period = 0, + $date = 0, $return = false, $filter_event_validated = false, + $filter_event_critical = false, $filter_event_warning = false, + $filter_event_no_validated = false, $only_data = false) { + + global $config; + + if ($only_data) { + $return_data = array(); + } + + $id_agents = (array)safe_int ($id_agents, 1); + + if (!is_numeric ($date)) { + $date = strtotime ($date); + } + if (empty ($date)) { + $date = get_system_time (); + } + + $table->width = '99%'; + + $table->align = array(); + $table->align[0] = 'center'; + $table->align[1] = 'center'; + $table->align[3] = 'center'; + + $table->data = array (); + + $table->head = array (); + $table->head[0] = __('Status'); + $table->head[1] = __('Count'); + $table->head[2] = __('Name'); + $table->head[3] = __('Type'); + $table->head[4] = __('Criticity'); + $table->head[5] = __('Val. by'); + $table->head[6] = __('Timestamp'); + + $events = array (); + + foreach ($id_agents as $id_agent) { + $event = events_get_agent ($id_agent, + (int)$period, + (int)$date, + $filter_event_validated, $filter_event_critical, + $filter_event_warning, $filter_event_no_validated); + + if (empty($event)) { + $event = array(); + } + + if ($only_data) { + foreach ($event as $e) { + $return_data[] = array( + 'status' => $e['estado'], + 'count' => $e['event_rep'], + 'name' => $e['evento'], + 'type' => $e["event_type"], + 'criticity' => $e["criticity"], + 'validated_by' => $e['id_usuario'], + 'timestamp' => $e['timestamp_rep'] + ); + } + } + else { + if (!empty ($event)) { + array_push ($events, $event); + } + } + } + + if ($only_data) { + return $return_data; + } + + if ($events) { + $note = ''; + if (count($events) >= 1000) { + $note .= '* ' . __('Maximum of events shown') . ' (1000)
'; + } + foreach ($events as $eventRow) { + foreach ($eventRow as $k => $event) { + //First pass along the class of this row + $table->cellclass[$k][1] = $table->cellclass[$k][2] = + $table->cellclass[$k][4] = $table->cellclass[$k][5] = + $table->cellclass[$k][6] = + 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, + "title" => $title_st)); + + $data[] = $event['event_rep']; + + $data[] = ui_print_truncate_text( + io_safe_output($event['evento']), + 140, false, true); + //$data[] = $event['event_type']; + $data[] = events_print_type_img ($event["event_type"], true); + + $data[] = get_priority_name ($event['criticity']); + if (empty($event['id_usuario']) && $event['estado'] == EVENT_VALIDATE) { + $data[] = '' . __('System') . ''; + } + else { + $user_name = db_get_value ('fullname', 'tusuario', 'id_user', $event['id_usuario']); + $data[] = io_safe_output($user_name); + } + $data[] = '' . + date($config['date_format'], $event['timestamp_rep']) . ''; + array_push ($table->data, $data); + } + } + } + + if ($events) + return html_print_table ($table, $return) . $note; +} + /** * Get general statistical info on a group * diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index dc0e37e7e9..b00b44e41f 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -227,6 +227,13 @@ function reporting_html_print_report($report, $mini = false) { case 'database_serialized': reporting_html_database_serialized($table, $item); break; + case 'agent_detailed_event': + case 'event_report_agent': + reporting_html_event_report_agent($table, $item); + break; + case 'group_report': + reporting_html_group_report($table, $item); + break; } if ($item['type'] == 'agent_module') @@ -239,6 +246,199 @@ function reporting_html_print_report($report, $mini = false) { } } +function reporting_html_group_report($table, $item) { + global $config; + + $table->colspan['group_report']['cell'] = 3; + $table->cellstyle['group_report']['cell'] = 'text-align: center;'; + $table->data['group_report']['cell'] = " + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
" . + __('Total') . "
" . + __('Unknown') . "
" . + __('Agents') . "
" . + $item["data"]['group_stats']['total_agents'] . "
" . + $item["data"]['group_stats']['agents_unknown'] . "
" . + __('Total') . "
" . + __('Normal') . "
" . + __('Critical') . "
" . + __('Warning') . "
" . + __('Unknown') . "
" . + __('Not init') . "
" . + __('Monitors') . "
" . + $item["data"]['group_stats']['monitor_checks'] . "
" . + $item["data"]['group_stats']['monitor_ok'] ."
" . + $item["data"]['group_stats']['monitor_critical'] . "
" . + $item["data"]['group_stats']['monitor_warning'] . "
" . + $item["data"]['group_stats']['monitor_unknown'] . "
" . + $item["data"]['group_stats']['monitor_not_init'] . "
" . + __('Defined') . "
" . + __('Fired') . "
" . + __('Alerts') . "
" . + $item["data"]['group_stats']['monitor_alerts'] . "
" . + $item["data"]['group_stats']['monitor_alerts_fired'] . "
" . + __('Last %s', human_time_description_raw($item['date']['period'])) . "
" . + __('Events') . "
" . + $item["data"]["count_events"]."
"; +} + +function reporting_html_event_report_agent($table, $item) { + global $config; + + $table1->width = '99%'; + + $table1->align = array(); + $table1->align[0] = 'center'; + $table1->align[1] = 'center'; + $table1->align[3] = 'center'; + + $table1->data = array (); + + $table1->head = array (); + $table1->head[0] = __('Status'); + $table1->head[1] = __('Count'); + $table1->head[2] = __('Name'); + $table1->head[3] = __('Type'); + $table1->head[4] = __('Criticity'); + $table1->head[5] = __('Val. by'); + $table1->head[6] = __('Timestamp'); + + foreach ($item['data'] as $i => $event) { + $table1->cellclass[$i][1] = + $table1->cellclass[$i][2] = + $table1->cellclass[$i][4] = + $table1->cellclass[$i][5] = + $table1->cellclass[$i][6] = + get_priority_class ($event["criticity"]); + + $data = array (); + // Colored box + switch ($event['status']) { + 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, + "title" => $title_st)); + + $data[] = $event['count']; + + $data[] = ui_print_truncate_text( + io_safe_output($event['name']), + 140, false, true); + //$data[] = $event['event_type']; + $data[] = events_print_type_img ($event["type"], true); + + $data[] = get_priority_name ($event['criticity']); + if (empty($event['validated_by']) && $event['status'] == EVENT_VALIDATE) { + $data[] = '' . __('System') . ''; + } + else { + $user_name = db_get_value ('fullname', 'tusuario', 'id_user', $event['validated_by']); + $data[] = io_safe_output($user_name); + } + $data[] = '' . + date($config['date_format'], $event['timestamp']) . ''; + array_push ($table1->data, $data); + } + + $table->colspan['event_list']['cell'] = 3; + $table->cellstyle['event_list']['cell'] = 'text-align: center;'; + $table->data['event_list']['cell'] = html_print_table($table1, true); + + if (!empty($item['chart']['by_user_validator'])) { + $table1 = null; + $table1->width = '99%'; + $table1->head = array (); + $table1->head[0] = __('Events validated by user'); + $table1->data[0][0] = $item['chart']['by_user_validator']; + + $table->colspan['chart_by_user_validator']['cell'] = 3; + $table->cellstyle['chart_by_user_validator']['cell'] = 'text-align: center;'; + $table->data['chart_by_user_validator']['cell'] = html_print_table($table1, true); + } + + if (!empty($item['chart']['by_criticity'])) { + $table1 = null; + $table1->width = '99%'; + $table1->head = array (); + $table1->head[0] = __('Events by criticity'); + $table1->data[0][0] = $item['chart']['by_criticity']; + + $table->colspan['chart_by_criticity']['cell'] = 3; + $table->cellstyle['chart_by_criticity']['cell'] = 'text-align: center;'; + $table->data['chart_by_criticity']['cell'] = html_print_table($table1, true); + } + + if (!empty($item['chart']['validated_vs_unvalidated'])) { + $table1 = null; + $table1->width = '99%'; + $table1->head = array (); + $table1->head[0] = __('Amount events validated'); + $table1->data[0][0] = $item['chart']['validated_vs_unvalidated']; + + $table->colspan['chart_validated_vs_unvalidated']['cell'] = 3; + $table->cellstyle['chart_validated_vs_unvalidated']['cell'] = 'text-align: center;'; + $table->data['chart_validated_vs_unvalidated']['cell'] = html_print_table($table1, true); + } +} + function reporting_html_database_serialized($table, $item) { $table1->width = '100%'; @@ -2958,127 +3158,6 @@ function reporting_agents_get_group_agents_detailed ($id_group, $period = 0, $da } -/** - * Get a detailed report of summarized events per agent - * - * It construct a table object with all the grouped events happened in an agent - * during a period of time. - * - * @param mixed Agent id(s) to get the report from. - * @param int Period of time (in seconds) to get the report. - * @param int Beginning date (unixtime) of the report - * @param bool Flag to return or echo the report table (echo by default). - * - * @return A table object (XHTML) - */ -function reporting_get_agents_detailed_event ($id_agents, $period = 0, - $date = 0, $return = false, $filter_event_validated = false, - $filter_event_critical = false, $filter_event_warning = false, $filter_event_no_validated = false) { - - global $config; - - $id_agents = (array)safe_int ($id_agents, 1); - - if (!is_numeric ($date)) { - $date = strtotime ($date); - } - if (empty ($date)) { - $date = get_system_time (); - } - - $table->width = '99%'; - - $table->align = array(); - $table->align[0] = 'center'; - $table->align[1] = 'center'; - $table->align[3] = 'center'; - - $table->data = array (); - - $table->head = array (); - $table->head[0] = __('Status'); - $table->head[1] = __('Count'); - $table->head[2] = __('Name'); - $table->head[3] = __('Type'); - $table->head[4] = __('Criticity'); - $table->head[5] = __('Val. by'); - $table->head[6] = __('Timestamp'); - - $events = array (); - - foreach ($id_agents as $id_agent) { - $event = events_get_agent ($id_agent, - (int)$period, - (int)$date, - $filter_event_validated, $filter_event_critical, - $filter_event_warning, $filter_event_no_validated); - - if (!empty ($event)) { - array_push ($events, $event); - } - } - - if ($events) { - $note = ''; - if (count($events) >= 1000) { - $note .= '* ' . __('Maximum of events shown') . ' (1000)
'; - } - foreach ($events as $eventRow) { - foreach ($eventRow as $k => $event) { - //First pass along the class of this row - $table->cellclass[$k][1] = $table->cellclass[$k][2] = - $table->cellclass[$k][4] = $table->cellclass[$k][5] = - $table->cellclass[$k][6] = - 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, - "title" => $title_st)); - - $data[] = $event['event_rep']; - - $data[] = ui_print_truncate_text( - io_safe_output($event['evento']), - 140, false, true); - //$data[] = $event['event_type']; - $data[] = events_print_type_img ($event["event_type"], true); - - $data[] = get_priority_name ($event['criticity']); - if (empty($event['id_usuario']) && $event['estado'] == EVENT_VALIDATE) { - $data[] = '' . __('System') . ''; - } - else { - $user_name = db_get_value ('fullname', 'tusuario', 'id_user', $event['id_usuario']); - $data[] = io_safe_output($user_name); - } - $data[] = '' . - date($config['date_format'], $event['timestamp_rep']) . ''; - array_push ($table->data, $data); - } - } - } - - if ($events) - return html_print_table ($table, $return) . $note; -} - /** * Gets a detailed reporting of groups's events. * @@ -4003,136 +4082,6 @@ function reporting_render_report_html_item ($content, $table, $report, $mini = f } break; - case 'agent_detailed_event': - case 'event_report_agent': - if (empty($item_title)) { - $item_title = __('Agent detailed event'); - } - reporting_header_content($mini, $content, $report, $table, $item_title, - ui_print_truncate_text(agents_get_name($content['id_agent']), 'agent_medium', false)); - - $style = json_decode(io_safe_output($content['style']), true); - - $filter_event_no_validated = $style['filter_event_no_validated']; - $filter_event_validated = $style['filter_event_validated']; - $filter_event_critical = $style['filter_event_critical']; - $filter_event_warning = $style['filter_event_warning']; - - $event_graph_by_agent = $style['event_graph_by_agent']; - $event_graph_by_user_validator = $style['event_graph_by_user_validator']; - $event_graph_by_criticity = $style['event_graph_by_criticity']; - $event_graph_validated_vs_unvalidated = $style['event_graph_validated_vs_unvalidated']; - - $next_row = 1; - - // Put description at the end of the module (if exists) - if ($content["description"] != "") { - $data_desc = array(); - $data_desc[0] = $content["description"]; - array_push ($table->data, $data_desc); - $table->colspan[$next_row][0] = 3; - $next_row++; - } - - $data = array (); - $table->colspan[$next_row][0] = 3; - $next_row++; - $data[0] = reporting_get_agents_detailed_event( - $content['id_agent'], $content['period'], - $report["datetime"], true, - $filter_event_validated, - $filter_event_critical, - $filter_event_warning, - $filter_event_no_validated); - - if(!empty($data[0])) { - array_push ($table->data, $data); - - $table->colspan[$next_row][0] = 3; - $next_row++; - } - - - if ($event_graph_by_user_validator) { - $data_graph = reporting_get_count_events_validated_by_user( - array('id_agent' => $content['id_agent']), $content['period'], - $report["datetime"], - $filter_event_validated, - $filter_event_critical, - $filter_event_warning, - $filter_event_no_validated); - - $table_event_graph = null; - $table_event_graph->width = '100%'; - $table_event_graph->style[0] = 'text-align: center;'; - $table_event_graph->head[0] = __('Events validated by user'); - - $table_event_graph->data[0][0] = pie3d_graph( - false, $data_graph, 500, 150, __("other"), "", - ui_get_full_url(false, false, false, false) . "/images/logo_vertical_water.png", - $config['fontpath'], $config['font_size']); - - $data[0] = html_print_table($table_event_graph, true); - - $table->colspan[$next_row][0] = 3; - $next_row++; - array_push ($table->data, $data); - } - - if ($event_graph_by_criticity) { - $data_graph = reporting_get_count_events_by_criticity( - array('id_agent' => $content['id_agent']), $content['period'], - $report["datetime"], - $filter_event_validated, - $filter_event_critical, - $filter_event_warning, - $filter_event_no_validated); - - $colors = get_criticity_pie_colors($data_graph); - - $table_event_graph = null; - $table_event_graph->width = '100%'; - $table_event_graph->style[0] = 'text-align: center;'; - $table_event_graph->head[0] = __('Events by criticity'); - - $table_event_graph->data[0][0] = pie3d_graph( - false, $data_graph, 500, 150, __("other"), "", - ui_get_full_url(false, false, false, false) . "/images/logo_vertical_water.png", - $config['fontpath'], $config['font_size'], 1, false, $colors); - - $data[0] = html_print_table($table_event_graph, true); - - $table->colspan[$next_row][0] = 3; - $next_row++; - array_push ($table->data, $data); - } - - if ($event_graph_validated_vs_unvalidated) { - $data_graph = reporting_get_count_events_validated( - array('id_agent' => $content['id_agent']), $content['period'], - $report["datetime"], - $filter_event_validated, - $filter_event_critical, - $filter_event_warning, - $filter_event_no_validated); - - $table_event_graph = null; - $table_event_graph->width = '100%'; - $table_event_graph->style[0] = 'text-align: center;'; - $table_event_graph->head[0] = __('Amount events validated'); - - $table_event_graph->data[0][0] = pie3d_graph( - false, $data_graph, 500, 150, __("other"), "", - ui_get_full_url(false, false, false, false) . "/images/logo_vertical_water.png", - $config['fontpath'], $config['font_size']); - - $data[0] = html_print_table($table_event_graph, true); - - $table->colspan[$next_row][0] = 3; - $next_row++; - array_push ($table->data, $data); - } - break; case 'event_report_group': if (empty($item_title)) { @@ -4308,109 +4257,6 @@ function reporting_render_report_html_item ($content, $table, $report, $mini = f array_push ($table->data, $data); break; - case 'group_report': - $group_name = groups_get_name($content['id_group'], true); - $group_stats = reporting_get_group_stats($content['id_group']); - // Get events of the last 8 hours - $events = events_get_group_events ($content['id_group'], 28800, $report['datetime']); - - if ($events === false) { - $events = array(); - } - - if (empty($item_title)) { - $item_title = __('Group report').': "'.$group_name.'"'; - } - reporting_header_content($mini, $content, $report, $table, $item_title); - - $table->colspan[1][0] = 3; - - if ($content["description"] != "") { - $data_desc = array(); - $data_desc[0] = $content["description"]; - array_push ($table->data, $data_desc); - } - - $table->colspan[2][0] = 3; - - $table->data[2][0] = - " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
" . - __('Total') . "
" . - __('Unknown') . "
" . - __('Agents') . "
" . - $group_stats['total_agents'] . "
" . - $group_stats['agents_unknown'] . "
" . - __('Total') . "
" . - __('Normal') . "
" . - __('Critical') . "
" . - __('Warning') . "
" . - __('Unknown') . "
" . - __('Not init') . "
" . - __('Monitors') . "
" . - $group_stats['monitor_checks'] . "
" . - $group_stats['monitor_ok'] ."
" . - $group_stats['monitor_critical'] . "
" . - $group_stats['monitor_warning'] . "
" . - $group_stats['monitor_unknown'] . "
" . - $group_stats['monitor_not_init'] . "
" . - __('Defined') . "
" . - __('Fired') . "
" . - __('Alerts') . "
" . - $group_stats['monitor_alerts'] . "
" . - $group_stats['monitor_alerts_fired'] . "
" . - __('Last 8 hours') . "
" . - __('Events') . "
" . - count($events)."
"; - - break; - case 'top_n': $top_n = $content['top_n']; From 38ae50eb900f674cc96b1c141e30a767d9128d2f Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Wed, 22 Apr 2015 13:00:08 +0200 Subject: [PATCH 43/80] Working in the refactoring the code of reports (exception). --- .../include/functions_reporting.php | 400 ++++++++++++++- .../include/functions_reporting_html.php | 473 +++--------------- 2 files changed, 472 insertions(+), 401 deletions(-) diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index cf48d108fb..b7d2ad7e02 100644 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -374,12 +374,391 @@ function reporting_make_reporting_data($id_report, $date, $time, $report, $content); break; + case 'exception': + $report['contents'][] = reporting_exception( + $report, + $content, + $type, + $force_width_chart, + $force_height_chart); + break; } } return reporting_check_structure_report($report); } +function reporting_exception($report, $content, $type = 'dinamic', + $force_width_chart = null, $force_height_chart = null) { + global $config; + + $return['type'] = 'exception'; + + + if (empty($content['name'])) { + $content['name'] = __('Exception'); + } + + $return['title'] = $content['name']; + $exception_condition = $content['exception_condition']; + switch ($exception_condition) { + case REPORT_EXCEPTION_CONDITION_EVERYTHING: + $return['subtitle'] = __('Exception - Everything'); + break; + case REPORT_EXCEPTION_CONDITION_GE: + $return['subtitle'] = + sprintf(__('Exception - Modules over or equal to %s'), + $exception_condition_value); + break; + case REPORT_EXCEPTION_CONDITION_LE: + $return['subtitle'] = + sprintf(__('Exception - Modules under or equal to %s'), + $exception_condition_value); + break; + case REPORT_EXCEPTION_CONDITION_L: + $return['subtitle'] = + sprintf(__('Exception - Modules under %s'), + $exception_condition_value); + break; + case REPORT_EXCEPTION_CONDITION_G: + $return['subtitle'] = + sprintf(__('Exception - Modules over %s'), + $exception_condition_value); + break; + case REPORT_EXCEPTION_CONDITION_E: + $return['subtitle'] = + sprintf(__('Exception - Equal to %s'), + $exception_condition_value); + break; + case REPORT_EXCEPTION_CONDITION_NE: + $return['subtitle'] = + sprintf(__('Exception - Not equal to %s'), + $exception_condition_value); + break; + case REPORT_EXCEPTION_CONDITION_OK: + $return['subtitle'] = + __('Exception - Modules at normal status'); + break; + case REPORT_EXCEPTION_CONDITION_NOT_OK: + $return['subtitle'] = + __('Exception - Modules at critical or warning status'); + break; + } + $return["description"] = $content["description"]; + $return["date"] = reporting_get_date_text($report, $content); + + $return["data"] = array(); + $return["chart"] = array(); + $return["resume"] = array(); + + $order_uptodown = $content['order_uptodown']; + $exception_condition_value = $content['exception_condition_value']; + $show_graph = $content['show_graph']; + + //Get all the related data + $sql = sprintf(" + SELECT id_agent_module, server_name, operation + FROM treport_content_item + WHERE id_report_content = %d", $content['id_rc']); + + $exceptions = db_process_sql ($sql); + if ($exceptions === false) { + $return['failed'] = __('There are no Agent/Modules defined'); + } + else { + //Get the very first not null value + $i = 0; + do { + //Metaconsole connection + $server_name = $exceptions[$i]['server_name']; + if (($config ['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE')) { + $connection = metaconsole_get_connection($server_name); + if (metaconsole_load_external_db($connection) != NOERR) { + //ui_print_error_message ("Error connecting to ".$server_name); + continue; + } + } + + if ($content['period'] == 0) { + $min = + modules_get_last_value($exceptions[$i]['id_agent_module']); + } + else { + switch ($exceptions[$i]['operation']) { + case 'avg': + $min = reporting_get_agentmodule_data_average( + $exceptions[$i]['id_agent_module'], $content['period']); + break; + case 'max': + $min = reporting_get_agentmodule_data_max( + $exceptions[$i]['id_agent_module'], $content['period']); + break; + case 'min': + $min = reporting_get_agentmodule_data_min( + $exceptions[$i]['id_agent_module'], $content['period']); + break; + } + } + $i++; + + //Restore dbconnection + if (($config ['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE')) { + metaconsole_restore_db(); + } + } + while ($min === false && $i < count($exceptions)); + $max = $min; + $avg = 0; + + + $i = 0; + foreach ($exceptions as $exc) { + //Metaconsole connection + $server_name = $exc['server_name']; + if (($config ['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE')) { + $connection = metaconsole_get_connection($server_name); + if (metaconsole_load_external_db($connection) != NOERR) { + //ui_print_error_message ("Error connecting to ".$server_name); + continue; + } + } + + $ag_name = modules_get_agentmodule_agent_name ($exc ['id_agent_module']); + $mod_name = modules_get_agentmodule_name ($exc ['id_agent_module']); + $unit = db_get_value('unit', 'tagente_modulo', + 'id_agente_modulo', $exc['id_agent_module']); + + if ($content['period'] == 0) { + $value = + modules_get_last_value($exceptions[$i]['id_agent_module']); + } + else { + switch ($exc['operation']) { + case 'avg': + $value = reporting_get_agentmodule_data_average ($exc['id_agent_module'], $content['period']); + break; + case 'max': + $value = reporting_get_agentmodule_data_max ($exc['id_agent_module'], $content['period']); + break; + case 'min': + $value = reporting_get_agentmodule_data_min ($exc['id_agent_module'], $content['period']); + break; + } + } + + if ($value !== false) { + if ($value > $max) $max = $value; + if ($value < $min) $min = $value; + $avg += $value; + + //Skips + switch ($exception_condition) { + case REPORT_EXCEPTION_CONDITION_EVERYTHING: + break; + case REPORT_EXCEPTION_CONDITION_GE: + if ($value < $exception_condition_value) { + continue 2; + } + break; + case REPORT_EXCEPTION_CONDITION_LE: + if ($value > $exception_condition_value) { + continue 2; + } + break; + case REPORT_EXCEPTION_CONDITION_L: + if ($value > $exception_condition_value) { + continue 2; + } + break; + case REPORT_EXCEPTION_CONDITION_G: + if ($value < $exception_condition_value) { + continue 2; + } + break; + case REPORT_EXCEPTION_CONDITION_E: + if ($value != $exception_condition_value) { + continue 2; + } + break; + case REPORT_EXCEPTION_CONDITION_NE: + if ($value == $exception_condition_value) { + continue 2; + } + break; + case REPORT_EXCEPTION_CONDITION_OK: + if (modules_get_agentmodule_status($exc['id_agent_module']) != 0) { + continue 2; + } + break; + case REPORT_EXCEPTION_CONDITION_NOT_OK: + if (modules_get_agentmodule_status($exc['id_agent_module']) == 0) { + continue 2; + } + break; + } + + $i++; + $data_exceptions[] = $value; + $id_agent_module[] = $exc['id_agent_module']; + $agent_name[] = $ag_name; + $module_name[] = $mod_name; + $units[] = $unit; + if ($exc['operation'] == 'avg') { + $operation[] = "rate"; + } + else { + $operation[] = $exc['operation']; + } + } + //Restore dbconnection + if (($config ['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE')) { + metaconsole_restore_db(); + } + } + + if ($i == 0) { + switch ($exception_condition) { + case REPORT_EXCEPTION_CONDITION_EVERYTHING: + $return['failed'] = __('There are no Modules under those conditions.'); + break; + case REPORT_EXCEPTION_CONDITION_GE: + $return['failed'] = __('There are no Modules over or equal to %s.', $exception_condition_value); + break; + case REPORT_EXCEPTION_CONDITION_LE: + $return['failed'] = __('There are no Modules less or equal to %s.', $exception_condition_value); + break; + case REPORT_EXCEPTION_CONDITION_L: + $return['failed'] = __('There are no Modules less %s.', $exception_condition_value); + break; + case REPORT_EXCEPTION_CONDITION_G: + $return['failed'] = __('There are no Modules over %s.', $exception_condition_value); + break; + case REPORT_EXCEPTION_CONDITION_E: + $return['failed'] = __('There are no Modules equal to %s', $exception_condition_value); + break; + case REPORT_EXCEPTION_CONDITION_NE: + $return['failed'] = __('There are no Modules not equal to %s', $exception_condition_value); + break; + case REPORT_EXCEPTION_CONDITION_OK: + $return['failed'] = __('There are no Modules normal status'); + break; + case REPORT_EXCEPTION_CONDITION_NOT_OK: + $return['failed'] = __('There are no Modules at critial or warning status'); + break; + } + + } + else { + $avg = $avg / $i; + + switch ($order_uptodown) { + //Order descending + case 1: + array_multisort($data_exceptions, SORT_DESC, + $agent_name, SORT_ASC, $module_name, SORT_ASC, + $id_agent_module, SORT_ASC); + break; + //Order ascending + case 2: + array_multisort($data_exceptions, SORT_ASC, + $agent_name, SORT_ASC, $module_name, SORT_ASC, + $id_agent_module, SORT_ASC); + break; + //Order by agent name or without selection + case 0: + case 3: + array_multisort($agent_name, SORT_ASC, + $data_exceptions, SORT_ASC, $module_name, + SORT_ASC, $id_agent_module, SORT_ASC); + break; + } + + if ($order_uptodown == 1 || $order_uptodown == 2) { + $j = 0; + $data_pie_graph = array(); + $data_hbar = array(); + foreach ($data_exceptions as $dex) { + $data_hbar[$agent_name[$j]]['g'] = $dex; + $data_pie_graph[$agent_name[$j]] = $dex; + if ($show_graph == 0 || $show_graph == 1) { + $data = array(); + $data['agent'] = $agent_name[$j]; + $data['module'] = $module_name[$j]; + $data['operation'] = __($operation[$j]); + $data['value'] = $dex; + $data['formated_value'] = format_for_graph($dex, 2) . " " . $units[$j]; + $return['data'][] = $data; + } + $j++; + } + } + else if ($order_uptodown == 0 || $order_uptodown == 3) { + $j = 0; + $data_pie_graph = array(); + $data_hbar = array(); + foreach ($agent_name as $an) { + $data_hbar[$an]['g'] = $data_exceptions[$j]; + $data_pie_graph[$an] = $data_exceptions[$j]; + if ($show_graph == 0 || $show_graph == 1) { + $data = array(); + $data['agent'] = $an; + $data['module'] = $module_name[$j]; + $data['operation'] = __($operation[$j]); + $data['value'] = $data_exceptions[$j]; + $data['formated_value'] = format_for_graph($data_exceptions[$j], 2) . " " . $units[$j]; + $return['data'][] = $data; + } + $j++; + } + } + + if ($show_graph == 1 || $show_graph == 2) { + + + reporting_set_conf_charts($width, $height, $only_image, + $type, $content, $ttl); + + if (!empty($force_width_chart)) { + $width = $force_width_chart; + } + + if (!empty($force_height_chart)) { + $height = $force_height_chart; + } + + + $return["chart"]["pie"] = pie3d_graph(false, $data_pie_graph, + 600, 150, __("other"), + ui_get_full_url(false, false, false, false), + ui_get_full_url(false, false, false, false) . "/images/logo_vertical_water.png", + $config['fontpath'], $config['font_size']); + $return["chart"]["hbar"] = hbar_graph(false, + $data_hbar, 600, $height, + array(), array(), "", "", true, + ui_get_full_url(false, false, false, false), + ui_get_full_url(false, false, false, false) . "/images/logo_vertical_water.png", '', '', true, 1, true); + } + + + + if ($content['show_resume'] && $i > 0) { + $return["resume"]['min']['value'] = $min; + $return["resume"]['min']['formated_value'] = format_for_graph($min,2); + $return["resume"]['max']['value'] = $max; + $return["resume"]['max']['formated_value'] = format_for_graph($max,2); + $return["resume"]['avg']['value'] = $avg; + $return["resume"]['avg']['formated_value'] = format_for_graph($avg,2); + } + + + } + + } + + + return reporting_check_structure_content($return); +} + function reporting_group_report($report, $content) { global $config; @@ -1086,7 +1465,8 @@ function reporting_sql_graph($report, $content, $type, } // Get chart - reporting_set_conf_charts($width, $height, $only_image, $type, $content); + reporting_set_conf_charts($width, $height, $only_image, $type, + $content, $ttl); if (!empty($force_width_chart)) { $width = $force_width_chart; @@ -1203,7 +1583,8 @@ function reporting_netflow($report, $content, $type, $return["date"] = reporting_get_date_text($report, $content); // Get chart - reporting_set_conf_charts($width, $height, $only_image, $type, $content); + reporting_set_conf_charts($width, $height, $only_image, $type, + $content, $ttl); if (!empty($force_width_chart)) { $width = $force_width_chart; @@ -1255,7 +1636,8 @@ function reporting_simple_baseline_graph($report, $content, $return["date"] = reporting_get_date_text($report, $content); // Get chart - reporting_set_conf_charts($width, $height, $only_image, $type, $content); + reporting_set_conf_charts($width, $height, $only_image, $type, + $content, $ttl); if (!empty($force_width_chart)) { $width = $force_width_chart; @@ -1352,7 +1734,8 @@ function reporting_projection_graph($report, $content, } // Get chart - reporting_set_conf_charts($width, $height, $only_image, $type, $content); + reporting_set_conf_charts($width, $height, $only_image, $type, + $content, $ttl); if (!empty($force_width_chart)) { $width = $force_width_chart; @@ -2273,7 +2656,8 @@ function reporting_custom_graph($report, $content, $type = 'dinamic', $return['chart'] = ''; // Get chart - reporting_set_conf_charts($width, $height, $only_image, $type, $content); + reporting_set_conf_charts($width, $height, $only_image, $type, + $content, $ttl); $height += count($modules) * REPORTING_CUSTOM_GRAPH_LEGEND_EACH_MODULE_VERTICAL_SIZE; @@ -2342,7 +2726,8 @@ function reporting_simple_graph($report, $content, $type = 'dinamic', $return['chart'] = ''; // Get chart - reporting_set_conf_charts($width, $height, $only_image, $type, $content); + reporting_set_conf_charts($width, $height, $only_image, $type, + $content, $ttl); if (!empty($force_width_chart)) { $width = $force_width_chart; @@ -2478,7 +2863,8 @@ function reporting_check_structure_content($report) { return $report; } -function reporting_set_conf_charts(&$width, &$height, &$only_image, $type, $content, &$ttl) { +function reporting_set_conf_charts(&$width, &$height, &$only_image, $type, + $content, &$ttl) { switch ($type) { case 'dinamic': $only_image = false; diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index b00b44e41f..8ca00e1c61 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -234,6 +234,9 @@ function reporting_html_print_report($report, $mini = false) { case 'group_report': reporting_html_group_report($table, $item); break; + case 'exception': + reporting_html_exception($table, $item); + break; } if ($item['type'] == 'agent_module') @@ -246,6 +249,81 @@ function reporting_html_print_report($report, $mini = false) { } } +function reporting_html_exception($table, $item) { + + if (!empty($item['failed'])) { + $table->colspan['group_report']['cell'] = 3; + $table->cellstyle['group_report']['cell'] = 'text-align: center;'; + $table->data['event_list']['cell'] = $item['failed']; + } + else { + $table1->width = '99%'; + + $table1->align = array(); + $table1->align['agent'] = 'left'; + $table1->align['module'] = 'left'; + $table1->align['operation'] = 'left'; + $table1->align['value'] = 'right'; + + $table1->data = array (); + + $table1->head = array (); + $table1->head['agent'] = __('Agent'); + $table1->head['module'] = __('Module'); + $table1->head['operation'] = __('Operation'); + $table1->head['value'] = __('Value'); + + foreach ($item['data'] as $data) { + $row = array(); + $row['agent'] = $data['agent']; + $row['module'] = $data['module']; + $row['operation'] = $data['operation']; + $row['value'] = $data['formated_value']; + + $table1->data[] = $row; + } + + $table->colspan['data']['cell'] = 3; + $table->cellstyle['data']['cell'] = 'text-align: center;'; + $table->data['data']['cell'] = html_print_table($table1, true); + + if (!empty($item['chart'])) { + $table->colspan['chart_pie']['cell'] = 3; + $table->cellstyle['chart_pie']['cell'] = 'text-align: center;'; + $table->data['chart_pie']['cell'] = $item["chart"]["pie"]; + + $table->colspan['chart_hbar']['cell'] = 3; + $table->cellstyle['chart_hbar']['cell'] = 'text-align: center;'; + $table->data['chart_hbar']['cell'] = $item["chart"]["hbar"]; + } + + if (!empty($item['resume'])) { + $table1 = null; + $table1->width = '99%'; + + $table1->align = array(); + $table1->align['min'] = 'right'; + $table1->align['avg'] = 'right'; + $table1->align['max'] = 'right'; + + $table1->head = array (); + $table1->head['min'] = __('Min Value'); + $table1->head['avg'] = __('Average Value'); + $table1->head['max'] = __('Max Value'); + + $table1->data = array (); + $table1->data[] = array( + 'min' => $item['resume']['min']['formated_value'], + 'avg' => $item['resume']['avg']['formated_value'], + 'max' => $item['resume']['max']['formated_value']); + + $table->colspan['resume']['cell'] = 3; + $table->cellstyle['resume']['cell'] = 'text-align: center;'; + $table->data['resume']['cell'] = html_print_table($table1, true); + } + } +} + function reporting_html_group_report($table, $item) { global $config; @@ -4591,400 +4669,7 @@ function reporting_render_report_html_item ($content, $table, $report, $mini = f array_push ($table->data, array(html_print_table($table_summary, true))); } break; - case 'exception': - $order_uptodown = $content['order_uptodown']; - $exception_condition = $content['exception_condition']; - $exception_condition_value = $content['exception_condition_value']; - $show_graph = $content['show_graph']; - - $table->style[1] = 'text-align: right'; - - switch ($exception_condition) { - case REPORT_EXCEPTION_CONDITION_EVERYTHING: - $title_exeption = __('Exception - Everything'); - break; - case REPORT_EXCEPTION_CONDITION_GE: - $title_exeption = - sprintf(__('Exception - Modules over or equal to %s'), - $exception_condition_value); - break; - case REPORT_EXCEPTION_CONDITION_LE: - $title_exeption = - sprintf(__('Exception - Modules under or equal to %s'), - $exception_condition_value); - break; - case REPORT_EXCEPTION_CONDITION_L: - $title_exeption = - sprintf(__('Exception - Modules under %s'), - $exception_condition_value); - break; - case REPORT_EXCEPTION_CONDITION_G: - $title_exeption = - sprintf(__('Exception - Modules over %s'), - $exception_condition_value); - break; - case REPORT_EXCEPTION_CONDITION_E: - $title_exeption = - sprintf(__('Exception - Equal to %s'), - $exception_condition_value); - break; - case REPORT_EXCEPTION_CONDITION_NE: - $title_exeption = - sprintf(__('Exception - Not equal to %s'), - $exception_condition_value); - break; - case REPORT_EXCEPTION_CONDITION_OK: - $title_exeption = - __('Exception - Modules at normal status'); - break; - case REPORT_EXCEPTION_CONDITION_NOT_OK: - $title_exeption = - __('Exception - Modules at critical or warning status'); - break; - } - - if (empty($item_title)) { - $item_title = $title_exeption; - } - reporting_header_content($mini, $content, $report, $table, $item_title); - - // Put description at the end of the module (if exists) - $table->colspan[1][0] = 3; - if ($content["description"] != "") { - $data_desc = array(); - $data_desc[0] = $content["description"]; - array_push ($table->data, $data_desc); - } - //Get all the related data - $sql = sprintf(" - SELECT id_agent_module, server_name, operation - FROM treport_content_item - WHERE id_report_content = %d", $content['id_rc']); - - $exceptions = db_process_sql ($sql); - if ($exceptions === false) { - $data = array (); - $table->colspan[2][0] = 3; - $data[0] = __('There are no Agent/Modules defined'); - array_push ($table->data, $data); - break; - } - - if ($show_graph == 0 || $show_graph == 1) { - $table1->width = '99%'; - $table1->data = array (); - $table1->head = array (); - $table1->head[0] = __('Agent'); - $table1->head[1] = __('Module'); - $table1->head[2] = __('Operation'); - $table1->head[3] = __('Value'); - $table1->style[0] = 'text-align: left'; - $table1->style[1] = 'text-align: left'; - $table1->style[2] = 'text-align: left'; - $table1->style[3] = 'text-align: left'; - } - - //Get the very first not null value - $i=0; - do { - //Metaconsole connection - $server_name = $exceptions[$i]['server_name']; - if (($config ['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE')) { - $connection = metaconsole_get_connection($server_name); - if (metaconsole_load_external_db($connection) != NOERR) { - //ui_print_error_message ("Error connecting to ".$server_name); - continue; - } - } - - if ($content['period'] == 0) { - $min = - modules_get_last_value($exceptions[$i]['id_agent_module']); - } - else { - switch ($exceptions[$i]['operation']) { - case 'avg': - $min = reporting_get_agentmodule_data_average( - $exceptions[$i]['id_agent_module'], $content['period']); - break; - case 'max': - $min = reporting_get_agentmodule_data_max( - $exceptions[$i]['id_agent_module'], $content['period']); - break; - case 'min': - $min = reporting_get_agentmodule_data_min( - $exceptions[$i]['id_agent_module'], $content['period']); - break; - } - } - $i++; - - //Restore dbconnection - if (($config ['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE')) { - metaconsole_restore_db(); - } - } - while ($min === false && $i < count($exceptions)); - $max = $min; - $avg = 0; - - $i=0; - foreach ($exceptions as $exc) { - //Metaconsole connection - $server_name = $exc['server_name']; - if (($config ['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE')) { - $connection = metaconsole_get_connection($server_name); - if (metaconsole_load_external_db($connection) != NOERR) { - //ui_print_error_message ("Error connecting to ".$server_name); - continue; - } - } - - $ag_name = modules_get_agentmodule_agent_name ($exc ['id_agent_module']); - $mod_name = modules_get_agentmodule_name ($exc ['id_agent_module']); - $unit = db_get_value('unit', 'tagente_modulo', - 'id_agente_modulo', $exc['id_agent_module']); - - if ($content['period'] == 0) { - $value = - modules_get_last_value($exceptions[$i]['id_agent_module']); - } - else { - switch ($exc['operation']) { - case 'avg': - $value = reporting_get_agentmodule_data_average ($exc['id_agent_module'], $content['period']); - break; - case 'max': - $value = reporting_get_agentmodule_data_max ($exc['id_agent_module'], $content['period']); - break; - case 'min': - $value = reporting_get_agentmodule_data_min ($exc['id_agent_module'], $content['period']); - break; - } - } - - if ($value !== false) { - if ($value > $max) $max = $value; - if ($value < $min) $min = $value; - $avg += $value; - - //Skips - switch ($exception_condition) { - case REPORT_EXCEPTION_CONDITION_EVERYTHING: - break; - case REPORT_EXCEPTION_CONDITION_GE: - if ($value < $exception_condition_value) { - continue 2; - } - break; - case REPORT_EXCEPTION_CONDITION_LE: - if ($value > $exception_condition_value) { - continue 2; - } - break; - case REPORT_EXCEPTION_CONDITION_L: - if ($value > $exception_condition_value) { - continue 2; - } - break; - case REPORT_EXCEPTION_CONDITION_G: - if ($value < $exception_condition_value) { - continue 2; - } - break; - case REPORT_EXCEPTION_CONDITION_E: - if ($value != $exception_condition_value) { - continue 2; - } - break; - case REPORT_EXCEPTION_CONDITION_NE: - if ($value == $exception_condition_value) { - continue 2; - } - break; - case REPORT_EXCEPTION_CONDITION_OK: - if (modules_get_agentmodule_status($exc['id_agent_module']) != 0) { - continue 2; - } - break; - case REPORT_EXCEPTION_CONDITION_NOT_OK: - if (modules_get_agentmodule_status($exc['id_agent_module']) == 0) { - continue 2; - } - break; - } - - $i++; - $data_exceptions[] = $value; - $id_agent_module[] = $exc['id_agent_module']; - $agent_name[] = $ag_name; - $module_name[] = $mod_name; - $units[] = $unit; - if ($exc['operation'] == 'avg') { - $operation[] = "rate"; - } - else { - $operation[] = $exc['operation']; - } - } - //Restore dbconnection - if (($config ['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE')) { - metaconsole_restore_db(); - } - } - - //$i <= 0 means that there are no rows on the table, therefore no modules under the conditions defined. - if ($i <= 0) { - $data = array (); - $table->colspan[2][0] = 3; - $data[0] = __('There are no'); - - switch ($exception_condition) { - case REPORT_EXCEPTION_CONDITION_EVERYTHING: - $data[0] .= ' '.__('Modules under those conditions'); - break; - case REPORT_EXCEPTION_CONDITION_GE: - $data[0] .= ' '.__('Modules over or equal to').' '.$exception_condition_value; - break; - case REPORT_EXCEPTION_CONDITION_LE: - $data[0] .= ' '.__('Modules less or equal to').' '.$exception_condition_value; - break; - case REPORT_EXCEPTION_CONDITION_L: - $data[0] .= ' '.__('Modules less').' '.$exception_condition_value; - break; - case REPORT_EXCEPTION_CONDITION_G: - $data[0] .= ' '.__('Modules over').' '.$exception_condition_value; - break; - case REPORT_EXCEPTION_CONDITION_E: - $data[0] .= ' '.__('Modules equal to').' '.$exception_condition_value; - break; - case REPORT_EXCEPTION_CONDITION_NE: - $data[0] .= ' '.__('Modules not equal to').' '.$exception_condition_value; - break; - case REPORT_EXCEPTION_CONDITION_OK: - $data[0] .= ' '.__('Modules normal status'); - break; - case REPORT_EXCEPTION_CONDITION_NOT_OK: - $data[0] .= ' '.__('Modules at critial or warning status'); - break; - } - - - array_push ($table->data, $data); - break; - } - //$i > 0 means that there is at least one row on the table - elseif ($i > 0) { - $avg = $avg / $i; - - switch ($order_uptodown) { - //Order descending - case 1: - array_multisort($data_exceptions, SORT_DESC, $agent_name, SORT_ASC, $module_name, SORT_ASC, $id_agent_module, SORT_ASC); - break; - //Order ascending - case 2: - array_multisort($data_exceptions, SORT_ASC, $agent_name, SORT_ASC, $module_name, SORT_ASC, $id_agent_module, SORT_ASC); - break; - //Order by agent name or without selection - case 0: - case 3: - array_multisort($agent_name, SORT_ASC, $data_exceptions, SORT_ASC, $module_name, SORT_ASC, $id_agent_module, SORT_ASC); - break; - } - - if ($order_uptodown == 1 || $order_uptodown == 2) { - $j = 0; - $data_pie_graph = array(); - $data_hbar = array(); - foreach ($data_exceptions as $dex) { - $data_hbar[$agent_name[$j]]['g'] = $dex; - $data_pie_graph[$agent_name[$j]] = $dex; - if ($show_graph == 0 || $show_graph == 1) { - $data = array(); - $data[0] = $agent_name[$j]; - $data[1] = $module_name[$j]; - $data[2] = __($operation[$j]); - $data[3] = format_for_graph($dex, 2) . " " . $units[$j]; - array_push ($table1->data, $data); - } - $j++; - } - } - else if ($order_uptodown == 0 || $order_uptodown == 3) { - $j = 0; - $data_pie_graph = array(); - $data_hbar = array(); - foreach ($agent_name as $an) { - $data_hbar[$an]['g'] = $data_exceptions[$j]; - $data_pie_graph[$an] = $data_exceptions[$j]; - if ($show_graph == 0 || $show_graph == 1) { - $data = array(); - $data[0] = $an; - $data[1] = $module_name[$j]; - $data[2] = __($operation[$j]); - $data[3] = format_for_graph($data_exceptions[$j], 2) . " " . $units[$j]; - array_push ($table1->data, $data); - } - $j++; - } - } - } - - $table->colspan[2][0] = 3; - $table->cellstyle[2][0] = 'text-align: center;'; - if ($show_graph == 0 || $show_graph == 1) { - $data = array(); - $data[0] = html_print_table($table1, true); - array_push ($table->data, $data); - } - - $table->colspan[3][0] = 3; - $table->cellstyle[3][0] = 'text-align: center;'; - - $data = array(); - if ($show_graph == 1 || $show_graph == 2) { - $data[0] = pie3d_graph(false, $data_pie_graph, - 600, 150, __("other"), - ui_get_full_url(false, false, false, false), - ui_get_full_url(false, false, false, false) . "/images/logo_vertical_water.png", - $config['fontpath'], $config['font_size']); - array_push ($table->data, $data); - //Display bars graph - $table->colspan[4][0] = 3; - $table->cellstyle[4][0] = 'text-align: center;'; - $height = count($data_pie_graph) * 20 + 85; - $data = array(); - - $data[0] = hbar_graph(false, $data_hbar, 600, $height, - array(), array(), "", "", true, - ui_get_full_url(false, false, false, false), - ui_get_full_url(false, false, false, false) . "/images/logo_vertical_water.png", '', '', true, 1, true); - - array_push ($table->data, $data); - } - - if ($content['show_resume'] && $i>0) { - unset($table_summary); - - $table_summary->width = '99%'; - $table_summary->data = array (); - $table_summary->head = array (); - $table_summary->head[0] = __('Min Value'); - $table_summary->head[1] = __('Average Value'); - $table_summary->head[2] = __('Max Value'); - - $table_summary->data[0][0] = format_for_graph($min,2); - $table_summary->data[0][1] = format_for_graph($avg,2); - $table_summary->data[0][2] = format_for_graph($max,2); - - $table->colspan[5][0] = 3; - $table->cellstyle[5][0] = 'text-align: center;'; - array_push ($table->data, array(''.__('Summary').'')); - $table->colspan[6][0] = 3; - array_push ($table->data, array(html_print_table($table_summary, true))); - } - break; + case 'agent_module': $group_name = groups_get_name($content['id_group']); if ($content['id_module_group'] == 0) { From 201e4dcd8a2ced249e0c15e8ef936c00e1f4b9f7 Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Wed, 22 Apr 2015 16:32:24 +0200 Subject: [PATCH 44/80] Working in the refactoring the code of reports (agent_module). --- .../include/functions_reporting.php | 101 +++++ .../include/functions_reporting_html.php | 345 +++++++----------- 2 files changed, 240 insertions(+), 206 deletions(-) diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index b7d2ad7e02..4478cb963d 100644 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -382,12 +382,113 @@ function reporting_make_reporting_data($id_report, $date, $time, $force_width_chart, $force_height_chart); break; + case 'agent_module': + $report['contents'][] = reporting_agent_module( + $report, + $content); + break; } } return reporting_check_structure_report($report); } +function reporting_agent_module($report, $content) { + global $config; + + $id_group = $content['id_group']; + $id_module_group = $content['id_module_group']; + + $return['type'] = 'agent_module'; + + + if (empty($content['name'])) { + $content['name'] = __('Agent/Modules'); + } + + $return['title'] = $content['name']; + $group_name = groups_get_name($content['id_group'], true); + if ($content['id_module_group'] == 0) { + $module_group_name = __('All'); + } + else { + $module_group_name = db_get_value('name', 'tmodule_group', + 'id_mg', $content['id_module_group']); + } + $return['subtitle'] = $group_name . " - " . $module_group_name; + $return["description"] = $content["description"]; + $return["date"] = reporting_get_date_text($report, $content); + + $return["data"] = array(); + + $agents = array(); + if ($id_group > 0) { + $agents = agents_get_group_agents($id_group); + $agents = array_keys($agents); + } + + $filter_module_groups = false; + if ($id_module_group > 0) { + $filter_module_groups['id_module_group'] = $id_module_group; + } + + $all_modules = agents_get_modules($agents, false, + $filter_module_groups, true, false); + + $modules_by_name = array(); + $name = ''; + $cont = 0; + + foreach ($all_modules as $key => $module) { + if ($module == $name) { + $modules_by_name[$cont - 1]['id'][] = $key; + } + else { + $name = $module; + $modules_by_name[$cont]['name'] = $name; + $modules_by_name[$cont]['id'][] = $key; + $cont ++; + } + } + + $filter_groups = array(); + if ($id_group > 0) { + $filter_groups['id_grupo'] = $id_group; + } + $agents = agents_get_agents ($filter_groups); + $nagents = count($agents); + + if ($all_modules == false || $agents == false) { + $return['failed'] = __('There are no agents with modules'); + } + else { + foreach ($agents as $agent) { + $row = array(); + $row['agent_status'][$agent['id_agente']] = + agents_get_status($agent['id_agente']); + $row['agent_name'] = $agent['nombre']; + + $agent_modules = agents_get_modules($agent['id_agente']); + + $row['modules'] = array(); + foreach ($modules_by_name as $module) { + $row['modules'][$module['name']] = null; + foreach ($module['id'] as $module_id) { + if (array_key_exists($module_id, $agent_modules)) { + $row['modules'][$module['name']] = + modules_get_agentmodule_status($module_id); + break; + } + } + } + + $return['data'][] = $row; + } + } + + return reporting_check_structure_content($return); +} + function reporting_exception($report, $content, $type = 'dinamic', $force_width_chart = null, $force_height_chart = null) { global $config; diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index 8ca00e1c61..a516412760 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -237,6 +237,9 @@ function reporting_html_print_report($report, $mini = false) { case 'exception': reporting_html_exception($table, $item); break; + case 'agent_module': + reporting_html_agent_module($table, $item); + break; } if ($item['type'] == 'agent_module') @@ -249,12 +252,147 @@ function reporting_html_print_report($report, $mini = false) { } } +function reporting_html_agent_module($table, $item) { + $table->colspan['agent_module']['cell'] = 3; + $table->cellstyle['agent_module']['cell'] = 'text-align: center;'; + + if (!empty($item['failed'])) { + $table->data['agent_module']['cell'] = $item['failed']; + } + else { + $table_data = ''; + + $table_data .= ""; + + + $first = reset($item['data']); + $list_modules = $first['modules']; + + foreach ($list_modules as $module_name => $module) { + $file_name = string2image( + ui_print_truncate_text($module_name, 'module_small', + false, true, false, '...'), + false, false, 6, 270, '#B1B1B1', 'FFF', 4, 0); + $table_data .= '"; + } + + foreach ($item['data'] as $row) { + $table_data .= ""; + switch ($row['agent_status']) { + case 4: // Alert fired status + $rowcolor = COL_ALERTFIRED; + $textcolor = '#000'; + break; + case 1: // Critical status + $rowcolor = COL_CRITICAL; + $textcolor = '#FFF'; + break; + case 2: // Warning status + $rowcolor = COL_WARNING; + $textcolor = '#000'; + break; + case 0: // Normal status + $rowcolor = COL_NORMAL; + $textcolor = '#FFF'; + break; + case 3: + case -1: + default: // Unknown status + $rowcolor = COL_UNKNOWN; + $textcolor = '#FFF'; + break; + } + + $file_name = string2image( + ui_print_truncate_text($row['agent_name'], 'agent_small', + false, true, false, '...'), + false, false, 6, 0, $rowcolor, $textcolor, 4, 0); + $table_data .= ""; + + foreach ($row['modules'] as $module) { + if (is_null($module)) { + $table_data .= ""; + } + else { + $table_data .= ""; + } + + } + } + + $table_data .= "
" . __("Agents") . " / " . __("Modules") . "' . + html_print_image($file_name, true, + array('title' => $module_name)) . + "
" . + html_print_image($file_name, true, + array('title' => $row['agent_name'])) . ""; + switch ($module) { + case 0: + $table_data .= ui_print_status_image( + 'module_ok.png', + __("%s in %s : NORMAL", + $module['name'], + $row['agent_name']), + true, array('width' => '20px', 'height' => '20px')); + break; + case 1: + $table_data .= ui_print_status_image( + 'module_critical.png', + __("%s in %s : CRITICAL", + $module['name'], + $row['agent_name']), + true, array('width' => '20px', 'height' => '20px')); + break; + case 2: + $table_data .= ui_print_status_image( + 'module_warning.png', + __("%s in %s : WARNING", + $module['name'], + $row['agent_name']), + true, array('width' => '20px', 'height' => '20px')); + break; + case 3: + $table_data .= ui_print_status_image( + 'module_unknown.png', + __("%s in %s : UNKNOWN", + $module['name'], + $row['agent_name']), + true, array('width' => '20px', 'height' => '20px')); + break; + case 4: + $table_data .= ui_print_status_image( + 'module_alertsfired.png', + __("%s in %s : ALERTS FIRED", + $module['name'], + $row['agent_name']), + true, array('width' => '20px', 'height' => '20px')); + break; + } + $table_data .= "
"; + + $table_data .= "
"; + + $table_data .= ""; + $table_data .= ""; + $table_data .= ""; + $table_data .= ""; + $table_data .= ""; + $table_data .= ""; + $table_data .= ""; + $table_data .= "
" . __('Legend') . "
" . __("Orange cell when the module has fired alerts") . "
" . __("Red cell when the module has a critical status") . "
" . __("Yellow cell when the module has a warning status") . "
" . __("Green cell when the module has a normal status") . "
" . __("Grey cell when the module has an unknown status") . "
"; + $table_data .= "
"; + + + $table->data['agent_module']['cell'] = $table_data; + } +} + function reporting_html_exception($table, $item) { if (!empty($item['failed'])) { $table->colspan['group_report']['cell'] = 3; $table->cellstyle['group_report']['cell'] = 'text-align: center;'; - $table->data['event_list']['cell'] = $item['failed']; + $table->data['group_report']['cell'] = $item['failed']; } else { $table1->width = '99%'; @@ -4670,211 +4808,6 @@ function reporting_render_report_html_item ($content, $table, $report, $mini = f } break; - case 'agent_module': - $group_name = groups_get_name($content['id_group']); - if ($content['id_module_group'] == 0) { - $module_group_name = __('All'); - } - else { - $module_group_name = db_get_value('name', 'tmodule_group', - 'id_mg', $content['id_module_group']); - } - - if (empty($item_title)) { - $item_title = __('Agents/Modules'); - } - reporting_header_content($mini, $content, $report, $table, $item_title, - $group_name . ' - ' . $module_group_name); - - $id_group = $content['id_group']; - $id_module_group = $content['id_module_group']; - $offset = get_parameter('offset', 0); - $block = 20; //Maximun number of modules displayed on the table - $modulegroup = get_parameter('modulegroup', 0); - $table->style[1] = 'text-align: right'; - - // Put description at the end of the module (if exists) - $table->colspan[1][0] = 3; - if ($content["description"] != "") { - $data_desc = array(); - $data_desc[0] = $content["description"]; - array_push ($table->data, $data_desc); - } - - $agents = ''; - if ($id_group > 0) { - $agents = agents_get_group_agents($id_group); - $agents = array_keys($agents); - } - - $filter_module_groups = false; - if ($id_module_group > 0) { - $filter_module_groups['id_module_group'] = $id_module_group; - } - - $all_modules = agents_get_modules ($agents, false, $filter_module_groups, true, false); - - $modules_by_name = array(); - $name = ''; - $cont = 0; - - foreach ($all_modules as $key => $module) { - if ($module == $name) { - $modules_by_name[$cont-1]['id'][] = $key; - } - else { - $name = $module; - $modules_by_name[$cont]['name'] = $name; - $modules_by_name[$cont]['id'][] = $key; - $cont ++; - } - } - - if ($config["pure"] == 1) { - $block = count($modules_by_name); - } - - $filter_groups = array ('offset' => (int) $offset, - 'limit' => (int) $config['block_size']); - - if ($id_group > 0) { - $filter_groups['id_grupo'] = $id_group; - } - - $agents = agents_get_agents ($filter_groups); - $nagents = count($agents); - - if ($all_modules == false || $agents == false) { - $data = array (); - $table->colspan[2][0] = 3; - $data[0] = __('There are no agents with modules'); - array_push ($table->data, $data); - break; - } - $table_data = ''; - - $table_data .= ""; - - $nmodules = 0; - foreach ($modules_by_name as $module) { - $nmodules++; - - $file_name = string2image(ui_print_truncate_text($module['name'], 'module_small', false, true, false, '...'), false, false, 6, 270, '#B1B1B1', 'FFF', 4, 0); - $table_data .= '"; - } - // Dont use pagination - /*if ($block < $nmodules) { - $table_data .= ""; - }*/ - - $filter_agents = false; - if ($id_group > 0) { - $filter_agents = array('id_grupo' => $id_group); - } - // Prepare pagination - ui_pagination ((int)count(agents_get_agents ($filter_agents))); - $table_data .= "
"; - - foreach ($agents as $agent) { - // Get stats for this group - $agent_status = agents_get_status($agent['id_agente']); - - switch($agent_status) { - case 4: // Alert fired status - $rowcolor = COL_ALERTFIRED; - $textcolor = '#000'; - break; - case 1: // Critical status - $rowcolor = COL_CRITICAL; - $textcolor = '#FFF'; - break; - case 2: // Warning status - $rowcolor = COL_WARNING; - $textcolor = '#000'; - break; - case 0: // Normal status - $rowcolor = COL_NORMAL; - $textcolor = '#FFF'; - break; - case 3: - case -1: - default: // Unknown status - $rowcolor = COL_UNKNOWN; - $textcolor = '#FFF'; - break; - } - - $table_data .= ""; - - $file_name = string2image(ui_print_truncate_text($agent['nombre'], 'agent_small', false, true, false, '...'), false, false, 6, 0, $rowcolor, $textcolor, 4, 0); - $table_data .= ""; - $agent_modules = agents_get_modules($agent['id_agente']); - - $nmodules = 0; - - foreach ($modules_by_name as $module) { - $nmodules++; - // Don't use pagination - /*if ($nmodules > $block) { - continue; - }*/ - - $match = false; - foreach($module['id'] as $module_id){ - if (!$match && array_key_exists($module_id,$agent_modules)) { - $status = modules_get_agentmodule_status($module_id); - $table_data .= ""; - $match = true; - } - } - - if (!$match) { - $table_data .= ""; - } - } - - $table_data .= ""; - } - - $table_data .= "
".__("Agents")." / ".__("Modules")."' . html_print_image($file_name, true, array('title' => $module['name']))."...
".html_print_image($file_name, true, array('title' => $agent['nombre'])).""; - $win_handle = dechex(crc32($module_id.$module["name"])); - $graph_type = return_graphtype (modules_get_agentmodule_type($module_id)); - - switch ($status) { - case 0: - $table_data .= ui_print_status_image ('module_ok.png', $module['name']." in ".$agent['nombre'].": ".__('NORMAL'), true, array('width' => '20px', 'height' => '20px')); - break; - case 1: - $table_data .= ui_print_status_image ('module_critical.png', $module['name']." in ".$agent['nombre'].": ".__('CRITICAL'), true, array('width' => '20px', 'height' => '20px')); - break; - case 2: - $table_data .= ui_print_status_image ('module_warning.png', $module['name']." in ".$agent['nombre'].": ".__('WARNING'), true, array('width' => '20px', 'height' => '20px')); - break; - case 3: - $table_data .= ui_print_status_image ('module_unknown.png', $module['name']." in ".$agent['nombre'].": ".__('UNKNOWN'), true, array('width' => '20px', 'height' => '20px')); - break; - case 4: - $table_data .= ui_print_status_image ('module_alertsfired.png', $module['name']." in ".$agent['nombre'].": ".__('ALERTS FIRED'), true, array('width' => '20px', 'height' => '20px')); - break; - } - $table_data .= "
"; - - $table_data .= "
"; - - $table_data .= ""; - $table_data .= ""; - $table_data .= ""; - $table_data .= ""; - $table_data .= ""; - $table_data .= ""; - $table_data .= ""; - $table_data .= "
" . __('Legend') . "
" . __("Orange cell when the module has fired alerts") . "
" . __("Red cell when the module has a critical status") . "
" . __("Yellow cell when the module has a warning status") . "
" . __("Green cell when the module has a normal status") . "
" . __("Grey cell when the module has an unknown status") . "
"; - $table_data .= "
"; - $data = array (); - $table->colspan[2][0] = 3; - $data[0] = $table_data; - array_push ($table->data, $data); - break; case 'inventory': if (empty($item_title)) { $item_title = __('Inventory'); From 78267bcda4865576328da5fe567be41aff25eb4c Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Fri, 24 Apr 2015 11:51:46 +0200 Subject: [PATCH 45/80] Working in the refactoring the code of reports (inventory). --- .../include/functions_reporting.php | 44 +++++++++ .../include/functions_reporting_html.php | 95 ++++++++++++------- 2 files changed, 105 insertions(+), 34 deletions(-) diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index 4478cb963d..55da92ab4a 100644 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -387,12 +387,56 @@ function reporting_make_reporting_data($id_report, $date, $time, $report, $content); break; + case 'inventory': + $report['contents'][] = reporting_inventory( + $report, + $content); + break; } } return reporting_check_structure_report($report); } +function reporting_inventory($report, $content) { + global $config; + + $es = json_decode($content['external_source'], true); + + $return['type'] = 'inventory'; + + if (empty($content['name'])) { + $content['name'] = __('Inventory'); + } + + $return['title'] = $content['name']; + $return["description"] = $content["description"]; + $return["date"] = reporting_get_date_text($report, $content); + + $es = json_decode($content['external_source'], true); + + $id_agent = $es['id_agents']; + $module_name = $es['inventory_modules']; + if (empty($module_name)) { + $module_name = array(0 => 0); + } + $date = $es['date']; + $description = $content['description']; + + $inventory_data = inventory_get_data( + (array)$id_agent, (array)$module_name, $date, '', false, + 'hash'); + + if ($inventory_data == ERR_NODATA) { + $return['failed'] = __('No data found.'); + } + else { + $return['data'] = $inventory_data; + } + + return reporting_check_structure_content($return); +} + function reporting_agent_module($report, $content) { global $config; diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index a516412760..4e7dd331be 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -240,6 +240,9 @@ function reporting_html_print_report($report, $mini = false) { case 'agent_module': reporting_html_agent_module($table, $item); break; + case 'inventory': + reporting_html_inventory($table, $item); + break; } if ($item['type'] == 'agent_module') @@ -252,6 +255,63 @@ function reporting_html_print_report($report, $mini = false) { } } +function reporting_html_inventory($table, $item) { + if (!empty($item['failed'])) { + $table->colspan['failed']['cell'] = 3; + $table->cellstyle['failed']['cell'] = 'text-align: center;'; + $table->data['failed']['cell'] = $item['failed']; + } + else { + foreach ($item['data'] as $module_item) { + $table1 = null; + $table1->width = '99%'; + + $first = reset($module_item['data']); + $count_columns = count($first); + + + $table1->cellstyle[0][0] = + 'background: #373737; color: #FFF;'; + $table1->data[0][0] = $module_item['agent_name']; + if ($count_columns == 1) + $table1->colspan[0][0] = $count_columns + 1; // + columm date + else + $table1->colspan[0][0] = $count_columns; + + + $table1->cellstyle[1][0] = + $table1->cellstyle[1][1] = + 'background: #373737; color: #FFF;'; + $table1->data[1][0] = $module_item['name']; + if ($count_columns - 1 > 0) + $table1->colspan[1][0] = $count_columns - 1; + $table1->data[1][1] = $module_item['timestamp']; + + + $table1->cellstyle[2] = array_pad( + array(), + $count_columns, + 'background: #373737; color: #FFF;'); + $table1->data[2] = array_keys($first); + if ($count_columns - 1 == 0) { + $table1->colspan[2][0] = $count_columns + 1; // + columm date; + } + + $table1->data = array_merge($table1->data, $module_item['data']); + + + $table->colspan[ + $module_item['name'] . "_" .$module_item['id_agente']]['cell'] = 3; + $table->data[ + $module_item['name'] . "_" .$module_item['id_agente']]['cell'] = + html_print_table($table1, true); + + + } + } + +} + function reporting_html_agent_module($table, $item) { $table->colspan['agent_module']['cell'] = 3; $table->cellstyle['agent_module']['cell'] = 'text-align: center;'; @@ -4808,40 +4868,7 @@ function reporting_render_report_html_item ($content, $table, $report, $mini = f } break; - case 'inventory': - if (empty($item_title)) { - $item_title = __('Inventory'); - } - reporting_header_content($mini, $content, $report, $table, $item_title); - - $es = json_decode($content['external_source'], true); - - $id_agent = $es['id_agents']; - $module_name = $es['inventory_modules']; - if (empty($module_name)) { - $module_name = array(0 => 0); - } - $date = $es['date']; - $description = $content['description']; - - $data = array (); - $table->colspan[1][0] = 2; - $table->colspan[2][0] = 2; - if ($description != '') { - $data[0] = $description; - array_push ($table->data, $data); - } - - $inventory_data = inventory_get_data((array)$id_agent,(array)$module_name,$date,'',false); - - if ($inventory_data == ERR_NODATA) { - $inventory_data = "
".__('No data found.')."
"; - $inventory_data .= " "; - } - - $data[0] = $inventory_data; - array_push ($table->data, $data); - break; + case 'inventory_changes': if (empty($item_title)) { $item_title = __('Inventory changes'); From 24e0c6430b6a2009c08a881d9d7583a1e4c75343 Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Fri, 24 Apr 2015 13:07:50 +0200 Subject: [PATCH 46/80] Working in the refactoring the code of reports (inventory_changes). --- .../include/functions_reporting.php | 43 +++++++++ .../include/functions_reporting_html.php | 87 ++++++++++++------- 2 files changed, 97 insertions(+), 33 deletions(-) diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index 55da92ab4a..0e63eb26ef 100644 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -392,12 +392,55 @@ function reporting_make_reporting_data($id_report, $date, $time, $report, $content); break; + case 'inventory_changes': + $report['contents'][] = reporting_inventory_changes( + $report, + $content); + break; } } return reporting_check_structure_report($report); } +function reporting_inventory_changes($report, $content) { + global $config; + + $return['type'] = 'inventory_changes'; + + if (empty($content['name'])) { + $content['name'] = __('Inventory Changes'); + } + + $return['title'] = $content['name']; + $return['subtitle'] = agents_get_name($content['id_agent']); + $return["description"] = $content["description"]; + $return["date"] = reporting_get_date_text($report, $content); + + $es = json_decode($content['external_source'], true); + + $id_agent = $es['id_agents']; + $module_name = $es['inventory_modules']; + + + + $inventory_changes = inventory_get_changes( + $id_agent, $module_name, + $report["datetime"] - $content['period'], + $report["datetime"], "array"); + + $return['data'] = array(); + + if ($inventory_changes == ERR_NODATA) { + $return['failed'] = __('No changes found.'); + } + else { + $return['data'] = $inventory_changes; + } + + return reporting_check_structure_content($return); +} + function reporting_inventory($report, $content) { global $config; diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index 4e7dd331be..24cef9c5d9 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -243,6 +243,9 @@ function reporting_html_print_report($report, $mini = false) { case 'inventory': reporting_html_inventory($table, $item); break; + case 'inventory_changes': + reporting_html_inventory_changes($table, $item); + break; } if ($item['type'] == 'agent_module') @@ -255,6 +258,57 @@ function reporting_html_print_report($report, $mini = false) { } } +function reporting_html_inventory_changes($table, $item) { + if (!empty($item['failed'])) { + $table->colspan['failed']['cell'] = 3; + $table->cellstyle['failed']['cell'] = 'text-align: center;'; + $table->data['failed']['cell'] = $item['failed']; + } + else { + foreach ($item['data'] as $module_item) { + $table1 = null; + $table1->width = '99%'; + + $table1->cellstyle[0][0] = + $table1->cellstyle[0][1] = + 'background: #373737; color: #FFF;'; + $table1->data[0][0] = $module_item['agent']; + $table1->data[0][1] = $module_item['module']; + + + $table1->cellstyle[1][0] = + 'background: #373737; color: #FFF;'; + $table1->data[1][0] = $module_item['date']; + $table1->colspan[1][0] = 2; + + + $table1->cellstyle[2][0] = + 'background: #373737; color: #FFF; text-align: center;'; + $table1->data[2][0] = __('Added'); + $table1->colspan[2][0] = 2; + + + $table1->data = array_merge($table1->data, $module_item['added']); + + + $table1->cellstyle[3 + count($module_item['added'])][0] = + 'background: #373737; color: #FFF; text-align: center;'; + $table1->data[3 + count($module_item['added'])][0] = __('Deleted'); + $table1->colspan[3 + count($module_item['added'])][0] = 2; + + + $table1->data = array_merge($table1->data, $module_item['deleted']); + + + $table->colspan[ + $module_item['agent'] . "_" .$module_item['module']]['cell'] = 3; + $table->data[ + $module_item['agent'] . "_" .$module_item['module']]['cell'] = + html_print_table($table1, true); + } + } +} + function reporting_html_inventory($table, $item) { if (!empty($item['failed'])) { $table->colspan['failed']['cell'] = 3; @@ -4869,39 +4923,6 @@ function reporting_render_report_html_item ($content, $table, $report, $mini = f break; - case 'inventory_changes': - if (empty($item_title)) { - $item_title = __('Inventory changes'); - } - reporting_header_content($mini, $content, $report, $table, $item_title); - - $es = json_decode($content['external_source'], true); - - $id_agent = $es['id_agents']; - $module_name = $es['inventory_modules']; - $description = $content['description']; - - $inventory_changes = inventory_get_changes($id_agent, $module_name, $report["datetime"] - $content['period'], $report["datetime"]); - - if ($inventory_changes == ERR_NODATA) { - $inventory_changes = "
".__('No changes found.')."
"; - $inventory_changes .= " "; - } - - $data = array (); - - $table->colspan[1][0] = 2; - - if ($description != '') { - $data[0] = $description; - array_push ($table->data, $data); - } - - $data[0] = $inventory_changes; - $table->colspan[2][0] = 2; - - array_push ($table->data, $data); - break; } //Restore dbconnection if (($config ['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE') && $remote_connection == 1) { From 55dc1a278e536ea3c78e17f5f10c0f735f0c9740 Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Fri, 24 Apr 2015 14:24:17 +0200 Subject: [PATCH 47/80] Working in the refactoring the code of reports (event_report_module). --- pandora_console/include/functions_events.php | 2 +- .../include/functions_reporting.php | 146 +++++++++++++ .../include/functions_reporting_html.php | 193 +++++++----------- 3 files changed, 216 insertions(+), 125 deletions(-) diff --git a/pandora_console/include/functions_events.php b/pandora_console/include/functions_events.php index 3c195207ba..8439d3b16c 100644 --- a/pandora_console/include/functions_events.php +++ b/pandora_console/include/functions_events.php @@ -1342,7 +1342,7 @@ function events_get_module ($id_agent_module, $period, $date = 0) { $datelimit = $date - $period; - $sql_where .= sprintf(' AND id_agentmodule = %d AND utimestamp > %d + $sql_where = sprintf(' AND id_agentmodule = %d AND utimestamp > %d AND utimestamp <= %d ', $id_agent_module, $datelimit, $date); return events_get_events_grouped($sql_where, 0, 1000); diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index 0e63eb26ef..4ae20cb5cc 100644 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -397,12 +397,48 @@ function reporting_make_reporting_data($id_report, $date, $time, $report, $content); break; + case 'event_report_module': + $report['contents'][] = reporting_event_report_module( + $report, + $content); + break; } } return reporting_check_structure_report($report); } +function reporting_event_report_module($report, $content) { + global $config; + + $return['type'] = 'event_report_module'; + + if (empty($content['name'])) { + $content['name'] = __('Event Report Module'); + } + + $return['title'] = $content['name']; + $return['subtitle'] = agents_get_name($content['id_agent']) . + " - " . + io_safe_output( + modules_get_agentmodule_name($content['id_agent_module'])); + $return["description"] = $content["description"]; + $return["date"] = reporting_get_date_text($report, $content); + + $data = reporting_get_module_detailed_event( + $content['id_agent_module'], $content['period'], + $report["datetime"], true, false, true); + + if (empty($data)) { + $return['failed'] = __('No events'); + } + else { + $return['data'] = $data; + } + + return reporting_check_structure_content($return); +} + function reporting_inventory_changes($report, $content) { global $config; @@ -3084,6 +3120,116 @@ function reporting_set_conf_charts(&$width, &$height, &$only_image, $type, +/** + * Get a detailed report of summarized events per agent + * + * It construct a table object with all the grouped events happened in an agent + * during a period of time. + * + * @param mixed Module id to get the report from. + * @param int Period of time (in seconds) to get the report. + * @param int Beginning date (unixtime) of the report + * @param bool Flag to return or echo the report table (echo by default). + * @param bool Flag to return the html or table object, by default html. + * + * @return mixed A table object (XHTML) or object table is false the html. + */ +function reporting_get_module_detailed_event ($id_modules, $period = 0, + $date = 0, $return = false, $html = true, $only_data = false) { + + global $config; + + $id_modules = (array)safe_int ($id_modules, 1); + + if (!is_numeric ($date)) { + $date = strtotime ($date); + } + if (empty ($date)) { + $date = get_system_time (); + } + + $table->width = '99%'; + $table->data = array (); + $table->head = array (); + $table->head[0] = __('Status'); + $table->head[1] = __('Event name'); + $table->head[2] = __('Event type'); + $table->head[3] = __('Criticity'); + $table->head[4] = __('Count'); + $table->head[5] = __('Timestamp'); + $table->style[0] = 'text-align: center;'; + $table->style[4] = 'text-align: center;'; + + $events = array (); + + foreach ($id_modules as $id_module) { + $event = events_get_module ($id_module, (int) $period, (int) $date); + if (!empty ($event)) { + array_push ($events, $event); + } + } + + if ($only_data) { + return $event; + } + + if ($events) { + $note = ''; + if (count($events) >= 1000) { + $note .= '* ' . __('Maximum of events shown') . ' (1000)
'; + } + foreach ($events as $eventRow) { + foreach ($eventRow as $k => $event) { + //$k = count($table->data); + $table->cellclass[$k][1] = $table->cellclass[$k][2] = + $table->cellclass[$k][3] = $table->cellclass[$k][4] = + $table->cellclass[$k][5] = 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[0] = html_print_image ($img_st, true, + array ("class" => "image_status", + "width" => 16, + "title" => $title_st, + "id" => 'status_img_' . $event["id_evento"])); + + $data[1] = io_safe_output($event['evento']); + $data[2] = $event['event_type']; + $data[3] = get_priority_name ($event['criticity']); + $data[4] = $event['event_rep']; + $data[5] = date($config['date_format'], $event['timestamp_rep']); + array_push ($table->data, $data); + } + } + + if ($html) { + return html_print_table ($table, $return) . $note; + } + else { + return $table; + } + } + else { + return false; + } +} + + /** * Get a detailed report of summarized events per agent * diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index 24cef9c5d9..d57ba6153d 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -246,6 +246,9 @@ function reporting_html_print_report($report, $mini = false) { case 'inventory_changes': reporting_html_inventory_changes($table, $item); break; + case 'event_report_module': + reporting_html_event_report_module($table, $item); + break; } if ($item['type'] == 'agent_module') @@ -258,6 +261,72 @@ function reporting_html_print_report($report, $mini = false) { } } +function reporting_html_event_report_module($table, $item) { + + global $config; + + if (!empty($item['failed'])) { + $table->colspan['events']['cell'] = 3; + $table->data['events']['cell'] = $item['failed']; + } + else { + $table1->width = '99%'; + $table1->data = array (); + $table1->head = array (); + $table1->head[0] = __('Status'); + $table1->head[1] = __('Event name'); + $table1->head[2] = __('Event type'); + $table1->head[3] = __('Criticity'); + $table1->head[4] = __('Count'); + $table1->head[5] = __('Timestamp'); + $table1->style[0] = 'text-align: center;'; + $table1->style[4] = 'text-align: center;'; + + + foreach ($item['data'] as $i => $event) { + $data = array(); + + $table1->cellclass[$i][1] = + $table1->cellclass[$i][2] = + $table1->cellclass[$i][3] = + $table1->cellclass[$i][4] = + $table1->cellclass[$i][5] = get_priority_class($event["criticity"]); + + // 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[0] = html_print_image ($img_st, true, + array ("class" => "image_status", + "width" => 16, + "title" => $title_st, + "id" => 'status_img_' . $event["id_evento"])); + $data[1] = io_safe_output($event['evento']); + $data[2] = $event['event_type']; + $data[3] = get_priority_name ($event['criticity']); + $data[4] = $event['event_rep']; + $data[5] = date($config['date_format'], $event['timestamp_rep']); + + $table1->data[] = $data; + } + + $table->colspan['events']['cell'] = 3; + $table->data['events']['cell'] = html_print_table($table1, true); + } +} + function reporting_html_inventory_changes($table, $item) { if (!empty($item['failed'])) { $table->colspan['failed']['cell'] = 3; @@ -3607,109 +3676,6 @@ function reporting_get_group_detailed_event ($id_group, $period = 0, } -/** - * Get a detailed report of summarized events per agent - * - * It construct a table object with all the grouped events happened in an agent - * during a period of time. - * - * @param mixed Module id to get the report from. - * @param int Period of time (in seconds) to get the report. - * @param int Beginning date (unixtime) of the report - * @param bool Flag to return or echo the report table (echo by default). - * @param bool Flag to return the html or table object, by default html. - * - * @return mixed A table object (XHTML) or object table is false the html. - */ -function reporting_get_module_detailed_event ($id_modules, $period = 0, $date = 0, $return = false, $html = true) { - global $config; - - $id_modules = (array)safe_int ($id_modules, 1); - - if (!is_numeric ($date)) { - $date = strtotime ($date); - } - if (empty ($date)) { - $date = get_system_time (); - } - - $table->width = '99%'; - $table->data = array (); - $table->head = array (); - $table->head[0] = __('Status'); - $table->head[1] = __('Event name'); - $table->head[2] = __('Event type'); - $table->head[3] = __('Criticity'); - $table->head[4] = __('Count'); - $table->head[5] = __('Timestamp'); - $table->style[0] = 'text-align: center;'; - $table->style[4] = 'text-align: center;'; - - $events = array (); - - foreach ($id_modules as $id_module) { - $event = events_get_module ($id_module, (int) $period, (int) $date); - if (!empty ($event)) { - array_push ($events, $event); - } - } - - if ($events) { - $note = ''; - if (count($events) >= 1000) { - $note .= '* ' . __('Maximum of events shown') . ' (1000)
'; - } - foreach ($events as $eventRow) { - foreach ($eventRow as $k => $event) { - //$k = count($table->data); - $table->cellclass[$k][1] = $table->cellclass[$k][2] = - $table->cellclass[$k][3] = $table->cellclass[$k][4] = - $table->cellclass[$k][5] = 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[0] = html_print_image ($img_st, true, - array ("class" => "image_status", - "width" => 16, - "title" => $title_st, - "id" => 'status_img_' . $event["id_evento"])); - - $data[1] = io_safe_output($event['evento']); - $data[2] = $event['event_type']; - $data[3] = get_priority_name ($event['criticity']); - $data[4] = $event['event_rep']; - $data[5] = date($config['date_format'], $event['timestamp_rep']); - array_push ($table->data, $data); - } - } - - if ($html) { - return html_print_table ($table, $return) . $note; - } - else { - return $table; - } - } - else { - return false; - } -} - /** * This is the callback sorting function for SLA values descending @@ -4565,27 +4531,6 @@ function reporting_render_report_html_item ($content, $table, $report, $mini = f array_push ($table->data, $data); } break; - case 'event_report_module': - if (empty($item_title)) { - $item_title = __('Module detailed event'); - } - reporting_header_content($mini, $content, $report, $table, $item_title, - ui_print_truncate_text($agent_name, 'agent_medium', false) . - '
' . ui_print_truncate_text($module_name, 'module_medium', false)); - - // Put description at the end of the module (if exists) - $table->colspan[1][0] = 3; - if ($content["description"] != "") { - $data_desc = array(); - $data_desc[0] = $content["description"]; - array_push ($table->data, $data_desc); - } - - $data = array (); - $table->colspan[2][0] = 3; - $data[0] = reporting_get_module_detailed_event($content['id_agent_module'], $content['period'], $report["datetime"], true); - array_push ($table->data, $data); - break; case 'top_n': $top_n = $content['top_n']; From d1bff5de92e14ea302688df54a5e8cf55f43254b Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Fri, 24 Apr 2015 17:09:26 +0200 Subject: [PATCH 48/80] Fixed the lost period in availability item. TICKET: #2149 (cherry picked from commit 61aa789033e3199d1e733f3fb2abf89b2b8e116d) --- pandora_console/godmode/reporting/reporting_builder.php | 1 + 1 file changed, 1 insertion(+) diff --git a/pandora_console/godmode/reporting/reporting_builder.php b/pandora_console/godmode/reporting/reporting_builder.php index 2850deb5db..b842d68a6a 100644 --- a/pandora_console/godmode/reporting/reporting_builder.php +++ b/pandora_console/godmode/reporting/reporting_builder.php @@ -1112,6 +1112,7 @@ switch ($action) { $good_format = true; break; case 'availability': + $values['period'] = get_parameter('period'); // HACK it is saved in show_graph field. // Show interfaces instead the modules $values['show_graph'] = From 184e705b8dd67afdff2792bf3280432cd37ad52c Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Fri, 24 Apr 2015 17:17:38 +0200 Subject: [PATCH 49/80] Fixed the returning to item editor when it is availability item. TICKET: #2149 (cherry picked from commit 29f4c1d7e7fc86313bbb063036e55bfa79e5e9ab) --- .../godmode/reporting/reporting_builder.item_editor.php | 1 + 1 file changed, 1 insertion(+) diff --git a/pandora_console/godmode/reporting/reporting_builder.item_editor.php b/pandora_console/godmode/reporting/reporting_builder.item_editor.php index 9b200eaaa8..3f08ebbd99 100644 --- a/pandora_console/godmode/reporting/reporting_builder.item_editor.php +++ b/pandora_console/godmode/reporting/reporting_builder.item_editor.php @@ -130,6 +130,7 @@ switch ($action) { case 'exception': case 'general': case 'network_interfaces_report': + case 'availability': $get_data_editor = true; break; default: From d947d62b5190529293f06dae6b483eb1debf387e Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Fri, 24 Apr 2015 19:05:17 +0200 Subject: [PATCH 50/80] Fixed show the widget 'show resume' in the 'availability' item in report. TICKET: #2149 (cherry picked from commit 0f72fa8bbd198acee934093ad034623f98c6ef2a) --- .../godmode/reporting/reporting_builder.item_editor.php | 1 + .../godmode/reporting/reporting_builder.list_items.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/pandora_console/godmode/reporting/reporting_builder.item_editor.php b/pandora_console/godmode/reporting/reporting_builder.item_editor.php index 3f08ebbd99..f3a9160254 100644 --- a/pandora_console/godmode/reporting/reporting_builder.item_editor.php +++ b/pandora_console/godmode/reporting/reporting_builder.item_editor.php @@ -2355,6 +2355,7 @@ function chooseType() { $("#row_order_uptodown").show(); $("#row_show_address_agent").show(); $("#row_show_in_two_columns").show(); + $("#row_show_resume").show(); break; case 'group_report': $("#row_group").show(); diff --git a/pandora_console/godmode/reporting/reporting_builder.list_items.php b/pandora_console/godmode/reporting/reporting_builder.list_items.php index 552dcf339a..11a1204f00 100644 --- a/pandora_console/godmode/reporting/reporting_builder.list_items.php +++ b/pandora_console/godmode/reporting/reporting_builder.list_items.php @@ -77,7 +77,7 @@ else { $agents[$row['id_agente']] = $row['nombre']; } - switch ($config['dbtype']){ + switch ($config['dbtype']) { case "mysql": case "postgresql": $rows = db_get_all_rows_sql(' From bc9918707a05ce6a57130083badea4a874e8c648 Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Mon, 27 Apr 2015 13:42:03 +0200 Subject: [PATCH 51/80] Working in the refactoring the code of reports (event_report_group) and added the filter by text. TICKET: #2066 --- .../reporting_builder.item_editor.php | 16 + .../godmode/reporting/reporting_builder.php | 20 + pandora_console/include/functions_events.php | 56 ++- .../include/functions_reporting.php | 261 ++++++++++- .../include/functions_reporting_html.php | 431 +++++++----------- 5 files changed, 491 insertions(+), 293 deletions(-) diff --git a/pandora_console/godmode/reporting/reporting_builder.item_editor.php b/pandora_console/godmode/reporting/reporting_builder.item_editor.php index f3a9160254..09659d6b02 100644 --- a/pandora_console/godmode/reporting/reporting_builder.item_editor.php +++ b/pandora_console/godmode/reporting/reporting_builder.item_editor.php @@ -104,6 +104,9 @@ $netflow_filter = 0; $max_values = 0; $resolution = 0; +//Others +$filter_search = ""; + switch ($action) { case 'new': $actionParameter = 'save'; @@ -412,6 +415,8 @@ switch ($action) { $event_graph_by_user_validator = $style['event_graph_by_user_validator']; $event_graph_by_criticity = $style['event_graph_by_criticity']; $event_graph_validated_vs_unvalidated = $style['event_graph_validated_vs_unvalidated']; + + $filter_search = $style['event_filter_search']; break; case 'event_report_module': $description = $item['description']; @@ -1190,6 +1195,14 @@ else ?> + + + + + +
@@ -2066,6 +2079,7 @@ function chooseType() { $("#row_max_values").hide(); $("#row_resolution").hide(); $("#row_last_value").hide(); + $("#row_filter_search").hide(); // SLA list default state $("#sla_list").hide(); @@ -2094,6 +2108,8 @@ function chooseType() { $("#row_event_graph_by_user").show(); $("#row_event_graph_by_criticity").show(); $("#row_event_graph_by_validated").show(); + + $("#row_filter_search").show(); break; case 'simple_graph': $("#row_time_compare_overlapped").show(); diff --git a/pandora_console/godmode/reporting/reporting_builder.php b/pandora_console/godmode/reporting/reporting_builder.php index b842d68a6a..4b727b17e7 100644 --- a/pandora_console/godmode/reporting/reporting_builder.php +++ b/pandora_console/godmode/reporting/reporting_builder.php @@ -957,6 +957,8 @@ switch ($action) { $event_graph_by_criticity = get_parameter('event_graph_by_criticity', 0); $event_graph_validated_vs_unvalidated = get_parameter('event_graph_validated_vs_unvalidated', 0); + $event_filter_search = get_parameter('filter_search', ''); + // If metaconsole is activated if ($config['metaconsole'] == 1 && defined('METACONSOLE')) { if (($values['type'] == 'custom_graph') or ($values['type'] == 'automatic_custom_graph')) { @@ -1023,6 +1025,13 @@ switch ($action) { $style['event_graph_by_user_validator'] = $event_graph_by_user_validator; $style['event_graph_by_criticity'] = $event_graph_by_criticity; $style['event_graph_validated_vs_unvalidated'] = $event_graph_validated_vs_unvalidated; + + switch ($values['type']) { + case 'event_report_group': + $style['event_filter_search'] = + $event_filter_search; + break; + } break; case 'simple_graph': // Warning. We are using this column to hold this value to avoid @@ -1243,6 +1252,9 @@ switch ($action) { $event_graph_by_user_validator = get_parameter('event_graph_by_user_validator', 0); $event_graph_by_criticity = get_parameter('event_graph_by_criticity', 0); $event_graph_validated_vs_unvalidated = get_parameter('event_graph_validated_vs_unvalidated', 0); + + $event_filter_search = get_parameter('filter_search', ''); + //Added for events items $style['filter_event_no_validated'] = $filter_event_no_validated; $style['filter_event_validated'] = $filter_event_validated; @@ -1253,6 +1265,14 @@ switch ($action) { $style['event_graph_by_user_validator'] = $event_graph_by_user_validator; $style['event_graph_by_criticity'] = $event_graph_by_criticity; $style['event_graph_validated_vs_unvalidated'] = $event_graph_validated_vs_unvalidated; + + switch ($values['type']) { + case 'event_report_group': + $style['event_filter_search'] = + $event_filter_search; + break; + } + break; case 'simple_graph': // Warning. We are using this column to hold this value to avoid diff --git a/pandora_console/include/functions_events.php b/pandora_console/include/functions_events.php index 8439d3b16c..c79896f86a 100644 --- a/pandora_console/include/functions_events.php +++ b/pandora_console/include/functions_events.php @@ -109,7 +109,9 @@ function events_get_event ($id, $fields = false) { return $event; } -function events_get_events_grouped($sql_post, $offset = 0, $pagination = 1, $meta = false, $history = false, $total = false) { +function events_get_events_grouped($sql_post, $offset = 0, + $pagination = 1, $meta = false, $history = false, $total = false) { + global $config; $table = events_get_events_table($meta, $history); @@ -1174,7 +1176,8 @@ 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) { + $filter_event_warning = false, $filter_event_no_validated = false, + $filter_event_search = false) { global $config; @@ -1204,8 +1207,17 @@ function events_get_group_events ($id_group, $period, $date, if ($filter_event_no_validated) { $sql_where .= ' AND estado = 0 '; } - $sql_where .= sprintf(' AND id_grupo IN (%s) AND utimestamp > %d - AND utimestamp <= %d ', implode (",", $id_group), $datelimit, $date); + + if (!empty($filter_event_search)) { + $sql_where .= ' AND (evento LIKE "%'. io_safe_input($filter_event_search) . '%"'. + ' OR id_evento LIKE "%' . io_safe_input($filter_event_search) . '%")'; + } + + $sql_where .= sprintf(' + AND id_grupo IN (%s) + AND utimestamp > %d + AND utimestamp <= %d ', + implode (",", $id_group), $datelimit, $date); return events_get_events_grouped($sql_where, 0, 1000); } @@ -2523,7 +2535,9 @@ function events_clean_tags ($tags) { */ function events_get_count_events_by_agent ($id_group, $period, $date, $filter_event_validated = false, $filter_event_critical = false, - $filter_event_warning = false, $filter_event_no_validated = false) { + $filter_event_warning = false, $filter_event_no_validated = false, + $filter_event_search = false) { + global $config; $id_group = groups_safe_acl ($config["id_user"], $id_group, "AR"); @@ -2554,6 +2568,11 @@ function events_get_count_events_by_agent ($id_group, $period, $date, $sql_where .= ' AND estado = 0 '; } + if (!empty($filter_event_search)) { + $sql_where .= ' AND (evento LIKE "%%'. io_safe_input($filter_event_search) . '%%"'. + ' OR id_evento LIKE "%%' . io_safe_input($filter_event_search) . '%%")'; + } + $sql = sprintf ('SELECT id_agente, (SELECT t2.nombre FROM tagente AS t2 @@ -2595,7 +2614,9 @@ function events_get_count_events_by_agent ($id_group, $period, $date, */ function events_get_count_events_validated_by_user ($filter, $period, $date, $filter_event_validated = false, $filter_event_critical = false, - $filter_event_warning = false, $filter_event_no_validated = false) { + $filter_event_warning = false, $filter_event_no_validated = false, + $filter_event_search = false) { + global $config; $sql_filter = ' AND 1=1 '; @@ -2636,6 +2657,11 @@ function events_get_count_events_validated_by_user ($filter, $period, $date, $sql_where .= ' AND estado = 0 '; } + if (!empty($filter_event_search)) { + $sql_where .= ' AND (evento LIKE "%%'. io_safe_input($filter_event_search) . '%%"'. + ' OR id_evento LIKE "%%' . io_safe_input($filter_event_search) . '%%")'; + } + $sql = sprintf ('SELECT id_usuario, (SELECT t2.fullname FROM tusuario AS t2 @@ -2677,7 +2703,9 @@ function events_get_count_events_validated_by_user ($filter, $period, $date, */ function events_get_count_events_by_criticity ($filter, $period, $date, $filter_event_validated = false, $filter_event_critical = false, - $filter_event_warning = false, $filter_event_no_validated = false) { + $filter_event_warning = false, $filter_event_no_validated = false, + $filter_event_search = false) { + global $config; $sql_filter = ' AND 1=1 '; @@ -2718,6 +2746,11 @@ function events_get_count_events_by_criticity ($filter, $period, $date, $sql_where .= ' AND estado = 0 '; } + if (!empty($filter_event_search)) { + $sql_where .= ' AND (evento LIKE "%%'. io_safe_input($filter_event_search) . '%%"'. + ' OR id_evento LIKE "%%' . io_safe_input($filter_event_search) . '%%")'; + } + $sql = sprintf ('SELECT criticity, COUNT(*) AS count FROM tevento @@ -2752,7 +2785,9 @@ function events_get_count_events_by_criticity ($filter, $period, $date, */ function events_get_count_events_validated ($filter, $period, $date, $filter_event_validated = false, $filter_event_critical = false, - $filter_event_warning = false, $filter_event_no_validated = false) { + $filter_event_warning = false, $filter_event_no_validated = false, + $filter_event_search = false) { + global $config; $sql_filter = ' AND 1=1 '; @@ -2793,6 +2828,11 @@ function events_get_count_events_validated ($filter, $period, $date, $sql_where .= ' AND estado = 0 '; } + if (!empty($filter_event_search)) { + $sql_where .= ' AND (evento LIKE "%%'. io_safe_input($filter_event_search) . '%%"'. + ' OR id_evento LIKE "%%' . io_safe_input($filter_event_search) . '%%")'; + } + $sql = sprintf ('SELECT estado, COUNT(*) AS count FROM tevento diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index 4ae20cb5cc..132ff434c0 100644 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -104,6 +104,11 @@ function reporting_make_reporting_data($id_report, $date, $time, $return = array(); $report = db_get_row ('treport', 'id_report', $id_report); + $report["group"] = $report['id_group']; + $report["group_name"] = groups_get_name ($report['id_group']); + $report['contents'] = array(); + $datetime = strtotime($date . ' ' . $time); + $report["datetime"] = $datetime; switch ($config["dbtype"]) { case "mysql": @@ -120,16 +125,9 @@ function reporting_make_reporting_data($id_report, $date, $time, break; } if ($contents === false) { - return $return; + return reporting_check_structure_report($report); } - $report["group"] = $report['id_group']; - $report["group_name"] = groups_get_name ($report['id_group']); - - $datetime = strtotime($date . ' ' . $time); - $report["datetime"] = $datetime; - - $report['contents'] = array(); foreach ($contents as $content) { if (!empty($period)) { @@ -402,12 +400,136 @@ function reporting_make_reporting_data($id_report, $date, $time, $report, $content); break; + case 'event_report_group': + $report['contents'][] = reporting_event_report_group( + $report, + $content); + break; } } return reporting_check_structure_report($report); } +function reporting_event_report_group($report, $content) { + global $config; + + $return['type'] = 'event_report_group'; + + if (empty($content['name'])) { + $content['name'] = __('Event Report Group'); + } + + $return['title'] = $content['name']; + $return['subtitle'] = groups_get_name($content['id_group'], true); + if (!empty($content['style']['event_filter_search'])) { + $return['subtitle'] .= " (" . $content['style']['event_filter_search'] . ")"; + } + $return["description"] = $content["description"]; + $return["date"] = reporting_get_date_text($report, $content); + + + $filter_event_no_validated = $content['style']['filter_event_no_validated']; + $filter_event_validated = $content['style']['filter_event_validated']; + $filter_event_critical = $content['style']['filter_event_critical']; + $filter_event_warning = $content['style']['filter_event_warning']; + $filter_event_filter_search = $content['style']['event_filter_search']; + + $event_graph_by_agent = $content['style']['event_graph_by_agent']; + $event_graph_by_user_validator = $content['style']['event_graph_by_user_validator']; + $event_graph_by_criticity = $content['style']['event_graph_by_criticity']; + $event_graph_validated_vs_unvalidated = $content['style']['event_graph_validated_vs_unvalidated']; + + + $data = reporting_get_group_detailed_event( + $content['id_group'], $content['period'], $report["datetime"], + true, true, $filter_event_validated, $filter_event_critical, + $filter_event_warning, $filter_event_no_validated, + $filter_event_filter_search, 'hash'); + + if (empty($data)) { + $return['failed'] = __('No events'); + } + else { + $return['data'] = $data; + } + + $return['chart']['by_agent'] = null; + $return['chart']['by_user_validator'] = null; + $return['chart']['by_criticity'] = null; + $return['chart']['validated_vs_unvalidated'] = null; + + if ($event_graph_by_agent) { + $data_graph = reporting_get_count_events_by_agent( + $content['id_group'], $content['period'], + $report["datetime"], + $filter_event_validated, + $filter_event_critical, + $filter_event_warning, + $filter_event_no_validated, + $filter_event_filter_search); + + $return['chart']['by_agent']= pie3d_graph( + false, $data_graph, 500, 150, __("other"), "", + ui_get_full_url(false, false, false, false) . "/images/logo_vertical_water.png", + $config['fontpath'], $config['font_size']); + } + + if ($event_graph_by_user_validator) { + $data_graph = + reporting_get_count_events_validated_by_user( + array('id_group' => $content['id_group']), $content['period'], + $report["datetime"], + $filter_event_validated, + $filter_event_critical, + $filter_event_warning, + $filter_event_no_validated, + $filter_event_filter_search); + + $return['chart']['by_user_validator'] = pie3d_graph( + false, $data_graph, 500, 150, __("other"), "", + ui_get_full_url(false, false, false, false) . "/images/logo_vertical_water.png", + $config['fontpath'], $config['font_size']); + } + + if ($event_graph_by_criticity) { + $data_graph = reporting_get_count_events_by_criticity( + array('id_group' => $content['id_group']), $content['period'], + $report["datetime"], + $filter_event_validated, + $filter_event_critical, + $filter_event_warning, + $filter_event_no_validated, + $filter_event_filter_search); + + $colors = get_criticity_pie_colors($data_graph); + + $return['chart']['by_criticity'] = pie3d_graph( + false, $data_graph, 500, 150, __("other"), "", + ui_get_full_url(false, false, false, false) . "/images/logo_vertical_water.png", + $config['fontpath'], $config['font_size'], 1, false, $colors); + } + + if ($event_graph_validated_vs_unvalidated) { + $data_graph = + reporting_get_count_events_validated( + array('id_group' => $content['id_group']), $content['period'], + $report["datetime"], + $filter_event_validated, + $filter_event_critical, + $filter_event_warning, + $filter_event_no_validated, + $filter_event_filter_search); + + $return['chart']['validated_vs_unvalidated'] = pie3d_graph( + false, $data_graph, 500, 150, __("other"), "", + ui_get_full_url(false, false, false, false) . "/images/logo_vertical_water.png", + $config['fontpath'], $config['font_size']); + } + + return reporting_check_structure_content($return); +} + function reporting_event_report_module($report, $content) { global $config; @@ -3119,6 +3241,129 @@ function reporting_set_conf_charts(&$width, &$height, &$only_image, $type, //////////////////////////////////////////////////////////////////////// +/** + * Gets a detailed reporting of groups's events. + * + * @param unknown_type $id_group Id of the group. + * @param unknown_type $period Time period of the report. + * @param unknown_type $date Date of the report. + * @param unknown_type $return Whether to return or not. + * @param unknown_type $html Whether to return HTML code or not. + * + * @return string Report of groups's events + */ +function reporting_get_group_detailed_event ($id_group, $period = 0, + $date = 0, $return = false, $html = true, + $filter_event_validated = false, $filter_event_critical = false, + $filter_event_warning = false, $filter_event_no_validated = false, + $filter_event_filter_search = null, $return_type = false) { + + global $config; + + if (!is_numeric ($date)) { + $date = strtotime ($date); + } + if (empty ($date)) { + $date = get_system_time (); + } + + $table->width = '99%'; + + $table->align = array(); + $table->align[0] = 'center'; + $table->align[2] = 'center'; + + $table->data = array (); + + $table->head = array (); + $table->head[0] = __('Status'); + $table->head[1] = __('Name'); + $table->head[2] = __('Type'); + $table->head[3] = __('Agent'); + $table->head[4] = __('Criticity'); + $table->head[5] = __('Val. by'); + $table->head[6] = __('Timestamp'); + + $events = events_get_group_events($id_group, $period, $date, + $filter_event_validated, $filter_event_critical, + $filter_event_warning, $filter_event_no_validated, + $filter_event_filter_search); + + if ($return_type === 'hash') { + return $events; + } + + if ($events) { + $note = ''; + if (count($events) >= 1000) { + $note .= '* ' . __('Maximum of events shown') . ' (1000)
'; + } + foreach ($events as $k => $event) { + //First pass along the class of this row + $table->cellclass[$k][1] = $table->cellclass[$k][3] = + $table->cellclass[$k][4] = $table->cellclass[$k][5] = + $table->cellclass[$k][6] = + 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, + "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['id_agente'])) + $data[] = agents_get_name($event['id_agente']); + else + $data[] = __('Pandora System'); + $data[] = get_priority_name ($event['criticity']); + if (empty($event['id_usuario']) && $event['estado'] == EVENT_VALIDATE) { + $data[] = '' . __('System') . ''; + } + else { + $user_name = db_get_value ('fullname', 'tusuario', 'id_user', $event['id_usuario']); + $data[] = io_safe_output($user_name); + } + $data[] = '' . + date($config['date_format'], $event['timestamp_rep']) . + ''; + array_push ($table->data, $data); + } + + if ($html) { + return html_print_table ($table, $return) . $note; + } + else { + return $table; + } + } + else { + return false; + } +} /** * Get a detailed report of summarized events per agent diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index d57ba6153d..a410eb5df8 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -249,6 +249,9 @@ function reporting_html_print_report($report, $mini = false) { case 'event_report_module': reporting_html_event_report_module($table, $item); break; + case 'event_report_group': + reporting_html_event_report_group($table, $item); + break; } if ($item['type'] == 'agent_module') @@ -261,6 +264,141 @@ function reporting_html_print_report($report, $mini = false) { } } +function reporting_html_event_report_group($table, $item) { + global $config; + + if (!empty($item['failed'])) { + $table->colspan['events']['cell'] = 3; + $table->data['events']['cell'] = $item['failed']; + } + else { + $table1->width = '99%'; + + $table1->align = array(); + $table1->align[0] = 'center'; + $table1->align[2] = 'center'; + + $table1->data = array (); + + $table1->head = array (); + $table1->head[0] = __('Status'); + $table1->head[1] = __('Name'); + $table1->head[2] = __('Type'); + $table1->head[3] = __('Agent'); + $table1->head[4] = __('Criticity'); + $table1->head[5] = __('Val. by'); + $table1->head[6] = __('Timestamp'); + + foreach ($item['data'] as $k => $event) { + //First pass along the class of this row + $table1->cellclass[$k][1] = $table1->cellclass[$k][3] = + $table1->cellclass[$k][4] = $table1->cellclass[$k][5] = + $table1->cellclass[$k][6] = + 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, + "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['id_agente'])) + $data[] = agents_get_name($event['id_agente']); + else + $data[] = __('Pandora System'); + $data[] = get_priority_name ($event['criticity']); + if (empty($event['id_usuario']) && $event['estado'] == EVENT_VALIDATE) { + $data[] = '' . __('System') . ''; + } + else { + $user_name = db_get_value ('fullname', 'tusuario', 'id_user', $event['id_usuario']); + $data[] = io_safe_output($user_name); + } + $data[] = '' . + date($config['date_format'], $event['timestamp_rep']) . + ''; + array_push ($table1->data, $data); + } + + $table->colspan['events']['cell'] = 3; + $table->data['events']['cell'] = html_print_table($table1, true); + + + + if (!empty($item['chart']['by_agent'])) { + $table1 = null; + $table1->width = '99%'; + $table1->head = array (); + $table1->head[0] = __('Events by agent'); + $table1->data[0][0] = $item['chart']['by_agent']; + + $table->colspan['chart_by_agent']['cell'] = 3; + $table->cellstyle['chart_by_agent']['cell'] = 'text-align: center;'; + $table->data['chart_by_agent']['cell'] = html_print_table($table1, true); + } + + if (!empty($item['chart']['by_user_validator'])) { + $table1 = null; + $table1->width = '99%'; + $table1->head = array (); + $table1->head[0] = __('Events by user validator'); + $table1->data[0][0] = $item['chart']['by_user_validator']; + + $table->colspan['chart_by_user_validator']['cell'] = 3; + $table->cellstyle['chart_by_user_validator']['cell'] = 'text-align: center;'; + $table->data['chart_by_user_validator']['cell'] = html_print_table($table1, true); + } + + if (!empty($item['chart']['by_criticity'])) { + $table1 = null; + $table1->width = '99%'; + $table1->head = array (); + $table1->head[0] = __('Events by criticity'); + $table1->data[0][0] = $item['chart']['by_criticity']; + + $table->colspan['chart_by_criticity']['cell'] = 3; + $table->cellstyle['chart_by_criticity']['cell'] = 'text-align: center;'; + $table->data['chart_by_criticity']['cell'] = html_print_table($table1, true); + } + + if (!empty($item['chart']['validated_vs_unvalidated'])) { + $table1 = null; + $table1->width = '99%'; + $table1->head = array (); + $table1->head[0] = __('Events validated vs unvalidated'); + $table1->data[0][0] = $item['chart']['validated_vs_unvalidated']; + + $table->colspan['chart_validated_vs_unvalidated']['cell'] = 3; + $table->cellstyle['chart_validated_vs_unvalidated']['cell'] = 'text-align: center;'; + $table->data['chart_validated_vs_unvalidated']['cell'] = html_print_table($table1, true); + } + } +} + function reporting_html_event_report_module($table, $item) { global $config; @@ -3557,123 +3695,6 @@ function reporting_agents_get_group_agents_detailed ($id_group, $period = 0, $da } -/** - * Gets a detailed reporting of groups's events. - * - * @param unknown_type $id_group Id of the group. - * @param unknown_type $period Time period of the report. - * @param unknown_type $date Date of the report. - * @param unknown_type $return Whether to return or not. - * @param unknown_type $html Whether to return HTML code or not. - * - * @return string Report of groups's events - */ -function reporting_get_group_detailed_event ($id_group, $period = 0, - $date = 0, $return = false, $html = true, - $filter_event_validated = false, $filter_event_critical = false, - $filter_event_warning = false, $filter_event_no_validated = false) { - - global $config; - - if (!is_numeric ($date)) { - $date = strtotime ($date); - } - if (empty ($date)) { - $date = get_system_time (); - } - - $table->width = '99%'; - - $table->align = array(); - $table->align[0] = 'center'; - $table->align[2] = 'center'; - - $table->data = array (); - - $table->head = array (); - $table->head[0] = __('Status'); - $table->head[1] = __('Name'); - $table->head[2] = __('Type'); - $table->head[3] = __('Agent'); - $table->head[4] = __('Criticity'); - $table->head[5] = __('Val. by'); - $table->head[6] = __('Timestamp'); - - $events = events_get_group_events($id_group, $period, $date, - $filter_event_validated, $filter_event_critical, - $filter_event_warning, $filter_event_no_validated); - - if ($events) { - $note = ''; - if (count($events) >= 1000) { - $note .= '* ' . __('Maximum of events shown') . ' (1000)
'; - } - foreach ($events as $k => $event) { - //First pass along the class of this row - $table->cellclass[$k][1] = $table->cellclass[$k][3] = - $table->cellclass[$k][4] = $table->cellclass[$k][5] = - $table->cellclass[$k][6] = - 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, - "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['id_agente'])) - $data[] = agents_get_name($event['id_agente']); - else - $data[] = __('Pandora System'); - $data[] = get_priority_name ($event['criticity']); - if (empty($event['id_usuario']) && $event['estado'] == EVENT_VALIDATE) { - $data[] = '' . __('System') . ''; - } - else { - $user_name = db_get_value ('fullname', 'tusuario', 'id_user', $event['id_usuario']); - $data[] = io_safe_output($user_name); - } - $data[] = '' . - date($config['date_format'], $event['timestamp_rep']) . - ''; - array_push ($table->data, $data); - } - - if ($html) { - return html_print_table ($table, $return) . $note; - } - else { - return $table; - } - } - else { - return false; - } -} @@ -4379,158 +4400,7 @@ function reporting_render_report_html_item ($content, $table, $report, $mini = f break; - case 'event_report_group': - if (empty($item_title)) { - $item_title = __('Group detailed event'); - } - reporting_header_content($mini, $content, $report, $table, $item_title, - ui_print_truncate_text(groups_get_name($content['id_group'], true), 60, false)); - - $next_row = 1; - - // Put description at the end of the module (if exists) - if ($content["description"] != "") { - $data_desc = array(); - $data_desc[0] = $content["description"]; - array_push ($table->data, $data_desc); - $table->colspan[$next_row][0] = 3; - $next_row++; - } - - $data = array (); - - $style = json_decode(io_safe_output($content['style']), true); - - $filter_event_no_validated = $style['filter_event_no_validated']; - $filter_event_validated = $style['filter_event_validated']; - $filter_event_critical = $style['filter_event_critical']; - $filter_event_warning = $style['filter_event_warning']; - - $event_graph_by_agent = $style['event_graph_by_agent']; - $event_graph_by_user_validator = $style['event_graph_by_user_validator']; - $event_graph_by_criticity = $style['event_graph_by_criticity']; - $event_graph_validated_vs_unvalidated = $style['event_graph_validated_vs_unvalidated']; - - $data[0] = reporting_get_group_detailed_event( - $content['id_group'], $content['period'], - $report["datetime"], true, true, - $filter_event_validated, - $filter_event_critical, - $filter_event_warning, - $filter_event_no_validated); - if(!empty($data[0])) { - array_push ($table->data, $data); - - $table->colspan[$next_row][0] = 3; - $next_row++; - } - - if ($event_graph_by_agent) { - $data_graph = reporting_get_count_events_by_agent( - $content['id_group'], $content['period'], - $report["datetime"], - $filter_event_validated, - $filter_event_critical, - $filter_event_warning, - $filter_event_no_validated); - - $table_event_graph = null; - $table_event_graph->width = '100%'; - $table_event_graph->style[0] = 'text-align: center;'; - $table_event_graph->head[0] = __('Events by agent'); - - $table_event_graph->data[0][0] = pie3d_graph( - false, $data_graph, 500, 150, __("other"), "", - ui_get_full_url(false, false, false, false) . "/images/logo_vertical_water.png", - $config['fontpath'], $config['font_size']); - - $data[0] = html_print_table($table_event_graph, true); - - $table->colspan[$next_row][0] = 3; - $next_row++; - array_push ($table->data, $data); - } - - if ($event_graph_by_user_validator) { - $data_graph = reporting_get_count_events_validated_by_user( - array('id_group' => $content['id_group']), $content['period'], - $report["datetime"], - $filter_event_validated, - $filter_event_critical, - $filter_event_warning, - $filter_event_no_validated); - - $table_event_graph = null; - $table_event_graph->head[0] = __('Events validated by user'); - $table_event_graph->width = '100%'; - $table_event_graph->style[0] = 'text-align: center;'; - - $table_event_graph->data[0][0] = pie3d_graph( - false, $data_graph, 500, 150, __("other"), "", - ui_get_full_url(false, false, false, false) . "/images/logo_vertical_water.png", - $config['fontpath'], $config['font_size']); - - $data[0] = html_print_table($table_event_graph, true); - - $table->colspan[$next_row][0] = 3; - $next_row++; - array_push ($table->data, $data); - } - - if ($event_graph_by_criticity) { - $data_graph = reporting_get_count_events_by_criticity( - array('id_group' => $content['id_group']), $content['period'], - $report["datetime"], - $filter_event_validated, - $filter_event_critical, - $filter_event_warning, - $filter_event_no_validated); - - $colors = get_criticity_pie_colors($data_graph); - - $table_event_graph = null; - $table_event_graph->head[0] = __('Events by criticity'); - $table_event_graph->width = '100%'; - $table_event_graph->style[0] = 'text-align: center;'; - - $table_event_graph->data[0][0] = pie3d_graph( - false, $data_graph, 500, 150, __("other"), "", - ui_get_full_url(false, false, false, false) . "/images/logo_vertical_water.png", - $config['fontpath'], $config['font_size'], 1, false, $colors); - - $data[0] = html_print_table($table_event_graph, true); - - $table->colspan[$next_row][0] = 3; - $next_row++; - array_push ($table->data, $data); - } - - if ($event_graph_validated_vs_unvalidated) { - $data_graph = reporting_get_count_events_validated( - array('id_group' => $content['id_group']), $content['period'], - $report["datetime"], - $filter_event_validated, - $filter_event_critical, - $filter_event_warning, - $filter_event_no_validated); - - $table_event_graph = null; - $table_event_graph->head[0] = __('Amount events validated'); - $table_event_graph->width = '100%'; - $table_event_graph->style[0] = 'text-align: center;'; - - $table_event_graph->data[0][0] = pie3d_graph( - false, $data_graph, 500, 150, __("other"), "", - ui_get_full_url(false, false, false, false) . "/images/logo_vertical_water.png", - $config['fontpath'], $config['font_size']); - - $data[0] = html_print_table($table_event_graph, true); - - $table->colspan[$next_row][0] = 3; - $next_row++; - array_push ($table->data, $data); - } - break; + case 'top_n': $top_n = $content['top_n']; @@ -4942,7 +4812,8 @@ function reporting_template_graphs_get_user ($id_user = 0, $only_names = false, function reporting_get_count_events_by_agent ($id_group, $period = 0, $date = 0, $filter_event_validated = false, $filter_event_critical = false, - $filter_event_warning = false, $filter_event_no_validated = false) { + $filter_event_warning = false, $filter_event_no_validated = false, + $filter_event_filter_search = null) { if (!is_numeric ($date)) { $date = strtotime ($date); @@ -4953,7 +4824,8 @@ function reporting_get_count_events_by_agent ($id_group, $period = 0, return events_get_count_events_by_agent($id_group, $period, $date, $filter_event_validated, $filter_event_critical, - $filter_event_warning, $filter_event_no_validated); + $filter_event_warning, $filter_event_no_validated, + $filter_event_filter_search); } /** @@ -4970,7 +4842,8 @@ function reporting_get_count_events_by_agent ($id_group, $period = 0, function reporting_get_count_events_validated_by_user ($filter, $period = 0, $date = 0, $filter_event_validated = false, $filter_event_critical = false, - $filter_event_warning = false, $filter_event_no_validated = false) { + $filter_event_warning = false, $filter_event_no_validated = false, + $filter_event_search = false) { if (!is_numeric ($date)) { $date = strtotime ($date); @@ -4981,7 +4854,7 @@ function reporting_get_count_events_validated_by_user ($filter, $period = 0, return events_get_count_events_validated_by_user($filter, $period, $date, $filter_event_validated, $filter_event_critical, - $filter_event_warning, $filter_event_no_validated); + $filter_event_warning, $filter_event_no_validated, $filter_event_search); } /** @@ -4998,7 +4871,8 @@ function reporting_get_count_events_validated_by_user ($filter, $period = 0, function reporting_get_count_events_by_criticity ($filter, $period = 0, $date = 0, $filter_event_validated = false, $filter_event_critical = false, - $filter_event_warning = false, $filter_event_no_validated = false) { + $filter_event_warning = false, $filter_event_no_validated = false, + $filter_event_search = false) { if (!is_numeric ($date)) { $date = strtotime ($date); @@ -5009,7 +4883,8 @@ function reporting_get_count_events_by_criticity ($filter, $period = 0, return events_get_count_events_by_criticity($filter, $period, $date, $filter_event_validated, $filter_event_critical, - $filter_event_warning, $filter_event_no_validated); + $filter_event_warning, $filter_event_no_validated, + $filter_event_search); } /** @@ -5026,7 +4901,8 @@ function reporting_get_count_events_by_criticity ($filter, $period = 0, function reporting_get_count_events_validated ($filter, $period = 0, $date = 0, $filter_event_validated = false, $filter_event_critical = false, - $filter_event_warning = false, $filter_event_no_validated = false) { + $filter_event_warning = false, $filter_event_no_validated = false, + $filter_event_search = false) { if (!is_numeric ($date)) { $date = strtotime ($date); @@ -5037,7 +4913,8 @@ function reporting_get_count_events_validated ($filter, $period = 0, return events_get_count_events_validated($filter, $period, $date, $filter_event_validated, $filter_event_critical, - $filter_event_warning, $filter_event_no_validated); + $filter_event_warning, $filter_event_no_validated, + $filter_event_search); } function reporting_get_agents_by_status ($data, $graph_width = 250, $graph_height = 150, $links = false) { From 5c2b0c0549463d6ea6ab4e658c5b90a4285101eb Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Wed, 29 Apr 2015 16:14:39 +0200 Subject: [PATCH 52/80] Working in the refactoring the code of reports (top_n). --- .../include/functions_reporting.php | 340 +++++++++++++++ .../include/functions_reporting_html.php | 409 ++++-------------- 2 files changed, 414 insertions(+), 335 deletions(-) diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index 132ff434c0..a6425a2e3a 100644 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -405,12 +405,351 @@ function reporting_make_reporting_data($id_report, $date, $time, $report, $content); break; + case 'top_n': + $report['contents'][] = reporting_event_top_n( + $report, + $content, + $type, + $force_width_chart, + $force_height_chart); + break; } } return reporting_check_structure_report($report); } +function reporting_event_top_n($report, $content, $type = 'dinamic', + $force_width_chart = null, $force_height_chart = null) { + global $config; + + $return['type'] = 'top_n'; + + if (empty($content['name'])) { + $content['name'] = __('Top N'); + } + + $return['title'] = $content['name']; + $top_n = $content['top_n']; + + switch ($top_n) { + case REPORT_TOP_N_MAX: + $type_top_n = __('Max'); + break; + case REPORT_TOP_N_MIN: + $type_top_n = __('Min'); + break; + case REPORT_TOP_N_AVG: + default: + //If nothing is selected then it will be shown the average data + $type_top_n = __('Avg'); + break; + } + $return['subtitle'] = __('Top %d' ,$content['top_n_value']) . ' - ' . $type_top_n; + $return["description"] = $content["description"]; + $return["date"] = reporting_get_date_text($report, $content); + + + $order_uptodown = $content['order_uptodown']; + + $top_n_value = $content['top_n_value']; + $show_graph = $content['show_graph']; + + //Get all the related data + $sql = sprintf("SELECT id_agent_module, server_name + FROM treport_content_item + WHERE id_report_content = %d", $content['id_rc']); + + $tops = db_process_sql ($sql); + + // Get chart + reporting_set_conf_charts($width, $height, $only_image, $type, + $content, $ttl); + + if (!empty($force_width_chart)) { + $width = $force_width_chart; + } + + if (!empty($force_height_chart)) { + $height = $force_height_chart; + } + + + if (empty($tops)) { + $return['failed'] = __('There are no Agent/Modules defined'); + } + else { + $data_top = array(); + + foreach ($tops as $key => $row) { + + //Metaconsole connection + $server_name = $row['server_name']; + if (($config ['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE')) { + $connection = metaconsole_get_connection($server_name); + if (metaconsole_load_external_db($connection) != NOERR) { + //ui_print_error_message ("Error connecting to ".$server_name); + continue; + } + } + + $ag_name = modules_get_agentmodule_agent_name($row ['id_agent_module']); + $mod_name = modules_get_agentmodule_name ($row ['id_agent_module']); + $unit = db_get_value('unit', 'tagente_modulo', + 'id_agente_modulo', $row ['id_agent_module']); + + + switch ($top_n) { + case REPORT_TOP_N_MAX: + $value = reporting_get_agentmodule_data_max ($row['id_agent_module'], $content['period']); + break; + case REPORT_TOP_N_MIN: + $value = reporting_get_agentmodule_data_min ($row['id_agent_module'], $content['period']); + break; + case REPORT_TOP_N_AVG: + default: + //If nothing is selected then it will be shown the average data + $value = reporting_get_agentmodule_data_average ($row['id_agent_module'], $content['period']); + break; + } + + //If the returned value from modules_get_agentmodule_data_max/min/avg is false it won't be stored. + if ($value !== false) { + $data_top[$key] = $value; + $id_agent_module[$key] = $row['id_agent_module']; + $agent_name[$key] = $ag_name; + $module_name[$key] = $mod_name; + $units[$key] = $unit; + } + + //Restore dbconnection + if (($config ['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE')) { + metaconsole_restore_db(); + } + } + + if (empty($data_top)) { + $return['failed'] = __('Insuficient data'); + } + else { + $data_return = array(); + + //Order to show. + switch ($order_uptodown) { + //Descending + case 1: + array_multisort($data_top, SORT_DESC, $agent_name, SORT_ASC, $module_name, SORT_ASC, $id_agent_module, SORT_ASC, $units, SORT_ASC); + break; + //Ascending + case 2: + array_multisort($data_top, SORT_ASC, $agent_name, SORT_ASC, $module_name, SORT_ASC, $id_agent_module, SORT_ASC, $units, SORT_ASC); + break; + //By agent name or without selection + case 0: + case 3: + array_multisort($agent_name, SORT_ASC, $data_top, SORT_ASC, $module_name, SORT_ASC, $id_agent_module, SORT_ASC, $units, SORT_ASC); + break; + } + + array_splice ($data_top, $top_n_value); + array_splice ($agent_name, $top_n_value); + array_splice ($module_name, $top_n_value); + array_splice ($id_agent_module, $top_n_value); + array_splice ($units, $top_n_value); + + $data_top_values = array (); + $data_top_values['data_top'] = $data_top; + $data_top_values['agent_name'] = $agent_name; + $data_top_values['module_name'] = $module_name; + $data_top_values['id_agent_module'] = $id_agent_module; + $data_top_values['units'] = $units; + + // Define truncate size depends the graph width + $truncate_size = $width / (4 * ($config['font_size']))-1; + + if ($order_uptodown == 1 || $order_uptodown == 2) { + $i = 0; + $data_pie_graph = array(); + $data_hbar = array(); + foreach ($data_top as $dt) { + $item_name = ''; + $item_name = + ui_print_truncate_text($agent_name[$i], $truncate_size, false, true, false, "...") . + ' - ' . + ui_print_truncate_text($module_name[$i], $truncate_size, false, true, false, "..."); + + + + //Dirty hack, maybe I am going to apply a job in Apple + //https://www.imperialviolet.org/2014/02/22/applebug.html + $item_name_key_pie = $item_name; + $exist_key = true; + while ($exist_key) { + if (isset($data_pie_graph[$item_name_key_pie])) { + $item_name_key_pie .= ' '; + } + else { + $exist_key = false; + } + } + $item_name_key_hbar = $item_name; + $exist_key = true; + while ($exist_key) { + if (isset($data_hbar[$item_name_key_hbar])) { + $item_name_key_hbar = ' ' . $item_name_key_hbar; + } + else { + $exist_key = false; + } + } + + + + $data_hbar[$item_name]['g'] = $dt; + $data_pie_graph[$item_name] = $dt; + + if ($show_graph == 0 || $show_graph == 1) { + $data = array(); + $data['agent'] = $agent_name[$i]; + $data['module'] = $module_name[$i]; + + $data['value'] = $dt; + $data['formated_value'] = format_for_graph($dt,2) . " " . $units[$i]; + $data_return[] = $data; + } + $i++; + if ($i >= $top_n_value) break; + } + } + else if ($order_uptodown == 0 || $order_uptodown == 3) { + $i = 0; + $data_pie_graph = array(); + $data_hbar = array(); + foreach ($agent_name as $an) { + $item_name = ''; + $item_name = + ui_print_truncate_text($agent_name[$i], + $truncate_size, false, true, false, "...") . + ' - ' . + ui_print_truncate_text($module_name[$i], + $truncate_size, false, true, false, "..."); + + + + //Dirty hack, maybe I am going to apply a job in Apple + //https://www.imperialviolet.org/2014/02/22/applebug.html + $item_name_key_pie = $item_name; + $exist_key = true; + while ($exist_key) { + if (isset($data_pie_graph[$item_name_key_pie])) { + $item_name_key_pie .= ' '; + } + else { + $exist_key = false; + } + } + $item_name_key_hbar = $item_name; + $exist_key = true; + while ($exist_key) { + if (isset($data_hbar[$item_name_key_hbar])) { + $item_name_key_hbar = ' ' . $item_name_key_hbar; + } + else { + $exist_key = false; + } + } + + + + $data_pie_graph[$item_name] = $data_top[$i]; + $data_hbar[$item_name]['g'] = $data_top[$i]; + if ($show_graph == 0 || $show_graph == 1) { + $data = array(); + $data['agent'] = $an; + $data['module'] = $module_name[$i]; + $data['value'] = $data_top[$i]; + $data['formated_value'] = format_for_graph($data_top[$i],2) . " " . $units[$i]; + $data_return[] = $data; + } + $i++; + if ($i >= $top_n_value) break; + } + } + + + $return['chars']['bars'] = null; + $return['chars']['pie'] = null; + + + if ($show_graph != REPORT_TOP_N_ONLY_TABLE) { + + $return['chars']['pie'] = pie3d_graph(false, + $data_pie_graph, + $width, $height, __("other"), + ui_get_full_url(false, true, false, false) . '/', + ui_get_full_url(false, false, false, false) . "/images/logo_vertical_water.png", + $config['fontpath'], $config['font_size']); + + + //Display bars graph + $return['chars']['bars'] = hbar_graph( + false, $data_hbar, $width, + $height, array(), array(), "", "", true, + ui_get_full_url(false, true, false, false) . '/', $config['homedir'] . "/images/logo_vertical_water.png", $config['fontpath'], $config['font_size'], true, 1, true); + } + + $return['resume'] = null; + + if ($content['show_resume'] && count($data_top_values) > 0) { + //Get the very first not null value + $i=0; + do { + $min = $data_top_values['data_top'][$i]; + $i++; + } + while ($min === false && $i < count($data_top_values)); + $max = $min; + $avg = 0; + + $i=0; + foreach ($data_top_values['data_top'] as $key => $dtv) { + if ($dtv < $min) $min = $dtv; + if ($dtv > $max) $max = $dtv; + $avg += $dtv; + $i++; + } + $avg = $avg / $i; + + unset($table_summary); + + $table_summary->width = '99%'; + $table_summary->data = array (); + $table_summary->head = array (); + $table_summary->head[0] = __('Min Value'); + $table_summary->head[1] = __('Average Value'); + $table_summary->head[2] = __('Max Value'); + + $return['resume']['min']['value'] = $min; + $return['resume']['min']['formated_value'] = format_for_graph($min, 2); + $return['resume']['avg']['value'] = $avg; + $return['resume']['avg']['formated_value'] = format_for_graph($avg, 2); + $return['resume']['max']['value'] = $max; + $return['resume']['max']['formated_value'] = format_for_graph($max, 2); + + $table->colspan[5][0] = 3; + array_push ($table->data, array(''.__('Summary').'')); + $table->colspan[6][0] = 3; + array_push ($table->data, array(html_print_table($table_summary, true))); + } + + + $return['data'] = $data_return; + } + } + + return reporting_check_structure_content($return); +} + function reporting_event_report_group($report, $content) { global $config; @@ -736,6 +1075,7 @@ function reporting_agent_module($report, $content) { function reporting_exception($report, $content, $type = 'dinamic', $force_width_chart = null, $force_height_chart = null) { + global $config; $return['type'] = 'exception'; diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index a410eb5df8..5088e78099 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -252,6 +252,9 @@ function reporting_html_print_report($report, $mini = false) { case 'event_report_group': reporting_html_event_report_group($table, $item); break; + case 'top_n': + reporting_html_top_n($table, $item); + break; } if ($item['type'] == 'agent_module') @@ -264,6 +267,75 @@ function reporting_html_print_report($report, $mini = false) { } } +function reporting_html_top_n($table, $item) { + if (!empty($item['failed'])) { + $table->colspan['top_n']['cell'] = 3; + $table->data['top_n']['cell'] = $item['failed']; + } + else { + $table1->width = '99%'; + + $table1->align = array(); + $table1->align[0] = 'left'; + $table1->align[1] = 'left'; + $table1->align[2] = 'right'; + + $table1->data = array (); + + $table1->head = array (); + $table1->head[0] = __('Agent'); + $table1->head[1] = __('Module'); + $table1->head[2] = __('Value'); + + foreach ($item['data'] as $top) { + $row = array(); + $row[] = $top['agent']; + $row[] = $top['module']; + $row[] = $top['formated_value']; + $table1->data[] = $row; + } + + $table->colspan['top_n']['cell'] = 3; + $table->data['top_n']['cell'] = html_print_table($table1, true); + + if (!empty($item['chars']['pie'])) { + $table->colspan['char_pie']['cell'] = 3; + $table->data['char_pie']['cell'] = $item['chars']['pie']; + } + + if (!empty($item['chars']['bars'])) { + $table->colspan['char_bars']['cell'] = 3; + $table->data['char_bars']['cell'] = $item['chars']['bars']; + } + + if (!empty($item['resume'])) { + $table1 = null; + $table1->width = '99%'; + + $table1->align = array(); + $table1->align[0] = 'center'; + $table1->align[1] = 'center'; + $table1->align[2] = 'center'; + + $table1->data = array (); + + $table1->head = array (); + $table1->head[0] = __('Min Value'); + $table1->head[1] = __('Average Value'); + $table1->head[2] = __('Max Value'); + + $row = array(); + $row[] = $item['resume']['min']['formated_value']; + $row[] = $item['resume']['avg']['formated_value']; + $row[] = $item['resume']['max']['formated_value']; + $table1->data[] = $row; + + $table->colspan['resume']['cell'] = 3; + $table->data['resume']['cell'] = html_print_table($table1, true); + } + } +} + function reporting_html_event_report_group($table, $item) { global $config; @@ -288,7 +360,7 @@ function reporting_html_event_report_group($table, $item) { $table1->head[4] = __('Criticity'); $table1->head[5] = __('Val. by'); $table1->head[6] = __('Timestamp'); - + foreach ($item['data'] as $k => $event) { //First pass along the class of this row $table1->cellclass[$k][1] = $table1->cellclass[$k][3] = @@ -4402,340 +4474,7 @@ function reporting_render_report_html_item ($content, $table, $report, $mini = f - case 'top_n': - $top_n = $content['top_n']; - - switch ($top_n) { - case REPORT_TOP_N_MAX: - $type_top_n = __('Max'); - break; - case REPORT_TOP_N_MIN: - $type_top_n = __('Min'); - break; - case REPORT_TOP_N_AVG: - default: - //If nothing is selected then it will be shown the average data - $type_top_n = __('Avg'); - break; - } - - if (empty($item_title)) { - $item_title = 'Top '.$content['top_n_value'] . '
' . $type_top_n; - } - reporting_header_content($mini, $content, $report, $table, $item_title); - - $order_uptodown = $content['order_uptodown']; - - $top_n_value = $content['top_n_value']; - $show_graph = $content['show_graph']; - - $table->style[0] = 'padding: 8px 5px 8px 5px;'; - $table->style[1] = 'text-align: right'; - - // Put description at the end of the module (if exists) - $table->colspan[1][0] = 3; - if ($content["description"] != "") { - $data_desc = array(); - $data_desc[0] = $content["description"]; - array_push ($table->data, $data_desc); - } - //Get all the related data - $sql = sprintf("SELECT id_agent_module, server_name - FROM treport_content_item - WHERE id_report_content = %d", $content['id_rc']); - - $tops = db_process_sql ($sql); - - if ($tops === false) { - $data = array (); - $table->colspan[2][0] = 3; - $data[0] = __('There are no Agent/Modules defined'); - array_push ($table->data, $data); - break; - } - - if ($show_graph != REPORT_TOP_N_ONLY_GRAPHS) { - $table1->width = '99%'; - $table1->data = array (); - $table1->head = array (); - $table1->head[0] = __('Agent'); - $table1->head[1] = __('Module'); - $table1->head[2] = __('Value'); - $table1->style[0] = 'text-align: left'; - $table1->style[1] = 'text-align: left'; - $table1->style[2] = 'text-align: left'; - } - - //Get data of all agents (before to slide to N values) - $data_top = array(); - - foreach ($tops as $key => $row) { - - //Metaconsole connection - $server_name = $row['server_name']; - if (($config ['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE')) { - $connection = metaconsole_get_connection($server_name); - if (metaconsole_load_external_db($connection) != NOERR) { - //ui_print_error_message ("Error connecting to ".$server_name); - continue; - } - } - - $ag_name = modules_get_agentmodule_agent_name($row ['id_agent_module']); - $mod_name = modules_get_agentmodule_name ($row ['id_agent_module']); - $unit = db_get_value('unit', 'tagente_modulo', - 'id_agente_modulo', $row ['id_agent_module']); - - - switch ($top_n) { - case REPORT_TOP_N_MAX: - $value = reporting_get_agentmodule_data_max ($row['id_agent_module'], $content['period']); - break; - case REPORT_TOP_N_MIN: - $value = reporting_get_agentmodule_data_min ($row['id_agent_module'], $content['period']); - break; - case REPORT_TOP_N_AVG: - default: - //If nothing is selected then it will be shown the average data - $value = reporting_get_agentmodule_data_average ($row['id_agent_module'], $content['period']); - break; - } - - //If the returned value from modules_get_agentmodule_data_max/min/avg is false it won't be stored. - if ($value !== false) { - $data_top[$key] = $value; - $id_agent_module[$key] = $row['id_agent_module']; - $agent_name[$key] = $ag_name; - $module_name[$key] = $mod_name; - $units[$key] = $unit; - } - - //Restore dbconnection - if (($config ['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE')) { - metaconsole_restore_db(); - } - } - - if (empty($data_top)) { - $data = array (); - $table->colspan[2][0] = 3; - $data[0] = __('Insuficient data'); - array_push ($table->data, $data); - break; - } - - //Order to show. - switch ($order_uptodown) { - //Descending - case 1: - array_multisort($data_top, SORT_DESC, $agent_name, SORT_ASC, $module_name, SORT_ASC, $id_agent_module, SORT_ASC, $units, SORT_ASC); - break; - //Ascending - case 2: - array_multisort($data_top, SORT_ASC, $agent_name, SORT_ASC, $module_name, SORT_ASC, $id_agent_module, SORT_ASC, $units, SORT_ASC); - break; - //By agent name or without selection - case 0: - case 3: - array_multisort($agent_name, SORT_ASC, $data_top, SORT_ASC, $module_name, SORT_ASC, $id_agent_module, SORT_ASC, $units, SORT_ASC); - break; - } - - array_splice ($data_top, $top_n_value); - array_splice ($agent_name, $top_n_value); - array_splice ($module_name, $top_n_value); - array_splice ($id_agent_module, $top_n_value); - array_splice ($units, $top_n_value); - - $data_top_values = array (); - $data_top_values['data_top'] = $data_top; - $data_top_values['agent_name'] = $agent_name; - $data_top_values['module_name'] = $module_name; - $data_top_values['id_agent_module'] = $id_agent_module; - $data_top_values['units'] = $units; - - // Define truncate size depends the graph width - $truncate_size = $sizgraph_w / (4 * ($config['font_size']))-1; - - if ($order_uptodown == 1 || $order_uptodown == 2) { - $i = 0; - $data_pie_graph = array(); - $data_hbar = array(); - foreach ($data_top as $dt) { - $item_name = ''; - $item_name = - ui_print_truncate_text($agent_name[$i], $truncate_size, false, true, false, "...") . - ' - ' . - ui_print_truncate_text($module_name[$i], $truncate_size, false, true, false, "..."); - - - - //Dirty hack, maybe I am going to apply a job in Apple - //https://www.imperialviolet.org/2014/02/22/applebug.html - $item_name_key_pie = $item_name; - $exist_key = true; - while ($exist_key) { - if (isset($data_pie_graph[$item_name_key_pie])) { - $item_name_key_pie .= ' '; - } - else { - $exist_key = false; - } - } - $item_name_key_hbar = $item_name; - $exist_key = true; - while ($exist_key) { - if (isset($data_hbar[$item_name_key_hbar])) { - $item_name_key_hbar = ' ' . $item_name_key_hbar; - } - else { - $exist_key = false; - } - } - - - - $data_hbar[$item_name]['g'] = $dt; - $data_pie_graph[$item_name] = $dt; - - if ($show_graph == 0 || $show_graph == 1) { - $data = array(); - $data[0] = $agent_name[$i]; - $data[1] = $module_name[$i]; - - $data[2] = format_for_graph($dt,2) . " " . $units[$i]; - array_push ($table1->data, $data); - } - $i++; - if ($i >= $top_n_value) break; - } - } - else if ($order_uptodown == 0 || $order_uptodown == 3) { - $i = 0; - $data_pie_graph = array(); - $data_hbar = array(); - foreach ($agent_name as $an) { - $item_name = ''; - $item_name = - ui_print_truncate_text($agent_name[$i], - $truncate_size, false, true, false, "...") . - ' - ' . - ui_print_truncate_text($module_name[$i], - $truncate_size, false, true, false, "..."); - - - - //Dirty hack, maybe I am going to apply a job in Apple - //https://www.imperialviolet.org/2014/02/22/applebug.html - $item_name_key_pie = $item_name; - $exist_key = true; - while ($exist_key) { - if (isset($data_pie_graph[$item_name_key_pie])) { - $item_name_key_pie .= ' '; - } - else { - $exist_key = false; - } - } - $item_name_key_hbar = $item_name; - $exist_key = true; - while ($exist_key) { - if (isset($data_hbar[$item_name_key_hbar])) { - $item_name_key_hbar = ' ' . $item_name_key_hbar; - } - else { - $exist_key = false; - } - } - - - - $data_pie_graph[$item_name] = $data_top[$i]; - $data_hbar[$item_name]['g'] = $data_top[$i]; - if ($show_graph == 0 || $show_graph == 1) { - $data = array(); - $data[0] = $an; - $data[1] = $module_name[$i]; - $data[2] = format_for_graph($data_top[$i],2) . " " . $units[$i]; - array_push ($table1->data, $data); - } - $i++; - if ($i >= $top_n_value) break; - } - } - - unset($data); - $table->colspan[2][0] = 3; - $table->style[2] = 'text-align:center'; - if ($show_graph == 0 || $show_graph == 1) { - $data = array(); - $data[0] = html_print_table($table1, true); - array_push ($table->data, $data); - } - - $table->colspan[3][0] = 3; - $data = array(); - if ($show_graph != REPORT_TOP_N_ONLY_TABLE) { - - $data[0] = pie3d_graph(false, $data_pie_graph, - $sizgraph_w, $sizgraph_h, __("other"), - ui_get_full_url(false, true, false, false) . '/', - ui_get_full_url(false, false, false, false) . "/images/logo_vertical_water.png", - $config['fontpath'], $config['font_size']); - - - array_push ($table->data, $data); - //Display bars graph - $table->colspan[4][0] = 3; - $table->style[0] .= 'text-align:center'; - $height = count($data_pie_graph)*20+35; - $data = array(); - $data[0] = hbar_graph(false, $data_hbar, $sizgraph_w, - $height, array(), array(), "", "", true, - ui_get_full_url(false, true, false, false) . '/', $config['homedir'] . "/images/logo_vertical_water.png", $config['fontpath'], $config['font_size'], true, 1, true); - - array_push ($table->data, $data); - } - - if ($content['show_resume'] && count($data_top_values) > 0) { - //Get the very first not null value - $i=0; - do { - $min = $data_top_values['data_top'][$i]; - $i++; - } - while ($min === false && $i < count($data_top_values)); - $max = $min; - $avg = 0; - - $i=0; - foreach ($data_top_values['data_top'] as $key => $dtv) { - if ($dtv < $min) $min = $dtv; - if ($dtv > $max) $max = $dtv; - $avg += $dtv; - $i++; - } - $avg = $avg / $i; - - unset($table_summary); - - $table_summary->width = '99%'; - $table_summary->data = array (); - $table_summary->head = array (); - $table_summary->head[0] = __('Min Value'); - $table_summary->head[1] = __('Average Value'); - $table_summary->head[2] = __('Max Value'); - - $table_summary->data[0][0] = format_for_graph($min, 2); - $table_summary->data[0][1] = format_for_graph($avg, 2); - $table_summary->data[0][2] = format_for_graph($max, 2); - - $table->colspan[5][0] = 3; - array_push ($table->data, array(''.__('Summary').'')); - $table->colspan[6][0] = 3; - array_push ($table->data, array(html_print_table($table_summary, true))); - } - break; + } From 3a74ee9f1533ed715bfb19f172c5466198065791 Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Wed, 29 Apr 2015 19:05:06 +0200 Subject: [PATCH 53/80] Working in the refactoring the code of reports (SLA). --- .../include/functions_reporting.php | 423 ++++++++++- .../include/functions_reporting_html.php | 665 ++++-------------- 2 files changed, 538 insertions(+), 550 deletions(-) diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index a6425a2e3a..df5c2c352b 100644 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -413,14 +413,424 @@ function reporting_make_reporting_data($id_report, $date, $time, $force_width_chart, $force_height_chart); break; + case 'SLA': + $report['contents'][] = reporting_SLA( + $report, + $content, + $type, + $force_width_chart, + $force_height_chart); + break; } } return reporting_check_structure_report($report); } +function reporting_SLA($report, $content, $type = 'dinamic', + $force_width_chart = null, $force_height_chart = null) { + + global $config; + + $return['type'] = 'SLA'; + + if (empty($content['name'])) { + $content['name'] = __('S.L.A.'); + } + + $return['title'] = $content['name']; + $return["description"] = $content["description"]; + $return["date"] = reporting_get_date_text($report, $content); + + + + $edge_interval = 10; + + $slas = db_get_all_rows_field_filter ( + 'treport_content_sla_combined', + 'id_report_content', $content['id_rc']); + + if (empty($slas)) { + $return['failed'] = __('There are no SLAs defined'); + } + else { + + // What show? + $show_table = $content['show_graph'] == 0 || $content['show_graph'] == 1; + $show_graphs = $content['show_graph'] == 1 || $content['show_graph'] == 2; + + + // Table Planned Downtimes + require_once ($config['homedir'] . '/include/functions_planned_downtimes.php'); + $metaconsole_on = ($config['metaconsole'] == 1) && defined('METACONSOLE'); + $downtime_malformed = false; + + $planned_downtimes_empty = true; + $malformed_planned_downtimes_empty = true; + + $return['planned_downtimes'] = array(); + + if ($metaconsole_on) { + $id_agent_modules_by_server = array(); + + foreach ($slas as $sla) { + $server = $sla['server_name']; + if (empty($server)) + continue; + + if (!isset($id_agent_modules_by_server[$server])) + $id_agent_modules_by_server[$server] = array(); + + $id_agent_modules_by_server[$server][] = $sla['id_agent_module']; + } + + $planned_downtimes_by_server = array(); + $malformed_planned_downtimes_by_server = array(); + foreach ($id_agent_modules_by_server as $server => $id_agent_modules) { + //Metaconsole connection + if (!empty($server)) { + $connection = metaconsole_get_connection($server); + if (!metaconsole_load_external_db($connection)) { + continue; + } + + $planned_downtimes_by_server[$server] = reporting_get_planned_downtimes(($report['datetime']-$content['period']), $report['datetime'], $id_agent_modules); + $malformed_planned_downtimes_by_server[$server] = planned_downtimes_get_malformed(); + + if (!empty($planned_downtimes_by_server[$server])) + $planned_downtimes_empty = false; + if (!empty($malformed_planned_downtimes_by_server[$server])) + $malformed_planned_downtimes_empty = false; + + //Restore db connection + metaconsole_restore_db(); + } + } + + if (!$planned_downtimes_empty) { + foreach ($planned_downtimes_by_server as $server => $planned_downtimes) { + foreach ($planned_downtimes as $planned_downtime) { + $data = array(); + $data['server'] = $server; + $data['name'] = $planned_downtime['name']; + $data['description'] = $planned_downtime['description']; + $data['execution'] = ucfirst($planned_downtime['type_execution']); + $data['dates'] = ""; + switch ($planned_downtime['type_execution']) { + case 'once': + $data['dates'] = date ("Y-m-d H:i", $planned_downtime['date_from']) . + " " . __('to') . " ". + date ("Y-m-d H:i", $planned_downtime['date_to']); + break; + case 'periodically': + switch ($planned_downtime['type_periodicity']) { + case 'weekly': + $data['dates'] = __('Weekly:'); + $data['dates'] .= " "; + if ($planned_downtime['monday']) { + $data['dates'] .= __('Mon'); + $data['dates'] .= " "; + } + if ($planned_downtime['tuesday']) { + $data['dates'] .= __('Tue'); + $data['dates'] .= " "; + } + if ($planned_downtime['wednesday']) { + $data['dates'] .= __('Wed'); + $data['dates'] .= " "; + } + if ($planned_downtime['thursday']) { + $data['dates'] .= __('Thu'); + $data['dates'] .= " "; + } + if ($planned_downtime['friday']) { + $data['dates'] .= __('Fri'); + $data['dates'] .= " "; + } + if ($planned_downtime['saturday']) { + $data['dates'] .= __('Sat'); + $data['dates'] .= " "; + } + if ($planned_downtime['sunday']) { + $data['dates'] .= __('Sun'); + $data['dates'] .= " "; + } + $data['dates'] .= " (" . $planned_downtime['periodically_time_from']; + $data['dates'] .= "-" . $planned_downtime['periodically_time_to'] . ")"; + break; + case 'monthly': + $data['dates'] = __('Monthly:') . " "; + $data['dates'] .= __('From day') . " " . $planned_downtime['periodically_day_from']; + $data['dates'] .= " " . strtolower(__('To day')) . " "; + $data['dates'] .= $planned_downtime['periodically_day_to']; + $data['dates'] .= " (" . $planned_downtime['periodically_time_from']; + $data['dates'] .= "-" . $planned_downtime['periodically_time_to'] . ")"; + break; + } + break; + } + + $data['malformed'] = 0; + if (!$malformed_planned_downtimes_empty + && isset($malformed_planned_downtimes_by_server[$server]) + && isset($malformed_planned_downtimes_by_server[$server][$planned_downtime['id']])) { + + $data['malformed'] = 1; + + if (!$downtime_malformed) + $downtime_malformed = true; + } + + $return['planned_downtimes'][] = $data; + } + } + } + } + else { + $id_agent_modules = array(); + foreach ($slas as $sla) { + if (!empty($sla['id_agent_module'])) + $id_agent_modules[] = $sla['id_agent_module']; + } + + $planned_downtimes = reporting_get_planned_downtimes(($report['datetime']-$content['period']), $report['datetime'], $id_agent_modules); + $malformed_planned_downtimes = planned_downtimes_get_malformed(); + + if (!empty($planned_downtimes)) + $planned_downtimes_empty = false; + if (!empty($malformed_planned_downtimes)) + $malformed_planned_downtimes_empty = false; + + if (!$planned_downtimes_empty) { + foreach ($planned_downtimes as $planned_downtime) { + + $data = array(); + $data['name'] = $planned_downtime['name']; + $data['description'] = $planned_downtime['description']; + $data['execution'] = ucfirst($planned_downtime['type_execution']); + $data['dates'] = ""; + switch ($planned_downtime['type_execution']) { + case 'once': + $data['dates'] = date ("Y-m-d H:i", $planned_downtime['date_from']) . + " " . __('to') . " ". + date ("Y-m-d H:i", $planned_downtime['date_to']); + break; + case 'periodically': + switch ($planned_downtime['type_periodicity']) { + case 'weekly': + $data['dates'] = __('Weekly:'); + $data['dates'] .= " "; + if ($planned_downtime['monday']) { + $data['dates'] .= __('Mon'); + $data['dates'] .= " "; + } + if ($planned_downtime['tuesday']) { + $data['dates'] .= __('Tue'); + $data['dates'] .= " "; + } + if ($planned_downtime['wednesday']) { + $data['dates'] .= __('Wed'); + $data['dates'] .= " "; + } + if ($planned_downtime['thursday']) { + $data['dates'] .= __('Thu'); + $data['dates'] .= " "; + } + if ($planned_downtime['friday']) { + $data['dates'] .= __('Fri'); + $data['dates'] .= " "; + } + if ($planned_downtime['saturday']) { + $data['dates'] .= __('Sat'); + $data['dates'] .= " "; + } + if ($planned_downtime['sunday']) { + $data['dates'] .= __('Sun'); + $data['dates'] .= " "; + } + $data['dates'] .= " (" . $planned_downtime['periodically_time_from']; + $data['dates'] .= "-" . $planned_downtime['periodically_time_to'] . ")"; + break; + case 'monthly': + $data['dates'] = __('Monthly:') . " "; + $data['dates'] .= __('From day') . " " . $planned_downtime['periodically_day_from']; + $data['dates'] .= " " . strtolower(__('To day')) . " "; + $data['dates'] .= $planned_downtime['periodically_day_to']; + $data['dates'] .= " (" . $planned_downtime['periodically_time_from']; + $data['dates'] .= "-" . $planned_downtime['periodically_time_to'] . ")"; + break; + } + break; + } + + $data['malformed'] = 0; + if (!$malformed_planned_downtimes_empty && isset($malformed_planned_downtimes[$planned_downtime['id']])) { + $data['malformed'] = 1; + if (!$downtime_malformed) + $downtime_malformed = true; + } + + $return['planned_downtimes'][] = $data; + } + } + } + + if ($downtime_malformed) { + $return['failed'] = + __('This item is affected by a malformed planned downtime. Go to the planned downtimes section to solve this.'); + } + else { + + + $urlImage = ui_get_full_url(false, true, false, false); + + $sla_failed = false; + $total_SLA = 0; + $total_result_SLA = 'ok'; + $sla_showed = array(); + $sla_showed_values = array(); + + foreach ($slas as $sla) { + $server_name = $sla ['server_name']; + //Metaconsole connection + if (($config ['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE')) { + $connection = metaconsole_get_connection($server_name); + if (!metaconsole_load_external_db($connection)) { + //ui_print_error_message ("Error connecting to ".$server_name); + continue; + } + } + + if (modules_is_disable_agent($sla['id_agent_module'])) { + continue; + } + + //Get the sla_value in % and store it on $sla_value + $sla_value = reporting_get_agentmodule_sla( + $sla['id_agent_module'], $content['period'], + $sla['sla_min'], $sla['sla_max'], + $report["datetime"], $content, + $content['time_from'], $content['time_to']); + + if (($config ['metaconsole'] == 1) && defined('METACONSOLE')) { + //Restore db connection + metaconsole_restore_db(); + } + + //Do not show right modules if 'only_display_wrong' is active + if ($content['only_display_wrong'] == 1 && + $sla_value >= $sla['sla_limit']) { + + continue; + } + + $sla_showed[] = $sla; + $sla_showed_values[] = $sla_value; + + } + + // SLA items sorted descending () + if ($content['top_n'] == 2) { + arsort($sla_showed_values); + } + // SLA items sorted ascending + else if ($content['top_n'] == 1) { + asort($sla_showed_values); + } + } + + $return['data'] = array(); + $return['charts'] = null; + + foreach ($sla_showed_values as $k => $sla_value) { + $sla = $sla_showed[$k]; + + $server_name = $sla ['server_name']; + //Metaconsole connection + if (($config ['metaconsole'] == 1) && ($server_name != '') && defined('METACONSOLE')) { + $connection = metaconsole_get_connection($server_name); + if (metaconsole_connect($connection) != NOERR) { + continue; + } + } + + $total_SLA += $sla_value; + + if ($show_table) { + $data = array (); + $data['agent'] = modules_get_agentmodule_agent_name ($sla['id_agent_module']); + $data['module'] = modules_get_agentmodule_name ($sla['id_agent_module']); + $data['max'] = $sla['sla_max']; + $data['min'] = $sla['sla_min']; + $data['sla_limit'] = $sla['sla_limit']; + + $data['sla_value_unknown'] = 0; + $data['sla_status'] = 0; + $data['sla_value'] = 0; + if ($sla_value === false) { + $data['sla_value_unknown'] = 1; + } + else { + + if ($sla_value >= $sla['sla_limit']) { + $data['sla_status'] = 1; + } + else { + $sla_failed = true; + $data['sla_status'] = 0; + } + + // Print icon with status including edge + # Fix : 100% accurance is 'inside limits' although 10% was not overrun + // if (($sla_value == 100 && $sla_value >= $sla['sla_limit']) || ($sla_value > ($sla['sla_limit'] + $edge_interval))) { + // $data[6] = html_print_image('images/status_sets/default/severity_normal.png',true,array('title'=>__('Inside limits'))); + // } + // elseif (($sla_value <= $sla['sla_limit'] + $edge_interval) + // && ($sla_value >= $sla['sla_limit'] - $edge_interval)) { + // $data[6] = html_print_image('images/status_sets/default/severity_warning.png',true,array('title'=>__('On the edge'))); + // } + // else { + // $data[6] = html_print_image('images/status_sets/default/severity_critical.png',true,array('title'=>__('Out of limits'))); + // } + + $data['sla_value'] = $sla_value; + $data['sla_formated_value'] = format_numeric ($sla_value, 2). "%"; + } + + $return['data'][] = $data; + } + + + // Slice graphs calculation + if ($show_graphs) { + $dataslice = array(); + $dataslice['agent'] = modules_get_agentmodule_agent_name ($sla['id_agent_module']); + $dataslice['module'] = modules_get_agentmodule_name ($sla['id_agent_module']); + + $dataslice['chart'] = graph_sla_slicebar( + $sla['id_agent_module'], $content['period'], + $sla['sla_min'], $sla['sla_max'], + $report['datetime'], $content, $content['time_from'], + $content['time_to'], 650, 25, $urlImage, 1, false, false); + + $return['charts'][] = $dataslice; + } + + if ($config ['metaconsole'] == 1 && defined('METACONSOLE')) { + //Restore db connection + metaconsole_restore_db(); + } + } + + + } + + return reporting_check_structure_content($return); +} + function reporting_event_top_n($report, $content, $type = 'dinamic', $force_width_chart = null, $force_height_chart = null) { + global $config; $return['type'] = 'top_n'; @@ -677,13 +1087,13 @@ function reporting_event_top_n($report, $content, $type = 'dinamic', } - $return['chars']['bars'] = null; - $return['chars']['pie'] = null; + $return['charts']['bars'] = null; + $return['charts']['pie'] = null; if ($show_graph != REPORT_TOP_N_ONLY_TABLE) { - $return['chars']['pie'] = pie3d_graph(false, + $return['charts']['pie'] = pie3d_graph(false, $data_pie_graph, $width, $height, __("other"), ui_get_full_url(false, true, false, false) . '/', @@ -692,7 +1102,7 @@ function reporting_event_top_n($report, $content, $type = 'dinamic', //Display bars graph - $return['chars']['bars'] = hbar_graph( + $return['charts']['bars'] = hbar_graph( false, $data_hbar, $width, $height, array(), array(), "", "", true, ui_get_full_url(false, true, false, false) . '/', $config['homedir'] . "/images/logo_vertical_water.png", $config['fontpath'], $config['font_size'], true, 1, true); @@ -735,11 +1145,6 @@ function reporting_event_top_n($report, $content, $type = 'dinamic', $return['resume']['avg']['formated_value'] = format_for_graph($avg, 2); $return['resume']['max']['value'] = $max; $return['resume']['max']['formated_value'] = format_for_graph($max, 2); - - $table->colspan[5][0] = 3; - array_push ($table->data, array(''.__('Summary').'')); - $table->colspan[6][0] = 3; - array_push ($table->data, array(html_print_table($table_summary, true))); } diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index 5088e78099..dec0a34429 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -255,6 +255,9 @@ function reporting_html_print_report($report, $mini = false) { case 'top_n': reporting_html_top_n($table, $item); break; + case 'SLA': + reporting_html_SLA($table, $item, $mini); + break; } if ($item['type'] == 'agent_module') @@ -267,6 +270,123 @@ function reporting_html_print_report($report, $mini = false) { } } +function reporting_html_SLA($table, $item, $mini) { + if ($mini) { + $font_size = '1.5'; + } + else { + $font_size = '3'; + } + + if (!empty($item['failed'])) { + $table->colspan['sla']['cell'] = 3; + $table->data['sla']['cell'] = $item['failed']; + } + else { + + if (!empty($item['planned_downtimes'])) { + $table1->width = '99%'; + + $table1->align = array(); + $table1->align[0] = 'left'; + $table1->align[1] = 'left'; + $table1->align[2] = 'left'; + $table1->align[3] = 'left'; + + $table1->data = array (); + + $table1->head = array (); + $table1->head[0] = __('Name'); + $table1->head[1] = __('Description'); + $table1->head[2] = __('Execution'); + $table1->head[3] = __('Dates'); + + foreach ($item['planned_downtimes'] as $downtime) { + $row = array(); + $row[] = $downtime['name']; + $row[] = $downtime['description']; + $row[] = $downtime['execution']; + $row[] = $downtime['dates']; + + $table1->data[] = $row; + } + + $table->colspan['planned_downtime']['cell'] = 3; + $table->data['planned_downtime']['cell'] = html_print_table($table1, true); + } + + $table1->width = '99%'; + + $table1->align = array(); + $table1->align[0] = 'left'; + $table1->align[1] = 'left'; + $table1->align[2] = 'right'; + $table1->align[3] = 'right'; + $table1->align[4] = 'right'; + $table1->align[5] = 'right'; + + $table1->data = array (); + + $table1->head = array (); + $table1->head[0] = __('Agent'); + $table1->head[1] = __('Module'); + $table1->head[2] = __('Max/Min Values'); + $table1->head[3] = __('SLA Limit'); + $table1->head[4] = __('SLA Compliance'); + $table1->head[5] = __('Status'); + + + + foreach ($item['data'] as $sla) { + $row = array(); + $row[] = $sla['agent']; + $row[] = $sla['module']; + $row[] = $sla['max'] . " / " . $sla['min']; + $row[] = $sla['sla_limit'] . "%"; + + if ($sla['sla_value_unknown']) { + $row[] = '' . + ' - ' . ''; + $row[] = '' . + __('Unknown') . ''; + } + elseif ($sla['sla_status']) { + $row[] = '' . + $sla['sla_value'] . "%" . ''; + $row[] = '' . + __('OK') . ''; + } + else { + $row[] = '' . + $sla['sla_value'] . "%" . ''; + $row[] = '' . + __('Fail') . ''; + } + + $table1->data[] = $row; + } + + $table->colspan['sla']['cell'] = 3; + $table->data['sla']['cell'] = html_print_table($table1, true); + + if (!empty($item['charts'])) { + $table1 = null; + $table1->width = '99%'; + + $table1->data = array (); + + foreach ($item['charts'] as $chart) { + $table1->data[] = array( + $chart['agent'] . "
" . $chart['module'], + $chart['chart']); + } + + $table->colspan['charts']['cell'] = 3; + $table->data['charts']['cell'] = html_print_table($table1, true); + } + } +} + function reporting_html_top_n($table, $item) { if (!empty($item['failed'])) { $table->colspan['top_n']['cell'] = 3; @@ -298,14 +418,14 @@ function reporting_html_top_n($table, $item) { $table->colspan['top_n']['cell'] = 3; $table->data['top_n']['cell'] = html_print_table($table1, true); - if (!empty($item['chars']['pie'])) { + if (!empty($item['charts']['pie'])) { $table->colspan['char_pie']['cell'] = 3; - $table->data['char_pie']['cell'] = $item['chars']['pie']; + $table->data['char_pie']['cell'] = $item['charts']['pie']; } - if (!empty($item['chars']['bars'])) { + if (!empty($item['charts']['bars'])) { $table->colspan['char_bars']['cell'] = 3; - $table->data['char_bars']['cell'] = $item['chars']['bars']; + $table->data['char_bars']['cell'] = $item['charts']['bars']; } if (!empty($item['resume'])) { @@ -3933,543 +4053,6 @@ function reporting_render_report_html_item ($content, $table, $report, $mini = f if (function_exists("reporting_enterprise_sla_services")) reporting_enterprise_sla_services($mini, $content, $report, $table, $item_title); break; - case 3: - case 'SLA': - if (empty($item_title)) { - $item_title = __('S.L.A.'); - } - reporting_header_content($mini, $content, $report, $table, $item_title); - - $edge_interval = 10; - - // What show? - $show_table = $content['show_graph'] == 0 || $content['show_graph'] == 1; - $show_graphs = $content['show_graph'] == 1 || $content['show_graph'] == 2; - - //RUNNING - $table->style[1] = 'text-align: right'; - - // Put description at the end of the module (if exists) - - $table->colspan[0][1] = 2; - $next_row = 1; - if ($content["description"] != "") { - $table->colspan[$next_row][0] = 3; - $next_row++; - $data_desc = array(); - $data_desc[0] = $content["description"]; - array_push ($table->data, $data_desc); - } - - $slas = db_get_all_rows_field_filter ('treport_content_sla_combined', - 'id_report_content', $content['id_rc']); - - if ($slas === false) { - $data = array (); - $table->colspan[$next_row][0] = 3; - $next_row++; - $data[0] = __('There are no SLAs defined'); - array_push ($table->data, $data); - $slas = array (); - break; - } - elseif ($show_table) { - $table1->width = '99%'; - $table1->data = array (); - $table1->head = array (); - $table1->head[0] = __('Agent'); - $table1->head[1] = __('Module'); - $table1->head[2] = __('Max/Min Values'); - $table1->head[3] = __('SLA Limit'); - $table1->head[4] = __('SLA Compliance'); - $table1->head[5] = __('Status'); - // $table1->head[6] = __('Criticity'); - $table1->style[0] = 'text-align: left'; - $table1->style[1] = 'text-align: left'; - $table1->style[2] = 'text-align: right'; - $table1->style[3] = 'text-align: right'; - $table1->style[4] = 'text-align: right'; - $table1->style[5] = 'text-align: right'; - // $table1->style[6] = 'text-align: center'; - } - - // Table Planned Downtimes - require_once ($config['homedir'] . '/include/functions_planned_downtimes.php'); - $metaconsole_on = ($config['metaconsole'] == 1) && defined('METACONSOLE'); - $downtime_malformed = false; - - $planned_downtimes_empty = true; - $malformed_planned_downtimes_empty = true; - - if ($metaconsole_on) { - $id_agent_modules_by_server = array(); - - foreach ($slas as $sla) { - $server = $sla['server_name']; - if (empty($server)) - continue; - - if (!isset($id_agent_modules_by_server[$server])) - $id_agent_modules_by_server[$server] = array(); - - $id_agent_modules_by_server[$server][] = $sla['id_agent_module']; - } - - $planned_downtimes_by_server = array(); - $malformed_planned_downtimes_by_server = array(); - foreach ($id_agent_modules_by_server as $server => $id_agent_modules) { - //Metaconsole connection - if (!empty($server)) { - $connection = metaconsole_get_connection($server); - if (!metaconsole_load_external_db($connection)) { - continue; - } - - $planned_downtimes_by_server[$server] = reporting_get_planned_downtimes(($report['datetime']-$content['period']), $report['datetime'], $id_agent_modules); - $malformed_planned_downtimes_by_server[$server] = planned_downtimes_get_malformed(); - - if (!empty($planned_downtimes_by_server[$server])) - $planned_downtimes_empty = false; - if (!empty($malformed_planned_downtimes_by_server[$server])) - $malformed_planned_downtimes_empty = false; - - //Restore db connection - metaconsole_restore_db(); - } - } - - if (!$planned_downtimes_empty) { - $table_planned_downtimes = new StdClass(); - $table_planned_downtimes->width = '100%'; - $table_planned_downtimes->title = __('This SLA has been affected by the following planned downtimes'); - $table_planned_downtimes->head = array(); - $table_planned_downtimes->head[0] = __('Server'); - $table_planned_downtimes->head[1] = __('Name'); - $table_planned_downtimes->head[2] = __('Description'); - $table_planned_downtimes->head[3] = __('Execution'); - $table_planned_downtimes->head[4] = __('Dates'); - $table_planned_downtimes->headstyle = array(); - $table_planned_downtimes->style = array(); - $table_planned_downtimes->cellstyle = array(); - $table_planned_downtimes->data = array(); - - foreach ($planned_downtimes_by_server as $server => $planned_downtimes) { - foreach ($planned_downtimes as $planned_downtime) { - $data = array(); - $data[0] = $server; - $data[1] = $planned_downtime['name']; - $data[2] = $planned_downtime['description']; - $data[3] = ucfirst($planned_downtime['type_execution']); - $data[4] = ""; - switch ($planned_downtime['type_execution']) { - case 'once': - $data[3] = date ("Y-m-d H:i", $planned_downtime['date_from']) . - " " . __('to') . " ". - date ("Y-m-d H:i", $planned_downtime['date_to']); - break; - case 'periodically': - switch ($planned_downtime['type_periodicity']) { - case 'weekly': - $data[4] = __('Weekly:'); - $data[4] .= " "; - if ($planned_downtime['monday']) { - $data[4] .= __('Mon'); - $data[4] .= " "; - } - if ($planned_downtime['tuesday']) { - $data[4] .= __('Tue'); - $data[4] .= " "; - } - if ($planned_downtime['wednesday']) { - $data[4] .= __('Wed'); - $data[4] .= " "; - } - if ($planned_downtime['thursday']) { - $data[4] .= __('Thu'); - $data[4] .= " "; - } - if ($planned_downtime['friday']) { - $data[4] .= __('Fri'); - $data[4] .= " "; - } - if ($planned_downtime['saturday']) { - $data[4] .= __('Sat'); - $data[4] .= " "; - } - if ($planned_downtime['sunday']) { - $data[4] .= __('Sun'); - $data[4] .= " "; - } - $data[4] .= " (" . $planned_downtime['periodically_time_from']; - $data[4] .= "-" . $planned_downtime['periodically_time_to'] . ")"; - break; - case 'monthly': - $data[4] = __('Monthly:') . " "; - $data[4] .= __('From day') . " " . $planned_downtime['periodically_day_from']; - $data[4] .= " " . strtolower(__('To day')) . " "; - $data[4] .= $planned_downtime['periodically_day_to']; - $data[4] .= " (" . $planned_downtime['periodically_time_from']; - $data[4] .= "-" . $planned_downtime['periodically_time_to'] . ")"; - break; - } - break; - } - - if (!$malformed_planned_downtimes_empty - && isset($malformed_planned_downtimes_by_server[$server]) - && isset($malformed_planned_downtimes_by_server[$server][$planned_downtime['id']])) { - $next_row_num = count($table_planned_downtimes->data); - $table_planned_downtimes->cellstyle[$next_row_num][0] = 'color: red'; - $table_planned_downtimes->cellstyle[$next_row_num][1] = 'color: red'; - $table_planned_downtimes->cellstyle[$next_row_num][2] = 'color: red'; - $table_planned_downtimes->cellstyle[$next_row_num][3] = 'color: red'; - $table_planned_downtimes->cellstyle[$next_row_num][4] = 'color: red'; - - if (!$downtime_malformed) - $downtime_malformed = true; - } - - $table_planned_downtimes->data[] = $data; - } - } - } - } - else { - $id_agent_modules = array(); - foreach ($slas as $sla) { - if (!empty($sla['id_agent_module'])) - $id_agent_modules[] = $sla['id_agent_module']; - } - - $planned_downtimes = reporting_get_planned_downtimes(($report['datetime']-$content['period']), $report['datetime'], $id_agent_modules); - $malformed_planned_downtimes = planned_downtimes_get_malformed(); - - if (!empty($planned_downtimes)) - $planned_downtimes_empty = false; - if (!empty($malformed_planned_downtimes)) - $malformed_planned_downtimes_empty = false; - - if (!$planned_downtimes_empty) { - $table_planned_downtimes = new StdClass(); - $table_planned_downtimes->width = '100%'; - $table_planned_downtimes->title = __('This SLA has been affected by the following planned downtimes'); - $table_planned_downtimes->head = array(); - $table_planned_downtimes->head[0] = __('Name'); - $table_planned_downtimes->head[1] = __('Description'); - $table_planned_downtimes->head[2] = __('Execution'); - $table_planned_downtimes->head[3] = __('Dates'); - $table_planned_downtimes->headstyle = array(); - $table_planned_downtimes->style = array(); - $table_planned_downtimes->cellstyle = array(); - $table_planned_downtimes->data = array(); - - foreach ($planned_downtimes as $planned_downtime) { - - $data = array(); - $data[0] = $planned_downtime['name']; - $data[1] = $planned_downtime['description']; - $data[2] = ucfirst($planned_downtime['type_execution']); - $data[3] = ""; - switch ($planned_downtime['type_execution']) { - case 'once': - $data[3] = date ("Y-m-d H:i", $planned_downtime['date_from']) . - " " . __('to') . " ". - date ("Y-m-d H:i", $planned_downtime['date_to']); - break; - case 'periodically': - switch ($planned_downtime['type_periodicity']) { - case 'weekly': - $data[3] = __('Weekly:'); - $data[3] .= " "; - if ($planned_downtime['monday']) { - $data[3] .= __('Mon'); - $data[3] .= " "; - } - if ($planned_downtime['tuesday']) { - $data[3] .= __('Tue'); - $data[3] .= " "; - } - if ($planned_downtime['wednesday']) { - $data[3] .= __('Wed'); - $data[3] .= " "; - } - if ($planned_downtime['thursday']) { - $data[3] .= __('Thu'); - $data[3] .= " "; - } - if ($planned_downtime['friday']) { - $data[3] .= __('Fri'); - $data[3] .= " "; - } - if ($planned_downtime['saturday']) { - $data[3] .= __('Sat'); - $data[3] .= " "; - } - if ($planned_downtime['sunday']) { - $data[3] .= __('Sun'); - $data[3] .= " "; - } - $data[3] .= " (" . $planned_downtime['periodically_time_from']; - $data[3] .= "-" . $planned_downtime['periodically_time_to'] . ")"; - break; - case 'monthly': - $data[3] = __('Monthly:') . " "; - $data[3] .= __('From day') . " " . $planned_downtime['periodically_day_from']; - $data[3] .= " " . strtolower(__('To day')) . " "; - $data[3] .= $planned_downtime['periodically_day_to']; - $data[3] .= " (" . $planned_downtime['periodically_time_from']; - $data[3] .= "-" . $planned_downtime['periodically_time_to'] . ")"; - break; - } - break; - } - - if (!$malformed_planned_downtimes_empty && isset($malformed_planned_downtimes[$planned_downtime['id']])) { - $next_row_num = count($table_planned_downtimes->data); - $table_planned_downtimes->cellstyle[$next_row_num][0] = 'color: red'; - $table_planned_downtimes->cellstyle[$next_row_num][1] = 'color: red'; - $table_planned_downtimes->cellstyle[$next_row_num][2] = 'color: red'; - $table_planned_downtimes->cellstyle[$next_row_num][3] = 'color: red'; - - if (!$downtime_malformed) - $downtime_malformed = true; - } - - $table_planned_downtimes->data[] = $data; - } - } - } - - if ($downtime_malformed) { - $info_malformed = ui_print_error_message( - __('This item is affected by a malformed planned downtime') . ". " . - __('Go to the planned downtimes section to solve this') . ".", '', true); - - $data = array(); - $data[0] = $info_malformed; - $data[0] .= html_print_table($table_planned_downtimes, true); - $table->colspan[$next_row][0] = 3; - $next_row++; - array_push ($table->data, $data); - break; - } - - $data_graph = array (); - // $data_horin_graph = array(); - $data_graph[__('Inside limits')] = 0; - $data_graph[__('Out of limits')] = 0; - $data_graph[__('On the edge')] = 0; - $data_graph[__('Unknown')] = 0; - // $data_horin_graph[__('Inside limits')] = 0; - // $data_horin_graph[__('Out of limits')] = 0; - // $data_horin_graph[__('On the edge')] = 0; - // $data_horin_graph[__('Unknown')] = 0; - - $data_graph[__('Plannified downtime')] = 0; - - $urlImage = ui_get_full_url(false, true, false, false); - - $sla_failed = false; - $total_SLA = 0; - $total_result_SLA = 'ok'; - $sla_showed = array(); - $sla_showed_values = array(); - - foreach ($slas as $sla) { - $server_name = $sla ['server_name']; - //Metaconsole connection - if (($config ['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE')) { - $connection = metaconsole_get_connection($server_name); - if (!metaconsole_load_external_db($connection)) { - //ui_print_error_message ("Error connecting to ".$server_name); - continue; - } - } - - if (modules_is_disable_agent($sla['id_agent_module'])) { - continue; - } - - //Get the sla_value in % and store it on $sla_value - $sla_value = reporting_get_agentmodule_sla( - $sla['id_agent_module'], $content['period'], - $sla['sla_min'], $sla['sla_max'], - $report["datetime"], $content, - $content['time_from'], $content['time_to']); - - if (($config ['metaconsole'] == 1) && defined('METACONSOLE')) { - //Restore db connection - metaconsole_restore_db(); - } - - //Do not show right modules if 'only_display_wrong' is active - if ($content['only_display_wrong'] == 1 && - $sla_value >= $sla['sla_limit']) { - - continue; - } - - $sla_showed[] = $sla; - $sla_showed_values[] = $sla_value; - - } - - // SLA items sorted descending () - if ($content['top_n'] == 2) { - arsort($sla_showed_values); - } - // SLA items sorted ascending - else if ($content['top_n'] == 1) { - asort($sla_showed_values); - } - - // Slice graphs calculation - if ($show_graphs && !empty($slas)) { - $tableslice->width = '99%'; - $tableslice->style[0] = 'text-align: right'; - $tableslice->data = array (); - } - - foreach ($sla_showed_values as $k => $sla_value) { - $sla = $sla_showed[$k]; - - $server_name = $sla ['server_name']; - //Metaconsole connection - if (($config ['metaconsole'] == 1) && ($server_name != '') && defined('METACONSOLE')) { - $connection = metaconsole_get_connection($server_name); - if (metaconsole_connect($connection) != NOERR) { - //ui_print_error_message ("Error connecting to ".$server_name); - continue; - } - } - - //Fill the array data_graph for the pie graph - // if ($sla_value === false) { - // $data_graph[__('Unknown')]++; - // // $data_horin_graph[__('Unknown')]['g']++; - // } - // # Fix : 100% accurance is 'inside limits' although 10% was not overrun - // else if (($sla_value == 100 && $sla_value >= $sla['sla_limit']) ) { - // $data_graph[__('Inside limits')]++; - // $data_horin_graph[__('Inside limits')]['g']++; - // } - // else if ($sla_value <= ($sla['sla_limit']+10) && $sla_value >= ($sla['sla_limit']-10)) { - // $data_graph[__('On the edge')]++; - // $data_horin_graph[__('On the edge')]['g']++; - // } - // else if ($sla_value > ($sla['sla_limit']+10)) { - // $data_graph[__('Inside limits')]++; - // $data_horin_graph[__('Inside limits')]['g']++; - // } - // else if ($sla_value < ($sla['sla_limit']-10)) { - // $data_graph[__('Out of limits')]++; - // $data_horin_graph[__('Out of limits')]['g']++; - // } - - // if ($sla_value === false) { - // if ($total_result_SLA != 'fail') - // $total_result_SLA = 'unknown'; - // } - // else if ($sla_value < $sla['sla_limit']) { - // $total_result_SLA = 'fail'; - // } - - $total_SLA += $sla_value; - - if ($show_table) { - $data = array (); - $data[0] = modules_get_agentmodule_agent_name ($sla['id_agent_module']); - $data[1] = modules_get_agentmodule_name ($sla['id_agent_module']); - $data[2] = $sla['sla_max'].'/'; - $data[2] .= $sla['sla_min']; - $data[3] = $sla['sla_limit'].'%'; - - if ($sla_value === false) { - $data[4] = ''; - $data[5] = ''.__('Unknown').''; - // $data[6] = html_print_image('images/status_sets/default/severity_maintenance.png',true,array('title'=>__('Unknown'))); - } - else { - $data[4] = ''; - $data[5] = ''; - // $data[6] = ''; - - if ($sla_value >= $sla['sla_limit']) { - $data[4] = ''; - $data[5] = ''.__('OK').''; - } - else { - $sla_failed = true; - $data[4] = ''; - $data[5] = ''.__('Fail').''; - } - - // Print icon with status including edge - # Fix : 100% accurance is 'inside limits' although 10% was not overrun - // if (($sla_value == 100 && $sla_value >= $sla['sla_limit']) || ($sla_value > ($sla['sla_limit'] + $edge_interval))) { - // $data[6] = html_print_image('images/status_sets/default/severity_normal.png',true,array('title'=>__('Inside limits'))); - // } - // elseif (($sla_value <= $sla['sla_limit'] + $edge_interval) - // && ($sla_value >= $sla['sla_limit'] - $edge_interval)) { - // $data[6] = html_print_image('images/status_sets/default/severity_warning.png',true,array('title'=>__('On the edge'))); - // } - // else { - // $data[6] = html_print_image('images/status_sets/default/severity_critical.png',true,array('title'=>__('Out of limits'))); - // } - - $data[4] .= format_numeric ($sla_value, 2). "%"; - } - $data[4] .= ""; - - array_push ($table1->data, $data); - } - - // Slice graphs calculation - if ($show_graphs) { - $dataslice = array(); - $dataslice[0] = modules_get_agentmodule_agent_name ($sla['id_agent_module']); - $dataslice[0] .= "
"; - $dataslice[0] .= modules_get_agentmodule_name ($sla['id_agent_module']); - - $dataslice[1] = graph_sla_slicebar ($sla['id_agent_module'], $content['period'], - $sla['sla_min'], $sla['sla_max'], $report['datetime'], $content, $content['time_from'], - $content['time_to'], 650, 25, $urlImage, 1, false, false); - - array_push ($tableslice->data, $dataslice); - } - - if ($config ['metaconsole'] == 1 && defined('METACONSOLE')) { - //Restore db connection - metaconsole_restore_db(); - } - } - - if ($show_table) { - $data = array(); - $data[0] = html_print_table($table1, true); - $table->colspan[$next_row][0] = 3; - $next_row++; - array_push ($table->data, $data); - } - - // $data = array(); - // $data_pie_graph = json_encode ($data_graph); - if ($show_graphs && !empty($slas)) { - $table->colspan[$next_row][0] = 3; - $next_row++; - $data = array(); - $data[0] = html_print_table($tableslice, true); - array_push ($table->data, $data); - } - - if (!empty($table_planned_downtimes)) { - $data = array(); - $data[0] = html_print_table($table_planned_downtimes, true); - $table->colspan[$next_row][0] = 3; - $next_row++; - array_push ($table->data, $data); - } - break; From 5545e4e6161a29228cfa53f87d06ece13fc663cf Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Thu, 30 Apr 2015 16:48:10 +0200 Subject: [PATCH 54/80] Fixed the SLA form editor for to set graphs. TICKET: #2172 (cherry picked from commit e1e64b1a54c58713ff93319f6a15a11ffb355546) --- pandora_console/godmode/reporting/reporting_builder.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pandora_console/godmode/reporting/reporting_builder.php b/pandora_console/godmode/reporting/reporting_builder.php index 4b727b17e7..73f31bd922 100644 --- a/pandora_console/godmode/reporting/reporting_builder.php +++ b/pandora_console/godmode/reporting/reporting_builder.php @@ -849,6 +849,8 @@ switch ($action) { $values['top_n'] = get_parameter('combo_sla_sort_options',0); $values['top_n_value'] = get_parameter('quantity'); $values['text'] = get_parameter('text'); + $values['show_graph'] = get_parameter('combo_graph_options'); + $good_format = true; break; case 'inventory': @@ -1083,6 +1085,8 @@ switch ($action) { $values['top_n'] = get_parameter('combo_sla_sort_options',0); $values['top_n_value'] = get_parameter('quantity'); $values['text'] = get_parameter('text'); + $values['show_graph'] = get_parameter('combo_graph_options'); + $good_format = true; break; case 'inventory': From c2fdcbb1d837d18ca01e013e3a7b1a6e0734f4fe Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Tue, 5 May 2015 13:15:10 +0200 Subject: [PATCH 55/80] Working in the refactoring the code of reports (SLA_monthly). --- pandora_console/include/functions_reporting.php | 8 ++++++++ pandora_console/include/functions_reporting_html.php | 7 +++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index df5c2c352b..3cffabf170 100644 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -421,6 +421,14 @@ function reporting_make_reporting_data($id_report, $date, $time, $force_width_chart, $force_height_chart); break; + case 'SLA_monthly': + $report['contents'][] = reporting_enterprise_sla_monthly_refactoriced( + $report, + $content); + break; + case 'SLA_services': + + break; } } diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index dec0a34429..81a53319e3 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -258,6 +258,9 @@ function reporting_html_print_report($report, $mini = false) { case 'SLA': reporting_html_SLA($table, $item, $mini); break; + case 'SLA_monthly': + reporting_enterprise_html_SLA_monthly($table, $item, $mini); + break; } if ($item['type'] == 'agent_module') @@ -4045,10 +4048,6 @@ function reporting_render_report_html_item ($content, $table, $report, $mini = f $item_title = $content['name']; switch ($content["type"]) { - case 'SLA_monthly': - if (function_exists("reporting_enterprise_sla_monthly")) - reporting_enterprise_sla_monthly($mini, $content, $report, $table, $item_title); - break; case 'SLA_services': if (function_exists("reporting_enterprise_sla_services")) reporting_enterprise_sla_services($mini, $content, $report, $table, $item_title); From 249e2e730d59d00b74b46e966d233f4180456cc5 Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Wed, 6 May 2015 13:24:29 +0200 Subject: [PATCH 56/80] Working in the refactoring the code of reports (SLA_services). --- pandora_console/include/functions_reporting.php | 7 ++++++- .../include/functions_reporting_html.php | 16 +++------------- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index 3cffabf170..b1a9dcc3a4 100644 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -427,7 +427,12 @@ function reporting_make_reporting_data($id_report, $date, $time, $content); break; case 'SLA_services': - + $report['contents'][] = reporting_enterprise_sla_services_refactoriced( + $report, + $content, + $type, + $force_width_chart, + $force_height_chart); break; } } diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index 81a53319e3..8840793a78 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -261,6 +261,9 @@ function reporting_html_print_report($report, $mini = false) { case 'SLA_monthly': reporting_enterprise_html_SLA_monthly($table, $item, $mini); break; + case 'SLA_services': + reporting_enterprise_html_SLA_services($table, $item, $mini); + break; } if ($item['type'] == 'agent_module') @@ -4047,19 +4050,6 @@ function reporting_render_report_html_item ($content, $table, $report, $mini = f $item_title = $content['name']; - switch ($content["type"]) { - case 'SLA_services': - if (function_exists("reporting_enterprise_sla_services")) - reporting_enterprise_sla_services($mini, $content, $report, $table, $item_title); - break; - - - - - - - - } //Restore dbconnection if (($config ['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE') && $remote_connection == 1) { metaconsole_restore_db_force(); From 94313bb24927291b0655b5fa29a8c80d87f70aaf Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Wed, 6 May 2015 16:28:57 +0200 Subject: [PATCH 57/80] Fixed the lost default parameter in the function. --- pandora_console/include/functions_reports.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pandora_console/include/functions_reports.php b/pandora_console/include/functions_reports.php index 4b366b92e7..d06899952f 100644 --- a/pandora_console/include/functions_reports.php +++ b/pandora_console/include/functions_reports.php @@ -82,7 +82,10 @@ function reports_get_report ($id_report, $filter = false, $fields = false) { * * @return array An array with all the reports the user can view. */ -function reports_get_reports ($filter = false, $fields = false, $returnAllGroup = true, $privileges = 'RR', $group = false, $strict_user) { +function reports_get_reports ($filter = false, $fields = false, + $returnAllGroup = true, $privileges = 'RR', $group = false, + $strict_user = false) { + global $config; if (! is_array ($filter)) From c7108cce464d57cd2aa387dbbae48b26797218e5 Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Wed, 6 May 2015 16:31:10 +0200 Subject: [PATCH 58/80] Changes in the code for the report in the dashboard. --- .../include/functions_reporting.php | 448 ++++++++++++++++ .../include/functions_reporting_html.php | 491 ------------------ .../operation/reporting/reporting_viewer.php | 63 --- 3 files changed, 448 insertions(+), 554 deletions(-) diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index b1a9dcc3a4..a1d08bf995 100644 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -3993,10 +3993,13 @@ function reporting_set_conf_charts(&$width, &$height, &$only_image, $type, } } +//////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// // MAYBE MOVE THE NEXT FUNCTIONS TO A FILE NAMED AS FUNCTION_REPORTING.UTILS.PHP // //////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////// /** @@ -5748,4 +5751,449 @@ function reporting_tiny_stats ($counts_info, $return = false, $type = 'agent', $ echo $out; } } + + +/** + * Get SLA of a module. + * + * @param int Agent module to calculate SLA + * @param int Period to check the SLA compliance. + * @param int Minimum data value the module in the right interval + * @param int Maximum data value the module in the right interval. False will + * ignore max value + * @param int Beginning date of the report in UNIX time (current date by default). + * @param array $dayWeek Array of days week to extract as array('monday' => false, 'tuesday' => true....), and by default is null. + * @param string $timeFrom Time in the day to start to extract in mysql format, by default null. + * @param string $timeTo Time in the day to end to extract in mysql format, by default null. + * + * @return float SLA percentage of the requested module. False if no data were + * found + */ +function reporting_get_agentmodule_sla ($id_agent_module, $period = 0, + $min_value = 1, $max_value = false, $date = 0, $daysWeek = null, + $timeFrom = null, $timeTo = null) { + + global $config; + + if (empty($id_agent_module)) + return false; + + // Set initial conditions + $bad_period = 0; + // Limit date to start searching data + $datelimit = $date - $period; + $search_in_history_db = db_search_in_history_db($datelimit); + + // Initialize variables + if (empty ($date)) { + $date = get_system_time (); + } + if ($daysWeek === null) { + $daysWeek = array(); + } + + + // Calculate the SLA for large time without hours + if ($timeFrom == $timeTo) { + // Get interval data + $sql = sprintf ('SELECT * + FROM tagente_datos + 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 + if ($daysWeek) { + foreach ($daysWeek as $key => $value) { + if (!$value) { + if ($key == 'monday') { + $days[] = 2; + } + if ($key == 'tuesday') { + $days[] = 3; + } + if ($key == 'wednesday') { + $days[] = 4; + } + if ($key == 'thursday') { + $days[] = 5; + } + if ($key == 'friday') { + $days[] = 6; + } + if ($key == 'saturday') { + $days[] = 7; + } + if ($key == 'sunday') { + $days[] = 1; + } + } + } + } + + if (count($days) > 0) { + $sql .= ' AND DAYOFWEEK(FROM_UNIXTIME(utimestamp)) NOT IN (' . implode(',', $days) . ')'; + } + + $sql .= "\n"; + $sql .= ' ORDER BY utimestamp ASC'; + $interval_data = db_get_all_rows_sql ($sql, $search_in_history_db); + + if ($interval_data === false) { + $interval_data = array (); + } + + // Calculate planned downtime dates + $downtime_dates = reporting_get_planned_downtimes_intervals($id_agent_module, $datelimit, $date); + + // Get previous data + $previous_data = modules_get_previous_data ($id_agent_module, $datelimit); + + if ($previous_data !== false) { + $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) { + $next_data['utimestamp'] = $date; + array_push ($interval_data, $next_data); + } + else if (count ($interval_data) > 0) { + // Propagate the last known data to the end of the interval + $next_data = array_pop ($interval_data); + array_push ($interval_data, $next_data); + $next_data['utimestamp'] = $date; + array_push ($interval_data, $next_data); + } + + if (count ($interval_data) < 2) { + return false; + } + + + $first_data = array_shift ($interval_data); + + // Do not count the empty start of an interval as 0 + if ($first_data['utimestamp'] != $datelimit) { + $period = $date - $first_data['utimestamp']; + } + + $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; + } + } + } + else { + $previous_status = 0; + } + + + + + + foreach ($interval_data as $data) { + // Previous status was critical + if ($previous_status == 1) { + $bad_period += $data['utimestamp'] - $previous_utimestamp; + } + + if (array_key_exists('datos', $data)) { + // Re-calculate previous status for the next data + if ((($max_value > $min_value AND ($data['datos'] > $max_value OR $data['datos'] < $min_value))) OR + ($max_value <= $min_value AND $data['datos'] < $min_value)) { + + $previous_status = 1; + foreach ($downtime_dates as $date_dt) { + if (($date_dt['date_from'] <= $data['utimestamp']) AND ($date_dt['date_to'] >= $data['utimestamp'])) { + $previous_status = 0; + } + } + } + else { + $previous_status = 0; + } + } + + $previous_utimestamp = $data['utimestamp']; + } + + // Return the percentage of SLA compliance + return (float) (100 - ($bad_period / $period) * 100); + } + elseif ($period <= SECONDS_1DAY) { + + + return reporting_get_agentmodule_sla_day( + $id_agent_module, + $period, + $min_value, + $max_value, + $date, + $daysWeek, + $timeFrom, + $timeTo); + } + else { + // Extract the data each day + + $sla = 0; + + $i = 0; + for ($interval = 0; $interval <= $period; $interval = $interval + SECONDS_1DAY) { + $datelimit = $date - $interval; + + $sla_day = reporting_get_agentmodule_sla( + $id_agent_module, + SECONDS_1DAY, + $min_value, + $max_value, + $datelimit + $interval, + $daysWeek, + $timeFrom, $timeTo); + + + $sla += $sla_day; + $i++; + } + + $sla = $sla / $i; + + return $sla; + } +} + + +/** + * Get the time intervals where an agentmodule is affected by the planned downtimes. + * + * @param int Agent module to calculate planned downtimes intervals. + * @param int Start date in utimestamp. + * @param int End date in utimestamp. + * @param bool Whether ot not to get the planned downtimes that affect the service associated with the agentmodule. + * + * @return Array with time intervals. + */ +function reporting_get_planned_downtimes_intervals ($id_agent_module, $start_date, $end_date, $check_services = false) { + global $config; + + if (empty($id_agent_module)) + return false; + + require_once ($config['homedir'] . '/include/functions_planned_downtimes.php'); + + $malformed_planned_downtimes = planned_downtimes_get_malformed(); + if (empty($malformed_planned_downtimes)) + $malformed_planned_downtimes = array(); + + $sql_downtime = "SELECT DISTINCT(tpdr.id), tpdr.* + FROM ( + SELECT tpd.* + FROM tplanned_downtime tpd, tplanned_downtime_agents tpda, tagente_modulo tam + WHERE tpd.id = tpda.id_downtime + AND tpda.all_modules = 1 + AND tpda.id_agent = tam.id_agente + AND tam.id_agente_modulo = $id_agent_module + UNION ALL + SELECT tpd.* + FROM tplanned_downtime tpd, tplanned_downtime_modules tpdm + WHERE tpd.id = tpdm.id_downtime + AND tpdm.id_agent_module = $id_agent_module + ) tpdr + ORDER BY tpdr.id"; + + $downtimes = db_get_all_rows_sql($sql_downtime); + + if ($downtimes == false) { + $downtimes = array(); + } + $downtime_dates = array(); + foreach ($downtimes as $downtime) { + $downtime_id = $downtime['id']; + $downtime_type = $downtime['type_execution']; + $downtime_periodicity = $downtime['type_periodicity']; + + if ($downtime_type == 'once') { + $dates = array(); + $dates['date_from'] = $downtime['date_from']; + $dates['date_to'] = $downtime['date_to']; + $downtime_dates[] = $dates; + } + else if ($downtime_type == 'periodically') { + + // If a planned downtime have malformed dates, its intervals aren't taken account + $downtime_malformed = false; + foreach ($malformed_planned_downtimes as $malformed_planned_downtime) { + if ($downtime_id == $malformed_planned_downtime['id']) { + $downtime_malformed = true; + break; + } + } + if ($downtime_malformed == true) { + continue; + } + // If a planned downtime have malformed dates, its intervals aren't taken account + + $downtime_time_from = $downtime['periodically_time_from']; + $downtime_time_to = $downtime['periodically_time_to']; + + $downtime_hour_from = date("H", strtotime($downtime_time_from)); + $downtime_minute_from = date("i", strtotime($downtime_time_from)); + $downtime_second_from = date("s", strtotime($downtime_time_from)); + $downtime_hour_to = date("H", strtotime($downtime_time_to)); + $downtime_minute_to = date("i", strtotime($downtime_time_to)); + $downtime_second_to = date("s", strtotime($downtime_time_to)); + + if ($downtime_periodicity == "monthly") { + $downtime_day_from = $downtime['periodically_day_from']; + $downtime_day_to = $downtime['periodically_day_to']; + + $date_aux = strtotime(date("Y-m-01", $start_date)); + $year_aux = date("Y", $date_aux); + $month_aux = date("m", $date_aux); + + $end_year = date("Y", $end_date); + $end_month = date("m", $end_date); + + while ($year_aux < $end_year || ($year_aux == $end_year && $month_aux <= $end_month)) { + + if ($downtime_day_from > $downtime_day_to) { + $dates = array(); + $dates['date_from'] = strtotime("$year_aux-$month_aux-$downtime_day_from $downtime_hour_from:$downtime_minute_from:$downtime_second_from"); + $dates['date_to'] = strtotime(date("Y-m-t H:i:s", strtotime("$year_aux-$month_aux-28 23:59:59"))); + $downtime_dates[] = $dates; + + $dates = array(); + if ($month_aux + 1 <= 12) { + $dates['date_from'] = strtotime("$year_aux-".($month_aux + 1)."-01 00:00:00"); + $dates['date_to'] = strtotime("$year_aux-".($month_aux + 1)."-$downtime_day_to $downtime_hour_to:$downtime_minute_to:$downtime_second_to"); + } + else { + $dates['date_from'] = strtotime(($year_aux + 1)."-01-01 00:00:00"); + $dates['date_to'] = strtotime(($year_aux + 1)."-01-$downtime_day_to $downtime_hour_to:$downtime_minute_to:$downtime_second_to"); + } + $downtime_dates[] = $dates; + } + else { + if ($downtime_day_from == $downtime_day_to && strtotime($downtime_time_from) > strtotime($downtime_time_to)) { + $date_aux_from = strtotime("$year_aux-$month_aux-$downtime_day_from $downtime_hour_from:$downtime_minute_from:$downtime_second_from"); + $max_day_num = date('t', $date_aux); + + $dates = array(); + $dates['date_from'] = strtotime("$year_aux-$month_aux-$downtime_day_from $downtime_hour_from:$downtime_minute_from:$downtime_second_from"); + $dates['date_to'] = strtotime("$year_aux-$month_aux-$downtime_day_from 23:59:59"); + $downtime_dates[] = $dates; + + if ($downtime_day_to + 1 > $max_day_num) { + + $dates = array(); + if ($month_aux + 1 <= 12) { + $dates['date_from'] = strtotime("$year_aux-".($month_aux + 1)."-01 00:00:00"); + $dates['date_to'] = strtotime("$year_aux-".($month_aux + 1)."-01 $downtime_hour_to:$downtime_minute_to:$downtime_second_to"); + } + else { + $dates['date_from'] = strtotime(($year_aux + 1)."-01-01 00:00:00"); + $dates['date_to'] = strtotime(($year_aux + 1)."-01-01 $downtime_hour_to:$downtime_minute_to:$downtime_second_to"); + } + $downtime_dates[] = $dates; + } + else { + $dates = array(); + $dates['date_from'] = strtotime("$year_aux-$month_aux-".($downtime_day_to + 1)." 00:00:00"); + $dates['date_to'] = strtotime("$year_aux-$month_aux-".($downtime_day_to + 1)." $downtime_hour_to:$downtime_minute_to:$downtime_second_to"); + $downtime_dates[] = $dates; + } + } + else { + $dates = array(); + $dates['date_from'] = strtotime("$year_aux-$month_aux-$downtime_day_from $downtime_hour_from:$downtime_minute_from:$downtime_second_from"); + $dates['date_to'] = strtotime("$year_aux-$month_aux-$downtime_day_to $downtime_hour_to:$downtime_minute_to:$downtime_second_to"); + $downtime_dates[] = $dates; + } + } + + $month_aux++; + if ($month_aux > 12) { + $month_aux = 1; + $year_aux++; + } + } + } + else if ($downtime_periodicity == "weekly") { + $date_aux = $start_date; + $active_days = array(); + $active_days[0] = ($downtime['sunday'] == 1) ? true : false; + $active_days[1] = ($downtime['monday'] == 1) ? true : false; + $active_days[2] = ($downtime['tuesday'] == 1) ? true : false; + $active_days[3] = ($downtime['wednesday'] == 1) ? true : false; + $active_days[4] = ($downtime['thursday'] == 1) ? true : false; + $active_days[5] = ($downtime['friday'] == 1) ? true : false; + $active_days[6] = ($downtime['saturday'] == 1) ? true : false; + + while ($date_aux <= $end_date) { + $weekday_num = date('w', $date_aux); + + if ($active_days[$weekday_num]) { + $day_num = date('d', $date_aux); + $month_num = date('m', $date_aux); + $year_num = date('Y', $date_aux); + + $max_day_num = date('t', $date_aux); + + if (strtotime($downtime_time_from) > strtotime($downtime_time_to)) { + $dates = array(); + $dates['date_from'] = strtotime("$year_num-$month_num-$day_num $downtime_hour_from:$downtime_minute_from:$downtime_second_from"); + $dates['date_to'] = strtotime("$year_num-$month_num-$day_num 23:59:59"); + $downtime_dates[] = $dates; + + $dates = array(); + if ($day_num + 1 > $max_day_num) { + if ($month_num + 1 > 12) { + $dates['date_from'] = strtotime(($year_num + 1)."-01-01 00:00:00"); + $dates['date_to'] = strtotime(($year_num + 1)."-01-01 $downtime_hour_to:$downtime_minute_to:$downtime_second_to"); + } + else { + $dates['date_from'] = strtotime("$year_num-".($month_num + 1)."-01 00:00:00"); + $dates['date_to'] = strtotime("$year_num-".($month_num + 1)."-01 $downtime_hour_to:$downtime_minute_to:$downtime_second_to"); + } + } + else { + $dates['date_from'] = strtotime("$year_num-$month_num-".($day_num + 1)." 00:00:00"); + $dates['date_to'] = strtotime("$year_num-$month_num-".($day_num + 1)." $downtime_hour_to:$downtime_minute_to:$downtime_second_to"); + } + $downtime_dates[] = $dates; + } + else { + $dates = array(); + $dates['date_from'] = strtotime("$year_num-$month_num-$day_num $downtime_hour_from:$downtime_minute_from:$downtime_second_from"); + $dates['date_to'] = strtotime("$year_num-$month_num-$day_num $downtime_hour_to:$downtime_minute_to:$downtime_second_to"); + $downtime_dates[] = $dates; + } + } + + $date_aux += SECONDS_1DAY; + } + } + } + } + + if ($check_services) { + enterprise_include_once("include/functions_services.php"); + if (function_exists("services_get_planned_downtimes_intervals")) { + services_get_planned_downtimes_intervals($downtime_dates, $start_date, $end_date, false, $id_agent_module); + } + } + + return $downtime_dates; +} ?> \ No newline at end of file diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index 8840793a78..a34687c64b 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -2250,225 +2250,6 @@ function reporting_get_agentmodule_sla_day ($id_agent_module, $period = 0, $min_ return (float) (100 - ($bad_period / $period) * 100); } -/** - * Get SLA of a module. - * - * @param int Agent module to calculate SLA - * @param int Period to check the SLA compliance. - * @param int Minimum data value the module in the right interval - * @param int Maximum data value the module in the right interval. False will - * ignore max value - * @param int Beginning date of the report in UNIX time (current date by default). - * @param array $dayWeek Array of days week to extract as array('monday' => false, 'tuesday' => true....), and by default is null. - * @param string $timeFrom Time in the day to start to extract in mysql format, by default null. - * @param string $timeTo Time in the day to end to extract in mysql format, by default null. - * - * @return float SLA percentage of the requested module. False if no data were - * found - */ -function reporting_get_agentmodule_sla ($id_agent_module, $period = 0, - $min_value = 1, $max_value = false, $date = 0, $daysWeek = null, - $timeFrom = null, $timeTo = null) { - - global $config; - - if (empty($id_agent_module)) - return false; - - // Set initial conditions - $bad_period = 0; - // Limit date to start searching data - $datelimit = $date - $period; - $search_in_history_db = db_search_in_history_db($datelimit); - - // Initialize variables - if (empty ($date)) { - $date = get_system_time (); - } - if ($daysWeek === null) { - $daysWeek = array(); - } - - - // Calculate the SLA for large time without hours - if ($timeFrom == $timeTo) { - // Get interval data - $sql = sprintf ('SELECT * - FROM tagente_datos - 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 - if ($daysWeek) { - foreach ($daysWeek as $key => $value) { - if (!$value) { - if ($key == 'monday') { - $days[] = 2; - } - if ($key == 'tuesday') { - $days[] = 3; - } - if ($key == 'wednesday') { - $days[] = 4; - } - if ($key == 'thursday') { - $days[] = 5; - } - if ($key == 'friday') { - $days[] = 6; - } - if ($key == 'saturday') { - $days[] = 7; - } - if ($key == 'sunday') { - $days[] = 1; - } - } - } - } - - if (count($days) > 0) { - $sql .= ' AND DAYOFWEEK(FROM_UNIXTIME(utimestamp)) NOT IN (' . implode(',', $days) . ')'; - } - - $sql .= "\n"; - $sql .= ' ORDER BY utimestamp ASC'; - $interval_data = db_get_all_rows_sql ($sql, $search_in_history_db); - - if ($interval_data === false) { - $interval_data = array (); - } - - // Calculate planned downtime dates - $downtime_dates = reporting_get_planned_downtimes_intervals($id_agent_module, $datelimit, $date); - - // Get previous data - $previous_data = modules_get_previous_data ($id_agent_module, $datelimit); - - if ($previous_data !== false) { - $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) { - $next_data['utimestamp'] = $date; - array_push ($interval_data, $next_data); - } - else if (count ($interval_data) > 0) { - // Propagate the last known data to the end of the interval - $next_data = array_pop ($interval_data); - array_push ($interval_data, $next_data); - $next_data['utimestamp'] = $date; - array_push ($interval_data, $next_data); - } - - if (count ($interval_data) < 2) { - return false; - } - - - $first_data = array_shift ($interval_data); - - // Do not count the empty start of an interval as 0 - if ($first_data['utimestamp'] != $datelimit) { - $period = $date - $first_data['utimestamp']; - } - - $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; - } - } - } - else { - $previous_status = 0; - } - - - - - - foreach ($interval_data as $data) { - // Previous status was critical - if ($previous_status == 1) { - $bad_period += $data['utimestamp'] - $previous_utimestamp; - } - - if (array_key_exists('datos', $data)) { - // Re-calculate previous status for the next data - if ((($max_value > $min_value AND ($data['datos'] > $max_value OR $data['datos'] < $min_value))) OR - ($max_value <= $min_value AND $data['datos'] < $min_value)) { - - $previous_status = 1; - foreach ($downtime_dates as $date_dt) { - if (($date_dt['date_from'] <= $data['utimestamp']) AND ($date_dt['date_to'] >= $data['utimestamp'])) { - $previous_status = 0; - } - } - } - else { - $previous_status = 0; - } - } - - $previous_utimestamp = $data['utimestamp']; - } - - // Return the percentage of SLA compliance - return (float) (100 - ($bad_period / $period) * 100); - } - elseif ($period <= SECONDS_1DAY) { - - - return reporting_get_agentmodule_sla_day( - $id_agent_module, - $period, - $min_value, - $max_value, - $date, - $daysWeek, - $timeFrom, - $timeTo); - } - else { - // Extract the data each day - - $sla = 0; - - $i = 0; - for ($interval = 0; $interval <= $period; $interval = $interval + SECONDS_1DAY) { - $datelimit = $date - $interval; - - $sla_day = reporting_get_agentmodule_sla( - $id_agent_module, - SECONDS_1DAY, - $min_value, - $max_value, - $datelimit + $interval, - $daysWeek, - $timeFrom, $timeTo); - - - $sla += $sla_day; - $i++; - } - - $sla = $sla / $i; - - return $sla; - } -} /** * Get several SLA data for an agentmodule within a period divided on subperiods @@ -2789,228 +2570,6 @@ function reporting_get_agentmodule_sla_array ($id_agent_module, $period = 0, $mi return $data_colors; } -/** - * Get the time intervals where an agentmodule is affected by the planned downtimes. - * - * @param int Agent module to calculate planned downtimes intervals. - * @param int Start date in utimestamp. - * @param int End date in utimestamp. - * @param bool Whether ot not to get the planned downtimes that affect the service associated with the agentmodule. - * - * @return Array with time intervals. - */ -function reporting_get_planned_downtimes_intervals ($id_agent_module, $start_date, $end_date, $check_services = false) { - global $config; - - if (empty($id_agent_module)) - return false; - - require_once ($config['homedir'] . '/include/functions_planned_downtimes.php'); - - $malformed_planned_downtimes = planned_downtimes_get_malformed(); - if (empty($malformed_planned_downtimes)) - $malformed_planned_downtimes = array(); - - $sql_downtime = "SELECT DISTINCT(tpdr.id), tpdr.* - FROM ( - SELECT tpd.* - FROM tplanned_downtime tpd, tplanned_downtime_agents tpda, tagente_modulo tam - WHERE tpd.id = tpda.id_downtime - AND tpda.all_modules = 1 - AND tpda.id_agent = tam.id_agente - AND tam.id_agente_modulo = $id_agent_module - UNION ALL - SELECT tpd.* - FROM tplanned_downtime tpd, tplanned_downtime_modules tpdm - WHERE tpd.id = tpdm.id_downtime - AND tpdm.id_agent_module = $id_agent_module - ) tpdr - ORDER BY tpdr.id"; - - $downtimes = db_get_all_rows_sql($sql_downtime); - - if ($downtimes == false) { - $downtimes = array(); - } - $downtime_dates = array(); - foreach ($downtimes as $downtime) { - $downtime_id = $downtime['id']; - $downtime_type = $downtime['type_execution']; - $downtime_periodicity = $downtime['type_periodicity']; - - if ($downtime_type == 'once') { - $dates = array(); - $dates['date_from'] = $downtime['date_from']; - $dates['date_to'] = $downtime['date_to']; - $downtime_dates[] = $dates; - } - else if ($downtime_type == 'periodically') { - - // If a planned downtime have malformed dates, its intervals aren't taken account - $downtime_malformed = false; - foreach ($malformed_planned_downtimes as $malformed_planned_downtime) { - if ($downtime_id == $malformed_planned_downtime['id']) { - $downtime_malformed = true; - break; - } - } - if ($downtime_malformed == true) { - continue; - } - // If a planned downtime have malformed dates, its intervals aren't taken account - - $downtime_time_from = $downtime['periodically_time_from']; - $downtime_time_to = $downtime['periodically_time_to']; - - $downtime_hour_from = date("H", strtotime($downtime_time_from)); - $downtime_minute_from = date("i", strtotime($downtime_time_from)); - $downtime_second_from = date("s", strtotime($downtime_time_from)); - $downtime_hour_to = date("H", strtotime($downtime_time_to)); - $downtime_minute_to = date("i", strtotime($downtime_time_to)); - $downtime_second_to = date("s", strtotime($downtime_time_to)); - - if ($downtime_periodicity == "monthly") { - $downtime_day_from = $downtime['periodically_day_from']; - $downtime_day_to = $downtime['periodically_day_to']; - - $date_aux = strtotime(date("Y-m-01", $start_date)); - $year_aux = date("Y", $date_aux); - $month_aux = date("m", $date_aux); - - $end_year = date("Y", $end_date); - $end_month = date("m", $end_date); - - while ($year_aux < $end_year || ($year_aux == $end_year && $month_aux <= $end_month)) { - - if ($downtime_day_from > $downtime_day_to) { - $dates = array(); - $dates['date_from'] = strtotime("$year_aux-$month_aux-$downtime_day_from $downtime_hour_from:$downtime_minute_from:$downtime_second_from"); - $dates['date_to'] = strtotime(date("Y-m-t H:i:s", strtotime("$year_aux-$month_aux-28 23:59:59"))); - $downtime_dates[] = $dates; - - $dates = array(); - if ($month_aux + 1 <= 12) { - $dates['date_from'] = strtotime("$year_aux-".($month_aux + 1)."-01 00:00:00"); - $dates['date_to'] = strtotime("$year_aux-".($month_aux + 1)."-$downtime_day_to $downtime_hour_to:$downtime_minute_to:$downtime_second_to"); - } - else { - $dates['date_from'] = strtotime(($year_aux + 1)."-01-01 00:00:00"); - $dates['date_to'] = strtotime(($year_aux + 1)."-01-$downtime_day_to $downtime_hour_to:$downtime_minute_to:$downtime_second_to"); - } - $downtime_dates[] = $dates; - } - else { - if ($downtime_day_from == $downtime_day_to && strtotime($downtime_time_from) > strtotime($downtime_time_to)) { - $date_aux_from = strtotime("$year_aux-$month_aux-$downtime_day_from $downtime_hour_from:$downtime_minute_from:$downtime_second_from"); - $max_day_num = date('t', $date_aux); - - $dates = array(); - $dates['date_from'] = strtotime("$year_aux-$month_aux-$downtime_day_from $downtime_hour_from:$downtime_minute_from:$downtime_second_from"); - $dates['date_to'] = strtotime("$year_aux-$month_aux-$downtime_day_from 23:59:59"); - $downtime_dates[] = $dates; - - if ($downtime_day_to + 1 > $max_day_num) { - - $dates = array(); - if ($month_aux + 1 <= 12) { - $dates['date_from'] = strtotime("$year_aux-".($month_aux + 1)."-01 00:00:00"); - $dates['date_to'] = strtotime("$year_aux-".($month_aux + 1)."-01 $downtime_hour_to:$downtime_minute_to:$downtime_second_to"); - } - else { - $dates['date_from'] = strtotime(($year_aux + 1)."-01-01 00:00:00"); - $dates['date_to'] = strtotime(($year_aux + 1)."-01-01 $downtime_hour_to:$downtime_minute_to:$downtime_second_to"); - } - $downtime_dates[] = $dates; - } - else { - $dates = array(); - $dates['date_from'] = strtotime("$year_aux-$month_aux-".($downtime_day_to + 1)." 00:00:00"); - $dates['date_to'] = strtotime("$year_aux-$month_aux-".($downtime_day_to + 1)." $downtime_hour_to:$downtime_minute_to:$downtime_second_to"); - $downtime_dates[] = $dates; - } - } - else { - $dates = array(); - $dates['date_from'] = strtotime("$year_aux-$month_aux-$downtime_day_from $downtime_hour_from:$downtime_minute_from:$downtime_second_from"); - $dates['date_to'] = strtotime("$year_aux-$month_aux-$downtime_day_to $downtime_hour_to:$downtime_minute_to:$downtime_second_to"); - $downtime_dates[] = $dates; - } - } - - $month_aux++; - if ($month_aux > 12) { - $month_aux = 1; - $year_aux++; - } - } - } - else if ($downtime_periodicity == "weekly") { - $date_aux = $start_date; - $active_days = array(); - $active_days[0] = ($downtime['sunday'] == 1) ? true : false; - $active_days[1] = ($downtime['monday'] == 1) ? true : false; - $active_days[2] = ($downtime['tuesday'] == 1) ? true : false; - $active_days[3] = ($downtime['wednesday'] == 1) ? true : false; - $active_days[4] = ($downtime['thursday'] == 1) ? true : false; - $active_days[5] = ($downtime['friday'] == 1) ? true : false; - $active_days[6] = ($downtime['saturday'] == 1) ? true : false; - - while ($date_aux <= $end_date) { - $weekday_num = date('w', $date_aux); - - if ($active_days[$weekday_num]) { - $day_num = date('d', $date_aux); - $month_num = date('m', $date_aux); - $year_num = date('Y', $date_aux); - - $max_day_num = date('t', $date_aux); - - if (strtotime($downtime_time_from) > strtotime($downtime_time_to)) { - $dates = array(); - $dates['date_from'] = strtotime("$year_num-$month_num-$day_num $downtime_hour_from:$downtime_minute_from:$downtime_second_from"); - $dates['date_to'] = strtotime("$year_num-$month_num-$day_num 23:59:59"); - $downtime_dates[] = $dates; - - $dates = array(); - if ($day_num + 1 > $max_day_num) { - if ($month_num + 1 > 12) { - $dates['date_from'] = strtotime(($year_num + 1)."-01-01 00:00:00"); - $dates['date_to'] = strtotime(($year_num + 1)."-01-01 $downtime_hour_to:$downtime_minute_to:$downtime_second_to"); - } - else { - $dates['date_from'] = strtotime("$year_num-".($month_num + 1)."-01 00:00:00"); - $dates['date_to'] = strtotime("$year_num-".($month_num + 1)."-01 $downtime_hour_to:$downtime_minute_to:$downtime_second_to"); - } - } - else { - $dates['date_from'] = strtotime("$year_num-$month_num-".($day_num + 1)." 00:00:00"); - $dates['date_to'] = strtotime("$year_num-$month_num-".($day_num + 1)." $downtime_hour_to:$downtime_minute_to:$downtime_second_to"); - } - $downtime_dates[] = $dates; - } - else { - $dates = array(); - $dates['date_from'] = strtotime("$year_num-$month_num-$day_num $downtime_hour_from:$downtime_minute_from:$downtime_second_from"); - $dates['date_to'] = strtotime("$year_num-$month_num-$day_num $downtime_hour_to:$downtime_minute_to:$downtime_second_to"); - $downtime_dates[] = $dates; - } - } - - $date_aux += SECONDS_1DAY; - } - } - } - } - - if ($check_services) { - enterprise_include_once("include/functions_services.php"); - if (function_exists("services_get_planned_downtimes_intervals")) { - services_get_planned_downtimes_intervals($downtime_dates, $start_date, $end_date, false, $id_agent_module); - } - } - - return $downtime_dates; -} /** * Get the planned downtimes that affect the passed modules on an specific datetime range. @@ -4003,57 +3562,7 @@ function reporting_header_content($mini, $content, $report, &$table, */ function reporting_render_report_html_item ($content, $table, $report, $mini = false) { - global $config; - global $graphic_type; - $only_image = (bool)$config['flash_charts'] ? false : true; - - if ($mini) { - $sizem = '1.5'; - $sizgraph_w = '450'; - $sizgraph_h = '100'; - } - else { - $sizem = '3'; - $sizgraph_w = '900'; - $sizgraph_h = '230'; - } - - // Disable remote connections for netflow report items - if ($content['type'] != 'netflow_area' && - $content['type'] != 'netflow_pie' && - $content['type'] != 'netflow_data' && - $content['type'] != 'netflow_statistics' && - $content['type'] != 'netflow_summary') { - - $remote_connection = 1; - } - else { - $remote_connection = 0; - } - - $server_name = $content ['server_name']; - if (($config ['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE') && $remote_connection == 1) { - $connection = metaconsole_get_connection($server_name); - if (metaconsole_load_external_db($connection) != NOERR) { - //ui_print_error_message ("Error connecting to ".$server_name); - } - } - - $module_name = db_get_value ('nombre', 'tagente_modulo', 'id_agente_modulo', $content['id_agent_module']); - if ($content['id_agent_module'] != 0) { - $agent_name = modules_get_agentmodule_agent_name ($content['id_agent_module']); - } - else { - $agent_name = agents_get_name($content['id_agent']); - } - - $item_title = $content['name']; - - //Restore dbconnection - if (($config ['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE') && $remote_connection == 1) { - metaconsole_restore_db_force(); - } } diff --git a/pandora_console/operation/reporting/reporting_viewer.php b/pandora_console/operation/reporting/reporting_viewer.php index 448300a64b..990a2f032a 100644 --- a/pandora_console/operation/reporting/reporting_viewer.php +++ b/pandora_console/operation/reporting/reporting_viewer.php @@ -245,7 +245,6 @@ if ($enable_init_date) { } $report = reporting_make_reporting_data($id_report, $date, $time, $period, 'dinamic'); -//~ html_debug_print($report); reporting_html_print_report($report); echo "
"; @@ -353,67 +352,5 @@ if ($datetime === false || $datetime == -1) { return; } -// TODO: Evaluate if it's better to render blocks when are calculated -// (enabling realtime flush) or if it's better to wait report to be -// finished before showing anything (this could break the execution -// by overflowing the running PHP memory on HUGE reports). - - -$table->size = array (); -$table->style = array (); -$table->width = '98%'; -$table->class = 'databox'; -$table->rowclass = array (); -$table->rowclass[0] = 'datos3'; - -$report["group_name"] = groups_get_name ($report['id_group']); - -switch ($config["dbtype"]) { - case "mysql": - $contents = db_get_all_rows_field_filter ("treport_content", - "id_report", $id_report, "`order`"); - break; - case "postgresql": - $contents = db_get_all_rows_field_filter ("treport_content", - "id_report", $id_report, '"order"'); - break; - case "oracle": - $contents = db_get_all_rows_field_filter ("treport_content", - "id_report", $id_report, '"order"'); - break; -} -if ($contents === false) { - return; -} - -foreach ($contents as $content) { - $table->data = array (); - $table->head = array (); - $table->style = array (); - $table->colspan = array (); - $table->rowstyle = array (); - - // Calculate new inteval for all reports - if ($enable_init_date) { - if ($datetime_init >= $datetime) { - $datetime_init = $date_init_less; - } - $new_interval = $report['datetime'] - $datetime_init; - $content['period'] = $new_interval; - } - - reporting_render_report_html_item ($content, $table, $report); - - if ($content['type'] == 'agent_module') - echo '
'; - - html_print_table ($table); - - if ($content['type'] == 'agent_module') - echo '
'; - - flush (); -} - enterprise_hook('close_meta_frame'); ?> From d2e57f2ec889d292552435ee5df536c730ff2443 Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Wed, 6 May 2015 18:28:46 +0200 Subject: [PATCH 59/80] Fixed the lost value for the config max_file_size. --- pandora_console/include/functions_config.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pandora_console/include/functions_config.php b/pandora_console/include/functions_config.php index a1413d7d0e..d8d7e5e88f 100644 --- a/pandora_console/include/functions_config.php +++ b/pandora_console/include/functions_config.php @@ -1329,6 +1329,12 @@ function config_process_config () { config_update_value ('session_timeout', 90); } + if (!isset ($config["max_file_size"])) { + config_update_value ('max_file_size', "2M"); + } + + + /* Finally, check if any value was overwritten in a form */ config_update_config(); } @@ -1557,7 +1563,7 @@ function config_prepare_session() { if (isset($_COOKIE[session_name()])) setcookie(session_name(), $_COOKIE[session_name()], time() + $sessionCookieExpireTime, "/"); - ini_set("post_max_size",$config["max_file_size"]); - ini_set("upload_max_filesize",$config["max_file_size"]); + ini_set("post_max_size", $config["max_file_size"]); + ini_set("upload_max_filesize", $config["max_file_size"]); } ?> From 1a035873dc79d04ffbf155a874e3eeed8eaa8c20 Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Wed, 6 May 2015 18:42:42 +0200 Subject: [PATCH 60/80] Fixed the PHP Warnings about the re-start the session. --- pandora_console/include/config_process.php | 4 +++- pandora_console/include/functions.php | 4 +++- pandora_console/index.php | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/pandora_console/include/config_process.php b/pandora_console/include/config_process.php index fb5605b44c..35db109620 100644 --- a/pandora_console/include/config_process.php +++ b/pandora_console/include/config_process.php @@ -120,7 +120,9 @@ config_process_config(); config_prepare_session(); require_once ($config["homedir"].'/include/load_session.php'); -$resultado = session_start(); +if(session_id() == '') { + $resultado = session_start(); +} if (!isset($config["homeurl_static"])) { diff --git a/pandora_console/include/functions.php b/pandora_console/include/functions.php index e8cdef04b1..c3c234e185 100644 --- a/pandora_console/include/functions.php +++ b/pandora_console/include/functions.php @@ -1691,7 +1691,9 @@ function check_login ($output = true) { } else { require_once($config["homedir"].'/mobile/include/user.class.php'); - session_start (); + if(session_id() == '') { + session_start (); + } session_write_close (); if (isset($_SESSION['user'])) { $user = $_SESSION['user']; diff --git a/pandora_console/index.php b/pandora_console/index.php index 196ef0f5f3..45826477e5 100755 --- a/pandora_console/index.php +++ b/pandora_console/index.php @@ -66,7 +66,9 @@ if ((! file_exists ("include/config.php")) || (! is_readable ("include/config.ph } // Real start -session_start (); +if(session_id() == '') { + session_start (); +} require_once ("include/config.php"); From def5a597a22398a983aa2f841eeacd49464493e1 Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Thu, 7 May 2015 17:05:50 +0200 Subject: [PATCH 61/80] Fixed the image for the 'simple_graph' in the enterprise pdf reports. --- pandora_console/include/functions_reporting.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index a1d08bf995..bf3412ea08 100644 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -3859,7 +3859,11 @@ function reporting_simple_graph($report, $content, $type = 'dinamic', false, $only_avg, false, - $report["datetime"], $only_image, $urlImage); + $report["datetime"], + $only_image, + $urlImage, + "", + $ttl); } else { @@ -3887,7 +3891,7 @@ function reporting_simple_graph($report, $content, $type = 'dinamic', true, $only_image, ui_get_full_url(false, false, false, false), - 1, + $ttl, false, '', $time_compare_overlapped, From 7ce25e96279e9d4d95e5200b9ec3f2f9f0fb95b7 Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Tue, 12 May 2015 16:41:08 +0200 Subject: [PATCH 62/80] Some changes and fixed for the reports in PDF. --- pandora_console/include/functions_graph.php | 5 +- .../include/functions_reporting.php | 152 ++++++++++++++++-- .../include/functions_reporting_html.php | 105 +----------- 3 files changed, 150 insertions(+), 112 deletions(-) diff --git a/pandora_console/include/functions_graph.php b/pandora_console/include/functions_graph.php index 8230479511..665dba2fb6 100755 --- a/pandora_console/include/functions_graph.php +++ b/pandora_console/include/functions_graph.php @@ -2671,7 +2671,10 @@ function grafico_eventos_usuario ($width, $height) { * @param integer width graph width * @param integer Graph type 1 vbar, 2 hbar, 3 pie */ -function graph_custom_sql_graph ($id, $width, $height, $type = 'sql_graph_vbar', $only_image = false, $homeurl = '', $ttl = 1) { +function graph_custom_sql_graph ($id, $width, $height, + $type = 'sql_graph_vbar', $only_image = false, $homeurl = '', + $ttl = 1) { + global $config; $report_content = db_get_row ('treport_content', 'id_rc', $id); diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index bf3412ea08..7162dd4405 100644 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -365,7 +365,10 @@ function reporting_make_reporting_data($id_report, $date, $time, case 'event_report_agent': $report['contents'][] = reporting_event_report_agent( $report, - $content); + $content, + $type, + $force_width_chart, + $force_height_chart); break; case 'group_report': $report['contents'][] = reporting_group_report( @@ -1894,7 +1897,10 @@ function reporting_group_report($report, $content) { return reporting_check_structure_content($return); } -function reporting_event_report_agent($report, $content) { +function reporting_event_report_agent($report, $content, + $type = 'dinamic', $force_width_chart = null, + $force_height_chart = null) { + global $config; $return['type'] = 'event_report_agent'; @@ -1930,6 +1936,21 @@ function reporting_event_report_agent($report, $content) { $filter_event_no_validated, true); + + + reporting_set_conf_charts($width, $height, $only_image, $type, + $content, $ttl); + + if (!empty($force_width_chart)) { + $width = $force_width_chart; + } + + if (!empty($force_height_chart)) { + $height = $force_height_chart; + } + + + $return["chart"]["by_user_validator"] = null; $return["chart"]["by_criticity"] = null; $return["chart"]["validated_vs_unvalidated"] = null; @@ -1951,10 +1972,11 @@ function reporting_event_report_agent($report, $content) { 500, 150, __("other"), - "", + ui_get_full_url(false, false, false, false), ui_get_full_url(false, false, false, false) . "/images/logo_vertical_water.png", $config['fontpath'], - $config['font_size']); + $config['font_size'], + $ttl); } if ($event_graph_by_criticity) { @@ -1969,9 +1991,18 @@ function reporting_event_report_agent($report, $content) { $colors = get_criticity_pie_colors($data_graph); $return["chart"]["by_criticity"] = pie3d_graph( - false, $data_graph, 500, 150, __("other"), "", + false, + $data_graph, + 500, + 150, + __("other"), + ui_get_full_url(false, false, false, false), ui_get_full_url(false, false, false, false) . "/images/logo_vertical_water.png", - $config['fontpath'], $config['font_size'], 1, false, $colors); + $config['fontpath'], + $config['font_size'], + $ttl, + false, + $colors); } if ($event_graph_validated_vs_unvalidated) { @@ -1984,9 +2015,16 @@ function reporting_event_report_agent($report, $content) { $filter_event_no_validated); $return["chart"]["validated_vs_unvalidated"] = pie3d_graph( - false, $data_graph, 500, 150, __("other"), "", + false, + $data_graph, + 500, + 150, + __("other"), + ui_get_full_url(false, false, false, false), ui_get_full_url(false, false, false, false) . "/images/logo_vertical_water.png", - $config['fontpath'], $config['font_size']); + $config['fontpath'], + $config['font_size'], + $ttl); } return reporting_check_structure_content($return); @@ -2593,7 +2631,8 @@ function reporting_sql_graph($report, $content, $type, $height, $content["type"], true, - ui_get_full_url(false, false, false, false)); + ui_get_full_url(false, false, false, false), + $ttl); break; case 'data': break; @@ -3997,6 +4036,13 @@ function reporting_set_conf_charts(&$width, &$height, &$only_image, $type, } } + + + + + + + //////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// @@ -4005,6 +4051,94 @@ function reporting_set_conf_charts(&$width, &$height, &$only_image, $type, //////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// +/** + * Gets a detailed reporting of groups's events. + * + * @param unknown_type $id_group Id of the group. + * @param unknown_type $period Time period of the report. + * @param unknown_type $date Date of the report. + * @param unknown_type $return Whether to return or not. + * @param unknown_type $html Whether to return HTML code or not. + * + * @return string Report of groups's events + */ +function reporting_get_count_events_validated ($filter, $period = 0, + $date = 0, + $filter_event_validated = false, $filter_event_critical = false, + $filter_event_warning = false, $filter_event_no_validated = false, + $filter_event_search = false) { + + if (!is_numeric ($date)) { + $date = strtotime ($date); + } + if (empty ($date)) { + $date = get_system_time (); + } + + return events_get_count_events_validated($filter, $period, $date, + $filter_event_validated, $filter_event_critical, + $filter_event_warning, $filter_event_no_validated, + $filter_event_search); +} + +/** + * Gets a detailed reporting of groups's events. + * + * @param unknown_type $id_group Id of the group. + * @param unknown_type $period Time period of the report. + * @param unknown_type $date Date of the report. + * @param unknown_type $return Whether to return or not. + * @param unknown_type $html Whether to return HTML code or not. + * + * @return string Report of groups's events + */ +function reporting_get_count_events_by_criticity ($filter, $period = 0, + $date = 0, + $filter_event_validated = false, $filter_event_critical = false, + $filter_event_warning = false, $filter_event_no_validated = false, + $filter_event_search = false) { + + if (!is_numeric ($date)) { + $date = strtotime ($date); + } + if (empty ($date)) { + $date = get_system_time (); + } + + return events_get_count_events_by_criticity($filter, $period, $date, + $filter_event_validated, $filter_event_critical, + $filter_event_warning, $filter_event_no_validated, + $filter_event_search); +} + +/** + * Gets a detailed reporting of groups's events. + * + * @param unknown_type $filter. + * @param unknown_type $period Time period of the report. + * @param unknown_type $date Date of the report. + * @param unknown_type $return Whether to return or not. + * @param unknown_type $html Whether to return HTML code or not. + * + * @return string Report of groups's events + */ +function reporting_get_count_events_validated_by_user ($filter, $period = 0, + $date = 0, + $filter_event_validated = false, $filter_event_critical = false, + $filter_event_warning = false, $filter_event_no_validated = false, + $filter_event_search = false) { + + if (!is_numeric ($date)) { + $date = strtotime ($date); + } + if (empty ($date)) { + $date = get_system_time (); + } + + return events_get_count_events_validated_by_user($filter, $period, $date, + $filter_event_validated, $filter_event_critical, + $filter_event_warning, $filter_event_no_validated, $filter_event_search); +} /** * Gets a detailed reporting of groups's events. diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index a34687c64b..9c571475e0 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -1057,7 +1057,7 @@ function reporting_html_group_report($table, $item) {
" . __('Events') . "
" . - $item["data"]["count_events"]."
+ $item["data"]["count_events"] . "
"; } @@ -3549,21 +3549,6 @@ function reporting_header_content($mini, $content, $report, &$table, array_push ($table->data, $data); } -/** - * This function is used once, in reporting_viewer.php, the HTML report render - * file. This function proccess each report item and write the render in the - * table record. - * - * @param array $content Record of treport_content table for current item - * @param array $table HTML Table row - * @param array $report Report contents, with some added fields. - * @param array $mini Mini flag for reduce the size. - * - */ - -function reporting_render_report_html_item ($content, $table, $report, $mini = false) { - -} @@ -3648,94 +3633,10 @@ function reporting_get_count_events_by_agent ($id_group, $period = 0, $filter_event_filter_search); } -/** - * Gets a detailed reporting of groups's events. - * - * @param unknown_type $filter. - * @param unknown_type $period Time period of the report. - * @param unknown_type $date Date of the report. - * @param unknown_type $return Whether to return or not. - * @param unknown_type $html Whether to return HTML code or not. - * - * @return string Report of groups's events - */ -function reporting_get_count_events_validated_by_user ($filter, $period = 0, - $date = 0, - $filter_event_validated = false, $filter_event_critical = false, - $filter_event_warning = false, $filter_event_no_validated = false, - $filter_event_search = false) { - - if (!is_numeric ($date)) { - $date = strtotime ($date); - } - if (empty ($date)) { - $date = get_system_time (); - } - - return events_get_count_events_validated_by_user($filter, $period, $date, - $filter_event_validated, $filter_event_critical, - $filter_event_warning, $filter_event_no_validated, $filter_event_search); -} -/** - * Gets a detailed reporting of groups's events. - * - * @param unknown_type $id_group Id of the group. - * @param unknown_type $period Time period of the report. - * @param unknown_type $date Date of the report. - * @param unknown_type $return Whether to return or not. - * @param unknown_type $html Whether to return HTML code or not. - * - * @return string Report of groups's events - */ -function reporting_get_count_events_by_criticity ($filter, $period = 0, - $date = 0, - $filter_event_validated = false, $filter_event_critical = false, - $filter_event_warning = false, $filter_event_no_validated = false, - $filter_event_search = false) { - - if (!is_numeric ($date)) { - $date = strtotime ($date); - } - if (empty ($date)) { - $date = get_system_time (); - } - - return events_get_count_events_by_criticity($filter, $period, $date, - $filter_event_validated, $filter_event_critical, - $filter_event_warning, $filter_event_no_validated, - $filter_event_search); -} -/** - * Gets a detailed reporting of groups's events. - * - * @param unknown_type $id_group Id of the group. - * @param unknown_type $period Time period of the report. - * @param unknown_type $date Date of the report. - * @param unknown_type $return Whether to return or not. - * @param unknown_type $html Whether to return HTML code or not. - * - * @return string Report of groups's events - */ -function reporting_get_count_events_validated ($filter, $period = 0, - $date = 0, - $filter_event_validated = false, $filter_event_critical = false, - $filter_event_warning = false, $filter_event_no_validated = false, - $filter_event_search = false) { - - if (!is_numeric ($date)) { - $date = strtotime ($date); - } - if (empty ($date)) { - $date = get_system_time (); - } - - return events_get_count_events_validated($filter, $period, $date, - $filter_event_validated, $filter_event_critical, - $filter_event_warning, $filter_event_no_validated, - $filter_event_search); -} + + function reporting_get_agents_by_status ($data, $graph_width = 250, $graph_height = 150, $links = false) { global $config; From 9e75cce59f4e4af610c8a2dedf42b2fb12915833 Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Tue, 12 May 2015 18:18:48 +0200 Subject: [PATCH 63/80] Some changes and fixed for the reports in PDF. --- .../include/functions_reporting.php | 101 ++++++++++++++++-- .../include/functions_reporting_html.php | 30 +----- 2 files changed, 92 insertions(+), 39 deletions(-) diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index 7162dd4405..21061981ec 100644 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -406,7 +406,10 @@ function reporting_make_reporting_data($id_report, $date, $time, case 'event_report_group': $report['contents'][] = reporting_event_report_group( $report, - $content); + $content, + $type, + $force_width_chart, + $force_height_chart); break; case 'top_n': $report['contents'][] = reporting_event_top_n( @@ -1171,7 +1174,10 @@ function reporting_event_top_n($report, $content, $type = 'dinamic', return reporting_check_structure_content($return); } -function reporting_event_report_group($report, $content) { +function reporting_event_report_group($report, $content, + $type = 'dinamic', $force_width_chart = null, + $force_height_chart = null) { + global $config; $return['type'] = 'event_report_group'; @@ -1214,6 +1220,21 @@ function reporting_event_report_group($report, $content) { $return['data'] = $data; } + + + reporting_set_conf_charts($width, $height, $only_image, $type, + $content, $ttl); + + if (!empty($force_width_chart)) { + $width = $force_width_chart; + } + + if (!empty($force_height_chart)) { + $height = $force_height_chart; + } + + + $return['chart']['by_agent'] = null; $return['chart']['by_user_validator'] = null; $return['chart']['by_criticity'] = null; @@ -1230,9 +1251,16 @@ function reporting_event_report_group($report, $content) { $filter_event_filter_search); $return['chart']['by_agent']= pie3d_graph( - false, $data_graph, 500, 150, __("other"), "", + false, + $data_graph, + 500, + 150, + __("other"), + ui_get_full_url(false, false, false, false), ui_get_full_url(false, false, false, false) . "/images/logo_vertical_water.png", - $config['fontpath'], $config['font_size']); + $config['fontpath'], + $config['font_size'], + $ttl); } if ($event_graph_by_user_validator) { @@ -1247,9 +1275,16 @@ function reporting_event_report_group($report, $content) { $filter_event_filter_search); $return['chart']['by_user_validator'] = pie3d_graph( - false, $data_graph, 500, 150, __("other"), "", + false, + $data_graph, + 500, + 150, + __("other"), + ui_get_full_url(false, false, false, false), ui_get_full_url(false, false, false, false) . "/images/logo_vertical_water.png", - $config['fontpath'], $config['font_size']); + $config['fontpath'], + $config['font_size'], + $ttl); } if ($event_graph_by_criticity) { @@ -1265,9 +1300,18 @@ function reporting_event_report_group($report, $content) { $colors = get_criticity_pie_colors($data_graph); $return['chart']['by_criticity'] = pie3d_graph( - false, $data_graph, 500, 150, __("other"), "", + false, + $data_graph, + 500, + 150, + __("other"), + ui_get_full_url(false, false, false, false), ui_get_full_url(false, false, false, false) . "/images/logo_vertical_water.png", - $config['fontpath'], $config['font_size'], 1, false, $colors); + $config['fontpath'], + $config['font_size'], + $ttl, + false, + $colors); } if ($event_graph_validated_vs_unvalidated) { @@ -1282,9 +1326,16 @@ function reporting_event_report_group($report, $content) { $filter_event_filter_search); $return['chart']['validated_vs_unvalidated'] = pie3d_graph( - false, $data_graph, 500, 150, __("other"), "", + false, + $data_graph, + 500, + 150, + __("other"), + ui_get_full_url(false, false, false, false), ui_get_full_url(false, false, false, false) . "/images/logo_vertical_water.png", - $config['fontpath'], $config['font_size']); + $config['fontpath'], + $config['font_size'], + $ttl); } return reporting_check_structure_content($return); @@ -6334,4 +6385,34 @@ function reporting_get_planned_downtimes_intervals ($id_agent_module, $start_dat return $downtime_dates; } + +/** + * Gets a detailed reporting of groups's events. + * + * @param unknown_type $id_group Id of the group. + * @param unknown_type $period Time period of the report. + * @param unknown_type $date Date of the report. + * @param unknown_type $return Whether to return or not. + * @param unknown_type $html Whether to return HTML code or not. + * + * @return string Report of groups's events + */ +function reporting_get_count_events_by_agent ($id_group, $period = 0, + $date = 0, + $filter_event_validated = false, $filter_event_critical = false, + $filter_event_warning = false, $filter_event_no_validated = false, + $filter_event_filter_search = null) { + + if (!is_numeric ($date)) { + $date = strtotime ($date); + } + if (empty ($date)) { + $date = get_system_time (); + } + + return events_get_count_events_by_agent($id_group, $period, $date, + $filter_event_validated, $filter_event_critical, + $filter_event_warning, $filter_event_no_validated, + $filter_event_filter_search); +} ?> \ No newline at end of file diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index 9c571475e0..3c2fce6db9 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -3603,35 +3603,7 @@ function reporting_template_graphs_get_user ($id_user = 0, $only_names = false, return $templates; } -/** - * Gets a detailed reporting of groups's events. - * - * @param unknown_type $id_group Id of the group. - * @param unknown_type $period Time period of the report. - * @param unknown_type $date Date of the report. - * @param unknown_type $return Whether to return or not. - * @param unknown_type $html Whether to return HTML code or not. - * - * @return string Report of groups's events - */ -function reporting_get_count_events_by_agent ($id_group, $period = 0, - $date = 0, - $filter_event_validated = false, $filter_event_critical = false, - $filter_event_warning = false, $filter_event_no_validated = false, - $filter_event_filter_search = null) { - - if (!is_numeric ($date)) { - $date = strtotime ($date); - } - if (empty ($date)) { - $date = get_system_time (); - } - - return events_get_count_events_by_agent($id_group, $period, $date, - $filter_event_validated, $filter_event_critical, - $filter_event_warning, $filter_event_no_validated, - $filter_event_filter_search); -} + From e005a352ab94283bb1326d596cee61546e2200cb Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Wed, 13 May 2015 13:55:54 +0200 Subject: [PATCH 64/80] Some fixes for the enterprise PDF reports. --- pandora_console/include/functions_reporting.php | 5 +++-- pandora_console/include/functions_reporting_html.php | 5 ++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index 21061981ec..7cbcba5c39 100644 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -2251,11 +2251,12 @@ function reporting_network_interfaces_report($report, $content, $network_interfaces_by_agents = agents_get_network_interfaces(false, $filter); if (empty($network_interfaces_by_agents)) { - $return['error'] = 1; + $return['failed'] = + __('The group has no agents or none of the agents has any network interface'); $return['data'] = array(); } else { - $return['error'] = 0; + $return['failed'] = null; $return['data'] = array(); foreach ($network_interfaces_by_agents as $agent_id => $agent) { diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index 3c2fce6db9..3feb2fe9a4 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -1218,11 +1218,10 @@ function reporting_html_group_configuration($table, $item) { function reporting_html_network_interfaces_report($table, $item) { - if ($item['error']) { + if (!empty($item['failed'])) { $table->colspan['interfaces']['cell'] = 3; $table->cellstyle['interfaces']['cell'] = 'text-align: left;'; - $table->data['interfaces']['cell'] = - __('The group has no agents or none of the agents has any network interface'); + $table->data['interfaces']['cell'] = $item['failed']; } else { From fadeaef80a16b32362f5c6c624daf1c159f9a28f Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Thu, 14 May 2015 13:17:59 +0200 Subject: [PATCH 65/80] Some fixed for the enterprise PDF reports. --- .../include/functions_reporting.php | 317 +++++++++++++++++- .../include/functions_reporting_html.php | 256 +------------- 2 files changed, 303 insertions(+), 270 deletions(-) diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index 7cbcba5c39..18091c6495 100644 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -1557,6 +1557,17 @@ function reporting_exception($report, $content, $type = 'dinamic', $content['name'] = __('Exception'); } + $order_uptodown = $content['order_uptodown']; + $exception_condition_value = $content['exception_condition_value']; + $show_graph = $content['show_graph']; + + $formated_exception_value = $exception_condition_value; + if (is_numeric($exception_condition_value)) { + $formated_exception_value = format_for_graph( + $exception_condition_value, 2); + } + + $return['title'] = $content['name']; $exception_condition = $content['exception_condition']; switch ($exception_condition) { @@ -1566,32 +1577,32 @@ function reporting_exception($report, $content, $type = 'dinamic', case REPORT_EXCEPTION_CONDITION_GE: $return['subtitle'] = sprintf(__('Exception - Modules over or equal to %s'), - $exception_condition_value); + $formated_exception_value); break; case REPORT_EXCEPTION_CONDITION_LE: $return['subtitle'] = sprintf(__('Exception - Modules under or equal to %s'), - $exception_condition_value); + $formated_exception_value); break; case REPORT_EXCEPTION_CONDITION_L: $return['subtitle'] = sprintf(__('Exception - Modules under %s'), - $exception_condition_value); + $formated_exception_value); break; case REPORT_EXCEPTION_CONDITION_G: $return['subtitle'] = sprintf(__('Exception - Modules over %s'), - $exception_condition_value); + $formated_exception_value); break; case REPORT_EXCEPTION_CONDITION_E: $return['subtitle'] = sprintf(__('Exception - Equal to %s'), - $exception_condition_value); + $formated_exception_value); break; case REPORT_EXCEPTION_CONDITION_NE: $return['subtitle'] = sprintf(__('Exception - Not equal to %s'), - $exception_condition_value); + $formated_exception_value); break; case REPORT_EXCEPTION_CONDITION_OK: $return['subtitle'] = @@ -1609,9 +1620,7 @@ function reporting_exception($report, $content, $type = 'dinamic', $return["chart"] = array(); $return["resume"] = array(); - $order_uptodown = $content['order_uptodown']; - $exception_condition_value = $content['exception_condition_value']; - $show_graph = $content['show_graph']; + //Get all the related data $sql = sprintf(" @@ -1885,16 +1894,34 @@ function reporting_exception($report, $content, $type = 'dinamic', } - $return["chart"]["pie"] = pie3d_graph(false, $data_pie_graph, - 600, 150, __("other"), + $return["chart"]["pie"] = pie3d_graph( + false, + $data_pie_graph, + 600, + 150, + __("other"), ui_get_full_url(false, false, false, false), ui_get_full_url(false, false, false, false) . "/images/logo_vertical_water.png", - $config['fontpath'], $config['font_size']); - $return["chart"]["hbar"] = hbar_graph(false, - $data_hbar, 600, $height, - array(), array(), "", "", true, + $config['fontpath'], + $config['font_size'], + $ttl); + $return["chart"]["hbar"] = hbar_graph( + false, + $data_hbar, + 600, + 100, + array(), + array(), + "", + "", + true, ui_get_full_url(false, false, false, false), - ui_get_full_url(false, false, false, false) . "/images/logo_vertical_water.png", '', '', true, 1, true); + ui_get_full_url(false, false, false, false) . "/images/logo_vertical_water.png", + '', + '', + true, + $ttl, + true); } @@ -6416,4 +6443,262 @@ function reporting_get_count_events_by_agent ($id_group, $period = 0, $filter_event_warning, $filter_event_no_validated, $filter_event_filter_search); } + +/** + * Get the maximum value of an agent module in a period of time. + * + * @param int Agent module id to get the maximum value. + * @param int Period of time to check (in seconds) + * @param int Top date to check the values. Default current time. + * + * @return float The maximum module value in the interval. + */ +function reporting_get_agentmodule_data_max ($id_agent_module, $period=0, $date = 0) { + global $config; + + // Initialize variables + if (empty ($date)) $date = get_system_time (); + $datelimit = $date - $period; + + $search_in_history_db = db_search_in_history_db($datelimit); + + $id_module_type = modules_get_agentmodule_type ($id_agent_module); + $module_type = modules_get_moduletype_name ($id_module_type); + $uncompressed_module = is_module_uncompressed ($module_type); + + // Get module data + $interval_data = db_get_all_rows_sql ('SELECT * + FROM tagente_datos + WHERE id_agente_modulo = ' . (int) $id_agent_module . + ' AND utimestamp > ' . (int) $datelimit . + ' AND utimestamp < ' . (int) $date . + ' ORDER BY utimestamp ASC', $search_in_history_db); + if ($interval_data === false) $interval_data = array (); + + // Uncompressed module data + if ($uncompressed_module) { + + // Compressed module data + } + else { + // Get previous data + $previous_data = modules_get_previous_data ($id_agent_module, $datelimit); + if ($previous_data !== false) { + $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) { + $next_data['utimestamp'] = $date; + array_push ($interval_data, $next_data); + } + else if (count ($interval_data) > 0) { + // Propagate the last known data to the end of the interval + $next_data = array_pop ($interval_data); + array_push ($interval_data, $next_data); + $next_data['utimestamp'] = $date; + array_push ($interval_data, $next_data); + } + } + + // Set initial conditions + if (empty($iterval_data)) { + $max = 0; + } + else { + if ($uncompressed_module || $interval_data[0]['utimestamp'] == $datelimit) { + $max = $interval_data[0]['datos']; + } + else { + $max = 0; + } + } + + foreach ($interval_data as $data) { + if ($data['datos'] > $max) { + $max = $data['datos']; + } + } + + return $max; +} + +/** + * Get the minimum value of an agent module in a period of time. + * + * @param int Agent module id to get the minimum value. + * @param int Period of time to check (in seconds) + * @param int Top date to check the values in Unix time. Default current time. + * + * @return float The minimum module value of the module + */ +function reporting_get_agentmodule_data_min ($id_agent_module, $period=0, $date = 0) { + global $config; + + // Initialize variables + if (empty ($date)) $date = get_system_time (); + $datelimit = $date - $period; + + $search_in_history_db = db_search_in_history_db($datelimit); + + $id_module_type = modules_get_agentmodule_type ($id_agent_module); + $module_type = modules_get_moduletype_name ($id_module_type); + $uncompressed_module = is_module_uncompressed ($module_type); + + // Get module data + $interval_data = db_get_all_rows_sql ('SELECT * + FROM tagente_datos + WHERE id_agente_modulo = ' . (int) $id_agent_module . + ' AND utimestamp > ' . (int) $datelimit . + ' AND utimestamp < ' . (int) $date . + ' ORDER BY utimestamp ASC', $search_in_history_db); + if ($interval_data === false) $interval_data = array (); + + // Uncompressed module data + if ($uncompressed_module) { + $min_necessary = 1; + + // Compressed module data + } + else { + // Get previous data + $previous_data = modules_get_previous_data ($id_agent_module, $datelimit); + if ($previous_data !== false) { + $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) { + $next_data['utimestamp'] = $date; + array_push ($interval_data, $next_data); + } + else if (count ($interval_data) > 0) { + // Propagate the last known data to the end of the interval + $next_data = array_pop ($interval_data); + array_push ($interval_data, $next_data); + $next_data['utimestamp'] = $date; + array_push ($interval_data, $next_data); + } + } + + if (count ($interval_data) < 1) { + return false; + } + + // Set initial conditions + $min = $interval_data[0]['datos']; + + foreach ($interval_data as $data) { + if ($data['datos'] < $min) { + $min = $data['datos']; + } + } + + return $min; +} + +/** + * Get the sum of values of an agent module in a period of time. + * + * @param int Agent module id to get the sumatory. + * @param int Period of time to check (in seconds) + * @param int Top date to check the values. Default current time. + * + * @return float The sumatory of the module values in the interval. + */ +function reporting_get_agentmodule_data_sum ($id_agent_module, + $period = 0, $date = 0) { + + global $config; + + // Initialize variables + if (empty ($date)) $date = get_system_time (); + $datelimit = $date - $period; + + $search_in_history_db = db_search_in_history_db($datelimit); + + $id_module_type = db_get_value ('id_tipo_modulo', 'tagente_modulo', + 'id_agente_modulo', $id_agent_module); + $module_name = db_get_value ('nombre', 'ttipo_modulo', 'id_tipo', + $id_module_type); + $module_interval = modules_get_interval ($id_agent_module); + $uncompressed_module = is_module_uncompressed ($module_name); + + // Wrong module type + if (is_module_data_string ($module_name)) { + return 0; + } + + // Incremental modules are treated differently + $module_inc = is_module_inc ($module_name); + + // Get module data + $interval_data = db_get_all_rows_sql(' + SELECT * FROM tagente_datos + WHERE id_agente_modulo = ' . (int) $id_agent_module . ' + AND utimestamp > ' . (int) $datelimit . ' + AND utimestamp < ' . (int) $date . ' + ORDER BY utimestamp ASC', $search_in_history_db); + if ($interval_data === false) $interval_data = array (); + + // Uncompressed module data + if ($uncompressed_module) { + $min_necessary = 1; + + // Compressed module data + } + else { + // Get previous data + $previous_data = modules_get_previous_data ($id_agent_module, $datelimit); + if ($previous_data !== false) { + $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) { + $next_data['utimestamp'] = $date; + array_push ($interval_data, $next_data); + } + else if (count ($interval_data) > 0) { + // Propagate the last known data to the end of the interval + $next_data = array_pop ($interval_data); + array_push ($interval_data, $next_data); + $next_data['utimestamp'] = $date; + array_push ($interval_data, $next_data); + } + + $min_necessary = 2; + } + + if (count ($interval_data) < $min_necessary) { + return false; + } + + // Set initial conditions + $total = 0; + if (! $uncompressed_module) { + $previous_data = array_shift ($interval_data); + } + + foreach ($interval_data as $data) { + if ($uncompressed_module) { + $total += $data['datos']; + } + else if ($module_inc) { + $total += $previous_data['datos'] * ($data['utimestamp'] - $previous_data['utimestamp']); + } + else { + $total += $previous_data['datos'] * ($data['utimestamp'] - $previous_data['utimestamp']) / $module_interval; + } + $previous_data = $data; + } + + return $total; +} ?> \ No newline at end of file diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index 3feb2fe9a4..23a6aed5b6 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -1816,263 +1816,11 @@ function reporting_html_sql(&$table, $item) { } -/** - * Get the maximum value of an agent module in a period of time. - * - * @param int Agent module id to get the maximum value. - * @param int Period of time to check (in seconds) - * @param int Top date to check the values. Default current time. - * - * @return float The maximum module value in the interval. - */ -function reporting_get_agentmodule_data_max ($id_agent_module, $period=0, $date = 0) { - global $config; - - // Initialize variables - if (empty ($date)) $date = get_system_time (); - $datelimit = $date - $period; - - $search_in_history_db = db_search_in_history_db($datelimit); - - $id_module_type = modules_get_agentmodule_type ($id_agent_module); - $module_type = modules_get_moduletype_name ($id_module_type); - $uncompressed_module = is_module_uncompressed ($module_type); - - // Get module data - $interval_data = db_get_all_rows_sql ('SELECT * - FROM tagente_datos - WHERE id_agente_modulo = ' . (int) $id_agent_module . - ' AND utimestamp > ' . (int) $datelimit . - ' AND utimestamp < ' . (int) $date . - ' ORDER BY utimestamp ASC', $search_in_history_db); - if ($interval_data === false) $interval_data = array (); - - // Uncompressed module data - if ($uncompressed_module) { - - // Compressed module data - } - else { - // Get previous data - $previous_data = modules_get_previous_data ($id_agent_module, $datelimit); - if ($previous_data !== false) { - $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) { - $next_data['utimestamp'] = $date; - array_push ($interval_data, $next_data); - } - else if (count ($interval_data) > 0) { - // Propagate the last known data to the end of the interval - $next_data = array_pop ($interval_data); - array_push ($interval_data, $next_data); - $next_data['utimestamp'] = $date; - array_push ($interval_data, $next_data); - } - } - - // Set initial conditions - if (empty($iterval_data)) { - $max = 0; - } - else { - if ($uncompressed_module || $interval_data[0]['utimestamp'] == $datelimit) { - $max = $interval_data[0]['datos']; - } - else { - $max = 0; - } - } - - foreach ($interval_data as $data) { - if ($data['datos'] > $max) { - $max = $data['datos']; - } - } - - return $max; -} -/** - * Get the minimum value of an agent module in a period of time. - * - * @param int Agent module id to get the minimum value. - * @param int Period of time to check (in seconds) - * @param int Top date to check the values in Unix time. Default current time. - * - * @return float The minimum module value of the module - */ -function reporting_get_agentmodule_data_min ($id_agent_module, $period=0, $date = 0) { - global $config; - - // Initialize variables - if (empty ($date)) $date = get_system_time (); - $datelimit = $date - $period; - $search_in_history_db = db_search_in_history_db($datelimit); - - $id_module_type = modules_get_agentmodule_type ($id_agent_module); - $module_type = modules_get_moduletype_name ($id_module_type); - $uncompressed_module = is_module_uncompressed ($module_type); - - // Get module data - $interval_data = db_get_all_rows_sql ('SELECT * - FROM tagente_datos - WHERE id_agente_modulo = ' . (int) $id_agent_module . - ' AND utimestamp > ' . (int) $datelimit . - ' AND utimestamp < ' . (int) $date . - ' ORDER BY utimestamp ASC', $search_in_history_db); - if ($interval_data === false) $interval_data = array (); - - // Uncompressed module data - if ($uncompressed_module) { - $min_necessary = 1; - - // Compressed module data - } - else { - // Get previous data - $previous_data = modules_get_previous_data ($id_agent_module, $datelimit); - if ($previous_data !== false) { - $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) { - $next_data['utimestamp'] = $date; - array_push ($interval_data, $next_data); - } - else if (count ($interval_data) > 0) { - // Propagate the last known data to the end of the interval - $next_data = array_pop ($interval_data); - array_push ($interval_data, $next_data); - $next_data['utimestamp'] = $date; - array_push ($interval_data, $next_data); - } - } - - if (count ($interval_data) < 1) { - return false; - } - - // Set initial conditions - $min = $interval_data[0]['datos']; - - foreach ($interval_data as $data) { - if ($data['datos'] < $min) { - $min = $data['datos']; - } - } - - return $min; -} -/** - * Get the sum of values of an agent module in a period of time. - * - * @param int Agent module id to get the sumatory. - * @param int Period of time to check (in seconds) - * @param int Top date to check the values. Default current time. - * - * @return float The sumatory of the module values in the interval. - */ -function reporting_get_agentmodule_data_sum ($id_agent_module, - $period = 0, $date = 0) { - - global $config; - - // Initialize variables - if (empty ($date)) $date = get_system_time (); - $datelimit = $date - $period; - - $search_in_history_db = db_search_in_history_db($datelimit); - - $id_module_type = db_get_value ('id_tipo_modulo', 'tagente_modulo', - 'id_agente_modulo', $id_agent_module); - $module_name = db_get_value ('nombre', 'ttipo_modulo', 'id_tipo', - $id_module_type); - $module_interval = modules_get_interval ($id_agent_module); - $uncompressed_module = is_module_uncompressed ($module_name); - - // Wrong module type - if (is_module_data_string ($module_name)) { - return 0; - } - - // Incremental modules are treated differently - $module_inc = is_module_inc ($module_name); - - // Get module data - $interval_data = db_get_all_rows_sql(' - SELECT * FROM tagente_datos - WHERE id_agente_modulo = ' . (int) $id_agent_module . ' - AND utimestamp > ' . (int) $datelimit . ' - AND utimestamp < ' . (int) $date . ' - ORDER BY utimestamp ASC', $search_in_history_db); - if ($interval_data === false) $interval_data = array (); - - // Uncompressed module data - if ($uncompressed_module) { - $min_necessary = 1; - - // Compressed module data - } - else { - // Get previous data - $previous_data = modules_get_previous_data ($id_agent_module, $datelimit); - if ($previous_data !== false) { - $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) { - $next_data['utimestamp'] = $date; - array_push ($interval_data, $next_data); - } - else if (count ($interval_data) > 0) { - // Propagate the last known data to the end of the interval - $next_data = array_pop ($interval_data); - array_push ($interval_data, $next_data); - $next_data['utimestamp'] = $date; - array_push ($interval_data, $next_data); - } - - $min_necessary = 2; - } - - if (count ($interval_data) < $min_necessary) { - return false; - } - - // Set initial conditions - $total = 0; - if (! $uncompressed_module) { - $previous_data = array_shift ($interval_data); - } - - foreach ($interval_data as $data) { - if ($uncompressed_module) { - $total += $data['datos']; - } - else if ($module_inc) { - $total += $previous_data['datos'] * ($data['utimestamp'] - $previous_data['utimestamp']); - } - else { - $total += $previous_data['datos'] * ($data['utimestamp'] - $previous_data['utimestamp']) / $module_interval; - } - $previous_data = $data; - } - - return $total; -} + + /** * Get SLA of a module. From 60d301944da8bcc657dd7ab493c697d80be3dee1 Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Thu, 14 May 2015 15:52:55 +0200 Subject: [PATCH 66/80] Some fixed for the enterprise PDF reports. --- pandora_console/include/functions_reporting_html.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index 23a6aed5b6..9422c71a42 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -1731,7 +1731,7 @@ function reporting_html_general(&$table, $item) { foreach ($list_modules as $name) { $table1->style[$name] = 'text-align: right;'; if (isset($modules[$name])) { - $row[$name] = $value; + $row[$name] = $modules[$name]; } else { $row[$name] = "--"; From 98d9032034d20cb2ad0d1788069dfe8b687b7c13 Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Thu, 14 May 2015 16:21:04 +0200 Subject: [PATCH 67/80] Some fixed for the enterprise PDF reports. --- .../include/functions_reporting.php | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index 18091c6495..7f22d2f4fa 100644 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -1114,17 +1114,33 @@ function reporting_event_top_n($report, $content, $type = 'dinamic', $return['charts']['pie'] = pie3d_graph(false, $data_pie_graph, - $width, $height, __("other"), + $width, $height, + __("other"), ui_get_full_url(false, true, false, false) . '/', ui_get_full_url(false, false, false, false) . "/images/logo_vertical_water.png", - $config['fontpath'], $config['font_size']); + $config['fontpath'], + $config['font_size'], + $ttl); //Display bars graph $return['charts']['bars'] = hbar_graph( - false, $data_hbar, $width, - $height, array(), array(), "", "", true, - ui_get_full_url(false, true, false, false) . '/', $config['homedir'] . "/images/logo_vertical_water.png", $config['fontpath'], $config['font_size'], true, 1, true); + false, + $data_hbar, + $width, + count($data_hbar) * 50, + array(), + array(), + "", + "", + true, + ui_get_full_url(false, true, false, false) . '/', + $config['homedir'] . "/images/logo_vertical_water.png", + $config['fontpath'], + $config['font_size'], + true, + $ttl, + true); } $return['resume'] = null; From 4387c36bbfa76670c077c4ba1cfbe71de874bdef Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Thu, 14 May 2015 17:26:49 +0200 Subject: [PATCH 68/80] Some fixed for the enterprise PDF reports. --- .../include/functions_reporting.php | 696 +++++++++++++++++- .../include/functions_reporting_html.php | 652 ---------------- 2 files changed, 689 insertions(+), 659 deletions(-) diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index 7f22d2f4fa..a140b663dc 100644 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -462,6 +462,18 @@ function reporting_SLA($report, $content, $type = 'dinamic', $return["date"] = reporting_get_date_text($report, $content); + // Get chart + reporting_set_conf_charts($width, $height, $only_image, $type, + $content, $ttl); + + if (!empty($force_width_chart)) { + $width = $force_width_chart; + } + + if (!empty($force_height_chart)) { + $height = $force_height_chart; + } + $edge_interval = 10; @@ -777,8 +789,10 @@ function reporting_SLA($report, $content, $type = 'dinamic', if ($show_table) { $data = array (); - $data['agent'] = modules_get_agentmodule_agent_name ($sla['id_agent_module']); - $data['module'] = modules_get_agentmodule_name ($sla['id_agent_module']); + $data['agent'] = modules_get_agentmodule_agent_name( + $sla['id_agent_module']); + $data['module'] = modules_get_agentmodule_name( + $sla['id_agent_module']); $data['max'] = $sla['sla_max']; $data['min'] = $sla['sla_min']; $data['sla_limit'] = $sla['sla_limit']; @@ -813,7 +827,7 @@ function reporting_SLA($report, $content, $type = 'dinamic', // } $data['sla_value'] = $sla_value; - $data['sla_formated_value'] = format_numeric ($sla_value, 2). "%"; + $data['sla_formated_value'] = format_numeric($sla_value, 2). "%"; } $return['data'][] = $data; @@ -827,10 +841,20 @@ function reporting_SLA($report, $content, $type = 'dinamic', $dataslice['module'] = modules_get_agentmodule_name ($sla['id_agent_module']); $dataslice['chart'] = graph_sla_slicebar( - $sla['id_agent_module'], $content['period'], - $sla['sla_min'], $sla['sla_max'], - $report['datetime'], $content, $content['time_from'], - $content['time_to'], 650, 25, $urlImage, 1, false, false); + $sla['id_agent_module'], + $content['period'], + $sla['sla_min'], + $sla['sla_max'], + $report['datetime'], + $content, + $content['time_from'], + $content['time_to'], + 650, + 25, + $urlImage, + $ttl, + false, + false); $return['charts'][] = $dataslice; } @@ -6717,4 +6741,662 @@ function reporting_get_agentmodule_data_sum ($id_agent_module, return $total; } + +/** + * Get the planned downtimes that affect the passed modules on an specific datetime range. + * + * @param int Start date in utimestamp. + * @param int End date in utimestamp. + * @param array The agent modules ids. + * + * @return Array with the planned downtimes that are executed in any moment of the range selected and affect the + * agent modules selected. + */ +function reporting_get_planned_downtimes ($start_date, $end_date, $id_agent_modules = false) { + $start_time = date("H:i:s", $start_date); + $end_time = date("H:i:s", $end_date); + + $start_day = date("d", $start_date); + $end_day = date("d", $end_date); + + $start_month = date("m", $start_date); + $end_month = date("m", $end_date); + + if ($start_date > $end_date) { + return false; + } + + if ($end_date - $start_date >= SECONDS_1MONTH) { + // If the date range is larger than 1 month, every monthly planned downtime will be inside + $periodically_monthly_w = "type_periodicity = 'monthly'"; + } + else { + // Check if the range is larger than the planned downtime execution, or if its start or end + // is inside the planned downtime execution. + // The start and end time is very important. + $periodically_monthly_w = "type_periodicity = 'monthly' + AND (((periodically_day_from > '$start_day' + OR (periodically_day_from = '$start_day' + AND periodically_time_from >= '$start_time')) + AND (periodically_day_to < '$end_day' + OR (periodically_day_to = '$end_day' + AND periodically_time_to <= '$end_time'))) + OR ((periodically_day_from < '$start_day' + OR (periodically_day_from = '$start_day' + AND periodically_time_from <= '$start_time')) + AND (periodically_day_to > '$start_day' + OR (periodically_day_to = '$start_day' + AND periodically_time_to >= '$start_time'))) + OR ((periodically_day_from < '$end_day' + OR (periodically_day_from = '$end_day' + AND periodically_time_from <= '$end_time')) + AND (periodically_day_to > '$end_day' + OR (periodically_day_to = '$end_day' + AND periodically_time_to >= '$end_time'))))"; + } + + $periodically_weekly_days = array(); + $date_aux = $start_date; + $i = 0; + + if (($end_date - $start_date) >= SECONDS_1WEEK) { + // If the date range is larger than 7 days, every weekly planned downtime will be inside. + for ($i = 0; $i < 7; $i++) { + $weekday_actual = strtolower(date('l', $date_aux)); + $periodically_weekly_days[] = "($weekday_actual = 1)"; + $date_aux += SECONDS_1DAY; + } + } + else if (($end_date - $start_date) <= SECONDS_1DAY && $start_day == $end_day) { + // If the date range is smaller than 1 day, the start and end days can be equal or consecutive. + // If they are equal, the execution times have to be contained in the date range times or contain + // the start or end time of the date range. + $weekday_actual = strtolower(date('l', $start_date)); + $periodically_weekly_days[] = "($weekday_actual = 1 + AND ((periodically_time_from > '$start_time' AND periodically_time_to < '$end_time') + OR (periodically_time_from = '$start_time' + OR (periodically_time_from < '$start_time' + AND periodically_time_to >= '$start_time')) + OR (periodically_time_from = '$end_time' + OR (periodically_time_from < '$end_time' + AND periodically_time_to >= '$end_time'))))"; + } + else { + while ($date_aux <= $end_date && $i < 7) { + + $weekday_actual = strtolower(date('l', $date_aux)); + $day_num_actual = date('d', $date_aux); + + if ($date_aux == $start_date) { + $periodically_weekly_days[] = "($weekday_actual = 1 AND periodically_time_to >= '$start_time')"; + } + else if ($day_num_actual == $end_day) { + $periodically_weekly_days[] = "($weekday_actual = 1 AND periodically_time_from <= '$end_time')"; + } + else { + $periodically_weekly_days[] = "($weekday_actual = 1)"; + } + + $date_aux += SECONDS_1DAY; + $i++; + } + } + + if (!empty($periodically_weekly_days)) { + $periodically_weekly_w = "type_periodicity = 'weekly' AND (".implode(" OR ", $periodically_weekly_days).")"; + $periodically_condition = "(($periodically_monthly_w) OR ($periodically_weekly_w))"; + } + else { + $periodically_condition = "($periodically_monthly_w)"; + } + + if ($id_agent_modules !== false) { + if (empty($id_agent_modules)) + return array(); + + $id_agent_modules_str = implode(",", $id_agent_modules); + + $sql_downtime = "SELECT DISTINCT(tpdr.id), tpdr.* + FROM ( + SELECT tpd.* + FROM tplanned_downtime tpd, tplanned_downtime_agents tpda, tagente_modulo tam + WHERE (tpd.id = tpda.id_downtime + AND tpda.all_modules = 1 + AND tpda.id_agent = tam.id_agente + AND tam.id_agente_modulo IN ($id_agent_modules_str)) + AND ((type_execution = 'periodically' + AND $periodically_condition) + OR (type_execution = 'once' + AND ((date_from >= '$start_date' AND date_to <= '$end_date') + OR (date_from <= '$start_date' AND date_to >= '$end_date') + OR (date_from <= '$start_date' AND date_to >= '$start_date') + OR (date_from <= '$end_date' AND date_to >= '$end_date')))) + UNION ALL + SELECT tpd.* + FROM tplanned_downtime tpd, tplanned_downtime_modules tpdm + WHERE (tpd.id = tpdm.id_downtime + AND tpdm.id_agent_module IN ($id_agent_modules_str)) + AND ((type_execution = 'periodically' + AND $periodically_condition) + OR (type_execution = 'once' + AND ((date_from >= '$start_date' AND date_to <= '$end_date') + OR (date_from <= '$start_date' AND date_to >= '$end_date') + OR (date_from <= '$start_date' AND date_to >= '$start_date') + OR (date_from <= '$end_date' AND date_to >= '$end_date')))) + ) tpdr + ORDER BY tpdr.id"; + } + else { + $sql_downtime = "SELECT * + FROM tplanned_downtime tpd, tplanned_downtime_modules tpdm + WHERE (type_execution = 'periodically' + AND $periodically_condition) + OR (type_execution = 'once' + AND ((date_from >= '$start_date' AND date_to <= '$end_date') + OR (date_from <= '$start_date' AND date_to >= '$end_date') + OR (date_from <= '$start_date' AND date_to >= '$start_date') + OR (date_from <= '$end_date' AND date_to >= '$end_date')))"; + } + + $downtimes = db_get_all_rows_sql($sql_downtime); + if ($downtimes == false) { + $downtimes = array(); + } + + return $downtimes; +} + +/** + * Get SLA of a module. + * + * @param int Agent module to calculate SLA + * @param int Period to check the SLA compliance. + * @param int Minimum data value the module in the right interval + * @param int Maximum data value the module in the right interval. False will + * ignore max value + * @param int Beginning date of the report in UNIX time (current date by default). + * @param array $dayWeek Array of days week to extract as array('monday' => false, 'tuesday' => true....), and by default is null. + * @param string $timeFrom Time in the day to start to extract in mysql format, by default null. + * @param string $timeTo Time in the day to end to extract in mysql format, by default null. + * + * @return float SLA percentage of the requested module. False if no data were + * found + */ +function reporting_get_agentmodule_sla_day ($id_agent_module, $period = 0, $min_value = 1, $max_value = false, $date = 0, $daysWeek = null, $timeFrom = null, $timeTo = null) { + global $config; + + if (empty($id_agent_module)) + return false; + + // Initialize variables + if (empty ($date)) { + $date = get_system_time (); + } + if ($daysWeek === null) { + $daysWeek = array(); + } + // Limit date to start searching data + $datelimit = $date - $period; + + $search_in_history_db = db_search_in_history_db($datelimit); + + // Get interval data + $sql = sprintf ('SELECT * + FROM tagente_datos + 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 + if ($daysWeek) { + foreach ($daysWeek as $key => $value) { + if (!$value) { + if ($key == 'monday') { + $days[] = 2; + } + if ($key == 'tuesday') { + $days[] = 3; + } + if ($key == 'wednesday') { + $days[] = 4; + } + if ($key == 'thursday') { + $days[] = 5; + } + if ($key == 'friday') { + $days[] = 6; + } + if ($key == 'saturday') { + $days[] = 7; + } + if ($key == 'sunday') { + $days[] = 1; + } + } + } + } + + if (count($days) > 0) { + $sql .= ' AND DAYOFWEEK(FROM_UNIXTIME(utimestamp)) NOT IN (' . implode(',', $days) . ')'; + } + + if ($timeFrom < $timeTo) { + $sql .= ' AND (TIME(FROM_UNIXTIME(utimestamp)) >= "' . $timeFrom . '" AND TIME(FROM_UNIXTIME(utimestamp)) <= "'. $timeTo . '")'; + } + elseif ($timeFrom > $timeTo) { + $sql .= ' AND (TIME(FROM_UNIXTIME(utimestamp)) >= "' . $timeFrom . '" OR TIME(FROM_UNIXTIME(utimestamp)) <= "'. $timeTo . '")'; + } + $sql .= ' ORDER BY utimestamp ASC'; + $interval_data = db_get_all_rows_sql ($sql, $search_in_history_db); + + if ($interval_data === false) { + $interval_data = array (); + } + + // Calculate planned downtime dates + $downtime_dates = reporting_get_planned_downtimes_intervals($id_agent_module, $datelimit, $date); + + // Get previous data + $previous_data = modules_get_previous_data ($id_agent_module, $datelimit); + + if ($previous_data !== false) { + $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) { + $next_data['utimestamp'] = $date; + array_push ($interval_data, $next_data); + } + else if (count ($interval_data) > 0) { + // Propagate the last known data to the end of the interval + $next_data = array_pop ($interval_data); + array_push ($interval_data, $next_data); + $next_data['utimestamp'] = $date; + array_push ($interval_data, $next_data); + } + + if (count ($interval_data) < 2) { + return false; + } + + // Set initial conditions + $bad_period = 0; + $first_data = array_shift ($interval_data); + + // Do not count the empty start of an interval as 0 + if ($first_data['utimestamp'] != $datelimit) { + $period = $date - $first_data['utimestamp']; + } + + $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; + } + } + } + else { + $previous_status = 0; + } + + + + foreach ($interval_data as $data) { + // Previous status was critical + if ($previous_status == 1) { + $bad_period += $data['utimestamp'] - $previous_utimestamp; + } + + if (array_key_exists('datos', $data)) { + // Re-calculate previous status for the next data + if ((($max_value > $min_value AND ($data['datos'] > $max_value OR $data['datos'] < $min_value))) OR + ($max_value <= $min_value AND $data['datos'] < $min_value)) { + + $previous_status = 1; + foreach ($downtime_dates as $date_dt) { + if (($date_dt['date_from'] <= $data['utimestamp']) AND ($date_dt['date_to'] >= $data['utimestamp'])) { + $previous_status = 0; + } + } + } + else { + $previous_status = 0; + } + } + + $previous_utimestamp = $data['utimestamp']; + } + + // Return the percentage of SLA compliance + return (float) (100 - ($bad_period / $period) * 100); +} + +/** + * Get several SLA data for an agentmodule within a period divided on subperiods + * + * @param int Agent module to calculate SLA + * @param int Period to check the SLA compliance. + * @param int Minimum data value the module in the right interval + * @param int Maximum data value the module in the right interval. False will + * ignore max value + * @param array $days Array of days week to extract as array('monday' => false, 'tuesday' => true....), and by default is null. + * @param string $timeFrom Time in the day to start to extract in mysql format, by default null. + * @param string $timeTo Time in the day to end to extract in mysql format, by default null. + * + * @return Array with values either 1, 2, 3 or 4 depending if the SLA percentage for this subperiod + * is within the sla limits, on the edge, outside or with an unknown value. + */ +function reporting_get_agentmodule_sla_array ($id_agent_module, $period = 0, $min_value = 1, $max_value = false, $date = 0, $daysWeek = null, $timeFrom = null, $timeTo = null) { + global $config; + + if (empty($id_agent_module)) + return false; + + // Initialize variables + if (empty ($date)) { + $date = get_system_time (); + } + if ($daysWeek === null) { + $daysWeek = array(); + } + + // Hotfix: The edge values are confuse to the users + $percent = 0; + + // Limit date to start searching data + $datelimit = $date - $period; + + $search_in_history_db = db_search_in_history_db($datelimit); + + // Get interval data + $sql = sprintf ('SELECT * FROM tagente_datos + 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 + + if ($daysWeek) { + foreach ($daysWeek as $key => $value) { + if (!$value) { + if ($key == 'monday') { + $days[] = 2; + } + if ($key == 'tuesday') { + $days[] = 3; + } + if ($key == 'wednesday') { + $days[] = 4; + } + if ($key == 'thursday') { + $days[] = 5; + } + if ($key == 'friday') { + $days[] = 6; + } + if ($key == 'saturday') { + $days[] = 7; + } + if ($key == 'sunday') { + $days[] = 1; + } + } + } + } + + if (count($days) > 0) { + $sql .= ' AND DAYOFWEEK(FROM_UNIXTIME(utimestamp)) NOT IN (' . implode(',', $days) . ')'; + } + + if ($timeFrom != $timeTo) { + if ($timeFrom < $timeTo) { + $sql .= ' AND (TIME(FROM_UNIXTIME(utimestamp)) >= "' . $timeFrom . '" AND TIME(FROM_UNIXTIME(utimestamp)) <= "'. $timeTo . '")'; + } + elseif ($timeFrom > $timeTo) { + $sql .= ' AND (TIME(FROM_UNIXTIME(utimestamp)) >= "' . $timeFrom . '" OR TIME(FROM_UNIXTIME(utimestamp)) <= "'. $timeTo . '")'; + } + } + + $sql .= ' ORDER BY utimestamp ASC'; + $interval_data = db_get_all_rows_sql ($sql, $search_in_history_db); + + if ($interval_data === false) { + $interval_data = array (); + } + + + // Indexing data + $interval_data_indexed = array(); + 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, + "utimestamp > $datelimit", + "utimestamp < $date", + 'order' => 'utimestamp ASC'), + array ('id_evento', 'evento', 'timestamp', 'utimestamp', 'event_type')); + + if ($events_unknown === false) { + $events_unknown = array (); + } + + // Add unknown periods to data + for ($i = 0; isset($events_unknown[$i]); $i++) { + $eu = $events_unknown[$i]; + + if ($eu['event_type'] == 'going_unknown') { + $interval_data_indexed[$eu['utimestamp']]['data'] = 0; + $interval_data_indexed[$eu['utimestamp']]['status'] = 4; + + // Search the corresponding recovery event. + for ($j = $i+1; isset($events_unknown[$j]); $j++) { + $eu = $events_unknown[$j]; + + if ($eu['event_type'] != 'going_unknown' && substr ($eu['event_type'], 0, 5) == 'going') { + $interval_data_indexed[$eu['utimestamp']]['data'] = 0; + $interval_data_indexed[$eu['utimestamp']]['status'] = 6; + + // Do not process read events again. + $i = $j; + break; + } + } + } + } + + // 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, + "utimestamp <= $datelimit", + 'order' => 'utimestamp DESC')); + if (isset($prev_event['event_type']) && $prev_event['event_type'] == 'going_unknown') { + $start_unknown = true; + } + else { + $start_unknown = false; + } + //------------------------------------------------------------------ + + //-----------------Set limits of the interval----------------------- + // 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 ) { + $previous_value = $previous_data['datos']; + // if ((($previous_value > ($min_value - $percent)) && ($previous_value < ($min_value + $percent))) || + // (($previous_value > ($max_value - $percent)) && ($previous_value < ($max_value + $percent)))) {//2 when value is within the edges + // $previous_known_status = 2; + // } + // else + if (($previous_value >= ($min_value + $percent)) && ($previous_value <= ($max_value - $percent))) { //1 when value is OK + $previous_known_status = 1; + } + elseif (($previous_value <= ($min_value - $percent)) || ($previous_value >= ($max_value + $percent))) { //3 when value is Wrong + $previous_known_status = 3; + } + } + + // If the starting of the graph is unknown we set it + if ($start_unknown) { + $interval_data_indexed[$datelimit]['data'] = 0; + $interval_data_indexed[$datelimit]['status'] = 4; + } + else { + if ($previous_data !== false ) { + $interval_data_indexed[$datelimit]['data'] = $previous_data['datos']; + } + else { // If there are not data befor interval set unknown + $interval_data_indexed[$datelimit]['data'] = 0; + $interval_data_indexed[$datelimit]['status'] = 4; + $previous_known_status = 1; // Assume the module was in normal status if there is no previous data. + } + } + + // 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) { + $interval_data_indexed[$date]['data'] = $previous_data['datos']; + } + else if (count ($interval_data_indexed) > 0) { + // Propagate the last known data to the end of the interval (if there is no module data at the end point) + ksort($interval_data_indexed); + $last_data = end($interval_data_indexed); + $interval_data_indexed[$date] = $last_data; + } + + //------------------------------------------------------------------ + + //--------Calculate planned downtime dates-------------------------- + $downtime_dates = reporting_get_planned_downtimes_intervals($id_agent_module, $datelimit, $date); + + foreach ($downtime_dates as $downtime_date) { + // Delete data of the planned downtime and put the last data on the upper limit + $interval_data_indexed[$downtime_date['date_from']]['data'] = 0; + $interval_data_indexed[$downtime_date['date_from']]['status'] = 5; + $interval_data_indexed[$downtime_date['date_to']]['data'] = 0; + $interval_data_indexed[$downtime_date['date_to']]['status'] = 4; + + $last_downtime_data = false; + foreach ($interval_data_indexed as $idi_timestamp => $idi) { + if ($idi_timestamp != $downtime_date['date_from'] && $idi_timestamp != $downtime_date['date_to'] && + $idi_timestamp >= $downtime_date['date_from'] && $idi_timestamp <= $downtime_date['date_to']) { + $last_downtime_data = $idi['data']; + unset($interval_data_indexed[$idi_timestamp]); + } + } + + // Set the last data of the interval as limit + if ($last_downtime_data !== false) { + $interval_data_indexed[$downtime_date['date_to']]['data'] = $last_downtime_data; + } + } + //------------------------------------------------------------------ + + // Sort the array + ksort($interval_data_indexed); + + // We need more or equal two points + if (count ($interval_data_indexed) < 2) { + return false; + } + + //Get the percentage for the limits + $diff = $max_value - $min_value; + + // Get module type + $id_module_type = db_get_value('id_tipo_modulo', 'tagente_modulo', 'id_agente_modulo', $id_agent_module); + // If module is boolean don't create translation intervals (on the edge intervals) + // if ($id_module_type == 2 or $id_module_type == 6 or $id_module_type == 9 or $id_module_type == 18){ + // $percent = 0; + // } + // else { + // // Getting 10% of $diff --> $percent = ($diff/100)*10, so... + // $percent = $diff / 10; + // } + + //Set initial conditions + $first_data = array_shift ($interval_data); + $previous_utimestamp = $date - $period; + + $previous_value = $first_data ['datos']; + $previous_status = 0; + + if (isset($first_data['status'])) { + // 4 for the Unknown value and 5 for planned downtime + $previous_status = $first_data['status']; + } + // elseif ((($previous_value > ($min_value - $percent)) && ($previous_value < ($min_value + $percent))) || + // (($previous_value > ($max_value - $percent)) && ($previous_value < ($max_value + $percent)))) {//2 when value is within the edges + // $previous_status = 2; + // } + elseif (($previous_value >= ($min_value + $percent)) && ($previous_value <= ($max_value - $percent))) { //1 when value is OK + $previous_status = 1; + } + elseif (($previous_value <= ($min_value - $percent)) || ($previous_value >= ($max_value + $percent))) { //3 when value is Wrong + $previous_status = 3; + } + + $data_colors = array(); + $i = 0; + + foreach ($interval_data_indexed as $utimestamp => $data) { + $change = false; + $value = $data['data']; + if (isset($data['status'])) { + // Leaving unkown status. + if ($data['status'] == 6) { + $status = $previous_known_status; + } + // 4 unknown, 5 planned downtime. + else { + $status = $data['status']; + } + } + // elseif ((($value > ($min_value - $percent)) && ($value < ($min_value + $percent))) || + // (($value > ($max_value - $percent)) && ($value < ($max_value + $percent)))) { //2 when value is within the edges + // $status = 2; + // } + elseif (($value >= ($min_value + $percent)) && ($value <= ($max_value - $percent))) { //1 when value is OK + $status = 1; + } + elseif (($value <= ($min_value - $percent)) || ($value >= ($max_value + $percent))) { //3 when value is Wrong + $status = 3; + } + + if ($status != $previous_status) { + $change = true; + $data_colors[$i]['data'] = $previous_status; + $data_colors[$i]['utimestamp'] = $utimestamp - $previous_utimestamp; + $i++; + $previous_status = $status; + $previous_utimestamp = $utimestamp; + } + + // Save the last known status. + if ($status <= 3) { + $previous_known_status = $status; + } + } + if ($change == false) { + $data_colors[$i]['data'] = $previous_status; + $data_colors[$i]['utimestamp'] = $date - $previous_utimestamp; + } + + return $data_colors; +} ?> \ No newline at end of file diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index 9422c71a42..ff568efc7d 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -1822,665 +1822,13 @@ function reporting_html_sql(&$table, $item) { -/** - * Get SLA of a module. - * - * @param int Agent module to calculate SLA - * @param int Period to check the SLA compliance. - * @param int Minimum data value the module in the right interval - * @param int Maximum data value the module in the right interval. False will - * ignore max value - * @param int Beginning date of the report in UNIX time (current date by default). - * @param array $dayWeek Array of days week to extract as array('monday' => false, 'tuesday' => true....), and by default is null. - * @param string $timeFrom Time in the day to start to extract in mysql format, by default null. - * @param string $timeTo Time in the day to end to extract in mysql format, by default null. - * - * @return float SLA percentage of the requested module. False if no data were - * found - */ -function reporting_get_agentmodule_sla_day ($id_agent_module, $period = 0, $min_value = 1, $max_value = false, $date = 0, $daysWeek = null, $timeFrom = null, $timeTo = null) { - global $config; - - if (empty($id_agent_module)) - return false; - - // Initialize variables - if (empty ($date)) { - $date = get_system_time (); - } - if ($daysWeek === null) { - $daysWeek = array(); - } - // Limit date to start searching data - $datelimit = $date - $period; - - $search_in_history_db = db_search_in_history_db($datelimit); - - // Get interval data - $sql = sprintf ('SELECT * - FROM tagente_datos - 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 - if ($daysWeek) { - foreach ($daysWeek as $key => $value) { - if (!$value) { - if ($key == 'monday') { - $days[] = 2; - } - if ($key == 'tuesday') { - $days[] = 3; - } - if ($key == 'wednesday') { - $days[] = 4; - } - if ($key == 'thursday') { - $days[] = 5; - } - if ($key == 'friday') { - $days[] = 6; - } - if ($key == 'saturday') { - $days[] = 7; - } - if ($key == 'sunday') { - $days[] = 1; - } - } - } - } - - if (count($days) > 0) { - $sql .= ' AND DAYOFWEEK(FROM_UNIXTIME(utimestamp)) NOT IN (' . implode(',', $days) . ')'; - } - - if ($timeFrom < $timeTo) { - $sql .= ' AND (TIME(FROM_UNIXTIME(utimestamp)) >= "' . $timeFrom . '" AND TIME(FROM_UNIXTIME(utimestamp)) <= "'. $timeTo . '")'; - } - elseif ($timeFrom > $timeTo) { - $sql .= ' AND (TIME(FROM_UNIXTIME(utimestamp)) >= "' . $timeFrom . '" OR TIME(FROM_UNIXTIME(utimestamp)) <= "'. $timeTo . '")'; - } - $sql .= ' ORDER BY utimestamp ASC'; - $interval_data = db_get_all_rows_sql ($sql, $search_in_history_db); - - if ($interval_data === false) { - $interval_data = array (); - } - - // Calculate planned downtime dates - $downtime_dates = reporting_get_planned_downtimes_intervals($id_agent_module, $datelimit, $date); - - // Get previous data - $previous_data = modules_get_previous_data ($id_agent_module, $datelimit); - - if ($previous_data !== false) { - $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) { - $next_data['utimestamp'] = $date; - array_push ($interval_data, $next_data); - } - else if (count ($interval_data) > 0) { - // Propagate the last known data to the end of the interval - $next_data = array_pop ($interval_data); - array_push ($interval_data, $next_data); - $next_data['utimestamp'] = $date; - array_push ($interval_data, $next_data); - } - - if (count ($interval_data) < 2) { - return false; - } - - // Set initial conditions - $bad_period = 0; - $first_data = array_shift ($interval_data); - - // Do not count the empty start of an interval as 0 - if ($first_data['utimestamp'] != $datelimit) { - $period = $date - $first_data['utimestamp']; - } - - $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; - } - } - } - else { - $previous_status = 0; - } - - - - foreach ($interval_data as $data) { - // Previous status was critical - if ($previous_status == 1) { - $bad_period += $data['utimestamp'] - $previous_utimestamp; - } - - if (array_key_exists('datos', $data)) { - // Re-calculate previous status for the next data - if ((($max_value > $min_value AND ($data['datos'] > $max_value OR $data['datos'] < $min_value))) OR - ($max_value <= $min_value AND $data['datos'] < $min_value)) { - - $previous_status = 1; - foreach ($downtime_dates as $date_dt) { - if (($date_dt['date_from'] <= $data['utimestamp']) AND ($date_dt['date_to'] >= $data['utimestamp'])) { - $previous_status = 0; - } - } - } - else { - $previous_status = 0; - } - } - - $previous_utimestamp = $data['utimestamp']; - } - - // Return the percentage of SLA compliance - return (float) (100 - ($bad_period / $period) * 100); -} -/** - * Get several SLA data for an agentmodule within a period divided on subperiods - * - * @param int Agent module to calculate SLA - * @param int Period to check the SLA compliance. - * @param int Minimum data value the module in the right interval - * @param int Maximum data value the module in the right interval. False will - * ignore max value - * @param array $days Array of days week to extract as array('monday' => false, 'tuesday' => true....), and by default is null. - * @param string $timeFrom Time in the day to start to extract in mysql format, by default null. - * @param string $timeTo Time in the day to end to extract in mysql format, by default null. - * - * @return Array with values either 1, 2, 3 or 4 depending if the SLA percentage for this subperiod - * is within the sla limits, on the edge, outside or with an unknown value. - */ -function reporting_get_agentmodule_sla_array ($id_agent_module, $period = 0, $min_value = 1, $max_value = false, $date = 0, $daysWeek = null, $timeFrom = null, $timeTo = null) { - global $config; - - if (empty($id_agent_module)) - return false; - - // Initialize variables - if (empty ($date)) { - $date = get_system_time (); - } - if ($daysWeek === null) { - $daysWeek = array(); - } - - // Hotfix: The edge values are confuse to the users - $percent = 0; - - // Limit date to start searching data - $datelimit = $date - $period; - - $search_in_history_db = db_search_in_history_db($datelimit); - - // Get interval data - $sql = sprintf ('SELECT * FROM tagente_datos - 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 - - if ($daysWeek) { - foreach ($daysWeek as $key => $value) { - if (!$value) { - if ($key == 'monday') { - $days[] = 2; - } - if ($key == 'tuesday') { - $days[] = 3; - } - if ($key == 'wednesday') { - $days[] = 4; - } - if ($key == 'thursday') { - $days[] = 5; - } - if ($key == 'friday') { - $days[] = 6; - } - if ($key == 'saturday') { - $days[] = 7; - } - if ($key == 'sunday') { - $days[] = 1; - } - } - } - } - - if (count($days) > 0) { - $sql .= ' AND DAYOFWEEK(FROM_UNIXTIME(utimestamp)) NOT IN (' . implode(',', $days) . ')'; - } - - if ($timeFrom != $timeTo) { - if ($timeFrom < $timeTo) { - $sql .= ' AND (TIME(FROM_UNIXTIME(utimestamp)) >= "' . $timeFrom . '" AND TIME(FROM_UNIXTIME(utimestamp)) <= "'. $timeTo . '")'; - } - elseif ($timeFrom > $timeTo) { - $sql .= ' AND (TIME(FROM_UNIXTIME(utimestamp)) >= "' . $timeFrom . '" OR TIME(FROM_UNIXTIME(utimestamp)) <= "'. $timeTo . '")'; - } - } - - $sql .= ' ORDER BY utimestamp ASC'; - $interval_data = db_get_all_rows_sql ($sql, $search_in_history_db); - - if ($interval_data === false) { - $interval_data = array (); - } - - - // Indexing data - $interval_data_indexed = array(); - 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, - "utimestamp > $datelimit", - "utimestamp < $date", - 'order' => 'utimestamp ASC'), - array ('id_evento', 'evento', 'timestamp', 'utimestamp', 'event_type')); - - if ($events_unknown === false) { - $events_unknown = array (); - } - - // Add unknown periods to data - for ($i = 0; isset($events_unknown[$i]); $i++) { - $eu = $events_unknown[$i]; - - if ($eu['event_type'] == 'going_unknown') { - $interval_data_indexed[$eu['utimestamp']]['data'] = 0; - $interval_data_indexed[$eu['utimestamp']]['status'] = 4; - - // Search the corresponding recovery event. - for ($j = $i+1; isset($events_unknown[$j]); $j++) { - $eu = $events_unknown[$j]; - - if ($eu['event_type'] != 'going_unknown' && substr ($eu['event_type'], 0, 5) == 'going') { - $interval_data_indexed[$eu['utimestamp']]['data'] = 0; - $interval_data_indexed[$eu['utimestamp']]['status'] = 6; - - // Do not process read events again. - $i = $j; - break; - } - } - } - } - - // 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, - "utimestamp <= $datelimit", - 'order' => 'utimestamp DESC')); - if (isset($prev_event['event_type']) && $prev_event['event_type'] == 'going_unknown') { - $start_unknown = true; - } - else { - $start_unknown = false; - } - //------------------------------------------------------------------ - - //-----------------Set limits of the interval----------------------- - // 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 ) { - $previous_value = $previous_data['datos']; - // if ((($previous_value > ($min_value - $percent)) && ($previous_value < ($min_value + $percent))) || - // (($previous_value > ($max_value - $percent)) && ($previous_value < ($max_value + $percent)))) {//2 when value is within the edges - // $previous_known_status = 2; - // } - // else - if (($previous_value >= ($min_value + $percent)) && ($previous_value <= ($max_value - $percent))) { //1 when value is OK - $previous_known_status = 1; - } - elseif (($previous_value <= ($min_value - $percent)) || ($previous_value >= ($max_value + $percent))) { //3 when value is Wrong - $previous_known_status = 3; - } - } - - // If the starting of the graph is unknown we set it - if ($start_unknown) { - $interval_data_indexed[$datelimit]['data'] = 0; - $interval_data_indexed[$datelimit]['status'] = 4; - } - else { - if ($previous_data !== false ) { - $interval_data_indexed[$datelimit]['data'] = $previous_data['datos']; - } - else { // If there are not data befor interval set unknown - $interval_data_indexed[$datelimit]['data'] = 0; - $interval_data_indexed[$datelimit]['status'] = 4; - $previous_known_status = 1; // Assume the module was in normal status if there is no previous data. - } - } - - // 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) { - $interval_data_indexed[$date]['data'] = $previous_data['datos']; - } - else if (count ($interval_data_indexed) > 0) { - // Propagate the last known data to the end of the interval (if there is no module data at the end point) - ksort($interval_data_indexed); - $last_data = end($interval_data_indexed); - $interval_data_indexed[$date] = $last_data; - } - - //------------------------------------------------------------------ - - //--------Calculate planned downtime dates-------------------------- - $downtime_dates = reporting_get_planned_downtimes_intervals($id_agent_module, $datelimit, $date); - - foreach ($downtime_dates as $downtime_date) { - // Delete data of the planned downtime and put the last data on the upper limit - $interval_data_indexed[$downtime_date['date_from']]['data'] = 0; - $interval_data_indexed[$downtime_date['date_from']]['status'] = 5; - $interval_data_indexed[$downtime_date['date_to']]['data'] = 0; - $interval_data_indexed[$downtime_date['date_to']]['status'] = 4; - - $last_downtime_data = false; - foreach ($interval_data_indexed as $idi_timestamp => $idi) { - if ($idi_timestamp != $downtime_date['date_from'] && $idi_timestamp != $downtime_date['date_to'] && - $idi_timestamp >= $downtime_date['date_from'] && $idi_timestamp <= $downtime_date['date_to']) { - $last_downtime_data = $idi['data']; - unset($interval_data_indexed[$idi_timestamp]); - } - } - - // Set the last data of the interval as limit - if ($last_downtime_data !== false) { - $interval_data_indexed[$downtime_date['date_to']]['data'] = $last_downtime_data; - } - } - //------------------------------------------------------------------ - - // Sort the array - ksort($interval_data_indexed); - - // We need more or equal two points - if (count ($interval_data_indexed) < 2) { - return false; - } - - //Get the percentage for the limits - $diff = $max_value - $min_value; - - // Get module type - $id_module_type = db_get_value('id_tipo_modulo', 'tagente_modulo', 'id_agente_modulo', $id_agent_module); - // If module is boolean don't create translation intervals (on the edge intervals) - // if ($id_module_type == 2 or $id_module_type == 6 or $id_module_type == 9 or $id_module_type == 18){ - // $percent = 0; - // } - // else { - // // Getting 10% of $diff --> $percent = ($diff/100)*10, so... - // $percent = $diff / 10; - // } - - //Set initial conditions - $first_data = array_shift ($interval_data); - $previous_utimestamp = $date - $period; - - $previous_value = $first_data ['datos']; - $previous_status = 0; - - if (isset($first_data['status'])) { - // 4 for the Unknown value and 5 for planned downtime - $previous_status = $first_data['status']; - } - // elseif ((($previous_value > ($min_value - $percent)) && ($previous_value < ($min_value + $percent))) || - // (($previous_value > ($max_value - $percent)) && ($previous_value < ($max_value + $percent)))) {//2 when value is within the edges - // $previous_status = 2; - // } - elseif (($previous_value >= ($min_value + $percent)) && ($previous_value <= ($max_value - $percent))) { //1 when value is OK - $previous_status = 1; - } - elseif (($previous_value <= ($min_value - $percent)) || ($previous_value >= ($max_value + $percent))) { //3 when value is Wrong - $previous_status = 3; - } - - $data_colors = array(); - $i = 0; - - foreach ($interval_data_indexed as $utimestamp => $data) { - $change = false; - $value = $data['data']; - if (isset($data['status'])) { - // Leaving unkown status. - if ($data['status'] == 6) { - $status = $previous_known_status; - } - // 4 unknown, 5 planned downtime. - else { - $status = $data['status']; - } - } - // elseif ((($value > ($min_value - $percent)) && ($value < ($min_value + $percent))) || - // (($value > ($max_value - $percent)) && ($value < ($max_value + $percent)))) { //2 when value is within the edges - // $status = 2; - // } - elseif (($value >= ($min_value + $percent)) && ($value <= ($max_value - $percent))) { //1 when value is OK - $status = 1; - } - elseif (($value <= ($min_value - $percent)) || ($value >= ($max_value + $percent))) { //3 when value is Wrong - $status = 3; - } - - if ($status != $previous_status) { - $change = true; - $data_colors[$i]['data'] = $previous_status; - $data_colors[$i]['utimestamp'] = $utimestamp - $previous_utimestamp; - $i++; - $previous_status = $status; - $previous_utimestamp = $utimestamp; - } - - // Save the last known status. - if ($status <= 3) { - $previous_known_status = $status; - } - } - if ($change == false) { - $data_colors[$i]['data'] = $previous_status; - $data_colors[$i]['utimestamp'] = $date - $previous_utimestamp; - } - - return $data_colors; -} -/** - * Get the planned downtimes that affect the passed modules on an specific datetime range. - * - * @param int Start date in utimestamp. - * @param int End date in utimestamp. - * @param array The agent modules ids. - * - * @return Array with the planned downtimes that are executed in any moment of the range selected and affect the - * agent modules selected. - */ -function reporting_get_planned_downtimes ($start_date, $end_date, $id_agent_modules = false) { - $start_time = date("H:i:s", $start_date); - $end_time = date("H:i:s", $end_date); - $start_day = date("d", $start_date); - $end_day = date("d", $end_date); - $start_month = date("m", $start_date); - $end_month = date("m", $end_date); - if ($start_date > $end_date) { - return false; - } - - if ($end_date - $start_date >= SECONDS_1MONTH) { - // If the date range is larger than 1 month, every monthly planned downtime will be inside - $periodically_monthly_w = "type_periodicity = 'monthly'"; - } - else { - // Check if the range is larger than the planned downtime execution, or if its start or end - // is inside the planned downtime execution. - // The start and end time is very important. - $periodically_monthly_w = "type_periodicity = 'monthly' - AND (((periodically_day_from > '$start_day' - OR (periodically_day_from = '$start_day' - AND periodically_time_from >= '$start_time')) - AND (periodically_day_to < '$end_day' - OR (periodically_day_to = '$end_day' - AND periodically_time_to <= '$end_time'))) - OR ((periodically_day_from < '$start_day' - OR (periodically_day_from = '$start_day' - AND periodically_time_from <= '$start_time')) - AND (periodically_day_to > '$start_day' - OR (periodically_day_to = '$start_day' - AND periodically_time_to >= '$start_time'))) - OR ((periodically_day_from < '$end_day' - OR (periodically_day_from = '$end_day' - AND periodically_time_from <= '$end_time')) - AND (periodically_day_to > '$end_day' - OR (periodically_day_to = '$end_day' - AND periodically_time_to >= '$end_time'))))"; - } - - $periodically_weekly_days = array(); - $date_aux = $start_date; - $i = 0; - - if (($end_date - $start_date) >= SECONDS_1WEEK) { - // If the date range is larger than 7 days, every weekly planned downtime will be inside. - for ($i = 0; $i < 7; $i++) { - $weekday_actual = strtolower(date('l', $date_aux)); - $periodically_weekly_days[] = "($weekday_actual = 1)"; - $date_aux += SECONDS_1DAY; - } - } - else if (($end_date - $start_date) <= SECONDS_1DAY && $start_day == $end_day) { - // If the date range is smaller than 1 day, the start and end days can be equal or consecutive. - // If they are equal, the execution times have to be contained in the date range times or contain - // the start or end time of the date range. - $weekday_actual = strtolower(date('l', $start_date)); - $periodically_weekly_days[] = "($weekday_actual = 1 - AND ((periodically_time_from > '$start_time' AND periodically_time_to < '$end_time') - OR (periodically_time_from = '$start_time' - OR (periodically_time_from < '$start_time' - AND periodically_time_to >= '$start_time')) - OR (periodically_time_from = '$end_time' - OR (periodically_time_from < '$end_time' - AND periodically_time_to >= '$end_time'))))"; - } - else { - while ($date_aux <= $end_date && $i < 7) { - - $weekday_actual = strtolower(date('l', $date_aux)); - $day_num_actual = date('d', $date_aux); - - if ($date_aux == $start_date) { - $periodically_weekly_days[] = "($weekday_actual = 1 AND periodically_time_to >= '$start_time')"; - } - else if ($day_num_actual == $end_day) { - $periodically_weekly_days[] = "($weekday_actual = 1 AND periodically_time_from <= '$end_time')"; - } - else { - $periodically_weekly_days[] = "($weekday_actual = 1)"; - } - - $date_aux += SECONDS_1DAY; - $i++; - } - } - - if (!empty($periodically_weekly_days)) { - $periodically_weekly_w = "type_periodicity = 'weekly' AND (".implode(" OR ", $periodically_weekly_days).")"; - $periodically_condition = "(($periodically_monthly_w) OR ($periodically_weekly_w))"; - } - else { - $periodically_condition = "($periodically_monthly_w)"; - } - - if ($id_agent_modules !== false) { - if (empty($id_agent_modules)) - return array(); - - $id_agent_modules_str = implode(",", $id_agent_modules); - - $sql_downtime = "SELECT DISTINCT(tpdr.id), tpdr.* - FROM ( - SELECT tpd.* - FROM tplanned_downtime tpd, tplanned_downtime_agents tpda, tagente_modulo tam - WHERE (tpd.id = tpda.id_downtime - AND tpda.all_modules = 1 - AND tpda.id_agent = tam.id_agente - AND tam.id_agente_modulo IN ($id_agent_modules_str)) - AND ((type_execution = 'periodically' - AND $periodically_condition) - OR (type_execution = 'once' - AND ((date_from >= '$start_date' AND date_to <= '$end_date') - OR (date_from <= '$start_date' AND date_to >= '$end_date') - OR (date_from <= '$start_date' AND date_to >= '$start_date') - OR (date_from <= '$end_date' AND date_to >= '$end_date')))) - UNION ALL - SELECT tpd.* - FROM tplanned_downtime tpd, tplanned_downtime_modules tpdm - WHERE (tpd.id = tpdm.id_downtime - AND tpdm.id_agent_module IN ($id_agent_modules_str)) - AND ((type_execution = 'periodically' - AND $periodically_condition) - OR (type_execution = 'once' - AND ((date_from >= '$start_date' AND date_to <= '$end_date') - OR (date_from <= '$start_date' AND date_to >= '$end_date') - OR (date_from <= '$start_date' AND date_to >= '$start_date') - OR (date_from <= '$end_date' AND date_to >= '$end_date')))) - ) tpdr - ORDER BY tpdr.id"; - } - else { - $sql_downtime = "SELECT * - FROM tplanned_downtime tpd, tplanned_downtime_modules tpdm - WHERE (type_execution = 'periodically' - AND $periodically_condition) - OR (type_execution = 'once' - AND ((date_from >= '$start_date' AND date_to <= '$end_date') - OR (date_from <= '$start_date' AND date_to >= '$end_date') - OR (date_from <= '$start_date' AND date_to >= '$start_date') - OR (date_from <= '$end_date' AND date_to >= '$end_date')))"; - } - - $downtimes = db_get_all_rows_sql($sql_downtime); - if ($downtimes == false) { - $downtimes = array(); - } - - return $downtimes; -} function reporting_get_stats_servers($tiny = true) { global $config; From c1fffcfc4f3bb7cb023891623db5352f84a72256 Mon Sep 17 00:00:00 2001 From: artica Date: Fri, 15 May 2015 00:01:15 +0200 Subject: [PATCH 69/80] Auto-updated build strings. --- pandora_agents/unix/DEBIAN/control | 2 +- pandora_agents/unix/DEBIAN/make_deb_package.sh | 2 +- pandora_agents/unix/pandora_agent | 2 +- pandora_agents/unix/pandora_agent.redhat.spec | 2 +- pandora_agents/unix/pandora_agent.spec | 2 +- pandora_agents/win32/installer/pandora.mpi | 2 +- pandora_agents/win32/pandora.cc | 2 +- pandora_agents/win32/versioninfo.rc | 2 +- pandora_console/DEBIAN/control | 2 +- pandora_console/DEBIAN/make_deb_package.sh | 2 +- pandora_console/include/config_process.php | 2 +- pandora_console/install.php | 2 +- pandora_console/pandora_console.redhat.spec | 2 +- pandora_console/pandora_console.spec | 2 +- pandora_console/pandoradb_data.sql | 2 +- pandora_server/DEBIAN/control | 2 +- pandora_server/DEBIAN/make_deb_package.sh | 2 +- pandora_server/lib/PandoraFMS/Config.pm | 2 +- pandora_server/pandora_server.redhat.spec | 2 +- pandora_server/pandora_server.spec | 2 +- pandora_server/util/pandora_db.pl | 2 +- pandora_server/util/pandora_manage.pl | 2 +- 22 files changed, 22 insertions(+), 22 deletions(-) diff --git a/pandora_agents/unix/DEBIAN/control b/pandora_agents/unix/DEBIAN/control index 4767bf171a..e2c41b0cec 100644 --- a/pandora_agents/unix/DEBIAN/control +++ b/pandora_agents/unix/DEBIAN/control @@ -1,5 +1,5 @@ package: pandorafms-agent-unix -Version: 6.0dev-150514 +Version: 6.0dev-150515 Architecture: all Priority: optional Section: admin diff --git a/pandora_agents/unix/DEBIAN/make_deb_package.sh b/pandora_agents/unix/DEBIAN/make_deb_package.sh index aa53cc40c5..16209acba2 100644 --- a/pandora_agents/unix/DEBIAN/make_deb_package.sh +++ b/pandora_agents/unix/DEBIAN/make_deb_package.sh @@ -14,7 +14,7 @@ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -pandora_version="6.0dev-150514" +pandora_version="6.0dev-150515" echo "Test if you has the tools for to make the packages." whereis dpkg-deb | cut -d":" -f2 | grep dpkg-deb > /dev/null diff --git a/pandora_agents/unix/pandora_agent b/pandora_agents/unix/pandora_agent index acbb90bfbd..57f0bd59b2 100644 --- a/pandora_agents/unix/pandora_agent +++ b/pandora_agents/unix/pandora_agent @@ -41,7 +41,7 @@ my $Sem = undef; my $ThreadSem = undef; use constant AGENT_VERSION => '6.0dev'; -use constant AGENT_BUILD => '150514'; +use constant AGENT_BUILD => '150515'; # Commands to retrieve total memory information in kB use constant TOTALMEMORY_CMDS => { diff --git a/pandora_agents/unix/pandora_agent.redhat.spec b/pandora_agents/unix/pandora_agent.redhat.spec index 0cf745d560..0bdfc78c16 100644 --- a/pandora_agents/unix/pandora_agent.redhat.spec +++ b/pandora_agents/unix/pandora_agent.redhat.spec @@ -3,7 +3,7 @@ # %define name pandorafms_agent_unix %define version 6.0dev -%define release 150514 +%define release 150515 Summary: Pandora FMS Linux agent, PERL version Name: %{name} diff --git a/pandora_agents/unix/pandora_agent.spec b/pandora_agents/unix/pandora_agent.spec index 1efcc840d1..10e28228fe 100644 --- a/pandora_agents/unix/pandora_agent.spec +++ b/pandora_agents/unix/pandora_agent.spec @@ -3,7 +3,7 @@ # %define name pandorafms_agent_unix %define version 6.0dev -%define release 150514 +%define release 150515 Summary: Pandora FMS Linux agent, PERL version Name: %{name} diff --git a/pandora_agents/win32/installer/pandora.mpi b/pandora_agents/win32/installer/pandora.mpi index 85746d3f10..b2bf24a6ea 100644 --- a/pandora_agents/win32/installer/pandora.mpi +++ b/pandora_agents/win32/installer/pandora.mpi @@ -186,7 +186,7 @@ UpgradeApplicationID {} Version -{150514} +{150515} ViewReadme {Yes} diff --git a/pandora_agents/win32/pandora.cc b/pandora_agents/win32/pandora.cc index 086e349dcd..f67a33ea7c 100644 --- a/pandora_agents/win32/pandora.cc +++ b/pandora_agents/win32/pandora.cc @@ -30,7 +30,7 @@ using namespace Pandora; using namespace Pandora_Strutils; #define PATH_SIZE _MAX_PATH+1 -#define PANDORA_VERSION ("6.0dev(Build 150514)") +#define PANDORA_VERSION ("6.0dev(Build 150515)") string pandora_path; string pandora_dir; diff --git a/pandora_agents/win32/versioninfo.rc b/pandora_agents/win32/versioninfo.rc index 832a3ada61..3d1ceb7397 100644 --- a/pandora_agents/win32/versioninfo.rc +++ b/pandora_agents/win32/versioninfo.rc @@ -11,7 +11,7 @@ BEGIN VALUE "LegalCopyright", "Artica ST" VALUE "OriginalFilename", "PandoraAgent.exe" VALUE "ProductName", "Pandora FMS Windows Agent" - VALUE "ProductVersion", "(6.0dev(Build 150514))" + VALUE "ProductVersion", "(6.0dev(Build 150515))" VALUE "FileVersion", "1.0.0.0" END END diff --git a/pandora_console/DEBIAN/control b/pandora_console/DEBIAN/control index 476f603c9b..68bdd78164 100644 --- a/pandora_console/DEBIAN/control +++ b/pandora_console/DEBIAN/control @@ -1,5 +1,5 @@ package: pandorafms-console -Version: 6.0dev-150514 +Version: 6.0dev-150515 Architecture: all Priority: optional Section: admin diff --git a/pandora_console/DEBIAN/make_deb_package.sh b/pandora_console/DEBIAN/make_deb_package.sh index a797a540ad..b378b5b4d2 100644 --- a/pandora_console/DEBIAN/make_deb_package.sh +++ b/pandora_console/DEBIAN/make_deb_package.sh @@ -14,7 +14,7 @@ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -pandora_version="6.0dev-150514" +pandora_version="6.0dev-150515" package_pear=0 package_pandora=1 diff --git a/pandora_console/include/config_process.php b/pandora_console/include/config_process.php index ea063fdf0a..18d8615620 100644 --- a/pandora_console/include/config_process.php +++ b/pandora_console/include/config_process.php @@ -22,7 +22,7 @@ /** * Pandora build version and version */ -$build_version = 'PC150514'; +$build_version = 'PC150515'; $pandora_version = 'v6.0dev'; // Do not overwrite default timezone set if defined. diff --git a/pandora_console/install.php b/pandora_console/install.php index 1345fb86a7..9d8e8bafbd 100644 --- a/pandora_console/install.php +++ b/pandora_console/install.php @@ -63,7 +63,7 @@
Date: Sat, 16 May 2015 00:01:10 +0200 Subject: [PATCH 70/80] Auto-updated build strings. --- pandora_agents/unix/DEBIAN/control | 2 +- pandora_agents/unix/DEBIAN/make_deb_package.sh | 2 +- pandora_agents/unix/pandora_agent | 2 +- pandora_agents/unix/pandora_agent.redhat.spec | 2 +- pandora_agents/unix/pandora_agent.spec | 2 +- pandora_agents/win32/installer/pandora.mpi | 2 +- pandora_agents/win32/pandora.cc | 2 +- pandora_agents/win32/versioninfo.rc | 2 +- pandora_console/DEBIAN/control | 2 +- pandora_console/DEBIAN/make_deb_package.sh | 2 +- pandora_console/include/config_process.php | 2 +- pandora_console/install.php | 2 +- pandora_console/pandora_console.redhat.spec | 2 +- pandora_console/pandora_console.spec | 2 +- pandora_console/pandoradb_data.sql | 2 +- pandora_server/DEBIAN/control | 2 +- pandora_server/DEBIAN/make_deb_package.sh | 2 +- pandora_server/lib/PandoraFMS/Config.pm | 2 +- pandora_server/pandora_server.redhat.spec | 2 +- pandora_server/pandora_server.spec | 2 +- pandora_server/util/pandora_db.pl | 2 +- pandora_server/util/pandora_manage.pl | 2 +- 22 files changed, 22 insertions(+), 22 deletions(-) diff --git a/pandora_agents/unix/DEBIAN/control b/pandora_agents/unix/DEBIAN/control index e2c41b0cec..018599ebc2 100644 --- a/pandora_agents/unix/DEBIAN/control +++ b/pandora_agents/unix/DEBIAN/control @@ -1,5 +1,5 @@ package: pandorafms-agent-unix -Version: 6.0dev-150515 +Version: 6.0dev-150516 Architecture: all Priority: optional Section: admin diff --git a/pandora_agents/unix/DEBIAN/make_deb_package.sh b/pandora_agents/unix/DEBIAN/make_deb_package.sh index 16209acba2..97a8d38496 100644 --- a/pandora_agents/unix/DEBIAN/make_deb_package.sh +++ b/pandora_agents/unix/DEBIAN/make_deb_package.sh @@ -14,7 +14,7 @@ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -pandora_version="6.0dev-150515" +pandora_version="6.0dev-150516" echo "Test if you has the tools for to make the packages." whereis dpkg-deb | cut -d":" -f2 | grep dpkg-deb > /dev/null diff --git a/pandora_agents/unix/pandora_agent b/pandora_agents/unix/pandora_agent index 57f0bd59b2..d58fab5f9d 100644 --- a/pandora_agents/unix/pandora_agent +++ b/pandora_agents/unix/pandora_agent @@ -41,7 +41,7 @@ my $Sem = undef; my $ThreadSem = undef; use constant AGENT_VERSION => '6.0dev'; -use constant AGENT_BUILD => '150515'; +use constant AGENT_BUILD => '150516'; # Commands to retrieve total memory information in kB use constant TOTALMEMORY_CMDS => { diff --git a/pandora_agents/unix/pandora_agent.redhat.spec b/pandora_agents/unix/pandora_agent.redhat.spec index 0bdfc78c16..e8fd7c9dda 100644 --- a/pandora_agents/unix/pandora_agent.redhat.spec +++ b/pandora_agents/unix/pandora_agent.redhat.spec @@ -3,7 +3,7 @@ # %define name pandorafms_agent_unix %define version 6.0dev -%define release 150515 +%define release 150516 Summary: Pandora FMS Linux agent, PERL version Name: %{name} diff --git a/pandora_agents/unix/pandora_agent.spec b/pandora_agents/unix/pandora_agent.spec index 10e28228fe..12d77f8eb9 100644 --- a/pandora_agents/unix/pandora_agent.spec +++ b/pandora_agents/unix/pandora_agent.spec @@ -3,7 +3,7 @@ # %define name pandorafms_agent_unix %define version 6.0dev -%define release 150515 +%define release 150516 Summary: Pandora FMS Linux agent, PERL version Name: %{name} diff --git a/pandora_agents/win32/installer/pandora.mpi b/pandora_agents/win32/installer/pandora.mpi index b2bf24a6ea..968e26e873 100644 --- a/pandora_agents/win32/installer/pandora.mpi +++ b/pandora_agents/win32/installer/pandora.mpi @@ -186,7 +186,7 @@ UpgradeApplicationID {} Version -{150515} +{150516} ViewReadme {Yes} diff --git a/pandora_agents/win32/pandora.cc b/pandora_agents/win32/pandora.cc index f67a33ea7c..ae1eb2e487 100644 --- a/pandora_agents/win32/pandora.cc +++ b/pandora_agents/win32/pandora.cc @@ -30,7 +30,7 @@ using namespace Pandora; using namespace Pandora_Strutils; #define PATH_SIZE _MAX_PATH+1 -#define PANDORA_VERSION ("6.0dev(Build 150515)") +#define PANDORA_VERSION ("6.0dev(Build 150516)") string pandora_path; string pandora_dir; diff --git a/pandora_agents/win32/versioninfo.rc b/pandora_agents/win32/versioninfo.rc index 3d1ceb7397..93982e7e38 100644 --- a/pandora_agents/win32/versioninfo.rc +++ b/pandora_agents/win32/versioninfo.rc @@ -11,7 +11,7 @@ BEGIN VALUE "LegalCopyright", "Artica ST" VALUE "OriginalFilename", "PandoraAgent.exe" VALUE "ProductName", "Pandora FMS Windows Agent" - VALUE "ProductVersion", "(6.0dev(Build 150515))" + VALUE "ProductVersion", "(6.0dev(Build 150516))" VALUE "FileVersion", "1.0.0.0" END END diff --git a/pandora_console/DEBIAN/control b/pandora_console/DEBIAN/control index 68bdd78164..46fa499ce8 100644 --- a/pandora_console/DEBIAN/control +++ b/pandora_console/DEBIAN/control @@ -1,5 +1,5 @@ package: pandorafms-console -Version: 6.0dev-150515 +Version: 6.0dev-150516 Architecture: all Priority: optional Section: admin diff --git a/pandora_console/DEBIAN/make_deb_package.sh b/pandora_console/DEBIAN/make_deb_package.sh index b378b5b4d2..fbeebd35e2 100644 --- a/pandora_console/DEBIAN/make_deb_package.sh +++ b/pandora_console/DEBIAN/make_deb_package.sh @@ -14,7 +14,7 @@ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -pandora_version="6.0dev-150515" +pandora_version="6.0dev-150516" package_pear=0 package_pandora=1 diff --git a/pandora_console/include/config_process.php b/pandora_console/include/config_process.php index 18d8615620..90d7247ec4 100644 --- a/pandora_console/include/config_process.php +++ b/pandora_console/include/config_process.php @@ -22,7 +22,7 @@ /** * Pandora build version and version */ -$build_version = 'PC150515'; +$build_version = 'PC150516'; $pandora_version = 'v6.0dev'; // Do not overwrite default timezone set if defined. diff --git a/pandora_console/install.php b/pandora_console/install.php index 9d8e8bafbd..96248a1afa 100644 --- a/pandora_console/install.php +++ b/pandora_console/install.php @@ -63,7 +63,7 @@
Date: Sun, 17 May 2015 00:01:09 +0200 Subject: [PATCH 71/80] Auto-updated build strings. --- pandora_agents/unix/DEBIAN/control | 2 +- pandora_agents/unix/DEBIAN/make_deb_package.sh | 2 +- pandora_agents/unix/pandora_agent | 2 +- pandora_agents/unix/pandora_agent.redhat.spec | 2 +- pandora_agents/unix/pandora_agent.spec | 2 +- pandora_agents/win32/installer/pandora.mpi | 2 +- pandora_agents/win32/pandora.cc | 2 +- pandora_agents/win32/versioninfo.rc | 2 +- pandora_console/DEBIAN/control | 2 +- pandora_console/DEBIAN/make_deb_package.sh | 2 +- pandora_console/include/config_process.php | 2 +- pandora_console/install.php | 2 +- pandora_console/pandora_console.redhat.spec | 2 +- pandora_console/pandora_console.spec | 2 +- pandora_console/pandoradb_data.sql | 2 +- pandora_server/DEBIAN/control | 2 +- pandora_server/DEBIAN/make_deb_package.sh | 2 +- pandora_server/lib/PandoraFMS/Config.pm | 2 +- pandora_server/pandora_server.redhat.spec | 2 +- pandora_server/pandora_server.spec | 2 +- pandora_server/util/pandora_db.pl | 2 +- pandora_server/util/pandora_manage.pl | 2 +- 22 files changed, 22 insertions(+), 22 deletions(-) diff --git a/pandora_agents/unix/DEBIAN/control b/pandora_agents/unix/DEBIAN/control index 018599ebc2..0c21343352 100644 --- a/pandora_agents/unix/DEBIAN/control +++ b/pandora_agents/unix/DEBIAN/control @@ -1,5 +1,5 @@ package: pandorafms-agent-unix -Version: 6.0dev-150516 +Version: 6.0dev-150517 Architecture: all Priority: optional Section: admin diff --git a/pandora_agents/unix/DEBIAN/make_deb_package.sh b/pandora_agents/unix/DEBIAN/make_deb_package.sh index 97a8d38496..125766837a 100644 --- a/pandora_agents/unix/DEBIAN/make_deb_package.sh +++ b/pandora_agents/unix/DEBIAN/make_deb_package.sh @@ -14,7 +14,7 @@ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -pandora_version="6.0dev-150516" +pandora_version="6.0dev-150517" echo "Test if you has the tools for to make the packages." whereis dpkg-deb | cut -d":" -f2 | grep dpkg-deb > /dev/null diff --git a/pandora_agents/unix/pandora_agent b/pandora_agents/unix/pandora_agent index d58fab5f9d..23430882f0 100644 --- a/pandora_agents/unix/pandora_agent +++ b/pandora_agents/unix/pandora_agent @@ -41,7 +41,7 @@ my $Sem = undef; my $ThreadSem = undef; use constant AGENT_VERSION => '6.0dev'; -use constant AGENT_BUILD => '150516'; +use constant AGENT_BUILD => '150517'; # Commands to retrieve total memory information in kB use constant TOTALMEMORY_CMDS => { diff --git a/pandora_agents/unix/pandora_agent.redhat.spec b/pandora_agents/unix/pandora_agent.redhat.spec index e8fd7c9dda..295f026a9a 100644 --- a/pandora_agents/unix/pandora_agent.redhat.spec +++ b/pandora_agents/unix/pandora_agent.redhat.spec @@ -3,7 +3,7 @@ # %define name pandorafms_agent_unix %define version 6.0dev -%define release 150516 +%define release 150517 Summary: Pandora FMS Linux agent, PERL version Name: %{name} diff --git a/pandora_agents/unix/pandora_agent.spec b/pandora_agents/unix/pandora_agent.spec index 12d77f8eb9..ccb3c0c66e 100644 --- a/pandora_agents/unix/pandora_agent.spec +++ b/pandora_agents/unix/pandora_agent.spec @@ -3,7 +3,7 @@ # %define name pandorafms_agent_unix %define version 6.0dev -%define release 150516 +%define release 150517 Summary: Pandora FMS Linux agent, PERL version Name: %{name} diff --git a/pandora_agents/win32/installer/pandora.mpi b/pandora_agents/win32/installer/pandora.mpi index 968e26e873..b440adc89f 100644 --- a/pandora_agents/win32/installer/pandora.mpi +++ b/pandora_agents/win32/installer/pandora.mpi @@ -186,7 +186,7 @@ UpgradeApplicationID {} Version -{150516} +{150517} ViewReadme {Yes} diff --git a/pandora_agents/win32/pandora.cc b/pandora_agents/win32/pandora.cc index ae1eb2e487..4f711cd17f 100644 --- a/pandora_agents/win32/pandora.cc +++ b/pandora_agents/win32/pandora.cc @@ -30,7 +30,7 @@ using namespace Pandora; using namespace Pandora_Strutils; #define PATH_SIZE _MAX_PATH+1 -#define PANDORA_VERSION ("6.0dev(Build 150516)") +#define PANDORA_VERSION ("6.0dev(Build 150517)") string pandora_path; string pandora_dir; diff --git a/pandora_agents/win32/versioninfo.rc b/pandora_agents/win32/versioninfo.rc index 93982e7e38..42d8b64ea1 100644 --- a/pandora_agents/win32/versioninfo.rc +++ b/pandora_agents/win32/versioninfo.rc @@ -11,7 +11,7 @@ BEGIN VALUE "LegalCopyright", "Artica ST" VALUE "OriginalFilename", "PandoraAgent.exe" VALUE "ProductName", "Pandora FMS Windows Agent" - VALUE "ProductVersion", "(6.0dev(Build 150516))" + VALUE "ProductVersion", "(6.0dev(Build 150517))" VALUE "FileVersion", "1.0.0.0" END END diff --git a/pandora_console/DEBIAN/control b/pandora_console/DEBIAN/control index 46fa499ce8..520c0fcd4e 100644 --- a/pandora_console/DEBIAN/control +++ b/pandora_console/DEBIAN/control @@ -1,5 +1,5 @@ package: pandorafms-console -Version: 6.0dev-150516 +Version: 6.0dev-150517 Architecture: all Priority: optional Section: admin diff --git a/pandora_console/DEBIAN/make_deb_package.sh b/pandora_console/DEBIAN/make_deb_package.sh index fbeebd35e2..ad272d7e0f 100644 --- a/pandora_console/DEBIAN/make_deb_package.sh +++ b/pandora_console/DEBIAN/make_deb_package.sh @@ -14,7 +14,7 @@ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -pandora_version="6.0dev-150516" +pandora_version="6.0dev-150517" package_pear=0 package_pandora=1 diff --git a/pandora_console/include/config_process.php b/pandora_console/include/config_process.php index 90d7247ec4..f5e17d4cfe 100644 --- a/pandora_console/include/config_process.php +++ b/pandora_console/include/config_process.php @@ -22,7 +22,7 @@ /** * Pandora build version and version */ -$build_version = 'PC150516'; +$build_version = 'PC150517'; $pandora_version = 'v6.0dev'; // Do not overwrite default timezone set if defined. diff --git a/pandora_console/install.php b/pandora_console/install.php index 96248a1afa..6475ed0f21 100644 --- a/pandora_console/install.php +++ b/pandora_console/install.php @@ -63,7 +63,7 @@
Date: Mon, 18 May 2015 00:01:11 +0200 Subject: [PATCH 72/80] Auto-updated build strings. --- pandora_agents/unix/DEBIAN/control | 2 +- pandora_agents/unix/DEBIAN/make_deb_package.sh | 2 +- pandora_agents/unix/pandora_agent | 2 +- pandora_agents/unix/pandora_agent.redhat.spec | 2 +- pandora_agents/unix/pandora_agent.spec | 2 +- pandora_agents/win32/installer/pandora.mpi | 2 +- pandora_agents/win32/pandora.cc | 2 +- pandora_agents/win32/versioninfo.rc | 2 +- pandora_console/DEBIAN/control | 2 +- pandora_console/DEBIAN/make_deb_package.sh | 2 +- pandora_console/include/config_process.php | 2 +- pandora_console/install.php | 2 +- pandora_console/pandora_console.redhat.spec | 2 +- pandora_console/pandora_console.spec | 2 +- pandora_console/pandoradb_data.sql | 2 +- pandora_server/DEBIAN/control | 2 +- pandora_server/DEBIAN/make_deb_package.sh | 2 +- pandora_server/lib/PandoraFMS/Config.pm | 2 +- pandora_server/pandora_server.redhat.spec | 2 +- pandora_server/pandora_server.spec | 2 +- pandora_server/util/pandora_db.pl | 2 +- pandora_server/util/pandora_manage.pl | 2 +- 22 files changed, 22 insertions(+), 22 deletions(-) diff --git a/pandora_agents/unix/DEBIAN/control b/pandora_agents/unix/DEBIAN/control index 0c21343352..cf6452d7f2 100644 --- a/pandora_agents/unix/DEBIAN/control +++ b/pandora_agents/unix/DEBIAN/control @@ -1,5 +1,5 @@ package: pandorafms-agent-unix -Version: 6.0dev-150517 +Version: 6.0dev-150518 Architecture: all Priority: optional Section: admin diff --git a/pandora_agents/unix/DEBIAN/make_deb_package.sh b/pandora_agents/unix/DEBIAN/make_deb_package.sh index 125766837a..03bb20caf3 100644 --- a/pandora_agents/unix/DEBIAN/make_deb_package.sh +++ b/pandora_agents/unix/DEBIAN/make_deb_package.sh @@ -14,7 +14,7 @@ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -pandora_version="6.0dev-150517" +pandora_version="6.0dev-150518" echo "Test if you has the tools for to make the packages." whereis dpkg-deb | cut -d":" -f2 | grep dpkg-deb > /dev/null diff --git a/pandora_agents/unix/pandora_agent b/pandora_agents/unix/pandora_agent index 23430882f0..b928bb1075 100644 --- a/pandora_agents/unix/pandora_agent +++ b/pandora_agents/unix/pandora_agent @@ -41,7 +41,7 @@ my $Sem = undef; my $ThreadSem = undef; use constant AGENT_VERSION => '6.0dev'; -use constant AGENT_BUILD => '150517'; +use constant AGENT_BUILD => '150518'; # Commands to retrieve total memory information in kB use constant TOTALMEMORY_CMDS => { diff --git a/pandora_agents/unix/pandora_agent.redhat.spec b/pandora_agents/unix/pandora_agent.redhat.spec index 295f026a9a..c1039f40b0 100644 --- a/pandora_agents/unix/pandora_agent.redhat.spec +++ b/pandora_agents/unix/pandora_agent.redhat.spec @@ -3,7 +3,7 @@ # %define name pandorafms_agent_unix %define version 6.0dev -%define release 150517 +%define release 150518 Summary: Pandora FMS Linux agent, PERL version Name: %{name} diff --git a/pandora_agents/unix/pandora_agent.spec b/pandora_agents/unix/pandora_agent.spec index ccb3c0c66e..183254be3e 100644 --- a/pandora_agents/unix/pandora_agent.spec +++ b/pandora_agents/unix/pandora_agent.spec @@ -3,7 +3,7 @@ # %define name pandorafms_agent_unix %define version 6.0dev -%define release 150517 +%define release 150518 Summary: Pandora FMS Linux agent, PERL version Name: %{name} diff --git a/pandora_agents/win32/installer/pandora.mpi b/pandora_agents/win32/installer/pandora.mpi index b440adc89f..8e2ff3b931 100644 --- a/pandora_agents/win32/installer/pandora.mpi +++ b/pandora_agents/win32/installer/pandora.mpi @@ -186,7 +186,7 @@ UpgradeApplicationID {} Version -{150517} +{150518} ViewReadme {Yes} diff --git a/pandora_agents/win32/pandora.cc b/pandora_agents/win32/pandora.cc index 4f711cd17f..0543e30c57 100644 --- a/pandora_agents/win32/pandora.cc +++ b/pandora_agents/win32/pandora.cc @@ -30,7 +30,7 @@ using namespace Pandora; using namespace Pandora_Strutils; #define PATH_SIZE _MAX_PATH+1 -#define PANDORA_VERSION ("6.0dev(Build 150517)") +#define PANDORA_VERSION ("6.0dev(Build 150518)") string pandora_path; string pandora_dir; diff --git a/pandora_agents/win32/versioninfo.rc b/pandora_agents/win32/versioninfo.rc index 42d8b64ea1..d7a7118eff 100644 --- a/pandora_agents/win32/versioninfo.rc +++ b/pandora_agents/win32/versioninfo.rc @@ -11,7 +11,7 @@ BEGIN VALUE "LegalCopyright", "Artica ST" VALUE "OriginalFilename", "PandoraAgent.exe" VALUE "ProductName", "Pandora FMS Windows Agent" - VALUE "ProductVersion", "(6.0dev(Build 150517))" + VALUE "ProductVersion", "(6.0dev(Build 150518))" VALUE "FileVersion", "1.0.0.0" END END diff --git a/pandora_console/DEBIAN/control b/pandora_console/DEBIAN/control index 520c0fcd4e..d6ef4ab72e 100644 --- a/pandora_console/DEBIAN/control +++ b/pandora_console/DEBIAN/control @@ -1,5 +1,5 @@ package: pandorafms-console -Version: 6.0dev-150517 +Version: 6.0dev-150518 Architecture: all Priority: optional Section: admin diff --git a/pandora_console/DEBIAN/make_deb_package.sh b/pandora_console/DEBIAN/make_deb_package.sh index ad272d7e0f..700fb80781 100644 --- a/pandora_console/DEBIAN/make_deb_package.sh +++ b/pandora_console/DEBIAN/make_deb_package.sh @@ -14,7 +14,7 @@ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -pandora_version="6.0dev-150517" +pandora_version="6.0dev-150518" package_pear=0 package_pandora=1 diff --git a/pandora_console/include/config_process.php b/pandora_console/include/config_process.php index f5e17d4cfe..f488bb8817 100644 --- a/pandora_console/include/config_process.php +++ b/pandora_console/include/config_process.php @@ -22,7 +22,7 @@ /** * Pandora build version and version */ -$build_version = 'PC150517'; +$build_version = 'PC150518'; $pandora_version = 'v6.0dev'; // Do not overwrite default timezone set if defined. diff --git a/pandora_console/install.php b/pandora_console/install.php index 6475ed0f21..fce5a92c52 100644 --- a/pandora_console/install.php +++ b/pandora_console/install.php @@ -63,7 +63,7 @@
Date: Thu, 14 May 2015 19:43:29 +0200 Subject: [PATCH 73/80] Fixed stupid typo on operation to show total available memory (cherry picked from commit cfc0583167ccdfb345df656e298334af54b94c01) --- pandora_agents/unix/plugins/pandora_mem | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandora_agents/unix/plugins/pandora_mem b/pandora_agents/unix/plugins/pandora_mem index 1d7745a8fd..229b05ca8a 100755 --- a/pandora_agents/unix/plugins/pandora_mem +++ b/pandora_agents/unix/plugins/pandora_mem @@ -21,7 +21,7 @@ my $freemem=`cat /proc/meminfo | grep 'MemFree' | awk '{ print \$2 } '`; my $cached=`cat /proc/meminfo | grep '^Cached:' | awk '{ print \$2 } '`; my $cachedswap=`cat /proc/meminfo | grep '^SwapCached:' | awk '{ print \$2 }'`; my $available=$freemem+$cached+$cachedwap; -my $available_percent = floor(($available / $STOTAL)*100); +my $available_percent = floor(($available / $TOTAL)*100); print "\n"; From 2b698e5f351655570b94bfae1ea5179ef1015e46 Mon Sep 17 00:00:00 2001 From: Ramon Novoa Date: Mon, 18 May 2015 11:05:55 +0200 Subject: [PATCH 74/80] Added a missing include. (cherry picked from commit 641600c9ef89f117e08f0a6a01c6fe66e05539c7) --- pandora_console/include/functions_config.php | 1 + 1 file changed, 1 insertion(+) diff --git a/pandora_console/include/functions_config.php b/pandora_console/include/functions_config.php index 39cabf1f32..1c84a03865 100644 --- a/pandora_console/include/functions_config.php +++ b/pandora_console/include/functions_config.php @@ -853,6 +853,7 @@ function config_process_config () { // } require_once ($config["homedir"] . "/include/auth/mysql.php"); + require_once ($config["homedir"] . "/include/functions_io.php"); // Next is the directory where "/attachment" directory is placed, From 36467aaa5e5660079c6c05dc49ef4390dc633000 Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Mon, 18 May 2015 14:49:02 +0200 Subject: [PATCH 75/80] Working in the refactoring the code of reports. Removed the xml code. --- pandora_console/include/functions_xml.php | 171 -- .../operation/reporting/reporting_xml.php | 1456 +---------------- 2 files changed, 72 insertions(+), 1555 deletions(-) delete mode 100644 pandora_console/include/functions_xml.php mode change 100644 => 100755 pandora_console/operation/reporting/reporting_xml.php diff --git a/pandora_console/include/functions_xml.php b/pandora_console/include/functions_xml.php deleted file mode 100644 index da291e3ef4..0000000000 --- a/pandora_console/include/functions_xml.php +++ /dev/null @@ -1,171 +0,0 @@ -". $agent_data['nombre']."\n"; - $content_report .= " ". $agent_data['comentarios']."\n"; - $content_report .= " ".$agent_data['direccion']."\n"; - $content_report .= " ".$agent_data['id_grupo']."\n"; - $content_report .= " ". $agent_data['intervalo']."\n"; - - $sql = "SELECT t1.description, t2.name - FROM tagent_custom_data t1, tagent_custom_fields t2 - WHERE t1.id_agent=".$agent_data['id_agente']." - AND t1.id_field=t2.id_field"; - $custom_fields = db_get_all_rows_sql($sql); - - if ($custom_fields !== false) { - foreach ($custom_fields as $field) { - $field['name'] = io_safe_output($field['name']); - //remove blank - $field['name'] = preg_replace('/\s/', '_', $field['name']); - $content_report .= " <".$field['name'].">".$field['description']."\n"; - } - } - $content_report .= " ".$agent_data['id_os']."\n"; - $content_report .= " ". agents_get_name ($agent_data['id_parent'])."\n"; - $content_report .= " ".$agent_data['id_extra']."\n"; - $content_report .= " ".$agent_data['disabled']."\n"; - - $result = fwrite($file, $content_report); - $position++; - - fclose($file); - return $position; -} - -//xml con los datos de módulos de un agente -function xml_file_agent_conf ($modules = array(), $file_temp, $position = 0, $id_agent) { - - $file = fopen($file_temp, 'a+'); - - foreach ($modules as $module) { - - $content_report = " \n"; - - $content_report .= " ".$module['nombre']."\n"; - $content_report .= " ".$module['id_agente_modulo']."\n"; - $content_report .= " ".$module['id_tipo_modulo']."\n"; - $content_report .= " ".$module['descripcion']."\n"; - $content_report .= " ". $module['extended_info']."\n"; - $content_report .= " ". $module['unit']."\n"; - $content_report .= " ". $module['max']."\n"; - $content_report .= " ".$module['min']."\n"; - $content_report .= " ". $module['module_interval']."\n"; - $content_report .= " ". $module['module_ff_interval']."\n"; - $content_report .= " ". $module['tcp_port']."\n"; - $content_report .= " ". $module['tcp_send']."\n"; - $content_report .= " ". $module['tcp_rcv']."\n"; - $content_report .= " ". $module['snmp_community']."\n"; - $content_report .= " ".$module['snmp_oid']."\n"; - $content_report .= " ". $module['ip_target']."\n"; - $content_report .= " ".$module['id_module_group']."\n"; - $content_report .= " ". $module['disabled']."\n"; - $content_report .= " ".$module['id_plugin']."\n"; - $content_report .= " ". $module['post_process']."\n"; - $content_report .= " ". $module['min_warning']."\n"; - $content_report .= " ". $module['max_warning']."\n"; - $content_report .= " ". $module['str_warning']."\n"; - $content_report .= " ". $module['min_critical']."\n"; - $content_report .= " ".$module['max_critical']."\n"; - $content_report .= " ". $module['str_critical']."\n"; - $content_report .= " ". $module['id_policy_module']."\n"; - $content_report .= " ".$module['wizard_level']."\n"; - $content_report .= " ". $module['critical_instructions']."\n"; - $content_report .= " ". $module['warning_instructions']."\n"; - $content_report .= " ".$module['unknown_instructions']."\n"; - - $content_report .= " \n"; - - $result = fwrite($file, $content_report); - $position++; - } - fclose($file); - - return $position; -} - -// xml eventos -function xml_file_event ($events = array(), $file_temp, $position = 0, $id_agent) { - - $file = fopen($file_temp, 'a+'); - - foreach ($events as $event) { - - $content_report = " \n"; - $content_report .= " " . io_safe_output($event['evento']) . "\n"; - $content_report .= " " . $event['event_type'] . "\n"; - $content_report .= " " . get_priority_name($event['criticity']) . "\n"; - $content_report .= " " . $event['count_rep'] . "\n"; - $content_report .= " " . $event['time2'] . "\n"; - $content_report .= " " . io_safe_output(modules_get_agentmodule_name ($event['id_agentmodule'])) . "\n"; - $content_report .= " " . io_safe_output(agents_get_name ($id_agent)) . "\n"; - - if ($event['estado'] == 0) - $status = __('New'); - else if ($event['estado'] == 1) - $status = __('Validated'); - else if ($event['estado'] == 2) - $status = __('In process'); - else - $status = ""; - - $content_report .= " ".$status."\n"; - $content_report .= " ".$event['user_comment']."\n"; - $content_report .= " ".$event['tags']."\n"; - $content_report .= " ".$event['source']."\n"; - $content_report .= " ".$event['id_extra']."\n"; - $content_report .= " ".$event['owner_user']."\n"; - $content_report .= " \n"; - - $result = fwrite($file, $content_report); - $position++; - - } - fclose($file); - - return $position; -} - -//xml graph -function xml_file_graph ($data_module = array(), $file_temp, $position = 0) { - - $file = fopen($file_temp, 'a+'); - - foreach ($data_module as $data_m) { - - $content_report = " \n"; - $content_report .= " ".date ('Y-m-d H:i:s', $data_m['utimestamp'])."\n"; - $content_report .= " ".$data_m['utimestamp']."\n"; - $content_report .= " ".$data_m['datos']."\n"; - $content_report .= " \n"; - - $result = fwrite($file, $content_report); - $position++; - } - - fclose($file); - - return $position; -} -?> diff --git a/pandora_console/operation/reporting/reporting_xml.php b/pandora_console/operation/reporting/reporting_xml.php old mode 100644 new mode 100755 index c220fd0874..e55a23b890 --- a/pandora_console/operation/reporting/reporting_xml.php +++ b/pandora_console/operation/reporting/reporting_xml.php @@ -17,46 +17,41 @@ include_once("include/functions_modules.php"); include_once("include/functions_events.php"); include_once ('include/functions_groups.php'); include_once ('include/functions_netflow.php'); -include_once ('include/functions_xml.php'); enterprise_include_once ('include/functions_metaconsole.php'); -function xml_array ($array, $buffer_file = array()) { - - foreach ($array as $name => $value) { - //si coincide con el nivel de anidación y existe el fichero - $file_to_print = false; - if(isset($buffer_file[$name]) && file_exists($buffer_file[$name])) { - $file_to_print = $buffer_file[$name]; - } - - if (is_int ($name)) { - echo ""; - $name = "object"; - } - else { - echo "<".$name.">"; - } - - if (is_array ($value)) { - //si es la ruta al fichero que contiene el xml - if(is_string($file_to_print)) { - $file = fopen($file_to_print, 'r'); - while (!feof($file)) { - $buffer = fgets($file); - echo "$buffer"; - } - $file_to_print = false; - } - xml_array ($value, $file_to_print); - } - else { - echo $value; - } - - echo ""; +function array2XML($data, $root = null, $xml = NULL) { + if ($xml == null) { + $xml = simplexml_load_string( + "\n<" . $root . " />"); } + + foreach($data as $key => $value) { + if (is_numeric($key)) { + $key = "item_" . $key; + } + + if (is_array($value)) { + $node = $xml->addChild($key); + array2XML($value, $root, $node); + } + else { + $value = htmlentities($value); + + if (!is_numeric($value) && !is_bool($value)) { + if (!empty($value)) { + $xml->addChild($key, $value); + } + } + else { + $xml->addChild($key, $value); + } + } + } + + return html_entity_decode($xml->asXML()); } + // Login check if (isset ($_GET["direct"])) { /* @@ -130,1365 +125,58 @@ check_login (); $id_report = (int) get_parameter ('id'); -if (!$id_report) { - db_pandora_audit("HACK Attempt", - "Trying to access graph viewer without valid ID"); - require ("general/noaccess.php"); - - exit; -} +$date_mode = get_parameter('date_mode', 'none'); -$report = db_get_row ('treport', 'id_report', $id_report); - -if (empty($report) || ! check_acl ($config['id_user'], $report['id_group'], "RR")) { - db_pandora_audit("ACL Violation","Trying to access graph reader"); - include ("general/noaccess.php"); - exit; -} - -$report["datetime"] = get_system_time(); - -header ('Content-type: application/xml; charset="utf-8"', true); - -echo ''; //' - this is to mislead highlighters giving crap about the PHP closing tag - -$date = (string) get_parameter ('date', date ('Y-m-j')); -$time = (string) get_parameter ('time', date ('h:iA')); - -$datetime = strtotime ($date.' '.$time); - -if ($datetime === false || $datetime == -1) { - //Not translatable because this is an error message and might have - //to be used on the other end - echo "Invalid date selected"; - exit; -} - -$group_name = groups_get_name ($report['id_group'], true); - -switch ($config["dbtype"]) { - case "mysql": - $contents = db_get_all_rows_field_filter ('treport_content', 'id_report', $id_report, '`order`'); +$period = null; +switch ($date_mode) { + case 'none': + case 'end_time': + // Get different date to search the report. + $date = (string) get_parameter ('date', date ('Y-m-j')); + $time = (string) get_parameter ('time', date ('h:iA')); break; - case "postgresql": - case "oracle": - $contents = db_get_all_rows_field_filter ('treport_content', 'id_report', $id_report, '"order"'); + case 'init_and_end_time': + // Get different date to search the report. + $date = (string) get_parameter ('date', date ('Y-m-j')); + $time = (string) get_parameter ('time', date ('h:iA')); + + // Calculations in order to modify init date of the report + $date_init_less = strtotime(date ('Y-m-j')) - SECONDS_1DAY; + + $date_init = get_parameter('date_init', date ('Y-m-j', $date_init_less)); + $time_init = get_parameter('time_init', date ('h:iA')); + $datetime_init = strtotime ($date_init.' '.$time_init); + + $period = strtotime ($date.' '.$time) - $datetime_init; break; } -$time = get_system_time (); -echo ''; -echo ''.$time.''; -echo ''.date ("r",$time).''; -$xml["id"] = $id_report; -$xml["name"] = io_safe_output_xml ($report['name']); -$xml["description"] = io_safe_output_xml($report['description']); -$xml["group"]["id"] = $report['id_group']; -$xml["group"]["name"] = io_safe_output_xml ($group_name); +$report = reporting_make_reporting_data($id_report, $date, $time, + $period, 'static'); -if ($contents === false) { - $contents = array (); -} +//~ html_debug_print($report); exit; -xml_array ($xml); +//------- Removed the unused fields ------------------------------------ +unset($report['header']); +unset($report['first_page']); +unset($report['footer']); +unset($report['custom_font']); +unset($report['id_template']); +unset($report['id_group_edit']); +unset($report['metaconsole']); +unset($report['private']); +unset($report['custom_logo']); +//---------------------------------------------------------------------- -echo ''; -$counter = 0; -foreach ($contents as $content) { +$xml = null; +$xml = array2XML($report, "report", $xml); +//~ $xml = preg_replace("/(<\/[^>]+>)/", "$1\n", $xml); +$xml = preg_replace("/(<[^>]+>)(<[^>]+>)(<[^>]+>)/", "$1\n$2\n$3", $xml); +$xml = preg_replace("/(<[^>]+>)(<[^>]+>)/", "$1\n$2", $xml); - echo ''; - $data = array (); +header("Content-Type: application/xml; charset=utf-8"); - $data["period"] = human_time_description_raw ($content['period']); - $data["uperiod"] = $content['period']; - $data["type"] = $content["type"]; - if (isset($content['name']) && !empty($content['name'])) { - $data["name"] = io_safe_output_xml($content["name"]); - } - - // Support for metaconsole - $server_name = $content ['server_name']; - - // Disable remote connections for netflow report items - if ($content['type'] != 'netflow_area' && - $content['type'] != 'netflow_pie' && - $content['type'] != 'netflow_data' && - $content['type'] != 'netflow_statistics' && - $content['type'] != 'netflow_summary') { - - $remote_connection = 1; - } - else { - $remote_connection = 0; - } - - if (($config ['metaconsole'] == 1) && ($server_name != '') && defined('METACONSOLE') && $remote_connection == 1) { - $connection = metaconsole_get_connection($server_name); - if (metaconsole_connect($connection) != NOERR){ - //ui_print_error_message ("Error connecting to ".$server_name); - } - } - - $session_id = session_id(); - - switch ($content["type"]) { - - case 1: - case 'simple_graph': - $data["module"] = io_safe_output_xml (db_get_value ('nombre', 'tagente_modulo', 'id_agente_modulo', $content['id_agent_module'])); - $data["agent"] = io_safe_output_xml (modules_get_agentmodule_agent_name ($content['id_agent_module'])); - - $data["title"] = __('Simple graph'); - $data["objdata"] = array(); - - $date_end = time(); - $date_init = $date_end - $content['period']; - /// - $temp_file = $config['attachment_store'] . '/simple_graph_' . $time.'_'.$content['id_rc'] . '.tmp'; - $file = fopen ($temp_file, 'a+'); - - $buffer_file["objdata"] = $config['attachment_store'] . '/simple_graph_' . $time.'_'.$content['id_rc'] . '.tmp'; - - $limit = 1000; - $offset = 0; - - $sql_count = "SELECT COUNT(id_agente_modulo) - FROM tagente_datos - WHERE id_agente_modulo=".$content['id_agent_module']." - AND (utimestamp>=$date_init AND utimestamp<=$date_end)"; - $data_count = db_get_value_sql($sql_count); - - if ($data_count == false) { - $content_report = " \n"; - $result = fwrite($file, $content_report); - fclose($file); - } - else if ($data_count <= $limit) { - $content_report = " \n"; - $result = fwrite($file, $content_report); - fclose($file); - - $sql = "SELECT * - FROM tagente_datos - WHERE id_agente_modulo=".$content['id_agent_module']." - AND (utimestamp>=$date_init AND utimestamp<=$date_end)"; - - $data_module = db_get_all_rows_sql($sql); - xml_file_graph ($data_module, $temp_file); - - $file = fopen ($temp_file, 'a+'); - $content_report = " \n"; - $result = fwrite($file, $content_report); - } - else { - $content_report = " \n"; - $result = fwrite($file, $content_report); - fclose($file); - - $position = 0; - while ($offset < $data_count) { - - $sql = "SELECT * - FROM tagente_datos - WHERE id_agente_modulo=".$content['id_agent_module']." - AND (utimestamp>=$date_init AND utimestamp<=$date_end) LIMIT $offset,$limit"; - $data_module = db_get_all_rows_sql($sql); - - $position = xml_file_graph ($data_module, $temp_file, $position); - $offset += $limit; - } - - $file = fopen ($temp_file, 'a+'); - $content_report = " \n"; - $result = fwrite($file, $content_report); - fclose($file); - } - break; - case 'simple_baseline_graph': - - $data["module"] = io_safe_output_xml (db_get_value ('nombre', 'tagente_modulo', 'id_agente_modulo', $content['id_agent_module'])); - $data["agent"] = io_safe_output_xml (modules_get_agentmodule_agent_name ($content['id_agent_module'])); - $data["title"] = __('Simple baseline graph'); - $data["objdata"] = array(); - - $date_end = time(); - $date_init = $date_end - $content['period']; - - $temp_file = $config['attachment_store'] . '/simple_baseline_graph_' . $time.'_'.$content['id_rc'] . '.tmp'; - - $file = fopen ($temp_file, 'a+'); - - $buffer_file["objdata"] = $config['attachment_store'] . '/simple_baseline_graph_' . $time.'_'.$content['id_rc'] . '.tmp'; - - $limit = 1000; - $offset = 0; - - $sql_count = "SELECT COUNT(id_agente_modulo) - FROM tagente_datos - WHERE id_agente_modulo=".$content['id_agent_module']." - AND (utimestamp>=$date_init AND utimestamp<=$date_end)"; - $data_count = db_get_value_sql($sql_count); - - if ($data_count == false) { - $content_report = " \n"; - $result = fwrite($file, $content_report); - } - else if ($data_count <= $limit) { - $content_report = " \n"; - $result = fwrite($file, $content_report); - fclose($file); - - $sql = "SELECT * - FROM tagente_datos - WHERE id_agente_modulo=".$content['id_agent_module']." - AND (utimestamp>=$date_init AND utimestamp<=$date_end)"; - - $data_module = db_get_all_rows_sql($sql); - xml_file_graph ($data_module, $temp_file); - - $file = fopen ($temp_file, 'a+'); - $content_report = " \n"; - $result = fwrite($file, $content_report); - fclose($file); - - } - else { - $content_report = " \n"; - $result = fwrite($file, $content_report); - fclose($file); - - $position = 0; - while ($offset < $data_count) { - - $sql = "SELECT * FROM tagente_datos WHERE id_agente_modulo=".$content['id_agent_module']." - AND (utimestamp>=$date_init AND utimestamp<=$date_end) LIMIT $offset,$limit"; - $data_module = db_get_all_rows_sql($sql); - - $position = xml_file_graph ($data_module, $temp_file, $position); - $offset += $limit; - } - - $file = fopen ($temp_file, 'a+'); - $content_report = " \n"; - $result = fwrite($file, $content_report); - fclose($file); - } - /// - break; - case 2: - case 'custom_graph': - case 'automatic_custom_graph': - - $data["module"] = io_safe_output_xml (db_get_value ('nombre', 'tagente_modulo', 'id_agente_modulo', $content['id_agent_module'])); - $data["agent"] = io_safe_output_xml (modules_get_agentmodule_agent_name ($content['id_agent_module'])); - - $graph = db_get_row ("tgraph", "id_graph", $content['id_gs']); - $data["title"] = __('Custom graph'); - $data["objdata"] = array(); - - $result = db_get_all_rows_field_filter ("tgraph_source","id_graph",$content['id_gs']); - $modules = array (); - $weights = array (); - - if ($result === false) { - $result = array(); - } - - foreach ($result as $content2) { - array_push ($modules, $content2['id_agent_module']); - array_push ($weights, $content2["weight"]); - } - - $date_end = time(); - $date_init = $date_end - $content['period']; - /// - $temp_file = $config['attachment_store'] . '/custom_graph_' . $time.'_'.$content['id_rc'] . '.tmp'; - - $file = fopen ($temp_file, 'a+'); - - $buffer_file["objdata"] = $config['attachment_store'] . '/custom_graph_' . $time.'_'.$content['id_rc'] . '.tmp'; - - $limit = 1000; - $offset = 0; - - $sql_count = "SELECT COUNT(id_agente_modulo) - FROM tagente_datos - WHERE id_agente_modulo=".$content['id_agent_module']." - AND (utimestamp>=$date_init AND utimestamp<=$date_end)"; - $data_count = db_get_value_sql($sql_count); - - if ($data_count == false) { - $content_report = " \n"; - $result = fwrite($file, $content_report); - fclose($file); - } - else if ($data_count <= $limit) { - $content_report = " \n"; - $result = fwrite($file, $content_report); - fclose($file); - - $sql = "SELECT * - FROM tagente_datos - WHERE id_agente_modulo=".$content['id_agent_module']." - AND (utimestamp>=$date_init AND utimestamp<=$date_end)"; - - $data_module = db_get_all_rows_sql($sql); - xml_file_graph ($data_module, $temp_file); - - $file = fopen ($temp_file, 'a+'); - $content_report = " \n"; - $result = fwrite($file, $content_report); - - } - else { - $content_report = " \n"; - $result = fwrite($file, $content_report); - fclose($file); - - $position = 0; - while ($offset < $data_count) { - - $sql = "SELECT * FROM tagente_datos WHERE id_agente_modulo=".$content['id_agent_module']." - AND (utimestamp>=$date_init AND utimestamp<=$date_end) LIMIT $offset,$limit"; - $data_module = db_get_all_rows_sql($sql); - - $position = xml_file_graph ($data_module, $temp_file, $position); - $offset += $limit; - } - - $file = fopen ($temp_file, 'a+'); - $content_report = " \n"; - $result = fwrite($file, $content_report); - fclose($file); - } - /// - break; - case 3: - case 'SLA': - $data["title"] = __('S.L.A.'); - - $slas = db_get_all_rows_field_filter ('treport_content_sla_combined','id_report_content', $content['id_rc']); - if ($slas === false) { - $data["objdata"]["error"] = __('There are no SLAs defined'); - $slas = array (); - } - - $data["objdata"]["sla"] = array (); - $sla_failed = false; - - foreach ($slas as $sla) { - - //Metaconsole connection - $server_name = $sla ['server_name']; - if (($config ['metaconsole'] == 1) && ($server_name != '') && defined('METACONSOLE')) { - $connection = metaconsole_get_connection($server_name); - if (metaconsole_connect($connection) != NOERR) { - //ui_print_error_message ("Error connecting to ".$server_name); - continue; - } - } - - $sla_data = array (); - $sla_data["agent"] = io_safe_output(modules_get_agentmodule_agent_name ($sla['id_agent_module'])); - $sla_data["module"] = modules_get_agentmodule_name ($sla['id_agent_module']); - $sla_data["max"] = $sla['sla_max']; - $sla_data["min"] = $sla['sla_min']; - $sla_value = reporting_get_agentmodule_sla ($sla['id_agent_module'], $content['period'], $sla['sla_min'], $sla['sla_max'], $datetime, $content, $content['time_from'], $content['time_to']); - if ($sla_value === false) { - $sla_data["error"] = __('Unknown'); - } - else { - if ($sla_value < $sla['sla_limit']) { - $sla_data["failed"] = true; - } - $sla_data["value"] = format_numeric ($sla_value); - } - array_push ($data["objdata"]["sla"], $sla_data); - - if (($config ['metaconsole'] == 1) && defined('METACONSOLE')) { - //Restore db connection - metaconsole_restore_db(); - } - - } - break; - case 6: - case 'monitor_report': - $data["title"] = __('Monitor report'); - $monitor_value = reporting_get_agentmodule_sla ($content['id_agent_module'], $content['period'], 1, false, $datetime); - if ($monitor_value === false) { - $monitor_value = __('Unknown'); - } - else { - $monitor_value = format_numeric ($monitor_value); - } - $data["objdata"]["good"] = $monitor_value; - if ($monitor_value !== __('Unknown')) { - $monitor_value = format_numeric (100 - $monitor_value); - } - $data["objdata"]["bad"] = $monitor_value; - break; - case 7: - case 'avg_value': - $data["module"] = io_safe_output_xml (db_get_value ('nombre', 'tagente_modulo', 'id_agente_modulo', $content['id_agent_module'])); - $data["agent"] = io_safe_output_xml (modules_get_agentmodule_agent_name ($content['id_agent_module'])); - $data["title"] = __('Avg. Value'); - $data["objdata"]["avg_value"] = reporting_get_agentmodule_data_average ($content['id_agent_module'], $content['period'], $datetime); - if ($data["objdata"]["avg_value"] === false) { - $data["objdata"]["avg_value"] = __('Unknown'); - } - else { - $data["objdata"]["avg_value"] = format_numeric ($data["objdata"]["avg_value"]); - } - break; - case 8: - case 'max_value': - $data["module"] = io_safe_output_xml (db_get_value ('nombre', 'tagente_modulo', 'id_agente_modulo', $content['id_agent_module'])); - $data["agent"] = io_safe_output_xml (modules_get_agentmodule_agent_name ($content['id_agent_module'])); - - $data["title"] = __('Max. Value'); - $data["objdata"]["max_value"] = reporting_get_agentmodule_data_max ($content['id_agent_module'], $content['period'], $datetime); - if ($data["objdata"]["max_value"] === false) { - $data["objdata"]["max_value"] = __('Unknown'); - } - else { - $data["objdata"]["max_value"] = format_numeric ($data["objdata"]["max_value"]); - } - break; - case 9: - case 'min_value': - $data["module"] = io_safe_output_xml (db_get_value ('nombre', 'tagente_modulo', 'id_agente_modulo', $content['id_agent_module'])); - $data["agent"] = io_safe_output_xml (modules_get_agentmodule_agent_name ($content['id_agent_module'])); - - $data["title"] = __('Min. Value'); - $data["objdata"]["min_value"] = reporting_get_agentmodule_data_min ($content['id_agent_module'], $content['period'], $datetime); - if ($data["objdata"]["min_value"] === false) { - $data["objdata"]["min_value"] = __('Unknown'); - } - else { - $data["objdata"]["min_value"] = format_numeric ($data["objdata"]["min_value"]); - } - break; - case 10: - case 'sumatory': - $data["module"] = io_safe_output_xml (db_get_value ('nombre', 'tagente_modulo', 'id_agente_modulo', $content['id_agent_module'])); - $data["agent"] = io_safe_output_xml (modules_get_agentmodule_agent_name ($content['id_agent_module'])); - - $data["title"] = __('Sumatory'); - $data["objdata"]["summatory_value"] = reporting_get_agentmodule_data_sum ($content['id_agent_module'], $content['period'], $datetime); - if ($data["objdata"]["summatory_value"] === false) { - $data["objdata"]["summatory_value"] = __('Unknown'); - } - else { - $data["objdata"]["summatory_value"] = format_numeric ($data["objdata"]["summatory_value"]); - } - break; - case 'agent_detailed_event': - case 'event_report_agent': - $data["title"] = __('Agent detailed event'); - $data["objdata"] = array (); - - $date = get_system_time (); - /// - $temp_file = $config['attachment_store'] . '/event_report_agent_' . $time.'_'.$content['id_rc'] . '.tmp'; - $file = fopen ($temp_file, 'a+'); - $buffer_file["objdata"] = $config['attachment_store'] . '/event_report_agent_' . $time.'_'.$content['id_rc'] . '.tmp'; - - $limit = 1000; - $offset = 0; - - $datelimit = $date - $content['period']; - - $sql_count = "SELECT count(*) FROM (SELECT count(*) - FROM tevento - WHERE id_agente =".$content['id_agent']." AND utimestamp > $datelimit AND utimestamp <= $date - GROUP BY id_agentmodule, evento) t1"; - $data_count = db_get_value_sql($sql_count); - - if ($data_count == false) { - $content_report = " \n"; - $result = fwrite($file, $content_report); - fclose($file); - } - else if ($data_count <= $limit) { - $content_report = " \n"; - $result = fwrite($file, $content_report); - fclose($file); - - $sql = sprintf (' - SELECT evento, event_type, criticity, - count(*) AS count_rep, max(timestamp) AS time2, - id_agentmodule, estado, user_comment, tags, - source, id_extra, owner_user - FROM tevento - WHERE id_agente = %d AND utimestamp > %d - AND utimestamp <= %d - GROUP BY id_agentmodule, evento - ORDER BY time2 DESC', $content['id_agent'], - $datelimit, $date); - - $events = db_get_all_rows_sql ($sql); - xml_file_event ($events, $temp_file,0, $content['id_agent']); - - $file = fopen ($temp_file, 'a+'); - $content_report = " \n"; - $result = fwrite($file, $content_report); - - - } - else { - $content_report = " \n"; - $result = fwrite($file, $content_report); - fclose($file); - - $position = 0; - while ($offset < $data_count) { - - $sql = sprintf ('SELECT evento, event_type, criticity, count(*) as count_rep, - max(timestamp) AS time2, id_agentmodule, estado, user_comment, tags, source, id_extra, owner_user - FROM tevento - WHERE id_agente = %d AND utimestamp > %d AND utimestamp <= %d - GROUP BY id_agentmodule, evento - ORDER BY time2 DESC LIMIT %d,%d', $content['id_agent'], $datelimit, $date, $offset,$limit); - - $events = db_get_all_rows_sql ($sql); - - $position = xml_file_event ($events, $temp_file, $position, $content['id_agent']); - $offset += $limit; - } - - $file = fopen ($temp_file, 'a+'); - $content_report = " \n"; - $result = fwrite($file, $content_report); - fclose($file); - } - /// - break; - case 'text': - $data["title"] = __('Text'); - $data["objdata"] = ""; - break; - case 'sql': - - $data["title"] = __('SQL'); - - //name tags of row - if ($content['header_definition'] != '') { - $tags = explode('|', $content['header_definition']); - } - - if ($content['treport_custom_sql_id'] != 0) { - switch ($config["dbtype"]) { - case "mysql": - $sql = db_get_value_filter('`sql`', 'treport_custom_sql', array('id' => $content['treport_custom_sql_id'])); - break; - case "postgresql": - $sql = db_get_value_filter('"sql"', 'treport_custom_sql', array('id' => $content['treport_custom_sql_id'])); - break; - case "oracle": - $sql = db_get_value_filter('sql', 'treport_custom_sql', array('id' => $content['treport_custom_sql_id'])); - break; - } - } - else { - $sql = $content['external_source']; - } - - $sql = safe_output ($sql); - $result = db_get_all_rows_sql($sql); - if ($result === false) { - $result = array(); - } - - if (isset($result[0])) { - for ($i = 0; $i < (count($result[0]) - count($tags)); $i) { - $tags[] = 'unname_' . $i; - } - } - - $data["objdata"]["data"] = array (); - - foreach ($result as $row) { - $objdata = array (); - $i = 0; - foreach ($row as $column) { - $objdata[$tags[$i]] = $column; - $i++; - } - array_push($data["objdata"]["data"], $objdata); - } - break; - case 'event_report_group': - $data["title"] = __('Group detailed event'); - $data['group'] = groups_get_name($content['id_group'], true); - $data["objdata"] = array(); - - $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'; - - $limit = 1000; - $offset = 0; - - if ($data_count == false) { - $content_report = " \n"; - $result = fwrite($file, $content_report); - fclose($file); - } - else if ($data_count <= $limit) { - $content_report = " \n"; - $result = fwrite($file, $content_report); - fclose($file); - - $sql = sprintf ('SELECT * FROM tevento - WHERE utimestamp > %d AND utimestamp <= %d - AND id_grupo IN (%s) - ORDER BY utimestamp ASC', - $datelimit, $report["datetime"], implode (",", $id_group)); - $events = db_get_all_rows_sql($sql); - xml_file_event ($events, $temp_file, 0, $content['id_agent']); - - $file = fopen ($temp_file, 'a+'); - $content_report = " \n"; - $result = fwrite($file, $content_report); - - } - else { - $content_report = " \n"; - $result = fwrite($file, $content_report); - fclose($file); - - $position = 0; - while ($offset < $data_count) { - - $sql = sprintf ('SELECT * FROM tevento - WHERE utimestamp > %d AND utimestamp <= %d - 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']); - $offset += $limit; - } - - $file = fopen ($temp_file, 'a+'); - $content_report = " \n"; - $result = fwrite($file, $content_report); - fclose($file); - } - } - break; - case 'event_report_module': - - $data["title"] = __('Agents detailed event'); - $data["objdata"] = array(); - - $date = get_system_time (); - $datelimit = $date - $content['period']; - - $sql_count = "SELECT count(*) FROM (SELECT count(*) - FROM tevento - WHERE id_agente =".$content['id_agent']." AND utimestamp > $datelimit AND utimestamp <=". $date. - " GROUP BY id_agentmodule, evento) t1"; - - $data_count = db_get_value_sql($sql_count); - - $temp_file = $config['attachment_store'] . '/event_report_module_' . $time.'_'.$content['id_rc'] . '.tmp'; - $file = fopen ($temp_file, 'a+'); - $buffer_file["objdata"] = $config['attachment_store'] . '/event_report_module_' . $time.'_'.$content['id_rc'] . '.tmp'; - - $limit = 1000; - $offset = 0; - - if ($data_count == false) { - $content_report = " \n"; - $result = fwrite($file, $content_report); - fclose($file); - } - else if ($data_count <= $limit) { - $content_report = " \n"; - $result = fwrite($file, $content_report); - fclose($file); - - $sql = "SELECT evento, event_type, criticity, count(*) as count_rep, max(timestamp) AS time2, id_agentmodule, estado, user_comment, tags, source, id_extra, owner_user - FROM tevento - WHERE id_agente =".$content['id_agent']." AND utimestamp > $datelimit AND utimestamp <=". $date. - " GROUP BY id_agentmodule, evento"; - - $events = db_get_all_rows_sql($sql); - - xml_file_event ($events, $temp_file, 0, $content['id_agent']); - - $file = fopen ($temp_file, 'a+'); - $content_report = " \n"; - $result = fwrite($file, $content_report); - - } - else { - $content_report = " \n"; - $result = fwrite($file, $content_report); - fclose($file); - - $position = 0; - while ($offset < $data_count) { - - $sql = sprintf ('SELECT evento, event_type, criticity, count(*) as count_rep, max(timestamp) AS time2, id_agentmodule, estado, user_comment, tags, source, id_extra, owner_user - FROM tevento - WHERE id_agentmodule = %d AND utimestamp > %d AND utimestamp <= %d - GROUP BY id_agentmodule, evento ORDER BY time2 DESC LIMIT %d,%d', $content['id_agent_module'], $datelimit, $date, $offset,$limit); - - $events = db_get_all_rows_sql($sql); - - $position = xml_file_event ($events, $temp_file, $position, $content['id_agent']); - $offset += $limit; - } - - $file = fopen ($temp_file, 'a+'); - $content_report = " \n"; - $result = fwrite($file, $content_report); - fclose($file); - } - break; - case 'alert_report_module': - $data["title"] = __('Alert report module'); - $data["objdata"]["alert_report_module"] = array(); - - $alerts = reporting_alert_reporting_module ($content['id_agent_module'], $content['period'], $report["datetime"], true, false); - - foreach ($alerts->data as $row) { - $objdata = array(); - - $actionsHtml = strip_tags($row[2], '
  • '); - $actions = explode('
  • ', $actionsHtml); - - $objdata['template'] = $row[1]; - - $objdata['action'] = array(); - foreach ($actions as $action) { - $actionText = strip_tags($action); - if ($actionText == '') { - continue; - } - $objdata['action'][] = $actionText; - } - - $firedHtml = strip_tags($row[3], '
  • '); - $fireds= explode('
  • ', $firedHtml); - - $objdata['fired'] = array(); - foreach ($fireds as $fired) { - $firedText = strip_tags($fired); - if ($firedText == '') { - continue; - } - $objdata['fired'][] = $firedText; - } - array_push($data["objdata"]["alert_report_module"], $objdata); - } - break; - case 'alert_report_agent': - $data["title"] = __('Alert report agent'); - - $alerts = reporting_alert_reporting_agent ($content['id_agent'], $content['period'], $report["datetime"], true, false); - $data["objdata"]["alert_report_agent"] = array(); - - foreach ($alerts->data as $row) { - $objdata = array(); - - $objdata['module'] = $row[0]; - $objdata['template'] = $row[1]; - - $actionsHtml = strip_tags($row[2], '
  • '); - $actions = explode('
  • ', $actionsHtml); - - $objdata['action'] = array(); - foreach ($actions as $action) { - $actionText = strip_tags($action); - if ($actionText == '') { - continue; - } - $objdata['action'][] = $actionText; - } - - $firedHtml = strip_tags($row[3], '
  • '); - $fireds= explode('
  • ', $firedHtml); - - $objdata['fired'] = array(); - foreach ($fireds as $fired) { - $firedText = strip_tags($fired); - if ($firedText == '') { - continue; - } - $objdata['fired'][] = $firedText; - } - - array_push($data["objdata"]["alert_report_agent"], $objdata); - } - break; - case 'url': - $data["title"] = __('Import text from URL'); - - $curlObj = curl_init(); - - curl_setopt($curlObj, CURLOPT_URL, $content['external_source']); - curl_setopt($curlObj, CURLOPT_RETURNTRANSFER, 1); - $output = curl_exec($curlObj); - curl_close($curlObj); - - $data["objdata"] = $output; - break; - case 'database_serialized': - $data["title"] = __('Serialize data'); - - //Create the head - $tags = array(); - if ($content['header_definition'] != '') { - $tags = explode('|', $content['header_definition']); - } - else { - $tags[] = 'Data'; - } - array_unshift($tags, 'Date'); - - $datelimit = $report["datetime"] - $content['period']; - - $result = db_get_all_rows_sql('SELECT * - FROM tagente_datos - WHERE id_agente_modulo = ' . $content['id_agent_module'] . ' - AND utimestamp > ' . $datelimit . ' - AND utimestamp <= ' . $report["datetime"]); - - // Adds string data if there is no numeric data - if ((count($result) < 0) or (!$result)){ - $result = db_get_all_rows_sql('SELECT * - FROM tagente_datos_string - WHERE id_agente_modulo = ' . $content['id_agent_module'] . ' - AND utimestamp > ' . $datelimit . ' - AND utimestamp <= ' . $report["datetime"]); - } - if ($result === false) { - $result = array(); - } - - $data["objdata"]["data"] = array (); - foreach ($result as $row) { - $date = date ($config["date_format"], $row['utimestamp']); - $serialized = $row['datos']; - - $rowsUnserialize = (array)$serialized; - if (!empty($content['line_separator'])) { - $rowsUnserialize = explode($line_separator, - $serialized); - } - - foreach ($rowsUnserialize as $rowUnser) { - - $columnsUnserialize = (array)$rowUnser; - if (!empty($content['column_separator'])) { - $columnsUnserialize = explode($content['column_separator'], $rowUnser); - } - - array_unshift($columnsUnserialize, $date); - - $objdata = array (); - $i = 0; - foreach ($columnsUnserialize as $column) { - $objdata[$tags[$i]] = $column; - $i++; - } - array_push($data["objdata"]["data"], $objdata); - } - } - break; - case 'TTRT': - $ttr = reporting_get_agentmodule_ttr ($content['id_agent_module'], $content['period'], $report["datetime"]); - if ($ttr === false) { - $ttr = __('Unknown'); - } - else if ($ttr != 0) { - $ttr = human_time_description_raw ($ttr); - } - - $data["title"] = __('TTRT'); - $data["objdata"] = $ttr; - break; - case 'TTO': - $tto = reporting_get_agentmodule_tto ($content['id_agent_module'], $content['period'], $report["datetime"]); - if ($tto === false) { - $tto = __('Unknown'); - } - else if ($tto != 0) { - $tto = human_time_description_raw ($tto); - } - - $data["title"] = __('TTO'); - $data["objdata"] = $tto; - break; - case 'MTBF': - $mtbf = reporting_get_agentmodule_mtbf ($content['id_agent_module'], $content['period'], $report["datetime"]); - if ($mtbf === false) { - $mtbf = __('Unknown'); - } - else if ($mtbf != 0) { - $mtbf = human_time_description_raw ($mtbf); - } - - $data["title"] = __('MTBF'); - $data["objdata"] = $mtbf; - break; - case 'MTTR': - $mttr = reporting_get_agentmodule_mttr ($content['id_agent_module'], $content['period'], $report["datetime"]); - if ($mttr === false) { - $mttr = __('Unknown'); - } - else if ($mttr != 0) { - $mttr = human_time_description_raw ($mttr); - } - - $data["title"] = __('MTTR'); - $data["objdata"] = $mttr; - break; - case 'inventory': - $data["title"] = __('Inventory'); - $data["objdata"]["inventory"] = array(); - - $es = json_decode($content['external_source'], true); - - $id_agent = $es['id_agents']; - $module_name = $es['inventory_modules']; - $date = $es['date']; - - $data["objdata"]["inventory"] = inventory_get_data((array)$id_agent,(array)$module_name,$date,'',false, 'array'); - break; - case 'inventory_changes': - $data["title"] = __('Inventory changes'); - $data["objdata"]["inventory_changes"] = array(); - - $es = json_decode($content['external_source'], true); - - $id_agent = $es['id_agents']; - $module_name = $es['inventory_modules']; - - $data["objdata"]["inventory_changes"] = inventory_get_changes($id_agent, $module_name, $report["datetime"] - $content['period'], $report["datetime"], 'array'); - - break; - case 'agent_configuration': - - $agent_name = agents_get_name ($content['id_agent']); - - $sql = "SELECT * FROM tagente WHERE id_agente=".$content['id_agent']; - $agent_data = db_get_row_sql($sql); - - $data["title"] = __('Configuration report for agent ').$agent_name; - $data["agent"] = $agent_name; - $data["objdata"] = array(); - - ///// - $temp_file = $config['attachment_store'] . '/agent_configuration_' . $time.'_'.$content['id_rc'] . '.tmp'; - $file = fopen ($temp_file, 'a+'); - $buffer_file["objdata"] = $config['attachment_store'] . '/agent_configuration_' . $time.'_'.$content['id_rc'] . '.tmp'; - - $content_report = " \n"; - $result = fwrite($file, $content_report); - fclose($file); - - xml_file_agent_data($agent_data, $temp_file, $agent_name); - - $userGroups = users_get_groups($config['id_user'], 'AR', false); - if (empty($userGroups)) { - return array(); - } - $id_groups = array_keys($userGroups); - if (!empty($id_groups)) { - - $sql_count = "SELECT count(*) FROM (SELECT * - FROM tagente_modulo WHERE - ( - 1 = ( - SELECT is_admin - FROM tusuario - WHERE id_user = '".$config['id_user']."' - ) - OR tagente_modulo.id_agente IN ( - SELECT id_agente - FROM tagente - WHERE id_grupo IN (" . implode(',', $id_groups) . ") - ) - OR 0 IN ( - SELECT id_grupo - FROM tusuario_perfil - WHERE id_usuario ='".$config['id_user']."' - AND id_perfil IN ( - SELECT id_perfil - FROM tperfil WHERE agent_view = 1 - ) - ) - ) AND id_agente=".$content['id_agent']." AND delete_pending = 0 - ORDER BY nombre) t1"; - $data_count = db_get_value_sql($sql_count); - - $limit = 1000; - $offset = 0; - - if ($data_count == false) { - - $content_report = " \n"; - $content_report .= " \n"; - - $file = fopen ($temp_file, 'a+'); - $result = fwrite($file, $content_report); - fclose($file); - } else if ($data_count <= $limit) { - $content_report = " \n"; - - $file = fopen ($temp_file, 'a+'); - $result = fwrite($file, $content_report); - fclose($file); - - $sql = "SELECT * - FROM tagente_modulo WHERE - ( - 1 = ( - SELECT is_admin - FROM tusuario - WHERE id_user = '".$config['id_user']."' - ) - OR tagente_modulo.id_agente IN ( - SELECT id_agente - FROM tagente - WHERE id_grupo IN (" . implode(',', $id_groups) . ") - ) - OR 0 IN ( - SELECT id_grupo - FROM tusuario_perfil - WHERE id_usuario ='".$config['id_user']."' - AND id_perfil IN ( - SELECT id_perfil - FROM tperfil WHERE agent_view = 1 - ) - ) - ) AND id_agente=".$content['id_agent']." AND delete_pending = 0 - ORDER BY nombre"; - - $modules = db_get_all_rows_sql ($sql); - xml_file_agent_conf ($modules, $temp_file,0, $content['id_agent']); - - $file = fopen ($temp_file, 'a+'); - $content_report = " \n"; - $content_report .= " \n"; - $result = fwrite($file, $content_report); - - } - else { - $content_report = " \n"; - - $file = fopen ($temp_file, 'a+'); - $result = fwrite($file, $content_report); - fclose($file); - - $position = 0; - while ($offset < $data_count) { - - $sql = "SELECT * - FROM tagente_modulo WHERE - ( - 1 = ( - SELECT is_admin - FROM tusuario - WHERE id_user = '".$config['id_user']."' - ) - OR tagente_modulo.id_agente IN ( - SELECT id_agente - FROM tagente - WHERE id_grupo IN (" . implode(',', $id_groups) . ") - ) - OR 0 IN ( - SELECT id_grupo - FROM tusuario_perfil - WHERE id_usuario ='".$config['id_user']."' - AND id_perfil IN ( - SELECT id_perfil - FROM tperfil WHERE agent_view = 1 - ) - ) - ) AND id_agente=".$content['id_agent']." AND delete_pending = 0 - ORDER BY nombre - LIMIT $offset,$limit"; - - $modules = db_get_all_rows_sql ($sql); - - $position = xml_file_agent_conf ($modules, $temp_file, $position, $content['id_agent']); - $offset += $limit; - } - - $file = fopen ($temp_file, 'a+'); - $content_report = " \n"; - $content_report .= " \n"; - $result = fwrite($file, $content_report); - fclose($file); - } - - } - - break; - case 'group_configuration': - - $group_name = groups_get_name ($content['id_group'], true); - - $data["title"] = __('Configuration report for group ').$group_name; - $data["group"] = $group_name; - - /// - $data["objdata"] = array(); - $temp_file = $config['attachment_store'] . '/group_configuration_' . $time.'_'.$content['id_rc'] . '.tmp'; - $file = fopen ($temp_file, 'a+'); - $buffer_file["objdata"] = $config['attachment_store'] . '/group_configuration_' . $time.'_'.$content['id_rc'] . '.tmp'; - - $content_report = " \n"; - $content_report .= " ".$group_name."\n"; - $content_report .= " ".$content['id_group']."\n"; - $result = fwrite($file, $content_report); - fclose($file); - - $sql = "SELECT * FROM tagente WHERE id_grupo=".$content['id_group']; - $agents_list = db_get_all_rows_sql($sql); - if ($agents_list === false) - $agents_list = array(); - $i = 0; - foreach ($agents_list as $key=>$agent) { - $file = fopen ($temp_file, 'a+'); - $content_report = " \n"; - $content_report .= " \n"; - $result = fwrite($file, $content_report); - xml_file_agent_data($agent, $temp_file); - - $userGroups = users_get_groups($config['id_user'], 'AR', false); - if (empty($userGroups)) { - return array(); - } - $id_groups = array_keys($userGroups); - if (!empty($id_groups)) { - - $sql_count = "SELECT count(*) FROM (SELECT * - FROM tagente_modulo WHERE - ( - 1 = ( - SELECT is_admin - FROM tusuario - WHERE id_user = '".$config['id_user']."' - ) - OR tagente_modulo.id_agente IN ( - SELECT id_agente - FROM tagente - WHERE id_grupo IN (" . implode(',', $id_groups) . ") - ) - OR 0 IN ( - SELECT id_grupo - FROM tusuario_perfil - WHERE id_usuario ='".$config['id_user']."' - AND id_perfil IN ( - SELECT id_perfil - FROM tperfil WHERE agent_view = 1 - ) - ) - ) AND id_agente=".$agent['id_agente']." AND delete_pending = 0 - ORDER BY nombre) t1"; - - $data_count = db_get_value_sql($sql_count); - - $limit = 1000; - $offset = 0; - - if ($data_count == false) { - $content_report = " \n"; - $content_report .= " \n"; - - $file = fopen ($temp_file, 'a+'); - $result = fwrite($file, $content_report); - fclose($file); - - } else if ($data_count <= $limit) { - $content_report = " \n"; - - $file = fopen ($temp_file, 'a+'); - $result = fwrite($file, $content_report); - fclose($file); - - $sql = "SELECT * - FROM tagente_modulo WHERE - ( - 1 = ( - SELECT is_admin - FROM tusuario - WHERE id_user = '".$config['id_user']."' - ) - OR tagente_modulo.id_agente IN ( - SELECT id_agente - FROM tagente - WHERE id_grupo IN (" . implode(',', $id_groups) . ") - ) - OR 0 IN ( - SELECT id_grupo - FROM tusuario_perfil - WHERE id_usuario ='".$config['id_user']."' - AND id_perfil IN ( - SELECT id_perfil - FROM tperfil WHERE agent_view = 1 - ) - ) - ) AND id_agente=".$agent['id_agente']." AND delete_pending = 0 - ORDER BY nombre"; - - $modules = db_get_all_rows_sql ($sql); - xml_file_agent_conf ($modules, $temp_file, 0, $content['id_agent']); - - $file = fopen ($temp_file, 'a+'); - $content_report = " \n"; - $content_report .= " \n"; - $result = fwrite($file, $content_report); - - - } - else { - $content_report = " \n"; - - $file = fopen ($temp_file, 'a+'); - $result = fwrite($file, $content_report); - fclose($file); - - $position = 0; - while ($offset < $data_count) { - - $sql = "SELECT * - FROM tagente_modulo WHERE - ( - 1 = ( - SELECT is_admin - FROM tusuario - WHERE id_user = '".$config['id_user']."' - ) - OR tagente_modulo.id_agente IN ( - SELECT id_agente - FROM tagente - WHERE id_grupo IN (" . implode(',', $id_groups) . ") - ) - OR 0 IN ( - SELECT id_grupo - FROM tusuario_perfil - WHERE id_usuario ='".$config['id_user']."' - AND id_perfil IN ( - SELECT id_perfil - FROM tperfil WHERE agent_view = 1 - ) - ) - ) AND id_agente=".$agent['id_agente']." AND delete_pending = 0 - ORDER BY nombre - LIMIT $offset,$limit"; - - $modules = db_get_all_rows_sql ($sql); - - $position = xml_file_agent_conf ($modules, $temp_file, $position, $content['id_agent']); - $offset += $limit; - } - - $file = fopen ($temp_file, 'a+'); - $content_report = " \n"; - $content_report .= " \n"; - $result = fwrite($file, $content_report); - fclose($file); - } - - } - $i++; - - $file = fopen ($temp_file, 'a+'); - $content_report = " \n"; - $result = fwrite($file, $content_report); - fclose($file); - } - $file = fopen ($temp_file, 'a+'); - $content_report = " \n"; - $result = fwrite($file, $content_report); - fclose($file); - /// - - break; - case 'netflow_area': - case 'netflow_pie': - case 'netflow_data': - case 'netflow_statistics': - case 'netflow_summary': - // Read the report item - $report_id = $report['id_report']; - $content_id = $content['id_rc']; - $max_aggregates= $content['top_n_value']; - $type = $content['show_graph']; - $description = io_safe_output ($content['description']); - $resolution = $content['top_n']; - $type = $content['type']; - $period = $content['period']; - - // Calculate the start and end dates - $end_date = $report['datetime']; - $start_date = $end_date - $period; - - // Get item filters - $filter = db_get_row_sql("SELECT * - FROM tnetflow_filter - WHERE id_sg = '" . (int)$content['text'] . "'", false, true); - if ($description == '') { - $description = io_safe_output ($filter['id_name']); - } - - // Build a unique id for the cache - //$unique_id = $report_id . '_' . $content_id . '_' . ($end_date - $start_date); - - $table->colspan[0][0] = 4; - if ($filter['aggregate'] != 'none') { - $data["title"] = $description . ' (' . __($filter['aggregate']) . '/' . __($filter['output']) . ')'; - } - else { - $data["title"] = $description . ' (' . __($filter['output']) . ')'; - } - - //$data["objdata"]["netflow"] = netflow_draw_item ($start_date, $end_date, $resolution, $type, $filter, $max_aggregates, $unique_id, $server_name, 'XML'); - $data["objdata"]["netflow"] = netflow_draw_item ($start_date, $end_date, $resolution, $type, $filter, $max_aggregates, $server_name, 'XML'); - $buffer_file["objdata"] = $config['attachment_store'] . '/netflow_' . $time.'_'.$content['id_rc'] . '.tmp'; - $objdata_file = true; - break; - } - - xml_array ($data, $buffer_file); - echo '
    '; - $counter++; - - if (($config ['metaconsole'] == 1) && defined('METACONSOLE') && $remote_connection == 1) { - //Restore db connection - metaconsole_restore_db(); - } - -} - -echo '
    '; +echo $xml; ?> From bc6e585d83ab0d88f1faf30633dead0fb5ad48d2 Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Mon, 18 May 2015 16:11:54 +0200 Subject: [PATCH 76/80] Removed the debug trace --- pandora_console/operation/reporting/reporting_xml.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/pandora_console/operation/reporting/reporting_xml.php b/pandora_console/operation/reporting/reporting_xml.php index e55a23b890..e96a8b10d4 100755 --- a/pandora_console/operation/reporting/reporting_xml.php +++ b/pandora_console/operation/reporting/reporting_xml.php @@ -155,8 +155,6 @@ switch ($date_mode) { $report = reporting_make_reporting_data($id_report, $date, $time, $period, 'static'); -//~ html_debug_print($report); exit; - //------- Removed the unused fields ------------------------------------ unset($report['header']); unset($report['first_page']); From 45ea3dc3d9b121cc881c93a4a71b7c9248f4280d Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Mon, 18 May 2015 16:23:23 +0200 Subject: [PATCH 77/80] Added json file icon. Thanks Carla. --- pandora_console/images/json.png | Bin 0 -> 480 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100755 pandora_console/images/json.png diff --git a/pandora_console/images/json.png b/pandora_console/images/json.png new file mode 100755 index 0000000000000000000000000000000000000000..8426579bce838716eefb55d77c4c7cb40435ba8b GIT binary patch literal 480 zcmV<60U!Q}P){=b5P0wWWM zbMW9nMi31UK&S|$1cc!nm;^uoVFm-!U$;8d0Y|>Oy~kQRbrI@ z2p~oz75lL%00xXB)^Nchb{~k}!>nS$r3px{2b!t~WKM+1G2!vP0X{c_Ogw-^lL8PY z0&O_}5I{tSG9ywr)nk#L2sCX21HRw_i9u6L03lB?K;69_CDA}l0XhCYG~qk|TAK(9 zIwmYZV+d5xfF4Zf3gba0Aq5Rig`gPehlauhWC<3uL~#Hq;16I`h$}^r3;+U*CWsL| z=75v~iDrNj*aDn^gcMke1hO~C@`KPQnh)gnL*w-UPD9ZQ07bq4C|01UM*$j@22l0^ zsP7bD>41rVfgr`_k$ms~nk(`_sSTRq4x;NLl;HP6(=&2ng|&RDxDP2 z$~RDQKLB+l>4rjGxBylV01Z!oO5rWa2}TqsD Date: Tue, 19 May 2015 00:01:15 +0200 Subject: [PATCH 78/80] Auto-updated build strings. --- pandora_agents/unix/DEBIAN/control | 2 +- pandora_agents/unix/DEBIAN/make_deb_package.sh | 2 +- pandora_agents/unix/pandora_agent | 2 +- pandora_agents/unix/pandora_agent.redhat.spec | 2 +- pandora_agents/unix/pandora_agent.spec | 2 +- pandora_agents/win32/installer/pandora.mpi | 2 +- pandora_agents/win32/pandora.cc | 2 +- pandora_agents/win32/versioninfo.rc | 2 +- pandora_console/DEBIAN/control | 2 +- pandora_console/DEBIAN/make_deb_package.sh | 2 +- pandora_console/include/config_process.php | 2 +- pandora_console/install.php | 2 +- pandora_console/pandora_console.redhat.spec | 2 +- pandora_console/pandora_console.spec | 2 +- pandora_console/pandoradb_data.sql | 2 +- pandora_server/DEBIAN/control | 2 +- pandora_server/DEBIAN/make_deb_package.sh | 2 +- pandora_server/lib/PandoraFMS/Config.pm | 2 +- pandora_server/pandora_server.redhat.spec | 2 +- pandora_server/pandora_server.spec | 2 +- pandora_server/util/pandora_db.pl | 2 +- pandora_server/util/pandora_manage.pl | 2 +- 22 files changed, 22 insertions(+), 22 deletions(-) diff --git a/pandora_agents/unix/DEBIAN/control b/pandora_agents/unix/DEBIAN/control index cf6452d7f2..ae7fd3d7fc 100644 --- a/pandora_agents/unix/DEBIAN/control +++ b/pandora_agents/unix/DEBIAN/control @@ -1,5 +1,5 @@ package: pandorafms-agent-unix -Version: 6.0dev-150518 +Version: 6.0dev-150519 Architecture: all Priority: optional Section: admin diff --git a/pandora_agents/unix/DEBIAN/make_deb_package.sh b/pandora_agents/unix/DEBIAN/make_deb_package.sh index 03bb20caf3..c587519336 100644 --- a/pandora_agents/unix/DEBIAN/make_deb_package.sh +++ b/pandora_agents/unix/DEBIAN/make_deb_package.sh @@ -14,7 +14,7 @@ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -pandora_version="6.0dev-150518" +pandora_version="6.0dev-150519" echo "Test if you has the tools for to make the packages." whereis dpkg-deb | cut -d":" -f2 | grep dpkg-deb > /dev/null diff --git a/pandora_agents/unix/pandora_agent b/pandora_agents/unix/pandora_agent index b928bb1075..375383d2fd 100644 --- a/pandora_agents/unix/pandora_agent +++ b/pandora_agents/unix/pandora_agent @@ -41,7 +41,7 @@ my $Sem = undef; my $ThreadSem = undef; use constant AGENT_VERSION => '6.0dev'; -use constant AGENT_BUILD => '150518'; +use constant AGENT_BUILD => '150519'; # Commands to retrieve total memory information in kB use constant TOTALMEMORY_CMDS => { diff --git a/pandora_agents/unix/pandora_agent.redhat.spec b/pandora_agents/unix/pandora_agent.redhat.spec index c1039f40b0..6b1c292da0 100644 --- a/pandora_agents/unix/pandora_agent.redhat.spec +++ b/pandora_agents/unix/pandora_agent.redhat.spec @@ -3,7 +3,7 @@ # %define name pandorafms_agent_unix %define version 6.0dev -%define release 150518 +%define release 150519 Summary: Pandora FMS Linux agent, PERL version Name: %{name} diff --git a/pandora_agents/unix/pandora_agent.spec b/pandora_agents/unix/pandora_agent.spec index 183254be3e..85a0ee8b2a 100644 --- a/pandora_agents/unix/pandora_agent.spec +++ b/pandora_agents/unix/pandora_agent.spec @@ -3,7 +3,7 @@ # %define name pandorafms_agent_unix %define version 6.0dev -%define release 150518 +%define release 150519 Summary: Pandora FMS Linux agent, PERL version Name: %{name} diff --git a/pandora_agents/win32/installer/pandora.mpi b/pandora_agents/win32/installer/pandora.mpi index 8e2ff3b931..b5ec9aeb24 100644 --- a/pandora_agents/win32/installer/pandora.mpi +++ b/pandora_agents/win32/installer/pandora.mpi @@ -186,7 +186,7 @@ UpgradeApplicationID {} Version -{150518} +{150519} ViewReadme {Yes} diff --git a/pandora_agents/win32/pandora.cc b/pandora_agents/win32/pandora.cc index 0543e30c57..0b1fca500e 100644 --- a/pandora_agents/win32/pandora.cc +++ b/pandora_agents/win32/pandora.cc @@ -30,7 +30,7 @@ using namespace Pandora; using namespace Pandora_Strutils; #define PATH_SIZE _MAX_PATH+1 -#define PANDORA_VERSION ("6.0dev(Build 150518)") +#define PANDORA_VERSION ("6.0dev(Build 150519)") string pandora_path; string pandora_dir; diff --git a/pandora_agents/win32/versioninfo.rc b/pandora_agents/win32/versioninfo.rc index d7a7118eff..60bd3db54a 100644 --- a/pandora_agents/win32/versioninfo.rc +++ b/pandora_agents/win32/versioninfo.rc @@ -11,7 +11,7 @@ BEGIN VALUE "LegalCopyright", "Artica ST" VALUE "OriginalFilename", "PandoraAgent.exe" VALUE "ProductName", "Pandora FMS Windows Agent" - VALUE "ProductVersion", "(6.0dev(Build 150518))" + VALUE "ProductVersion", "(6.0dev(Build 150519))" VALUE "FileVersion", "1.0.0.0" END END diff --git a/pandora_console/DEBIAN/control b/pandora_console/DEBIAN/control index d6ef4ab72e..ebc545fd69 100644 --- a/pandora_console/DEBIAN/control +++ b/pandora_console/DEBIAN/control @@ -1,5 +1,5 @@ package: pandorafms-console -Version: 6.0dev-150518 +Version: 6.0dev-150519 Architecture: all Priority: optional Section: admin diff --git a/pandora_console/DEBIAN/make_deb_package.sh b/pandora_console/DEBIAN/make_deb_package.sh index 700fb80781..858a4a0b35 100644 --- a/pandora_console/DEBIAN/make_deb_package.sh +++ b/pandora_console/DEBIAN/make_deb_package.sh @@ -14,7 +14,7 @@ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -pandora_version="6.0dev-150518" +pandora_version="6.0dev-150519" package_pear=0 package_pandora=1 diff --git a/pandora_console/include/config_process.php b/pandora_console/include/config_process.php index f488bb8817..ca471b886b 100644 --- a/pandora_console/include/config_process.php +++ b/pandora_console/include/config_process.php @@ -22,7 +22,7 @@ /** * Pandora build version and version */ -$build_version = 'PC150518'; +$build_version = 'PC150519'; $pandora_version = 'v6.0dev'; // Do not overwrite default timezone set if defined. diff --git a/pandora_console/install.php b/pandora_console/install.php index fce5a92c52..a8172b1c71 100644 --- a/pandora_console/install.php +++ b/pandora_console/install.php @@ -63,7 +63,7 @@
    Date: Tue, 19 May 2015 11:26:36 +0200 Subject: [PATCH 79/80] Ask for the old password before letting a user renew his password. (cherry picked from commit 0840c207646277c9eb7fb55504794d1d98e9c8a7) --- pandora_console/include/javascript/jquery.pandora.js | 2 +- pandora_console/index.php | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/pandora_console/include/javascript/jquery.pandora.js b/pandora_console/include/javascript/jquery.pandora.js index 0f65d6056f..731975b642 100644 --- a/pandora_console/include/javascript/jquery.pandora.js +++ b/pandora_console/include/javascript/jquery.pandora.js @@ -129,7 +129,7 @@ $(document).ready (function () { resizable: true, draggable: true, modal: true, - height: 260, + height: 360, width: 590, overlay: { opacity: 0.5, diff --git a/pandora_console/index.php b/pandora_console/index.php index 45826477e5..4dfcb5791d 100755 --- a/pandora_console/index.php +++ b/pandora_console/index.php @@ -153,11 +153,12 @@ $change_pass = get_parameter_post('renew_password', 0); if ($change_pass == 1) { + $password_old = (string) get_parameter_post ('old_password', ''); $password_new = (string) get_parameter_post ('new_password', ''); $password_confirm = (string) get_parameter_post ('confirm_new_password', ''); $id = (string) get_parameter_post ('login', ''); - $changed_pass = login_update_password_check ($password_new, $password_confirm, $id); + $changed_pass = login_update_password_check ($password_old, $password_new, $password_confirm, $id); } $searchPage = false; From f2683594b5a59a31922dc56567198ea711ec83ce Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Tue, 19 May 2015 17:36:47 +0200 Subject: [PATCH 80/80] Fixes in the new code of reports. --- pandora_console/include/functions_reporting.php | 6 +++--- pandora_console/include/functions_reporting_html.php | 9 ++++++++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index a140b663dc..4bfb09ceef 100644 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -2700,12 +2700,12 @@ function reporting_sql_graph($report, $content, $type, global $config; switch ($type_sql_graph) { - case 'netflow_area': - $return['type'] = 'sql_graph_vbar'; - break; case 'sql_graph_hbar': $return['type'] = 'sql_graph_hbar'; break; + case 'sql_graph_vbar': + $return['type'] = 'sql_graph_vbar'; + break; case 'sql_graph_pie': $return['type'] = 'sql_graph_pie'; break; diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index ff568efc7d..7ac80a0a5a 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -97,6 +97,9 @@ function reporting_html_header(&$table, $mini, $title, $subtitle, function reporting_html_print_report($report, $mini = false) { + + + foreach ($report['contents'] as $key => $item) { $table->size = array (); $table->style = array (); @@ -1206,7 +1209,7 @@ function reporting_html_group_configuration($table, $item) { foreach ($item['data'] as $agent) { $table2->width = '100%'; $table2->data = array (); - reporting_html_agent_configuration(&$table2, array('data' => $agent)); + reporting_html_agent_configuration($table2, array('data' => $agent)); $cell .= html_print_table($table2, true); } @@ -1522,6 +1525,10 @@ function reporting_html_agent_configuration(&$table, $item) { } } +function reporting_html_TTRT_value(&$table, $item, $mini, $only_value = false, $check_empty = false) { + reporting_html_value($table, $item, $mini); +} + function reporting_html_TTO_value(&$table, $item, $mini, $only_value = false, $check_empty = false) { reporting_html_value($table, $item, $mini); }