$id_agent_modules) {
//Metaconsole connection
if (!empty($server)) {
$connection = metaconsole_get_connection($server);
if (!metaconsole_load_external_db($connection)) {
continue;
}
$planned_downtimes_by_server[$server] = reporting_get_planned_downtimes(($report['datetime']-$content['period']), $report['datetime'], $id_agent_modules);
$malformed_planned_downtimes_by_server[$server] = planned_downtimes_get_malformed();
if (!empty($planned_downtimes_by_server[$server]))
$planned_downtimes_empty = false;
if (!empty($malformed_planned_downtimes_by_server[$server]))
$malformed_planned_downtimes_empty = false;
//Restore db connection
metaconsole_restore_db();
}
}
if (!$planned_downtimes_empty) {
foreach ($planned_downtimes_by_server as $server => $planned_downtimes) {
foreach ($planned_downtimes as $planned_downtime) {
$data = array();
$data['server'] = $server;
$data['name'] = $planned_downtime['name'];
$data['description'] = $planned_downtime['description'];
$data['execution'] = ucfirst($planned_downtime['type_execution']);
$data['dates'] = reporting_format_planned_downtime_dates($planned_downtime);
$data['malformed'] = 0;
if (!$malformed_planned_downtimes_empty
&& isset($malformed_planned_downtimes_by_server[$server])
&& isset($malformed_planned_downtimes_by_server[$server][$planned_downtime['id']])) {
$data['malformed'] = 1;
if (!$downtime_malformed)
$downtime_malformed = true;
}
$return['planned_downtimes'][] = $data;
}
}
}
}
else {
$id_agent_modules = array();
foreach ($slas as $sla) {
if (!empty($sla['id_agent_module']))
$id_agent_modules[] = $sla['id_agent_module'];
}
$planned_downtimes =
reporting_get_planned_downtimes(
($report['datetime'] - $content['period']),
$report['datetime'],
$id_agent_modules);
$malformed_planned_downtimes = planned_downtimes_get_malformed();
if (!empty($planned_downtimes))
$planned_downtimes_empty = false;
if (!empty($malformed_planned_downtimes))
$malformed_planned_downtimes_empty = false;
if (!$planned_downtimes_empty) {
foreach ($planned_downtimes as $planned_downtime) {
$data = array();
$data['name'] = $planned_downtime['name'];
$data['description'] = $planned_downtime['description'];
$data['execution'] = ucfirst($planned_downtime['type_execution']);
$data['dates'] =
reporting_format_planned_downtime_dates($planned_downtime);
$data['malformed'] = 0;
if (!$malformed_planned_downtimes_empty && isset($malformed_planned_downtimes[$planned_downtime['id']])) {
$data['malformed'] = 1;
if (!$downtime_malformed)
$downtime_malformed = true;
}
$return['planned_downtimes'][] = $data;
}
}
}
if ($downtime_malformed) {
$return['failed'] =
__('This item is affected by a malformed planned downtime. Go to the planned downtimes section to solve this.');
}
else {
$urlImage = ui_get_full_url(false, true, false, false);
$sla_failed = false;
$total_SLA = 0;
$total_result_SLA = 'ok';
$sla_showed = array();
$sla_showed_values = array();
foreach ($slas as $sla) {
$server_name = $sla ['server_name'];
//Metaconsole connection
if ($metaconsole_on && $server_name != '') {
$connection = metaconsole_get_connection($server_name);
if (!metaconsole_load_external_db($connection)) {
//ui_print_error_message ("Error connecting to ".$server_name);
continue;
}
}
if (modules_is_disable_agent($sla['id_agent_module'])
|| modules_is_not_init($sla['id_agent_module'])) {
if ($metaconsole_on) {
//Restore db connection
metaconsole_restore_db();
}
continue;
}
//Get the sla_value in % and store it on $sla_value
$sla_value = reporting_get_agentmodule_sla(
$sla['id_agent_module'],
$content['period'],
$sla['sla_min'],
$sla['sla_max'],
$report["datetime"],
$content,
$content['time_from'],
$content['time_to']);
if ($metaconsole_on) {
//Restore db connection
metaconsole_restore_db();
}
//Do not show right modules if 'only_display_wrong' is active
if ($content['only_display_wrong'] == 1 &&
$sla_value >= $sla['sla_limit']) {
continue;
}
$sla_showed[] = $sla;
$sla_showed_values[] = $sla_value;
}
// SLA items sorted descending ()
if ($content['top_n'] == 2) {
arsort($sla_showed_values);
}
// SLA items sorted ascending
else if ($content['top_n'] == 1) {
asort($sla_showed_values);
}
}
$return['data'] = array();
$return['charts'] = null;
foreach ($sla_showed_values as $k => $sla_value) {
$sla = $sla_showed[$k];
$server_name = $sla ['server_name'];
//Metaconsole connection
if ($metaconsole_on && $server_name != '') {
$connection = metaconsole_get_connection($server_name);
if (metaconsole_connect($connection) != NOERR) {
continue;
}
}
$total_SLA += $sla_value;
if ($show_table) {
$data = array ();
$data['agent'] = modules_get_agentmodule_agent_name(
$sla['id_agent_module']);
$data['module'] = modules_get_agentmodule_name(
$sla['id_agent_module']);
switch ($config["dbtype"]) {
case "mysql":
case "postgresql":
$data['max'] = $sla['sla_max'];
$data['min'] = $sla['sla_min'];
$data['sla_limit'] = $sla['sla_limit'];
break;
case "oracle":
$data['max'] = oracle_format_float_to_php($sla['sla_max']);
$data['min'] = oracle_format_float_to_php($sla['sla_min']);
$data['sla_limit'] = oracle_format_float_to_php($sla['sla_limit']);
break;
}
$data['sla_value_unknown'] = 0;
$data['sla_status'] = 0;
$data['sla_value'] = 0;
if ($sla_value === false) {
$data['sla_value_unknown'] = 1;
}
else {
if ($sla_value >= $sla['sla_limit']) {
$data['sla_status'] = 1;
}
else {
$sla_failed = true;
$data['sla_status'] = 0;
}
// Print icon with status including edge
# Fix : 100% accurance is 'inside limits' although 10% was not overrun
// if (($sla_value == 100 && $sla_value >= $sla['sla_limit']) || ($sla_value > ($sla['sla_limit'] + $edge_interval))) {
// $data[6] = html_print_image('images/status_sets/default/severity_normal.png',true,array('title'=>__('Inside limits')));
// }
// elseif (($sla_value <= $sla['sla_limit'] + $edge_interval)
// && ($sla_value >= $sla['sla_limit'] - $edge_interval)) {
// $data[6] = html_print_image('images/status_sets/default/severity_warning.png',true,array('title'=>__('On the edge')));
// }
// else {
// $data[6] = html_print_image('images/status_sets/default/severity_critical.png',true,array('title'=>__('Out of limits')));
// }
$data['sla_value'] = $sla_value;
$data['sla_formated_value'] = format_numeric($sla_value, 2). "%";
}
$return['data'][] = $data;
}
// Slice graphs calculation
if ($show_graphs) {
$dataslice = array();
$dataslice['agent'] = modules_get_agentmodule_agent_name ($sla['id_agent_module']);
$dataslice['module'] = modules_get_agentmodule_name ($sla['id_agent_module']);
$dataslice['chart'] = graph_sla_slicebar(
$sla['id_agent_module'],
$content['period'],
$sla['sla_min'],
$sla['sla_max'],
$report['datetime'],
$content,
$content['time_from'],
$content['time_to'],
650,
25,
$urlImage,
$ttl,
false,
false);
$return['charts'][] = $dataslice;
}
if ($metaconsole_on) {
//Restore db connection
metaconsole_restore_db();
}
}
}
return reporting_check_structure_content($return);
}
function reporting_event_top_n($report, $content, $type = 'dinamic',
$force_width_chart = null, $force_height_chart = null) {
global $config;
$return['type'] = 'top_n';
if (empty($content['name'])) {
$content['name'] = __('Top N');
}
$return['title'] = $content['name'];
$top_n = $content['top_n'];
switch ($top_n) {
case REPORT_TOP_N_MAX:
$type_top_n = __('Max');
break;
case REPORT_TOP_N_MIN:
$type_top_n = __('Min');
break;
case REPORT_TOP_N_AVG:
default:
//If nothing is selected then it will be shown the average data
$type_top_n = __('Avg');
break;
}
$return['subtitle'] = __('Top %d' ,$content['top_n_value']) . ' - ' . $type_top_n;
$return["description"] = $content["description"];
$return["date"] = reporting_get_date_text($report, $content);
$order_uptodown = $content['order_uptodown'];
$top_n_value = $content['top_n_value'];
$show_graph = $content['show_graph'];
$return['top_n'] = $content['top_n_value'];
if (empty($content['subitems'])) {
//Get all the related data
$sql = sprintf("SELECT id_agent_module, server_name
FROM treport_content_item
WHERE id_report_content = %d", $content['id_rc']);
$tops = db_process_sql ($sql);
}
else {
$tops = $content['subitems'];
}
// Get chart
reporting_set_conf_charts($width, $height, $only_image, $type,
$content, $ttl);
if (!empty($force_width_chart)) {
$width = $force_width_chart;
}
if (!empty($force_height_chart)) {
$height = $force_height_chart;
}
if (empty($tops)) {
$return['failed'] = __('There are no Agent/Modules defined');
}
else {
$data_top = array();
foreach ($tops as $key => $row) {
//Metaconsole connection
$server_name = $row['server_name'];
if (($config ['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE')) {
$connection = metaconsole_get_connection($server_name);
if (metaconsole_load_external_db($connection) != NOERR) {
//ui_print_error_message ("Error connecting to ".$server_name);
continue;
}
}
$ag_name = modules_get_agentmodule_agent_name($row ['id_agent_module']);
$mod_name = modules_get_agentmodule_name ($row ['id_agent_module']);
$unit = db_get_value('unit', 'tagente_modulo',
'id_agente_modulo', $row ['id_agent_module']);
switch ($top_n) {
case REPORT_TOP_N_MAX:
$value = reporting_get_agentmodule_data_max ($row['id_agent_module'], $content['period']);
break;
case REPORT_TOP_N_MIN:
$value = reporting_get_agentmodule_data_min ($row['id_agent_module'], $content['period']);
break;
case REPORT_TOP_N_AVG:
default:
//If nothing is selected then it will be shown the average data
$value = reporting_get_agentmodule_data_average ($row['id_agent_module'], $content['period']);
break;
}
//If the returned value from modules_get_agentmodule_data_max/min/avg is false it won't be stored.
if ($value !== false) {
$data_top[$key] = $value;
$id_agent_module[$key] = $row['id_agent_module'];
$agent_name[$key] = $ag_name;
$module_name[$key] = $mod_name;
$units[$key] = $unit;
}
//Restore dbconnection
if (($config ['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE')) {
metaconsole_restore_db();
}
}
if (empty($data_top)) {
$return['failed'] = __('Insuficient data');
}
else {
$data_return = array();
//Order to show.
switch ($order_uptodown) {
//Descending
case 1:
array_multisort($data_top, SORT_DESC, $agent_name, SORT_ASC, $module_name, SORT_ASC, $id_agent_module, SORT_ASC, $units, SORT_ASC);
break;
//Ascending
case 2:
array_multisort($data_top, SORT_ASC, $agent_name, SORT_ASC, $module_name, SORT_ASC, $id_agent_module, SORT_ASC, $units, SORT_ASC);
break;
//By agent name or without selection
case 0:
case 3:
array_multisort($agent_name, SORT_ASC, $data_top, SORT_ASC, $module_name, SORT_ASC, $id_agent_module, SORT_ASC, $units, SORT_ASC);
break;
}
array_splice ($data_top, $top_n_value);
array_splice ($agent_name, $top_n_value);
array_splice ($module_name, $top_n_value);
array_splice ($id_agent_module, $top_n_value);
array_splice ($units, $top_n_value);
$data_top_values = array ();
$data_top_values['data_top'] = $data_top;
$data_top_values['agent_name'] = $agent_name;
$data_top_values['module_name'] = $module_name;
$data_top_values['id_agent_module'] = $id_agent_module;
$data_top_values['units'] = $units;
// Define truncate size depends the graph width
$truncate_size = $width / (4 * ($config['font_size']))-1;
if ($order_uptodown == 1 || $order_uptodown == 2) {
$i = 0;
$data_pie_graph = array();
$data_hbar = array();
foreach ($data_top as $dt) {
$item_name = '';
$item_name =
ui_print_truncate_text($agent_name[$i], $truncate_size, false, true, false, "...") .
' - ' .
ui_print_truncate_text($module_name[$i], $truncate_size, false, true, false, "...");
//Dirty hack, maybe I am going to apply a job in Apple
//https://www.imperialviolet.org/2014/02/22/applebug.html
$item_name_key_pie = $item_name;
$exist_key = true;
while ($exist_key) {
if (isset($data_pie_graph[$item_name_key_pie])) {
$item_name_key_pie .= ' ';
}
else {
$exist_key = false;
}
}
$item_name_key_hbar = $item_name;
$exist_key = true;
while ($exist_key) {
if (isset($data_hbar[$item_name_key_hbar])) {
$item_name_key_hbar = ' ' . $item_name_key_hbar;
}
else {
$exist_key = false;
}
}
$data_hbar[$item_name]['g'] = $dt;
$data_pie_graph[$item_name] = $dt;
if ($show_graph == 0 || $show_graph == 1) {
$data = array();
$data['agent'] = $agent_name[$i];
$data['module'] = $module_name[$i];
$data['value'] = $dt;
$data['formated_value'] = format_for_graph($dt,2) . " " . $units[$i];
$data_return[] = $data;
}
$i++;
if ($i >= $top_n_value) break;
}
}
else if ($order_uptodown == 0 || $order_uptodown == 3) {
$i = 0;
$data_pie_graph = array();
$data_hbar = array();
foreach ($agent_name as $an) {
$item_name = '';
$item_name =
ui_print_truncate_text($agent_name[$i],
$truncate_size, false, true, false, "...") .
' - ' .
ui_print_truncate_text($module_name[$i],
$truncate_size, false, true, false, "...");
//Dirty hack, maybe I am going to apply a job in Apple
//https://www.imperialviolet.org/2014/02/22/applebug.html
$item_name_key_pie = $item_name;
$exist_key = true;
while ($exist_key) {
if (isset($data_pie_graph[$item_name_key_pie])) {
$item_name_key_pie .= ' ';
}
else {
$exist_key = false;
}
}
$item_name_key_hbar = $item_name;
$exist_key = true;
while ($exist_key) {
if (isset($data_hbar[$item_name_key_hbar])) {
$item_name_key_hbar = ' ' . $item_name_key_hbar;
}
else {
$exist_key = false;
}
}
$data_pie_graph[$item_name] = $data_top[$i];
$data_hbar[$item_name]['g'] = $data_top[$i];
if ($show_graph == 0 || $show_graph == 1) {
$data = array();
$data['agent'] = $an;
$data['module'] = $module_name[$i];
$data['value'] = $data_top[$i];
$data['formated_value'] = format_for_graph($data_top[$i],2) . " " . $units[$i];
$data_return[] = $data;
}
$i++;
if ($i >= $top_n_value) break;
}
}
$return['charts']['bars'] = null;
$return['charts']['pie'] = null;
if ($show_graph != REPORT_TOP_N_ONLY_TABLE) {
$return['charts']['pie'] = pie3d_graph(false,
$data_pie_graph,
$width, $height,
__("other"),
ui_get_full_url(false, true, false, false) . '/',
ui_get_full_url(false, false, false, false) . "/images/logo_vertical_water.png",
$config['fontpath'],
$config['font_size'],
$ttl);
//Display bars graph
$return['charts']['bars'] = hbar_graph(
false,
$data_hbar,
$width,
count($data_hbar) * 50,
array(),
array(),
"",
"",
true,
ui_get_full_url(false, true, false, false) . '/',
$config['homedir'] . "/images/logo_vertical_water.png",
$config['fontpath'],
$config['font_size'],
true,
$ttl,
true);
}
$return['resume'] = null;
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;
$return['resume']['min']['value'] = $min;
$return['resume']['min']['formated_value'] = format_for_graph($min, 2);
$return['resume']['avg']['value'] = $avg;
$return['resume']['avg']['formated_value'] = format_for_graph($avg, 2);
$return['resume']['max']['value'] = $max;
$return['resume']['max']['formated_value'] = format_for_graph($max, 2);
}
$return['data'] = $data_return;
}
}
return reporting_check_structure_content($return);
}
function reporting_event_report_group($report, $content,
$type = 'dinamic', $force_width_chart = null,
$force_height_chart = null) {
global $config;
$return['type'] = 'event_report_group';
if (empty($content['name'])) {
$content['name'] = __('Event Report Group');
}
if ($config['metaconsole']) {
$id_meta = metaconsole_get_id_server($content["server_name"]);
$server = metaconsole_get_connection_by_id ($id_meta);
metaconsole_connect($server);
}
$return['title'] = $content['name'];
$return['subtitle'] = groups_get_name($content['id_group'], true);
if (!empty($content['style']['event_filter_search'])) {
$return['subtitle'] .= " (" . $content['style']['event_filter_search'] . ")";
}
$return["description"] = $content["description"];
$return["date"] = reporting_get_date_text($report, $content);
$filter_event_no_validated = $content['style']['filter_event_no_validated'];
$filter_event_validated = $content['style']['filter_event_validated'];
$filter_event_critical = $content['style']['filter_event_critical'];
$filter_event_warning = $content['style']['filter_event_warning'];
$filter_event_filter_search = $content['style']['event_filter_search'];
$event_graph_by_agent = $content['style']['event_graph_by_agent'];
$event_graph_by_user_validator = $content['style']['event_graph_by_user_validator'];
$event_graph_by_criticity = $content['style']['event_graph_by_criticity'];
$event_graph_validated_vs_unvalidated = $content['style']['event_graph_validated_vs_unvalidated'];
$data = reporting_get_group_detailed_event(
$content['id_group'], $content['period'], $report["datetime"],
true, true, $filter_event_validated, $filter_event_critical,
$filter_event_warning, $filter_event_no_validated,
$filter_event_filter_search, 'hash');
if (empty($data)) {
$return['failed'] = __('No events');
}
else {
$return['data'] = $data;
}
reporting_set_conf_charts($width, $height, $only_image, $type,
$content, $ttl);
if (!empty($force_width_chart)) {
$width = $force_width_chart;
}
if (!empty($force_height_chart)) {
$height = $force_height_chart;
}
$return['chart']['by_agent'] = null;
$return['chart']['by_user_validator'] = null;
$return['chart']['by_criticity'] = null;
$return['chart']['validated_vs_unvalidated'] = null;
if ($event_graph_by_agent) {
$data_graph = reporting_get_count_events_by_agent(
$content['id_group'], $content['period'],
$report["datetime"],
$filter_event_validated,
$filter_event_critical,
$filter_event_warning,
$filter_event_no_validated,
$filter_event_filter_search);
$return['chart']['by_agent']= pie3d_graph(
false,
$data_graph,
500,
150,
__("other"),
ui_get_full_url(false, false, false, false),
ui_get_full_url(false, false, false, false) . "/images/logo_vertical_water.png",
$config['fontpath'],
$config['font_size'],
$ttl);
}
if ($event_graph_by_user_validator) {
$data_graph =
reporting_get_count_events_validated_by_user(
array('id_group' => $content['id_group']), $content['period'],
$report["datetime"],
$filter_event_validated,
$filter_event_critical,
$filter_event_warning,
$filter_event_no_validated,
$filter_event_filter_search);
$return['chart']['by_user_validator'] = pie3d_graph(
false,
$data_graph,
500,
150,
__("other"),
ui_get_full_url(false, false, false, false),
ui_get_full_url(false, false, false, false) . "/images/logo_vertical_water.png",
$config['fontpath'],
$config['font_size'],
$ttl);
}
if ($event_graph_by_criticity) {
$data_graph = reporting_get_count_events_by_criticity(
array('id_group' => $content['id_group']), $content['period'],
$report["datetime"],
$filter_event_validated,
$filter_event_critical,
$filter_event_warning,
$filter_event_no_validated,
$filter_event_filter_search);
$colors = get_criticity_pie_colors($data_graph);
$return['chart']['by_criticity'] = pie3d_graph(
false,
$data_graph,
500,
150,
__("other"),
ui_get_full_url(false, false, false, false),
ui_get_full_url(false, false, false, false) . "/images/logo_vertical_water.png",
$config['fontpath'],
$config['font_size'],
$ttl,
false,
$colors);
}
if ($event_graph_validated_vs_unvalidated) {
$data_graph =
reporting_get_count_events_validated(
array('id_group' => $content['id_group']), $content['period'],
$report["datetime"],
$filter_event_validated,
$filter_event_critical,
$filter_event_warning,
$filter_event_no_validated,
$filter_event_filter_search);
$return['chart']['validated_vs_unvalidated'] = pie3d_graph(
false,
$data_graph,
500,
150,
__("other"),
ui_get_full_url(false, false, false, false),
ui_get_full_url(false, false, false, false) . "/images/logo_vertical_water.png",
$config['fontpath'],
$config['font_size'],
$ttl);
}
if ($config['metaconsole']) {
metaconsole_restore_db();
}
return reporting_check_structure_content($return);
}
function reporting_event_report_module($report, $content) {
global $config;
$return['type'] = 'event_report_module';
if (empty($content['name'])) {
$content['name'] = __('Event Report Module');
}
if ($config['metaconsole']) {
$id_meta = metaconsole_get_id_server($content["server_name"]);
$server = metaconsole_get_connection_by_id ($id_meta);
metaconsole_connect($server);
}
$return['title'] = $content['name'];
$return['subtitle'] = agents_get_name($content['id_agent']) .
" - " .
io_safe_output(
modules_get_agentmodule_name($content['id_agent_module']));
$return["description"] = $content["description"];
$return["date"] = reporting_get_date_text($report, $content);
$return['label'] = (isset($content['style']['label'])) ? $content['style']['label'] : '';
$data = reporting_get_module_detailed_event(
$content['id_agent_module'], $content['period'],
$report["datetime"], true, false, true);
if (empty($data)) {
$return['failed'] = __('No events');
}
else {
$return['data'] = $data;
}
if ($config['metaconsole']) {
metaconsole_restore_db();
}
return reporting_check_structure_content($return);
}
function reporting_inventory_changes($report, $content, $type) {
global $config;
$return['type'] = 'inventory_changes';
if (empty($content['name'])) {
$content['name'] = __('Inventory Changes');
}
if ($config['metaconsole']) {
$id_meta = metaconsole_get_id_server($content["server_name"]);
$server = metaconsole_get_connection_by_id ($id_meta);
metaconsole_connect($server);
}
$return['title'] = $content['name'];
$return['subtitle'] = agents_get_name($content['id_agent']);
$return["description"] = $content["description"];
$return["date"] = reporting_get_date_text($report, $content);
$es = json_decode($content['external_source'], true);
$id_agent = $es['id_agents'];
$module_name = $es['inventory_modules'];
switch ($type) {
case 'data':
$inventory_changes = inventory_get_changes(
$id_agent, $module_name,
$report["datetime"] - $content['period'],
$report["datetime"], "csv");
break;
default:
$inventory_changes = inventory_get_changes(
$id_agent, $module_name,
$report["datetime"] - $content['period'],
$report["datetime"], "array");
break;
}
$return['data'] = array();
if ($inventory_changes == ERR_NODATA) {
$return['failed'] = __('No changes found.');
}
else {
$return['data'] = $inventory_changes;
}
if ($config['metaconsole']) {
metaconsole_restore_db();
}
return reporting_check_structure_content($return);
}
function reporting_inventory($report, $content, $type) {
global $config;
$es = json_decode($content['external_source'], true);
$return['type'] = 'inventory';
if (empty($content['name'])) {
$content['name'] = __('Inventory');
}
if ($config['metaconsole']) {
$id_meta = metaconsole_get_id_server($content["server_name"]);
$server = metaconsole_get_connection_by_id ($id_meta);
metaconsole_connect($server);
}
$return['title'] = $content['name'];
$return["description"] = $content["description"];
$return["date"] = reporting_get_date_text($report, $content);
$es = json_decode($content['external_source'], true);
$id_agent = $es['id_agents'];
$module_name = $es['inventory_modules'];
if (empty($module_name)) {
$module_name = array(0 => 0);
}
$date = $es['date'];
$description = $content['description'];
switch ($type) {
case 'data':
$inventory_data = inventory_get_data(
(array)$id_agent, (array)$module_name, $date, '', false,
'csv');
break;
default:
$inventory_data = inventory_get_data(
(array)$id_agent, (array)$module_name, $date, '', false,
'hash');
break;
}
if ($inventory_data == ERR_NODATA) {
$return['failed'] = __('No data found.');
}
else {
$return['data'] = $inventory_data;
}
if ($config['metaconsole']) {
metaconsole_restore_db();
}
return reporting_check_structure_content($return);
}
function reporting_agent_module($report, $content) {
global $config;
$id_group = $content['id_group'];
$id_module_group = $content['id_module_group'];
$return['type'] = 'agent_module';
if (empty($content['name'])) {
$content['name'] = __('Agent/Modules');
}
$return['title'] = $content['name'];
$group_name = groups_get_name($content['id_group'], true);
if ($content['id_module_group'] == 0) {
$module_group_name = __('All');
}
else {
$module_group_name = db_get_value('name', 'tmodule_group',
'id_mg', $content['id_module_group']);
}
$return['subtitle'] = $group_name . " - " . $module_group_name;
$return["description"] = $content["description"];
$return["date"] = reporting_get_date_text($report, $content);
$return['label'] = (isset($content['style']['label'])) ? $content['style']['label'] : '';
$return["data"] = array();
$agents = array();
if ($id_group > 0) {
$agents = agents_get_group_agents($id_group);
$agents = array_keys($agents);
}
$filter_module_groups = false;
if ($id_module_group > 0) {
$filter_module_groups['id_module_group'] = $id_module_group;
}
$all_modules = agents_get_modules($agents, false,
$filter_module_groups, true, false);
$modules_by_name = array();
$name = '';
$cont = 0;
foreach ($all_modules as $key => $module) {
if ($module == $name) {
$modules_by_name[$cont - 1]['id'][] = $key;
}
else {
$name = $module;
$modules_by_name[$cont]['name'] = $name;
$modules_by_name[$cont]['id'][] = $key;
$cont ++;
}
}
$filter_groups = array();
if ($id_group > 0) {
$filter_groups['id_grupo'] = $id_group;
}
$agents = agents_get_agents ($filter_groups);
$nagents = count($agents);
if ($all_modules == false || $agents == false) {
$return['failed'] = __('There are no agents with modules');
}
else {
foreach ($agents as $agent) {
$row = array();
$row['agent_status'][$agent['id_agente']] =
agents_get_status($agent['id_agente']);
$row['agent_name'] = $agent['nombre'];
$agent_modules = agents_get_modules($agent['id_agente']);
$row['modules'] = array();
foreach ($modules_by_name as $module) {
$row['modules'][$module['name']] = null;
foreach ($module['id'] as $module_id) {
if (array_key_exists($module_id, $agent_modules)) {
$row['modules'][$module['name']] =
modules_get_agentmodule_status($module_id);
break;
}
}
}
$return['data'][] = $row;
}
}
if ($config['metaconsole']) {
metaconsole_restore_db();
}
return reporting_check_structure_content($return);
}
function reporting_exception($report, $content, $type = 'dinamic',
$force_width_chart = null, $force_height_chart = null) {
global $config;
$return['type'] = 'exception';
if (empty($content['name'])) {
$content['name'] = __('Exception');
}
$order_uptodown = $content['order_uptodown'];
$exception_condition_value = $content['exception_condition_value'];
$show_graph = $content['show_graph'];
$formated_exception_value = $exception_condition_value;
if (is_numeric($exception_condition_value)) {
$formated_exception_value = format_for_graph(
$exception_condition_value, 2);
}
$return['title'] = $content['name'];
$exception_condition = $content['exception_condition'];
switch ($exception_condition) {
case REPORT_EXCEPTION_CONDITION_EVERYTHING:
$return['subtitle'] = __('Exception - Everything');
$return['subtype'] = __('Everything');
break;
case REPORT_EXCEPTION_CONDITION_GE:
$return['subtitle'] =
sprintf(__('Exception - Modules over or equal to %s'),
$formated_exception_value);
$return['subtype'] = __('Modules over or equal to %s');
break;
case REPORT_EXCEPTION_CONDITION_LE:
$return['subtitle'] =
sprintf(__('Exception - Modules under or equal to %s'),
$formated_exception_value);
$return['subtype'] = __('Modules under or equal to %s');
break;
case REPORT_EXCEPTION_CONDITION_L:
$return['subtitle'] =
sprintf(__('Exception - Modules under %s'),
$formated_exception_value);
$return['subtype'] = __('Modules under %s');
break;
case REPORT_EXCEPTION_CONDITION_G:
$return['subtitle'] =
sprintf(__('Exception - Modules over %s'),
$formated_exception_value);
$return['subtype'] = __('Modules over %s');
break;
case REPORT_EXCEPTION_CONDITION_E:
$return['subtitle'] =
sprintf(__('Exception - Equal to %s'),
$formated_exception_value);
$return['subtype'] = __('Equal to %s');
break;
case REPORT_EXCEPTION_CONDITION_NE:
$return['subtitle'] =
sprintf(__('Exception - Not equal to %s'),
$formated_exception_value);
$return['subtype'] = __('Not equal to %s');
break;
case REPORT_EXCEPTION_CONDITION_OK:
$return['subtitle'] =
__('Exception - Modules at normal status');
$return['subtype'] = __('Modules at normal status');
break;
case REPORT_EXCEPTION_CONDITION_NOT_OK:
$return['subtitle'] =
__('Exception - Modules at critical or warning status');
$return['subtype'] = __('Modules at critical or warning status');
break;
}
$return["description"] = $content["description"];
$return["date"] = reporting_get_date_text($report, $content);
$return["data"] = array();
$return["chart"] = array();
$return["resume"] = array();
if (empty($content['subitems'])) {
//Get all the related data
$sql = sprintf("
SELECT id_agent_module, server_name, operation
FROM treport_content_item
WHERE id_report_content = %d", $content['id_rc']);
$exceptions = db_process_sql ($sql);
}
else {
$exceptions = $content['subitems'];
}
if ($exceptions === false) {
$return['failed'] = __('There are no Agent/Modules defined');
}
else {
//Get the very first not null value
$i = 0;
do {
//Metaconsole connection
$server_name = $exceptions[$i]['server_name'];
if (($config ['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE')) {
$connection = metaconsole_get_connection($server_name);
if (metaconsole_load_external_db($connection) != NOERR) {
//ui_print_error_message ("Error connecting to ".$server_name);
continue;
}
}
if ($content['period'] == 0) {
$min =
modules_get_last_value($exceptions[$i]['id_agent_module']);
}
else {
switch ($exceptions[$i]['operation']) {
case 'avg':
$min = reporting_get_agentmodule_data_average(
$exceptions[$i]['id_agent_module'], $content['period']);
break;
case 'max':
$min = reporting_get_agentmodule_data_max(
$exceptions[$i]['id_agent_module'], $content['period']);
break;
case 'min':
$min = reporting_get_agentmodule_data_min(
$exceptions[$i]['id_agent_module'], $content['period']);
break;
}
}
$i++;
//Restore dbconnection
if (($config ['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE')) {
metaconsole_restore_db();
}
}
while ($min === false && $i < count($exceptions));
$max = $min;
$avg = 0;
$i = 0;
foreach ($exceptions as $exc) {
//Metaconsole connection
$server_name = $exc['server_name'];
if (($config ['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE')) {
$connection = metaconsole_get_connection($server_name);
if (metaconsole_load_external_db($connection) != NOERR) {
//ui_print_error_message ("Error connecting to ".$server_name);
continue;
}
}
$ag_name = modules_get_agentmodule_agent_name ($exc ['id_agent_module']);
$mod_name = modules_get_agentmodule_name ($exc ['id_agent_module']);
$unit = db_get_value('unit', 'tagente_modulo',
'id_agente_modulo', $exc['id_agent_module']);
if ($content['period'] == 0) {
$value =
modules_get_last_value($exceptions[$i]['id_agent_module']);
}
else {
switch ($exc['operation']) {
case 'avg':
$value = reporting_get_agentmodule_data_average ($exc['id_agent_module'], $content['period']);
break;
case 'max':
$value = reporting_get_agentmodule_data_max ($exc['id_agent_module'], $content['period']);
break;
case 'min':
$value = reporting_get_agentmodule_data_min ($exc['id_agent_module'], $content['period']);
break;
}
}
if ($value !== false) {
if ($value > $max) $max = $value;
if ($value < $min) $min = $value;
$avg += $value;
//Skips
switch ($exception_condition) {
case REPORT_EXCEPTION_CONDITION_EVERYTHING:
break;
case REPORT_EXCEPTION_CONDITION_GE:
if ($value < $exception_condition_value) {
continue 2;
}
break;
case REPORT_EXCEPTION_CONDITION_LE:
if ($value > $exception_condition_value) {
continue 2;
}
break;
case REPORT_EXCEPTION_CONDITION_L:
if ($value > $exception_condition_value) {
continue 2;
}
break;
case REPORT_EXCEPTION_CONDITION_G:
if ($value < $exception_condition_value) {
continue 2;
}
break;
case REPORT_EXCEPTION_CONDITION_E:
if ($value != $exception_condition_value) {
continue 2;
}
break;
case REPORT_EXCEPTION_CONDITION_NE:
if ($value == $exception_condition_value) {
continue 2;
}
break;
case REPORT_EXCEPTION_CONDITION_OK:
if (modules_get_agentmodule_status($exc['id_agent_module']) != 0) {
continue 2;
}
break;
case REPORT_EXCEPTION_CONDITION_NOT_OK:
if (modules_get_agentmodule_status($exc['id_agent_module']) == 0) {
continue 2;
}
break;
}
$i++;
$data_exceptions[] = $value;
$id_agent_module[] = $exc['id_agent_module'];
$agent_name[] = $ag_name;
$module_name[] = $mod_name;
$units[] = $unit;
if ($exc['operation'] == 'avg') {
$operation[] = "rate";
}
else {
$operation[] = $exc['operation'];
}
}
//Restore dbconnection
if (($config ['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE')) {
metaconsole_restore_db();
}
}
if ($i == 0) {
switch ($exception_condition) {
case REPORT_EXCEPTION_CONDITION_EVERYTHING:
$return['failed'] = __('There are no Modules under those conditions.');
break;
case REPORT_EXCEPTION_CONDITION_GE:
$return['failed'] = __('There are no Modules over or equal to %s.', $exception_condition_value);
break;
case REPORT_EXCEPTION_CONDITION_LE:
$return['failed'] = __('There are no Modules less or equal to %s.', $exception_condition_value);
break;
case REPORT_EXCEPTION_CONDITION_L:
$return['failed'] = __('There are no Modules less %s.', $exception_condition_value);
break;
case REPORT_EXCEPTION_CONDITION_G:
$return['failed'] = __('There are no Modules over %s.', $exception_condition_value);
break;
case REPORT_EXCEPTION_CONDITION_E:
$return['failed'] = __('There are no Modules equal to %s', $exception_condition_value);
break;
case REPORT_EXCEPTION_CONDITION_NE:
$return['failed'] = __('There are no Modules not equal to %s', $exception_condition_value);
break;
case REPORT_EXCEPTION_CONDITION_OK:
$return['failed'] = __('There are no Modules normal status');
break;
case REPORT_EXCEPTION_CONDITION_NOT_OK:
$return['failed'] = __('There are no Modules at critial or warning status');
break;
}
}
else {
$avg = $avg / $i;
switch ($order_uptodown) {
//Order descending
case 1:
array_multisort($data_exceptions, SORT_DESC,
$agent_name, SORT_ASC, $module_name, SORT_ASC,
$id_agent_module, SORT_ASC);
break;
//Order ascending
case 2:
array_multisort($data_exceptions, SORT_ASC,
$agent_name, SORT_ASC, $module_name, SORT_ASC,
$id_agent_module, SORT_ASC);
break;
//Order by agent name or without selection
case 0:
case 3:
array_multisort($agent_name, SORT_ASC,
$data_exceptions, SORT_ASC, $module_name,
SORT_ASC, $id_agent_module, SORT_ASC);
break;
}
if ($order_uptodown == 1 || $order_uptodown == 2) {
$j = 0;
$data_pie_graph = array();
$data_hbar = array();
foreach ($data_exceptions as $dex) {
$data_hbar[$agent_name[$j]]['g'] = $dex;
$data_pie_graph[$agent_name[$j]] = $dex;
if ($show_graph == 0 || $show_graph == 1) {
$data = array();
$data['agent'] = $agent_name[$j];
$data['module'] = $module_name[$j];
$data['operation'] = __($operation[$j]);
$data['value'] = $dex;
$data['formated_value'] = format_for_graph($dex, 2) . " " . $units[$j];
$return['data'][] = $data;
}
$j++;
}
}
else if ($order_uptodown == 0 || $order_uptodown == 3) {
$j = 0;
$data_pie_graph = array();
$data_hbar = array();
foreach ($agent_name as $an) {
$data_hbar[$an]['g'] = $data_exceptions[$j];
$data_pie_graph[$an] = $data_exceptions[$j];
if ($show_graph == 0 || $show_graph == 1) {
$data = array();
$data['agent'] = $an;
$data['module'] = $module_name[$j];
$data['operation'] = __($operation[$j]);
$data['value'] = $data_exceptions[$j];
$data['formated_value'] = format_for_graph($data_exceptions[$j], 2) . " " . $units[$j];
$return['data'][] = $data;
}
$j++;
}
}
if ($show_graph == 1 || $show_graph == 2) {
reporting_set_conf_charts($width, $height, $only_image,
$type, $content, $ttl);
if (!empty($force_width_chart)) {
$width = $force_width_chart;
}
if (!empty($force_height_chart)) {
$height = $force_height_chart;
}
$return["chart"]["pie"] = pie3d_graph(
false,
$data_pie_graph,
600,
150,
__("other"),
ui_get_full_url(false, false, false, false),
ui_get_full_url(false, false, false, false) . "/images/logo_vertical_water.png",
$config['fontpath'],
$config['font_size'],
$ttl);
$params = array(
'flash_chart' => false,
'chart_data' => $data_hbar,
'width' => 600,
'height' => 25 * count($data_hbar),
'color' => array(),
'legend' => array(),
'long_index' => array(),
'no_data_image' => ui_get_full_url("images/image_problem.opaque.png", false, false, false),
'xaxisname' => "",
'yaxisname' => "",
'water_mark' => ui_get_full_url(false, false, false, false) . "/images/logo_vertical_water.png",
'font' => "",
'font_size' => "",
'unit' => "",
'ttl' => $ttl,
'homeurl' => ui_get_full_url(false, false, false, false),
'backgroundColor' => 'white'
);
$return["chart"]["hbar"] = call_user_func_array(
'hbar_graph',
$params);
}
if ($content['show_resume'] && $i > 0) {
$return["resume"]['min']['value'] = $min;
$return["resume"]['min']['formated_value'] = format_for_graph($min,2);
$return["resume"]['max']['value'] = $max;
$return["resume"]['max']['formated_value'] = format_for_graph($max,2);
$return["resume"]['avg']['value'] = $avg;
$return["resume"]['avg']['formated_value'] = format_for_graph($avg,2);
}
}
}
return reporting_check_structure_content($return);
}
function reporting_group_report($report, $content) {
global $config;
$metaconsole_on = ($config['metaconsole'] == 1) && defined('METACONSOLE');
$return['type'] = 'group_report';
if (empty($content['name'])) {
$content['name'] = __('Group Report');
}
if ($config['metaconsole']) {
$id_meta = metaconsole_get_id_server($content["server_name"]);
$server = metaconsole_get_connection_by_id ($id_meta);
metaconsole_connect($server);
}
$return['title'] = $content['name'];
$return['subtitle'] = groups_get_name($content['id_group'], true);
$return["description"] = $content["description"];
$return["date"] = reporting_get_date_text($report, $content);
$return["data"] = array();
$events = events_get_group_events(
$content['id_group'],
$content['period'],
$report['datetime'],
false,
false,
false,
false,
false,
$metaconsole_on);
if (empty($events)) {
$events = array();
}
$return["data"]["count_events"] = count($events);
$return["data"]["group_stats"] = reporting_get_group_stats($content['id_group']);
if ($config['metaconsole']) {
metaconsole_restore_db();
}
return reporting_check_structure_content($return);
}
function reporting_event_report_agent($report, $content,
$type = 'dinamic', $force_width_chart = null,
$force_height_chart = null) {
global $config;
$return['type'] = 'event_report_agent';
if (empty($content['name'])) {
$content['name'] = __('Event Report Agent');
}
$return['title'] = $content['name'];
$return['subtitle'] = agents_get_name($content['id_agent']);
$return["description"] = $content["description"];
$return["date"] = reporting_get_date_text($report, $content);
$return['label'] = (isset($content['style']['label'])) ? $content['style']['label'] : '';
$style = $content['style'];
$filter_event_no_validated = $style['filter_event_no_validated'];
$filter_event_validated = $style['filter_event_validated'];
$filter_event_critical = $style['filter_event_critical'];
$filter_event_warning = $style['filter_event_warning'];
$event_graph_by_user_validator = $style['event_graph_by_user_validator'];
$event_graph_by_criticity = $style['event_graph_by_criticity'];
$event_graph_validated_vs_unvalidated = $style['event_graph_validated_vs_unvalidated'];
$return['data'] = reporting_get_agents_detailed_event(
$content['id_agent'],
$content['period'],
$report["datetime"],
true,
$filter_event_validated,
$filter_event_critical,
$filter_event_warning,
$filter_event_no_validated,
true);
reporting_set_conf_charts($width, $height, $only_image, $type,
$content, $ttl);
if (!empty($force_width_chart)) {
$width = $force_width_chart;
}
if (!empty($force_height_chart)) {
$height = $force_height_chart;
}
$return["chart"]["by_user_validator"] = null;
$return["chart"]["by_criticity"] = null;
$return["chart"]["validated_vs_unvalidated"] = null;
if ($event_graph_by_user_validator) {
$data_chart =
reporting_get_count_events_validated_by_user(
array('id_agent' => $content['id_agent']),
$content['period'],
$report["datetime"],
$filter_event_validated,
$filter_event_critical,
$filter_event_warning,
$filter_event_no_validated);
$return["chart"]["by_user_validator"] = pie3d_graph(
false,
$data_chart,
500,
150,
__("other"),
ui_get_full_url(false, false, false, false),
ui_get_full_url(false, false, false, false) . "/images/logo_vertical_water.png",
$config['fontpath'],
$config['font_size'],
$ttl);
}
if ($event_graph_by_criticity) {
$data_graph = reporting_get_count_events_by_criticity(
array('id_agent' => $content['id_agent']), $content['period'],
$report["datetime"],
$filter_event_validated,
$filter_event_critical,
$filter_event_warning,
$filter_event_no_validated);
$colors = get_criticity_pie_colors($data_graph);
$return["chart"]["by_criticity"] = pie3d_graph(
false,
$data_graph,
500,
150,
__("other"),
ui_get_full_url(false, false, false, false),
ui_get_full_url(false, false, false, false) . "/images/logo_vertical_water.png",
$config['fontpath'],
$config['font_size'],
$ttl,
false,
$colors);
}
if ($event_graph_validated_vs_unvalidated) {
$data_graph = reporting_get_count_events_validated(
array('id_agent' => $content['id_agent']), $content['period'],
$report["datetime"],
$filter_event_validated,
$filter_event_critical,
$filter_event_warning,
$filter_event_no_validated);
$return["chart"]["validated_vs_unvalidated"] = pie3d_graph(
false,
$data_graph,
500,
150,
__("other"),
ui_get_full_url(false, false, false, false),
ui_get_full_url(false, false, false, false) . "/images/logo_vertical_water.png",
$config['fontpath'],
$config['font_size'],
$ttl);
}
if ($config['metaconsole']) {
metaconsole_restore_db();
}
return reporting_check_structure_content($return);
}
function reporting_historical_data($report, $content) {
global $config;
$return['type'] = 'historical_data';
$period = $content['period'];
$date_limit = time() - $period;
if (empty($content['name'])) {
$content['name'] = __('Historical data');
}
$return['title'] = $content['name'];
$return["description"] = $content["description"];
$return["date"] = reporting_get_date_text($report, $content);
$return['label'] = (isset($content['style']['label'])) ? $content['style']['label'] : '';
$return['keys'] = array(__('Date'), __('Data'));
$module_type = db_get_value_filter('id_tipo_modulo', 'tagente_modulo',
array('id_agente_modulo' => $content['id_agent_module']));
$result = array();
switch ($module_type) {
case 3:
case 17:
case 23:
case 33:
$result = db_get_all_rows_sql (
'SELECT *
FROM tagente_datos_string
WHERE id_agente_modulo =' . $content['id_agent_module'] . '
AND utimestamp >' . $date_limit . '
AND utimestamp <=' . time()
);
break;
default:
$result = db_get_all_rows_sql (
'SELECT *
FROM tagente_datos
WHERE id_agente_modulo =' . $content['id_agent_module'] . '
AND utimestamp >' . $date_limit . '
AND utimestamp <=' . time()
);
break;
}
$data = array();
foreach ($result as $row) {
$data[] = array(
__('Date') => date ($config["date_format"], $row['utimestamp']),
__('Data') => $row['datos']);
}
$return["data"] = $data;
return reporting_check_structure_content($return);
}
function reporting_database_serialized($report, $content) {
global $config;
$return['type'] = 'database_serialized';
if (empty($content['name'])) {
$content['name'] = __('Database Serialized');
}
$return['title'] = $content['name'];
$return["description"] = $content["description"];
$return["date"] = reporting_get_date_text($report, $content);
$return['label'] = (isset($content['style']['label'])) ? $content['style']['label'] : '';
$keys = array();
if ($content['header_definition'] != '') {
$keys = explode('|', $content['header_definition']);
}
$return['keys'] = $keys;
$module_name = io_safe_output(
modules_get_agentmodule_name($content['id_agent_module']));
$agent_name = io_safe_output(
modules_get_agentmodule_agent_name ($content['id_agent_module']));
$return['agent_name'] = $agent_name;
$return['module_name'] = $module_name;
$datelimit = $report["datetime"] - $content['period'];
$search_in_history_db = db_search_in_history_db($datelimit);
// This query gets information from the default and the historic database
$result = db_get_all_rows_sql('SELECT *
FROM tagente_datos
WHERE id_agente_modulo = ' . $content['id_agent_module'] . '
AND utimestamp > ' . $datelimit . '
AND utimestamp <= ' . $report["datetime"], $search_in_history_db);
// Adds string data if there is no numeric data
if ((count($result) < 0) or (!$result)) {
// This query gets information from the default and the historic database
$result = db_get_all_rows_sql('SELECT *
FROM tagente_datos_string
WHERE id_agente_modulo = ' . $content['id_agent_module'] . '
AND utimestamp > ' . $datelimit . '
AND utimestamp <= ' . $report["datetime"], $search_in_history_db);
}
if ($result === false) {
$result = array();
}
$data = array();
foreach ($result as $row) {
$date = date($config["date_format"], $row['utimestamp']);
$serialized_data = $row['datos'];
// Cut line by line
if (empty($content['line_separator']) ||
empty($serialized_data)) {
$rowsUnserialize = array($row['datos']);
}
else {
$rowsUnserialize = explode($content['line_separator'], $serialized_data);
}
foreach ($rowsUnserialize as $rowUnser) {
$row = array();
$row['date'] = $date;
$row['data'] = array();
if (empty($content['column_separator'])) {
if (empty($keys)) {
$row['data'][][] = $rowUnser;
}
else {
$row['data'][][$keys[0]] = $rowUnser;
}
}
else {
$columnsUnserialize = explode($content['column_separator'], $rowUnser);
$i = 0;
$temp_row = array();
foreach ($columnsUnserialize as $cell) {
if (isset($keys[$i])) {
$temp_row[$keys[$i]] = $cell;
}
else {
$temp_row[] = $cell;
}
$i++;
}
$row['data'][] = $temp_row;
}
$data[] = $row;
}
}
$return["data"] = $data;
return reporting_check_structure_content($return);
}
function reporting_group_configuration($report, $content) {
global $config;
$return['type'] = 'group_configuration';
if (empty($content['name'])) {
$content['name'] = __('Group configuration');
}
if ($config['metaconsole']) {
$id_meta = metaconsole_get_id_server($content["server_name"]);
$server = metaconsole_get_connection_by_id ($id_meta);
metaconsole_connect($server);
}
$group_name = groups_get_name($content['id_group'], true);
$return['title'] = $content['name'];
$return['subtitle'] = $group_name;
$return["description"] = $content["description"];
$return["date"] = reporting_get_date_text($report, $content);
$return['id_group'] = $content['id_group'];
if ($content['id_group'] == 0) {
switch ($config["dbtype"]) {
case "mysql":
case "postgresql":
$sql = "SELECT * FROM tagente;";
break;
case "oracle":
$sql = "SELECT * FROM tagente";
break;
}
}
else {
$sql = "
SELECT *
FROM tagente
WHERE id_grupo=" . $content['id_group'];
}
$agents_list = db_get_all_rows_sql($sql);
if ($agents_list === false)
$agents_list = array();
$return['data'] = array();
foreach ($agents_list as $agent) {
$content_agent = $content;
$content_agent['id_agent'] = $agent['id_agente'];
// Restore the connection to metaconsole
// because into the function reporting_agent_configuration
// connect to metaconsole.
if ($config['metaconsole']) {
metaconsole_restore_db();
}
$agent_report = reporting_agent_configuration(
$report, $content_agent);
$return['data'][] = $agent_report['data'];
}
if ($config['metaconsole']) {
metaconsole_restore_db();
}
return reporting_check_structure_content($return);
}
function reporting_network_interfaces_report($report, $content,
$type = 'dinamic', $force_width_chart = null, $force_height_chart = null) {
global $config;
$return['type'] = 'network_interfaces_report';
if (empty($content['name'])) {
$content['name'] = __('Network interfaces report');
}
$group_name = groups_get_name($content['id_group']);
$return['title'] = $content['name'];
$return['subtitle'] = $group_name;
$return["description"] = $content["description"];
$return["date"] = reporting_get_date_text($report, $content);
include_once($config['homedir'] . "/include/functions_custom_graphs.php");
$filter = array(
'id_grupo' => $content['id_group'],
'disabled' => 0);
$network_interfaces_by_agents = agents_get_network_interfaces(false, $filter);
if (empty($network_interfaces_by_agents)) {
$return['failed'] =
__('The group has no agents or none of the agents has any network interface');
$return['data'] = array();
}
else {
$return['failed'] = null;
$return['data'] = array();
foreach ($network_interfaces_by_agents as $agent_id => $agent) {
$row_data = array();
$row_data['agent'] = $agent['name'];
$row_data['interfaces'] = array();
foreach ($agent['interfaces'] as $interface_name => $interface) {
$row_interface = array();
$row_interface['name'] = $interface_name;
$row_interface['ip'] = $interface['ip'];
$row_interface['mac'] = $interface['mac'];
$row_interface['status'] = $interface['status_image'];
$row_interface['chart'] = null;
// Get chart
reporting_set_conf_charts($width, $height, $only_image,
$type, $content, $ttl);
if (!empty($force_width_chart)) {
$width = $force_width_chart;
}
if (!empty($force_height_chart)) {
$height = $force_height_chart;
}
switch ($type) {
case 'dinamic':
case 'static':
if (!empty($interface['traffic'])) {
$row_interface['chart'] = custom_graphs_print(0,
$height,
$width,
$content['period'],
null,
true,
$report["datetime"],
$only_image,
'white',
array_values($interface['traffic']),
$config['homeurl'],
array_keys($interface['traffic']),
array_fill(0, count($interface['traffic']), __("bytes/s")),
false,
true,
true,
true,
$ttl);
}
break;
case 'data':
break;
}
$row_data['interfaces'][] = $row_interface;
}
$return['data'][] = $row_data;
}
}
return reporting_check_structure_content($return);
}
function reporting_alert_report_group($report, $content) {
global $config;
$return['type'] = 'alert_report_group';
if (empty($content['name'])) {
$content['name'] = __('Alert Report Group');
}
if ($config['metaconsole']) {
$id_meta = metaconsole_get_id_server($content["server_name"]);
$server = metaconsole_get_connection_by_id ($id_meta);
metaconsole_connect($server);
}
$group_name = groups_get_name($content['id_group'], true);
$return['title'] = $content['name'];
$return['subtitle'] = $group_name;
$return["description"] = $content["description"];
$return["date"] = reporting_get_date_text($report, $content);
if ($content['id_group'] == 0) {
$alerts = db_get_all_rows_sql('
SELECT *
FROM talert_template_modules
WHERE disabled = 0
AND id_agent_module IN (
SELECT id_agente_modulo
FROM tagente_modulo)');
}
else {
$alerts = db_get_all_rows_sql('
SELECT *
FROM talert_template_modules
WHERE disabled = 0
AND id_agent_module IN (
SELECT id_agente_modulo
FROM tagente_modulo
WHERE id_agente IN (
SELECT id_agente
FROM tagente WHERE id_grupo = ' . $content['id_group'] . '))');
}
if (empty($alerts)) {
$alerts = array();
}
$data = array();
foreach ($alerts as $alert) {
$data_row = array();
$data_row['disabled'] = $alert['disabled'];
$data_row['agent'] = io_safe_output(agents_get_name(
agents_get_agent_id_by_module_id($alert['id_agent_module'])));
$data_row['module'] = db_get_value_filter('nombre', 'tagente_modulo',
array('id_agente_modulo' => $alert['id_agent_module']));
$data_row['template'] = db_get_value_filter('name', 'talert_templates',
array('id' => $alert['id_alert_template']));
$actions = alerts_get_alert_agent_module_actions ($alert['id']);
if (!empty($actions)) {
$row = db_get_row_sql('SELECT id_alert_action
FROM talert_templates
WHERE id IN (SELECT id_alert_template
FROM talert_template_modules
WHERE id = ' . $alert['id'] . ')');
$id_action = 0;
if (!empty($row))
$id_action = $row['id_alert_action'];
// Prevent from void action
if (empty($id_action))
$id_action = 0;
}
else {
$actions = db_get_all_rows_sql('SELECT name
FROM talert_actions
WHERE id = ' . $id_action);
}
$data_row['action'] = array();
foreach ($actions as $action) {
$data_row['action'][] = $action['name'];
}
$data_row['fired'] = array();
$firedTimes = get_module_alert_fired(
$alert['id_agent_module'],
$alert['id'],
(int) $content['period'],
(int) $report["datetime"]);
if (empty($firedTimes)) {
$firedTimes = array();
$firedTimes[0]['timestamp'] = '----------------------------';
}
foreach ($firedTimes as $fireTime) {
$data_row['fired'][] = $fireTime['timestamp'];
}
$data[] = $data_row;
}
$return['data'] = $data;
if ($config['metaconsole']) {
metaconsole_restore_db();
}
return reporting_check_structure_content($return);
}
function reporting_alert_report_agent($report, $content) {
global $config;
$return['type'] = 'alert_report_agent';
if (empty($content['name'])) {
$content['name'] = __('Alert Report Agent');
}
if ($config['metaconsole']) {
$id_meta = metaconsole_get_id_server($content["server_name"]);
$server = metaconsole_get_connection_by_id ($id_meta);
metaconsole_connect($server);
}
$agent_name = agents_get_name($content['id_agent']);
$return['title'] = $content['name'];
$return['subtitle'] = $agent_name;
$return["description"] = $content["description"];
$return["date"] = reporting_get_date_text($report, $content);
$return['label'] = (isset($content['style']['label'])) ? $content['style']['label'] : '';
$alerts = agents_get_alerts($content['id_agent']);
if (isset($alerts['simple'])) {
$alerts = $alerts['simple'];
}
else {
$alerts = array();
}
$data = array();
if (is_array($alerts) || is_object($alerts)) {
foreach ($alerts as $alert) {
$data_row = array();
$data_row['disabled'] = $alert['disabled'];
$data_row['module'] = db_get_value_filter('nombre', 'tagente_modulo',
array('id_agente_modulo' => $alert['id_agent_module']));
$data_row['template'] = db_get_value_filter('name', 'talert_templates',
array('id' => $alert['id_alert_template']));
$actions = alerts_get_alert_agent_module_actions ($alert['id']);
if (!empty($actions)) {
$row = db_get_row_sql('SELECT id_alert_action
FROM talert_templates
WHERE id IN (SELECT id_alert_template
FROM talert_template_modules
WHERE id = ' . $alert['id_alert_template'] . ')');
$id_action = 0;
if (!empty($row))
$id_action = $row['id_alert_action'];
// Prevent from void action
if (empty($id_action))
$id_action = 0;
}
else {
$actions = db_get_all_rows_sql('SELECT name
FROM talert_actions
WHERE id = ' . $id_action);
}
if (empty($actions)) {
$actions = array();
}
$data_row['action'] = array();
foreach ($actions as $action) {
$data_row['action'][] = $action['name'];
}
$data_row['fired'] = array();
$firedTimes = get_module_alert_fired(
$alert['id_agent_module'],
$alert['id'],
(int) $content['period'],
(int) $report["datetime"]);
if (empty($firedTimes)) {
$firedTimes = array();
$firedTimes[0]['timestamp'] = '----------------------------';
}
foreach ($firedTimes as $fireTime) {
$data_row['fired'][] = $fireTime['timestamp'];
}
$data[] = $data_row;
}
}
$return['data'] = $data;
if ($config['metaconsole']) {
metaconsole_restore_db();
}
return reporting_check_structure_content($return);
}
function reporting_alert_report_module($report, $content) {
global $config;
$return['type'] = 'alert_report_module';
if (empty($content['name'])) {
$content['name'] = __('Alert Report Module');
}
if ($config['metaconsole']) {
$id_meta = metaconsole_get_id_server($content["server_name"]);
$server = metaconsole_get_connection_by_id ($id_meta);
metaconsole_connect($server);
}
$module_name = io_safe_output(
modules_get_agentmodule_name($content['id_agent_module']));
$agent_name = io_safe_output(
modules_get_agentmodule_agent_name ($content['id_agent_module']));
$return['title'] = $content['name'];
$return['subtitle'] = $agent_name . " - " . $module_name;
$return["description"] = $content["description"];
$return["date"] = reporting_get_date_text($report, $content);
$return['label'] = (isset($content['style']['label'])) ? $content['style']['label'] : '';
switch ($config["dbtype"]) {
case "mysql":
case "postgresql":
$alerts = db_get_all_rows_sql('
SELECT *, t1.id as id_alert_template_module
FROM talert_template_modules t1
INNER JOIN talert_templates t2
ON t1.id_alert_template = t2.id
WHERE id_agent_module = ' . $content['id_agent_module']);
break;
case "oracle":
$alerts = db_get_all_rows_sql('
SELECT t1.*, t2.*, t1.id as id_alert_template_module
FROM talert_template_modules t1
INNER JOIN talert_templates t2
ON t1.id_alert_template = t2.id
WHERE id_agent_module = ' . $content['id_agent_module']);
break;
}
if ($alerts === false) {
$alerts = array();
}
$data = array();
foreach ($alerts as $alert) {
$data_row = array();
$data_row['disabled'] = $alert['disabled'];
$data_row['template'] = db_get_value_filter('name',
'talert_templates', array('id' => $alert['id_alert_template']));
$actions = alerts_get_alert_agent_module_actions ($alert['id_alert_template_module']);
if (!empty($actions)) {
$row = db_get_row_sql('SELECT id_alert_action
FROM talert_templates
WHERE id IN (SELECT id_alert_template
FROM talert_template_modules
WHERE id = ' . $alert['id_alert_template_module'] . ')');
$id_action = 0;
if (!empty($row))
$id_action = $row['id_alert_action'];
// Prevent from void action
if (empty($id_action))
$id_action = 0;
}
else {
$actions = db_get_all_rows_sql('SELECT name
FROM talert_actions
WHERE id = ' . $id_action);
}
$data_row['action'] = array();
foreach ($actions as $action) {
$data_row['action'][] = $action['name'];
}
$data_row['fired'] = array();
$firedTimes = get_module_alert_fired(
$content['id_agent_module'],
$alert['id_alert_template_module'],
(int) $content['period'],
(int) $report["datetime"]);
if (empty($firedTimes)) {
$firedTimes = array();
$firedTimes[0]['timestamp'] = '----------------------------';
}
foreach ($firedTimes as $fireTime) {
$data_row['fired'][] = $fireTime['timestamp'];
}
$data[] = $data_row;
}
$return['data'] = $data;
if ($config['metaconsole']) {
metaconsole_restore_db();
}
return reporting_check_structure_content($return);
}
function reporting_sql_graph($report, $content, $type,
$force_width_chart, $force_height_chart, $type_sql_graph) {
global $config;
switch ($type_sql_graph) {
case 'sql_graph_hbar':
$return['type'] = 'sql_graph_hbar';
break;
case 'sql_graph_vbar':
$return['type'] = 'sql_graph_vbar';
break;
case 'sql_graph_pie':
$return['type'] = 'sql_graph_pie';
break;
}
if (empty($content['name'])) {
switch ($type_sql_graph) {
case 'sql_graph_vbar':
$return['name'] = __('SQL Graph Vertical Bars');
break;
case 'sql_graph_hbar':
$return['name'] = __('SQL Graph Horizontal Bars');
break;
case 'sql_graph_pie':
$return['name'] = __('SQL Graph Pie');
break;
}
}
// Get chart
reporting_set_conf_charts($width, $height, $only_image, $type,
$content, $ttl);
if (!empty($force_width_chart)) {
$width = $force_width_chart;
}
if (!empty($force_height_chart)) {
$height = $force_height_chart;
}
$return['title'] = $content['name'];
$return["description"] = $content["description"];
$return["date"] = reporting_get_date_text();
switch ($type) {
case 'dinamic':
case 'static':
$return['chart'] = graph_custom_sql_graph(
$content["id_rc"],
$width,
$height,
$content["type"],
true,
ui_get_full_url(false, false, false, false),
$ttl);
break;
case 'data':
break;
}
return reporting_check_structure_content($return);
}
function reporting_monitor_report($report, $content) {
global $config;
$return['type'] = 'monitor_report';
if (empty($content['name'])) {
$content['name'] = __('Monitor Report');
}
$return['title'] = $content['name'];
$return["description"] = $content["description"];
$return["date"] = reporting_get_date_text($report, $content);
$return['label'] = (isset($content['style']['label'])) ? $content['style']['label'] : '';
if ($config['metaconsole']) {
$id_meta = metaconsole_get_id_server($content["server_name"]);
$server = metaconsole_get_connection_by_id ($id_meta);
metaconsole_connect($server);
}
$module = modules_get_agentmodule ($content['id_agent_module']);
$module_name = io_safe_output(
modules_get_agentmodule_name($content['id_agent_module']));
$agent_name = io_safe_output(
modules_get_agentmodule_agent_name ($content['id_agent_module']));
$return['agent_name'] = $agent_name;
$return['module_name'] = $module_name;
$value = reporting_get_agentmodule_monitor(
$content['id_agent_module'],
$content['period'],
$module['min_critical'],
$module['max_critical'],
$report["datetime"]);
if ($value === __('Unknown')) {
$return['data']['unknown'] = 1;
}
else {
$return['data']['unknown'] = 0;
$return["data"]["ok"]["value"] = $value;
$return["data"]["ok"]["formated_value"] = format_numeric($value, 2);
$return["data"]["fail"]["value"] = 100 - $return["data"]["ok"]["value"];
$return["data"]["fail"]["formated_value"] = (100 - $return["data"]["ok"]["formated_value"]);
}
if ($config['metaconsole']) {
metaconsole_restore_db();
}
return reporting_check_structure_content($return);
}
function reporting_netflow($report, $content, $type,
$force_width_chart, $force_height_chart, $type_netflow = null) {
global $config;
switch ($type_netflow) {
case 'netflow_area':
$return['type'] = 'netflow_area';
break;
case 'netflow_pie':
$return['type'] = 'netflow_pie';
break;
case 'netflow_data':
$return['type'] = 'netflow_data';
break;
case 'netflow_statistics':
$return['type'] = 'netflow_statistics';
break;
case 'netflow_summary':
$return['type'] = 'netflow_summary';
break;
}
if (empty($content['name'])) {
switch ($type_netflow) {
case 'netflow_area':
$return['name'] = __('Netflow Area');
break;
case 'netflow_pie':
$return['name'] = __('Netflow Pie');
break;
case 'netflow_data':
$return['name'] = __('Netflow Data');
break;
case 'netflow_statistics':
$return['name'] = __('Netflow Statistics');
break;
case 'netflow_summary':
$return['name'] = __('Netflow Summary');
break;
}
}
$return['title'] = $content['name'];
$return["description"] = $content["description"];
$return["date"] = reporting_get_date_text($report, $content);
// Get chart
reporting_set_conf_charts($width, $height, $only_image, $type,
$content, $ttl);
if (!empty($force_width_chart)) {
$width = $force_width_chart;
}
if (!empty($force_height_chart)) {
$height = $force_height_chart;
}
// Get item filters
$filter = db_get_row_sql("SELECT *
FROM tnetflow_filter
WHERE id_sg = '" . (int)$content['text'] . "'", false, true);
switch ($type) {
case 'dinamic':
case 'static':
$return['chart'] = netflow_draw_item (
$report['datetime'] - $content['period'],
$report['datetime'],
$content['top_n'],
$type_netflow,
$filter,
$content['top_n_value'],
$content ['server_name'],
'HTML');
break;
case 'data':
break;
}
return reporting_check_structure_content($return);
}
function reporting_simple_baseline_graph($report, $content,
$type = 'dinamic', $force_width_chart = null,
$force_height_chart = null) {
global $config;
if ($config['metaconsole']) {
$id_meta = metaconsole_get_id_server($content["server_name"]);
$server = metaconsole_get_connection_by_id ($id_meta);
metaconsole_connect($server);
}
$return['type'] = 'simple_baseline_graph';
if (empty($content['name'])) {
$content['name'] = __('Simple baseline graph');
}
$return['title'] = $content['name'];
$return["description"] = $content["description"];
$return["date"] = reporting_get_date_text($report, $content);
$return['label'] = (isset($content['style']['label'])) ? $content['style']['label'] : '';
// Get chart
reporting_set_conf_charts($width, $height, $only_image, $type,
$content, $ttl);
if (!empty($force_width_chart)) {
$width = $force_width_chart;
}
if (!empty($force_height_chart)) {
$height = $force_height_chart;
}
switch ($type) {
case 'dinamic':
case 'static':
$return['chart'] = grafico_modulo_sparse(
$content['id_agent_module'],
$content['period'],
false,
$width,
$height,
'',
'',
false,
true,
true,
$report["datetime"],
'',
true,
0,
true,
$only_image,
ui_get_full_url(false, false, false, false),
$ttl);
break;
case 'data':
break;
}
if ($config['metaconsole']) {
metaconsole_restore_db();
}
return reporting_check_structure_content($return);
}
function reporting_prediction_date($report, $content) {
global $config;
$return['type'] = 'prediction_date';
if (empty($content['name'])) {
$content['name'] = __('Prediction Date');
}
$return['title'] = $content['name'];
$return["description"] = $content["description"];
$return["date"] = reporting_get_date_text($report, $content);
$return['label'] = (isset($content['style']['label'])) ? $content['style']['label'] : '';
$module_name = io_safe_output(
modules_get_agentmodule_name($content['id_agent_module']));
$agent_name = io_safe_output(
modules_get_agentmodule_agent_name ($content['id_agent_module']));
$return['agent_name'] = $agent_name;
$return['module_name'] = $module_name;
set_time_limit(500);
$intervals_text = $content['text'];
$max_interval = substr($intervals_text, 0, strpos($intervals_text, ';'));
$min_interval = substr($intervals_text, strpos($intervals_text, ';') + 1);
$value = forecast_prediction_date ($content['id_agent_module'], $content['period'], $max_interval, $min_interval);
if ($value === false) {
$return["data"]['value'] = __('Unknown');
}
else {
$return["data"]['value'] = date ('d M Y H:i:s', $value);
}
return reporting_check_structure_content($return);
}
function reporting_projection_graph($report, $content,
$type = 'dinamic', $force_width_chart = null,
$force_height_chart = null) {
global $config;
if ($config['metaconsole']) {
$id_meta = metaconsole_get_id_server($content["server_name"]);
$server = metaconsole_get_connection_by_id ($id_meta);
metaconsole_connect($server);
}
$return['type'] = 'projection_graph';
if (empty($content['name'])) {
$content['name'] = __('Projection Graph');
}
$return['title'] = $content['name'];
$return["description"] = $content["description"];
$return["date"] = reporting_get_date_text($report, $content);
$return['label'] = (isset($content['style']['label'])) ? $content['style']['label'] : '';
$module_name = io_safe_output(
modules_get_agentmodule_name($content['id_agent_module']));
$agent_name = io_safe_output(
modules_get_agentmodule_agent_name ($content['id_agent_module']));
$return['agent_name'] = $agent_name;
$return['module_name'] = $module_name;
set_time_limit(500);
$output_projection = forecast_projection_graph(
$content['id_agent_module'], $content['period'], $content['top_n_value']);
// If projection doesn't have data then don't draw graph
if ($output_projection == NULL) {
$output_projection = false;
}
// Get chart
reporting_set_conf_charts($width, $height, $only_image, $type,
$content, $ttl);
if (!empty($force_width_chart)) {
$width = $force_width_chart;
}
if (!empty($force_height_chart)) {
$height = $force_height_chart;
}
switch ($type) {
case 'dinamic':
case 'static':
$return['chart'] = graphic_combined_module(
array($content['id_agent_module']),
array(),
$content['period'],
$width,
$height,
'Projection%20Sample%20Graph',
'',
0,
0,
0,
0,
$report["datetime"],
$only_image,
ui_get_full_url(false, false, false, false) . '/',
$ttl,
// Important parameter, this tell to graphic_combined_module function that is a projection graph
$output_projection,
$content['top_n_value']
);
break;
case 'data':
$return['data'] = forecast_projection_graph(
$content['id_agent_module'],
$content['period'],
$content['top_n_value'],
false, false, true);
break;
}
if ($config['metaconsole']) {
metaconsole_restore_db();
}
return reporting_check_structure_content($return);
}
function reporting_agent_configuration($report, $content) {
global $config;
$return['type'] = 'agent_configuration';
if (empty($content['name'])) {
$content['name'] = __('Agent configuration');
}
$return['title'] = $content['name'];
$return["description"] = $content["description"];
$return["date"] = reporting_get_date_text($report, $content);
$return['label'] = (isset($content['style']['label'])) ? $content['style']['label'] : '';
if ($config['metaconsole']) {
$id_meta = metaconsole_get_id_server($content["server_name"]);
$server = metaconsole_get_connection_by_id ($id_meta);
metaconsole_connect($server);
}
$sql = "
SELECT *
FROM tagente
WHERE id_agente=" . $content['id_agent'];
$agent_data = db_get_row_sql($sql);
$agent_configuration = array();
$agent_configuration['name'] = $agent_data['nombre'];
$agent_configuration['group'] = groups_get_name($agent_data['id_grupo']);
$agent_configuration['group_icon'] =
ui_print_group_icon ($agent_data['id_grupo'], true, '', '', false);
$agent_configuration['os'] = os_get_name($agent_data["id_os"]);
$agent_configuration['os_icon'] = ui_print_os_icon($agent_data["id_os"], true, true);
$agent_configuration['address'] = $agent_data['direccion'];
$agent_configuration['description'] = $agent_data['comentarios'];
$agent_configuration['enabled'] = (int)!$agent_data['disabled'];
$agent_configuration['group'] = $report["group"];
$modules = agents_get_modules ($content['id_agent']);
$agent_configuration['modules'] = array();
//Agent's modules
if (!empty($modules)) {
foreach ($modules as $id_agent_module => $module) {
$sql = "
SELECT *
FROM tagente_modulo
WHERE id_agente_modulo = $id_agent_module";
$module_db = db_get_row_sql($sql);
$data_module = array();
$data_module['name'] = $module_db['nombre'];
if ($module_db['disabled']) {
$data_module['name'] .= " (" . __('Disabled') . ")";
}
$data_module['type_icon'] =
ui_print_moduletype_icon($module_db['id_tipo_modulo'], true);
$data_module['type'] =
modules_get_type_name($module_db['id_tipo_modulo']);
$data_module['max_warning'] =
$module_db['max_warning'];
$data_module['min_warning'] =
$module_db['min_warning'];
$data_module['max_critical'] =
$module_db['max_critical'];
$data_module['min_critical'] =
$module_db['min_critical'];
$data_module['threshold'] = $module_db['module_ff_interval'];
$data_module['description'] = $module_db['descripcion'];
if (($module_db['module_interval'] == 0) ||
($module_db['module_interval'] == '')) {
$data_module['interval'] = db_get_value('intervalo',
'tagente', 'id_agente', $content['id_agent']);
}
else {
$data_module['interval'] = $module_db['module_interval'];
}
$data_module['unit'] = $module_db['unit'];
$module_status = db_get_row(
'tagente_estado', 'id_agente_modulo', $id_agent_module);
modules_get_status($id_agent_module,
$module_status['estado'],
$module_status['datos'], $status, $title);
$data_module['status_icon'] =
ui_print_status_image($status, $title, true);
$data_module['status'] = $title;
$sql_tag = "
SELECT name
FROM ttag
WHERE id_tag IN (
SELECT id_tag
FROM ttag_module
WHERE id_agente_modulo = $id_agent_module)";
$tags = db_get_all_rows_sql($sql_tag);
if ($tags === false)
$data_module['tags'] = array();
else {
foreach ($tags as $tag) {
$data_module['tags'][] = $tag['name'];
}
}
$agent_configuration['modules'][] = $data_module;
}
}
$return['data'] = $agent_configuration;
if ($config['metaconsole']) {
metaconsole_restore_db();
}
return reporting_check_structure_content($return);
}
function reporting_value($report, $content, $type) {
global $config;
$return = array();
switch ($type) {
case 'max':
$return['type'] = 'max_value';
break;
case 'min':
$return['type'] = 'min_value';
break;
case 'avg':
$return['type'] = 'avg_value';
break;
case 'sum':
$return['type'] = 'sumatory';
break;
case 'MTTR':
$return['type'] = 'MTTR';
break;
case 'MTBF':
$return['type'] = 'MTBF';
break;
case 'TTO':
$return['type'] = 'TTO';
break;
case 'TTRT':
$return['type'] = 'TTRT';
break;
}
if (empty($content['name'])) {
switch ($type) {
case 'max':
$content['name'] = __('Max. Value');
break;
case 'min':
$content['name'] = __('Min. Value');
break;
case 'avg':
$content['name'] = __('AVG. Value');
break;
case 'sum':
$content['name'] = __('Summatory');
break;
case 'MTTR':
$content['name'] = __('MTTR');
break;
case 'MTBF':
$content['name'] = __('MTBF');
break;
case 'TTO':
$content['name'] = __('TTO');
break;
case 'TTRT':
$return['type'] = __('TTRT');
break;
}
}
if ($config['metaconsole']) {
$id_meta = metaconsole_get_id_server($content["server_name"]);
$server = metaconsole_get_connection_by_id ($id_meta);
metaconsole_connect($server);
}
$module_name = io_safe_output(
modules_get_agentmodule_name($content['id_agent_module']));
$agent_name = io_safe_output(
modules_get_agentmodule_agent_name ($content['id_agent_module']));
$unit = db_get_value('unit', 'tagente_modulo', 'id_agente_modulo',
$content ['id_agent_module']);
$return['title'] = $content['name'];
$return['subtitle'] = $agent_name . " - " . $module_name;
$return["description"] = $content["description"];
$return["date"] = reporting_get_date_text($report, $content);
$return['label'] = (isset($content['style']['label'])) ? $content['style']['label'] : '';
$return['agent_name'] = $agent_name;
$return['module_name'] = $module_name;
switch ($type) {
case 'max':
$value = reporting_get_agentmodule_data_max(
$content['id_agent_module'], $content['period'], $report["datetime"]);
$formated_value = format_for_graph($value, 2) . " " . $unit;
break;
case 'min':
$value = reporting_get_agentmodule_data_min(
$content['id_agent_module'], $content['period'], $report["datetime"]);
$formated_value = format_for_graph($value, 2) . " " . $unit;
break;
case 'avg':
$value = reporting_get_agentmodule_data_average(
$content['id_agent_module'], $content['period'], $report["datetime"]);
$formated_value = format_for_graph($value, 2) . " " . $unit;
break;
case 'sum':
$value = reporting_get_agentmodule_data_sum(
$content['id_agent_module'], $content['period'], $report["datetime"]);
$formated_value = format_for_graph($value, 2) . " " . $unit;
break;
case 'MTTR':
$value = reporting_get_agentmodule_mttr(
$content['id_agent_module'], $content['period'], $report["datetime"]);
$formated_value = null;
break;
case 'MTBF':
$value = reporting_get_agentmodule_mtbf(
$content['id_agent_module'], $content['period'], $report["datetime"]);
$formated_value = null;
break;
case 'TTO':
$value = reporting_get_agentmodule_tto(
$content['id_agent_module'], $content['period'], $report["datetime"]);
if ($value == 0) {
$formated_value = null;
}
else {
$formated_value = human_time_description_raw ($value);
}
break;
case 'TTRT':
$value = reporting_get_agentmodule_ttr(
$content['id_agent_module'], $content['period'], $report["datetime"]);
if ($value == 0) {
$formated_value = null;
}
else {
$formated_value = human_time_description_raw ($value);
}
break;
}
$return['data'] = array(
'value' => $value,
'formated_value' => $formated_value);
if ($config['metaconsole']) {
metaconsole_restore_db();
}
return reporting_check_structure_content($return);
}
function reporting_url($report, $content, $type = 'dinamic') {
global $config;
$return = array();
$return['type'] = 'url';
if (empty($content['name'])) {
$content['name'] = __('Url');
}
$return['title'] = $content['name'];
$return["description"] = $content["description"];
$return["date"] = reporting_get_date_text();
$return["url"] = $content["external_source"];
switch ($type) {
case 'dinamic':
$return["data"] = null;
break;
case 'data':
case 'static':
$curlObj = curl_init();
curl_setopt($curlObj, CURLOPT_URL, $content['external_source']);
curl_setopt($curlObj, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($curlObj);
curl_close($curlObj);
$return["data"] = $output;
break;
}
return reporting_check_structure_content($return);
}
function reporting_text($report, $content) {
global $config;
$return = array();
$return['type'] = 'text';
if (empty($content['name'])) {
$content['name'] = __('Text');
}
$return['title'] = $content['name'];
$return["description"] = $content["description"];
$return["date"] = reporting_get_date_text();
$return["data"] = html_entity_decode($content['text']);
return reporting_check_structure_content($return);
}
function reporting_sql($report, $content) {
global $config;
$return = array();
$return['type'] = 'sql';
if (empty($content['name'])) {
$content['name'] = __('SQL');
}
$return['title'] = $content['name'];
$return["description"] = $content["description"];
$return["date"] = reporting_get_date_text();
if ($config['metaconsole']) {
$id_meta = metaconsole_get_id_server($content["server_name"]);
$server = metaconsole_get_connection_by_id ($id_meta);
metaconsole_connect($server);
}
if ($content['treport_custom_sql_id'] != 0) {
switch ($config["dbtype"]) {
case "mysql":
$sql = io_safe_output (db_get_value_filter('`sql`', 'treport_custom_sql', array('id' => $content['treport_custom_sql_id'])));
break;
case "postgresql":
$sql = io_safe_output (db_get_value_filter('"sql"', 'treport_custom_sql', array('id' => $content['treport_custom_sql_id'])));
break;
case "oracle":
$sql = io_safe_output (db_get_value_filter('sql', 'treport_custom_sql', array('id' => $content['treport_custom_sql_id'])));
break;
}
}
else {
$sql = io_safe_output ($content['external_source']);
}
// Do a security check on SQL coming from the user
$sql = check_sql ($sql);
$return['sql'] = $sql;
$return['correct'] = 1;
$return['error'] = "";
$return['data'] = array();
if ($sql != '') {
$header = array();
if ($content['header_definition'] != '') {
$header = explode('|', $content['header_definition']);
$return['header'] = $header;
}
$result = db_get_all_rows_sql($sql);
if ($result !== false) {
foreach ($result as $row) {
$data_row = array();
$i = 0;
foreach ($row as $dbkey => $field) {
if (isset($header[$i])) {
$key = $header[$i];
}
else {
$key = $dbkey;
}
$data_row[$key] = $field;
$i++;
}
$return['data'][] = $data_row;
}
}
}
else {
$return['correct'] = 0;
$return['error'] = __('Illegal query: Due security restrictions, there are some tokens or words you cannot use: *, delete, drop, alter, modify, union, password, pass, insert or update.');
}
if ($config['metaconsole']) {
metaconsole_restore_db();
}
return reporting_check_structure_content($return);
}
function reporting_availability($report, $content, $date=false, $time=false) {
global $config;
$return = array();
$return['type'] = 'availability';
$return['subtype'] = $content['group_by_agent'];
$return['resume'] = $content['show_resume'];
if (empty($content['name'])) {
$content['name'] = __('Availability');
}
if($date){
$datetime_to = strtotime ($date . ' ' . $time);
}
$return['title'] = $content['name'];
$return["description"] = $content["description"];
$return["date"] = reporting_get_date_text(
$report,
$content);
$return['id_rc'] = $content['id_rc'];
if ($content['show_graph']) {
$return['kind_availability'] = "address";
}
else {
$return['kind_availability'] = "module";
}
if (empty($content['subitems'])) {
$sql = sprintf("
SELECT id_agent_module,
server_name, operation
FROM treport_content_item
WHERE id_report_content = %d",
$content['id_rc']);
$items = db_process_sql ($sql);
}
else {
$items = $content['subitems'];
}
$data = array();
$avg = 0;
$min = null;
$min_text = "";
$max = null;
$max_text = "";
$count = 0;
$style = io_safe_output($content['style']);
if($style['hide_notinit_agents']){
$aux_id_agents = $agents;
$i=0;
foreach ($items as $item) {
$utimestamp = db_get_value('utimestamp', 'tagente_datos', 'id_agente_modulo', $item['id_agent_module']);
if (($utimestamp === false) || (intval($utimestamp) > intval($datetime_to))){
unset($items[$i]);
}
$i++;
}
}
if (!empty($items)) {
foreach ($items as $item) {
//aaMetaconsole connection
$server_name = $item ['server_name'];
if (($config ['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE')) {
$connection = metaconsole_get_connection($server_name);
if (metaconsole_load_external_db($connection) != NOERR) {
//ui_print_error_message ("Error connecting to ".$server_name);
continue;
}
}
if (modules_is_disable_agent($item['id_agent_module'])
|| modules_is_not_init($item['id_agent_module'])) {
//Restore dbconnection
if (($config ['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE')) {
metaconsole_restore_db();
}
continue;
}
$row = array();
$text = "";
// HACK it is saved in show_graph field.
// Show interfaces instead the modules
if ($content['show_graph']) {
$text = $row['availability_item'] = agents_get_address(
modules_get_agentmodule_agent($item['id_agent_module']));
if (empty($text)) {
$text = $row['availability_item'] = __('No Address');
}
}
else {
$text = $row['availability_item'] = modules_get_agentmodule_name(
$item['id_agent_module']);
}
$row['agent'] = modules_get_agentmodule_agent_name(
$item['id_agent_module']);
$text = $row['agent'] . " (" . $text . ")";
$sla_value = reporting_get_agentmodule_sla(
$item['id_agent_module'],
$content['period'],
0.50,
1.50,
$report["datetime"],
null,
$content['time_from'],
$content['time_to']);
$item['interval_agent_module'] = modules_get_interval ($item['id_agent_module']);
$unknown_seconds = modules_get_unknown_time ($item['id_agent_module'], $report["datetime"], $content['period']);
if ($unknown_seconds !== false) {
$count_checks = (int)(($content['period'] - $unknown_seconds)/$item['interval_agent_module']);
}
if ($sla_value === false) {
$row['checks'] = __('Unknown');
$row['failed'] = __('Unknown');
$row['fail'] = __('Unknown');
$row['poling_time'] = __('Unknown');
$row['time_unavaliable'] = __('Unknown');
$row['ok'] = __('Unknown');
$row['order'] = 0;
$percent_ok = 0;
}
else {
$percent_ok = $sla_value;
$percent_fail = (100 - $percent_ok);
$row['checks'] = format_numeric($count_checks, 0);
$row['ok'] = $percent_ok . " %";
$row['order'] = $percent_ok;
$row['fail'] = $percent_fail . " %";
//$row['failed'] = format_numeric($percent_fail * $count_checks / 100, 0);
//if the value of time in failures is less than those recorded in the database the number of errors that have registered in the database is set
$count_time_failed = ceil($percent_fail * $count_checks / 100);
$sql_count_failed = 'SELECT count(*) FROM tagente_datos WHERE datos = 0 AND id_agente_modulo =' . $item['id_agent_module'];
$count_failed = db_get_value_sql($sql_count_failed);
if($count_failed < $count_time_failed){
$row['failed'] = $count_time_failed;
} else {
$row['failed'] = $count_failed;
}
$row['poling_time'] = "-";
if ($percent_ok > 0) {
$row['poling_time'] =
human_time_description_raw(
($percent_ok * $count_checks / 100) * modules_get_interval($item['id_agent_module']),
true);
}
$row['time_unavaliable'] = "-";
if ($percent_fail > 0) {
$row['time_unavaliable'] =
human_time_description_raw(
($percent_fail * $count_checks / 100) * modules_get_interval($item['id_agent_module']),
true);
}
}
$data[] = $row;
$avg = (($avg * $count) + $percent_ok) / ($count + 1);
if (is_null($min)) {
$min = $percent_ok;
$min_text = $text;
}
else {
if ($min > $percent_ok) {
$min = $percent_ok;
$min_text = $text;
}
}
if (is_null($max)) {
$max = $percent_ok;
$max_text = $text;
}
else {
if ($max < $percent_ok) {
$max = $percent_ok;
$max_text = $text;
}
}
//Restore dbconnection
if (($config ['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE')) {
metaconsole_restore_db();
}
$count++;
}
switch ($content['order_uptodown']) {
case REPORT_ITEM_ORDER_BY_AGENT_NAME:
$temp = array();
foreach ($data as $row) {
$i = 0;
foreach ($temp as $t_row) {
if (strcmp($row['agent'], $t_row['agent']) < 0) {
break;
}
$i++;
}
array_splice($temp, $i, 0, array($row));
}
$data = $temp;
break;
case REPORT_ITEM_ORDER_BY_ASCENDING:
$temp = array();
foreach ($data as $row) {
$i = 0;
foreach ($temp as $t_row) {
if ($row['order'] < $t_row['order']) {
break;
}
$i++;
}
array_splice($temp, $i, 0, array($row));
}
$data = $temp;
break;
case REPORT_ITEM_ORDER_BY_DESCENDING:
$temp = array();
foreach ($data as $row) {
$i = 0;
foreach ($temp as $t_row) {
if ($row['order'] > $t_row['order']) {
break;
}
$i++;
}
array_splice($temp, $i, 0, array($row));
}
$data = $temp;
break;
}
}
$return["data"] = $data;
$return["resume"] = array();
$return["resume"]['min_text'] = $min_text;
$return["resume"]['min'] = $min;
$return["resume"]['avg'] = $avg;
$return["resume"]['max_text'] = $max_text;
$return["resume"]['max'] = $max;
return reporting_check_structure_content($return);
}
function reporting_general($report, $content) {
global $config;
$return = array();
$return['type'] = 'general';
$return['subtype'] = $content['group_by_agent'];
$return['resume'] = $content['show_resume'];
if (empty($content['name'])) {
$content['name'] = __('General');
}
$return['title'] = $content['name'];
$return["description"] = $content["description"];
$return["date"] = reporting_get_date_text(
$report,
$content);
$return["data"] = array();
$return["avg_value"] = 0;
$return["min"] = array();
$return["min"]["value"] = null;
$return["min"]["formated_value"] = null;
$return["min"]["agent"] = null;
$return["min"]["module"] = null;
$return["max"] = array();
$return["max"]["value"] = null;
$return["max"]["formated_value"] = null;
$return["max"]["agent"] = null;
$return["max"]["module"] = null;
if (empty($content['subitems'])) {
$generals = db_get_all_rows_filter(
'treport_content_item',
array('id_report_content' => $content['id_rc']));
}
else {
$generals = $content['subitems'];
}
if (empty($generals)) {
$generals = array();
}
$i = 0;
foreach ($generals as $key => $row) {
//Metaconsole connection
$server_name = $row ['server_name'];
if (($config ['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE')) {
$connection = metaconsole_get_connection($server_name);
if (metaconsole_load_external_db($connection) != NOERR) {
//ui_print_error_message ("Error connecting to ".$server_name);
continue;
}
}
if (modules_is_disable_agent($row['id_agent_module']) ||
modules_is_not_init($row['id_agent_module'])) {
if (is_metaconsole()) {
//Restore db connection
metaconsole_restore_db();
}
continue;
}
$mod_name = modules_get_agentmodule_name ($row['id_agent_module']);
$ag_name = modules_get_agentmodule_agent_name ($row['id_agent_module']);
$type_mod = modules_get_last_value($row['id_agent_module']);
$unit = db_get_value('unit', 'tagente_modulo',
'id_agente_modulo',
$row['id_agent_module']);
if ($content['period'] == 0) {
$data_res[$key] =
modules_get_last_value($row['id_agent_module']);
}
else {
if(is_numeric($type_mod)){
switch ($row['operation']) {
case 'sum':
$data_res[$key] =
reporting_get_agentmodule_data_sum(
$row['id_agent_module'], $content['period'], $report["datetime"]);
break;
case 'max':
$data_res[$key] =
reporting_get_agentmodule_data_max(
$row['id_agent_module'], $content['period']);
break;
case 'min':
$data_res[$key] =
reporting_get_agentmodule_data_min(
$row['id_agent_module'], $content['period']);
break;
case 'avg':
default:
$data_res[$key] =
reporting_get_agentmodule_data_average(
$row['id_agent_module'], $content['period']);
break;
}
} else {
$data_res[$key] = $type_mod;
}
}
switch ($content['group_by_agent']) {
case REPORT_GENERAL_NOT_GROUP_BY_AGENT:
$id_agent_module[$key] = $row['id_agent_module'];
$agent_name[$key] = $ag_name;
$module_name[$key] = $mod_name;
$units[$key] = $unit;
$operations[$key] = $row['operation'];
break;
case REPORT_GENERAL_GROUP_BY_AGENT:
if ($data_res[$key] === false) {
$return["data"][$ag_name][$mod_name] = null;
}
else {
if (!is_numeric($data_res[$key])) {
$return["data"][$ag_name][$mod_name] = $data_res[$key];
}
else {
$return["data"][$ag_name][$mod_name] =
format_for_graph($data_res[$key], 2) . " " . $unit;
}
}
break;
}
// Calculate the avg, min and max
if (is_numeric($data_res[$key])) {
$change_min = false;
if (is_null($return["min"]["value"])) {
$change_min = true;
}
else {
if ($return["min"]["value"] > $data_res[$key]) {
$change_min = true;
}
}
if ($change_min) {
$return["min"]["value"] = $data_res[$key];
$return["min"]["formated_value"] =
format_for_graph($data_res[$key], 2) . " " . $unit;
$return["min"]["agent"] = $ag_name;
$return["min"]["module"] = $mod_name;
}
$change_max = false;
if (is_null($return["max"]["value"])) {
$change_max = true;
}
else {
if ($return["max"]["value"] < $data_res[$key]) {
$change_max = true;
}
}
if ($change_max) {
$return["max"]["value"] = $data_res[$key];
$return["max"]["formated_value"] =
format_for_graph($data_res[$key], 2) . " " . $unit;
$return["max"]["agent"] = $ag_name;
$return["max"]["module"] = $mod_name;
}
if ($i == 0) {
$return["avg_value"] = $data_res[$key];
}
else {
$return["avg_value"] =
(($return["avg_value"] * $i) / ($i + 1))
+
($data_res[$key] / ($i + 1));
}
}
$i++;
//Restore dbconnection
if (($config ['metaconsole'] == 1) && $server_name != '' && defined('METACONSOLE')) {
metaconsole_restore_db();
}
}
switch ($content['group_by_agent']) {
case REPORT_GENERAL_NOT_GROUP_BY_AGENT:
switch ($content['order_uptodown']) {
case REPORT_ITEM_ORDER_BY_AGENT_NAME:
array_multisort($agent_name, SORT_ASC,
$data_res, SORT_ASC, $module_name, SORT_ASC,
$id_agent_module, SORT_ASC, $operations,
SORT_ASC);
break;
case REPORT_ITEM_ORDER_BY_ASCENDING:
array_multisort($data_res, SORT_ASC,
$agent_name, SORT_ASC, $module_name,
SORT_ASC, $id_agent_module,
SORT_ASC, $operations, SORT_ASC);
break;
case REPORT_ITEM_ORDER_BY_DESCENDING:
array_multisort($data_res, SORT_DESC,
$agent_name, SORT_ASC, $module_name,
SORT_ASC, $id_agent_module,
SORT_ASC, $operations, SORT_ASC);
break;
case REPORT_ITEM_ORDER_BY_UNSORT:
break;
}
$i = 0;
foreach ($data_res as $d) {
$data = array();
$data['agent'] = $agent_name[$i];
$data['module'] = $module_name[$i];
$data['operator'] = "";
if ($content['period'] != 0) {
switch ($operations[$i]) {
case 'sum':
$data['operator'] = __('Summatory');
break;
case 'min':
$data['operator'] = __('Minimal');
break;
case 'max':
$data['operator'] = __('Maximun');
break;
case 'avg':
default:
$data['operator'] = __('Rate');
break;
}
}
if ($d === false) {
$data['value'] = null;
}
else {
switch ($config["dbtype"]) {
case "mysql":
case "postgresql":
break;
case "oracle":
if (preg_match("/[0-9]+,[0-9]E+[+-][0-9]+/", $d)) {
$d = oracle_format_float_to_php($d);
}
break;
}
if (!is_numeric($d)) {
$data['value'] = $d;
// to see the chains on the table
$data['formated_value'] = $d;
}
else {
$data['value'] = $d;
$data['formated_value'] = format_for_graph($d, 2) . " " .
$units[$i];
}
}
$return["data"][] = $data;
$i++;
}
break;
}
return reporting_check_structure_content($return);
}
function reporting_custom_graph($report, $content, $type = 'dinamic',
$force_width_chart = null, $force_height_chart = null, $type_report = "custom_graph") {
global $config;
require_once ($config["homedir"] . '/include/functions_graph.php');
if ($type_report == 'automatic_graph') {
// Do none
}
else {
if ($config['metaconsole']) {
$id_meta = metaconsole_get_id_server($content["server_name"]);
$server = metaconsole_get_connection_by_id ($id_meta);
metaconsole_connect($server);
}
}
$graph = db_get_row ("tgraph", "id_graph", $content['id_gs']);
$return = array();
$return['type'] = 'custom_graph';
if (empty($content['name'])) {
$content['name'] = __('Simple graph');
}
$return['title'] = $content['name'];
$return['subtitle'] = $graph['name'];
$return["description"] = $content["description"];
$return["date"] = reporting_get_date_text(
$report,
$content);
$graphs = db_get_all_rows_field_filter ("tgraph_source",
"id_graph", $content['id_gs']);
$modules = array ();
$weights = array ();
if ($graphs === false)
$graphs = array();
$labels = array();
foreach ($graphs as $graph_item) {
if ($type_report == 'automatic_graph') {
array_push ($modules, array(
'module' => $graph_item['id_agent_module'],
'server' => $graph_item['id_server']));
}
else {
array_push ($modules, $graph_item['id_agent_module']);
}
array_push ($weights, $graph_item["weight"]);
if (in_array('label',$content['style'])) {
$item = array('type' => 'custom_graph',
'id_agent' =>modules_get_agentmodule_agent($graph_item['id_agent_module']),
'id_agent_module'=>$graph_item['id_agent_module']);
$label = reporting_label_macro($item, $content['style']['label']);
$labels[$graph_item['id_agent_module']] = $label;
}
}
$return['chart'] = '';
// Get chart
reporting_set_conf_charts($width, $height, $only_image, $type,
$content, $ttl);
$height += count($modules) * REPORTING_CUSTOM_GRAPH_LEGEND_EACH_MODULE_VERTICAL_SIZE;
switch ($type) {
case 'dinamic':
case 'static':
$return['chart'] = graphic_combined_module(
$modules,
$weights,
$content['period'],
$width, $height,
'',
'',
0,
0,
0,
$graph["stacked"],
$report["datetime"],
$only_image,
ui_get_full_url(false, false, false, false),
$ttl,
false,
false,
'white',
array(),
array(),
true,
true,
true,
true,
$labels);
break;
case 'data':
break;
}
if ($type_report == 'automatic_graph') {
// Do none
}
else {
if ($config['metaconsole']) {
metaconsole_restore_db();
}
}
return reporting_check_structure_content($return);
}
function reporting_simple_graph($report, $content, $type = 'dinamic',
$force_width_chart = null, $force_height_chart = null) {
global $config;
if ($config['metaconsole']) {
$id_meta = metaconsole_get_id_server($content["server_name"]);
$server = metaconsole_get_connection_by_id ($id_meta);
metaconsole_connect($server);
}
$return = array();
$return['type'] = 'simple_graph';
if (empty($content['name'])) {
$content['name'] = __('Simple graph');
}
$module_name = io_safe_output(
modules_get_agentmodule_name($content['id_agent_module']));
$agent_name = io_safe_output(
modules_get_agentmodule_agent_name ($content['id_agent_module']));
$return['title'] = $content['name'];
$return['subtitle'] = $agent_name . " - " . $module_name;
$return['agent_name'] = $agent_name;
$return['module_name'] = $module_name;
$return["description"] = $content["description"];
$return["date"] = reporting_get_date_text(
$report,
$content);
$label = (isset($content['style']['label'])) ? $content['style']['label'] : '';
if ($label != '') {
$label = reporting_label_macro($content, $label);
}
$only_avg = true;
// Due to database compatibility problems, the 'only_avg' value
// is stored into the json contained into the 'style' column.
if (isset($content['style']['only_avg'])) {
$only_avg = (bool) $content['style']['only_avg'];
}
$moduletype_name = modules_get_moduletype_name(
modules_get_agentmodule_type(
$content['id_agent_module']));
$return['chart'] = '';
// Get chart
reporting_set_conf_charts($width, $height, $only_image, $type,
$content, $ttl);
if (!empty($force_width_chart)) {
$width = $force_width_chart;
}
if (!empty($force_height_chart)) {
$height = $force_height_chart;
}
switch ($type) {
case 'dinamic':
case 'static':
if (preg_match ("/string/", $moduletype_name)) {
$urlImage = ui_get_full_url(false, false, false, false);
$return['chart'] = grafico_modulo_string(
$content['id_agent_module'],
$content['period'],
false,
$width,
$height,
'
' . $label,
'',
false,
$only_avg,
false,
$report["datetime"],
$only_image,
$urlImage,
"",
$ttl);
}
else {
// HACK it is saved in show_graph field.
$time_compare_overlapped = false;
if ($content['show_graph']) {
$time_compare_overlapped = 'overlapped';
}
$return['chart'] = grafico_modulo_sparse(
$content['id_agent_module'],
$content['period'],
false,
$width,
$height,
'
' . $label,
'',
false,
$only_avg,
true,
$report["datetime"],
'',
0,
0,
true,
$only_image,
ui_get_full_url(false, false, false, false),
$ttl,
false,
'',
$time_compare_overlapped,
true,
true,
'white',
($content['style']['percentil_95'] == 1) ? 95 : null);
}
break;
case 'data':
$data = modules_get_agentmodule_data(
$content['id_agent_module'],
$content['period'],
$report["datetime"]);
foreach ($data as $d) {
$return['chart'][$d['utimestamp']] = $d['data'];
}
break;
}
if ($config['metaconsole']) {
metaconsole_restore_db();
}
return reporting_check_structure_content($return);
}
function reporting_get_date_text($report = null, $content = null) {
global $config;
$return = array();
$return['date'] = null;
$return['period'] = null;
$return['from'] = null;
$return['to'] = null;
if (!empty($report) && !empty($content)) {
if ($content['period'] == 0) {
$es = json_decode($content['external_source'], true);
if ($es['date'] == 0) {
$return['period'] = 0;
}
else {
$return['date'] = $es['date'];
}
}
else {
$return['period'] = $content['period'];
$return['from'] = $report["datetime"] - $content['period'];
$return['to'] = $report["datetime"];
}
}
return $return;
}
/**
* Check the common items exits
*/
function reporting_check_structure_report($return) {
if (!isset($return['group_name']))
$return['group_name'] = "";
if (!isset($return['title']))
$return['title'] = "";
if (!isset($return['datetime']))
$return['datetime'] = "";
if (!isset($return['period']))
$return['period'] = "";
return $return;
}
/**
* Check the common items exits
*/
function reporting_check_structure_content($report) {
if (!isset($report['title']))
$report['title'] = "";
if (!isset($report['subtitle']))
$report['subtitle'] = "";
if (!isset($report['description']))
$report['description'] = "";
if (!isset($report["date"])) {
$report["date"]['date'] = "";
$report["date"]['period'] = "";
$report["date"]['from'] = "";
$report["date"]['to'] = "";
}
return $report;
}
function reporting_set_conf_charts(&$width, &$height, &$only_image, $type,
$content, &$ttl) {
switch ($type) {
case 'dinamic':
$only_image = false;
$width = 900;
$height = 230;
$ttl = 1;
break;
case 'static':
$ttl = 2;
$only_image = true;
if ($content['style']['show_in_landscape']) {
$height = 1100;
$width = 1700;
}
else {
$height = 360;
$width = 780;
}
break;
case 'data':
break;
}
}
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
// MAYBE MOVE THE NEXT FUNCTIONS TO A FILE NAMED AS FUNCTION_REPORTING.UTILS.PHP //
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
/**
* Gets a detailed reporting of groups's events.
*
* @param unknown_type $id_group Id of the group.
* @param unknown_type $period Time period of the report.
* @param unknown_type $date Date of the report.
* @param unknown_type $return Whether to return or not.
* @param unknown_type $html Whether to return HTML code or not.
*
* @return string Report of groups's events
*/
function reporting_get_count_events_validated ($filter, $period = 0,
$date = 0,
$filter_event_validated = false, $filter_event_critical = false,
$filter_event_warning = false, $filter_event_no_validated = false,
$filter_event_search = false) {
if (!is_numeric ($date)) {
$date = strtotime ($date);
}
if (empty ($date)) {
$date = get_system_time ();
}
return events_get_count_events_validated($filter, $period, $date,
$filter_event_validated, $filter_event_critical,
$filter_event_warning, $filter_event_no_validated,
$filter_event_search);
}
/**
* Gets a detailed reporting of groups's events.
*
* @param unknown_type $id_group Id of the group.
* @param unknown_type $period Time period of the report.
* @param unknown_type $date Date of the report.
* @param unknown_type $return Whether to return or not.
* @param unknown_type $html Whether to return HTML code or not.
*
* @return string Report of groups's events
*/
function reporting_get_count_events_by_criticity ($filter, $period = 0,
$date = 0,
$filter_event_validated = false, $filter_event_critical = false,
$filter_event_warning = false, $filter_event_no_validated = false,
$filter_event_search = false) {
if (!is_numeric ($date)) {
$date = strtotime ($date);
}
if (empty ($date)) {
$date = get_system_time ();
}
return events_get_count_events_by_criticity($filter, $period, $date,
$filter_event_validated, $filter_event_critical,
$filter_event_warning, $filter_event_no_validated,
$filter_event_search);
}
/**
* Gets a detailed reporting of groups's events.
*
* @param unknown_type $filter.
* @param unknown_type $period Time period of the report.
* @param unknown_type $date Date of the report.
* @param unknown_type $return Whether to return or not.
* @param unknown_type $html Whether to return HTML code or not.
*
* @return string Report of groups's events
*/
function reporting_get_count_events_validated_by_user ($filter, $period = 0,
$date = 0,
$filter_event_validated = false, $filter_event_critical = false,
$filter_event_warning = false, $filter_event_no_validated = false,
$filter_event_search = false) {
if (!is_numeric ($date)) {
$date = strtotime ($date);
}
if (empty ($date)) {
$date = get_system_time ();
}
return events_get_count_events_validated_by_user($filter, $period, $date,
$filter_event_validated, $filter_event_critical,
$filter_event_warning, $filter_event_no_validated, $filter_event_search);
}
/**
* Gets a detailed reporting of groups's events.
*
* @param unknown_type $id_group Id of the group.
* @param unknown_type $period Time period of the report.
* @param unknown_type $date Date of the report.
* @param unknown_type $return Whether to return or not.
* @param unknown_type $html Whether to return HTML code or not.
*
* @return string Report of groups's events
*/
function reporting_get_group_detailed_event ($id_group, $period = 0,
$date = 0, $return = false, $html = true,
$filter_event_validated = false, $filter_event_critical = false,
$filter_event_warning = false, $filter_event_no_validated = false,
$filter_event_filter_search = null, $return_type = false) {
global $config;
if (!is_numeric ($date)) {
$date = strtotime ($date);
}
if (empty ($date)) {
$date = get_system_time ();
}
$table = new stdClass();
$table->width = '99%';
$table->align = array();
$table->align[0] = 'center';
$table->align[2] = 'center';
$table->data = array ();
$table->head = array ();
$table->head[0] = __('Status');
$table->head[1] = __('Name');
$table->head[2] = __('Type');
$table->head[3] = __('Agent');
$table->head[4] = __('Severity');
$table->head[5] = __('Val. by');
$table->head[6] = __('Timestamp');
$events = events_get_group_events($id_group, $period, $date,
$filter_event_validated, $filter_event_critical,
$filter_event_warning, $filter_event_no_validated,
$filter_event_filter_search);
if ($return_type === 'hash') {
return $events;
}
if ($events) {
$note = '';
if (count($events) >= 1000) {
$note .= '* ' . __('Maximum of events shown') . ' (1000)
';
}
foreach ($events as $k => $event) {
//First pass along the class of this row
$table->cellclass[$k][1] = $table->cellclass[$k][3] =
$table->cellclass[$k][4] = $table->cellclass[$k][5] =
$table->cellclass[$k][6] =
get_priority_class ($event["criticity"]);
$data = array ();
// Colored box
switch ($event['estado']) {
case 0:
$img_st = "images/star.png";
$title_st = __('New event');
break;
case 1:
$img_st = "images/tick.png";
$title_st = __('Event validated');
break;
case 2:
$img_st = "images/hourglass.png";
$title_st = __('Event in process');
break;
}
$data[] = html_print_image ($img_st, true,
array ("class" => "image_status",
"width" => 16,
"title" => $title_st,
"id" => 'status_img_' . $event["id_evento"]));
$data[] = ui_print_truncate_text(
io_safe_output($event['evento']),
140, false, true);
//$data[1] = $event['event_type'];
$data[] = events_print_type_img ($event["event_type"], true);
if (!empty($event['id_agente']))
$data[] = agents_get_name($event['id_agente']);
else
$data[] = __('Pandora System');
$data[] = get_priority_name ($event['criticity']);
if (empty($event['id_usuario']) && $event['estado'] == EVENT_VALIDATE) {
$data[] = '' . __('System') . '';
}
else {
$user_name = db_get_value ('fullname', 'tusuario', 'id_user', $event['id_usuario']);
$data[] = io_safe_output($user_name);
}
$data[] = '' .
date($config['date_format'], $event['timestamp_rep']) .
'';
array_push ($table->data, $data);
}
if ($html) {
return html_print_table ($table, $return) . $note;
}
else {
return $table;
}
}
else {
return false;
}
}
/**
* Get a detailed report of summarized events per agent
*
* It construct a table object with all the grouped events happened in an agent
* during a period of time.
*
* @param mixed Module id to get the report from.
* @param int Period of time (in seconds) to get the report.
* @param int Beginning date (unixtime) of the report
* @param bool Flag to return or echo the report table (echo by default).
* @param bool Flag to return the html or table object, by default html.
*
* @return mixed A table object (XHTML) or object table is false the html.
*/
function reporting_get_module_detailed_event ($id_modules, $period = 0,
$date = 0, $return = false, $html = true, $only_data = false) {
global $config;
$id_modules = (array)safe_int ($id_modules, 1);
if (!is_numeric ($date)) {
$date = strtotime ($date);
}
if (empty ($date)) {
$date = get_system_time ();
}
$events = array ();
foreach ($id_modules as $id_module) {
$event = events_get_module ($id_module, (int) $period, (int) $date);
if (!empty ($event)) {
array_push ($events, $event);
}
}
if ($only_data) {
return $event;
}
if ($events) {
$note = '';
if (count($events) >= 1000) {
$note .= '* ' . __('Maximum of events shown') . ' (1000)
';
}
foreach ($events as $eventRow) {
foreach ($eventRow as $k => $event) {
//$k = count($table->data);
$table->cellclass[$k][1] = $table->cellclass[$k][2] =
$table->cellclass[$k][3] = $table->cellclass[$k][4] =
$table->cellclass[$k][5] = get_priority_class ($event["criticity"]);
$data = array ();
// Colored box
switch ($event['estado']) {
case 0:
$img_st = "images/star.png";
$title_st = __('New event');
break;
case 1:
$img_st = "images/tick.png";
$title_st = __('Event validated');
break;
case 2:
$img_st = "images/hourglass.png";
$title_st = __('Event in process');
break;
}
$data[0] = html_print_image ($img_st, true,
array ("class" => "image_status",
"width" => 16,
"title" => $title_st,
"id" => 'status_img_' . $event["id_evento"]));
$data[1] = io_safe_output($event['evento']);
$data[2] = $event['event_type'];
$data[3] = get_priority_name ($event['criticity']);
$data[4] = $event['event_rep'];
$data[5] = date($config['date_format'], $event['timestamp_rep']);
array_push ($table->data, $data);
}
}
if ($html) {
return html_print_table ($table, $return) . $note;
}
else {
return $table;
}
}
else {
return false;
}
}
/**
* Get a detailed report of summarized events per agent
*
* It construct a table object with all the grouped events happened in an agent
* during a period of time.
*
* @param mixed Agent id(s) to get the report from.
* @param int Period of time (in seconds) to get the report.
* @param int Beginning date (unixtime) of the report
* @param bool Flag to return or echo the report table (echo by default).
*
* @return A table object (XHTML)
*/
function reporting_get_agents_detailed_event ($id_agents, $period = 0,
$date = 0, $return = false, $filter_event_validated = false,
$filter_event_critical = false, $filter_event_warning = false,
$filter_event_no_validated = false, $only_data = false) {
global $config;
if ($only_data) {
$return_data = array();
}
$id_agents = (array)safe_int ($id_agents, 1);
if (!is_numeric ($date)) {
$date = strtotime ($date);
}
if (empty ($date)) {
$date = get_system_time ();
}
$events = array ();
foreach ($id_agents as $id_agent) {
$event = events_get_agent ($id_agent,
(int)$period,
(int)$date,
$filter_event_validated, $filter_event_critical,
$filter_event_warning, $filter_event_no_validated);
if (empty($event)) {
$event = array();
}
if ($only_data) {
foreach ($event as $e) {
$return_data[] = array(
'status' => $e['estado'],
'count' => $e['event_rep'],
'name' => $e['evento'],
'type' => $e["event_type"],
'criticity' => $e["criticity"],
'validated_by' => $e['id_usuario'],
'timestamp' => $e['timestamp_rep']
);
}
}
else {
if (!empty ($event)) {
array_push ($events, $event);
}
}
}
if ($only_data) {
return $return_data;
}
if ($events) {
$note = '';
if (count($events) >= 1000) {
$note .= '* ' . __('Maximum of events shown') . ' (1000)
';
}
foreach ($events as $eventRow) {
foreach ($eventRow as $k => $event) {
//First pass along the class of this row
$table->cellclass[$k][1] = $table->cellclass[$k][2] =
$table->cellclass[$k][4] = $table->cellclass[$k][5] =
$table->cellclass[$k][6] =
get_priority_class ($event["criticity"]);
$data = array ();
// Colored box
switch ($event['estado']) {
case 0:
$img_st = "images/star.png";
$title_st = __('New event');
break;
case 1:
$img_st = "images/tick.png";
$title_st = __('Event validated');
break;
case 2:
$img_st = "images/hourglass.png";
$title_st = __('Event in process');
break;
}
$data[] = html_print_image ($img_st, true,
array ("class" => "image_status",
"width" => 16,
"title" => $title_st));
$data[] = $event['event_rep'];
$data[] = ui_print_truncate_text(
io_safe_output($event['evento']),
140, false, true);
//$data[] = $event['event_type'];
$data[] = events_print_type_img ($event["event_type"], true);
$data[] = get_priority_name ($event['criticity']);
if (empty($event['id_usuario']) && $event['estado'] == EVENT_VALIDATE) {
$data[] = '' . __('System') . '';
}
else {
$user_name = db_get_value ('fullname', 'tusuario', 'id_user', $event['id_usuario']);
$data[] = io_safe_output($user_name);
}
$data[] = '' .
date($config['date_format'], $event['timestamp_rep']) . '';
array_push ($table->data, $data);
}
}
}
if ($events)
return html_print_table ($table, $return) . $note;
}
/**
* Get general statistical info on a group
*
* @param int Group Id to get info from. 0 = all
*
* @return array Group statistics
*/
function reporting_get_group_stats ($id_group = 0, $access = 'AR') {
global $config;
$data = array ();
$data["monitor_checks"] = 0;
$data["monitor_not_init"] = 0;
$data["monitor_unknown"] = 0;
$data["monitor_ok"] = 0;
$data["monitor_bad"] = 0; // Critical + Unknown + Warning
$data["monitor_warning"] = 0;
$data["monitor_critical"] = 0;
$data["monitor_not_normal"] = 0;
$data["monitor_alerts"] = 0;
$data["monitor_alerts_fired"] = 0;
$data["monitor_alerts_fire_count"] = 0;
$data["total_agents"] = 0;
$data["total_alerts"] = 0;
$data["total_checks"] = 0;
$data["alerts"] = 0;
$data["agents_unknown"] = 0;
$data["monitor_health"] = 100;
$data["alert_level"] = 100;
$data["module_sanity"] = 100;
$data["server_sanity"] = 100;
$data["total_not_init"] = 0;
$data["monitor_non_init"] = 0;
$data["agent_ok"] = 0;
$data["agent_warning"] = 0;
$data["agent_critical"] = 0;
$data["agent_unknown"] = 0;
$data["agent_not_init"] = 0;
$cur_time = get_system_time ();
//Check for access credentials using check_acl. More overhead, much safer
if (!check_acl ($config["id_user"], $id_group, $access)) {
return $data;
}
if ($id_group == 0) {
$id_group = array_keys(
users_get_groups($config['id_user'], $access, false));
}
// -----------------------------------------------------------------
// Server processed stats. NOT realtime (taken from tgroup_stat)
// -----------------------------------------------------------------
if ($config["realtimestats"] == 0) {
if (!is_array($id_group)) {
$my_group = $id_group;
$id_group = array();
$id_group[0] = $my_group;
}
foreach ($id_group as $group) {
$group_stat = db_get_all_rows_sql ("SELECT *
FROM tgroup_stat, tgrupo
WHERE tgrupo.id_grupo = tgroup_stat.id_group
AND tgroup_stat.id_group = $group
ORDER BY nombre");
$data["monitor_checks"] += $group_stat[0]["modules"];
$data["agent_not_init"] += $group_stat[0]["non-init"];
$data["agent_unknown"] += $group_stat[0]["unknown"];
$data["agent_ok"] += $group_stat[0]["normal"];
$data["agent_warning"] += $group_stat[0]["warning"];
$data["agent_critical"] += $group_stat[0]["critical"];
$data["monitor_alerts"] += $group_stat[0]["alerts"];
$data["monitor_alerts_fired"] += $group_stat[0]["alerts_fired"];
$data["monitor_alerts_fire_count"] += $group_stat[0]["alerts_fired"];
$data["total_checks"] += $group_stat[0]["modules"];
$data["total_alerts"] += $group_stat[0]["alerts"];
$data["total_agents"] += $group_stat[0]["agents"];
$data["agents_unknown"] += $group_stat[0]["agents_unknown"];
$data["utimestamp"] = $group_stat[0]["utimestamp"];
// This fields are not in database
$data["monitor_ok"] += (int) groups_get_normal_monitors($group);
$data["monitor_warning"] += (int) groups_get_warning_monitors($group);
$data["monitor_critical"] += (int) groups_get_critical_monitors($group);
$data["monitor_unknown"] += (int) groups_get_unknown_monitors($group);
$data["monitor_not_init"] += (int) groups_get_not_init_monitors($group);
}
// -------------------------------------------------------------------
// Realtime stats, done by PHP Console
// -------------------------------------------------------------------
}
else {
if (!is_array($id_group)) {
$my_group = $id_group;
$id_group = array();
$id_group[0] = $my_group;
}
// Store the groups where we are quering
$covered_groups = array();
$group_array = array();
foreach ($id_group as $group) {
$children = groups_get_childrens($group);
//Show empty groups only if they have children with agents
//$group_array = array();
foreach ($children as $sub) {
// If the group is quering previously, we ingore it
if (!in_array($sub['id_grupo'],$covered_groups)) {
array_push($covered_groups, $sub['id_grupo']);
array_push($group_array, $sub['id_grupo']);
}
}
// Add id of this group to create the clause
// If the group is quering previously, we ingore it
if (!in_array($group,$covered_groups)) {
array_push($covered_groups, $group);
array_push($group_array, $group);
}
// If there are not groups to query, we jump to nextone
if (empty($group_array)) {
continue;
}
}
if (!empty($group_array)) {
// FOR THE FUTURE: Split the groups into groups with tags restrictions and groups without it
// To calculate in the light way the non tag restricted and in the heavy way the others
/*
$group_restricted_data = tags_get_acl_tags($config['id_user'], $group_array, $access, 'data');
$tags_restricted_groups = array_keys($group_restricted_data);
$no_tags_restricted_groups = $group_array;
foreach ($no_tags_restricted_groups as $k => $v) {
if (in_array($v, $tags_restricted_groups)) {
unset($no_tags_restricted_groups[$k]);
}
}
*/
if (!empty($group_array)) {
// Get monitor NOT INIT, except disabled AND async modules
$data["monitor_not_init"] += (int) groups_get_not_init_monitors ($group_array, array(), array(), false, false, true);
// Get monitor OK, except disabled and non-init
$data["monitor_ok"] += (int) groups_get_normal_monitors ($group_array, array(), array(), false, false, true);
// Get monitor CRITICAL, except disabled and non-init
$data["monitor_critical"] += (int) groups_get_critical_monitors ($group_array, array(), array(), false, false, true);
// Get monitor WARNING, except disabled and non-init
$data["monitor_warning"] += (int) groups_get_warning_monitors ($group_array, array(), array(), false, false, true);
// Get monitor UNKNOWN, except disabled and non-init
$data["monitor_unknown"] += (int) groups_get_unknown_monitors ($group_array, array(), array(), false, false, true);
// Get alerts configured, except disabled
$data["monitor_alerts"] += groups_monitor_alerts ($group_array) ;
// Get alert configured currently FIRED, except disabled
$data["monitor_alerts_fired"] += groups_monitor_fired_alerts ($group_array);
// Calculate totals using partial counts from above
// Get TOTAL non-init modules, except disabled ones and async modules
$data["total_not_init"] += $data["monitor_not_init"];
// Get TOTAL agents in a group
$data["total_agents"] += (int) groups_get_total_agents ($group_array, array(), array(), false, false, true);
// Get Agents OK
$data["agent_ok"] += (int) groups_get_normal_agents ($group_array, array(), array(), false, false, true);
// Get Agents Warning
$data["agent_warning"] += (int) groups_get_warning_agents ($group_array, array(), array(), false, false, true);
// Get Agents Critical
$data["agent_critical"] += (int) groups_get_critical_agents ($group_array, array(), array(), false, false, true);
// Get Agents Unknown
$data["agent_unknown"] += (int) groups_get_unknown_agents ($group_array, array(), array(), false, false, true);
// Get Agents Not init
$data["agent_not_init"] += (int) groups_get_not_init_agents ($group_array, array(), array(), false, false, true);
}
// Get total count of monitors for this group, except disabled.
$data["monitor_checks"] = $data["monitor_not_init"] + $data["monitor_unknown"] + $data["monitor_warning"] + $data["monitor_critical"] + $data["monitor_ok"];
// Calculate not_normal monitors
$data["monitor_not_normal"] += $data["monitor_checks"] - $data["monitor_ok"];
}
// Get total count of monitors for this group, except disabled.
$data["monitor_checks"] = $data["monitor_not_init"] + $data["monitor_unknown"] + $data["monitor_warning"] + $data["monitor_critical"] + $data["monitor_ok"];
/*
Monitor health (percentage)
Data health (percentage)
Global health (percentage)
Module sanity (percentage)
Alert level (percentage)
Server Sanity 0% Uninitialized modules
*/
}
if ($data["monitor_unknown"] > 0 && $data["monitor_checks"] > 0) {
$data["monitor_health"] = format_numeric (100 - ($data["monitor_not_normal"] / ($data["monitor_checks"] / 100)), 1);
}
else {
$data["monitor_health"] = 100;
}
if ($data["monitor_not_init"] > 0 && $data["monitor_checks"] > 0) {
$data["module_sanity"] = format_numeric (100 - ($data["monitor_not_init"] / ($data["monitor_checks"] / 100)), 1);
}
else {
$data["module_sanity"] = 100;
}
if (isset($data["alerts"])) {
if ($data["monitor_alerts_fired"] > 0 && $data["alerts"] > 0) {
$data["alert_level"] = format_numeric (100 - ($data ["monitor_alerts_fired"] / ($data["alerts"] / 100)), 1);
}
else {
$data["alert_level"] = 100;
}
}
else {
$data["alert_level"] = 100;
$data["alerts"] = 0;
}
$data["monitor_bad"] = $data["monitor_critical"] + $data["monitor_warning"];
if ($data["monitor_bad"] > 0 && $data["monitor_checks"] > 0) {
$data["global_health"] = format_numeric (100 - ($data["monitor_bad"] / ($data["monitor_checks"] / 100)), 1);
}
else {
$data["global_health"] = 100;
}
$data["server_sanity"] = format_numeric (100 - $data["module_sanity"], 1);
$data['alert_fired'] = 0;
if ($data["monitor_alerts_fired"] > 0) {
$data['alert_fired'] = 1;
}
if ($data["monitor_critical"] > 0) {
$data['status'] = 'critical';
}
elseif ($data["monitor_warning"] > 0) {
$data['status'] = 'warning';
}
elseif (($data["monitor_unknown"] > 0) || ($data["agents_unknown"] > 0)) {
$data['status'] = 'unknown';
}
elseif ($data["monitor_ok"] > 0) {
$data['status'] = 'ok';
}
elseif ($data["agent_not_init"] > 0) {
$data['status'] = 'not_init';
}
else {
$data['status'] = 'none';
}
return ($data);
}
function reporting_get_stats_indicators($data, $width = 280, $height = 20, $html = true) {
$table_ind = html_get_predefined_table();
$servers = array();
$servers["all"] = (int) db_get_value ('COUNT(id_server)','tserver');
$servers["up"] = (int) servers_check_status ();
$servers["down"] = $servers["all"] - $servers["up"];
if ($servers["all"] == 0) {
$servers["health"] = 0;
}
else {
$servers["health"] = $servers["up"] / ($servers["all"] / 100);
}
if ($html) {
$tdata[0] = '