';
$table_mbs->rowclass[] = '';
$table_mbs->data[] = $tdata;
}
if(!is_metaconsole()) {
$output = '
';
}
else {
$table_mbs->class = "tactical_view";
$table_mbs->style=array();
$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')), false, false, false, true);
$tdata[1] = $data["total_agents"] <= 0 ? '-' : $data["total_agents"];
$tdata[1] = '' . $tdata[1] . '';
/* Hello there! :)
We added some of what seems to be "buggy" messages to the openSource version recently. This is not to force open-source users to move to the enterprise version, this is just to inform people using Pandora FMS open source that it requires skilled people to maintain and keep it running smoothly without professional support. This does not imply open-source version is limited in any way. If you check the recently added code, it contains only warnings and messages, no limitations except one: we removed the option to add custom logo in header. In the Update Manager section, it warns about the 'danger’ of applying automated updates without a proper backup, remembering in the process that the Enterprise version comes with a human-tested package. Maintaining an OpenSource version with more than 500 agents is not so easy, that's why someone using a Pandora with 8000 agents should consider asking for support. It's not a joke, we know of many setups with a huge number of agents, and we hate to hear that “its becoming unstable and slow” :(
You can of course remove the warnings, that's why we include the source and do not use any kind of trick. And that's why we added here this comment, to let you know this does not reflect any change in our opensource mentality of does the last 14 years.
*/
if($data["total_agents"]>500 && !enterprise_installed()) {
$tdata[2] = "";
}
$tdata[3] = html_print_image('images/module.png', true, array('title' => __('Monitor checks')), false, false, false, true);
$tdata[4] = $data["monitor_checks"] <= 0 ? '-' : $data["monitor_checks"];
$tdata[4] = '' . $tdata[4] . '';
/* Hello there! :)
We added some of what seems to be "buggy" messages to the openSource version recently. This is not to force open-source users to move to the enterprise version, this is just to inform people using Pandora FMS open source that it requires skilled people to maintain and keep it running smoothly without professional support. This does not imply open-source version is limited in any way. If you check the recently added code, it contains only warnings and messages, no limitations except one: we removed the option to add custom logo in header. In the Update Manager section, it warns about the 'danger’ of applying automated updates without a proper backup, remembering in the process that the Enterprise version comes with a human-tested package. Maintaining an OpenSource version with more than 500 agents is not so easy, that's why someone using a Pandora with 8000 agents should consider asking for support. It's not a joke, we know of many setups with a huge number of agents, and we hate to hear that “its becoming unstable and slow” :(
You can of course remove the warnings, that's why we include the source and do not use any kind of trick. And that's why we added here this comment, to let you know this does not reflect any change in our opensource mentality of does the last 14 years.
*/
if(($data["monitor_checks"]/$data["total_agents"]>100) && !enterprise_installed()) {
$tdata[5] = "";
}
$table_am->rowclass[] = '';
$table_am->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;
}
/**
* Get the average value of an agent module in a period of time.
*
* @param int Agent module id
* @param int Period of time to check (in seconds)
* @param int Top date to check the values. Default current time.
*
* @return float The average module value in the interval.
*/
function reporting_get_agentmodule_data_average ($id_agent_module, $period=0, $date = 0) {
global $config;
// Initialize variables
if (empty ($date)) $date = get_system_time ();
$datelimit = $date - $period;
$search_in_history_db = db_search_in_history_db($datelimit);
$id_module_type = modules_get_agentmodule_type ($id_agent_module);
$module_type = modules_get_moduletype_name ($id_module_type);
$uncompressed_module = is_module_uncompressed ($module_type);
// Get module data
$interval_data = db_get_all_rows_sql ('SELECT *
FROM tagente_datos
WHERE id_agente_modulo = ' . (int) $id_agent_module .
' AND utimestamp > ' . (int) $datelimit .
' AND utimestamp < ' . (int) $date .
' ORDER BY utimestamp ASC', $search_in_history_db);
if ($interval_data === false) $interval_data = array ();
// Uncompressed module data
if ($uncompressed_module) {
$min_necessary = 1;
// Compressed module data
}
else {
// Get previous data
$previous_data = modules_get_previous_data ($id_agent_module, $datelimit);
if ($previous_data !== false) {
$previous_data['utimestamp'] = $datelimit;
array_unshift ($interval_data, $previous_data);
}
// Get next data
$next_data = modules_get_next_data ($id_agent_module, $date);
if ($next_data !== false) {
$next_data['utimestamp'] = $date;
array_push ($interval_data, $next_data);
}
else if (count ($interval_data) > 0) {
// Propagate the last known data to the end of the interval
$next_data = array_pop ($interval_data);
array_push ($interval_data, $next_data);
$next_data['utimestamp'] = $date;
array_push ($interval_data, $next_data);
}
$min_necessary = 2;
}
if (count ($interval_data) < $min_necessary) {
return false;
}
// Set initial conditions
$total = 0;
$count = 0;
if (! $uncompressed_module) {
$previous_data = array_shift ($interval_data);
// Do not count the empty start of an interval as 0
if ($previous_data['utimestamp'] != $datelimit) {
$period = $date - $previous_data['utimestamp'];
}
}
switch ($config["dbtype"]) {
case "mysql":
case "postgresql":
// Do none
break;
case "oracle":
$previous_data['datos'] =
oracle_format_float_to_php($previous_data['datos']);
break;
}
foreach ($interval_data as $data) {
switch ($config["dbtype"]) {
case "mysql":
case "postgresql":
// Do none
break;
case "oracle":
$data['datos'] =
oracle_format_float_to_php($data['datos']);
break;
}
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 MTTR value of an agent module in a period of time. See
* http://en.wikipedia.org/wiki/Mean_time_to_recovery
*
* @param int Agent module id
* @param int Period of time to check (in seconds)
* @param int Top date to check the values. Default current time.
*
* @return float The MTTR value in the interval.
*/
function reporting_get_agentmodule_mttr ($id_agent_module, $period = 0, $date = 0) {
// Initialize variables
if (empty ($date)) $date = get_system_time ();
// Read module configuration
$datelimit = $date - $period;
$search_in_history_db = db_search_in_history_db($datelimit);
$module = db_get_row_sql ('SELECT max_critical, min_critical, id_tipo_modulo
FROM tagente_modulo
WHERE id_agente_modulo = ' . (int) $id_agent_module);
if ($module === false) {
return false;
}
$critical_min = $module['min_critical'];
$critical_max = $module['max_critical'];
$module_type = $module['id_tipo_modulo'];
// Set critical_min and critical for proc modules
$module_type_str = modules_get_type_name ($module_type);
if (strstr ($module_type_str, 'proc') !== false &&
($critical_min == 0 && $critical_max == 0)) {
$critical_min = 1;
}
// Get module data
$interval_data = db_get_all_rows_sql ('SELECT * FROM tagente_datos
WHERE id_agente_modulo = ' . (int) $id_agent_module .
' AND utimestamp > ' . (int) $datelimit .
' AND utimestamp < ' . (int) $date .
' ORDER BY utimestamp ASC', $search_in_history_db);
if ($interval_data === false) $interval_data = array ();
// Get previous data
$previous_data = modules_get_previous_data(
$id_agent_module, $datelimit);
if ($previous_data !== false) {
$previous_data['utimestamp'] = $datelimit;
array_unshift ($interval_data, $previous_data);
}
// Get next data
$next_data = modules_get_next_data ($id_agent_module, $date);
if ($next_data !== false) {
$next_data['utimestamp'] = $date;
array_push ($interval_data, $next_data);
}
else if (count ($interval_data) > 0) {
// Propagate the last known data to the end of the interval
$next_data = array_pop ($interval_data);
array_push ($interval_data, $next_data);
$next_data['utimestamp'] = $date;
array_push ($interval_data, $next_data);
}
if (count ($interval_data) < 2) {
return false;
}
// Set initial conditions
$critical_period = 0;
$first_data = array_shift ($interval_data);
$previous_utimestamp = $first_data['utimestamp'];
switch ($config["dbtype"]) {
case "mysql":
case "postgresql":
// Do none
break;
case "oracle":
$first_data['datos'] =
oracle_format_float_to_php($first_data['datos']);
break;
}
if ((($critical_max > $critical_min AND ($first_data['datos'] > $critical_max OR $first_data['datos'] < $critical_min))) OR
($critical_max <= $critical_min AND $first_data['datos'] < $critical_min)) {
$previous_status = 1;
$critical_count = 1;
}
else {
$previous_status = 0;
$critical_count = 0;
}
foreach ($interval_data as $data) {
switch ($config["dbtype"]) {
case "mysql":
case "postgresql":
// Do none
break;
case "oracle":
$data['datos'] =
oracle_format_float_to_php($data['datos']);
break;
}
// Previous status was critical
if ($previous_status == 1) {
$critical_period += $data['utimestamp'] - $previous_utimestamp;
}
// Re-calculate previous status for the next data
if ((($critical_max > $critical_min AND ($data['datos'] > $critical_max OR $data['datos'] < $critical_min))) OR
($critical_max <= $critical_min AND $data['datos'] < $critical_min)) {
if ($previous_status == 0) {
$critical_count++;
}
$previous_status = 1;
}
else {
$previous_status = 0;
}
$previous_utimestamp = $data['utimestamp'];
}
if ($critical_count == 0) {
return 0;
}
return $critical_period / $critical_count;
}
/**
* Get the MTBF value of an agent module in a period of time. See
* http://en.wikipedia.org/wiki/Mean_time_between_failures
*
* @param int Agent module id
* @param int Period of time to check (in seconds)
* @param int Top date to check the values. Default current time.
*
* @return float The MTBF value in the interval.
*/
function reporting_get_agentmodule_mtbf ($id_agent_module, $period = 0, $date = 0) {
// Initialize variables
if (empty ($date)) $date = get_system_time ();
// Read module configuration
$datelimit = $date - $period;
$search_in_history_db = db_search_in_history_db($datelimit);
$module = db_get_row_sql ('SELECT max_critical, min_critical, id_tipo_modulo
FROM tagente_modulo
WHERE id_agente_modulo = ' . (int) $id_agent_module);
if ($module === false) {
return false;
}
$critical_min = $module['min_critical'];
$critical_max = $module['max_critical'];
$module_type = $module['id_tipo_modulo'];
// Set critical_min and critical for proc modules
$module_type_str = modules_get_type_name ($module_type);
if (strstr ($module_type_str, 'proc') !== false &&
($critical_min == 0 && $critical_max == 0)) {
$critical_min = 1;
}
// Get module data
$interval_data = db_get_all_rows_sql ('SELECT * FROM tagente_datos
WHERE id_agente_modulo = ' . (int) $id_agent_module .
' AND utimestamp > ' . (int) $datelimit .
' AND utimestamp < ' . (int) $date .
' ORDER BY utimestamp ASC', $search_in_history_db);
if ($interval_data === false) $interval_data = array ();
// Get previous data
$previous_data = modules_get_previous_data ($id_agent_module, $datelimit);
if ($previous_data !== false) {
$previous_data['utimestamp'] = $datelimit;
array_unshift ($interval_data, $previous_data);
}
// Get next data
$next_data = modules_get_next_data ($id_agent_module, $date);
if ($next_data !== false) {
$next_data['utimestamp'] = $date;
array_push ($interval_data, $next_data);
}
else if (count ($interval_data) > 0) {
// Propagate the last known data to the end of the interval
$next_data = array_pop ($interval_data);
array_push ($interval_data, $next_data);
$next_data['utimestamp'] = $date;
array_push ($interval_data, $next_data);
}
if (count ($interval_data) < 2) {
return false;
}
// Set initial conditions
$critical_period = 0;
$first_data = array_shift ($interval_data);
$previous_utimestamp = $first_data['utimestamp'];
switch ($config["dbtype"]) {
case "mysql":
case "postgresql":
// Do none
break;
case "oracle":
$first_data['datos'] =
oracle_format_float_to_php($first_data['datos']);
break;
}
if ((($critical_max > $critical_min AND ($first_data['datos'] > $critical_max OR $first_data['datos'] < $critical_min))) OR
($critical_max <= $critical_min AND $first_data['datos'] < $critical_min)) {
$previous_status = 1;
$critical_count = 1;
}
else {
$previous_status = 0;
$critical_count = 0;
}
foreach ($interval_data as $data) {
// Previous status was critical
if ($previous_status == 1) {
$critical_period += $data['utimestamp'] - $previous_utimestamp;
}
switch ($config["dbtype"]) {
case "mysql":
case "postgresql":
// Do none
break;
case "oracle":
$data['datos'] =
oracle_format_float_to_php($data['datos']);
break;
}
// Re-calculate previous status for the next data
if ((($critical_max > $critical_min AND ($data['datos'] > $critical_max OR $data['datos'] < $critical_min))) OR
($critical_max <= $critical_min AND $data['datos'] < $critical_min)) {
if ($previous_status == 0) {
$critical_count++;
}
$previous_status = 1;
}
else {
$previous_status = 0;
}
$previous_utimestamp = $data['utimestamp'];
}
if ($critical_count == 0) {
return 0;
}
return ($period - $critical_period) / $critical_count;
}
/**
* Get the TTO value of an agent module in a period of time.
*
* @param int Agent module id
* @param int Period of time to check (in seconds)
* @param int Top date to check the values. Default current time.
*
* @return float The TTO value in the interval.
*/
function reporting_get_agentmodule_tto ($id_agent_module, $period = 0, $date = 0) {
// Initialize variables
if (empty ($date)) $date = get_system_time ();
// Read module configuration
$datelimit = $date - $period;
$search_in_history_db = db_search_in_history_db($datelimit);
$module = db_get_row_sql ('SELECT max_critical, min_critical, id_tipo_modulo
FROM tagente_modulo
WHERE id_agente_modulo = ' . (int) $id_agent_module);
if ($module === false) {
return false;
}
$critical_min = $module['min_critical'];
$critical_max = $module['max_critical'];
$module_type = $module['id_tipo_modulo'];
// Set critical_min and critical for proc modules
$module_type_str = modules_get_type_name ($module_type);
if (strstr ($module_type_str, 'proc') !== false &&
($critical_min == 0 && $critical_max == 0)) {
$critical_min = 1;
}
// Get module data
$interval_data = db_get_all_rows_sql ('SELECT * FROM tagente_datos
WHERE id_agente_modulo = ' . (int) $id_agent_module .
' AND utimestamp > ' . (int) $datelimit .
' AND utimestamp < ' . (int) $date .
' ORDER BY utimestamp ASC', $search_in_history_db);
if ($interval_data === false) $interval_data = array ();
// Get previous data
$previous_data = modules_get_previous_data ($id_agent_module, $datelimit);
if ($previous_data !== false) {
$previous_data['utimestamp'] = $datelimit;
array_unshift ($interval_data, $previous_data);
}
// Get next data
$next_data = modules_get_next_data ($id_agent_module, $date);
if ($next_data !== false) {
$next_data['utimestamp'] = $date;
array_push ($interval_data, $next_data);
}
else if (count ($interval_data) > 0) {
// Propagate the last known data to the end of the interval
$next_data = array_pop ($interval_data);
array_push ($interval_data, $next_data);
$next_data['utimestamp'] = $date;
array_push ($interval_data, $next_data);
}
if (count ($interval_data) < 2) {
return false;
}
// Set initial conditions
$critical_period = 0;
$first_data = array_shift ($interval_data);
$previous_utimestamp = $first_data['utimestamp'];
if ((($critical_max > $critical_min AND ($first_data['datos'] > $critical_max OR $first_data['datos'] < $critical_min))) OR
($critical_max <= $critical_min AND $first_data['datos'] < $critical_min)) {
$previous_status = 1;
}
else {
$previous_status = 0;
}
foreach ($interval_data as $data) {
// Previous status was critical
if ($previous_status == 1) {
$critical_period += $data['utimestamp'] - $previous_utimestamp;
}
// Re-calculate previous status for the next data
if ((($critical_max > $critical_min AND ($data['datos'] > $critical_max OR $data['datos'] < $critical_min))) OR
($critical_max <= $critical_min AND $data['datos'] < $critical_min)) {
$previous_status = 1;
}
else {
$previous_status = 0;
}
$previous_utimestamp = $data['utimestamp'];
}
return $period - $critical_period;
}
/**
* Get the TTR value of an agent module in a period of time.
*
* @param int Agent module id
* @param int Period of time to check (in seconds)
* @param int Top date to check the values. Default current time.
*
* @return float The TTR value in the interval.
*/
function reporting_get_agentmodule_ttr ($id_agent_module, $period = 0, $date = 0) {
// Initialize variables
if (empty ($date)) $date = get_system_time ();
// Read module configuration
$datelimit = $date - $period;
$search_in_history_db = db_search_in_history_db($datelimit);
$module = db_get_row_sql ('SELECT max_critical, min_critical, id_tipo_modulo
FROM tagente_modulo
WHERE id_agente_modulo = ' . (int) $id_agent_module);
if ($module === false) {
return false;
}
$critical_min = $module['min_critical'];
$critical_max = $module['max_critical'];
$module_type = $module['id_tipo_modulo'];
// Set critical_min and critical for proc modules
$module_type_str = modules_get_type_name ($module_type);
if (strstr ($module_type_str, 'proc') !== false &&
($critical_min == 0 && $critical_max == 0)) {
$critical_min = 1;
}
// Get module data
$interval_data = db_get_all_rows_sql ('SELECT * FROM tagente_datos
WHERE id_agente_modulo = ' . (int) $id_agent_module .
' AND utimestamp > ' . (int) $datelimit .
' AND utimestamp < ' . (int) $date .
' ORDER BY utimestamp ASC', $search_in_history_db);
if ($interval_data === false) $interval_data = array ();
// Get previous data
$previous_data = modules_get_previous_data ($id_agent_module, $datelimit);
if ($previous_data !== false) {
$previous_data['utimestamp'] = $datelimit;
array_unshift ($interval_data, $previous_data);
}
// Get next data
$next_data = modules_get_next_data ($id_agent_module, $date);
if ($next_data !== false) {
$next_data['utimestamp'] = $date;
array_push ($interval_data, $next_data);
}
else if (count ($interval_data) > 0) {
// Propagate the last known data to the end of the interval
$next_data = array_pop ($interval_data);
array_push ($interval_data, $next_data);
$next_data['utimestamp'] = $date;
array_push ($interval_data, $next_data);
}
if (count ($interval_data) < 2) {
return false;
}
// Set initial conditions
$critical_period = 0;
$first_data = array_shift ($interval_data);
$previous_utimestamp = $first_data['utimestamp'];
if ((($critical_max > $critical_min AND ($first_data['datos'] > $critical_max OR $first_data['datos'] < $critical_min))) OR
($critical_max <= $critical_min AND $first_data['datos'] < $critical_min)) {
$previous_status = 1;
}
else {
$previous_status = 0;
}
foreach ($interval_data as $data) {
// Previous status was critical
if ($previous_status == 1) {
$critical_period += $data['utimestamp'] - $previous_utimestamp;
}
// Re-calculate previous status for the next data
if ((($critical_max > $critical_min AND ($data['datos'] > $critical_max OR $data['datos'] < $critical_min))) OR
($critical_max <= $critical_min AND $data['datos'] < $critical_min)) {
$previous_status = 1;
}
else {
$previous_status = 0;
}
$previous_utimestamp = $data['utimestamp'];
}
return $critical_period;
}
/**
* Get a detailed report of the modules of the agent
*
* @param int $id_agent Agent id to get the report for.
* @param string $filter filter for get partial modules.
*
* @return array An array
*/
function reporting_get_agent_module_info ($id_agent, $filter = false) {
global $config;
$return = array ();
$return["last_contact"] = 0; //Last agent contact
$return["status"] = STATUS_AGENT_NO_DATA;
$return["status_img"] = ui_print_status_image (STATUS_AGENT_NO_DATA, __('Agent without data'), true);
$return["alert_status"] = "notfired";
$return["alert_value"] = STATUS_ALERT_NOT_FIRED;
$return["alert_img"] = ui_print_status_image (STATUS_ALERT_NOT_FIRED, __('Alert not fired'), true);
$return["agent_group"] = agents_get_agent_group ($id_agent);
if (!check_acl ($config["id_user"], $return["agent_group"], "AR")) {
return $return;
}
if ($filter != '') {
$filter = 'AND ';
}
$filter = 'disabled = 0';
$modules = agents_get_modules($id_agent, false, $filter, true, false);
if ($modules === false) {
return $return;
}
$now = get_system_time ();
// Get modules status for this agent
$agent = db_get_row ("tagente", "id_agente", $id_agent);
$return["total_count"] = $agent["total_count"];
$return["normal_count"] = $agent["normal_count"];
$return["warning_count"] = $agent["warning_count"];
$return["critical_count"] = $agent["critical_count"];
$return["unknown_count"] = $agent["unknown_count"];
$return["fired_count"] = $agent["fired_count"];
$return["notinit_count"] = $agent["notinit_count"];
if ($return["total_count"] > 0) {
if ($return["critical_count"] > 0) {
$return["status"] = STATUS_AGENT_CRITICAL;
$return["status_img"] = ui_print_status_image (STATUS_AGENT_CRITICAL, __('At least one module in CRITICAL status'), true);
}
else if ($return["warning_count"] > 0) {
$return["status"] = STATUS_AGENT_WARNING;
$return["status_img"] = ui_print_status_image (STATUS_AGENT_WARNING, __('At least one module in WARNING status'), true);
}
else if ($return["unknown_count"] > 0) {
$return["status"] = STATUS_AGENT_DOWN;
$return["status_img"] = ui_print_status_image (STATUS_AGENT_DOWN, __('At least one module is in UKNOWN status'), true);
}
else {
$return["status"] = STATUS_AGENT_OK;
$return["status_img"] = ui_print_status_image (STATUS_AGENT_OK, __('All Monitors OK'), true);
}
}
//Alert not fired is by default
if ($return["fired_count"] > 0) {
$return["alert_status"] = "fired";
$return["alert_img"] = ui_print_status_image (STATUS_ALERT_FIRED, __('Alert fired'), true);
$return["alert_value"] = STATUS_ALERT_FIRED;
}
elseif (groups_give_disabled_group ($return["agent_group"])) {
$return["alert_status"] = "disabled";
$return["alert_value"] = STATUS_ALERT_DISABLED;
$return["alert_img"] = ui_print_status_image (STATUS_ALERT_DISABLED, __('Alert disabled'), true);
}
return $return;
}
/**
* Print tiny statistics of the status of one agent, group, etc.
*
* @param mixed Array with the counts of the total modules, normal modules, critical modules, warning modules, unknown modules and fired alerts
* @param bool return or echo flag
*
* @return string html formatted tiny stats of modules/alerts of an agent
*/
function reporting_tiny_stats ($counts_info, $return = false, $type = 'agent', $separator = ':', $strict_user = false) {
global $config;
$out = '';
// Depend the type of object, the stats will refer agents, modules...
switch ($type) {
case 'modules':
$template_title['total_count'] = __('%d Total modules');
$template_title['normal_count'] = __('%d Normal modules');
$template_title['critical_count'] = __('%d Critical modules');
$template_title['warning_count'] = __('%d Warning modules');
$template_title['unknown_count'] = __('%d Unknown modules');
break;
case 'agent':
$template_title['total_count'] = __('%d Total modules');
$template_title['normal_count'] = __('%d Normal modules');
$template_title['critical_count'] = __('%d Critical modules');
$template_title['warning_count'] = __('%d Warning modules');
$template_title['unknown_count'] = __('%d Unknown modules');
$template_title['fired_count'] = __('%d Fired alerts');
break;
default:
$template_title['total_count'] = __('%d Total agents');
$template_title['normal_count'] = __('%d Normal agents');
$template_title['critical_count'] = __('%d Critical agents');
$template_title['warning_count'] = __('%d Warning agents');
$template_title['unknown_count'] = __('%d Unknown agents');
$template_title['not_init_count'] = __('%d not init agents');
$template_title['fired_count'] = __('%d Fired alerts');
break;
}
if ($strict_user && $type == 'agent') {
$acltags = tags_get_user_module_and_tags ($config['id_user'],'AR', $strict_user);
$filter['disabled'] = 0;
$id_agent = $counts_info['id_agente'];
$counts_info = array();
$counts_info['normal_count'] = count(tags_get_agent_modules ($id_agent, false, $acltags, false, $filter, false, AGENT_MODULE_STATUS_NORMAL));
$counts_info['warning_count'] = count(tags_get_agent_modules ($id_agent, false, $acltags, false, $filter, false, AGENT_MODULE_STATUS_WARNING));
$counts_info['critical_count'] = count(tags_get_agent_modules ($id_agent, false, $acltags, false, $filter, false, AGENT_MODULE_STATUS_CRITICAL_BAD));
$counts_info['notinit_count'] = count(tags_get_agent_modules ($id_agent, false, $acltags, false, $filter, false, AGENT_MODULE_STATUS_NOT_INIT));
$counts_info['unknown_count'] = count(tags_get_agent_modules ($id_agent, false, $acltags, false, $filter, false, AGENT_MODULE_STATUS_UNKNOWN));
$counts_info['total_count'] = $counts_info['normal_count'] + $counts_info['warning_count'] + $counts_info['critical_count'] + $counts_info['unknown_count'] + $counts_info['notinit_count'];
$all_agent_modules = tags_get_agent_modules ($id_agent, false, $acltags, false, $filter);
if (!empty($all_agent_modules)) {
$mod_clause = "(".implode(',', array_keys($all_agent_modules)).")";
$counts_info['fired_count'] = (int) db_get_sql ("SELECT COUNT(times_fired)
FROM talert_template_modules
WHERE times_fired != 0 AND id_agent_module IN ".$mod_clause);
}
else {
$counts_info['fired_count'] = 0;
}
}
// Store the counts in a data structure to print hidden divs with titles
$stats = array();
if (isset($counts_info['total_count'])) {
$not_init = isset($counts_info['notinit_count']) ? $counts_info['notinit_count'] : 0;
$total_count = $counts_info['total_count'] - $not_init;
$stats[] = array('name' => 'total_count', 'count' => $total_count, 'title' => sprintf($template_title['total_count'], $total_count));
}
if (isset($counts_info['normal_count'])) {
$normal_count = $counts_info['normal_count'];
$stats[] = array('name' => 'normal_count', 'count' => $normal_count, 'title' => sprintf($template_title['normal_count'], $normal_count));
}
if (isset($counts_info['critical_count'])) {
$critical_count = $counts_info['critical_count'];
$stats[] = array('name' => 'critical_count', 'count' => $critical_count, 'title' => sprintf($template_title['critical_count'], $critical_count));
}
if (isset($counts_info['warning_count'])) {
$warning_count = $counts_info['warning_count'];
$stats[] = array('name' => 'warning_count', 'count' => $warning_count, 'title' => sprintf($template_title['warning_count'], $warning_count));
}
if (isset($counts_info['unknown_count'])) {
$unknown_count = $counts_info['unknown_count'];
$stats[] = array('name' => 'unknown_count', 'count' => $unknown_count, 'title' => sprintf($template_title['unknown_count'], $unknown_count));
}
if (isset($counts_info['not_init_count'])) {
$not_init_count = $counts_info['not_init_count'];
$stats[] = array('name' => 'not_init_count',
'count' => $not_init_count,
'title' => sprintf($template_title['not_init_count'], $not_init_count));
}
if (isset($template_title['fired_count'])) {
if (isset($counts_info['fired_count'])) {
$fired_count = $counts_info['fired_count'];
$stats[] = array('name' => 'fired_count', 'count' => $fired_count, 'title' => sprintf($template_title['fired_count'], $fired_count));
}
}
$uniq_id = uniqid();
foreach ($stats as $stat) {
$params = array('id' => 'forced_title_' . $stat['name'] . '_' . $uniq_id,
'class' => 'forced_title_layer',
'content' => $stat['title'],
'hidden' => true);
$out .= html_print_div($params, true);
}
// If total count is less than 0, is an error. Never show negative numbers
if ($total_count < 0) {
$total_count = 0;
}
$out .= '' . '' . $total_count . '';
if (isset($fired_count) && $fired_count > 0)
$out .= ' ' . $separator . ' ' . $fired_count . '';
if (isset($critical_count) && $critical_count > 0)
$out .= ' ' . $separator . ' ' . $critical_count . '';
if (isset($warning_count) && $warning_count > 0)
$out .= ' ' . $separator . ' ' . $warning_count . '';
if (isset($unknown_count) && $unknown_count > 0)
$out .= ' ' . $separator . ' ' . $unknown_count . '';
if (isset($not_init_count) && $not_init_count > 0)
$out .= ' ' . $separator . ' ' . $not_init_count . '';
if (isset($normal_count) && $normal_count > 0)
$out .= ' ' . $separator . ' ' . $normal_count . '';
$out .= '';
if ($return) {
return $out;
}
else {
echo $out;
}
}
/**
* 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 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 $min_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();
switch ($config["dbtype"]) {
case "mysql":
case "postgresql":
$tpdr_description = "tpdr.description";
break;
case "oracle":
$tpdr_description = "to_char(tpdr.description)";
break;
}
$sql_downtime = "
SELECT DISTINCT(tpdr.id),
tpdr.name,
" . $tpdr_description . ",
tpdr.date_from,
tpdr.date_to,
tpdr.executed,
tpdr.id_group,
tpdr.only_alerts,
tpdr.monday,
tpdr.tuesday,
tpdr.wednesday,
tpdr.thursday,
tpdr.friday,
tpdr.saturday,
tpdr.sunday,
tpdr.periodically_time_from,
tpdr.periodically_time_to,
tpdr.periodically_day_from,
tpdr.periodically_day_to,
tpdr.type_downtime,
tpdr.type_execution,
tpdr.type_periodicity,
tpdr.id_user
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;
}
/**
* Gets a detailed reporting of groups's events.
*
* @param unknown_type $id_group Id of the group.
* @param unknown_type $period Time period of the report.
* @param unknown_type $date Date of the report.
* @param unknown_type $return Whether to return or not.
* @param unknown_type $html Whether to return HTML code or not.
*
* @return string Report of groups's events
*/
function reporting_get_count_events_by_agent ($id_group, $period = 0,
$date = 0,
$filter_event_validated = false, $filter_event_critical = false,
$filter_event_warning = false, $filter_event_no_validated = false,
$filter_event_filter_search = null) {
if (!is_numeric ($date)) {
$date = strtotime ($date);
}
if (empty ($date)) {
$date = get_system_time ();
}
return events_get_count_events_by_agent($id_group, $period, $date,
$filter_event_validated, $filter_event_critical,
$filter_event_warning, $filter_event_no_validated,
$filter_event_filter_search);
}
/**
* 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;
}
}
switch ($config["dbtype"]) {
case "mysql":
case "postgresql":
// Do none
break;
case "oracle":
$max = oracle_format_float_to_php($max);
break;
}
foreach ($interval_data as $data) {
switch ($config["dbtype"]) {
case "mysql":
case "postgresql":
// Do none
break;
case "oracle":
$data['datos'] =
oracle_format_float_to_php($data['datos']);
break;
}
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'];
switch ($config["dbtype"]) {
case "mysql":
case "postgresql":
// Do none
break;
case "oracle":
$min = oracle_format_float_to_php($min);
break;
}
foreach ($interval_data as $data) {
switch ($config["dbtype"]) {
case "mysql":
case "postgresql":
// Do none
break;
case "oracle":
$data['datos'] =
oracle_format_float_to_php($data['datos']);
break;
}
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) {
switch ($config["dbtype"]) {
case "mysql":
case "postgresql":
// Do none
break;
case "oracle":
$data['datos'] =
oracle_format_float_to_php($data['datos']);
break;
}
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 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) {
global $config;
$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);
switch ($config["dbtype"]) {
case "mysql":
case "postgresql":
$tpdr_description = "tpdr.description";
break;
case "oracle":
$tpdr_description = "to_char(tpdr.description)";
break;
}
$sql_downtime = "
SELECT
DISTINCT(tpdr.id),
tpdr.name,
" . $tpdr_description . ",
tpdr.date_from,
tpdr.date_to,
tpdr.executed,
tpdr.id_group,
tpdr.only_alerts,
tpdr.monday,
tpdr.tuesday,
tpdr.wednesday,
tpdr.thursday,
tpdr.friday,
tpdr.saturday,
tpdr.sunday,
tpdr.periodically_time_from,
tpdr.periodically_time_to,
tpdr.periodically_day_from,
tpdr.periodically_day_to,
tpdr.type_downtime,
tpdr.type_execution,
tpdr.type_periodicity,
tpdr.id_user
FROM (
SELECT tpd.*
FROM tplanned_downtime tpd, tplanned_downtime_agents tpda, tagente_modulo tam
WHERE (tpd.id = tpda.id_downtime
AND tpda.all_modules = 1
AND tpda.id_agent = tam.id_agente
AND tam.id_agente_modulo IN ($id_agent_modules_str))
AND ((type_execution = 'periodically'
AND $periodically_condition)
OR (type_execution = 'once'
AND ((date_from >= '$start_date' AND date_to <= '$end_date')
OR (date_from <= '$start_date' AND date_to >= '$end_date')
OR (date_from <= '$start_date' AND date_to >= '$start_date')
OR (date_from <= '$end_date' AND date_to >= '$end_date'))))
UNION ALL
SELECT tpd.*
FROM tplanned_downtime tpd, tplanned_downtime_modules tpdm
WHERE (tpd.id = tpdm.id_downtime
AND tpdm.id_agent_module IN ($id_agent_modules_str))
AND ((type_execution = 'periodically'
AND $periodically_condition)
OR (type_execution = 'once'
AND ((date_from >= '$start_date' AND date_to <= '$end_date')
OR (date_from <= '$start_date' AND date_to >= '$end_date')
OR (date_from <= '$start_date' AND date_to >= '$start_date')
OR (date_from <= '$end_date' AND date_to >= '$end_date'))))
) tpdr
ORDER BY tpdr.id";
}
else {
$sql_downtime = "SELECT *
FROM tplanned_downtime tpd, tplanned_downtime_modules tpdm
WHERE (type_execution = 'periodically'
AND $periodically_condition)
OR (type_execution = 'once'
AND ((date_from >= '$start_date' AND date_to <= '$end_date')
OR (date_from <= '$start_date' AND date_to >= '$end_date')
OR (date_from <= '$start_date' AND date_to >= '$start_date')
OR (date_from <= '$end_date' AND date_to >= '$end_date')))";
}
$downtimes = db_get_all_rows_sql($sql_downtime);
if ($downtimes == false) {
$downtimes = array();
}
return $downtimes;
}
/**
* Get SLA of a module.
*
* @param int Agent module to calculate SLA
* @param int Period to check the SLA compliance.
* @param int Minimum data value the module in the right interval
* @param int Maximum data value the module in the right interval. False will
* ignore max value
* @param int Beginning date of the report in UNIX time (current date by default).
* @param array $dayWeek Array of days week to extract as array('monday' => false, 'tuesday' => true....), and by default is null.
* @param string $timeFrom Time in the day to start to extract in mysql format, by default null.
* @param string $timeTo Time in the day to end to extract in mysql format, by default null.
*
* @return float SLA percentage of the requested module. False if no data were
* found
*/
function reporting_get_agentmodule_sla_day ($id_agent_module, $period = 0, $min_value = 1, $max_value = false, $date = 0, $daysWeek = null, $timeFrom = null, $timeTo = null) {
global $config;
if (empty($id_agent_module))
return false;
// Initialize variables
if (empty ($date)) {
$date = get_system_time ();
}
if ($daysWeek === null) {
$daysWeek = array();
}
// Limit date to start searching data
$datelimit = $date - $period;
// Substract the not working time
// Initialize the working time status machine ($wt_status)
// Search the first data at worktime start
list ($period_reduced, $wt_status, $datelimit_increased) = reporting_get_agentmodule_sla_day_period ($period, $date, $timeFrom, $timeTo);
if ($period_reduced <= 0) {
return false;
}
$wt_points = reporting_get_agentmodule_sla_working_timestamp ($period, $date, $timeFrom, $timeTo);
$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;
}
}
}
}
/* The not working time consideration is now doing in foreach loop above
switch ($config["dbtype"]) {
case "mysql":
case "postgresql":
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 . '")';
}
break;
case "oracle":
break;
}
* */
$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 + $datelimit_increased);
if ($previous_data !== false) {
$previous_data['utimestamp'] = $datelimit + $datelimit_increased;
array_unshift ($interval_data, $previous_data);
} else if (count ($interval_data) > 0) {
// Propagate undefined status to first time point
$first_interval_time = array_shift ($interval_data);
$previous_point = $datelimit + $datelimit_increased;
$point = $datelimit + $datelimit_increased;
// Remove rebased points and substract time only on working time
while ($wt_points[0] <= $first_interval_time['utimestamp']) {
$point = array_shift ($wt_points);
if ($wt_status){
$period_reduced -= $point - $previous_point;
}
$wt_status = !$wt_status;
$previous_point = $point;
}
if ($wt_status){
$period_reduced -= $first_interval_time['utimestamp'] - $point;
}
array_unshift ($interval_data, $first_interval_time);
}
if (count ($wt_points) < 2) {
return false;
}
// 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) {
// Test if working time is changed
while ($wt_points[0] <= $data['utimestamp']) {
$intermediate_point = array_shift($wt_points);
if ($wt_status && ($previous_status == 1)) {
$bad_period += $intermediate_point - $previous_utimestamp;
}
$previous_utimestamp = $intermediate_point;
$wt_status = !$wt_status;
}
// Increses bad_period only if it is working time
if ($wt_status && ($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_reduced) * 100);
}
/**
* Get several SLA data for an agentmodule within a period divided on subperiods
*
* @param int Agent module to calculate SLA
* @param int Period to check the SLA compliance.
* @param int Minimum data value the module in the right interval
* @param int Maximum data value the module in the right interval. False will
* ignore max value
* @param array $days Array of days week to extract as array('monday' => false, 'tuesday' => true....), and by default is null.
* @param string $timeFrom Time in the day to start to extract in mysql format, by default null.
* @param string $timeTo Time in the day to end to extract in mysql format, by default null.
*
* @return Array with values either 1, 2, 3 or 4 depending if the SLA percentage for this subperiod
* is within the sla limits, on the edge, outside or with an unknown value.
*/
function reporting_get_agentmodule_sla_array ($id_agent_module, $period = 0, $min_value = 1, $max_value = false, $date = 0, $daysWeek = null, $timeFrom = null, $timeTo = null) {
global $config;
if (empty($id_agent_module))
return false;
// Initialize variables
if (empty ($date)) {
$date = get_system_time ();
}
if ($daysWeek === null) {
$daysWeek = array();
}
// Hotfix: The edge values are confuse to the users
$percent = 0;
// Limit date to start searching data
$datelimit = $date - $period;
$search_in_history_db = db_search_in_history_db($datelimit);
// Get interval data
$sql = sprintf ('SELECT * FROM tagente_datos
WHERE id_agente_modulo = %d
AND utimestamp > %d AND utimestamp <= %d',
$id_agent_module, $datelimit, $date);
//Add the working times (mon - tue - wed ...) and from time to time
$days = array();
//Translate to mysql week days
if ($daysWeek) {
foreach ($daysWeek as $key => $value) {
if (!$value) {
if ($key == 'monday') {
$days[] = 2;
}
if ($key == 'tuesday') {
$days[] = 3;
}
if ($key == 'wednesday') {
$days[] = 4;
}
if ($key == 'thursday') {
$days[] = 5;
}
if ($key == 'friday') {
$days[] = 6;
}
if ($key == 'saturday') {
$days[] = 7;
}
if ($key == 'sunday') {
$days[] = 1;
}
}
}
}
if (count($days) > 0) {
$sql .= ' AND DAYOFWEEK(FROM_UNIXTIME(utimestamp)) NOT IN (' . implode(',', $days) . ')';
}
if ($timeFrom != $timeTo) {
if ($timeFrom < $timeTo) {
$sql .= ' AND (TIME(FROM_UNIXTIME(utimestamp)) >= \'' .
$timeFrom . '\'
AND TIME(FROM_UNIXTIME(utimestamp)) <= \'' .
$timeTo . '\')';
}
elseif ($timeFrom > $timeTo) {
$sql .= ' AND (TIME(FROM_UNIXTIME(utimestamp)) >= \'' .
$timeFrom . '\'
OR TIME(FROM_UNIXTIME(utimestamp)) <= \''.
$timeTo . '\')';
}
}
$sql .= ' ORDER BY utimestamp ASC';
$interval_data = db_get_all_rows_sql ($sql, $search_in_history_db);
if ($interval_data === false) {
$interval_data = array ();
}
// Indexing data
$interval_data_indexed = array();
foreach($interval_data as $idata) {
$interval_data_indexed[$idata['utimestamp']]['data'] = $idata['datos'];
}
//-----------Calculate unknown status events------------------------
$events_unknown = db_get_all_rows_filter ('tevento',
array ('id_agentmodule' => $id_agent_module,
"utimestamp > $datelimit",
"utimestamp < $date",
'order' => 'utimestamp ASC'),
array ('id_evento', 'evento', 'timestamp', 'utimestamp', 'event_type'));
if ($events_unknown === false) {
$events_unknown = array ();
}
// Add unknown periods to data
for ($i = 0; isset($events_unknown[$i]); $i++) {
$eu = $events_unknown[$i];
if ($eu['event_type'] == 'going_unknown') {
$interval_data_indexed[$eu['utimestamp']]['data'] = 0;
$interval_data_indexed[$eu['utimestamp']]['status'] = 4;
// Search the corresponding recovery event.
for ($j = $i+1; isset($events_unknown[$j]); $j++) {
$eu = $events_unknown[$j];
if ($eu['event_type'] != 'going_unknown' && substr ($eu['event_type'], 0, 5) == 'going') {
$interval_data_indexed[$eu['utimestamp']]['data'] = 0;
$interval_data_indexed[$eu['utimestamp']]['status'] = 6;
// Do not process read events again.
$i = $j;
break;
}
}
}
}
// Get the last event before inverval to know if graph start on unknown
$prev_event = db_get_row_filter ('tevento',
array ('id_agentmodule' => $id_agent_module,
"utimestamp <= $datelimit",
'order' => 'utimestamp DESC'));
if (isset($prev_event['event_type']) && $prev_event['event_type'] == 'going_unknown') {
$start_unknown = true;
}
else {
$start_unknown = false;
}
//------------------------------------------------------------------
//-----------------Set limits of the interval-----------------------
// Get previous data (This adds the first data if the begin of module data is after the begin time interval)
$previous_data = modules_get_previous_data ($id_agent_module, $datelimit);
if ($previous_data !== false ) {
$previous_value = $previous_data['datos'];
// if ((($previous_value > ($min_value - $percent)) && ($previous_value < ($min_value + $percent))) ||
// (($previous_value > ($max_value - $percent)) && ($previous_value < ($max_value + $percent)))) {//2 when value is within the edges
// $previous_known_status = 2;
// }
// else
if (($previous_value >= ($min_value + $percent)) && ($previous_value <= ($max_value - $percent))) { //1 when value is OK
$previous_known_status = 1;
}
elseif (($previous_value <= ($min_value - $percent)) || ($previous_value >= ($max_value + $percent))) { //3 when value is Wrong
$previous_known_status = 3;
}
}
// If the starting of the graph is unknown we set it
if ($start_unknown) {
$interval_data_indexed[$datelimit]['data'] = 0;
$interval_data_indexed[$datelimit]['status'] = 4;
}
else {
if ($previous_data !== false ) {
$interval_data_indexed[$datelimit]['data'] = $previous_data['datos'];
}
else { // If there are not data befor interval set unknown
$interval_data_indexed[$datelimit]['data'] = 0;
$interval_data_indexed[$datelimit]['status'] = 4;
$previous_known_status = 1; // Assume the module was in normal status if there is no previous data.
}
}
// Get next data (This adds data before the interval of the report)
$next_data = modules_get_next_data ($id_agent_module, $date);
if ($next_data !== false) {
$interval_data_indexed[$date]['data'] = $previous_data['datos'];
}
else if (count ($interval_data_indexed) > 0) {
// Propagate the last known data to the end of the interval (if there is no module data at the end point)
ksort($interval_data_indexed);
$last_data = end($interval_data_indexed);
$interval_data_indexed[$date] = $last_data;
}
//------------------------------------------------------------------
//--------Calculate planned downtime dates--------------------------
$downtime_dates = reporting_get_planned_downtimes_intervals($id_agent_module, $datelimit, $date);
foreach ($downtime_dates as $downtime_date) {
// Delete data of the planned downtime and put the last data on the upper limit
$interval_data_indexed[$downtime_date['date_from']]['data'] = 0;
$interval_data_indexed[$downtime_date['date_from']]['status'] = 5;
$interval_data_indexed[$downtime_date['date_to']]['data'] = 0;
$interval_data_indexed[$downtime_date['date_to']]['status'] = 4;
$last_downtime_data = false;
foreach ($interval_data_indexed as $idi_timestamp => $idi) {
if ($idi_timestamp != $downtime_date['date_from'] && $idi_timestamp != $downtime_date['date_to'] &&
$idi_timestamp >= $downtime_date['date_from'] && $idi_timestamp <= $downtime_date['date_to']) {
$last_downtime_data = $idi['data'];
unset($interval_data_indexed[$idi_timestamp]);
}
}
// Set the last data of the interval as limit
if ($last_downtime_data !== false) {
$interval_data_indexed[$downtime_date['date_to']]['data'] = $last_downtime_data;
}
}
//------------------------------------------------------------------
// Sort the array
ksort($interval_data_indexed);
// We need more or equal two points
if (count ($interval_data_indexed) < 2) {
return false;
}
//Get the percentage for the limits
$diff = $max_value - $min_value;
// Get module type
$id_module_type = db_get_value('id_tipo_modulo', 'tagente_modulo', 'id_agente_modulo', $id_agent_module);
// If module is boolean don't create translation intervals (on the edge intervals)
// if ($id_module_type == 2 or $id_module_type == 6 or $id_module_type == 9 or $id_module_type == 18) {
// $percent = 0;
// }
// else {
// // Getting 10% of $diff --> $percent = ($diff/100)*10, so...
// $percent = $diff / 10;
// }
//Set initial conditions
$first_data = array_shift ($interval_data);
$previous_utimestamp = $date - $period;
$previous_value = $first_data ['datos'];
$previous_status = 0;
if (isset($first_data['status'])) {
// 4 for the Unknown value and 5 for planned downtime
$previous_status = $first_data['status'];
}
// elseif ((($previous_value > ($min_value - $percent)) && ($previous_value < ($min_value + $percent))) ||
// (($previous_value > ($max_value - $percent)) && ($previous_value < ($max_value + $percent)))) {//2 when value is within the edges
// $previous_status = 2;
// }
elseif (($previous_value >= ($min_value + $percent)) && ($previous_value <= ($max_value - $percent))) { //1 when value is OK
$previous_status = 1;
}
elseif (($previous_value <= ($min_value - $percent)) || ($previous_value >= ($max_value + $percent))) { //3 when value is Wrong
$previous_status = 3;
}
$data_colors = array();
$i = 0;
foreach ($interval_data_indexed as $utimestamp => $data) {
$change = false;
$value = $data['data'];
if (isset($data['status'])) {
// Leaving unkown status.
if ($data['status'] == 6) {
$status = $previous_known_status;
}
// 4 unknown, 5 planned downtime.
else {
$status = $data['status'];
}
}
// elseif ((($value > ($min_value - $percent)) && ($value < ($min_value + $percent))) ||
// (($value > ($max_value - $percent)) && ($value < ($max_value + $percent)))) { //2 when value is within the edges
// $status = 2;
// }
elseif (($value >= ($min_value + $percent)) && ($value <= ($max_value - $percent))) { //1 when value is OK
$status = 1;
}
elseif (($value <= ($min_value - $percent)) || ($value >= ($max_value + $percent))) { //3 when value is Wrong
$status = 3;
}
if ($status != $previous_status) {
$change = true;
$data_colors[$i]['data'] = $previous_status;
$data_colors[$i]['utimestamp'] = $utimestamp - $previous_utimestamp;
$i++;
$previous_status = $status;
$previous_utimestamp = $utimestamp;
}
// Save the last known status.
if ($status <= 3) {
$previous_known_status = $status;
}
}
if ($change == false) {
$data_colors[$i]['data'] = $previous_status;
$data_colors[$i]['utimestamp'] = $date - $previous_utimestamp;
}
return $data_colors;
}
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();'' . format_numeric($server_performance ["total_local_modules"]) . '';
$tdata[0] = html_print_image('images/module.png', true, array('title' => __('Total running modules'), 'width' => '25px'));
$tdata[1] = '' . format_numeric($server_performance ["total_modules"]) . '';
$tdata[2] = '' . format_numeric($server_performance ["total_modules_rate"], 2) . '';
$tdata[3] = html_print_image('images/module.png', true, array('title' => __('Ratio') . ': ' . __('Modules by second'), 'width' => '16px')) . '/sec ';
$table_srv->rowclass[] = '';
$table_srv->data[] = $tdata;
$tdata = array();
$tdata[0] = '';
$table_srv->colspan[count($table_srv->data)][0] = 4;
$table_srv->rowclass[] = '';
$table_srv->data[] = $tdata;
$tdata = array();
$tdata[0] = html_print_image('images/database.png', true, array('title' => __('Local modules'), 'width' => '25px'));
$tdata[1] = '' . format_numeric($server_performance ["total_local_modules"]) . '';
$tdata[2] = '' .
format_numeric($server_performance ["local_modules_rate"], 2) . '';
$tdata[3] = html_print_image('images/module.png', true, array('title' => __('Ratio') . ': ' . __('Modules by second'), 'width' => '16px')) . '/sec ';
$table_srv->rowclass[] = '';
$table_srv->data[] = $tdata;
if ($tiny) {
$tdata = array();
$tdata[0] = html_print_image('images/network.png', true, array('title' => __('Remote modules'), 'width' => '25px'));
$tdata[1] = '' . format_numeric($server_performance ["total_remote_modules"]) . '';
/* Hello there! :)
We added some of what seems to be "buggy" messages to the openSource version recently. This is not to force open-source users to move to the enterprise version, this is just to inform people using Pandora FMS open source that it requires skilled people to maintain and keep it running smoothly without professional support. This does not imply open-source version is limited in any way. If you check the recently added code, it contains only warnings and messages, no limitations except one: we removed the option to add custom logo in header. In the Update Manager section, it warns about the 'danger’ of applying automated updates without a proper backup, remembering in the process that the Enterprise version comes with a human-tested package. Maintaining an OpenSource version with more than 500 agents is not so easy, that's why someone using a Pandora with 8000 agents should consider asking for support. It's not a joke, we know of many setups with a huge number of agents, and we hate to hear that “its becoming unstable and slow” :(
You can of course remove the warnings, that's why we include the source and do not use any kind of trick. And that's why we added here this comment, to let you know this does not reflect any change in our opensource mentality of does the last 14 years.
*/
$tdata[2] = '' . format_numeric($server_performance ["remote_modules_rate"], 2) . '';
$tdata[3] = html_print_image('images/module.png', true, array('title' => __('Ratio') . ': ' . __('Modules by second'), 'width' => '16px')) . '/sec ';
if($server_performance ["total_remote_modules"]>10000 && !enterprise_installed()){
$tdata[4] = "";
}
else{
$tdata[4] = ' ';
}
$table_srv->rowclass[] = '';
$table_srv->data[] = $tdata;
}
else {
if (isset($server_performance ["total_network_modules"])) {
$tdata = array();
$tdata[0] = html_print_image('images/network.png', true, array('title' => __('Network modules'), 'width' => '25px'));
$tdata[1] = '' . format_numeric($server_performance ["total_network_modules"]) . '';
$tdata[2] = '' .
format_numeric($server_performance["network_modules_rate"], 2) .
'';
$tdata[3] = html_print_image('images/module.png', true, array('title' => __('Ratio') . ': ' . __('Modules by second'), 'width' => '16px')) . '/sec ';
if($server_performance ["total_remote_modules"]>10000 && !enterprise_installed()){
$tdata[4] = "";
}
else{
$tdata[4] = ' ';
}
$table_srv->rowclass[] = '';
$table_srv->data[] = $tdata;
}
if (isset($server_performance ["total_plugin_modules"])) {
$tdata = array();
$tdata[0] = html_print_image('images/plugin.png', true, array('title' => __('Plugin modules'), 'width' => '25px'));
$tdata[1] = '' . format_numeric($server_performance ["total_plugin_modules"]) . '';
$tdata[2] = '' . format_numeric($server_performance ["plugin_modules_rate"], 2) . '';
$tdata[3] = html_print_image('images/module.png', true, array('title' => __('Ratio') . ': ' . __('Modules by second'), 'width' => '16px')) . '/sec ';
$table_srv->rowclass[] = '';
$table_srv->data[] = $tdata;
}
if (isset($server_performance ["total_prediction_modules"])) {
$tdata = array();
$tdata[0] = html_print_image('images/chart_bar.png', true, array('title' => __('Prediction modules'), 'width' => '25px'));
$tdata[1] = '' . format_numeric($server_performance ["total_prediction_modules"]) . '';
$tdata[2] = '' . format_numeric($server_performance ["prediction_modules_rate"], 2) . '';
$tdata[3] = html_print_image('images/module.png', true, array('title' => __('Ratio') . ': ' . __('Modules by second'), 'width' => '16px')) . '/sec ';
$table_srv->rowclass[] = '';
$table_srv->data[] = $tdata;
}
if (isset($server_performance ["total_wmi_modules"])) {
$tdata = array();
$tdata[0] = html_print_image('images/wmi.png', true, array('title' => __('WMI modules'), 'width' => '25px'));
$tdata[1] = '' . format_numeric($server_performance ["total_wmi_modules"]) . '';
$tdata[2] = '' . format_numeric($server_performance ["wmi_modules_rate"], 2) . '';
$tdata[3] = html_print_image('images/module.png', true, array('title' => __('Ratio') . ': ' . __('Modules by second'), 'width' => '16px')) . '/sec ';
$table_srv->rowclass[] = '';
$table_srv->data[] = $tdata;
}
if (isset($server_performance ["total_web_modules"])) {
$tdata = array();
$tdata[0] = html_print_image('images/world.png', true, array('title' => __('Web modules'), 'width' => '25px'));
$tdata[1] = '' .
format_numeric($server_performance ["total_web_modules"]) .
'';
$tdata[2] = '' .
format_numeric($server_performance ["web_modules_rate"], 2) .
'';
$tdata[3] = html_print_image('images/module.png', true, array('title' => __('Ratio') . ': ' . __('Modules by second'), 'width' => '16px')) . '/sec ';
$table_srv->rowclass[] = '';
$table_srv->data[] = $tdata;
}
$tdata = array();
$tdata[0] = '';
$table_srv->colspan[count($table_srv->data)][0] = 4;
$table_srv->rowclass[] = '';
$table_srv->data[] = $tdata;
switch ($config["dbtype"]) {
case "mysql":
$system_events = db_get_value_sql(
'SELECT SQL_NO_CACHE COUNT(id_evento)
FROM tevento');
break;
case "postgresql":
case "oracle":
$system_events = db_get_value_sql(
'SELECT COUNT(id_evento)
FROM tevento');
break;
}
$tdata = array();
$tdata[0] = html_print_image('images/lightning_go.png', true,
array('title' => __('Total events'), 'width' => '25px'));
$tdata[1] = '' .
format_numeric($system_events) . '';
/* Hello there! :)
We added some of what seems to be "buggy" messages to the openSource version recently. This is not to force open-source users to move to the enterprise version, this is just to inform people using Pandora FMS open source that it requires skilled people to maintain and keep it running smoothly without professional support. This does not imply open-source version is limited in any way. If you check the recently added code, it contains only warnings and messages, no limitations except one: we removed the option to add custom logo in header. In the Update Manager section, it warns about the 'danger’ of applying automated updates without a proper backup, remembering in the process that the Enterprise version comes with a human-tested package. Maintaining an OpenSource version with more than 500 agents is not so easy, that's why someone using a Pandora with 8000 agents should consider asking for support. It's not a joke, we know of many setups with a huge number of agents, and we hate to hear that “its becoming unstable and slow” :(
You can of course remove the warnings, that's why we include the source and do not use any kind of trick. And that's why we added here this comment, to let you know this does not reflect any change in our opensource mentality of does the last 14 years.
*/
if($system_events > 50000 && !enterprise_installed()){
$tdata[2] = "";
}
else{
$tdata[3] = " ";
}
$table_srv->colspan[count($table_srv->data)][1] = 2;
$table_srv->rowclass[] = '';
$table_srv->data[] = $tdata;
}
$output = '';
return $output;
}
/**
* Get all the template graphs a user can see.
*
* @param $id_user User id to check.
* @param $only_names Wheter to return only graphs names in an associative array
* or all the values.
* @param $returnAllGroup Wheter to return graphs of group All or not.
* @param $privileges Privileges to check in user group
*
* @return template graphs of a an user. Empty array if none.
*/
function reporting_template_graphs_get_user ($id_user = 0, $only_names = false, $returnAllGroup = true, $privileges = 'RR') {
global $config;
if (!$id_user) {
$id_user = $config['id_user'];
}
$groups = users_get_groups ($id_user, $privileges, $returnAllGroup);
$all_templates = db_get_all_rows_in_table ('tgraph_template', 'name');
if ($all_templates === false)
return array ();
$templates = array ();
foreach ($all_templates as $template) {
if (!in_array($template['id_group'], array_keys($groups)))
continue;
if ($template["id_user"] != $id_user && $template['private'])
continue;
if ($template["id_group"] > 0)
if (!isset($groups[$template["id_group"]])) {
continue;
}
if ($only_names) {
$templates[$template['id_graph_template']] = $template['name'];
}
else {
$templates[$template['id_graph_template']] = $template;
$templatesCount = db_get_value_sql("SELECT COUNT(id_gs_template) FROM tgraph_source_template WHERE id_template = " . $template['id_graph_template']);
$templates[$template['id_graph_template']]['graphs_template_count'] = $templatesCount;
}
}
return $templates;
}
/**
* Get a human readable representation of the planned downtime date.
*
* @param array $planned_downtime Planned downtime row.
*
* @return string Representation of the date.
*/
function reporting_format_planned_downtime_dates ($planned_downtime) {
$dates = '';
if (!isset($planned_downtime) || !isset($planned_downtime['type_execution']))
return '';
switch ($planned_downtime['type_execution']) {
case 'once':
$dates = date ("Y-m-d H:i", $planned_downtime['date_from']) .
" " . __('to') . " ".
date ("Y-m-d H:i", $planned_downtime['date_to']);
break;
case 'periodically':
if (!isset($planned_downtime['type_periodicity']))
return '';
switch ($planned_downtime['type_periodicity']) {
case 'weekly':
$dates = __('Weekly:');
$dates .= " ";
if ($planned_downtime['monday']) {
$dates .= __('Mon');
$dates .= " ";
}
if ($planned_downtime['tuesday']) {
$dates .= __('Tue');
$dates .= " ";
}
if ($planned_downtime['wednesday']) {
$dates .= __('Wed');
$dates .= " ";
}
if ($planned_downtime['thursday']) {
$dates .= __('Thu');
$dates .= " ";
}
if ($planned_downtime['friday']) {
$dates .= __('Fri');
$dates .= " ";
}
if ($planned_downtime['saturday']) {
$dates .= __('Sat');
$dates .= " ";
}
if ($planned_downtime['sunday']) {
$dates .= __('Sun');
$dates .= " ";
}
$dates .= " (" . $planned_downtime['periodically_time_from'];
$dates .= "-" . $planned_downtime['periodically_time_to'] . ")";
break;
case 'monthly':
$dates = __('Monthly:') . " ";
$dates .= __('From day') . " " . $planned_downtime['periodically_day_from'];
$dates .= " " . strtolower(__('To day')) . " ";
$dates .= $planned_downtime['periodically_day_to'];
$dates .= " (" . $planned_downtime['periodically_time_from'];
$dates .= "-" . $planned_downtime['periodically_time_to'] . ")";
break;
}
break;
}
return $dates;
}
/**
* Get real period in SLA subtracting worktime period.
* Get if is working in the first point
* Get time between first point and
*
* @param int Period to check the SLA compliance.
* @param int Date_end date end the sla compliace interval
* @param int Working Time start
* @param int Working Time end
*
* @return array (int fixed SLA period, bool inside working time)
* found
*/
function reporting_get_agentmodule_sla_day_period ($period, $date_end, $wt_start = "00:00:00", $wt_end = "23:59:59") {
$date_start = $date_end - $period;
// Converts to timestamp
$human_date_end = date ('H:i:s', $date_end);
$human_date_start = date ('H:i:s', $date_start);
// Store into an array the points
// "s" start SLA interval point
// "e" end SLA interval point
// "f" start worktime interval point (from)
// "t" end worktime interval point (to)
$tp = array (
"s" => strtotime($human_date_start),
"e" => strtotime($human_date_end),
"f" => strtotime($wt_start),
"t" => strtotime($wt_end)
);
asort ($tp);
$order = "";
foreach ($tp as $type => $time) {
$order .= $type;
}
$period_reduced = $period;
$start_working = true;
$datelimit_increased = 0;
//Special case. If $order = "seft" and start time == end time it should be treated like "esft"
if (($period > 0) and ($human_date_end == $human_date_start) and ($order == "seft")) {
$order = "esft";
}
// Discriminates the cases depends what time point is higher than other
switch ($order) {
case "setf":
case "etfs":
case "tfse":
case "fset":
// Default $period_reduced
// Default $start_working
// Default $datelimit_increased
break;
case "stef":
case "tefs":
case "fste":
$period_reduced = $period - ($tp["e"] - $tp["t"]);
// Default $start_working
// Default $datelimit_increased
break;
case "stfe":
case "estf":
case "tfes":
$period_reduced = $period - ($tp["f"] -$tp["t"]);
// Default $start_working
// Default $datelimit_increased
break;
case "tsef":
case "seft":
case "ftse":
case "efts":
$period_reduced = -1;
$start_working = false;
// Default $datelimit_increased
break;
case "tsfe":
case "etsf":
case "sfet":
$period_reduced = $period - ($tp["f"] - $tp["s"]);
$start_working = false;
$datelimit_increased = $tp["f"] - $tp["s"];
break;
case "efst":
$period_reduced = $tp["t"] - $tp["s"];
// Default $start_working
// Default $datelimit_increased
break;
case "fest":
$period_reduced = ($tp["t"] - $tp["s"]) + ($tp["e"] - $tp["f"]);
// Default $start_working
// Default $datelimit_increased
break;
case "tesf":
$period_reduced = SECONDS_1DAY - ($tp["f"] - $tp["t"]);
$start_working = false;
$datelimit_increased = $tp["f"] - $tp["s"];
break;
case "sfte":
case "esft":
$period_reduced = $tp["t"] - $tp["f"];
$start_working = false;
$datelimit_increased = $tp["f"] - $tp["s"];
break;
case "ftes":
$period_reduced = $tp["t"] - $tp["f"];
$start_working = false;
$datelimit_increased = $tp["f"] + SECONDS_1DAY - $tp["s"];
break;
case "fets":
$period_reduced = $tp["e"] - $tp["f"];
$start_working = false;
$datelimit_increased = $tp["f"] + SECONDS_1DAY - $tp["s"];
break;
default:
// Default $period_reduced
// Default $start_working
// Default $datelimit_increased
break;
}
return array ($period_reduced, $start_working, $datelimit_increased);
}
/**
* Get working time SLA in timestamp form. Get all items and discard previous not necessaries
*
* @param int Period to check the SLA compliance.
* @param int Date_end date end the sla compliace interval
* @param int Working Time start
* @param int Working Time end
*
* @return array work time points
* found
*/
function reporting_get_agentmodule_sla_working_timestamp ($period, $date_end, $wt_start = "00:00:00", $wt_end = "23:59:59") {
$date_previous_day = $date_end - SECONDS_1DAY;
$wt = array ();
// Calculate posibles data points
$relative_date_end = strtotime (date ('H:i:s', $date_end));
$relative_00_00_00 = strtotime ("00:00:00");
$relative_wt_start = strtotime($wt_start) - $relative_00_00_00;
$relative_wt_end = strtotime($wt_end) - $relative_00_00_00;
$absolute_previous_00_00_00 = $date_previous_day - ($relative_date_end - $relative_00_00_00);
$absolute_00_00_00 = $date_end - ($relative_date_end - $relative_00_00_00);
array_push ($wt, $absolute_previous_00_00_00);
if ($relative_wt_start < $relative_wt_end) {
array_push ($wt, $absolute_previous_00_00_00 + $relative_wt_start);
array_push ($wt, $absolute_previous_00_00_00 + $relative_wt_end);
array_push ($wt, $absolute_00_00_00 + $relative_wt_start);
array_push ($wt, $absolute_00_00_00 + $relative_wt_end);
} else {
array_push ($wt, $absolute_previous_00_00_00 + $relative_wt_end);
array_push ($wt, $absolute_previous_00_00_00 + $relative_wt_start);
array_push ($wt, $absolute_00_00_00 + $relative_wt_end);
array_push ($wt, $absolute_00_00_00 + $relative_wt_start);
}
array_push ($wt, $absolute_00_00_00 + SECONDS_1DAY);
//Discard outside period time points
$date_start = $date_end - $period;
$first_time = array_shift ($wt);
while ($first_time < $date_start) {
if (empty ($wt)) {
return $wt;
}
$first_time = array_shift ($wt);
}
array_unshift ($wt, $first_time);
return $wt;
}
function reporting_label_macro ($item, $label) {
switch ($item['type']) {
case 'event_report_agent':
case 'alert_report_agent':
case 'agent_configuration':
if (preg_match("/_agent_/", $label)) {
$agent_name = agents_get_name($item['id_agent']);
$label = str_replace("_agent_", $agent_name, $label);
}
if (preg_match("/_agentdescription_/", $label)) {
$agent_name = agents_get_description($item['id_agent']);
$label = str_replace("_agentdescription_", $agent_name, $label);
}
if (preg_match("/_agentgroup_/", $label)) {
$agent_name = groups_get_name(agents_get_agent_group($item['id_agent']),true);
$label = str_replace("_agentgroup_", $agent_name, $label);
}
if (preg_match("/_address_/", $label)) {
$agent_name = agents_get_address($item['id_agent']);
$label = str_replace("_address_", $agent_name, $label);
}
break;
case 'simple_graph':
case 'custom_graph':
case 'simple_baseline_graph':
case 'event_report_module':
case 'alert_report_module':
case 'historical_data':
case 'sumatory':
case 'database_serialized':
case 'monitor_report':
case 'min_value':
case 'max_value':
case 'avg_value':
case 'projection_graph':
case 'prediction_date':
case 'TTRT':
case 'TTO':
case 'MTBF':
case 'MTTR':
if (preg_match("/_agent_/", $label)) {
$agent_name = agents_get_name($item['id_agent']);
$label = str_replace("_agent_", $agent_name, $label);
}
if (preg_match("/_agentdescription_/", $label)) {
$agent_name = agents_get_description($item['id_agent']);
$label = str_replace("_agentdescription_", $agent_name, $label);
}
if (preg_match("/_agentgroup_/", $label)) {
$agent_name = groups_get_name(agents_get_agent_group($item['id_agent']),true);
$label = str_replace("_agentgroup_", $agent_name, $label);
}
if (preg_match("/_address_/", $label)) {
$agent_name = agents_get_address($item['id_agent']);
$label = str_replace("_address_", $agent_name, $label);
}
if (preg_match("/_module_/", $label)) {
$module_name = modules_get_agentmodule_name($item['id_agent_module']);
$label = str_replace("_module_", $module_name, $label);
}
if (preg_match("/_moduledescription_/", $label)) {
$module_description = modules_get_agentmodule_descripcion($item['id_agent_module']);
$label = str_replace("_moduledescription_", $module_description, $label);
}
break;
}
return $label;
}
?>