From 54ae7e57831c3746867424661b992a88d99e53c2 Mon Sep 17 00:00:00 2001 From: "alejandro.campos@artica.es" Date: Mon, 16 Aug 2021 09:43:11 +0200 Subject: [PATCH] modified availability report --- pandora_console/extras/mr/49.sql | 8 ++ .../pandoradb_migrate_6.0_to_7.0.mysql.sql | 4 + .../reporting_builder.item_editor.php | 24 ++++ .../godmode/reporting/reporting_builder.php | 22 ++++ .../include/functions_reporting.php | 122 ++++++++++++++++-- .../include/functions_reporting_html.php | 55 ++++++-- pandora_console/pandoradb.sql | 4 + 7 files changed, 219 insertions(+), 20 deletions(-) create mode 100644 pandora_console/extras/mr/49.sql diff --git a/pandora_console/extras/mr/49.sql b/pandora_console/extras/mr/49.sql new file mode 100644 index 0000000000..dd55beec74 --- /dev/null +++ b/pandora_console/extras/mr/49.sql @@ -0,0 +1,8 @@ +START TRANSACTION; + +ALTER TABLE `treport_content_template` ADD COLUMN `time_in_warning_status` TINYINT(1) DEFAULT '0'; +ALTER TABLE `treport_content_template` ADD COLUMN `checks_in_warning_status` TINYINT(1) DEFAULT '0'; +ALTER TABLE `treport_content` ADD COLUMN `time_in_warning_status` TINYINT(1) DEFAULT '0'; +ALTER TABLE `treport_content` ADD COLUMN `checks_in_warning_status` TINYINT(1) DEFAULT '0'; + +COMMIT; diff --git a/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql b/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql index ac6c127f62..d052e2709e 100644 --- a/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql +++ b/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql @@ -896,6 +896,8 @@ ALTER TABLE `treport_content_template` ADD COLUMN `landscape` tinyint(1) UNSIGNE ALTER TABLE `treport_content_template` ADD COLUMN `pagebreak` tinyint(1) UNSIGNED NOT NULL default 0; ALTER TABLE `treport_content_template` ADD COLUMN `compare_work_time` tinyint(1) UNSIGNED NOT NULL default 0; ALTER TABLE `treport_content_template` ADD COLUMN `graph_render` tinyint(1) UNSIGNED NOT NULL default 0; +ALTER TABLE `treport_content_template` ADD COLUMN `time_in_warning_status` TINYINT(1) DEFAULT '0'; +ALTER TABLE `treport_content_template` ADD COLUMN `checks_in_warning_status` TINYINT(1) DEFAULT '0'; -- ---------------------------------------------------------------------- -- Table `tnews` @@ -1773,6 +1775,8 @@ ALTER TABLE `treport_content` ADD COLUMN `pagebreak` tinyint(1) UNSIGNED NOT NUL ALTER TABLE `treport_content` ADD COLUMN `compare_work_time` tinyint(1) UNSIGNED NOT NULL default 0; ALTER TABLE `treport_content` ADD COLUMN `graph_render` tinyint(1) UNSIGNED NOT NULL default 0; ALTER TABLE `treport_content` MODIFY `external_source` MEDIUMTEXT; +ALTER TABLE `treport_content` ADD COLUMN `time_in_warning_status` TINYINT(1) DEFAULT '0'; +ALTER TABLE `treport_content` ADD COLUMN `checks_in_warning_status` TINYINT(1) DEFAULT '0'; -- --------------------------------------------------------------------- -- Table `tmodule_relationship` diff --git a/pandora_console/godmode/reporting/reporting_builder.item_editor.php b/pandora_console/godmode/reporting/reporting_builder.item_editor.php index bffe894931..f96ad82589 100755 --- a/pandora_console/godmode/reporting/reporting_builder.item_editor.php +++ b/pandora_console/godmode/reporting/reporting_builder.item_editor.php @@ -162,12 +162,14 @@ $filter_exclude = ''; $total_time = true; $time_failed = true; $time_in_ok_status = true; +$time_in_warning_status = false; $time_in_unknown_status = true; $time_of_not_initialized_module = true; $time_of_downtime = true; $total_checks = true; $checks_failed = true; $checks_in_ok_status = true; +$checks_in_warning_status = true; $unknown_checks = true; $agent_max_value = true; $agent_min_value = true; @@ -673,12 +675,14 @@ switch ($action) { $total_time = $item['total_time']; $time_failed = $item['time_failed']; $time_in_ok_status = $item['time_in_ok_status']; + $time_in_warning_status = $item['time_in_warning_status']; $time_in_unknown_status = $item['time_in_unknown_status']; $time_of_not_initialized_module = $item['time_of_not_initialized_module']; $time_of_downtime = $item['time_of_downtime']; $total_checks = $item['total_checks']; $checks_failed = $item['checks_failed']; $checks_in_ok_status = $item['checks_in_ok_status']; + $checks_in_warning_status = $item['checks_in_warning_status']; $unknown_checks = $item['unknown_checks']; $agent_max_value = $item['agent_max_value']; $agent_min_value = $item['agent_min_value']; @@ -2309,6 +2313,14 @@ $class = 'databox filters';

+

+ '; + html_print_checkbox_switch('time_in_warning_status', 1, $time_in_warning_status); + ?> +

+ +

'; @@ -2421,6 +2433,18 @@ $class = 'databox filters';

+

+ +

+ +

Worktime @@ -6719,12 +6720,16 @@ function reporting_advanced_sla( // Take in mind: the "inverse" critical threshold. $inverse_interval = ($agentmodule_info['critical_inverse'] == 0) ? 1 : 0; + $inverse_interval_warning = (int) $agentmodule_info['critical_warning']; if (!$is_string_module) { - $min_value = $agentmodule_info['min_critical']; - $max_value = $agentmodule_info['max_critical']; + $min_value = $agentmodule_info['min_critical']; + $max_value = $agentmodule_info['max_critical']; + $min_value_warning = $agentmodule_info['min_warning']; + $max_value_warning = $agentmodule_info['max_warning']; } else { - $max_value = io_safe_output($agentmodule_info['str_critical']); + $max_values = io_safe_output($agentmodule_info['str_critical']); + $max_value_warning = io_safe_output($agentmodule_info['str_warning']); } if (!$is_string_module) { @@ -6732,14 +6737,27 @@ function reporting_advanced_sla( $min_value = null; } + if ((!isset($min_value_warning)) || ($min_value_warning == 0)) { + $min_value_warning = null; + } + if ((!isset($max_value)) || ($max_value == 0)) { $max_value = null; } + if ((!isset($max_value_warning)) || ($max_value_warning == 0)) { + $max_value_warning = null; + } + if ((!(isset($max_value))) && (!(isset($min_value)))) { $max_value = null; $min_value = null; } + + if ((!(isset($max_value_warning))) && (!(isset($min_value_warning)))) { + $max_value_warning = null; + $min_value_warning = null; + } } if ((!isset($min_value)) && (!isset($max_value))) { @@ -6765,6 +6783,30 @@ function reporting_advanced_sla( $min_value = 0; } } + + if ((!isset($min_value_warning)) && (!isset($max_value_warning))) { + if (($agentmodule_info['id_tipo_modulo'] == '2') + // Generic_proc. + || ($agentmodule_info['id_tipo_modulo'] == '6') + // Remote_icmp_proc. + || ($agentmodule_info['id_tipo_modulo'] == '9') + // Remote_tcp_proc. + || ($agentmodule_info['id_tipo_modulo'] == '18') + // Remote_snmp_proc. + || ($agentmodule_info['id_tipo_modulo'] == '21') + // Async_proc. + || ($agentmodule_info['id_tipo_modulo'] == '31') + ) { + // Web_proc + // boolean values are OK if they're different from 0. + $max_value_warning = 0; + $min_value_warning = 0; + $inverse_interval_warning = 0; + } else if ($agentmodule_info['id_tipo_modulo'] == '100') { + $max_value_warning = 0.9; + $min_value_warning = 0; + } + } } // By default show last day. @@ -7108,6 +7150,7 @@ function reporting_advanced_sla( // Timing. $time_total = 0; $time_in_ok = 0; + $time_in_warning = 0; $time_in_error = 0; $time_in_unknown = 0; $time_in_not_init = 0; @@ -7117,6 +7160,7 @@ function reporting_advanced_sla( // Checks. $bad_checks = 0; $ok_checks = 0; + $warning_checks = 0; $not_init_checks = 0; $unknown_checks = 0; $total_checks = 0; @@ -7209,6 +7253,7 @@ function reporting_advanced_sla( ) { // Check values if module is sring type. if ($is_string_module) { + // OK SLA check. if (empty($max_value)) { $match = preg_match('/^'.$max_value.'$/', $current_data['datos']); } else { @@ -7221,17 +7266,49 @@ function reporting_advanced_sla( } else { $sla_check_value = !$match; } + + // Warning SLA check. + if (empty($max_value_warning)) { + $match = preg_match('/^'.$max_value_warning.'$/', $current_data['datos']); + } else { + $match = preg_match('/'.$max_value_warning.'/', $current_data['datos']); + } + + if ($inverse_interval_warning == 0) { + $sla_check_value_warning = $match; + } else { + $sla_check_value_warning = !$match; + } } else { + // OK SLA check. $sla_check_value = sla_check_value( $current_data['datos'], $min_value, $max_value, $inverse_interval ); + + // Warning SLA check. + $sla_check_value_warning = sla_check_value( + $current_data['datos'], + $min_value_warning, + $max_value_warning, + $inverse_interval_warning, + 1 + ); } // Not unknown nor not init values. - if ($sla_check_value) { + if ($sla_check_value_warning && $sla_check_warning === true) { + if (isset($current_data['type']) === false + || ((int) $current_data['type'] === 0 + && $i !== 0) + ) { + $warning_checks++; + } + + $time_in_warning += $time_interval; + } else if ($sla_check_value === true) { if (isset($current_data['type']) === false || ((int) $current_data['type'] === 0 && $i !== 0) @@ -7239,7 +7316,7 @@ function reporting_advanced_sla( $ok_checks++; } - $time_in_ok += $time_interval; + $time_in_ok += $time_interval; } else { if (isset($current_data['type']) === false || ((int) $current_data['type'] === 0 @@ -7306,6 +7383,7 @@ function reporting_advanced_sla( // Timing. $return['time_total'] = $time_total; $return['time_ok'] = $time_in_ok; + $return['time_warning'] = $time_in_warning; $return['time_error'] = $time_in_error; $return['time_unknown'] = $time_in_unknown; $return['time_not_init'] = $time_in_not_init; @@ -7315,12 +7393,13 @@ function reporting_advanced_sla( // Checks. $return['checks_total'] = $total_checks; $return['checks_ok'] = $ok_checks; + $return['checks_warning'] = $warning_checks; $return['checks_error'] = $bad_checks; $return['checks_unknown'] = $unknown_checks; $return['checks_not_init'] = $not_init_checks; // SLA. - $return['SLA'] = reporting_sla_get_compliance_from_array($return); + $return['SLA'] = reporting_sla_get_compliance_from_array($return, $sla_check_warning); $return['sla_fixed'] = sla_truncate( $return['SLA'], $config['graph_precision'] @@ -7525,6 +7604,8 @@ function reporting_availability($report, $content, $date=false, $time=false) $text = ''; + $check_sla_warning = ((int) $content['time_in_warning_status']) === 1; + if (isset($item['compare']) === true && empty($item['compare']) === true ) { @@ -7546,14 +7627,26 @@ function reporting_availability($report, $content, $date=false, $time=false) '7' => $content['saturday'], ], $content['time_from'], - $content['time_to'] + $content['time_to'], + 1, + 1, + $check_sla_warning ); } else { // Intervals is dinamic. $row['data'] = reporting_advanced_sla( $item['id_agent_module'], ($report['datetime'] - $content['period']), - $report['datetime'] + $report['datetime'], + null, + null, + 0, + null, + null, + null, + 1, + 1, + $check_sla_warning ); } @@ -7699,12 +7792,14 @@ function reporting_availability($report, $content, $date=false, $time=false) $return['fields']['total_time'] = $content['total_time']; $return['fields']['time_failed'] = $content['time_failed']; $return['fields']['time_in_ok_status'] = $content['time_in_ok_status']; + $return['fields']['time_in_warning_status'] = $content['time_in_warning_status']; $return['fields']['time_in_unknown_status'] = $content['time_in_unknown_status']; $return['fields']['time_of_not_initialized_module'] = $content['time_of_not_initialized_module']; $return['fields']['time_of_downtime'] = $content['time_of_downtime']; $return['fields']['total_checks'] = $content['total_checks']; $return['fields']['checks_failed'] = $content['checks_failed']; $return['fields']['checks_in_ok_status'] = $content['checks_in_ok_status']; + $return['fields']['checks_in_warning_status'] = $content['checks_in_warning_status']; $return['fields']['unknown_checks'] = $content['unknown_checks']; $return['fields']['agent_max_value'] = $content['agent_max_value']; $return['fields']['agent_min_value'] = $content['agent_min_value']; @@ -9546,12 +9641,14 @@ function reporting_check_structure_content($report) $return['fields']['total_time'] = ''; $return['fields']['time_failed'] = ''; $return['fields']['time_in_ok_status'] = ''; + $return['fields']['time_in_warning_status'] = ''; $return['fields']['time_in_unknown_status'] = ''; $return['fields']['time_of_not_initialized_module'] = ''; $return['fields']['time_of_downtime'] = ''; $return['fields']['total_checks'] = ''; $return['fields']['checks_failed'] = ''; $return['fields']['checks_in_ok_status'] = ''; + $return['fields']['checks_in_warning_status'] = ''; $return['fields']['unknown_checks'] = ''; $return['fields']['agent_max_value'] = ''; $return['fields']['agent_min_value'] = ''; @@ -13603,9 +13700,14 @@ function reporting_sql_macro(array $report, string $sql): string * @param Array With keys time_ok, time_error, time_downtime and time_unknown * @return SLA Return the compliance value. */ -function reporting_sla_get_compliance_from_array($sla_array) +function reporting_sla_get_compliance_from_array($sla_array, $sla_check_warning=false) { $time_compliance = ($sla_array['time_ok'] + $sla_array['time_unknown'] + $sla_array['time_downtime']); + + if ($sla_check_warning === true) { + $time_compliance += $sla_array['time_warning']; + } + $time_total_working = ($time_compliance + $sla_array['time_error']); return $time_compliance == 0 ? 0 : (($time_compliance / $time_total_working) * 100); } diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index 30d562aa71..7992a2193a 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -1535,7 +1535,7 @@ function reporting_html_agents_inventory($table, $item, $pdf=0) foreach ($data as $data_field_key => $data_field_value) { $column_value = $data_field_value; - $show_link = $pdf === 0 ? true : false; + $show_link = ($pdf === 0) ? true : false; // Necessary transformations of data prior to represent it. if ($data_field_key === 'id_os') { @@ -3559,25 +3559,31 @@ function reporting_html_availability($table, $item, $pdf=0) $table1->head[4] = __(''); } - if ($item['fields']['time_in_unknown_status']) { - $table1->head[5] = __('Time Unknown'); + if ($item['fields']['time_in_warning_status']) { + $table1->head[5] = __('Time in warning status'); } else { $table1->head[5] = __(''); } - if ($item['fields']['time_of_not_initialized_module']) { - $table1->head[6] = __('Time Not Init Module'); + if ($item['fields']['time_in_unknown_status']) { + $table1->head[6] = __('Time Unknown'); } else { $table1->head[6] = __(''); } - if ($item['fields']['time_of_downtime']) { - $table1->head[7] = __('Time Downtime'); + if ($item['fields']['time_of_not_initialized_module']) { + $table1->head[7] = __('Time Not Init Module'); } else { $table1->head[7] = __(''); } - $table1->head[8] = __('% Ok'); + if ($item['fields']['time_of_downtime']) { + $table1->head[8] = __('Time Downtime'); + } else { + $table1->head[8] = __(''); + } + + $table1->head[9] = __('% Ok'); $table1->headstyle = []; if (isset($item['data'][0]['failover']) === true) { @@ -3593,6 +3599,7 @@ function reporting_html_availability($table, $item, $pdf=0) $table1->headstyle[6] = 'text-align: center'; $table1->headstyle[7] = 'text-align: right'; $table1->headstyle[8] = 'text-align: right'; + $table1->headstyle[9] = 'text-align: right'; if (isset($item['data'][0]['failover']) === true) { $table1->style[-1] = 'text-align: left'; @@ -3608,6 +3615,7 @@ function reporting_html_availability($table, $item, $pdf=0) $table1->style[7] = 'text-align: right'; $table1->style[8] = 'text-align: right'; $table1->style[9] = 'text-align: right'; + $table1->style[10] = 'text-align: right'; $table2 = new stdClass(); $table2->width = '99%'; @@ -3645,12 +3653,18 @@ function reporting_html_availability($table, $item, $pdf=0) $table2->head[4] = __(''); } - if ($item['fields']['unknown_checks']) { - $table2->head[5] = __('Checks Uknown'); + if ($item['fields']['checks_in_warning_status']) { + $table2->head[5] = __('Checks Warning'); } else { $table2->head[5] = __(''); } + if ($item['fields']['unknown_checks']) { + $table2->head[6] = __('Checks Uknown'); + } else { + $table2->head[6] = __(''); + } + $table2->headstyle = []; if (isset($item['data'][0]['failover']) === true) { $table2->headstyle[-1] = 'text-align: left'; @@ -3666,6 +3680,7 @@ function reporting_html_availability($table, $item, $pdf=0) $table2->headstyle[3] = 'text-align: right'; $table2->headstyle[4] = 'text-align: right'; $table2->headstyle[5] = 'text-align: right'; + $table2->headstyle[6] = 'text-align: right'; if (isset($item['data'][0]['failover']) === true) { $table2->style[-1] = 'text-align: left'; @@ -3763,6 +3778,20 @@ function reporting_html_availability($table, $item, $pdf=0) $table_row[] = ''; }; + if ($row['time_warning'] != 0 && $item['fields']['time_in_warning_status']) { + $table_row[] = human_time_description_raw( + $row['time_warning'], + true, + $interval_description + ); + } else if ($row['time_warning'] == 0 + && $item['fields']['time_in_warning_status'] + ) { + $table_row[] = '--'; + } else { + $table_row[] = ''; + }; + if ($row['time_unknown'] != 0 && $item['fields']['time_in_unknown_status'] ) { @@ -3872,6 +3901,12 @@ function reporting_html_availability($table, $item, $pdf=0) $table_row2[] = ''; } + if ($item['fields']['checks_in_warning_status']) { + $table_row2[] = $row['checks_warning']; + } else { + $table_row2[] = ''; + } + if ($item['fields']['unknown_checks']) { $table_row2[] = $row['checks_unknown']; } else { diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql index daa3c98746..a50bc4f5a7 100644 --- a/pandora_console/pandoradb.sql +++ b/pandora_console/pandoradb.sql @@ -1562,12 +1562,14 @@ CREATE TABLE IF NOT EXISTS `treport_content` ( `total_time` TINYINT(1) DEFAULT '1', `time_failed` TINYINT(1) DEFAULT '1', `time_in_ok_status` TINYINT(1) DEFAULT '1', + `time_in_warning_status` TINYINT(1) DEFAULT '0', `time_in_unknown_status` TINYINT(1) DEFAULT '1', `time_of_not_initialized_module` TINYINT(1) DEFAULT '1', `time_of_downtime` TINYINT(1) DEFAULT '1', `total_checks` TINYINT(1) DEFAULT '1', `checks_failed` TINYINT(1) DEFAULT '1', `checks_in_ok_status` TINYINT(1) DEFAULT '1', + `checks_in_warning_status` TINYINT(1) DEFAULT '0', `unknown_checks` TINYINT(1) DEFAULT '1', `agent_max_value` TINYINT(1) DEFAULT '1', `agent_min_value` TINYINT(1) DEFAULT '1', @@ -3175,12 +3177,14 @@ CREATE TABLE IF NOT EXISTS `treport_content_template` ( `total_time` TINYINT(1) DEFAULT '1', `time_failed` TINYINT(1) DEFAULT '1', `time_in_ok_status` TINYINT(1) DEFAULT '1', + `time_in_warning_status` TINYINT(1) DEFAULT '0', `time_in_unknown_status` TINYINT(1) DEFAULT '1', `time_of_not_initialized_module` TINYINT(1) DEFAULT '1', `time_of_downtime` TINYINT(1) DEFAULT '1', `total_checks` TINYINT(1) DEFAULT '1', `checks_failed` TINYINT(1) DEFAULT '1', `checks_in_ok_status` TINYINT(1) DEFAULT '1', + `checks_in_warning_status` TINYINT(1) DEFAULT '0', `unknown_checks` TINYINT(1) DEFAULT '1', `agent_max_value` TINYINT(1) DEFAULT '1', `agent_min_value` TINYINT(1) DEFAULT '1',