From 98aebc4587b7158495eec1c7920df78f4388ea53 Mon Sep 17 00:00:00 2001 From: Daniel Maya Date: Wed, 23 Mar 2022 16:59:15 +0100 Subject: [PATCH] #8533 added show module data (report) --- .../reporting_builder.item_editor.php | 34 +++ .../godmode/reporting/reporting_builder.php | 2 + .../include/functions_reporting.php | 23 +- .../include/functions_reporting_html.php | 229 ++++++++--------- .../javascript/multiselect_filtered.js | 1 - .../lib/Dashboard/Widgets/agent_module.php | 233 ++++++++++-------- 6 files changed, 299 insertions(+), 223 deletions(-) diff --git a/pandora_console/godmode/reporting/reporting_builder.item_editor.php b/pandora_console/godmode/reporting/reporting_builder.item_editor.php index 8cd4172daf..34ff7be3d9 100755 --- a/pandora_console/godmode/reporting/reporting_builder.item_editor.php +++ b/pandora_console/godmode/reporting/reporting_builder.item_editor.php @@ -760,6 +760,11 @@ switch ($action) { ); $selection_a_m = get_parameter('selection'); + + if (isset($es['show_type']) === true) { + $show_type = $es['show_type']; + } + $recursion = $item['recursion']; $group = $item['id_group']; @@ -1833,6 +1838,33 @@ $class = 'databox filters'; + + + + __('Show module status'), + 1 => __('Show module data'), + ]; + + html_print_select( + $show_select, + 'show_type', + $show_type, + '', + '', + 0, + false, + false, + true, + '', + false, + 'min-width: 180px' + ); + ?> + + + @@ -5925,6 +5957,7 @@ function chooseType() { $("#row_agent_not_assigned_to_ip").hide(); $("#row_show_summary").hide(); $("#row_group_by").hide(); + $("#row_type_show").hide(); // SLA list default state. $("#sla_list").hide(); @@ -6438,6 +6471,7 @@ function chooseType() { case 'agent_module': $("#row_module_group").show(); + $("#row_type_show").show(); case 'agent_module_status': $("#row_description").show(); $("#row_group").show(); diff --git a/pandora_console/godmode/reporting/reporting_builder.php b/pandora_console/godmode/reporting/reporting_builder.php index fbad042ef1..7fc89b6267 100755 --- a/pandora_console/godmode/reporting/reporting_builder.php +++ b/pandora_console/godmode/reporting/reporting_builder.php @@ -1677,6 +1677,7 @@ switch ($action) { // 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; @@ -2480,6 +2481,7 @@ switch ($action) { // 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; diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index ba3dc52551..cc8935b98c 100755 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -2802,6 +2802,12 @@ function reporting_agent_module($report, $content) true ); + if (isset($external_source['show_type']) === true) { + $show_type = $external_source['show_type']; + } else { + $show_type = 0; + } + $return['type'] = 'agent_module'; if (empty($content['name'])) { @@ -2838,6 +2844,10 @@ function reporting_agent_module($report, $content) modules_get_agentmodule_name($modul_id) ); $modules_by_name[$cont]['id'] = $modul_id; + if ($show_type === '1') { + $modules_by_name[$cont]['unit'] = modules_get_unit($modul_id); + } + $cont++; } @@ -2853,7 +2863,18 @@ function reporting_agent_module($report, $content) $row['modules'] = []; foreach ($modules_by_name as $module) { if (array_key_exists($module['id'], $agent_modules)) { - $row['modules'][$module['name']] = modules_get_agentmodule_status($module['id']); + if ($show_type === '1') { + $module_last_value = modules_get_last_value($module['id']); + if (!is_numeric($module_last_value)) { + $module_last_value = htmlspecialchars($module_last_value); + } + + $module['datos'] = $module_last_value; + $row['modules'][$module['name']] = modules_get_agentmodule_data_for_humans($module); + $row['show_type'] = $show_type; + } else { + $row['modules'][$module['name']] = modules_get_agentmodule_status($module['id']); + } } else { if (!array_key_exists($module['name'], $row['modules'])) { $row['modules'][$module['name']] = null; diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index b18b2a4b91..5385b645d6 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -1872,111 +1872,115 @@ function reporting_html_agent_module($table, $item) $table_data .= ""; } else { $table_data .= ""; - switch ($module) { - default: - case AGENT_STATUS_NORMAL: - $table_data .= ui_print_status_image( - 'module_ok.png', - __( - '%s in %s : NORMAL', - $module_name, - $row['agent_name'] - ), - true, - [ - 'width' => '20px', - 'height' => '20px', - ], - 'images/status_sets/default/' - ); - break; + if (isset($row['show_type']) === true && $row['show_type'] === '1') { + $table_data .= $module; + } else { + switch ($module) { + case AGENT_STATUS_CRITICAL: + $table_data .= ui_print_status_image( + 'module_critical.png', + __( + '%s in %s : CRITICAL', + $module_name, + $row['agent_name'] + ), + true, + [ + 'width' => '20px', + 'height' => '20px', + ], + 'images/status_sets/default/' + ); + break; - case AGENT_STATUS_CRITICAL: - $table_data .= ui_print_status_image( - 'module_critical.png', - __( - '%s in %s : CRITICAL', - $module_name, - $row['agent_name'] - ), - true, - [ - 'width' => '20px', - 'height' => '20px', - ], - 'images/status_sets/default/' - ); - break; + case AGENT_STATUS_WARNING: + $table_data .= ui_print_status_image( + 'module_warning.png', + __( + '%s in %s : WARNING', + $module_name, + $row['agent_name'] + ), + true, + [ + 'width' => '20px', + 'height' => '20px', + ], + 'images/status_sets/default/' + ); + break; - case AGENT_STATUS_WARNING: - $table_data .= ui_print_status_image( - 'module_warning.png', - __( - '%s in %s : WARNING', - $module_name, - $row['agent_name'] - ), - true, - [ - 'width' => '20px', - 'height' => '20px', - ], - 'images/status_sets/default/' - ); - break; + case AGENT_STATUS_UNKNOWN: + $table_data .= ui_print_status_image( + 'module_unknown.png', + __( + '%s in %s : UNKNOWN', + $module_name, + $row['agent_name'] + ), + true, + [ + 'width' => '20px', + 'height' => '20px', + ], + 'images/status_sets/default/' + ); + break; - case AGENT_STATUS_UNKNOWN: - $table_data .= ui_print_status_image( - 'module_unknown.png', - __( - '%s in %s : UNKNOWN', - $module_name, - $row['agent_name'] - ), - true, - [ - 'width' => '20px', - 'height' => '20px', - ], - 'images/status_sets/default/' - ); - break; + case AGENT_MODULE_STATUS_NORMAL_ALERT: + case AGENT_MODULE_STATUS_WARNING_ALERT: + case AGENT_MODULE_STATUS_CRITICAL_ALERT: + $table_data .= ui_print_status_image( + 'module_alertsfired.png', + __( + '%s in %s : ALERTS FIRED', + $module_name, + $row['agent_name'] + ), + true, + [ + 'width' => '20px', + 'height' => '20px', + ], + 'images/status_sets/default/' + ); + break; - case AGENT_MODULE_STATUS_NORMAL_ALERT: - case AGENT_MODULE_STATUS_WARNING_ALERT: - case AGENT_MODULE_STATUS_CRITICAL_ALERT: - $table_data .= ui_print_status_image( - 'module_alertsfired.png', - __( - '%s in %s : ALERTS FIRED', - $module_name, - $row['agent_name'] - ), - true, - [ - 'width' => '20px', - 'height' => '20px', - ], - 'images/status_sets/default/' - ); - break; + case 4: + $table_data .= ui_print_status_image( + 'module_no_data.png', + __( + '%s in %s : Not initialize', + $module_name, + $row['agent_name'] + ), + true, + [ + 'width' => '20px', + 'height' => '20px', + ], + 'images/status_sets/default/' + ); + break; - case 4: - $table_data .= ui_print_status_image( - 'module_no_data.png', - __( - '%s in %s : Not initialize', - $module_name, - $row['agent_name'] - ), - true, - [ - 'width' => '20px', - 'height' => '20px', - ], - 'images/status_sets/default/' - ); - break; + default: + case AGENT_STATUS_NORMAL: + $table_data .= ui_print_status_image( + 'module_ok.png', + __( + '%s in %s : NORMAL', + $module_name, + $row['agent_name'] + ), + true, + [ + 'width' => '20px', + 'height' => '20px', + ], + 'images/status_sets/default/' + ); + break; + } } $table_data .= ''; @@ -1986,18 +1990,19 @@ function reporting_html_agent_module($table, $item) $table_data .= ''; - $table_data .= "
"; - - $table_data .= ''; - $table_data .= "'; - $table_data .= "'; - $table_data .= "'; - $table_data .= "'; - $table_data .= "'; - $table_data .= "'; - $table_data .= "'; - $table_data .= '
".__('Legend').'
".__('Orange cell when the module has fired alerts').'
".__('Red cell when the module has a critical status').'
".__('Yellow cell when the module has a warning status').'
".__('Green cell when the module has a normal status').'
".__('Grey cell when the module has an unknown status').'
".__("Cell turns grey when the module is in 'not initialize' status").'
'; - $table_data .= '
'; + if (isset($row['show_type']) === false) { + $table_data .= "
"; + $table_data .= ''; + $table_data .= "'; + $table_data .= "'; + $table_data .= "'; + $table_data .= "'; + $table_data .= "'; + $table_data .= "'; + $table_data .= "'; + $table_data .= '
".__('Legend').'
".__('Orange cell when the module has fired alerts').'
".__('Red cell when the module has a critical status').'
".__('Yellow cell when the module has a warning status').'
".__('Green cell when the module has a normal status').'
".__('Grey cell when the module has an unknown status').'
".__("Cell turns grey when the module is in 'not initialize' status").'
'; + $table_data .= '
'; + } $table->data['agent_module']['cell'] = $table_data; } diff --git a/pandora_console/include/javascript/multiselect_filtered.js b/pandora_console/include/javascript/multiselect_filtered.js index 74f24f5a0a..dcaee528b0 100644 --- a/pandora_console/include/javascript/multiselect_filtered.js +++ b/pandora_console/include/javascript/multiselect_filtered.js @@ -232,7 +232,6 @@ function fmModuleChange(uniqId, isMeta) { selection: showCommonModules }, function(data) { - debugger; $("#filtered-module-modules-" + uniqId).html(""); if (data) { jQuery.each(data, function(id, value) { diff --git a/pandora_console/include/lib/Dashboard/Widgets/agent_module.php b/pandora_console/include/lib/Dashboard/Widgets/agent_module.php index a920ee8643..0d18407ac4 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/agent_module.php +++ b/pandora_console/include/lib/Dashboard/Widgets/agent_module.php @@ -505,118 +505,126 @@ class AgentModuleWidget extends Widget } foreach ($row['modules'] as $module_name => $module) { - if ($module === null) { - if (in_array($module_name, $allModules) === true) { - $style = 'background-color: transparent;'; - $table_data .= ""; - $table_data .= ''; - } else { - continue; - } - } else { + if ($this->values['mTypeShow'] === '1') { $style = 'text-align: center;'; $style .= ' background-color: transparent;'; $table_data .= ""; - switch ($module) { - case AGENT_STATUS_NORMAL: - $table_data .= \ui_print_status_image( - 'module_ok.png', - __( - '%s in %s : NORMAL', - $module_name, - $row['agent_alias'] - ), - true, - [ - 'width' => '20px', - 'height' => '20px', - ] - ); - break; - - case AGENT_STATUS_CRITICAL: - $table_data .= \ui_print_status_image( - 'module_critical.png', - __( - '%s in %s : CRITICAL', - $module_name, - $row['agent_alias'] - ), - true, - [ - 'width' => '20px', - 'height' => '20px', - ] - ); - break; - - case AGENT_STATUS_WARNING: - $table_data .= \ui_print_status_image( - 'module_warning.png', - __( - '%s in %s : WARNING', - $module_name, - $row['agent_alias'] - ), - true, - [ - 'width' => '20px', - 'height' => '20px', - ] - ); - break; - - case AGENT_STATUS_UNKNOWN: - $table_data .= \ui_print_status_image( - 'module_unknown.png', - __( - '%s in %s : UNKNOWN', - $module_name, - $row['agent_alias'] - ), - true, - [ - 'width' => '20px', - 'height' => '20px', - ] - ); - break; - - case 4: - $table_data .= \ui_print_status_image( - 'module_no_data.png', - __( - '%s in %s : Not initialize', - $module_name, - $row['agent_alias'] - ), - true, - [ - 'width' => '20px', - 'height' => '20px', - ] - ); - break; - - case AGENT_STATUS_ALERT_FIRED: - default: - $table_data .= \ui_print_status_image( - 'module_alertsfired.png', - __( - '%s in %s : ALERTS FIRED', - $module_name, - $row['agent_alias'] - ), - true, - [ - 'width' => '20px', - 'height' => '20px', - ] - ); - break; - } - + $table_data .= $module; $table_data .= ''; + } else { + if ($module === null) { + if (in_array($module_name, $allModules) === true) { + $style = 'background-color: transparent;'; + $table_data .= ""; + $table_data .= ''; + } else { + continue; + } + } else { + $style = 'text-align: center;'; + $style .= ' background-color: transparent;'; + $table_data .= ""; + switch ($module) { + case AGENT_STATUS_NORMAL: + $table_data .= \ui_print_status_image( + 'module_ok.png', + __( + '%s in %s : NORMAL', + $module_name, + $row['agent_alias'] + ), + true, + [ + 'width' => '20px', + 'height' => '20px', + ] + ); + break; + + case AGENT_STATUS_CRITICAL: + $table_data .= \ui_print_status_image( + 'module_critical.png', + __( + '%s in %s : CRITICAL', + $module_name, + $row['agent_alias'] + ), + true, + [ + 'width' => '20px', + 'height' => '20px', + ] + ); + break; + + case AGENT_STATUS_WARNING: + $table_data .= \ui_print_status_image( + 'module_warning.png', + __( + '%s in %s : WARNING', + $module_name, + $row['agent_alias'] + ), + true, + [ + 'width' => '20px', + 'height' => '20px', + ] + ); + break; + + case AGENT_STATUS_UNKNOWN: + $table_data .= \ui_print_status_image( + 'module_unknown.png', + __( + '%s in %s : UNKNOWN', + $module_name, + $row['agent_alias'] + ), + true, + [ + 'width' => '20px', + 'height' => '20px', + ] + ); + break; + + case 4: + $table_data .= \ui_print_status_image( + 'module_no_data.png', + __( + '%s in %s : Not initialize', + $module_name, + $row['agent_alias'] + ), + true, + [ + 'width' => '20px', + 'height' => '20px', + ] + ); + break; + + case AGENT_STATUS_ALERT_FIRED: + default: + $table_data .= \ui_print_status_image( + 'module_alertsfired.png', + __( + '%s in %s : ALERTS FIRED', + $module_name, + $row['agent_alias'] + ), + true, + [ + 'width' => '20px', + 'height' => '20px', + ] + ); + break; + } + + $table_data .= ''; + } } } @@ -783,7 +791,14 @@ class AgentModuleWidget extends Widget continue; } - $visualData[$agent_id]['modules'][$module->name()] = $module->getStatus()->estado(); + if ($this->values['mTypeShow'] === '1') { + $mod = $module->toArray(); + $mod['datos'] = $module->lastValue(); + $module_last_value = modules_get_agentmodule_data_for_humans($mod); + $visualData[$agent_id]['modules'][$module->name()] = $module_last_value; + } else { + $visualData[$agent_id]['modules'][$module->name()] = $module->getStatus()->estado(); + } } if ((bool) is_metaconsole() === true) {