' . (int) $datelimit . ' AND utimestamp < ' . (int) $date . ' ORDER BY utimestamp ASC', true); 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 = 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 = 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); } foreach ($interval_data as $data) { if (! $uncompressed_module) { $total += $previous_data['datos'] * ($data['utimestamp'] - $previous_data['utimestamp']); $previous_data = $data; } else { $total += $data['datos']; $count++; } } // Compressed module data if (! $uncompressed_module) { if ($period == 0) { return 0; } return $total / $period; } // Uncompressed module data if ($count == 0) { return 0; } return $total / $count; } /** * Get the maximum value of an agent module in a period of time. * * @param int Agent module id to get the maximum value. * @param int Period of time to check (in seconds) * @param int Top date to check the values. Default current time. * * @return float The maximum module value in the interval. */ function get_agentmodule_data_max ($id_agent_module, $period, $date = 0) { global $config; // Initialize variables if (empty ($date)) $date = get_system_time (); if ((empty ($period)) OR ($period == 0)) $period = $config["sla_period"]; $datelimit = $date - $period; $id_module_type = get_agentmodule_type ($id_agent_module); $module_type = get_moduletype_name ($id_module_type); $uncompressed_module = is_module_uncompressed ($module_type); // Get module data $interval_data = get_db_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', true); if ($interval_data === false) $interval_data = array (); // Uncompressed module data if ($uncompressed_module) { // Compressed module data } else { // Get previous data $previous_data = 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 = get_next_data ($id_agent_module, $date); if ($next_data !== false) { $next_data['utimestamp'] = $date; array_push ($interval_data, $next_data); } else if (count ($interval_data) > 0) { // Propagate the last known data to the end of the interval $next_data = array_pop ($interval_data); array_push ($interval_data, $next_data); $next_data['utimestamp'] = $date; array_push ($interval_data, $next_data); } } // Set initial conditions if (empty($iterval_data)) { $max = 0; } else { if ($uncompressed_module || $interval_data[0]['utimestamp'] == $datelimit) { $max = $interval_data[0]['datos']; } else { $max = 0; } } foreach ($interval_data as $data) { if ($data['datos'] > $max) { $max = $data['datos']; } } return $max; } /** * Get the minimum value of an agent module in a period of time. * * @param int Agent module id to get the minimum value. * @param int Period of time to check (in seconds) * @param int Top date to check the values in Unix time. Default current time. * * @return float The minimum module value of the module */ function get_agentmodule_data_min ($id_agent_module, $period, $date = 0) { global $config; // Initialize variables if (empty ($date)) $date = get_system_time (); if ((empty ($period)) OR ($period == 0)) $period = $config["sla_period"]; $datelimit = $date - $period; $id_module_type = get_agentmodule_type ($id_agent_module); $module_type = get_moduletype_name ($id_module_type); $uncompressed_module = is_module_uncompressed ($module_type); // Get module data $interval_data = get_db_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', true); 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 = 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 = get_next_data ($id_agent_module, $date); if ($next_data !== false) { $next_data['utimestamp'] = $date; array_push ($interval_data, $next_data); } else if (count ($interval_data) > 0) { // Propagate the last known data to the end of the interval $next_data = array_pop ($interval_data); array_push ($interval_data, $next_data); $next_data['utimestamp'] = $date; array_push ($interval_data, $next_data); } } if (count ($interval_data) < 1) { return false; } // Set initial conditions $min = $interval_data[0]['datos']; foreach ($interval_data as $data) { if ($data['datos'] < $min) { $min = $data['datos']; } } return $min; } /** * Get the sum of values of an agent module in a period of time. * * @param int Agent module id to get the sumatory. * @param int Period of time to check (in seconds) * @param int Top date to check the values. Default current time. * * @return float The sumatory of the module values in the interval. */ function get_agentmodule_data_sum ($id_agent_module, $period, $date = 0) { // Initialize variables if (empty ($date)) $date = get_system_time (); if ((empty ($period)) OR ($period == 0)) $period = $config["sla_period"]; $datelimit = $date - $period; $id_module_type = get_db_value ('id_tipo_modulo', 'tagente_modulo','id_agente_modulo', $id_agent_module); $module_name = get_db_value ('nombre', 'ttipo_modulo', 'id_tipo', $id_module_type); $module_interval = get_module_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 = get_db_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', true); 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 = 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 = get_next_data ($id_agent_module, $date); if ($next_data !== false) { $next_data['utimestamp'] = $date; array_push ($interval_data, $next_data); } else if (count ($interval_data) > 0) { // Propagate the last known data to the end of the interval $next_data = array_pop ($interval_data); array_push ($interval_data, $next_data); $next_data['utimestamp'] = $date; array_push ($interval_data, $next_data); } $min_necessary = 2; } if (count ($interval_data) < $min_necessary) { return false; } // Set initial conditions $total = 0; if (! $uncompressed_module) { $previous_data = array_shift ($interval_data); } foreach ($interval_data as $data) { if ($uncompressed_module) { $total += $data['datos']; } else if ($module_inc) { $total += $previous_data['datos'] * ($data['utimestamp'] - $previous_data['utimestamp']); } else { $total += $previous_data['datos'] * ($data['utimestamp'] - $previous_data['utimestamp']) / $module_interval; } $previous_data = $data; } return $total; } /** * Get SLA of a module. * * @param int Agent module to calculate SLA * @param int Period to check the SLA compliance. * @param int Minimum data value the module in the right interval * @param int Maximum data value the module in the right interval. False will * ignore max value * @param int Beginning date of the report in UNIX time (current date by default). * @param array $dayWeek Array of days week to extract as array('monday' => false, 'tuesday' => true....), and by default is null. * @param string $timeFrom Time in the day to start to extract in mysql format, by default null. * @param string $timeTo Time in the day to end to extract in mysql format, by default null. * * @return float SLA percentage of the requested module. False if no data were * found */ function get_agentmodule_sla ($id_agent_module, $period = 0, $min_value = 1, $max_value = false, $date = 0, $daysWeek = null, $timeFrom = null, $timeTo = null) { global $config; // Initialize variables if (empty ($date)) $date = get_system_time (); if ((empty ($period)) OR ($period == 0)) $period = $config["sla_period"]; if ($daysWeek === null) $daysWeek = array(); // Limit date to start searching data $datelimit = $date - $period; // 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 (!empty($timeFrom)) { $sql .= ' AND TIME(FROM_UNIXTIME(utimestamp)) >= "' . $timeFrom . '"'; } if (!empty($timeTo)) { $sql .= ' AND TIME(FROM_UNIXTIME(utimestamp)) <= "' . $timeTo . '"'; } $sql .= ' ORDER BY utimestamp ASC'; $interval_data = get_db_all_rows_sql ($sql, true); if ($interval_data === false) $interval_data = array (); // Get previous data $previous_data = 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 = 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); $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; } 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; } else { $previous_status = 0; } } $previous_utimestamp = $data['utimestamp']; } // Return the percentage of SLA compliance return (float) (100 - ($bad_period / $period) * 100); } function get_agentmodule_sla_array ($id_agent_module, $period = 0, $min_value = 1, $max_value = false, $daysWeek = null, $timeFrom = null, $timeTo = null) { global $config; // Get date $date = (string) get_parameter ('date', date ('Y-m-j')); $time = (string) get_parameter ('time', date ('h:iA')); $datetime = strtotime ($date.' '.$time); $k=10; $slices = $config["graph_res"] * $k; $sub_period = $period / ($config["graph_res"] * 10); $final_time = $datetime - $period + $sub_period; $data = array(); $i = 0; while ($final_time <= $datetime) { $sla_value = get_agentmodule_sla ($id_agent_module, $sub_period, $min_value, $max_value, $final_time, $daysWeek, $timeFrom, $timeTo); $data[$i] = $sla_value; $final_time += $sub_period; $i++; } return $data; } /** * Get general statistical info on a group * * @param int Group Id to get info from. 0 = all * * @return array Group statistics */ function get_group_stats ($id_group = 0) { global $config; $data = array (); $data["monitor_checks"] = 0; $data["monitor_not_init"] = 0; $data["monitor_unknown"] = 0; $data["monitor_ok"] = 0; $data["monitor_bad"] = 0; // Critical + Unknown + Warning $data["monitor_warning"] = 0; $data["monitor_critical"] = 0; $data["monitor_alerts"] = 0; $data["monitor_alerts_fired"] = 0; $data["monitor_alerts_fire_count"] = 0; $data["total_agents"] = 0; $data["total_alerts"] = 0; $data["total_checks"] = 0; $data["alerts"] = 0; $data["agents_unknown"] = 0; $data["monitor_health"] = 100; $data["alert_level"] = 100; $data["module_sanity"] = 100; $data["server_sanity"] = 100; $data["total_not_init"] = 0; $data["monitor_non_init"] = 0; $cur_time = get_system_time (); //Check for access credentials using check_acl. More overhead, much safer if (!check_acl ($config["id_user"], $id_group, "AR")) { return $data; } if ($id_group == 0) { $id_group = array_keys (get_user_groups ()); } // ------------------------------------------------------------------- // Server processed stats. NOT realtime (taken from tgroup_stat) // ------------------------------------------------------------------- if ($config["realtimestats"] == 0){ if (!is_array($id_group)){ $my_group = $id_group; $id_group = array(); $id_group[0] = $my_group; } foreach ($id_group as $group){ $group_stat = get_db_all_rows_sql ("SELECT * FROM tgroup_stat, tgrupo WHERE tgrupo.id_grupo = tgroup_stat.id_group AND tgroup_stat.id_group = $group ORDER BY nombre"); $data["monitor_checks"] += $group_stat[0]["modules"]; $data["monitor_not_init"] += $group_stat[0]["non-init"]; $data["monitor_unknown"] += $group_stat[0]["unknown"]; $data["monitor_ok"] += $group_stat[0]["normal"]; $data["monitor_warning"] += $group_stat[0]["warning"]; $data["monitor_critical"] += $group_stat[0]["critical"]; $data["monitor_alerts"] += $group_stat[0]["alerts"]; $data["monitor_alerts_fired"] += $group_stat[0]["alerts_fired"]; $data["monitor_alerts_fire_count"] += $group_stat[0]["alerts_fired"]; $data["total_checks"] += $group_stat[0]["modules"]; $data["total_alerts"] += $group_stat[0]["alerts"]; $data["total_agents"] += $group_stat[0]["agents"]; $data["agents_unknown"] += $group_stat[0]["agents_unknown"]; $data["utimestamp"] = $group_stat[0]["utimestamp"]; } // ------------------------------------------------------------------- // Realtime stats, done by PHP Console // ------------------------------------------------------------------- } else { if (!is_array($id_group)){ $my_group = $id_group; $id_group = array(); $id_group[0] = $my_group; } foreach ($id_group as $group){ switch ($config["dbtype"]) { case "mysql": $data["agents_unknown"] += get_db_sql ("SELECT COUNT(*) FROM tagente WHERE id_grupo = $group AND disabled = 0 AND ultimo_contacto < NOW() - (intervalo * 2)"); break; case "postgresql": $data["agents_unknown"] += get_db_sql ("SELECT COUNT(*) FROM tagente WHERE id_grupo = $group AND disabled = 0 AND ceil(date_part('epoch', ultimo_contacto)) < ceil(date_part('epoch', NOW())) - (intervalo * 2)"); break; } $data["total_agents"] += get_db_sql ("SELECT COUNT(*) FROM tagente WHERE id_grupo = $group AND disabled = 0"); $data["monitor_checks"] += get_db_sql ("SELECT COUNT(tagente_estado.id_agente_estado) FROM tagente_estado, tagente, tagente_modulo WHERE tagente.id_grupo = $group AND tagente.disabled = 0 AND tagente_estado.id_agente = tagente.id_agente AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo AND tagente_modulo.disabled = 0"); $data["total_not_init"] += get_db_sql ("SELECT COUNT(tagente_estado.id_agente_estado) FROM tagente_estado, tagente, tagente_modulo WHERE tagente.id_grupo = $group AND tagente.disabled = 0 AND tagente_estado.id_agente = tagente.id_agente AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo AND tagente_modulo.disabled = 0 AND tagente_modulo.id_tipo_modulo NOT IN (21,22,23,24) AND tagente_estado.utimestamp = 0"); switch ($config["dbtype"]) { case "mysql": $data["monitor_ok"] += get_db_sql ("SELECT COUNT(tagente_estado.id_agente_estado) FROM tagente_estado, tagente, tagente_modulo WHERE tagente.id_grupo = $group AND tagente.disabled = 0 AND tagente_estado.id_agente = tagente.id_agente AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo AND tagente_modulo.disabled = 0 AND estado = 0 AND ((UNIX_TIMESTAMP(NOW()) - tagente_estado.utimestamp) < (tagente_estado.current_interval * 2) OR (tagente_modulo.id_tipo_modulo IN(21,22,23,24,100))) AND (utimestamp > 0 OR (tagente_modulo.id_tipo_modulo IN(21,22,23,24)))"); break; case "postgresql": $data["monitor_ok"] += get_db_sql ("SELECT COUNT(tagente_estado.id_agente_estado) FROM tagente_estado, tagente, tagente_modulo WHERE tagente.id_grupo = $group AND tagente.disabled = 0 AND tagente_estado.id_agente = tagente.id_agente AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo AND tagente_modulo.disabled = 0 AND estado = 0 AND ((ceil(date_part('epoch', CURRENT_TIMESTAMP)) - tagente_estado.utimestamp) < (tagente_estado.current_interval * 2) OR (tagente_modulo.id_tipo_modulo IN(21,22,23,24,100))) AND (utimestamp > 0 OR (tagente_modulo.id_tipo_modulo IN(21,22,23,24)))"); break; } switch ($config["dbtype"]) { case "mysql": $data["monitor_critical"] += get_db_sql ("SELECT COUNT(tagente_estado.id_agente_estado) FROM tagente_estado, tagente, tagente_modulo WHERE tagente.id_grupo = $group AND tagente.disabled = 0 AND tagente_estado.id_agente = tagente.id_agente AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo AND tagente_modulo.disabled = 0 AND estado = 1 AND ((UNIX_TIMESTAMP(NOW()) - tagente_estado.utimestamp) < (tagente_estado.current_interval * 2) OR (tagente_modulo.id_tipo_modulo IN(21,22,23,24,100))) AND utimestamp > 0"); break; case "postgresql": $data["monitor_critical"] += get_db_sql ("SELECT COUNT(tagente_estado.id_agente_estado) FROM tagente_estado, tagente, tagente_modulo WHERE tagente.id_grupo = $group AND tagente.disabled = 0 AND tagente_estado.id_agente = tagente.id_agente AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo AND tagente_modulo.disabled = 0 AND estado = 1 AND ((ceil(date_part('epoch', CURRENT_TIMESTAMP)) - tagente_estado.utimestamp) < (tagente_estado.current_interval * 2) OR (tagente_modulo.id_tipo_modulo IN(21,22,23,24,100))) AND utimestamp > 0"); break; } switch ($config["dbtype"]) { case "mysql": $data["monitor_warning"] += get_db_sql ("SELECT COUNT(tagente_estado.id_agente_estado) FROM tagente_estado, tagente, tagente_modulo WHERE tagente.id_grupo = $group AND tagente.disabled = 0 AND tagente_estado.id_agente = tagente.id_agente AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo AND tagente_modulo.disabled = 0 AND estado = 2 AND ((UNIX_TIMESTAMP(NOW()) - tagente_estado.utimestamp) < (tagente_estado.current_interval * 2) OR (tagente_modulo.id_tipo_modulo IN(21,22,23,24,100))) AND utimestamp > 0"); break; case "postgresql": $data["monitor_warning"] += get_db_sql ("SELECT COUNT(tagente_estado.id_agente_estado) FROM tagente_estado, tagente, tagente_modulo WHERE tagente.id_grupo = $group AND tagente.disabled = 0 AND tagente_estado.id_agente = tagente.id_agente AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo AND tagente_modulo.disabled = 0 AND estado = 2 AND ((ceil(date_part('epoch', CURRENT_TIMESTAMP)) - tagente_estado.utimestamp) < (tagente_estado.current_interval * 2) OR (tagente_modulo.id_tipo_modulo IN(21,22,23,24,100))) AND utimestamp > 0"); break; } switch ($config["dbtype"]) { case "mysql": $data["monitor_unknown"] += get_db_sql ("SELECT COUNT(tagente_estado.id_agente_estado) FROM tagente_estado, tagente, tagente_modulo WHERE tagente.id_grupo = $group AND tagente.disabled = 0 AND tagente.id_agente = tagente_estado.id_agente AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo AND tagente_modulo.disabled = 0 AND utimestamp > 0 AND tagente_modulo.id_tipo_modulo NOT IN(21,22,23,24,100) AND (UNIX_TIMESTAMP(NOW()) - tagente_estado.utimestamp) >= (tagente_estado.current_interval * 2)"); break; case "postgresql": $data["monitor_unknown"] += get_db_sql ("SELECT COUNT(tagente_estado.id_agente_estado) FROM tagente_estado, tagente, tagente_modulo WHERE tagente.id_grupo = $group AND tagente.disabled = 0 AND tagente.id_agente = tagente_estado.id_agente AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo AND tagente_modulo.disabled = 0 AND utimestamp > 0 AND tagente_modulo.id_tipo_modulo NOT IN(21,22,23,24,100) AND (ceil(date_part('epoch', CURRENT_TIMESTAMP)) - tagente_estado.utimestamp) >= (tagente_estado.current_interval * 2)"); break; } $data["monitor_not_init"] += get_db_sql ("SELECT COUNT(tagente_estado.id_agente_estado) FROM tagente_estado, tagente, tagente_modulo WHERE tagente.id_grupo = $group AND tagente.disabled = 0 AND tagente.id_agente = tagente_estado.id_agente AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo AND tagente_modulo.disabled = 0 AND tagente_modulo.id_tipo_modulo NOT IN (21,22,23,24) AND utimestamp = 0"); $data["monitor_alerts"] += get_db_sql ("SELECT COUNT(talert_template_modules.id) FROM talert_template_modules, tagente_modulo, tagente_estado, tagente WHERE tagente.id_grupo = $group AND tagente_modulo.id_agente = tagente.id_agente AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo AND tagente_modulo.disabled = 0 AND tagente.disabled = 0 AND talert_template_modules.id_agent_module = tagente_modulo.id_agente_modulo"); $data["monitor_alerts_fired"] += get_db_sql ("SELECT COUNT(talert_template_modules.id) FROM talert_template_modules, tagente_modulo, tagente_estado, tagente WHERE tagente.id_grupo = $group AND tagente_modulo.id_agente = tagente.id_agente AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo AND tagente_modulo.disabled = 0 AND tagente.disabled = 0 AND talert_template_modules.id_agent_module = tagente_modulo.id_agente_modulo AND times_fired > 0"); } /* Monitor health (percentage) Data health (percentage) Global health (percentage) Module sanity (percentage) Alert level (percentage) Server Sanity 0% Uninitialized modules */ } if ($data["monitor_unknown"] > 0 && $data["monitor_checks"] > 0) { $data["monitor_health"] = format_numeric (100 - ($data["monitor_unknown"] / ($data["monitor_checks"] / 100)), 1); } else { $data["monitor_health"] = 100; } if ($data["monitor_not_init"] > 0 && $data["monitor_checks"] > 0) { $data["module_sanity"] = format_numeric (100 - ($data["monitor_not_init"] / ($data["monitor_checks"] / 100)), 1); } else { $data["module_sanity"] = 100; } if (isset($data["alerts"])){ if ($data["monitor_alerts_fired"] > 0 && $data["alerts"] > 0) { $data["alert_level"] = format_numeric (100 - ($data ["monitor_alerts_fired"] / ($data["alerts"] / 100)), 1); } else { $data["alert_level"] = 100; } } else { $data["alert_level"] = 100; $data["alerts"] = 0; } $data["monitor_bad"] = $data["monitor_critical"] + $data["monitor_warning"]; if ($data["monitor_bad"] > 0 && $data["monitor_checks"] > 0) { $data["global_health"] = format_numeric (100 - ($data["monitor_bad"] / ($data["monitor_checks"] / 100)), 1); } else { $data["global_health"] = 100; } $data["server_sanity"] = format_numeric (100 - $data["module_sanity"], 1); return ($data); } /** * Get an event reporting table. * * It construct a table object with all the events happened in a group * during a period of time. * * @param int Group id to get the report. * @param int Period of time to get the report. * @param int Beginning date of the report * @param int Flag to return or echo the report table (echo by default). * * @return object A table object */ function event_reporting ($id_group, $period, $date = 0, $return = false) { if (empty ($date)) { $date = get_system_time (); } elseif (!is_numeric ($date)) { $date = strtotime ($date); } $table->data = array (); $table->head = array (); $table->head[0] = __('Status'); $table->head[1] = __('Event name'); $table->head[2] = __('User ID'); $table->head[3] = __('Timestamp'); $events = get_group_events ($id_group, $period, $date); if (empty ($events)) { $events = array (); } foreach ($events as $event) { $data = array (); if ($event["estado"] == 0) $data[0] = print_image("images/dot_red.png", true); else $data[0] = print_image("images/dot_green.png", true); $data[1] = $event['evento']; $data[2] = $event['id_usuario'] != '0' ? $event['id_usuario'] : ''; $data[3] = $event["timestamp"]; array_push ($table->data, $data); } if (empty ($return)) print_table ($table); return $table; } /** * Get a table report from a alerts fired array. * * @param array Alerts fired array. * @see function get_alerts_fired () * * @return object A table object with a report of the fired alerts. */ function get_fired_alerts_reporting_table ($alerts_fired) { $agents = array (); global $config; require_once ($config["homedir"].'/include/functions_alerts.php'); foreach (array_keys ($alerts_fired) as $id_alert) { $alert_module = get_alert_agent_module ($id_alert); $template = get_alert_template ($id_alert); /* Add alerts fired to $agents_fired_alerts indexed by id_agent */ $id_agent = get_db_value ('id_agente', 'tagente_modulo', 'id_agente_modulo', $alert_module['id_agent_module']); if (!isset ($agents[$id_agent])) { $agents[$id_agent] = array (); } array_push ($agents[$id_agent], array ($alert_module, $template)); } $table->data = array (); $table->head = array (); $table->head[0] = __('Agent'); $table->head[1] = __('Alert description'); $table->head[2] = __('Times fired'); $table->head[3] = __('Priority'); foreach ($agents as $id_agent => $alerts) { $data = array (); foreach ($alerts as $tuple) { $alert_module = $tuple[0]; $template = $tuple[1]; if (! isset ($data[0])) $data[0] = get_agent_name ($id_agent); else $data[0] = ''; $data[1] = $template['name']; $data[2] = $alerts_fired[$alert_module['id']]; $data[3] = get_alert_priority ($alert_module['priority']); array_push ($table->data, $data); } } return $table; } /** * Get a report for alerts of agent. * * It prints the numbers of alerts defined, fired and not fired of agent. * * @param int $id_agent Agent to get info of the alerts. * @param int $period Period of time of the desired alert report. * @param int $date Beggining date of the report (current date by default). * @param bool $return Flag to return or echo the report (echo by default). * @param bool Flag to return the html or table object, by default html. * * @return mixed A table object (XHTML) or object table is false the html. */ function alert_reporting_agent ($id_agent, $period = 0, $date = 0, $return = true, $html = true) { if (!is_numeric ($date)) { $date = strtotime ($date); } if (empty ($date)) { $date = get_system_time (); } if (empty ($period)) { global $config; $period = $config["sla_period"]; } $table->width = '99%'; $table->data = array (); $table->head = array (); $table->head[0] = __('Module'); $table->head[1] = __('Template'); $table->head[2] = __('Actions'); $table->head[3] = __('Fired'); $alerts = get_agent_alerts ($id_agent); if (isset($alerts['simple'])) { $i = 0; if ($alerts['simple'] === false) $alerts['simple'] = array(); foreach ($alerts['simple'] as $alert) { $data = array(); $data[0] = get_db_value_filter('nombre', 'tagente_modulo', array('id_agente_modulo' => $alert['id_agent_module'])); $data[1] = get_db_value_filter('name', 'talert_templates', array('id' => $alert['id_alert_template'])); $actions = get_db_all_rows_sql('SELECT name FROM talert_actions WHERE id IN (SELECT id_alert_action FROM talert_template_module_actions WHERE id_alert_template_module = ' . $alert['id'] . ');'); $data[2] = '
'; $data[0] .= $monitor_value.' % ' . print_image("images/b_green.png", true, array("height" => "32", "width" => "32")) . '
'; if ($monitor_value !== __('Unknown')) { $monitor_value = format_numeric (100 - $monitor_value, 2) ; } $data[1] = ''; $data[1] .= $monitor_value.' % ' . print_image("images/b_red.png", true, array("height" => "32", "width" => "32")) . '
'; array_push ($table->data, $data); break; case 7: case 'avg_value': //RUNNING $data = array (); $data[0] = $sizh.__('Avg. Value').$sizhfin; $data[1] = $sizh.printTruncateText($agent_name).' - '.printTruncateText($module_name).$sizhfin; $data[2] = $sizh.human_time_description_raw ($content['period']).$sizhfin; array_push ($table->data, $data); // Put description at the end of the module (if exists) $table->colspan[1][0] = 3; if ($content["description"] != ""){ $data_desc = array(); $data_desc[0] = $content["description"]; array_push ($table->data, $data_desc); } $data = array (); $table->colspan[2][0] = 3; $value = get_agentmodule_data_average ($content['id_agent_module'], $content['period'], $report["datetime"]); if ($value === false) { $value = __('Unknown'); } else { $value = format_numeric ($value); } $data[0] = ''.$value.'
'; array_push ($table->data, $data); break; case 8: case 'max_value': //RUNNING $data = array (); $data[0] = $sizh.__('Max. Value').$sizhfin; $data[1] = $sizh.$agent_name.' - '.$module_name.$sizhfin; $data[2] = $sizh.human_time_description_raw ($content['period']).$sizhfin; array_push ($table->data, $data); // Put description at the end of the module (if exists) $table->colspan[1][0] = 3; if ($content["description"] != ""){ $data_desc = array(); $data_desc[0] = $content["description"]; array_push ($table->data, $data_desc); } $data = array (); $table->colspan[2][0] = 3; $value = format_numeric (get_agentmodule_data_max ($content['id_agent_module'], $content['period'], $report["datetime"])); $data[0] = ''.$value.'
'; array_push ($table->data, $data); break; case 9: case 'min_value': //RUNNING $data = array (); $data[0] = $sizh.__('Min. Value').$sizhfin; $data[1] = $sizh.$agent_name.' - '.$module_name.$sizhfin; $data[2] = $sizh.human_time_description_raw ($content['period']).$sizhfin; array_push ($table->data, $data); // Put description at the end of the module (if exists) $table->colspan[0][0] = 2; if ($content["description"] != ""){ $data_desc = array(); $data_desc[0] = $content["description"]; array_push ($table->data, $data_desc); } $data = array (); $table->colspan[1][0] = 2; $value = get_agentmodule_data_min ($content['id_agent_module'], $content['period'], $report["datetime"]); if ($value === false) { $value = __('Unknown'); } else { $value = format_numeric ($value); } $data[0] = ''.$value.'
'; array_push ($table->data, $data); break; case 10: case 'sumatory': //RUNNING $data = array (); $data[0] = $sizh.__('Summatory').$sizhfin; $data[1] = $sizh.$agent_name.' - '.$module_name.$sizhfin; $data[2] = $sizh.human_time_description_raw ($content['period']).$sizhfin; array_push ($table->data, $data); // Put description at the end of the module (if exists) $table->colspan[0][0] = 2; if ($content["description"] != ""){ $data_desc = array(); $data_desc[0] = $content["description"]; array_push ($table->data, $data_desc); } $data = array (); $table->colspan[1][0] = 2; $value = get_agentmodule_data_sum ($content['id_agent_module'], $content['period'], $report["datetime"]); if ($value === false) { $value = __('Unknown'); } else { $value = format_numeric ($value); } $data[0] = ''.$value.'
'; array_push ($table->data, $data); break; case 'agent_detailed_event': case 'event_report_agent': //RUNNING $data = array (); $data[0] = $sizh.__('Agent detailed event').$sizhfin; $data[1] = $sizh.get_agent_name($content['id_agent']).$sizhfin; array_push ($table->data, $data); // Put description at the end of the module (if exists) $table->colspan[1][0] = 3; if ($content["description"] != ""){ $data_desc = array(); $data_desc[0] = $content["description"]; array_push ($table->data, $data_desc); } $data = array (); $table->colspan[2][0] = 3; $data[0] = get_agents_detailed_event_reporting ($content['id_agent'], $content['period'], $report["datetime"], true); array_push ($table->data, $data); break; case 'text': $data = array(); $data[0] = $sizh. __('Text') . $sizhfin; array_push ($table->data, $data); $table->colspan[0][0] = 2; // Put description at the end of the module (if exists) $table->colspan[0][0] = 2; if ($content["description"] != ""){ $data_desc = array(); $data_desc[0] = $content["description"]; array_push ($table->data, $data_desc); } $data[0] = html_entity_decode($content['text']); array_push($table->data, $data); $table->colspan[2][0] = 2; break; case 'sql': $data = array(); $data[0] = $sizh. __('SQL') . $sizhfin; array_push ($table->data, $data); $table->colspan[0][0] = 2; // Put description at the end of the module (if exists) $table->colspan[0][0] = 2; if ($content["description"] != ""){ $data_desc = array(); $data_desc[0] = $content["description"]; array_push ($table->data, $data_desc); } $table2->class = 'databox'; $table2->width = '100%'; //Create the head $table2->head = array(); if ($content['header_definition'] != '') { $table2->head = explode('|', $content['header_definition']); } if ($content['treport_custom_sql_id'] != 0) { switch ($config["dbtype"]) { case "mysql": $sql = safe_output_html (get_db_value_filter('`sql`', 'treport_custom_sql', array('id' => $content['treport_custom_sql_id']))); break; case "postgresql": $sql = safe_output_html (get_db_value_filter('"sql"', 'treport_custom_sql', array('id' => $content['treport_custom_sql_id']))); break; } } else { $sql = safe_output_html ($content['external_source']); } // Do a security check on SQL coming from the user $sql = check_sql ($sql); if($sql != '') { $result = get_db_all_rows_sql($sql); if ($result === false) { $result = array(); } if (isset($result[0])) { if (count($result[0]) > count($table2->head)) { $table2->head = array_pad($table2->head, count($result[0]), ' '); } } $table2->data = array(); foreach ($result as $row) { array_push($table2->data, $row); } } else { $table2->data = array(); array_push($table2->data, array("id_user" => "'.$ttr.'
'; array_push ($table->data, $data); break; case 'TTO': $data = array (); $data[0] = $sizh. __('TTO') . $sizhfin; $data[1] = $sizh.$agent_name.' - '.$module_name.$sizhfin; array_push ($table->data, $data); // Put description at the end of the module (if exists) $table->colspan[1][0] = 3; if ($content["description"] != ""){ $data_desc = array(); $data_desc[0] = $content["description"]; array_push ($table->data, $data_desc); } $data = array (); $table->colspan[2][0] = 3; $tto = get_agentmodule_tto ($content['id_agent_module'], $content['period'], $report["datetime"]); if ($tto === false) { $tto = __('Unknown'); } else if ($tto != 0) { $tto = human_time_description_raw ($tto); } $data = array (); $table->colspan[2][0] = 3; $data[0] = ''.$tto.'
'; array_push ($table->data, $data); break; case 'MTBF': $data = array (); $data[0] = $sizh. __('MTBF') . $sizhfin; $data[1] = $sizh.$agent_name.' - '.$module_name.$sizhfin; array_push ($table->data, $data); // Put description at the end of the module (if exists) $table->colspan[1][0] = 3; if ($content["description"] != ""){ $data_desc = array(); $data_desc[0] = $content["description"]; array_push ($table->data, $data_desc); } $data = array (); $table->colspan[2][0] = 3; $mtbf = get_agentmodule_mtbf ($content['id_agent_module'], $content['period'], $report["datetime"]); if ($mtbf === false) { $mtbf = __('Unknown'); } else if ($mtbf != 0) { $mtbf = human_time_description_raw ($mtbf); } $data = array (); $table->colspan[2][0] = 3; $data[0] = ''.$mtbf.'
'; array_push ($table->data, $data); break; case 'MTTR': $data = array (); $data[0] = $sizh. __('MTTR') . $sizhfin; $data[1] = $sizh.$agent_name.' - '.$module_name.$sizhfin; array_push ($table->data, $data); // Put description at the end of the module (if exists) $table->colspan[1][0] = 3; if ($content["description"] != ""){ $data_desc = array(); $data_desc[0] = $content["description"]; array_push ($table->data, $data_desc); } $data = array (); $table->colspan[2][0] = 3; $mttr = get_agentmodule_mttr ($content['id_agent_module'], $content['period'], $report["datetime"]); if ($mttr === false) { $mttr = __('Unknown'); } else if ($mttr != 0) { $mttr = human_time_description_raw ($mttr); } $data = array (); $table->colspan[2][0] = 3; $data[0] = ''.$mttr.'
'; array_push ($table->data, $data); break; case 'general': $group_by_agent = $content['group_by_agent']; $order_uptodown = $content['order_uptodown']; $table->style[1] = 'text-align: right'; $data = array (); $data[0] = $sizh.__('General').$sizhfin; $data[1] = $sizh.human_time_description_raw ($content['period']).$sizhfin; array_push ($table->data, $data); // Put description at the end of the module (if exists) $table->colspan[1][0] = 3; if ($content["description"] != ""){ $data_desc = array(); $data_desc[0] = $content["description"]; array_push ($table->data, $data_desc); } switch ($group_by_agent) { //0 means not group by agent case 0: $sql = sprintf("select a.id_agent_module, b.nombre as agent_name, c.nombre as module_name from treport_content_item as a, tagente as b, tagente_modulo as c where a.id_agent_module = c.id_agente_modulo and c.id_agente = b.id_agente and id_report_content = %d", $content['id_rc']); $generals = process_sql ($sql); if ($generals === false) { $data = array (); $table->colspan[2][0] = 3; $data[0] = __('There are no Agent/Modules defined'); array_push ($table->data, $data); break; } $table1->width = '99%'; $table1->data = array (); $table1->head = array (); $table1->head[0] = __('Agent'); $table1->head[1] = __('Module'); $table1->head[2] = __('Value'); $table1->style[0] = 'text-align: center'; $table1->style[1] = 'text-align: center'; $table1->style[2] = 'text-align: center'; $data_avg = array(); foreach ($generals as $key => $row) { $data_avg[$key] = get_agentmodule_data_average ($row['id_agent_module'], $content['period']); $id_agent_module[$key] = $row['id_agent_module']; $agent_name[$key] = $row['agent_name']; $module_name[$key] = $row['module_name']; } if ($order_uptodown == 0 || $order_uptodown == 1 || $order_uptodown == 2) { switch ($order_uptodown) { //Descending case 1: array_multisort($data_avg, SORT_DESC, $agent_name, SORT_ASC, $module_name, SORT_ASC, $id_agent_module, SORT_ASC); break; //Ascending case 2: array_multisort($data_avg, SORT_ASC, $agent_name, SORT_ASC, $module_name, SORT_ASC, $id_agent_module, SORT_ASC); break; } $i=0; foreach ($data_avg as $d) { $data = array(); $data[0] = printTruncateText($agent_name[$i], 30); $data[1] = printTruncateText($module_name[$i], 30); $d === false ? $data[2] = '--':$data[2] = $d; array_push ($table1->data, $data); $i++; } } elseif ($order_uptodown == 3) { array_multisort($agent_name, SORT_ASC, $data_avg, SORT_ASC, $module_name, SORT_ASC, $id_agent_module, SORT_ASC); $i=0; foreach ($agent_name as $a) { $data = array(); $data[0] = printTruncateText($agent_name[$i], 30); $data[1] = printTruncateText($module_name[$i], 30); $data_avg[$i] === false ? $data[2] = '--':$data[2] = $data_avg[$i]; array_push ($table1->data, $data); $i++; } } $table->colspan[2][0] = 3; $data = array(); $data[0] = print_table($table1, true); array_push ($table->data, $data); break; //1 means group by agent case 1: //Get the list of agents $sql_agents = sprintf ("select distinct ta.nombre from tagente as ta, tagente_modulo as tam, treport_content_item as trci where ta.id_agente = tam.id_agente and tam.id_agente_modulo = trci.id_agent_module and trci.id_report_content = %d", $content['id_rc']); $agent_list = process_sql ($sql_agents); //Get the list of modules $sql_modules = sprintf ("select distinct tam.nombre from tagente_modulo as tam, treport_content_item as trci where tam.id_agente_modulo = trci.id_agent_module and trci.id_report_content = %d", $content['id_rc']); $modules_list = process_sql ($sql_modules); //Get the data $sql_data = sprintf("select trci.id_agent_module, ta.nombre as agent_name, tam.nombre as module_name from treport_content_item as trci, tagente as ta, tagente_modulo as tam where ta.id_agente = tam.id_agente and tam.id_agente_modulo = trci.id_agent_module and id_report_content = %d", $content['id_rc']); $generals = process_sql ($sql_data); if ($generals === false) { $data = array (); $table->colspan[2][0] = 3; $data[0] = __('There are no Agent/Modules defined'); array_push ($table->data, $data); break; } $table2->width = '99%'; $table2->data = array (); $table2->head = array (); $table2->head[0] = __('Agent'); $table2->style[0] = 'text-align: center'; $i = 1; foreach ($modules_list as $m) { $table2->head[$i] = printTruncateText($m['nombre'], 20); $table2->style[$i] = 'text-align: center'; $i++; } foreach ($agent_list as $a) { $data = array(); $data[0] = printTruncateText($a['nombre'], 20); $i = 1; foreach ($modules_list as $m) { foreach ($generals as $g) { $agent_name = $g['agent_name']; $module_name = $g['module_name']; $found = false; if (strcmp($a['nombre'], $agent_name) == 0 && strcmp($m['nombre'], $module_name) == 0) { if (get_agentmodule_data_average($g['id_agent_module'], $content['period']) === false) $data[$i] = '--'; else { $data[$i] = get_agentmodule_data_average($g['id_agent_module'], $content['period']); } $found = true; } else { $data[$i] = '--'; } if ($found == true) break; } $i++; } array_push($table2->data, $data); } $table->colspan[2][0] = 3; $data = array(); $data[0] = print_table($table2, true); array_push ($table->data, $data); break; } if ($content['show_resume'] && count($generals) > 0) { //Get the first valid value and assign it to $min & $max $min = false; $i=0; do { $min = get_agentmodule_data_average($generals[$i]['id_agent_module'], $content['period']); $i++; } while ($min === false && $i < count($generals)); $max = $min; $avg = 0; $length = 0; if ($generals === false) { $generals = array(); } foreach ($generals as $g) { $value = get_agentmodule_data_average ($g['id_agent_module'], $content['period']); if ($value !== false) { if ($value > $max) { $max = $value; } if ($value < $min ) { $min = $value; } $avg += $value; $length++; } } if ($length == 0) { $avg = 0; } else { $avg = $avg / $length; } $data_resume = array(); $data_resume[0] = "Max Value: ".$max; array_push ($table->data, $data_resume); $data_resume[0] = "Min Value: ".$min; array_push ($table->data, $data_resume); $data_resume[0] = "Average Value: ".$avg; array_push ($table->data, $data_resume); } break; case 'top_n': $order_uptodown = $content['order_uptodown']; $top_n = $content['top_n']; $top_n_value = $content['top_n_value']; $table->style[1] = 'text-align: right'; $data = array (); $data[0] = $sizh.__('Top').' '.$content['top_n_value'].$sizhfin; $data[1] = $sizh.human_time_description_raw ($content['period']).$sizhfin; array_push ($table->data, $data); // Put description at the end of the module (if exists) $table->colspan[1][0] = 3; if ($content["description"] != ""){ $data_desc = array(); $data_desc[0] = $content["description"]; array_push ($table->data, $data_desc); } //Get all the related data $sql = sprintf("select a.id_agent_module, b.nombre as agent_name, c.nombre as module_name from treport_content_item as a, tagente as b, tagente_modulo as c where a.id_agent_module = c.id_agente_modulo and c.id_agente = b.id_agente and id_report_content = %d", $content['id_rc']); $tops = process_sql ($sql); if ($tops === false) { $data = array (); $table->colspan[2][0] = 3; $data[0] = __('There are no Agent/Modules defined'); array_push ($table->data, $data); break; } $table1->width = '99%'; $table1->data = array (); $table1->head = array (); $table1->head[0] = __('Agent'); $table1->head[1] = __('Module'); $table1->head[2] = __('Value'); $table1->style[0] = 'text-align: center'; $table1->style[1] = 'text-align: center'; $table1->style[2] = 'text-align: center'; $data_top = array(); foreach ($tops as $key => $row) { switch ($top_n) { //Max case 1: $value = get_agentmodule_data_max ($row['id_agent_module'], $content['period']); break; //Min case 2: $value = get_agentmodule_data_min ($row['id_agent_module'], $content['period']); break; //Nothing or Average case 0: //If nothing is selected then it will be shown the average data case 3: $value = get_agentmodule_data_average ($row['id_agent_module'], $content['period']); break; } //If the returned value from get_agentmodule_data... is false it won't be stored. if ($value !== false) { $data_top[$key] = $value; $id_agent_module[$key] = $row['id_agent_module']; $agent_name[$key] = $row['agent_name']; $module_name[$key] = $row['module_name']; } } switch ($top_n) { //Max case 1: array_multisort($data_top, SORT_DESC, $agent_name, SORT_ASC, $module_name, SORT_ASC, $id_agent_module, SORT_ASC); break; //Min case 2: array_multisort($data_top, SORT_ASC, $agent_name, SORT_ASC, $module_name, SORT_ASC, $id_agent_module, SORT_ASC); break; //By agent name or without selection case 0: case 3: array_multisort($agent_name, SORT_ASC, $data_top, SORT_ASC, $module_name, SORT_ASC, $id_agent_module, SORT_ASC); break; } $data_top_values = array (); $data_top_values['data_top'] = $data_top; $data_top_values['agent_name'] = $agent_name; $data_top_values['module_name'] = $module_name; $data_top_values['id_agent_module'] = $id_agent_module; array_splice ($data_top, $top_n_value); array_splice ($agent_name, $top_n_value); array_splice ($module_name, $top_n_value); array_splice ($id_agent_module, $top_n_value); switch ($order_uptodown) { //Descending case 1: array_multisort($data_top, SORT_DESC, $agent_name, SORT_ASC, $module_name, SORT_ASC, $id_agent_module, SORT_ASC); break; //Ascending case 2: array_multisort($data_top, SORT_ASC, $agent_name, SORT_ASC, $module_name, SORT_ASC, $id_agent_module, SORT_ASC); break; //By agent name or without selection case 0: case 3: array_multisort($agent_name, SORT_ASC, $data_top, SORT_ASC, $module_name, SORT_ASC, $id_agent_module, SORT_ASC); break; } if ($order_uptodown == 1 || $order_uptodown == 2) { $i = 0; foreach ($data_top as $dt) { $data = array(); $data[0] = printTruncateText($agent_name[$i], 30); $data[1] = printTruncateText($module_name[$i], 30); $data[2] = $dt; array_push ($table1->data, $data); $i++; if ($i >= $top_n_value) break; } } else if ($order_uptodown == 0 || $order_uptodown == 3) { $i = 0; foreach ($agent_name as $an) { $data = array(); $data[0] = printTruncateText($an, 30); $data[1] = printTruncateText($module_name[$i], 30); $data[2] = $data_top[$i]; array_push ($table1->data, $data); $i++; if ($i >= $top_n_value) break; } } $table->colspan[2][0] = 3; $data = array(); $data[0] = print_table($table1, true); array_push ($table->data, $data); if ($content['show_resume'] && count($data_top_values) > 0) { //Get the very first not null value $i=0; do { $min = $data_top_values['data_top'][$i]; $i++; } while ($min === false && $i < count($data_top_values)); $max = $min; $avg = 0; $i=0; foreach ($data_top_values['data_top'] as $key => $dtv) { if ($dtv < $min) $min = $dtv; if ($dtv > $max) $max = $dtv; $avg += $dtv; $i++; } $avg = $avg / $i; $data_resume = array(); $data_resume[0] = __('Max Value').': '.$max; array_push ($table->data, $data_resume); $data_resume[0] = __('Min Value').': '.$min; array_push ($table->data, $data_resume); $data_resume[0] = __('Average Value').': '.$avg; array_push ($table->data, $data_resume); } break; case 'exception': $order_uptodown = $content['order_uptodown']; $exception_condition = $content['exception_condition']; $exception_condition_value = $content['exception_condition_value']; $table->style[1] = 'text-align: right'; $data = array (); $data[0] = $sizh.__('Exception'); switch ($exception_condition) { case 0: $data[0] .= ' - '.__('Everything'); break; case 1: $data[0] .= ' - '.__('Modules over or equal to').' '.$exception_condition_value; break; case 2: $data[0] .= ' - '.__('Modules under').' '.$exception_condition_value; break; case 3: $data[0] .= ' - '.__('Modules at normal status'); break; case 4: $data[0] .= ' - '.__('Modules at critial or warning status'); break; } $data[0].=$sizhfin; $data[1] = $sizh.human_time_description_raw ($content['period']).$sizhfin; array_push ($table->data, $data); // Put description at the end of the module (if exists) $table->colspan[1][0] = 3; if ($content["description"] != ""){ $data_desc = array(); $data_desc[0] = $content["description"]; array_push ($table->data, $data_desc); } //Get all the related data $sql = sprintf("select a.id_agent_module, b.nombre as agent_name, c.nombre as module_name from treport_content_item as a, tagente as b, tagente_modulo as c where a.id_agent_module = c.id_agente_modulo and c.id_agente = b.id_agente and id_report_content = %d", $content['id_rc']); $exceptions = process_sql ($sql); if ($exceptions === false) { $data = array (); $table->colspan[2][0] = 3; $data[0] = __('There are no Agent/Modules defined'); array_push ($table->data, $data); break; } $table1->width = '99%'; $table1->data = array (); $table1->head = array (); $table1->head[0] = __('Agent'); $table1->head[1] = __('Module'); $table1->head[2] = __('Value'); $table1->style[0] = 'text-align: center'; $table1->style[1] = 'text-align: center'; $table1->style[2] = 'text-align: center'; //Get the very first not null value $i=0; do { $min = get_agentmodule_data_average ($exceptions[$i]['id_agent_module'], $content['period']); $i++; } while ($min === false && $i < count($exceptions)); $max = $min; $avg = 0; $i=0; foreach ($exceptions as $exc) { $value = get_agentmodule_data_average ($exc['id_agent_module'], $content['period']); if ($value !== false) { if ($value > $max) $max = $value; if ($value < $min) $min = $value; $avg += $value; $i++; switch ($exception_condition) { //Display everything case 0: break; //Display modules over or equal to certain value case 1: //Skip modules under 'value' if ($value < $exception_condition_value) { continue 2; } break; //Display modules under a certain value case 2: //Skip modules over or equal to 'value' if ($value >= $exception_condition_value) { continue 2; } break; //Display modules at Normal status case 3: //Skip modules without normal status if (get_agentmodule_status($exc['id_agent_module']) != 0) { continue 2; } break; //Display modules at critical, warning or unknown status case 4: //Skip modules at normal status if (get_agentmodule_status($exc['id_agent_module']) == 0) { continue 2; } break; } $data_exceptions[] = $value; $id_agent_module[] = $exc['id_agent_module']; $agent_name[] = $exc['agent_name']; $module_name[] = $exc['module_name']; } } //$i > 0 means that there is at least one row on the table if ($i > 0) { $avg = $avg / $i; switch ($order_uptodown) { //Descending case 1: array_multisort($data_exceptions, SORT_DESC, $agent_name, SORT_ASC, $module_name, SORT_ASC, $id_agent_module, SORT_ASC); break; //Ascending case 2: array_multisort($data_exceptions, SORT_ASC, $agent_name, SORT_ASC, $module_name, SORT_ASC, $id_agent_module, SORT_ASC); break; //By agent name or without selection case 0: case 3: array_multisort($agent_name, SORT_ASC, $data_exceptions, SORT_ASC, $module_name, SORT_ASC, $id_agent_module, SORT_ASC); break; } if ($order_uptodown == 1 || $order_uptodown == 2) { $j=0; foreach ($data_exceptions as $dex) { $data = array(); $data[0] = printTruncateText($agent_name[$j], 30); $data[1] = printTruncateText($module_name[$j], 30); $data[2] = $dex; array_push ($table1->data, $data); $j++; } } else if ($order_uptodown == 0 || $order_uptodown == 3) { $j=0; foreach ($agent_name as $an) { $data = array(); $data[0] = printTruncateText($an, 30); $data[1] = printTruncateText($module_name[$j], 30); $data[2] = $data_exceptions[$j]; array_push ($table1->data, $data); $j++; } } } $table->colspan[2][0] = 3; $data = array(); $data[0] = print_table($table1, true); array_push ($table->data, $data); if ($content['show_resume'] && $i>0) { $data_resume = array(); $data_resume[0] = __('Max Value').': '.$max; array_push ($table->data, $data_resume); $data_resume[0] = __('Min Value').': '.$min; array_push ($table->data, $data_resume); $data_resume[0] = __('Average Value').': '.$avg; array_push ($table->data, $data_resume); } break; } } /** * 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 get_agentmodule_mtbf ($id_agent_module, $period, $date = 0) { // Initialize variables if (empty ($date)) $date = get_system_time (); if ((empty ($period)) OR ($period == 0)) $period = $config["sla_period"]; // Read module configuration $datelimit = $date - $period; $module = get_db_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 = get_module_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 = get_db_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', true); if ($interval_data === false) $interval_data = array (); // Get previous data $previous_data = 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 = get_next_data ($id_agent_module, $date); if ($next_data !== false) { $next_data['utimestamp'] = $date; array_push ($interval_data, $next_data); } else if (count ($interval_data) > 0) { // Propagate the last known data to the end of the interval $next_data = array_pop ($interval_data); array_push ($interval_data, $next_data); $next_data['utimestamp'] = $date; array_push ($interval_data, $next_data); } if (count ($interval_data) < 2) { return false; } // Set initial conditions $critical_period = 0; $first_data = array_shift ($interval_data); $previous_utimestamp = $first_data['utimestamp']; if ((($critical_max > $critical_min AND ($first_data['datos'] > $critical_max OR $first_data['datos'] < $critical_min))) OR ($critical_max <= $critical_min AND $first_data['datos'] < $critical_min)) { $previous_status = 1; $critical_count = 1; } else { $previous_status = 0; $critical_count = 0; } foreach ($interval_data as $data) { // Previous status was critical if ($previous_status == 1) { $critical_period += $data['utimestamp'] - $previous_utimestamp; } // Re-calculate previous status for the next data if ((($critical_max > $critical_min AND ($data['datos'] > $critical_max OR $data['datos'] < $critical_min))) OR ($critical_max <= $critical_min AND $data['datos'] < $critical_min)) { if ($previous_status == 0) { $critical_count++; } $previous_status = 1; } else { $previous_status = 0; } $previous_utimestamp = $data['utimestamp']; } if ($critical_count == 0) { return 0; } return ($period - $critical_period) / $critical_count; } /** * Get the MTTR value of an agent module in a period of time. See * http://en.wikipedia.org/wiki/Mean_time_to_recovery * * @param int Agent module id * @param int Period of time to check (in seconds) * @param int Top date to check the values. Default current time. * * @return float The MTTR value in the interval. */ function get_agentmodule_mttr ($id_agent_module, $period, $date = 0) { // Initialize variables if (empty ($date)) $date = get_system_time (); if ((empty ($period)) OR ($period == 0)) $period = $config["sla_period"]; // Read module configuration $datelimit = $date - $period; $module = get_db_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 = get_module_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 = get_db_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', true); if ($interval_data === false) $interval_data = array (); // Get previous data $previous_data = 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 = get_next_data ($id_agent_module, $date); if ($next_data !== false) { $next_data['utimestamp'] = $date; array_push ($interval_data, $next_data); } else if (count ($interval_data) > 0) { // Propagate the last known data to the end of the interval $next_data = array_pop ($interval_data); array_push ($interval_data, $next_data); $next_data['utimestamp'] = $date; array_push ($interval_data, $next_data); } if (count ($interval_data) < 2) { return false; } // Set initial conditions $critical_period = 0; $first_data = array_shift ($interval_data); $previous_utimestamp = $first_data['utimestamp']; if ((($critical_max > $critical_min AND ($first_data['datos'] > $critical_max OR $first_data['datos'] < $critical_min))) OR ($critical_max <= $critical_min AND $first_data['datos'] < $critical_min)) { $previous_status = 1; $critical_count = 1; } else { $previous_status = 0; $critical_count = 0; } foreach ($interval_data as $data) { // Previous status was critical if ($previous_status == 1) { $critical_period += $data['utimestamp'] - $previous_utimestamp; } // Re-calculate previous status for the next data if ((($critical_max > $critical_min AND ($data['datos'] > $critical_max OR $data['datos'] < $critical_min))) OR ($critical_max <= $critical_min AND $data['datos'] < $critical_min)) { if ($previous_status == 0) { $critical_count++; } $previous_status = 1; } else { $previous_status = 0; } $previous_utimestamp = $data['utimestamp']; } if ($critical_count == 0) { return 0; } return $critical_period / $critical_count; } /** * Get the TTO value of an agent module in a period of time. * * @param int Agent module id * @param int Period of time to check (in seconds) * @param int Top date to check the values. Default current time. * * @return float The TTO value in the interval. */ function get_agentmodule_tto ($id_agent_module, $period, $date = 0) { // Initialize variables if (empty ($date)) $date = get_system_time (); if ((empty ($period)) OR ($period == 0)) $period = $config["sla_period"]; // Read module configuration $datelimit = $date - $period; $module = get_db_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 = get_module_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 = get_db_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', true); if ($interval_data === false) $interval_data = array (); // Get previous data $previous_data = 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 = 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 get_agentmodule_ttr ($id_agent_module, $period, $date = 0) { // Initialize variables if (empty ($date)) $date = get_system_time (); if ((empty ($period)) OR ($period == 0)) $period = $config["sla_period"]; // Read module configuration $datelimit = $date - $period; $module = get_db_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 = get_module_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 = get_db_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', true); if ($interval_data === false) $interval_data = array (); // Get previous data $previous_data = 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 = 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; } ?>