' . (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_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 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 = SECONDS_1DAY; $interval <= $period; $interval = $interval + SECONDS_1DAY) {
$sla_day = reporting_get_agentmodule_sla(
$id_agent_module,
SECONDS_1DAY,
$min_value,
$max_value,
$datelimit + $interval,
$daysWeek,
$timeFrom, $timeTo);
// Avoid to add the period of module not init
if ($sla_day !== false) {
$sla += $sla_day;
$i++;
}
}
$sla = $sla / $i;
return $sla;
}
}
/**
* 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 Monitor report of a module.
* if (($min_value < $data['datos'])OR ($max_value > 0 AND
($data['datos'] > $min_value AND $data['datos'] < $max_value)))
* @param int Agent module to calculate monitor report
* @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).
*
* @return float Monitor percentage of the requested module. False if no data were
* found
*/
function reporting_get_agentmodule_monitor ($id_agent_module, $period = 0, $min_value = 1, $max_value = false, $date = 0) {
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
// 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);
$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 > 0) AND ($data['datos'] > $min_value
AND $data['datos'] < $max_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 > 0) AND ($data['datos'] > $min_value
AND $data['datos'] < $max_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 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] = '
';
}
else {
$tdata[2] = html_print_image('images/image_problem.png', true, array('width' => $graph_width));
}
$table_sum->rowclass[] = '';
$table_sum->data[] = $tdata;
$output = '';
return $output;
}
function reporting_get_stats_alerts($data) {
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();
$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;
$output = '';
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 = '';
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 = '';
return $output;
}
function reporting_get_stats_indicators($data, $width = 160, $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] = '';
$table_ind->rowclass[] = '';
$table_ind->data[] = $tdata;
$tdata[0] = '';
$table_ind->rowclass[] = '';
$table_ind->data[] = $tdata;
$tdata[0] = '';
$table_ind->rowclass[] = '';
$table_ind->data[] = $tdata;
$tdata[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"] += groups_monitor_ok($group);
$data["monitor_warning"] += groups_monitor_warning($group);
$data["monitor_critical"] += groups_monitor_critical($group);
$data["monitor_unknown"] += groups_monitor_unknown($group);
$data["monitor_not_init"] += groups_monitor_not_init($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 unknown agents by using the status code in modules
$data["agents_unknown"] += groups_agent_unknown ($group_array);
// Get monitor NOT INIT, except disabled AND async modules
$data["monitor_not_init"] += groups_monitor_not_init ($group_array);
// Get monitor OK, except disabled and non-init
$data["monitor_ok"] += groups_monitor_ok ($group_array);
// Get monitor CRITICAL, except disabled and non-init
$data["monitor_critical"] += groups_monitor_critical ($group_array);
// Get monitor WARNING, except disabled and non-init
$data["monitor_warning"] += groups_monitor_warning ($group_array);
// Get monitor UNKNOWN, except disabled and non-init
$data["monitor_unknown"] += groups_monitor_unknown ($group_array);
// 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 agents in a group
$data["total_agents"] += groups_total_agents ($group_array);
// Get TOTAL non-init modules, except disabled ones and async modules
$data["total_not_init"] += $data["monitor_not_init"];
// Get Agents OK
$data["agent_ok"] += groups_agent_ok($group_array);
// Get Agents Warning
$data["agent_warning"] += groups_agent_warning($group_array);
// Get Agents Critical
$data["agent_critical"] += groups_agent_critical($group_array);
// Get Agents Unknown
$data["agent_unknown"] += groups_agent_unknown($group_array);
// Get Agents Not init
$data["agent_not_init"] += groups_agent_not_init($group_array);
}
// 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);
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] = '
';
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] .= '
';
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 = '
';
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 .= '
';
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] = '
';
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] .= '
';
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 .= '
[".__('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'];
$filter_event_filter_search = $style['event_filter_search'];
$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,
$filter_event_filter_search);
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,
$filter_event_filter_search);
$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,
$filter_event_filter_search);
$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,
$filter_event_filter_search);
$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,
$filter_event_filter_search);
$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($agent_name, 'agent_medium', false) .
' ' . 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] =
"