From 0064bc0cba71e67791bcc884c1bd1c6b721bc750 Mon Sep 17 00:00:00 2001 From: Daniel Barbero Martin Date: Mon, 1 Jul 2019 17:07:39 +0200 Subject: [PATCH] fixed errors --- pandora_console/extras/mr/30.sql | 0 .../pandoradb_migrate_6.0_to_7.0.mysql.sql | 9 +- .../reporting_builder.item_editor.php | 185 ++++- .../include/ajax/reporting.ajax.php | 14 +- .../include/ajax/update_manager.ajax.php | 2 + .../include/functions_reporting.php | 719 +++++++++++------- .../include/functions_reporting_html.php | 86 ++- pandora_console/pandoradb.sql | 1 + pandora_console/pandoradb_data.sql | 4 +- 9 files changed, 697 insertions(+), 323 deletions(-) create mode 100644 pandora_console/extras/mr/30.sql diff --git a/pandora_console/extras/mr/30.sql b/pandora_console/extras/mr/30.sql new file mode 100644 index 0000000000..e69de29bb2 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 4bad7b3652..b9e48da3f8 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 @@ -1239,13 +1239,13 @@ ALTER TABLE titem MODIFY `source_data` int(10) unsigned; INSERT INTO `tconfig` (`token`, `value`) VALUES ('big_operation_step_datos_purge', '100'); INSERT INTO `tconfig` (`token`, `value`) VALUES ('small_operation_step_datos_purge', '1000'); INSERT INTO `tconfig` (`token`, `value`) VALUES ('days_autodisable_deletion', '30'); -INSERT INTO `tconfig` (`token`, `value`) VALUES ('MR', 29); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('MR', 30); INSERT INTO `tconfig` (`token`, `value`) VALUES ('custom_docs_logo', 'default_docs.png'); INSERT INTO `tconfig` (`token`, `value`) VALUES ('custom_support_logo', 'default_support.png'); INSERT INTO `tconfig` (`token`, `value`) VALUES ('custom_logo_white_bg_preview', 'pandora_logo_head_white_bg.png'); UPDATE tconfig SET value = 'https://licensing.artica.es/pandoraupdate7/server.php' WHERE token='url_update_manager'; DELETE FROM `tconfig` WHERE `token` = 'current_package_enterprise'; -INSERT INTO `tconfig` (`token`, `value`) VALUES ('current_package_enterprise', '736'); +INSERT INTO `tconfig` (`token`, `value`) VALUES ('current_package_enterprise', '737'); INSERT INTO `tconfig` (`token`, `value`) VALUES ('status_monitor_fields', 'policy,agent,data_type,module_name,server_type,interval,status,graph,warn,data,timestamp'); -- --------------------------------------------------------------------- @@ -2209,3 +2209,8 @@ CREATE TABLE IF NOT EXISTS `tcredential_store` ( `extra_2` text, PRIMARY KEY (`identifier`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +-- --------------------------------------------------------------------- +-- Table `treport_content_sla_combined` +-- --------------------------------------------------------------------- +ALTER TABLE `treport_content_sla_combined` ADD `id_agent_module_secondary` int(10) unsigned NOT NULL; diff --git a/pandora_console/godmode/reporting/reporting_builder.item_editor.php b/pandora_console/godmode/reporting/reporting_builder.item_editor.php index 8c4c21fb8f..d943fbf0fc 100755 --- a/pandora_console/godmode/reporting/reporting_builder.item_editor.php +++ b/pandora_console/godmode/reporting/reporting_builder.item_editor.php @@ -566,7 +566,6 @@ switch ($action) { $include_extended_events = $item['show_extended_events']; $filter_search = $style['event_filter_search']; - break; case 'event_report_group': @@ -2784,8 +2783,21 @@ function print_SLA_list($width, $action, $idItem=null) + if ($report_item_type == 'availability_graph') { + ?> + + + + + + '; + $itemsSLA = db_get_all_rows_filter( 'treport_content_sla_combined', ['id_report_content' => $idItem] @@ -2865,6 +2878,25 @@ function print_SLA_list($width, $action, $idItem=null) ['id_agente_modulo' => $item['id_agent_module']] ); + if (isset($item['id_agent_module_secondary']) === true + && $item['id_agent_module_secondary'] !== 0 + ) { + $idAgentSecondary = db_get_value_filter( + 'id_agente', + 'tagente_modulo', + ['id_agente_modulo' => $item['id_agent_module_secondary']] + ); + $nameAgentSecondary = agents_get_alias( + $idAgentSecondary + ); + + $nameModuleSecondary = db_get_value_filter( + 'nombre', + 'tagente_modulo', + ['id_agente_modulo' => $item['id_agent_module_secondary']] + ); + } + $server_name_element = ''; if ($meta && $server_name != '') { $server_name_element .= ' ('.$server_name.')'; @@ -2878,6 +2910,15 @@ function print_SLA_list($width, $action, $idItem=null) echo printSmallFont($nameModule); echo ''; + if ($report_item_type == 'availability_graph') { + echo ''; + echo printSmallFont($nameAgentSecondary).$server_name_element; + echo ''; + echo ''; + echo printSmallFont($nameModuleSecondary); + echo ''; + } + if (enterprise_installed() && $report_item_type == 'SLA_services' ) { @@ -2926,6 +2967,13 @@ function print_SLA_list($width, $action, $idItem=null) + + + + + + + + + + + + '; echo html_print_select( @@ -3915,10 +3999,13 @@ function deleteGeneralRow(id_row) { function addSLARow() { var nameAgent = $("input[name=agent_sla]").val(); + var nameAgentSecondary = $("input[name=agent_secondary]").val(); var idAgent = $("input[name=id_agent_sla]").val(); var serverId = $("input[name=id_server]").val(); var idModule = $("#id_agent_module_sla").val(); + var idModuleSecondary = $("#id_agent_module_secondary").val(); var nameModule = $("#id_agent_module_sla :selected").text(); + var nameModuleSecondary = $("#id_agent_module_secondary :selected").text(); var slaMin = $("input[name=sla_min]").val(); var slaMax = $("input[name=sla_max]").val(); var slaLimit = $("input[name=sla_limit]").val(); @@ -3979,10 +4066,63 @@ function addSLARow() { }); } + if (nameAgentSecondary != '') { + //Truncate nameAgentSecondary + var params = []; + params.push("truncate_text=1"); + params.push("text=" + nameAgentSecondary); + params.push("page=include/ajax/reporting.ajax"); + jQuery.ajax ({ + data: params.join ("&"), + type: 'POST', + url: action= + + + "/ajax.php", + async: false, + timeout: 10000, + success: function (data) { + nameAgentSecondary = data; + } + }); + + //Truncate nameModuleSecondary + var params = []; + params.push("truncate_text=1"); + params.push("text=" + nameModuleSecondary); + params.push("page=include/ajax/reporting.ajax"); + jQuery.ajax ({ + data: params.join ("&"), + type: 'POST', + url: action= + + + "/ajax.php", + async: false, + timeout: 10000, + success: function (data) { + nameModuleSecondary = data; + } + }); + } + var params = []; params.push("add_sla=1"); params.push("id=" + $("input[name=id_item]").val()); params.push("id_module=" + idModule); + params.push("id_module_secondary=" + idModuleSecondary); params.push("sla_min=" + slaMin); params.push("sla_max=" + slaMax); params.push("sla_limit=" + slaLimit); @@ -4015,6 +4155,8 @@ function addSLARow() { $("#row", row).attr('id', 'sla_' + data['id']); $(".agent_name", row).html(nameAgent); $(".module_name", row).html(nameModule); + $(".agent_name_secondary", row).html(nameAgentSecondary); + $(".module_name_secondary", row).html(nameModuleSecondary); $(".service_name", row).html(serviceName); $(".sla_min", row).html(slaMin); $(".sla_max", row).html(slaMax); @@ -4025,14 +4167,22 @@ function addSLARow() { ); $("#list_sla").append($(row).html()); $("input[name=id_agent_sla]").val(''); + $("input[name=id_agent_secondary]").val(''); $("input[name=id_server]").val(''); $("input[name=agent_sla]").val(''); + $("input[name=agent_secondary]").val(''); $("#id_agent_module_sla").empty(); $("#id_agent_module_sla").attr('disabled', 'true'); $("#id_agent_module_sla").append( $("") .attr ("value", 0) .html ($("#module_sla_text").html())); + $("#id_agent_module_secondary").empty(); + $("#id_agent_module_secondary").attr('disabled', 'true'); + $("#id_agent_module_secondary").append( + $("") + .attr ("value", 0) + .html ($("#module_sla_text").html())); $("input[name=sla_min]").val(''); $("input[name=sla_max]").val(''); $("input[name=sla_limit]").val(''); @@ -4161,7 +4311,6 @@ function addGeneralRow() { success: function (data) { if (data['correct']) { row = $("#general_template").clone(); - $("#row", row).show(); $("#row", row).attr('id', 'general_' + data['id']); $(".agent_name", row).html(nameAgent); diff --git a/pandora_console/include/ajax/reporting.ajax.php b/pandora_console/include/ajax/reporting.ajax.php index 55ed7dd216..16bdff9527 100755 --- a/pandora_console/include/ajax/reporting.ajax.php +++ b/pandora_console/include/ajax/reporting.ajax.php @@ -65,6 +65,7 @@ if ($add_sla) { $sla_max = get_parameter('sla_max', 0); $sla_min = get_parameter('sla_min', 0); $server_id = (int) get_parameter('server_id', 0); + $id_module_secondary = (int) get_parameter('id_module_secondary', 0); $id_service = (int) get_parameter('id_service'); if (empty($id_module) && !empty($id_service)) { @@ -85,12 +86,13 @@ if ($add_sla) { $result = db_process_sql_insert( 'treport_content_sla_combined', [ - 'id_report_content' => $id, - 'id_agent_module' => $id_module, - 'sla_max' => $sla_max, - 'sla_min' => $sla_min, - 'sla_limit' => $sla_limit, - 'server_name' => $connection['server_name'], + 'id_report_content' => $id, + 'id_agent_module' => $id_module, + 'id_agent_module_secondary' => $id_module_secondary, + 'sla_max' => $sla_max, + 'sla_min' => $sla_min, + 'sla_limit' => $sla_limit, + 'server_name' => $connection['server_name'], ] ); diff --git a/pandora_console/include/ajax/update_manager.ajax.php b/pandora_console/include/ajax/update_manager.ajax.php index 7a7cefc82b..13ea1f560b 100644 --- a/pandora_console/include/ajax/update_manager.ajax.php +++ b/pandora_console/include/ajax/update_manager.ajax.php @@ -134,6 +134,7 @@ if ($install_package) { $accept = (bool) get_parameter('accept', false); if ($accept) { + hd($accept, true); $package = (string) get_parameter('package'); $package = trim($package); @@ -163,6 +164,7 @@ if ($install_package) { unlink($files_copied); } + if (file_exists($package)) { if ($files_h = fopen($files_total, 'r')) { while ($line = stream_get_line($files_h, 65535, "\n")) { diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index 4261518b68..ce6d901740 100755 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -1,20 +1,30 @@ dynamic - $sla['sla_max'], - // max_value -> dynamic - $inverse_interval, - // inverse_interval -> dynamic - [ - '1' => $content['sunday'], - '2' => $content['monday'], - '3' => $content['tuesday'], - '4' => $content['wednesday'], - '5' => $content['thursday'], - '6' => $content['friday'], - '7' => $content['saturday'], - ], - $content['time_from'], - $content['time_to'], - $slice - ); - - if ($metaconsole_on) { - // Restore db connection - metaconsole_restore_db(); - } - - $server_name = $sla['server_name']; - // Metaconsole connection + // Metaconsole connection. if ($metaconsole_on && $server_name != '') { $connection = metaconsole_get_connection($server_name); if (metaconsole_connect($connection) != NOERR) { @@ -6521,199 +6458,118 @@ function reporting_availability_graph($report, $content, $pdf=false) } } - $planned_downtimes = reporting_get_planned_downtimes_intervals($sla['id_agent_module'], ($report['datetime'] - $content['period']), $report['datetime']); + if (isset($sla['id_agent_module_secondary']) === true + && $sla['id_agent_module_secondary'] != 0 + ) { + $sla_secondary['primary'] = $sla; + $sla_secondary['failover'] = $sla; + $sla_secondary['failover']['id_agent_module'] = $sla['id_agent_module_secondary']; - if ((is_array($planned_downtimes)) && (count($planned_downtimes) > 0)) { - // Sort retrieved planned downtimes - usort( - $planned_downtimes, - function ($a, $b) { - $a = intval($a['date_from']); - $b = intval($b['date_from']); - if ($a == $b) { - return 0; - } + // For graph slice for module-interval, if not slice=0. + $module_interval = modules_get_interval($sla['id_agent_module']); + $slice = ($content['period'] / $module_interval); - return ($a < $b) ? -1 : 1; - } + foreach ($sla_secondary as $k_sla => $v_sla) { + $sla_array = data_db_uncompress_module( + $v_sla, + $content, + $report['datetime'], + $slice + ); + + $return = prepare_data_for_paint( + $v_sla, + $sla_array, + $content, + $report['datetime'], + $return, + $k_sla + ); + + $data_combined[] = $sla_array; + } + + if (isset($data_combined) === true + && is_array($data_combined) === true + && count($data_combined) > 0 + ) { + $data_a = array_map( + function ($primary, $failover) { + if ($primary['date_from'] === $failover['date_from'] + && $primary['date_to'] === $failover['date_to'] + ) { + if ($primary['sla_fixed'] !== 100 + && $primary['sla_fixed'] < $failover['sla_fixed'] + ) { + $primary['time_total'] = $failover['time_total']; + $primary['time_ok'] = $failover['time_ok']; + $primary['time_error'] = $failover['time_error']; + $primary['time_unknown'] = $failover['time_unknown']; + $primary['time_not_init'] = $failover['time_not_init']; + $primary['time_downtime'] = $failover['time_downtime']; + $primary['time_out'] = $failover['time_out']; + $primary['checks_total'] = $failover['checks_total']; + $primary['checks_ok'] = $failover['checks_ok']; + $primary['checks_error'] = $failover['checks_error']; + $primary['checks_unknown'] = $failover['checks_unknown']; + $primary['checks_not_init'] = $failover['checks_not_init']; + $primary['SLA'] = $failover['SLA']; + $primary['sla_fixed'] = $failover['sla_fixed']; + } + + $return = $primary; + } + + return $return; + }, + $data_combined[0], + $data_combined[1] + ); + + $return = prepare_data_for_paint( + $sla, + $data_a, + $content, + $report['datetime'], + $return, + 'result' + ); + } + } else { + $sla_array = data_db_uncompress_module( + $sla, + $content, + $report['datetime'] ); - // Compress (overlapped) planned downtimes - $npd = count($planned_downtimes); - for ($i = 0; $i < $npd; $i++) { - if (isset($planned_downtimes[($i + 1)])) { - if ($planned_downtimes[$i]['date_to'] >= $planned_downtimes[($i + 1)]['date_from']) { - // merge - $planned_downtimes[$i]['date_to'] = $planned_downtimes[($i + 1)]['date_to']; - array_splice($planned_downtimes, ($i + 1), 1); - $npd--; - } - } - } - } else { - $planned_downtimes = null; + $return = prepare_data_for_paint( + $sla, + $sla_array, + $content, + $report['datetime'], + $return + ); } - $data = []; - $data['agent'] = modules_get_agentmodule_agent_alias($sla['id_agent_module']); - $data['module'] = modules_get_agentmodule_name($sla['id_agent_module']); - $data['max'] = $sla['sla_max']; - $data['min'] = $sla['sla_min']; - $data['sla_limit'] = $sla['sla_limit']; - $data['dinamic_text'] = $dinamic_text; - - if (isset($sla_array[0])) { - $data['time_total'] = 0; - $data['time_ok'] = 0; - $data['time_error'] = 0; - $data['time_unknown'] = 0; - $data['time_not_init'] = 0; - $data['time_downtime'] = 0; - $data['checks_total'] = 0; - $data['checks_ok'] = 0; - $data['checks_error'] = 0; - $data['checks_unknown'] = 0; - $data['checks_not_init'] = 0; - - $raw_graph = []; - $i = 0; - foreach ($sla_array as $value_sla) { - $data['time_total'] += $value_sla['time_total']; - $data['time_ok'] += $value_sla['time_ok']; - $data['time_error'] += $value_sla['time_error']; - $data['time_unknown'] += $value_sla['time_unknown']; - $data['time_downtime'] += $value_sla['time_downtime']; - $data['time_not_init'] += $value_sla['time_not_init']; - $data['checks_total'] += $value_sla['checks_total']; - $data['checks_ok'] += $value_sla['checks_ok']; - $data['checks_error'] += $value_sla['checks_error']; - $data['checks_unknown'] += $value_sla['checks_unknown']; - $data['checks_not_init'] += $value_sla['checks_not_init']; - - // generate raw data for graph - $period = reporting_sla_get_status_period($value_sla, $priority_mode); - $raw_graph[$i]['data'] = reporting_translate_sla_status_for_graph($period); - $raw_graph[$i]['utimestamp'] = ($value_sla['date_to'] - $value_sla['date_from']); - $i++; - } - - $data['sla_value'] = reporting_sla_get_compliance_from_array($data); - $data['sla_fixed'] = sla_truncate($data['sla_value'], $config['graph_precision']); - } else { - // Show only table not divider in slice for defect slice=1 - $data['time_total'] = $sla_array['time_total']; - $data['time_ok'] = $sla_array['time_ok']; - $data['time_error'] = $sla_array['time_error']; - $data['time_unknown'] = $sla_array['time_unknown']; - $data['time_downtime'] = $sla_array['time_downtime']; - $data['time_not_init'] = $sla_array['time_not_init']; - $data['checks_total'] = $sla_array['checks_total']; - $data['checks_ok'] = $sla_array['checks_ok']; - $data['checks_error'] = $sla_array['checks_error']; - $data['checks_unknown'] = $sla_array['checks_unknown']; - $data['checks_not_init'] = $sla_array['checks_not_init']; - $data['sla_value'] = $sla_array['SLA']; - } - - // checks whether or not it meets the SLA - if ($data['sla_value'] >= $sla['sla_limit']) { - $data['sla_status'] = 1; - $sla_failed = false; - } else { - $sla_failed = true; - $data['sla_status'] = 0; - } - - // Do not show right modules if 'only_display_wrong' is active - if ($content['only_display_wrong'] && $sla_failed == false) { - continue; - } - - // find order - $data['order'] = $data['sla_value']; - $return['data'][] = $data; - - $data_init = -1; - $acum = 0; - $sum = 0; - $array_result = []; - $i = 0; - foreach ($raw_graph as $key => $value) { - if ($data_init == -1) { - $data_init = $value['data']; - $acum = $value['utimestamp']; - $sum = $value['data']; - } else { - if ($data_init == $value['data']) { - $acum = ($acum + $value['utimestamp']); - $sum = ($sum + $value['real_data']); - } else { - $array_result[$i]['data'] = $data_init; - $array_result[$i]['utimestamp'] = $acum; - $array_result[$i]['real_data'] = $sum; - $i++; - $data_init = $value['data']; - $acum = $value['utimestamp']; - $sum = $value['real_data']; - } - } - } - - $array_result[$i]['data'] = $data_init; - $array_result[$i]['utimestamp'] = $acum; - $array_result[$i]['real_data'] = $sum; - - // Slice graphs calculation - $dataslice = []; - $dataslice['agent'] = modules_get_agentmodule_agent_alias($sla['id_agent_module']); - $dataslice['module'] = modules_get_agentmodule_name($sla['id_agent_module']); - $dataslice['order'] = $data['sla_value']; - $dataslice['checks_total'] = $data['checks_total']; - $dataslice['checks_ok'] = $data['checks_ok']; - $dataslice['time_total'] = $data['time_total']; - $dataslice['time_not_init'] = $data['time_not_init']; - $dataslice['sla_status'] = $data['sla_status']; - $dataslice['sla_value'] = $data['sla_value']; - - $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'], - 100, - 70, - $urlImage, - $ttl, - $array_result, - false - ); - - $return['charts'][] = $dataslice; - if ($metaconsole_on) { - // Restore db connection + // Restore db connection. metaconsole_restore_db(); } } - // SLA items sorted descending () + // SLA items sorted descending. if ($content['top_n'] == 2) { arsort($return['data']['']); - } - // SLA items sorted ascending - else if ($content['top_n'] == 1) { + } else if ($content['top_n'] == 1) { + // SLA items sorted ascending. asort($sla_showed_values); } - // order data for ascending or descending + // Order data for ascending or descending. if ($content['top_n'] != 0) { switch ($content['top_n']) { case 1: - // order tables + // Order tables. $temp = []; foreach ($return['data'] as $row) { $i = 0; @@ -6730,7 +6586,7 @@ function reporting_availability_graph($report, $content, $pdf=false) $return['data'] = $temp; - // order graphs + // Order graphs. $temp = []; foreach ($return['charts'] as $row) { $i = 0; @@ -6746,11 +6602,10 @@ function reporting_availability_graph($report, $content, $pdf=false) } $return['charts'] = $temp; - break; case 2: - // order tables + // Order tables. $temp = []; foreach ($return['data'] as $row) { $i = 0; @@ -6767,7 +6622,7 @@ function reporting_availability_graph($report, $content, $pdf=false) $return['data'] = $temp; - // order graph + // Order graph. $temp = []; foreach ($return['charts'] as $row) { $i = 0; @@ -6783,7 +6638,10 @@ function reporting_availability_graph($report, $content, $pdf=false) } $return['charts'] = $temp; + break; + default: + // If not posible. break; } } @@ -6793,6 +6651,311 @@ function reporting_availability_graph($report, $content, $pdf=false) } +/** + * Return data db uncompress for module. + * + * @param array $sla Data neccesary for db_uncompress. + * @param array $content Conetent report. + * @param array $datetime Date. + * @param integer $slice Defined slice. + * + * @return array + */ +function data_db_uncompress_module($sla, $content, $datetime, $slice=0) +{ + // Controller min and max == 0 then dinamic min and max critical. + $dinamic_text = 0; + if ($sla['sla_min'] == 0 && $sla['sla_max'] == 0) { + $sla['sla_min'] = null; + $sla['sla_max'] = null; + $dinamic_text = __('Dynamic'); + } + + // Controller inverse interval. + $inverse_interval = 0; + if ((isset($sla['sla_max'])) && (isset($sla['sla_min']))) { + if ($sla['sla_max'] < $sla['sla_min']) { + $content_sla_max = $sla['sla_max']; + $sla['sla_max'] = $sla['sla_min']; + $sla['sla_min'] = $content_sla_max; + $inverse_interval = 1; + $dinamic_text = __('Inverse'); + } + } + + if ($slice === 0) { + // For graph slice for module-interval, if not slice=0. + $module_interval = modules_get_interval($sla['id_agent_module']); + $slice = ($content['period'] / $module_interval); + } + + // Call functions sla. + $sla_array = []; + $sla_array = reporting_advanced_sla( + $sla['id_agent_module'], + ($datetime - $content['period']), + $datetime, + $sla['sla_min'], + $sla['sla_max'], + $inverse_interval, + [ + '1' => $content['sunday'], + '2' => $content['monday'], + '3' => $content['tuesday'], + '4' => $content['wednesday'], + '5' => $content['thursday'], + '6' => $content['friday'], + '7' => $content['saturday'], + ], + $content['time_from'], + $content['time_to'], + $slice + ); + + return $sla_array; +} + + +/** + * Return array planned downtimes. + * + * @param integer $id_agent_module Id module. + * @param integer $datetime Date utimestamp. + * @param integer $period Period utimestamp. + * + * @return array + */ +function reporting_get_planned_downtimes_sla($id_agent_module, $datetime, $period) +{ + $planned_downtimes = reporting_get_planned_downtimes_intervals( + $id_agent_module, + ($datetime - $period), + $datetime + ); + + if ((is_array($planned_downtimes)) + && (count($planned_downtimes) > 0) + ) { + // Sort retrieved planned downtimes. + usort( + $planned_downtimes, + function ($a, $b) { + $a = intval($a['date_from']); + $b = intval($b['date_from']); + if ($a == $b) { + return 0; + } + + return ($a < $b) ? (-1) : 1; + } + ); + + // Compress (overlapped) planned downtimes. + $npd = count($planned_downtimes); + for ($i = 0; $i < $npd; $i++) { + if (isset($planned_downtimes[($i + 1)])) { + if ($planned_downtimes[$i]['date_to'] >= $planned_downtimes[($i + 1)]['date_from']) { + // Merge. + $planned_downtimes[$i]['date_to'] = $planned_downtimes[($i + 1)]['date_to']; + array_splice($planned_downtimes, ($i + 1), 1); + $npd--; + } + } + } + } else { + $planned_downtimes = []; + } + + return $planned_downtimes; +} + + +/** + * Prepare data for Paint in report. + * + * @param array $sla Data Module to sla. + * @param array $sla_array Data uncompressed. + * @param array $content Content report data. + * @param integer $datetime Date. + * @param array $return Array return. + * @param string $secondary Type secondaary primary, failover, Result. + * + * @return array Return modify. + */ +function prepare_data_for_paint( + $sla, + $sla_array, + $content, + $datetime, + $return, + $secondary='' +) { + $data = []; + $alias_agent = modules_get_agentmodule_agent_alias( + $sla['id_agent_module'] + ); + $name_module = modules_get_agentmodule_name( + $sla['id_agent_module'] + ); + + $data['agent'] = $alias_agent; + $data['module'] = $name_module; + $data['max'] = $sla['sla_max']; + $data['min'] = $sla['sla_min']; + $data['sla_limit'] = $sla['sla_limit']; + $data['dinamic_text'] = $dinamic_text; + $data['secondary'] = $secondary; + if (isset($sla_array[0])) { + $data['time_total'] = 0; + $data['time_ok'] = 0; + $data['time_error'] = 0; + $data['time_unknown'] = 0; + $data['time_not_init'] = 0; + $data['time_downtime'] = 0; + $data['checks_total'] = 0; + $data['checks_ok'] = 0; + $data['checks_error'] = 0; + $data['checks_unknown'] = 0; + $data['checks_not_init'] = 0; + + $raw_graph = []; + $i = 0; + foreach ($sla_array as $value_sla) { + $data['time_total'] += $value_sla['time_total']; + $data['time_ok'] += $value_sla['time_ok']; + $data['time_error'] += $value_sla['time_error']; + $data['time_unknown'] += $value_sla['time_unknown']; + $data['time_downtime'] += $value_sla['time_downtime']; + $data['time_not_init'] += $value_sla['time_not_init']; + $data['checks_total'] += $value_sla['checks_total']; + $data['checks_ok'] += $value_sla['checks_ok']; + $data['checks_error'] += $value_sla['checks_error']; + $data['checks_unknown'] += $value_sla['checks_unknown']; + $data['checks_not_init'] += $value_sla['checks_not_init']; + + // Generate raw data for graph. + $period = reporting_sla_get_status_period( + $value_sla, + $priority_mode + ); + $raw_graph[$i]['data'] = reporting_translate_sla_status_for_graph( + $period + ); + $raw_graph[$i]['utimestamp'] = ($value_sla['date_to'] - $value_sla['date_from']); + $i++; + } + + $data['sla_value'] = reporting_sla_get_compliance_from_array( + $data + ); + $data['sla_fixed'] = sla_truncate( + $data['sla_value'], + $config['graph_precision'] + ); + } else { + // Show only table not divider in slice for defect slice=1. + $data['time_total'] = $sla_array['time_total']; + $data['time_ok'] = $sla_array['time_ok']; + $data['time_error'] = $sla_array['time_error']; + $data['time_unknown'] = $sla_array['time_unknown']; + $data['time_downtime'] = $sla_array['time_downtime']; + $data['time_not_init'] = $sla_array['time_not_init']; + $data['checks_total'] = $sla_array['checks_total']; + $data['checks_ok'] = $sla_array['checks_ok']; + $data['checks_error'] = $sla_array['checks_error']; + $data['checks_unknown'] = $sla_array['checks_unknown']; + $data['checks_not_init'] = $sla_array['checks_not_init']; + $data['sla_value'] = $sla_array['SLA']; + } + + // Checks whether or not it meets the SLA. + if ($data['sla_value'] >= $sla['sla_limit']) { + $data['sla_status'] = 1; + $sla_failed = false; + } else { + $sla_failed = true; + $data['sla_status'] = 0; + } + + // Do not show right modules if 'only_display_wrong' is active. + if ($content['only_display_wrong'] && $sla_failed == false) { + return $return; + } + + // Find order. + $data['order'] = $data['sla_value']; + $return['data'][] = $data; + + $data_init = -1; + $acum = 0; + $sum = 0; + $array_result = []; + $i = 0; + foreach ($raw_graph as $key => $value) { + if ($data_init == -1) { + $data_init = $value['data']; + $acum = $value['utimestamp']; + $sum = $value['data']; + } else { + if ($data_init == $value['data']) { + $acum = ($acum + $value['utimestamp']); + $sum = ($sum + $value['real_data']); + } else { + $array_result[$i]['data'] = $data_init; + $array_result[$i]['utimestamp'] = $acum; + $array_result[$i]['real_data'] = $sum; + $i++; + $data_init = $value['data']; + $acum = $value['utimestamp']; + $sum = $value['real_data']; + } + } + } + + $array_result[$i]['data'] = $data_init; + $array_result[$i]['utimestamp'] = $acum; + $array_result[$i]['real_data'] = $sum; + + // Slice graphs calculation. + $dataslice = []; + $dataslice['agent'] = $alias_agent; + $dataslice['module'] = $name_module; + $dataslice['order'] = $data['sla_value']; + $dataslice['checks_total'] = $data['checks_total']; + $dataslice['checks_ok'] = $data['checks_ok']; + $dataslice['time_total'] = $data['time_total']; + $dataslice['time_not_init'] = $data['time_not_init']; + $dataslice['sla_status'] = $data['sla_status']; + $dataslice['sla_value'] = $data['sla_value']; + + $height = 80; + if ($secondary !== '' && $secondary !== 'result') { + $height = 50; + } + + $dataslice['chart'] = graph_sla_slicebar( + $sla['id_agent_module'], + $content['period'], + $sla['sla_min'], + $sla['sla_max'], + $datetime, + $content, + $content['time_from'], + $content['time_to'], + 100, + $height, + $urlImage, + $ttl, + $array_result, + false + ); + + $return['charts'][] = $dataslice; + + return $return; +} + + /** * reporting_increment * diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index c8d5b3e29e..ecad568d1d 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -3252,15 +3252,7 @@ function reporting_html_availability_graph($table, $item, $pdf=0) $tables_chart = ''; - $table1 = new stdClass(); - $table1->width = '99%'; - $table1->data = []; - $table1->size = []; - $table1->size[0] = '10%'; - $table1->size[1] = '80%'; - $table1->size[2] = '5%'; - $table1->size[3] = '5%'; - foreach ($item['charts'] as $chart) { + foreach ($item['charts'] as $k_chart => $chart) { $checks_resume = ''; $sla_value = ''; if (reporting_sla_is_not_init_from_array($chart)) { @@ -3291,14 +3283,74 @@ function reporting_html_availability_graph($table, $item, $pdf=0) $checks_resume = '('.$chart['checks_ok'].'/'.$chart['checks_total'].')'; } - $table1->data[0][0] = $chart['agent'].'
'.$chart['module']; - $table1->data[0][1] = $chart['chart']; - $table1->data[0][2] = "".$sla_value.''; - $table1->data[0][3] = $checks_resume; - $tables_chart .= html_print_table( - $table1, - true - ); + // Check failover availability report. + if ($item['data'][$k_chart]['secondary'] === '') { + $table1 = new stdClass(); + $table1->width = '99%'; + $table1->data = []; + $table1->size = []; + $table1->size[0] = '10%'; + $table1->size[1] = '80%'; + $table1->size[2] = '5%'; + $table1->size[3] = '5%'; + $table1->data[0][0] = $chart['agent'].'
'.$chart['module']; + $table1->data[0][1] = $chart['chart']; + $table1->data[0][2] = "".$sla_value.''; + $table1->data[0][3] = $checks_resume; + $tables_chart .= html_print_table( + $table1, + true + ); + } else { + if ($item['data'][$k_chart]['secondary'] === 'primary') { + $table1 = new stdClass(); + $table1->width = '99%'; + $table1->data = []; + $table1->size = []; + $table1->size[0] = '10%'; + $table1->size[1] = '80%'; + $table1->size[2] = '5%'; + $table1->size[3] = '5%'; + } + + $title = ''; + $checks_resume_text = $checks_resume; + $sla_value_text = "".$sla_value.''; + switch ($item['data'][$k_chart]['secondary']) { + case 'primary': + $title = ''.__('Primary').''; + $title .= '
'.$chart['agent']; + $title .= '
'.$chart['module']; + break; + + case 'failover': + $title = ''.__('Failover').''; + $title .= '
'.$chart['agent']; + $title .= '
'.$chart['module']; + break; + + case 'result': + default: + $title = ''.__('Result').''; + $sla_value_text = "".$sla_value.''; + $checks_resume_text = ''; + $checks_resume_text .= $checks_resume; + $checks_resume_text .= ''; + break; + } + + $table1->data[$item['data'][$k_chart]['secondary']][0] = $title; + $table1->data[$item['data'][$k_chart]['secondary']][1] = $chart['chart']; + $table1->data[$item['data'][$k_chart]['secondary']][2] = $sla_value_text; + $table1->data[$item['data'][$k_chart]['secondary']][3] = $checks_resume_text; + + if ($item['data'][$k_chart]['secondary'] === 'result') { + $tables_chart .= html_print_table( + $table1, + true + ); + } + } } if ($item['type'] == 'availability_graph') { diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql index 6784ecb309..e73d31209b 100644 --- a/pandora_console/pandoradb.sql +++ b/pandora_console/pandoradb.sql @@ -1464,6 +1464,7 @@ CREATE TABLE IF NOT EXISTS `treport_content_sla_combined` ( `id` INTEGER UNSIGNED NOT NULL auto_increment, `id_report_content` INTEGER UNSIGNED NOT NULL, `id_agent_module` int(10) unsigned NOT NULL, + `id_agent_module_secondary` int(10) unsigned NOT NULL, `sla_max` double(18,2) NOT NULL default 0, `sla_min` double(18,2) NOT NULL default 0, `sla_limit` double(18,2) NOT NULL default 0, diff --git a/pandora_console/pandoradb_data.sql b/pandora_console/pandoradb_data.sql index c69e37e545..6c8811bf22 100644 --- a/pandora_console/pandoradb_data.sql +++ b/pandora_console/pandoradb_data.sql @@ -114,10 +114,10 @@ INSERT INTO `tconfig` (`token`, `value`) VALUES ('custom_report_front_logo', 'images/pandora_logo_white.jpg'), ('custom_report_front_header', ''), ('custom_report_front_footer', ''), -('MR', 29), +('MR', 30), ('identification_reminder', 1), ('identification_reminder_timestamp', 0), -('current_package_enterprise', '736'), +('current_package_enterprise', '737'), ('post_process_custom_values', '{"0.00000038580247":"Seconds to months","0.00000165343915":"Seconds to weeks","0.00001157407407":"Seconds to days","0.01666666666667":"Seconds to minutes","0.00000000093132":"Bytes to Gigabytes","0.00000095367432":"Bytes to Megabytes","0.0009765625":"Bytes to Kilobytes","0.00000001653439":"Timeticks to weeks","0.00000011574074":"Timeticks to days"}'), ('custom_docs_logo', 'default_docs.png'), ('custom_support_logo', 'default_support.png'),