diff --git a/pandora_console/godmode/reporting/reporting_builder.item_editor.php b/pandora_console/godmode/reporting/reporting_builder.item_editor.php index b98b651201..d57d930b6a 100755 --- a/pandora_console/godmode/reporting/reporting_builder.item_editor.php +++ b/pandora_console/godmode/reporting/reporting_builder.item_editor.php @@ -743,6 +743,7 @@ switch ($action) { break; case 'agent_module': + case 'agent_module_status': $description = $item['description']; $es = json_decode($item['external_source'], true); @@ -4744,6 +4745,7 @@ $(document).ready (function () { switch (type){ case 'agent_module': + case 'agent_module_status': case 'alert_report_actions': var agents_multiple = $('#id_agents2').val(); var modules_multiple = $('#module').val(); @@ -4878,6 +4880,7 @@ $(document).ready (function () { } switch (type){ case 'agent_module': + case 'agent_module_status': case 'alert_report_actions': var agents_multiple = $('#id_agents2').val(); var modules_multiple = $('#module').val(); @@ -6345,9 +6348,10 @@ function chooseType() { break; case 'agent_module': + $("#row_module_group").show(); + case 'agent_module_status': $("#row_description").show(); $("#row_group").show(); - $("#row_module_group").show(); $("#select_agent_modules").show(); $("#agents_modules_row").show(); $("#modules_row").show(); diff --git a/pandora_console/godmode/reporting/reporting_builder.php b/pandora_console/godmode/reporting/reporting_builder.php index 3296154cf9..e82bf0264b 100755 --- a/pandora_console/godmode/reporting/reporting_builder.php +++ b/pandora_console/godmode/reporting/reporting_builder.php @@ -1655,6 +1655,7 @@ switch ($action) { break; case 'agent_module': + case 'agent_module_status': $agents_to_report_text = get_parameter('id_agents2-multiple-text', ''); $modules_to_report_text = get_parameter('module-multiple-text', ''); @@ -2456,6 +2457,7 @@ switch ($action) { break; case 'agent_module': + case 'agent_module_status': $agents_to_report_text = get_parameter('id_agents2-multiple-text'); $modules_to_report_text = get_parameter('module-multiple-text', ''); diff --git a/pandora_console/include/functions_agents.php b/pandora_console/include/functions_agents.php index cde89f1b7b..dcf134d17c 100644 --- a/pandora_console/include/functions_agents.php +++ b/pandora_console/include/functions_agents.php @@ -750,6 +750,7 @@ function agents_get_agents_selected($group) 'id_tmetaconsole_setup', 'id_agente', 'alias', + 'server_name', ], 'AR', [ @@ -764,7 +765,7 @@ function agents_get_agents_selected($group) $all = array_reduce( $all, function ($carry, $item) { - $carry[$item['id_tmetaconsole_setup'].'|'.$item['id_tagente']] = $item['alias']; + $carry[$item['id_tmetaconsole_setup'].'|'.$item['id_tagente']] = $item['server_name'].' » '.$item['alias']; return $carry; }, [] @@ -4185,3 +4186,78 @@ function get_planned_downtime_agents_list($id_downtime, $filter_cond, $id_groups return $agents; } + + +/** + * Agent Module status and data + * + * @param integer $id_group Group + * @param array $agents Agents filter. + * @param array $modules Modules filter. + * + * @return array Result. + */ +function get_status_data_agent_modules($id_group, $agents=[], $modules=[]) +{ + $slq_filter_group = ''; + if (empty($id_group) === false) { + $slq_filter_group = sprintf( + ' AND tagente.id_grupo = %d', + $id_group + ); + } + + $slq_filter_agent = ''; + if (empty($agents) === false) { + $slq_filter_agent = sprintf( + ' AND tagente_modulo.id_agente IN (%s)', + implode(',', $agents) + ); + } + + $slq_filter_module = ''; + if (empty($modules) === false) { + $slq_filter_module = sprintf( + ' AND tagente_modulo.id_agente_modulo IN (%s)', + implode(',', $modules) + ); + } + + $sql = sprintf( + 'SELECT tagente_modulo.id_agente_modulo as id_agent_module, + tagente_modulo.nombre as name_module, + tagente_modulo.unit as unit_module, + tagente_modulo.id_agente as id_agent, + tagente_estado.datos as data_module, + tagente_estado.timestamp as data_time_module, + tagente_estado.estado as status_module, + tagente.alias as name_agent, + tagente.id_grupo as id_group, + tgrupo.nombre as name_group + FROM tagente_modulo + INNER JOIN tagente_estado + ON tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo + INNER JOIN tagente + ON tagente_modulo.id_agente = tagente.id_agente + LEFT JOIN tagent_secondary_group + ON tagente.id_agente = tagent_secondary_group.id_agent + INNER JOIN tgrupo + ON tagente.id_grupo = tgrupo.id_grupo + WHERE 1=1 + %s + %s + %s + ', + $slq_filter_group, + $slq_filter_agent, + $slq_filter_module + ); + + $res = db_get_all_rows_sql($sql); + + if ($res === false) { + $res = []; + } + + return $res; +} diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index 3693a72dcd..236474a62d 100755 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -730,6 +730,13 @@ function reporting_make_reporting_data( ); break; + case 'agent_module_status': + $report['contents'][] = reporting_agent_module_status( + $report, + $content + ); + break; + case 'alert_report_actions': $report['contents'][] = reporting_alert_report_actions( $report, @@ -2854,6 +2861,136 @@ function reporting_agent_module($report, $content) } +/** + * Agents module status + * + * @param array $report Info Report. + * @param array $content Info content. + * + * @return array + */ +function reporting_agent_module_status($report, $content) +{ + global $config; + $return['type'] = 'agent_module_status'; + + if (empty($content['name'])) { + $content['name'] = __('Agent/Modules Status'); + } + + $return['title'] = io_safe_output($content['name']); + $return['landscape'] = $content['landscape']; + $return['pagebreak'] = $content['pagebreak']; + $group_name = groups_get_name($content['id_group'], true); + if ($content['id_module_group'] == 0) { + $module_group_name = __('All'); + } else { + $module_group_name = db_get_value( + 'name', + 'tmodule_group', + 'id_mg', + $content['id_module_group'] + ); + } + + $return['subtitle'] = $group_name.' - '.$module_group_name; + $return['description'] = io_safe_output($content['description']); + $return['date'] = reporting_get_date_text($report, $content); + $return['label'] = (isset($content['style']['label'])) ? $content['style']['label'] : ''; + + $return['data'] = []; + + $external_source = json_decode( + $content['external_source'], + true + ); + + $agents = json_decode( + io_safe_output( + base64_decode($external_source['id_agents']) + ), + true + ); + + $modules = json_decode( + io_safe_output( + base64_decode($external_source['module']) + ), + true + ); + + if (is_metaconsole() === true) { + $agents_per_node = []; + $modules_per_node = []; + + if (empty($agents) === false) { + foreach ($agents as $value) { + $agent_array = explode('|', $value); + $agents_per_node[$agent_array[0]][] = $agent_array[1]; + } + } + + if (empty($modules) === false) { + foreach ($modules as $value) { + $module_array = explode('|', $value); + $modules_per_node[$module_array[0]][] = $module_array[1]; + } + } + + if (empty($agents_per_node) === false) { + foreach ($agents_per_node as $server => $agents) { + $connection = metaconsole_get_connection_by_id($server); + if (metaconsole_connect($connection) != NOERR) { + continue; + } + + $res[$connection['server_name']] = get_status_data_agent_modules( + $content['id_group'], + $agents, + $modules_per_node[$server] + ); + + metaconsole_restore_db(); + } + } else { + $metaconsole_connections = metaconsole_get_connection_names(); + // For all nodes. + if (isset($metaconsole_connections) === true + && is_array($metaconsole_connections) === true + ) { + foreach ($metaconsole_connections as $metaconsole) { + // Get server connection data. + $server_data = metaconsole_get_connection($metaconsole); + + // Establishes connection. + if (metaconsole_load_external_db($server_data) !== NOERR) { + continue; + } + + $res[$server_data['server_name']] = get_status_data_agent_modules( + $content['id_group'], + $agents, + $modules + ); + + metaconsole_restore_db(); + } + } + } + } else { + $res['node'] = get_status_data_agent_modules( + $content['id_group'], + $agents, + $modules + ); + } + + $return['data'] = $res; + + 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 f697b10a01..af44743228 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -377,6 +377,10 @@ function reporting_html_print_report($report, $mini=false, $report_info=1) reporting_html_agent_module($table, $item); break; + case 'agent_module_status': + reporting_html_agent_module_status($table, $item); + break; + case 'alert_report_actions': reporting_html_alert_report_actions($table, $item); break; @@ -1999,6 +2003,125 @@ function reporting_html_agent_module($table, $item) } +/** + * Html report agent modules status. + * + * @param object $table Head table or false if it comes from pdf. + * @param array $item Items data. + * @param integer $pdf Pdf output. + * + * @return mixed + */ +function reporting_html_agent_module_status($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%'; + + $table_info->align = []; + if (is_metaconsole() === true) { + $table_info->align['server'] = 'left'; + } + + $table_info->align['name_group'] = 'left'; + $table_info->align['name_agent'] = 'left'; + $table_info->align['name_module'] = 'left'; + $table_info->align['status_module'] = 'left'; + $table_info->align['data_module'] = 'left'; + $table_info->align['data_time_module'] = 'left'; + + $table_info->headstyle = []; + if (is_metaconsole() === true) { + $table_info->headstyle['server'] = 'text-align: left'; + } + + $table_info->headstyle['name_group'] = 'text-align: left'; + $table_info->headstyle['name_agent'] = 'text-align: left'; + $table_info->headstyle['name_module'] = 'text-align: left'; + $table_info->headstyle['status_module'] = 'text-align: left'; + $table_info->headstyle['data_module'] = 'text-align: left'; + $table_info->headstyle['data_time_module'] = 'text-align: left'; + + $table_info->head = []; + if (is_metaconsole() === true) { + $table_info->head['server'] = __('Server'); + } + + $table_info->head['name_agent'] = __('Agent'); + $table_info->head['name_module'] = __('Module'); + $table_info->head['name_group'] = __('Group'); + $table_info->head['status_module'] = __('Status'); + $table_info->head['data_module'] = __('Data'); + $table_info->head['data_time_module'] = __('Last time'); + + $table_info->data = []; + + foreach ($item['data'] as $server => $info) { + foreach ($info as $data) { + $row = []; + if (is_metaconsole() === true) { + $row['server'] = $server; + } + + $row['name_agent'] = $data['name_agent']; + $row['name_module'] = $data['name_module']; + $row['name_group'] = $data['name_group']; + $row['status_module'] = ui_print_module_status( + $data['status_module'], + true, + 'status_rounded_rectangles', + null, + ($pdf === 1) ? '       ' : '' + ); + + if (is_numeric($data['data_module']) === true) { + $row['data_module'] = remove_right_zeros( + number_format( + $data['data_module'], + $config['graph_precision'] + ) + ); + } else { + $row['data_module'] = (empty($data['data_module']) === true) ? '--' : $data['data_module']; + } + + $row['data_module'] .= $data['unit_module']; + $row['data_time_module'] = $data['data_time_module']; + + $table_info->data[] = $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. * diff --git a/pandora_console/include/functions_reports.php b/pandora_console/include/functions_reports.php index f310856ad2..a6811f3ffd 100755 --- a/pandora_console/include/functions_reports.php +++ b/pandora_console/include/functions_reports.php @@ -796,6 +796,11 @@ function reports_get_report_types($template=false, $not_editor=false) } } + $types['agent_module_status'] = [ + 'optgroup' => __('Grouped'), + 'name' => __('Agents/Modules status'), + ]; + // Only pandora managers have access to the whole database. if (check_acl($config['id_user'], 0, 'PM')) { $types['sql'] = [ diff --git a/pandora_console/include/functions_ui.php b/pandora_console/include/functions_ui.php index fa62ee3a16..41f04104f1 100755 --- a/pandora_console/include/functions_ui.php +++ b/pandora_console/include/functions_ui.php @@ -2737,10 +2737,11 @@ function ui_print_status_image( /** * Returns html code to print a shape for a module. * - * @param integer $status Module status. - * @param boolean $return True or false. - * @param string $class Custom class or use defined. - * @param string $title Custom title or inherit from module status. + * @param integer $status Module status. + * @param boolean $return True or false. + * @param string $class Custom class or use defined. + * @param string $title Custom title or inherit from module status. + * @param string $div_content Content. * * @return string HTML code for shape. */ @@ -2748,7 +2749,8 @@ function ui_print_module_status( $status, $return=false, $class='status_rounded_rectangles', - $title=null + $title=null, + $div_content='' ) { $color = modules_get_color_status($status, true); if ($title === null) { @@ -2758,7 +2760,7 @@ function ui_print_module_status( $output = '
'; + $output .= $title.'" data-use_title_for_force_title="1">'.$div_content.''; if ($return === false) { echo $output;