#11495 Fix service level detailed report

This commit is contained in:
miguel angel rasteu 2023-09-14 13:49:56 +02:00
parent 355de3b9bd
commit 5dcc2704cb
6 changed files with 337 additions and 29 deletions

View File

@ -117,6 +117,8 @@ $exception_condition = REPORT_EXCEPTION_CONDITION_EVERYTHING;
$exception_condition_value = 10;
$modulegroup = 0;
$period = SECONDS_1DAY;
$period_time_service_level = '28800';
$show_agents = false;
$search = '';
$full_text = 0;
$log_number = 1000;
@ -591,16 +593,6 @@ switch ($action) {
);
break;
case 'service_level':
$description = $item['description'];
$idAgentModule = $item['id_agent_module'];
$idAgent = db_get_value_filter(
'id_agente',
'tagente_modulo',
['id_agente_modulo' => $idAgentModule]
);
break;
case 'alert_report_module':
$description = $item['description'];
$idAgentModule = $item['id_agent_module'];
@ -882,6 +874,9 @@ switch ($action) {
case 'service_level':
$description = $item['description'];
$es = json_decode($item['external_source'], true);
$period_time_service_level = $es['period_time_service_level'];
$show_agents = $es['show_agents'];
// Decode agents and modules.
$id_agents = json_decode(
io_safe_output(base64_decode($es['id_agents'])),
@ -1493,6 +1488,53 @@ if (is_metaconsole() === true) {
</td>
</tr>
<tr id="row_period_service_level" class="datos">
<td class="bolder">
<?php
echo __('Time lapse');
ui_print_help_tip(
__('This is the range, or period of time over which the report renders the information for this report type. For example, a week means data from a week ago from now. ')
);
?>
</td>
<td >
<?php
$fields_time_service_level = [
'604800' => __('1 week'),
'172800' => __('48 hours'),
'86400' => __('24 hours'),
'43200' => __('12 hours'),
'28800' => __('8 hours'),
];
html_print_select(
$fields_time_service_level,
'period_time_service_level',
$period_time_service_level,
);
?>
</td>
</tr>
<tr id="row_show_agents" class="datos">
<td class="bolder" class="datos">
<?php
echo __('Show agents');
?>
</td>
<td >
<?php
html_print_checkbox_switch(
'show_agents',
'1',
$show_agents,
false,
false,
);
?>
</td>
</tr>
<tr id="row_period_range" class="datos">
<td class="bolder">
<?php
@ -6554,6 +6596,8 @@ function chooseType() {
$("#row_agent").hide();
$("#row_module").hide();
$("#row_period").hide();
$("#row_period_service_level").hide();
$("#row_show_agents").hide();
$("#row_search").hide();
$("#row_log_number").hide();
$("#row_period1").hide();
@ -6988,14 +7032,6 @@ function chooseType() {
$("#row_agent").show();
$("#row_module").show();
break;
case 'service_level':
$("#row_description").show();
$("#row_group").show();
$("#select_agent_modules").show();
$("#agents_modules_row").show();
$("#modules_row").show();
break;
case 'alert_report_module':
$("#row_description").show();
@ -7241,6 +7277,22 @@ function chooseType() {
}
$("#row_historical_db_check").hide();
break;
case 'service_level':
$("#row_period_service_level").show();
$("#row_show_agents").show();
$("#row_description").show();
$("#row_group").show();
$("#select_agent_modules").show();
$("#agents_modules_row").show();
$("#modules_row").show();
$("#row_historical_db_check").hide();
loadGeneralAgents();
$("#combo_group").change(function() {
loadGeneralAgents($(this).val());
});
$("#row_module_group").show();
break;
case 'agent_module':
$("#row_module_group").show();

View File

@ -1730,10 +1730,20 @@ switch ($action) {
$good_format = true;
break;
case 'service_level':
$es['period_time_service_level'] = get_parameter('period_time_service_level', '28800');
$es['show_agents'] = get_parameter('show_agents', false);
case 'agent_module':
case 'agent_module_status':
$agents_to_report_text = get_parameter('id_agents2-multiple-text', '');
if ($agents_to_report_text === '' || $agents_to_report_text === 'null') {
$agents_to_report_text = io_safe_input(json_encode(get_parameter('id_agents2', '')));
}
$modules_to_report_text = get_parameter('module-multiple-text', '');
if ($modules_to_report_text === '' || $modules_to_report_text === 'null') {
$modules_to_report_text = io_safe_input(json_encode(get_parameter('module', '')));
}
// Decode json check modules.
$agents_to_report = json_decode(
@ -1745,11 +1755,16 @@ switch ($action) {
true
);
$es['module'] = get_same_modules_all(
$agents_to_report,
$modules_to_report
);
if ((bool) is_metaconsole() === true) {
$es['module'] = $modules_to_report;
}
// Encode json modules and agents.
$es['module'] = base64_encode(json_encode($es['module']));
$es['id_agents'] = base64_encode(json_encode($agents_to_report));
@ -2673,10 +2688,20 @@ switch ($action) {
$good_format = true;
break;
case 'service_level':
$es['period_time_service_level'] = get_parameter('period_time_service_level', '28800');
$es['show_agents'] = get_parameter('show_agents', false);
case 'agent_module':
case 'agent_module_status':
$agents_to_report_text = get_parameter('id_agents2-multiple-text');
$agents_to_report_text = get_parameter('id_agents2-multiple-text', '');
if ($agents_to_report_text === '' || $agents_to_report_text === 'null') {
$agents_to_report_text = io_safe_input(json_encode(get_parameter('id_agents2', '')));
}
$modules_to_report_text = get_parameter('module-multiple-text', '');
if ($modules_to_report_text === '' || $modules_to_report_text === 'null') {
$modules_to_report_text = io_safe_input(json_encode(get_parameter('module', '')));
}
// Decode json check modules.
$agents_to_report = json_decode(
@ -2693,11 +2718,14 @@ switch ($action) {
$modules_to_report
);
if ((bool) is_metaconsole() === true) {
$es['module'] = $modules_to_report;
}
// Encode json modules and agents.
$es['module'] = base64_encode(json_encode($es['module']));
$es['id_agents'] = base64_encode(json_encode($agents_to_report));
$es['show_type'] = get_parameter('show_type', 0);
$values['external_source'] = json_encode($es);
$good_format = true;
break;

View File

@ -306,32 +306,48 @@ function format_for_graph(
}
function human_milliseconds_to_string($seconds)
function human_milliseconds_to_string($seconds, $size_text='large')
{
$ret = '';
// get the days
$days = intval(intval($seconds) / (360000 * 24));
if ($days > 0) {
$ret .= "$days days ";
if ($size_text === 'short') {
$ret .= str_replace(' ', '', "$days d").' ';
} else {
$ret .= "$days days ";
}
}
// get the hours
$hours = ((intval($seconds) / 360000) % 24);
if ($hours > 0) {
$ret .= "$hours hours ";
if ($size_text === 'short') {
$ret .= str_replace(' ', '', "$hours h").' ';
} else {
$ret .= "$hours hours ";
}
}
// get the minutes
$minutes = ((intval($seconds) / 6000) % 60);
if ($minutes > 0) {
$ret .= "$minutes minutes ";
if ($size_text === 'short') {
$ret .= str_replace(' ', '', "$minutes m").' ';
} else {
$ret .= "$minutes minutes ";
}
}
// get the seconds
$seconds = ((intval($seconds) / 100) % 60);
if ($seconds > 0) {
$ret .= "$seconds seconds";
if ($size_text === 'short') {
$ret .= str_replace(' ', '', "$seconds s").' ';
} else {
$ret .= "$seconds seconds ";
}
}
return $ret;

View File

@ -4782,10 +4782,29 @@ function service_level_module_data($datetime_from, $datetime_to, $id_agentmodule
$data['mtbf'] = false;
$data['mtrs'] = false;
$data['availability'] = false;
$data['critical_events'] = false;
$data['warning_events'] = false;
$data['last_status_change'] = false;
$data['module_name'] = false;
$availability = 0;
$type = '';
if ((bool) is_metaconsole() === true) {
if (enterprise_include_once('include/functions_metaconsole.php') !== ENTERPRISE_NOT_HOOK) {
$server_id = [];
$server_id['id'] = explode('|', $id_agentmodule)[0];
$id_agentmodule = explode('|', $id_agentmodule)[1];
$server_name = db_get_row_filter('tmetaconsole_setup', $server_id, 'server_name');
$connection = metaconsole_get_connection($server_name);
if (metaconsole_load_external_db($connection) !== NOERR) {
// Restore db connection.
metaconsole_restore_db();
return $data;
}
}
}
$uncompressed_data = db_uncompress_module_data(
$id_agentmodule,
$datetime_from,
@ -4815,6 +4834,24 @@ function service_level_module_data($datetime_from, $datetime_to, $id_agentmodule
ORDER BY utimestamp DESC';
$events_time = db_get_all_rows_sql($sql);
// Count events.
$sql = 'SELECT COUNT(*) as critical_events FROM tevento
WHERE id_agentmodule= '.$id_agentmodule.'
AND utimestamp >= '.$datetime_from.'
AND utimestamp <= '.$datetime_to.'
AND (event_type = "going_up_critical" OR event_type = "going_down_critical")';
$critical_events = db_get_sql($sql);
$sql = 'SELECT COUNT(*) as warning_events FROM tevento
WHERE id_agentmodule= '.$id_agentmodule.'
AND utimestamp >= '.$datetime_from.'
AND utimestamp <= '.$datetime_to.'
AND (event_type = "going_up_warning" OR event_type = "going_down_warning")';
$warning_events = db_get_sql($sql);
if ($events_time !== false && count($events_time) > 0) {
$failed_event = [];
$normal_event = [];
@ -4844,6 +4881,7 @@ function service_level_module_data($datetime_from, $datetime_to, $id_agentmodule
}
$mtbf_array = [];
if (!empty($failed_event) === true) {
if (count($failed_event) > 1) {
for ($i = 1; $i <= array_key_last($failed_event); $i++) {
@ -4866,9 +4904,8 @@ function service_level_module_data($datetime_from, $datetime_to, $id_agentmodule
$availability = round((($total_time_ok / $interval_time) * 100), 2);
}
// hd($availability, true);
if (count($mtbf_array) > 1) {
$mtbf = round(( $total_time_failed / count($mtbf_array)));
if ($critical_events > 1) {
$mtbf = round(( $total_time_failed / $critical_events));
} else {
$mtbf = false;
}
@ -4884,6 +4921,41 @@ function service_level_module_data($datetime_from, $datetime_to, $id_agentmodule
$data['mtbf'] = $mtbf;
$data['mtrs'] = $mtrs;
$data['availability'] = $availability;
} else {
$data['mtbf'] = false;
$data['mtrs'] = false;
$data['availability'] = false;
}
// Get last status change.
$sql = 'SELECT last_status_change FROM tagente_estado
WHERE id_agente_modulo = '.$id_agentmodule.' ';
$last_status_change = db_get_sql($sql);
// Get module name.
/*
$sql = 'SELECT nombre FROM tagente_modulo
WHERE id_agente_modulo = '.$id_agentmodule;*/
$sql = 'SELECT tagente_modulo.nombre as nombre, tagente.alias as alias
FROM tagente_modulo INNER JOIN tagente
ON tagente_modulo.id_agente = tagente.id_agente
WHERE id_agente_modulo = '.$id_agentmodule.' ';
$sql_query = db_get_all_rows_sql($sql);
$data['critical_events'] = $critical_events;
$data['warning_events'] = $warning_events;
$data['last_status_change'] = $last_status_change;
$data['module_name'] = $sql_query[0]['nombre'];
if ((bool) is_metaconsole() === true) {
$data['agent_alias'] = $server_name['server_name'].' » '.$sql_query[0]['alias'];
} else {
$data['agent_alias'] = $sql_query[0]['alias'];
}
if ((bool) is_metaconsole() === true) {
metaconsole_restore_db();
}
return $data;

View File

@ -778,6 +778,13 @@ function reporting_make_reporting_data(
);
break;
case 'service_level':
$report['contents'][] = reporting_service_level_detail(
$report,
$content
);
break;
case 'alert_report_actions':
$report['contents'][] = reporting_alert_report_actions(
$report,
@ -3567,6 +3574,60 @@ function reporting_agent_module_status($report, $content)
}
/**
* Service level detail
*
* @param array $report Info Report.
* @param array $content Info content.
*
* @return array
*/
function reporting_service_level_detail($report, $content)
{
global $config;
$return['type'] = 'service_level';
$module_data = [];
$interval_range = [];
$service_level_data = [];
$current_timestamp = time();
$return['title'] = io_safe_output($content['name']);
$return['landscape'] = $content['landscape'];
$return['pagebreak'] = $content['pagebreak'];
$return['description'] = io_safe_output($content['description']);
$return['label'] = (isset($content['style']['label'])) ? $content['style']['label'] : '';
$es = json_decode($content['external_source'], true);
$return['date'] = [];
$return['date']['date'] = false;
$return['date']['period'] = $es['period_time_service_level'];
$return['show_agents'] = $es['show_agents'];
$modules = json_decode(base64_decode($es['module']), true);
$agents = json_decode(base64_decode($es['id_agents']), true);
$interval_range['start'] = ($current_timestamp - $es['period_time_service_level']);
$interval_range['end'] = $current_timestamp;
foreach ($modules as $module) {
$service_level_data = service_level_module_data($interval_range['start'], $interval_range['end'], $module);
$module_data[$module] = [];
$module_data[$module]['mtrs'] = ($service_level_data['mtrs'] !== false) ? human_milliseconds_to_string(($service_level_data['mtrs'] * 100), 'short') : '-';
$module_data[$module]['mtbf'] = ($service_level_data['mtbf'] !== false) ? human_milliseconds_to_string(($service_level_data['mtbf'] * 100), 'short') : '-';
$module_data[$module]['availability'] = ($service_level_data['availability'] !== false) ? $service_level_data['availability'] : '100';
$module_data[$module]['warning_events'] = ($service_level_data['warning_events'] !== false) ? $service_level_data['warning_events'] : '0';
$module_data[$module]['critical_events'] = ($service_level_data['critical_events'] !== false) ? $service_level_data['critical_events'] : '0';
$module_data[$module]['last_status_change'] = ($service_level_data['last_status_change'] !== false) ? $service_level_data['last_status_change'] : '';
$module_data[$module]['module_name'] = ($service_level_data['module_name'] !== false) ? $service_level_data['module_name'] : '';
$module_data[$module]['agent_alias'] = ($service_level_data['agent_alias'] !== false) ? $service_level_data['agent_alias'] : '';
}
$return['data'] = $module_data;
return reporting_check_structure_content($return);
}
function reporting_exception(
$report,
$content,

View File

@ -260,7 +260,6 @@ function reporting_html_print_report($report, $mini=false, $report_info=1, $cust
}
$table->colspan['description_row']['description'] = 3;
switch ($item['type']) {
case 'availability':
default:
@ -403,6 +402,10 @@ function reporting_html_print_report($report, $mini=false, $report_info=1, $cust
reporting_html_agent_module_status($table, $item);
break;
case 'service_level':
reporting_html_service_level($table, $item);
break;
case 'alert_report_actions':
reporting_html_alert_report_actions($table, $item);
break;
@ -2452,6 +2455,82 @@ function reporting_html_agent_module_status($table, $item, $pdf=0)
}
function reporting_html_service_level($table, $item, $pdf=0)
{
global $config;
$return_pdf = '';
if (empty($item['data']) === true) {
if ($pdf !== 0) {
$return_pdf .= __('No items');
} else {
$table->colspan['group_report']['cell'] = 3;
$table->cellstyle['group_report']['cell'] = 'text-align: center;';
$table->data['group_report']['cell'] = __('No items');
}
} else {
$table_info = new stdClass();
$table_info->width = '99%';
if ($item['show_agents'] === '1') {
$show_agents = 'on';
} else {
$show_agents = 'off';
}
if ($show_agents === 'on') {
$table_info->head[0] = __('Agent / Module');
} else {
$table_info->head[0] = __('Module');
}
$table_info->head[1] = __('% Av.');
$table_info->head[2] = __('MTBF');
$table_info->head[3] = __('MTRS');
$table_info->head[4] = __('Crit. Events');
$table_info->head[5] = __('Warn. Events');
$table_info->head[6] = __('Last change');
$table_info->data = [];
$row = 0;
foreach ($item['data'] as $agentmodule_id => $module_data) {
if ($show_agents === 'on') {
$table_info->data[$row][0] = $module_data['agent_alias'].' / '.$module_data['module_name'];
} else {
$table_info->data[$row][0] = $module_data['module_name'];
}
$table_info->data[$row][1] = $module_data['availability'].'%';
$table_info->data[$row][2] = $module_data['mtbf'];
$table_info->data[$row][3] = $module_data['mtrs'];
$table_info->data[$row][4] = $module_data['critical_events'];
$table_info->data[$row][5] = $module_data['warning_events'];
if ($module_data['last_status_change'] !== '') {
$table_info->data[$row][6] = date(TIME_FORMAT, $module_data['last_status_change']);
}
// $table_info->data[$row][6] = date(TIME_FORMAT, $module_data['last_status_change']);
$row++;
}
if ($pdf !== 0) {
$table_info->title = $item['title'];
$table_info->titleclass = 'title_table_pdf';
$table_info->titlestyle = 'text-align:left;';
$return_pdf .= html_print_table($table_info, true);
} else {
$table->colspan['data']['cell'] = 3;
$table->cellstyle['data']['cell'] = 'text-align: center;';
$table->data['data']['cell'] = html_print_table($table_info, true);
}
}
if ($pdf !== 0) {
return $return_pdf;
}
}
/**
* Function to print to HTML Exception report.
*