diff --git a/pandora_console/godmode/reporting/reporting_builder.item_editor.php b/pandora_console/godmode/reporting/reporting_builder.item_editor.php index 53be2c1f07..724c5f6772 100755 --- a/pandora_console/godmode/reporting/reporting_builder.item_editor.php +++ b/pandora_console/godmode/reporting/reporting_builder.item_editor.php @@ -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) { + + + + + + __('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, + ); + ?> + + + + + + + + + + + + 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; diff --git a/pandora_console/include/functions_modules.php b/pandora_console/include/functions_modules.php index 07690151e4..a953d66ac1 100755 --- a/pandora_console/include/functions_modules.php +++ b/pandora_console/include/functions_modules.php @@ -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; diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index ee1f04b952..94585ee455 100755 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -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, diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index 719ddfd7a3..cd5e1b5e23 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -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. *