Merge branch 'ent-11495-nuevo-tipo-de-informe-service-level-detailed' into 'develop'

Ent 11495 nuevo tipo de informe service level detailed

See merge request artica/pandorafms!6447
This commit is contained in:
Rafael Ameijeiras 2023-12-13 12:20:17 +00:00
commit e042c67d2a
8 changed files with 311 additions and 13 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;
@ -882,6 +884,28 @@ switch ($action) {
$idAgentModule = $module;
break;
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'])),
true
);
$module = json_decode(
io_safe_output(base64_decode($es['module'])),
true
);
$recursion = $item['recursion'];
$group = $item['id_group'];
$modulegroup = $item['id_module_group'];
$idAgentModule = $module;
break;
case 'end_of_life':
$es = json_decode($item['external_source'], true);
@ -1146,6 +1170,7 @@ switch ($action) {
case 'sumatory':
case 'database_serialized':
case 'last_value':
case 'service_level':
case 'monitor_report':
case 'min_value':
case 'max_value':
@ -1656,6 +1681,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
@ -2263,7 +2335,7 @@ if (is_metaconsole() === true) {
$modulegroup,
$id_agents,
!$selection_a_m,
false
true
);
}
@ -5862,8 +5934,13 @@ $(document).ready (function () {
switch (type){
case 'agent_module':
case 'agent_module_status':
case 'service_level':
case 'alert_report_actions':
var agents_multiple = $('#id_agents2').val();
if (agents_multiple.length == 0) {
dialog_message('#message_no_agent');
return false;
}
var modules_multiple = $('#module').val();
$('#hidden-id_agents2-multiple-text').val(JSON.stringify(agents_multiple));
$('#hidden-module-multiple-text').val(JSON.stringify(modules_multiple));
@ -5889,6 +5966,7 @@ $(document).ready (function () {
case 'agent_configuration':
case 'module_histogram_graph':
case 'increment':
case 'service_level':
if ($("#hidden-id_agent").val() == 0) {
dialog_message('#message_no_agent');
return false;
@ -6049,8 +6127,13 @@ $(document).ready (function () {
switch (type){
case 'agent_module':
case 'agent_module_status':
case 'service_level':
case 'alert_report_actions':
var agents_multiple = $('#id_agents2').val();
if (agents_multiple.length == 0) {
dialog_message('#message_no_agent');
return false;
}
var modules_multiple = $('#module').val();
$('#hidden-id_agents2-multiple-text').val(JSON.stringify(agents_multiple));
$('#hidden-module-multiple-text').val(JSON.stringify(modules_multiple));
@ -6076,6 +6159,7 @@ $(document).ready (function () {
case 'agent_configuration':
case 'module_histogram_graph':
case 'increment':
case 'service_level':
if ($("#hidden-id_agent").val() == 0) {
dialog_message('#message_no_agent');
return false;
@ -7071,6 +7155,9 @@ function chooseType() {
$("#row_agent").hide();
$("#row_module").hide();
$("#row_search").hide();
$("#row_period").hide();
$("#row_period_service_level").hide();
$("#row_show_agents").hide();
$("#row_log_number").hide();
$("#row_period1").hide();
$("#row_period2").hide();
@ -7767,6 +7854,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));
@ -2780,10 +2795,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(
@ -2800,11 +2825,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

@ -251,7 +251,7 @@ if ($change_custom_fields_macros_report === true) {
}
if ($get_agents === true) {
$agents_id = str_replace('&quot;', '', $agents_id);
$agents_id = str_replace('&quot;', '"', $agents_id);
try {
$agents_id = json_decode($agents_id, true);

View File

@ -3643,7 +3643,7 @@ function select_modules_for_agent_group(
if (!$selection && $agents != null) {
$number_agents = count($id_agents);
$selection_filter = "HAVING COUNT(id_agente_modulo) = $number_agents";
$selection_filter = "GROUP BY nombre HAVING COUNT(id_agente_modulo) = $number_agents";
}
if (tags_has_user_acl_tags(false)) {
@ -3664,7 +3664,7 @@ function select_modules_for_agent_group(
$sql = "SELECT * FROM
(
SELECT DISTINCT(tagente_modulo.id_agente_modulo), tagente_modulo.nombre
SELECT (tagente_modulo.id_agente_modulo), tagente_modulo.nombre, tagente.alias
FROM tagente_modulo
$sql_tags_inner
INNER JOIN tagente
@ -3679,7 +3679,7 @@ function select_modules_for_agent_group(
$filter_not_string_modules
$sql_conditions_tags
) x
GROUP BY nombre
$selection_filter";
$modules = db_get_all_rows_sql($sql);

View File

@ -3801,7 +3801,7 @@ function get_modules_agents(
$return = array_reduce(
$modules[$tserver],
function ($carry, $item) use ($tserver, $nodes) {
function ($carry, $item) use ($tserver, $nodes, $selection) {
$t = [];
foreach ($item as $k => $v) {
$t[$k] = $v;
@ -3809,9 +3809,15 @@ function get_modules_agents(
$t['id_node'] = $tserver;
if ($nodes[$tserver] !== null) {
$t['nombre'] = io_safe_output(
$nodes[$tserver]->server_name().' &raquo; '.$t['nombre']
);
if (isset($t['alias']) === true && (bool) $selection === true) {
$t['nombre'] = io_safe_output(
$nodes[$tserver]->server_name().' &raquo; '.$t['alias'].' &raquo; '.$t['nombre']
);
} else {
$t['nombre'] = io_safe_output(
$nodes[$tserver]->server_name().' &raquo; '.$t['nombre']
);
}
}
$carry[] = $t;
@ -3845,9 +3851,23 @@ function get_modules_agents(
$selection,
false,
$useName,
false,
true,
$notStringModules
);
$modules = array_reduce(
$modules,
function ($carry, $item) use ($id_agents, $selection) {
if (count($id_agents) > 1 && (bool) $selection === true) {
$carry[$item['id_agente_modulo']] = $item['alias'].' &raquo; '.$item['nombre'];
} else {
$carry[$item['id_agente_modulo']] = $item['nombre'];
}
return $carry;
},
[]
);
}
return $modules;

View File

@ -804,6 +804,13 @@ function reporting_make_reporting_data(
);
break;
case 'service_level':
$report['contents'][] = reporting_service_level_detail(
$report,
$content
);
break;
case 'end_of_life':
$report['contents'][] = reporting_end_of_life(
$report,
@ -3707,6 +3714,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);
}
/**
* OS Version End of Life
*

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 'end_of_life':
reporting_html_end_of_life($table, $item);
break;
@ -3080,6 +3083,85 @@ 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').ui_print_help_tip(__('Counted only critical events generated automatic by the module'), true);
$table_info->head[5] = __('Warn. Events').ui_print_help_tip(__('Counted only warning events generated automatic by the module'), true);
$table_info->head[6] = __('Last change');
$table_info->data = [];
$table_info->cellstyle = [];
$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'];
$table_info->cellstyle[$row][0] = 'text-align:left; padding-left: 30px;';
} else {
$table_info->data[$row][0] = $module_data['module_name'];
$table_info->cellstyle[$row][0] = 'text-align:left; padding-left: 30px;';
}
$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;
}
}
/**
* Html report end of life.
*

View File

@ -777,6 +777,10 @@ function reports_get_report_types($template=false, $not_editor=false)
'optgroup' => __('Modules'),
'name' => __('Last value'),
];
$types['service_level'] = [
'optgroup' => __('Modules'),
'name' => __('Service Level Detailed'),
];
$types['general'] = [
'optgroup' => __('Grouped'),