From e70ecd461edac18a241a32b087ee951f6fbe54a8 Mon Sep 17 00:00:00 2001 From: Daniel Barbero Martin Date: Fri, 12 Nov 2021 13:11:49 +0100 Subject: [PATCH 01/31] WIP new report alert fired actions --- .../reporting_builder.item_editor.php | 291 ++++++++++++++++-- .../godmode/reporting/reporting_builder.php | 60 ++++ pandora_console/include/functions_alerts.php | 97 ++++++ pandora_console/include/functions_html.php | 56 +++- .../include/functions_reporting.php | 59 ++++ .../include/functions_reporting_html.php | 10 + pandora_console/include/functions_reports.php | 6 + pandora_console/include/styles/pandora.css | 29 ++ 8 files changed, 573 insertions(+), 35 deletions(-) diff --git a/pandora_console/godmode/reporting/reporting_builder.item_editor.php b/pandora_console/godmode/reporting/reporting_builder.item_editor.php index b0caf02af0..2c2802d31c 100755 --- a/pandora_console/godmode/reporting/reporting_builder.item_editor.php +++ b/pandora_console/godmode/reporting/reporting_builder.item_editor.php @@ -748,6 +748,38 @@ switch ($action) { $idAgentModule = $module; break; + case 'alert_report_actions': + hd('1'); + $description = $item['description']; + $es = json_decode($item['external_source'], true); + $id_agents = $es['id_agents']; + + $selection_a_m = get_parameter('selection'); + $recursion = $item['recursion']; + + if ((count($es['module']) == 1) && ($es['module'][0] == 0)) { + $module = ''; + } else { + $module = $es['module']; + } + + $group = $item['id_group']; + $modulegroup = $item['id_module_group']; + $idAgentModule = $module; + + $alert_templates_selected = $es['templates']; + $alert_actions_selected = $es['actions']; + + $show_summary = $es['show_summary']; + + $group_by = $es['group_by']; + + $period = $item['period']; + + $lapse = $item['lapse']; + $lapse_calc = 1; + break; + case 'agents_inventory': $description = $item['description']; $es = json_decode($item['external_source'], true); @@ -1648,7 +1680,7 @@ $class = 'databox filters'; $group], ['id_agente', 'alias']); foreach ($all_agent_log as $key => $value) { $agents2[$value['id_agente']] = $value['alias']; } @@ -1680,7 +1712,18 @@ $class = 'databox filters'; true, '', false, - 'min-width: 180px' + 'min-width: 500px; max-height: 100px', + false, + false, + false, + '', + false, + false, + false, + false, + true, + true, + true ); ?> @@ -1721,7 +1764,7 @@ $class = 'databox filters'; $all_modules = ''; } else { $all_modules = db_get_all_rows_sql( - 'SELECT DISTINCT nombre FROM + 'SELECT DISTINCT nombre, id_agente_modulo FROM tagente_modulo WHERE id_agente IN ('.implode(',', array_values($id_agents)).')' ); } @@ -1730,12 +1773,12 @@ $class = 'databox filters'; $all_modules = []; } - $modules_select = []; - $all_modules_structured = []; + $modules_select = []; + $all_modules_structured = []; if (is_array($idAgentModule) || is_object($idAgentModule)) { - foreach ($idAgentModule as $id) { - foreach ($all_modules as $key => $a) { - if ($a['id_agente_modulo'] == (int) $id) { + foreach ($all_modules as $key => $a) { + foreach ($idAgentModule as $id) { + if ((int) $a['id_agente_modulo'] === (int) $id) { $modules_select[$a['id_agente_modulo']] = $a['id_agente_modulo']; } } @@ -1751,14 +1794,115 @@ $class = 'databox filters'; 'module[]', $modules_select, $script = '', - __('None'), + '', 0, false, true, true, '', false, - 'min-width: 180px' + 'min-width: 500px; max-height: 100px', + false, + false, + false, + '', + false, + false, + false, + false, + true, + true, + true + ); + ?> + + + + + + + + + + + + + + @@ -3108,7 +3252,60 @@ $class = 'databox filters'; ?> - + + + + + + + + + + + + + + + + 'Agent', + 'module' => 'Module', + 'action' => 'Action', + 'template' => 'Template', + ]; + html_print_select( + $valuesGroupBy, + 'group_by', + $group_by, + '', + __('None'), + '0', + false, + false, + false, + '', + false, + false, + false, + false, + false, + '' + ); + ?> + + + '; echo html_print_select( @@ -4252,12 +4449,12 @@ $(document).ready (function () { // Load selected modules by default $("#id_agents2").trigger('click'); - $('#combo_server').change (function (){ + $('#combo_server').change(function () { $("#id_agents").html(''); - $("#id_agents2").html(''); - $("#module").html(''); - $("#inventory_modules").html(''); - }) + $("#id_agents2").html(''); + $("#module").html(''); + $("#inventory_modules").html(''); + }); $("#text-url").keyup ( function () { @@ -4273,7 +4470,6 @@ $(document).ready (function () { $("#combo_group").change ( function () { - // Alert report group must show all matches when selecting All group // ignoring 'recursion' option. #6497. if ($("#combo_group").val() == 0) { @@ -4284,7 +4480,12 @@ $(document).ready (function () { } $("#id_agents2").html(''); + // Check agent all. + $("#checkbox-id_agents2-check-all").prop('checked', false); $("#module").html(''); + // Check module all. + $("#checkbox-module-check-all").prop('checked', false); + $("#inventory_modules").html(''); jQuery.post ("ajax.php", {"page" : "operation/agentes/ver_agente", @@ -4310,7 +4511,6 @@ $(document).ready (function () { ); } ); - $("#combo_group").change(); $("#checkbox-recursion").change ( function () { @@ -4324,6 +4524,11 @@ $(document).ready (function () { }, function (data, status) { $("#id_agents2").html(''); + // Check agent all. + $("#checkbox-id_agents2-check-all").prop('checked', false); + $("#module").html(''); + // Check module all. + $("#checkbox-module-check-all").prop('checked', false); jQuery.each (data, function (id, value) { // Remove keys_prefix from the index id = id.substring(1); @@ -4351,6 +4556,8 @@ $(document).ready (function () { }, function (data, status) { $("#module").html(''); + // Check module all. + $("#checkbox-module-check-all").prop('checked', false); jQuery.each (data, function (id, value) { option = $("") .attr ("value", value["id_agente_modulo"]) @@ -4374,6 +4581,8 @@ $(document).ready (function () { }, function (data, status) { $("#module").html(''); + // Check module all. + $("#checkbox-module-check-all").prop('checked', false); if(data){ jQuery.each (data, function (id, value) { option = $("") @@ -4399,6 +4608,8 @@ $(document).ready (function () { }, function (data, status) { $("#module").html(''); + // Check module all. + $("#checkbox-module-check-all").prop('checked', false); if(data){ jQuery.each (data, function (id, value) { option = $("") @@ -5538,6 +5749,8 @@ function chooseType() { $('#row_hide_notinit_agents').hide(); $('#row_priority_mode').hide(); $("#row_module_group").hide(); + $("#row_alert_templates").hide(); + $("#row_alert_actions").hide(); $("#row_servers").hide(); $("#row_sort").hide(); $("#row_date").hide(); @@ -5896,6 +6109,18 @@ function chooseType() { $("#row_historical_db_check").hide(); break; + case 'alert_report_actions': + $("#row_description").show(); + $("#row_group").show(); + $("#select_agent_modules").show(); + $("#agents_modules_row").show(); + $("#modules_row").show(); + $("#row_alert_templates").show(); + $("#row_alert_actions").show(); + $("#row_period").show(); + $("#row_lapse").show(); + break; + case 'event_report_group': $("#row_description").show(); $("#row_period").show(); diff --git a/pandora_console/godmode/reporting/reporting_builder.php b/pandora_console/godmode/reporting/reporting_builder.php index 5d1dbb6dff..d09b67c2f5 100755 --- a/pandora_console/godmode/reporting/reporting_builder.php +++ b/pandora_console/godmode/reporting/reporting_builder.php @@ -1692,6 +1692,36 @@ switch ($action) { $good_format = true; break; + case 'alert_report_actions': + hd('3'); + $agents_to_report = get_parameter('id_agents2'); + $modules_to_report = get_parameter('module', ''); + $alert_templates_to_report = get_parameter('alert_templates'); + $alert_actions_to_report = get_parameter('alert_actions'); + $show_summary = get_parameter('show_summary', 0); + $group_by = get_parameter('group_by', 0); + + $es['module'] = get_same_modules( + $agents_to_report, + $modules_to_report + ); + $es['id_agents'] = $agents_to_report; + $es['templates'] = $alert_templates_to_report; + $es['actions'] = $alert_actions_to_report; + $es['show_summary'] = $show_summary; + $es['group_by'] = $group_by; + + $values['external_source'] = json_encode($es); + + $values['period'] = get_parameter('period'); + $values['lapse_calc'] = get_parameter( + 'lapse_calc' + ); + $values['lapse'] = get_parameter('lapse'); + + $good_format = true; + break; + case 'inventory': $values['period'] = 0; $es['date'] = get_parameter('date'); @@ -2436,6 +2466,36 @@ switch ($action) { $good_format = true; break; + case 'alert_report_actions': + hd('2'); + $agents_to_report = get_parameter('id_agents2'); + $modules_to_report = get_parameter('module', ''); + $alert_templates_to_report = get_parameter('alert_templates'); + $alert_actions_to_report = get_parameter('alert_actions'); + $show_summary = get_parameter('show_summary', 0); + $group_by = get_parameter('group_by', 0); + + $es['module'] = get_same_modules( + $agents_to_report, + $modules_to_report + ); + $es['id_agents'] = $agents_to_report; + $es['templates'] = $alert_templates_to_report; + $es['actions'] = $alert_actions_to_report; + $es['show_summary'] = $show_summary; + $es['group_by'] = $group_by; + + $values['external_source'] = json_encode($es); + + $values['period'] = get_parameter('period'); + $values['lapse_calc'] = get_parameter( + 'lapse_calc' + ); + $values['lapse'] = get_parameter('lapse'); + + $good_format = true; + break; + case 'inventory_changes': $values['period'] = get_parameter('period'); $es['id_agents'] = get_parameter('id_agents'); diff --git a/pandora_console/include/functions_alerts.php b/pandora_console/include/functions_alerts.php index 6ca454695d..a7c05a9003 100644 --- a/pandora_console/include/functions_alerts.php +++ b/pandora_console/include/functions_alerts.php @@ -2949,3 +2949,100 @@ function alerts_get_agent_modules( return $agent_modules; } + + +function alerts_get_alert_fired($filters=[], $groupsBy=[]) +{ + $filter_group = ''; + if (isset($filters['group']) === true) { + $filter_group = sprintf('AND id_grupo = %d', $filters['group']); + } + + $filter_agents = ''; + if (isset($filters['agents']) === true) { + $filter_agents = sprintf( + 'AND id_agente IN ("%s")', + implode(',', $filters['agents']) + ); + } + + $filter_modules = ''; + if (isset($filters['modules']) === true) { + $filter_modules = sprintf( + 'AND id_agentmodule IN ("%s")', + implode(',', $filters['modules']) + ); + } + + $filter_actions = ''; + if (isset($filters['actions']) === true) { + $filter_actions = ''; + } + + $filter_templates = ''; + if (isset($filters['templates']) === true) { + $filter_templates = ''; + } + + $filter_period = ''; + if (isset($filters['period']) === true) { + $filter_period = ''; + } + + $group_by = ''; + if (isset($groupsBy['group_by']) === true) { + switch ($groupsBy['group_by']) { + case 'module': + $group_by = sprintf('GROUP BY id_agentmodule'); + break; + + case 'action': + $group_by = sprintf('GROUP BY 1'); + break; + + case 'template': + $group_by = sprintf('GROUP BY id_alert_am'); + break; + + case 'agent': + $group_by = sprintf('GROUP BY id_agente'); + break; + + default: + // Nothing. + break; + } + } + + // TODO: group by periods $groupsBy['lapse']. + $query = sprintf( + 'SELECT id_agente, id_grupo, id_agentmodule, count(*) as fired + FROM tevento + WHERE custom_data != "" + AND event_type="alert_fired" + %s + %s + %s + %s + %s + %s + AND ( + JSON_CONTAINS(custom_data, "Mail to Admin", "$.actions") = 1 + OR JSON_CONTAINS(custom_data, "Restart agent", "$.actions") = 1 + ) + %s', + $filter_group, + $filter_agents, + $filter_modules, + $filter_actions, + $filter_templates, + $filter_period, + $group_by + ); + + hd($query, '', true); + + $alert_fired = db_get_all_rows_sql($query); + + hd($alert_fired); +} diff --git a/pandora_console/include/functions_html.php b/pandora_console/include/functions_html.php index d7136bb7ce..920262be42 100644 --- a/pandora_console/include/functions_html.php +++ b/pandora_console/include/functions_html.php @@ -728,7 +728,9 @@ function html_print_select( $simple_multiple_options=false, $required=false, $truncate_size=false, - $select2_enable=true + $select2_enable=true, + $select2_multiple_enable=false, + $select2_multiple_enable_all=false ) { $output = "\n"; @@ -790,6 +792,12 @@ function html_print_select( $required = 'required'; } + if ($select2_multiple_enable === true + && $select2_multiple_enable_all === true + ) { + $output .= '
'; + } + $output .= ''; + + if ($select2_multiple_enable === true + && $select2_multiple_enable_all === true + ) { + $output .= '
'; + $output .= ''.__('All').''; + $output .= html_print_checkbox_switch( + $id.'-check-all', + 1, + false, + true, + $disabled, + 'checkMultipleAll('.$id.')' + ); + $output .= '
'; + $output .= '
'; + } + if ($modal && !enterprise_installed()) { $output .= "
@@ -900,7 +926,7 @@ function html_print_select( $select2 = 'select2_dark.min'; } - if ($multiple === false && $select2_enable === true) { + if (($multiple === false || $select2_multiple_enable === true) && $select2_enable === true) { if (is_ajax()) { $output .= ''; } diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index a1a5c3b68e..cd8a2ddcee 100755 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -734,6 +734,13 @@ function reporting_make_reporting_data( ); break; + case 'alert_report_actions': + $report['contents'][] = reporting_alert_report_actions( + $report, + $content + ); + break; + case 'agents_inventory': $report['contents'][] = reporting_agents_inventory( $report, @@ -2658,6 +2665,58 @@ function reporting_inventory($report, $content, $type) } +function reporting_alert_report_actions($report, $content) +{ + global $config; + $return = []; + + $return['type'] = 'alert_report_actions'; + if (empty($content['name']) === true) { + $content['name'] = __('Alert actions'); + } + + $return['title'] = io_safe_output($content['name']); + $return['landscape'] = $content['landscape']; + $return['pagebreak'] = $content['pagebreak']; + + $return['subtitle'] = __('Actions'); + $return['description'] = io_safe_output($content['description']); + $return['date'] = reporting_get_date_text($report, $content); + + $return['data'] = []; + + $es = json_decode($content['external_source'], true); + + $period = $content['period']; + $id_group = $content['id_group']; + $modules = $es['modules']; + $agents = $es['id_agents']; + $templates = $es['templates']; + $actions = $es['actions']; + $show_summary = $es['show_summary']; + $group_by = $es['group_by']; + $lapse = $content['lapse']; + + $filters = [ + 'group' => $id_group, + 'agents' => $agents, + 'modules' => $modules, + 'templates' => $templates, + 'actions' => $actions, + 'period' => $period, + ]; + + $goupsBy = [ + 'group_by' => $group_by, + 'lapse' => $lapse, + ]; + + alerts_get_alert_fired($filters, $goupsBy); + + return reporting_check_structure_content($return); +} + + function reporting_agent_module($report, $content) { global $config; diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index d93848c3f1..40463ddcee 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 'alert_report_actions': + reporting_html_alert_report_actions($table, $item); + break; + case 'agents_inventory': reporting_html_agents_inventory($table, $item); break; @@ -2729,6 +2733,12 @@ function reporting_html_group_configuration($table, $item, $pdf=0) } +function reporting_html_alert_report_actions($table, $item, $pdf=0) +{ + hd($item); +} + + /** * This type of report element will generate the interface graphs * of all those devices that belong to the selected group. diff --git a/pandora_console/include/functions_reports.php b/pandora_console/include/functions_reports.php index 09e3340e70..4460a34ae5 100755 --- a/pandora_console/include/functions_reports.php +++ b/pandora_console/include/functions_reports.php @@ -834,6 +834,7 @@ function reports_get_report_types($template=false, $not_editor=false) 'optgroup' => __('Alerts'), 'name' => __('Agent alert report '), ]; + if (!$template) { $types['alert_report_group'] = [ 'optgroup' => __('Alerts'), @@ -841,6 +842,11 @@ function reports_get_report_types($template=false, $not_editor=false) ]; } + $types['alert_report_actions'] = [ + 'optgroup' => __('Alerts'), + 'name' => __('Actions alert report '), + ]; + $types['event_report_module'] = [ 'optgroup' => __('Events'), 'name' => __('Module event report'), diff --git a/pandora_console/include/styles/pandora.css b/pandora_console/include/styles/pandora.css index e541c8ff97..334a48d2ea 100644 --- a/pandora_console/include/styles/pandora.css +++ b/pandora_console/include/styles/pandora.css @@ -8348,3 +8348,32 @@ div.stat-win-spinner img { #license_error_msg_dialog { min-height: 350px !important; } + +.select2-container--default + .select2-selection--multiple + .select2-selection__rendered { + padding: 5px 10px 10px !important; +} + +.select2-container--default + .select2-selection--multiple + .select2-selection__choice { + background-color: #82b92e !important; + border: 1px solid #82b92e !important; + padding: 0.3em 0.6em !important; + color: #fff; + font-size: 1em; + display: flex; + flex-direction: row; + justify-content: flex-start; + align-items: center; + align-content: center; +} + +.select2-container--default + .select2-selection--multiple + .select2-selection__choice__remove { + color: #fff !important; + font-size: 1.2em; + margin-right: 5px !important; +} From 0caeee185ee2477fdd4a341c21665e382c363bfe Mon Sep 17 00:00:00 2001 From: Daniel Barbero Martin Date: Fri, 12 Nov 2021 13:21:05 +0100 Subject: [PATCH 02/31] WIP new report alert fired actions --- .../godmode/reporting/reporting_builder.item_editor.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pandora_console/godmode/reporting/reporting_builder.item_editor.php b/pandora_console/godmode/reporting/reporting_builder.item_editor.php index 2c2802d31c..d0eb91b8ab 100755 --- a/pandora_console/godmode/reporting/reporting_builder.item_editor.php +++ b/pandora_console/godmode/reporting/reporting_builder.item_editor.php @@ -5799,6 +5799,8 @@ function chooseType() { $("#row_network_filter").hide(); $("#row_alive_ip").hide(); $("#row_agent_not_assigned_to_ip").hide(); + $("#row_show_summary").hide(); + $("#row_group_by").hide(); // SLA list default state. $("#sla_list").hide(); @@ -6119,6 +6121,8 @@ function chooseType() { $("#row_alert_actions").show(); $("#row_period").show(); $("#row_lapse").show(); + $("#row_show_summary").show(); + $("#row_group_by").show(); break; case 'event_report_group': From 8746db24c984060f1630565c56d2439bf79a5fcb Mon Sep 17 00:00:00 2001 From: Daniel Barbero Martin Date: Thu, 25 Nov 2021 08:19:05 +0100 Subject: [PATCH 03/31] demo --- pandora_console/include/styles/pandora.css | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pandora_console/include/styles/pandora.css b/pandora_console/include/styles/pandora.css index 1b441e050d..c350e62f4a 100644 --- a/pandora_console/include/styles/pandora.css +++ b/pandora_console/include/styles/pandora.css @@ -8359,6 +8359,8 @@ div.stat-win-spinner img { .select2-selection--multiple .select2-selection__rendered { padding: 5px 10px 10px !important; + max-height: 120px; + overflow: auto !important; } .select2-container--default From dae6182ef0e3aa5d4289b8a5f5175ff1654ea83a Mon Sep 17 00:00:00 2001 From: Daniel Barbero Martin Date: Thu, 25 Nov 2021 17:28:00 +0100 Subject: [PATCH 04/31] wip reports alert actions --- .../reporting_builder.item_editor.php | 21 +- .../godmode/reporting/reporting_builder.php | 4 +- pandora_console/include/functions_alerts.php | 184 ++++++++++++++---- .../include/functions_reporting.php | 2 +- 4 files changed, 162 insertions(+), 49 deletions(-) diff --git a/pandora_console/godmode/reporting/reporting_builder.item_editor.php b/pandora_console/godmode/reporting/reporting_builder.item_editor.php index 72c4038deb..13a85c6e49 100755 --- a/pandora_console/godmode/reporting/reporting_builder.item_editor.php +++ b/pandora_console/godmode/reporting/reporting_builder.item_editor.php @@ -3286,11 +3286,17 @@ $class = 'databox filters'; ]; html_print_select( $valuesGroupBy, - 'group_by', + 'group_by[]', $group_by, '', - __('None'), - '0', + '', + 0, + false, + true, + false, + '', + false, + 'min-width: 500px; max-height: 100px', false, false, false, @@ -3299,8 +3305,9 @@ $class = 'databox filters'; false, false, false, - false, - '' + true, + true, + true ); ?> @@ -4575,9 +4582,9 @@ $(document).ready (function () { jQuery.post ("ajax.php", {"page" : "operation/agentes/ver_agente", "get_modules_group_json" : 1, + "selection" : $("#selection_agent_module").val(), "id_module_group" : $("#combo_modulegroup").val(), - "id_agents" : $("#id_agents2").val(), - "selection" : $("#selection_agent_module").val() + "id_agents" : $("#id_agents2").val() }, function (data, status) { $("#module").html(''); diff --git a/pandora_console/godmode/reporting/reporting_builder.php b/pandora_console/godmode/reporting/reporting_builder.php index c6611050d8..87ddd7567c 100755 --- a/pandora_console/godmode/reporting/reporting_builder.php +++ b/pandora_console/godmode/reporting/reporting_builder.php @@ -1699,7 +1699,7 @@ switch ($action) { $alert_templates_to_report = get_parameter('alert_templates'); $alert_actions_to_report = get_parameter('alert_actions'); $show_summary = get_parameter('show_summary', 0); - $group_by = get_parameter('group_by', 0); + $group_by = get_parameter('group_by'); $es['module'] = get_same_modules( $agents_to_report, @@ -2475,7 +2475,7 @@ switch ($action) { $alert_templates_to_report = get_parameter('alert_templates'); $alert_actions_to_report = get_parameter('alert_actions'); $show_summary = get_parameter('show_summary', 0); - $group_by = get_parameter('group_by', 0); + $group_by = get_parameter('group_by'); $es['module'] = get_same_modules( $agents_to_report, diff --git a/pandora_console/include/functions_alerts.php b/pandora_console/include/functions_alerts.php index 191cd4d4b8..77524b019a 100644 --- a/pandora_console/include/functions_alerts.php +++ b/pandora_console/include/functions_alerts.php @@ -2839,17 +2839,68 @@ function alerts_get_agent_modules( } +function alerts_get_actions_names($actions, $reduce=false) +{ + if (empty($actions) === true) { + return []; + } + + $where = ''; + if (is_array($actions) === true) { + $where = sprintf( + 'id IN (%s)', + implode(',', $actions) + ); + } else { + $where = sprintf(' id = %d', $actions); + } + + $sqltest = sprintf( + 'SELECT id, `name` + FROM talert_actions + WHERE %s', + $where + ); + + $result = db_get_all_rows_sql($sqltest); + + if ($result === false) { + $result = []; + } + + if ($reduce === true) { + $result = array_reduce( + $result, + function ($carry, $item) { + $carry[$item['id']] = $item['name']; + return $carry; + }, + [] + ); + } + + return $result; +} + + function alerts_get_alert_fired($filters=[], $groupsBy=[]) { + global $config; + + $filter_date = ''; + if (isset($filters['period']) === true && empty($filters['period']) === false) { + $filter_date = sprintf('AND utimestamp > %d', (time() - $filters['period'])); + } + $filter_group = ''; - if (isset($filters['group']) === true) { + if (isset($filters['group']) === true && empty($filters['group']) === false) { $filter_group = sprintf('AND id_grupo = %d', $filters['group']); } $filter_agents = ''; if (isset($filters['agents']) === true) { $filter_agents = sprintf( - 'AND id_agente IN ("%s")', + 'AND id_agente IN (%s)', implode(',', $filters['agents']) ); } @@ -2857,55 +2908,110 @@ function alerts_get_alert_fired($filters=[], $groupsBy=[]) $filter_modules = ''; if (isset($filters['modules']) === true) { $filter_modules = sprintf( - 'AND id_agentmodule IN ("%s")', + 'AND id_agentmodule IN (%s)', implode(',', $filters['modules']) ); } - $filter_actions = ''; - if (isset($filters['actions']) === true) { - $filter_actions = ''; - } - $filter_templates = ''; if (isset($filters['templates']) === true) { - $filter_templates = ''; + $filter_templates = sprintf( + 'AND id_alert_am IN (%s)', + implode(',', $filters['templates']) + ); } - $filter_period = ''; - if (isset($filters['period']) === true) { - $filter_period = ''; + $filter_actions = ''; + $fields_actions = []; + if (isset($filters['actions']) === true) { + $actions_names = alerts_get_actions_names($filters['actions'], true); + $filter_actions .= 'AND ( '; + $first = true; + foreach ($actions_names as $name_action) { + if ($first === false) { + $filter_actions .= ' OR '; + } + + $filter_actions .= sprintf( + "JSON_CONTAINS(custom_data, '\"%s\"', '\$.actions')", + io_safe_output($name_action) + ); + + $fields_actions[$name_action] = sprintf( + "SUM(JSON_CONTAINS(custom_data, '\"%s\"', '\$.actions')) as '%s'", + io_safe_output($name_action), + io_safe_output($name_action) + ); + + $first = false; + } + + $filter_actions .= ' ) '; } - $group_by = ''; + $group_array = []; + $fields = ['COUNT(tevento.id_evento) as fired']; if (isset($groupsBy['group_by']) === true) { - switch ($groupsBy['group_by']) { - case 'module': - $group_by = sprintf('GROUP BY id_agentmodule'); - break; + foreach ($groupsBy['group_by'] as $groupBy) { + switch ($groupBy) { + case 'module': + $fields[] = 'id_agentmodule'; + $group_array[] = 'id_agentmodule'; + break; - case 'action': - $group_by = sprintf('GROUP BY 1'); - break; + case 'action': + if (is_array($fields_actions) === true + && empty($fields_actions) === false + ) { + foreach ($fields_actions as $name => $field) { + $fields[] = $field; + $group_array[] = '"'.$name.'"'; + } + } + break; - case 'template': - $group_by = sprintf('GROUP BY id_alert_am'); - break; + case 'template': + $fields[] = 'talert_template_modules.id_alert_template as id_template'; + $group_array[] = 'talert_template_modules.id_alert_template'; + break; - case 'agent': - $group_by = sprintf('GROUP BY id_agente'); - break; + case 'agent': + $fields[] = 'id_agente as id_agent'; + $group_array[] = 'id_agente'; + break; - default: - // Nothing. - break; + case 'group': + $fields[] = 'id_grupo as id_group'; + $group_array[] = 'id_grupo'; + break; + + default: + // Nothing. + break; + } } } - // TODO: group by periods $groupsBy['lapse']. + if (isset($groupsBy['lapse']) === true) { + $fields[] = sprintf( + 'ROUND((CEILING(UNIX_TIMESTAMP(`timestamp`) / %d) * %d)) AS period', + (int) $groupsBy['lapse'], + (int) $groupsBy['lapse'] + ); + $group_array[] = 'period'; + } + + $group_by = ''; + if (is_array($group_array) === true && empty($group_array) === false) { + $group_by = sprintf(' GROUP BY %s', implode(", \n", $group_array)); + } + $query = sprintf( - 'SELECT id_agente, id_grupo, id_agentmodule, count(*) as fired + 'SELECT + %s FROM tevento + INNER JOIN talert_template_modules + ON talert_template_modules.id = tevento.id_alert_am WHERE custom_data != "" AND event_type="alert_fired" %s @@ -2914,23 +3020,23 @@ function alerts_get_alert_fired($filters=[], $groupsBy=[]) %s %s %s - AND ( - JSON_CONTAINS(custom_data, "Mail to Admin", "$.actions") = 1 - OR JSON_CONTAINS(custom_data, "Restart agent", "$.actions") = 1 - ) %s', + implode(", \n", $fields), + $filter_date, $filter_group, $filter_agents, $filter_modules, $filter_actions, $filter_templates, - $filter_period, $group_by ); - hd($query, '', true); + $data = db_get_all_rows_sql($query); - $alert_fired = db_get_all_rows_sql($query); + // TODO :XXx + hd($data); - hd($alert_fired); + foreach ($data as $key => $value) { + hd(date('y-m-d h:i:s', $value['period'])); + } } diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index bc0665283f..1ad9b7cc16 100755 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -2689,7 +2689,7 @@ function reporting_alert_report_actions($report, $content) $period = $content['period']; $id_group = $content['id_group']; - $modules = $es['modules']; + $modules = $es['module']; $agents = $es['id_agents']; $templates = $es['templates']; $actions = $es['actions']; From 780d2bf87de1ad4d0fc1e41fd8fcd242be0d178d Mon Sep 17 00:00:00 2001 From: Daniel Barbero Martin Date: Fri, 26 Nov 2021 11:43:57 +0100 Subject: [PATCH 05/31] wip reports alert actions --- .../reporting_builder.item_editor.php | 49 ++++++++++++++++--- .../godmode/reporting/reporting_builder.php | 48 +++++++++++++++--- pandora_console/include/functions_alerts.php | 38 ++++++++++---- 3 files changed, 112 insertions(+), 23 deletions(-) diff --git a/pandora_console/godmode/reporting/reporting_builder.item_editor.php b/pandora_console/godmode/reporting/reporting_builder.item_editor.php index 13a85c6e49..fe1ba14bf3 100755 --- a/pandora_console/godmode/reporting/reporting_builder.item_editor.php +++ b/pandora_console/godmode/reporting/reporting_builder.item_editor.php @@ -752,17 +752,24 @@ switch ($action) { hd('1'); $description = $item['description']; $es = json_decode($item['external_source'], true); - $id_agents = $es['id_agents']; + + hd($es); + + hd(base64_decode($es['id_agents'])); + + // Decode agents and modules. + $id_agents = json_decode( + io_safe_output(base64_decode($es['id_agents'])), + true + ); + $module = json_decode( + io_safe_output(base64_decode($es['module'])), + true + ); $selection_a_m = get_parameter('selection'); $recursion = $item['recursion']; - if ((count($es['module']) == 1) && ($es['module'][0] == 0)) { - $module = ''; - } else { - $module = $es['module']; - } - $group = $item['id_group']; $modulegroup = $item['id_module_group']; $idAgentModule = $module; @@ -1725,6 +1732,11 @@ $class = 'databox filters'; true, true ); + + html_print_input_hidden( + 'id_agents2-multiple-text', + json_encode($agents_select) + ); ?> @@ -1814,6 +1826,11 @@ $class = 'databox filters'; true, true ); + + html_print_input_hidden( + 'module-multiple-text', + json_encode($agents_select) + ); ?> @@ -4712,6 +4729,14 @@ $(document).ready (function () { } switch (type){ + case 'alert_report_actions': + var agents_multiple = $('#id_agents2').val(); + var modules_multiple = $('#module').val(); + $('#hidden-id_agents2-multiple-text').val(JSON.stringify(agents_multiple)); + $('#hidden-module-multiple-text').val(JSON.stringify(modules_multiple)); + $('#id_agents2').val(''); + $('#module').val(''); + break; case 'alert_report_module': case 'alert_report_agent': case 'event_report_agent': @@ -4850,6 +4875,16 @@ $(document).ready (function () { return false; } switch (type){ + case 'alert_report_actions': + var agents_multiple = $('#id_agents2').val(); + var modules_multiple = $('#module').val(); + console.log(agents_multiple); + console.log(modules_multiple); + $('#hidden-id_agents2-multiple-text').val(JSON.stringify(agents_multiple)); + $('#hidden-module-multiple-text').val(JSON.stringify(modules_multiple)); + $('#id_agents2').val(''); + $('#module').val(''); + break; case 'alert_report_module': case 'alert_report_agent': case 'event_report_agent': diff --git a/pandora_console/godmode/reporting/reporting_builder.php b/pandora_console/godmode/reporting/reporting_builder.php index 87ddd7567c..f429cc6c06 100755 --- a/pandora_console/godmode/reporting/reporting_builder.php +++ b/pandora_console/godmode/reporting/reporting_builder.php @@ -1693,24 +1693,40 @@ switch ($action) { break; case 'alert_report_actions': - hd('3'); - $agents_to_report = get_parameter('id_agents2'); - $modules_to_report = get_parameter('module', ''); $alert_templates_to_report = get_parameter('alert_templates'); $alert_actions_to_report = get_parameter('alert_actions'); $show_summary = get_parameter('show_summary', 0); $group_by = get_parameter('group_by'); + hd('3'); + $agents_to_report_text = get_parameter('id_agents2-multiple-text'); + $modules_to_report_text = get_parameter('module-multiple-text', ''); + + // Decode json check modules. + $agents_to_report = json_decode( + io_safe_output($agents_to_report_text), + true + ); + $modules_to_report = json_decode( + io_safe_output($modules_to_report_text), + true + ); $es['module'] = get_same_modules( $agents_to_report, $modules_to_report ); - $es['id_agents'] = $agents_to_report; + + // Encode json modules and agents. + $es['module'] = base64_encode(json_encode($es['module'])); + $es['id_agents'] = base64_encode(json_encode($agents_to_report)); + $es['templates'] = $alert_templates_to_report; $es['actions'] = $alert_actions_to_report; $es['show_summary'] = $show_summary; $es['group_by'] = $group_by; + hd($es); + $values['external_source'] = json_encode($es); $values['period'] = get_parameter('period'); @@ -2470,23 +2486,41 @@ switch ($action) { case 'alert_report_actions': hd('2'); - $agents_to_report = get_parameter('id_agents2'); - $modules_to_report = get_parameter('module', ''); $alert_templates_to_report = get_parameter('alert_templates'); $alert_actions_to_report = get_parameter('alert_actions'); $show_summary = get_parameter('show_summary', 0); $group_by = get_parameter('group_by'); + $agents_to_report_text = get_parameter('id_agents2-multiple-text'); + $modules_to_report_text = get_parameter('module-multiple-text', ''); + + // Decode json check modules. + $agents_to_report = json_decode( + io_safe_output($agents_to_report_text), + true + ); + $modules_to_report = json_decode( + io_safe_output($modules_to_report_text), + true + ); + $es['module'] = get_same_modules( $agents_to_report, $modules_to_report ); - $es['id_agents'] = $agents_to_report; + + // Encode json modules and agents. + $es['module'] = base64_encode(json_encode($es['module'])); + $es['id_agents'] = base64_encode(json_encode($agents_to_report)); + $es['templates'] = $alert_templates_to_report; $es['actions'] = $alert_actions_to_report; $es['show_summary'] = $show_summary; $es['group_by'] = $group_by; + + hd($es); + $values['external_source'] = json_encode($es); $values['period'] = get_parameter('period'); diff --git a/pandora_console/include/functions_alerts.php b/pandora_console/include/functions_alerts.php index 77524b019a..1dc3adac59 100644 --- a/pandora_console/include/functions_alerts.php +++ b/pandora_console/include/functions_alerts.php @@ -2888,17 +2888,23 @@ function alerts_get_alert_fired($filters=[], $groupsBy=[]) global $config; $filter_date = ''; - if (isset($filters['period']) === true && empty($filters['period']) === false) { + if (isset($filters['period']) === true + && empty($filters['period']) === false + ) { $filter_date = sprintf('AND utimestamp > %d', (time() - $filters['period'])); } $filter_group = ''; - if (isset($filters['group']) === true && empty($filters['group']) === false) { + if (isset($filters['group']) === true + && empty($filters['group']) === false + ) { $filter_group = sprintf('AND id_grupo = %d', $filters['group']); } $filter_agents = ''; - if (isset($filters['agents']) === true) { + if (isset($filters['agents']) === true + && empty($filters['agents']) === false + ) { $filter_agents = sprintf( 'AND id_agente IN (%s)', implode(',', $filters['agents']) @@ -2906,15 +2912,21 @@ function alerts_get_alert_fired($filters=[], $groupsBy=[]) } $filter_modules = ''; - if (isset($filters['modules']) === true) { + if (isset($filters['modules']) === true + && empty($filters['modules']) === false + ) { $filter_modules = sprintf( 'AND id_agentmodule IN (%s)', implode(',', $filters['modules']) ); } + hd($filters['templates']); + $filter_templates = ''; - if (isset($filters['templates']) === true) { + if (isset($filters['templates']) === true + && empty($filters['templates']) === false + ) { $filter_templates = sprintf( 'AND id_alert_am IN (%s)', implode(',', $filters['templates']) @@ -2923,7 +2935,9 @@ function alerts_get_alert_fired($filters=[], $groupsBy=[]) $filter_actions = ''; $fields_actions = []; - if (isset($filters['actions']) === true) { + if (isset($filters['actions']) === true + && empty($filters['actions']) === false + ) { $actions_names = alerts_get_actions_names($filters['actions'], true); $filter_actions .= 'AND ( '; $first = true; @@ -2951,7 +2965,9 @@ function alerts_get_alert_fired($filters=[], $groupsBy=[]) $group_array = []; $fields = ['COUNT(tevento.id_evento) as fired']; - if (isset($groupsBy['group_by']) === true) { + if (isset($groupsBy['group_by']) === true + && empty($filters['group_by']) === false + ) { foreach ($groupsBy['group_by'] as $groupBy) { switch ($groupBy) { case 'module': @@ -2992,7 +3008,9 @@ function alerts_get_alert_fired($filters=[], $groupsBy=[]) } } - if (isset($groupsBy['lapse']) === true) { + if (isset($groupsBy['lapse']) === true + && empty($filters['lapse']) === false + ) { $fields[] = sprintf( 'ROUND((CEILING(UNIX_TIMESTAMP(`timestamp`) / %d) * %d)) AS period', (int) $groupsBy['lapse'], @@ -3037,6 +3055,8 @@ function alerts_get_alert_fired($filters=[], $groupsBy=[]) hd($data); foreach ($data as $key => $value) { - hd(date('y-m-d h:i:s', $value['period'])); + if (isset($value['period']) === true) { + hd(date('y-m-d h:i:s', $value['period'])); + } } } From 0b04ba44f2e9fcec9ec2d3b1912c285192eee5c9 Mon Sep 17 00:00:00 2001 From: Daniel Barbero Martin Date: Fri, 26 Nov 2021 12:15:39 +0100 Subject: [PATCH 06/31] wip reports alert actions --- .../reporting_builder.item_editor.php | 6 --- .../godmode/reporting/reporting_builder.php | 5 --- pandora_console/include/functions_modules.php | 42 ++++++++++++++++++- 3 files changed, 41 insertions(+), 12 deletions(-) diff --git a/pandora_console/godmode/reporting/reporting_builder.item_editor.php b/pandora_console/godmode/reporting/reporting_builder.item_editor.php index fe1ba14bf3..cc641891e6 100755 --- a/pandora_console/godmode/reporting/reporting_builder.item_editor.php +++ b/pandora_console/godmode/reporting/reporting_builder.item_editor.php @@ -753,10 +753,6 @@ switch ($action) { $description = $item['description']; $es = json_decode($item['external_source'], true); - hd($es); - - hd(base64_decode($es['id_agents'])); - // Decode agents and modules. $id_agents = json_decode( io_safe_output(base64_decode($es['id_agents'])), @@ -4878,8 +4874,6 @@ $(document).ready (function () { case 'alert_report_actions': var agents_multiple = $('#id_agents2').val(); var modules_multiple = $('#module').val(); - console.log(agents_multiple); - console.log(modules_multiple); $('#hidden-id_agents2-multiple-text').val(JSON.stringify(agents_multiple)); $('#hidden-module-multiple-text').val(JSON.stringify(modules_multiple)); $('#id_agents2').val(''); diff --git a/pandora_console/godmode/reporting/reporting_builder.php b/pandora_console/godmode/reporting/reporting_builder.php index f429cc6c06..26be0e954d 100755 --- a/pandora_console/godmode/reporting/reporting_builder.php +++ b/pandora_console/godmode/reporting/reporting_builder.php @@ -1725,8 +1725,6 @@ switch ($action) { $es['show_summary'] = $show_summary; $es['group_by'] = $group_by; - hd($es); - $values['external_source'] = json_encode($es); $values['period'] = get_parameter('period'); @@ -2518,9 +2516,6 @@ switch ($action) { $es['show_summary'] = $show_summary; $es['group_by'] = $group_by; - - hd($es); - $values['external_source'] = json_encode($es); $values['period'] = get_parameter('period'); diff --git a/pandora_console/include/functions_modules.php b/pandora_console/include/functions_modules.php index eaa44fe741..7d02fc3d63 100755 --- a/pandora_console/include/functions_modules.php +++ b/pandora_console/include/functions_modules.php @@ -1435,6 +1435,45 @@ function modules_get_agentmodule_name($id_agente_modulo) } +/** + * Get the module names of an agent module. + * + * @param array $array_ids Agents module ids. + * + * @return array Id => name. + */ +function modules_get_agentmodule_name_array($array_ids) +{ + if (is_array($array_ids) === false || empty($array_ids) === true) { + return []; + } + + $sql = sprintf( + 'SELECT id_agente_modulo as id, nombre as `name` + FROM tagente_modulo + WHERE id_agente_modulo IN (%s)', + implode(',', $array_ids) + ); + + $result = db_get_all_rows_sql($sql); + + if ($result === false) { + $result = []; + } + + $result = array_reduce( + $result, + function ($carry, $item) { + $carry[$item['id']] = $item['name']; + return $carry; + }, + [] + ); + + return $result; +} + + /** * Get the module descripcion of an agent module. * @@ -3471,10 +3510,11 @@ function modules_get_agentmodule_mininterval_no_async($id_agent) function get_same_modules($agents, $modules) { + $name_modules = modules_get_agentmodule_name_array(array_values($modules)); $modules_to_report = []; if ($modules != '') { foreach ($modules as $m) { - $module_name = modules_get_agentmodule_name($m); + $module_name = $name_modules[$m]; foreach ($agents as $a) { $module_in_agent = db_get_value_filter( 'id_agente_modulo', From be5fe18762a372157be3afcb9d908e126106625b Mon Sep 17 00:00:00 2001 From: Daniel Barbero Martin Date: Fri, 26 Nov 2021 13:23:46 +0100 Subject: [PATCH 07/31] wip reports alert actions --- pandora_console/include/functions_modules.php | 49 +++++++++++-------- 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/pandora_console/include/functions_modules.php b/pandora_console/include/functions_modules.php index 7d02fc3d63..9a0b866b15 100755 --- a/pandora_console/include/functions_modules.php +++ b/pandora_console/include/functions_modules.php @@ -3511,30 +3511,39 @@ function modules_get_agentmodule_mininterval_no_async($id_agent) function get_same_modules($agents, $modules) { $name_modules = modules_get_agentmodule_name_array(array_values($modules)); - $modules_to_report = []; - if ($modules != '') { - foreach ($modules as $m) { - $module_name = $name_modules[$m]; - foreach ($agents as $a) { - $module_in_agent = db_get_value_filter( - 'id_agente_modulo', - 'tagente_modulo', - [ - 'id_agente' => $a, - 'nombre' => $module_name, - ] - ); - if ($module_in_agent) { - $modules_to_report[] = $module_in_agent; - } - } - } + + $sql = sprintf( + 'SELECT id_agente_modulo as id + FROM tagente_modulo + WHERE id_agente IN (%s)', + implode(',', array_values($agents)) + ); + + hd('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'); + hd($sql); + + $all = db_get_all_rows_sql($sql); + + if ($all === false) { + $all = []; } - $modules_to_report = array_merge($modules_to_report, $modules); + $all = array_reduce( + $all, + function ($carry, $item) use ($name_modules) { + if (isset($name_modules[$item['id']]) === true) { + $carry[$item['id']] = $item['id']; + } + + return $carry; + }, + [] + ); + + $modules_to_report = array_merge($all, $modules); $modules_to_report = array_unique($modules_to_report); - return $modules_to_report; + return $all; } From cb0039d7a712f7c8ed69a6b402ed6813c97a4f40 Mon Sep 17 00:00:00 2001 From: Daniel Barbero Martin Date: Fri, 26 Nov 2021 13:52:15 +0100 Subject: [PATCH 08/31] wip reports alert actions --- .../reporting/reporting_builder.item_editor.php | 14 ++++++++++---- pandora_console/operation/agentes/ver_agente.php | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/pandora_console/godmode/reporting/reporting_builder.item_editor.php b/pandora_console/godmode/reporting/reporting_builder.item_editor.php index cc641891e6..e44310a349 100755 --- a/pandora_console/godmode/reporting/reporting_builder.item_editor.php +++ b/pandora_console/godmode/reporting/reporting_builder.item_editor.php @@ -1772,18 +1772,24 @@ $class = 'databox filters'; $all_modules = ''; } else { $all_modules = db_get_all_rows_sql( - 'SELECT DISTINCT nombre, id_agente_modulo FROM - tagente_modulo WHERE id_agente IN ('.implode(',', array_values($id_agents)).')' + sprintf( + 'SELECT nombre, id_agente_modulo + FROM tagente_modulo + WHERE id_agente IN (%s)', + implode(',', array_values($id_agents)) + ) ); } - if ((empty($all_modules)) || $all_modules == -1) { + if (empty($all_modules) === 1 || $all_modules == -1) { $all_modules = []; } $modules_select = []; $all_modules_structured = []; - if (is_array($idAgentModule) || is_object($idAgentModule)) { + if (is_array($idAgentModule) === true + || is_object($idAgentModule) === true + ) { foreach ($all_modules as $key => $a) { foreach ($idAgentModule as $id) { if ((int) $a['id_agente_modulo'] === (int) $id) { diff --git a/pandora_console/operation/agentes/ver_agente.php b/pandora_console/operation/agentes/ver_agente.php index 10665095c2..b029bdf958 100644 --- a/pandora_console/operation/agentes/ver_agente.php +++ b/pandora_console/operation/agentes/ver_agente.php @@ -310,7 +310,7 @@ if (is_ajax()) { echo json_encode($modules); } else { - select_modules_for_agent_group($id_group, $id_agents, $selection); + select_modules_for_agent_group($id_group, $id_agents, $selection, false); } } From 960c2de6c31d83cc287c3912d0aeaf8b541c2d9f Mon Sep 17 00:00:00 2001 From: Daniel Barbero Martin Date: Fri, 26 Nov 2021 14:06:10 +0100 Subject: [PATCH 09/31] wip reports alert actions --- .../reporting/reporting_builder.item_editor.php | 13 +++++++------ pandora_console/include/functions_alerts.php | 2 -- pandora_console/include/functions_modules.php | 3 --- pandora_console/operation/agentes/ver_agente.php | 3 ++- 4 files changed, 9 insertions(+), 12 deletions(-) diff --git a/pandora_console/godmode/reporting/reporting_builder.item_editor.php b/pandora_console/godmode/reporting/reporting_builder.item_editor.php index e44310a349..b37050b628 100755 --- a/pandora_console/godmode/reporting/reporting_builder.item_editor.php +++ b/pandora_console/godmode/reporting/reporting_builder.item_editor.php @@ -4586,8 +4586,8 @@ $(document).ready (function () { $("#checkbox-module-check-all").prop('checked', false); jQuery.each (data, function (id, value) { option = $("") - .attr ("value", value["id_agente_modulo"]) - .html (value["nombre"]); + .attr ("value", id) + .html (value); $("#module").append (option); }); }, @@ -4609,11 +4609,12 @@ $(document).ready (function () { $("#module").html(''); // Check module all. $("#checkbox-module-check-all").prop('checked', false); + console.log(data); if(data){ jQuery.each (data, function (id, value) { option = $("") - .attr ("value", value["id_agente_modulo"]) - .html (value["nombre"]); + .attr ("value", id) + .html (value); $("#module").append (option); }); } @@ -4639,8 +4640,8 @@ $(document).ready (function () { if(data){ jQuery.each (data, function (id, value) { option = $("") - .attr ("value", value["id_agente_modulo"]) - .html (value["nombre"]); + .attr ("value", id) + .html (value); $("#module").append (option); }); } diff --git a/pandora_console/include/functions_alerts.php b/pandora_console/include/functions_alerts.php index 1dc3adac59..ac551944ba 100644 --- a/pandora_console/include/functions_alerts.php +++ b/pandora_console/include/functions_alerts.php @@ -2921,8 +2921,6 @@ function alerts_get_alert_fired($filters=[], $groupsBy=[]) ); } - hd($filters['templates']); - $filter_templates = ''; if (isset($filters['templates']) === true && empty($filters['templates']) === false diff --git a/pandora_console/include/functions_modules.php b/pandora_console/include/functions_modules.php index 9a0b866b15..b9a737e1d7 100755 --- a/pandora_console/include/functions_modules.php +++ b/pandora_console/include/functions_modules.php @@ -3519,9 +3519,6 @@ function get_same_modules($agents, $modules) implode(',', array_values($agents)) ); - hd('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'); - hd($sql); - $all = db_get_all_rows_sql($sql); if ($all === false) { diff --git a/pandora_console/operation/agentes/ver_agente.php b/pandora_console/operation/agentes/ver_agente.php index b029bdf958..cbbdd9e925 100644 --- a/pandora_console/operation/agentes/ver_agente.php +++ b/pandora_console/operation/agentes/ver_agente.php @@ -310,7 +310,8 @@ if (is_ajax()) { echo json_encode($modules); } else { - select_modules_for_agent_group($id_group, $id_agents, $selection, false); + $modules = select_modules_for_agent_group($id_group, $id_agents, $selection, false); + echo json_encode($modules); } } From 81277246a5fde8cd748af76e6dd7408ee35f24fb Mon Sep 17 00:00:00 2001 From: Daniel Barbero Martin Date: Fri, 26 Nov 2021 14:10:21 +0100 Subject: [PATCH 10/31] wip reports alert actions --- .../godmode/reporting/reporting_builder.item_editor.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandora_console/godmode/reporting/reporting_builder.item_editor.php b/pandora_console/godmode/reporting/reporting_builder.item_editor.php index b37050b628..11262f2ddd 100755 --- a/pandora_console/godmode/reporting/reporting_builder.item_editor.php +++ b/pandora_console/godmode/reporting/reporting_builder.item_editor.php @@ -1773,7 +1773,7 @@ $class = 'databox filters'; } else { $all_modules = db_get_all_rows_sql( sprintf( - 'SELECT nombre, id_agente_modulo + 'SELECT distinct(nombre), id_agente_modulo FROM tagente_modulo WHERE id_agente IN (%s)', implode(',', array_values($id_agents)) From 1d7c27c64da47ec103d226a297bdcc4da4c91ed2 Mon Sep 17 00:00:00 2001 From: Daniel Barbero Martin Date: Fri, 26 Nov 2021 14:29:46 +0100 Subject: [PATCH 11/31] wip reports alert actions --- .../reporting_builder.item_editor.php | 45 +++++++++---------- 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/pandora_console/godmode/reporting/reporting_builder.item_editor.php b/pandora_console/godmode/reporting/reporting_builder.item_editor.php index 11262f2ddd..ba39816bf7 100755 --- a/pandora_console/godmode/reporting/reporting_builder.item_editor.php +++ b/pandora_console/godmode/reporting/reporting_builder.item_editor.php @@ -1768,43 +1768,38 @@ $class = 'databox filters'; $a) { - foreach ($idAgentModule as $id) { - if ((int) $a['id_agente_modulo'] === (int) $id) { - $modules_select[$a['id_agente_modulo']] = $a['id_agente_modulo']; - } - } - } - } - - foreach ($all_modules as $a) { - $all_modules_structured[$a['id_agente_modulo']] = $a['nombre']; - } + $modules_select = get_same_modules( + array_values($id_agents), + array_values($idAgentModule) + ); html_print_select( - $all_modules_structured, + $all_modules, 'module[]', $modules_select, $script = '', From e8bf86a789ec565d1b598fcc591cfbbe1e95fe39 Mon Sep 17 00:00:00 2001 From: Daniel Barbero Martin Date: Mon, 29 Nov 2021 17:55:09 +0100 Subject: [PATCH 12/31] wip reports alert actions --- .../reporting_builder.item_editor.php | 39 ++- pandora_console/include/functions_agents.php | 39 +++ pandora_console/include/functions_alerts.php | 269 +++++++++++++----- pandora_console/include/functions_modules.php | 5 +- .../include/functions_reporting.php | 31 +- .../include/functions_reporting_html.php | 54 +++- 6 files changed, 338 insertions(+), 99 deletions(-) diff --git a/pandora_console/godmode/reporting/reporting_builder.item_editor.php b/pandora_console/godmode/reporting/reporting_builder.item_editor.php index ba39816bf7..6562813f2a 100755 --- a/pandora_console/godmode/reporting/reporting_builder.item_editor.php +++ b/pandora_console/godmode/reporting/reporting_builder.item_editor.php @@ -1770,6 +1770,7 @@ $class = 'databox filters'; 'Agent', - 'module' => 'Module', - 'action' => 'Action', - 'template' => 'Template', + 'agent' => __('Agent'), + 'module' => __('Module'), + 'group' => __('Group'), + 'template' => __('Template'), ]; + html_print_select( $valuesGroupBy, - 'group_by[]', + 'group_by', $group_by, '', - '', + __('None'), 0, false, - true, + false, false, '', false, - 'min-width: 500px; max-height: 100px', + '', false, false, false, @@ -3319,8 +3330,6 @@ $class = 'databox filters'; false, false, false, - true, - true, true ); ?> diff --git a/pandora_console/include/functions_agents.php b/pandora_console/include/functions_agents.php index 28f563b8e7..ff8f618f10 100644 --- a/pandora_console/include/functions_agents.php +++ b/pandora_console/include/functions_agents.php @@ -1649,6 +1649,45 @@ function agents_get_name($id_agent, $case='none') } +/** + * Get the agents names of an agent. + * + * @param array $array_ids Agents ids. + * + * @return array Id => name. + */ +function agents_get_alias_array($array_ids) +{ + if (is_array($array_ids) === false || empty($array_ids) === true) { + return []; + } + + $sql = sprintf( + 'SELECT id_agente as id, alias as `name` + FROM tagente + WHERE id_agente IN (%s)', + implode(',', $array_ids) + ); + + $result = db_get_all_rows_sql($sql); + + if ($result === false) { + $result = []; + } + + $result = array_reduce( + $result, + function ($carry, $item) { + $carry[$item['id']] = $item['name']; + return $carry; + }, + [] + ); + + return $result; +} + + /** * Get alias of an agent (cached function). * diff --git a/pandora_console/include/functions_alerts.php b/pandora_console/include/functions_alerts.php index ac551944ba..d8cbdeee40 100644 --- a/pandora_console/include/functions_alerts.php +++ b/pandora_console/include/functions_alerts.php @@ -2841,28 +2841,26 @@ function alerts_get_agent_modules( function alerts_get_actions_names($actions, $reduce=false) { - if (empty($actions) === true) { - return []; - } - $where = ''; - if (is_array($actions) === true) { - $where = sprintf( - 'id IN (%s)', - implode(',', $actions) - ); - } else { - $where = sprintf(' id = %d', $actions); + if (empty($actions) === false) { + if (is_array($actions) === true) { + $where = sprintf( + 'WHERE id IN (%s)', + implode(',', $actions) + ); + } else { + $where = sprintf('WHERE id = %d', $actions); + } } - $sqltest = sprintf( + $sql = sprintf( 'SELECT id, `name` FROM talert_actions - WHERE %s', + %s', $where ); - $result = db_get_all_rows_sql($sqltest); + $result = db_get_all_rows_sql($sql); if ($result === false) { $result = []; @@ -2883,22 +2881,30 @@ function alerts_get_actions_names($actions, $reduce=false) } -function alerts_get_alert_fired($filters=[], $groupsBy=[]) +function alerts_get_alert_fired($filters=[], $groupsBy=[], $total=false) { global $config; + hd(5); + $filter_date = ''; if (isset($filters['period']) === true && empty($filters['period']) === false ) { - $filter_date = sprintf('AND utimestamp > %d', (time() - $filters['period'])); + $filter_date = sprintf( + 'AND tevento.utimestamp > %d', + (time() - $filters['period']) + ); } $filter_group = ''; if (isset($filters['group']) === true && empty($filters['group']) === false ) { - $filter_group = sprintf('AND id_grupo = %d', $filters['group']); + $filter_group = sprintf( + 'AND tevento.id_grupo = %d', + $filters['group'] + ); } $filter_agents = ''; @@ -2906,7 +2912,7 @@ function alerts_get_alert_fired($filters=[], $groupsBy=[]) && empty($filters['agents']) === false ) { $filter_agents = sprintf( - 'AND id_agente IN (%s)', + 'AND tevento.id_agente IN (%s)', implode(',', $filters['agents']) ); } @@ -2916,7 +2922,7 @@ function alerts_get_alert_fired($filters=[], $groupsBy=[]) && empty($filters['modules']) === false ) { $filter_modules = sprintf( - 'AND id_agentmodule IN (%s)', + 'AND tevento.id_agentmodule IN (%s)', implode(',', $filters['modules']) ); } @@ -2926,17 +2932,21 @@ function alerts_get_alert_fired($filters=[], $groupsBy=[]) && empty($filters['templates']) === false ) { $filter_templates = sprintf( - 'AND id_alert_am IN (%s)', + 'AND talert_template_modules.id_alert_template IN (%s)', implode(',', $filters['templates']) ); } + // TODO: ALL; + $actions_names = alerts_get_actions_names($filters['actions'], true); + + $group_array = []; + $filter_actions = ''; $fields_actions = []; if (isset($filters['actions']) === true && empty($filters['actions']) === false ) { - $actions_names = alerts_get_actions_names($filters['actions'], true); $filter_actions .= 'AND ( '; $first = true; foreach ($actions_names as $name_action) { @@ -2945,12 +2955,12 @@ function alerts_get_alert_fired($filters=[], $groupsBy=[]) } $filter_actions .= sprintf( - "JSON_CONTAINS(custom_data, '\"%s\"', '\$.actions')", + "JSON_CONTAINS(tevento.custom_data, '\"%s\"', '\$.actions')", io_safe_output($name_action) ); $fields_actions[$name_action] = sprintf( - "SUM(JSON_CONTAINS(custom_data, '\"%s\"', '\$.actions')) as '%s'", + "SUM(JSON_CONTAINS(tevento.custom_data, '\"%s\"', '\$.actions')) as '%s'", io_safe_output($name_action), io_safe_output($name_action) ); @@ -2959,58 +2969,84 @@ function alerts_get_alert_fired($filters=[], $groupsBy=[]) } $filter_actions .= ' ) '; - } - - $group_array = []; - $fields = ['COUNT(tevento.id_evento) as fired']; - if (isset($groupsBy['group_by']) === true - && empty($filters['group_by']) === false - ) { - foreach ($groupsBy['group_by'] as $groupBy) { - switch ($groupBy) { - case 'module': - $fields[] = 'id_agentmodule'; - $group_array[] = 'id_agentmodule'; - break; - - case 'action': - if (is_array($fields_actions) === true - && empty($fields_actions) === false - ) { - foreach ($fields_actions as $name => $field) { - $fields[] = $field; - $group_array[] = '"'.$name.'"'; - } - } - break; - - case 'template': - $fields[] = 'talert_template_modules.id_alert_template as id_template'; - $group_array[] = 'talert_template_modules.id_alert_template'; - break; - - case 'agent': - $fields[] = 'id_agente as id_agent'; - $group_array[] = 'id_agente'; - break; - - case 'group': - $fields[] = 'id_grupo as id_group'; - $group_array[] = 'id_grupo'; - break; - - default: - // Nothing. - break; - } + } else { + foreach ($actions_names as $name_action) { + $fields[] = sprintf( + "SUM(JSON_CONTAINS(tevento.custom_data, '\"%s\"', '\$.actions')) as '%s'", + io_safe_output($name_action), + io_safe_output($name_action) + ); } } - if (isset($groupsBy['lapse']) === true - && empty($filters['lapse']) === false - ) { + if ($total === false) { + if (is_array($fields_actions) === true + && empty($fields_actions) === false + ) { + foreach ($fields_actions as $name => $field) { + $fields[] = $field; + } + } + + $names_modules = modules_get_agentmodule_name_array( + array_values($filters['modules']) + ); + } else { + $fields = ['COUNT(tevento.id_evento) as fired']; + } + + $names_search = []; + if (isset($groupsBy['group_by']) === true) { + switch ($groupsBy['group_by']) { + case 'module': + $fields[] = 'tevento.id_agentmodule as module'; + $group_array[] = 'tevento.id_agentmodule'; + $names_search = modules_get_agentmodule_name_array( + array_values($filters['modules']) + ); + break; + + case 'action': + if (is_array($fields_actions) === true + && empty($fields_actions) === false + ) { + foreach ($fields_actions as $name => $field) { + $fields[] = $field; + $group_array[] = '"'.$name.'"'; + } + } + break; + + case 'template': + $fields[] = 'talert_template_modules.id_alert_template as template'; + $group_array[] = 'talert_template_modules.id_alert_template'; + $names_search = alerts_get_templates_name_array( + array_values($filters['templates']) + ); + break; + + case 'agent': + $fields[] = 'tevento.id_agente as agent'; + $group_array[] = 'tevento.id_agente'; + $names_search = agents_get_alias_array( + array_values($filters['agents']) + ); + break; + + case 'group': + $fields[] = 'tevento.id_grupo as `group`'; + $group_array[] = 'tevento.id_grupo'; + break; + + default: + // Nothing. + break; + } + } + + if (isset($groupsBy['lapse']) === true) { $fields[] = sprintf( - 'ROUND((CEILING(UNIX_TIMESTAMP(`timestamp`) / %d) * %d)) AS period', + 'ROUND((CEILING(UNIX_TIMESTAMP(tevento.timestamp) / %d) * %d)) AS Period', (int) $groupsBy['lapse'], (int) $groupsBy['lapse'] ); @@ -3028,8 +3064,10 @@ function alerts_get_alert_fired($filters=[], $groupsBy=[]) FROM tevento INNER JOIN talert_template_modules ON talert_template_modules.id = tevento.id_alert_am + INNER JOIN talert_templates + ON talert_templates.id = talert_template_modules.id_alert_template WHERE custom_data != "" - AND event_type="alert_fired" + AND tevento.event_type="alert_fired" %s %s %s @@ -3049,12 +3087,89 @@ function alerts_get_alert_fired($filters=[], $groupsBy=[]) $data = db_get_all_rows_sql($query); - // TODO :XXx - hd($data); + if ($data === false) { + $data = []; + } - foreach ($data as $key => $value) { - if (isset($value['period']) === true) { - hd(date('y-m-d h:i:s', $value['period'])); + if ($total === false) { + if (empty($data) === false) { + $data = array_reduce( + $data, + function ($carry, $item) use ($groupsBy) { + $period = $item['Period']; + $grby = $item[$groupsBy['group_by']]; + unset($item['Period']); + unset($item[$groupsBy['group_by']]); + $carry[$period][$grby] = $item; + return $carry; + }, + [] + ); + + $first_element = array_shift($data); + $first_element = array_shift($first_element); + $clone = []; + foreach ($first_element as $key_clone => $value_clone) { + $clone[$key_clone] = 0; + } + + $result = []; + foreach ($data as $period => $array_data) { + foreach ($names_search as $id => $name) { + foreach ($array_data as $grby => $values) { + if ($grby === $id) { + $values[$groupsBy['group_by']] = $name; + $result[$period][$id] = $values; + } else { + $clone[$groupsBy['group_by']] = $name; + $result[$period][$id] = $clone; + } + } + } + } + + $data = $result; } } + + return $data; +} + + +/** + * Get the templates names of an agent. + * + * @param array $array_ids Templates ids. + * + * @return array Id => name. + */ +function alerts_get_templates_name_array($array_ids) +{ + if (is_array($array_ids) === false || empty($array_ids) === true) { + return []; + } + + $sql = sprintf( + 'SELECT id, `name` + FROM talert_templates + WHERE id IN (%s)', + implode(',', $array_ids) + ); + + $result = db_get_all_rows_sql($sql); + + if ($result === false) { + $result = []; + } + + $result = array_reduce( + $result, + function ($carry, $item) { + $carry[$item['id']] = $item['name']; + return $carry; + }, + [] + ); + + return $result; } diff --git a/pandora_console/include/functions_modules.php b/pandora_console/include/functions_modules.php index b9a737e1d7..6af27daa71 100755 --- a/pandora_console/include/functions_modules.php +++ b/pandora_console/include/functions_modules.php @@ -3513,7 +3513,8 @@ function get_same_modules($agents, $modules) $name_modules = modules_get_agentmodule_name_array(array_values($modules)); $sql = sprintf( - 'SELECT id_agente_modulo as id + 'SELECT id_agente_modulo as id, + nombre as `name` FROM tagente_modulo WHERE id_agente IN (%s)', implode(',', array_values($agents)) @@ -3528,7 +3529,7 @@ function get_same_modules($agents, $modules) $all = array_reduce( $all, function ($carry, $item) use ($name_modules) { - if (isset($name_modules[$item['id']]) === true) { + if (array_search($item['name'], $name_modules)) { $carry[$item['id']] = $item['id']; } diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index 1ad9b7cc16..a6c754598b 100755 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -2670,6 +2670,8 @@ function reporting_alert_report_actions($report, $content) global $config; $return = []; + hd('4'); + $return['type'] = 'alert_report_actions'; if (empty($content['name']) === true) { $content['name'] = __('Alert actions'); @@ -2699,19 +2701,40 @@ function reporting_alert_report_actions($report, $content) $filters = [ 'group' => $id_group, - 'agents' => $agents, - 'modules' => $modules, + 'agents' => json_decode( + io_safe_output(base64_decode($agents)), + true + ), + 'modules' => json_decode( + io_safe_output(base64_decode($modules)), + true + ), 'templates' => $templates, 'actions' => $actions, 'period' => $period, ]; - $goupsBy = [ + $groupsBy = [ 'group_by' => $group_by, 'lapse' => $lapse, ]; - alerts_get_alert_fired($filters, $goupsBy); + $return['filters'] = $filters; + $return['groupsBy'] = $groupsBy; + + $return['data']['data'] = alerts_get_alert_fired( + $filters, + $groupsBy, + false + ); + + if ((bool) $show_summary === true) { + $return['data']['summary'] = alerts_get_alert_fired( + $filters, + $groupsBy, + true + ); + } return reporting_check_structure_content($return); } diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index 40463ddcee..34feeee092 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -2735,7 +2735,59 @@ function reporting_html_group_configuration($table, $item, $pdf=0) function reporting_html_alert_report_actions($table, $item, $pdf=0) { - hd($item); + hd(6); + + $data = $item['data']; + $filters = $item['filters']; + $groupsBy = $item['groupsBy']; + + $output = ''; + + if (isset($data['data']) === true + && empty($data['data']) === false + ) { + if (isset($groupsBy['lapse']) === true + && empty($groupsBy['lapse']) === false + ) { + } + + foreach ($data['data'] as $period => $data_array) { + $output .= get_alert_table($data_array); + } + } else { + // TODO: SMS FAIL. + } + + if ($pdf === 0) { + $table->colspan['alert_report_action']['cell'] = 3; + $table->cellstyle['alert_report_action']['cell'] = 'text-align: center;'; + $table->data['alert_report_action']['cell'] = $output; + } else { + return $output; + } + +} + + +function get_alert_table($data) +{ + $table = new StdCLass(); + $table->width = '100%'; + $table->data = []; + $table->head = []; + $head = array_shift($data); + hd($head); + foreach (array_reverse(array_keys($head)) as $name) { + $table->head[$name] = $name; + } + + foreach ($data as $key => $params) { + foreach (array_reverse($params) as $name => $value) { + $table->data[$key][$name] = $value; + } + } + + return html_print_table($table, true); } From 33d9db657e0e9b9061c96a94e2b9ec2553e050e2 Mon Sep 17 00:00:00 2001 From: Daniel Barbero Martin Date: Mon, 29 Nov 2021 20:45:35 +0100 Subject: [PATCH 13/31] wip reports alert actions --- .../reporting_builder.item_editor.php | 23 ++-- pandora_console/include/functions_alerts.php | 129 +++++++++++------- .../include/functions_reporting_html.php | 23 +++- 3 files changed, 108 insertions(+), 67 deletions(-) diff --git a/pandora_console/godmode/reporting/reporting_builder.item_editor.php b/pandora_console/godmode/reporting/reporting_builder.item_editor.php index 6562813f2a..5ae58cca8b 100755 --- a/pandora_console/godmode/reporting/reporting_builder.item_editor.php +++ b/pandora_console/godmode/reporting/reporting_builder.item_editor.php @@ -185,6 +185,8 @@ $nothing_value = 0; $graph_render = (empty($config['type_mode_graph']) === true) ? 0 : $config['type_mode_graph']; +$valuesGroupBy = [0 => __('None')]; + switch ($action) { case 'new': $actionParameter = 'save'; @@ -777,6 +779,13 @@ switch ($action) { $group_by = $es['group_by']; + $valuesGroupBy = [ + 'agent' => __('Agent'), + 'module' => __('Module'), + 'group' => __('Group'), + 'template' => __('Template'), + ]; + $period = $item['period']; $lapse = $item['lapse']; @@ -3088,8 +3097,7 @@ $class = 'databox filters'; echo __('Time lapse intervals'); ui_print_help_tip( __( - 'Lapses of time in which the period is divided to make more precise calculations -' + 'Lapses of time in which the period is divided to make more precise calculations' ) ); ?> @@ -3100,7 +3108,7 @@ $class = 'databox filters'; 'lapse', $lapse, '', - '', + __('None'), '0', 10, '', @@ -3302,19 +3310,12 @@ $class = 'databox filters'; __('Agent'), - 'module' => __('Module'), - 'group' => __('Group'), - 'template' => __('Template'), - ]; - html_print_select( $valuesGroupBy, 'group_by', $group_by, '', - __('None'), + '', 0, false, false, diff --git a/pandora_console/include/functions_alerts.php b/pandora_console/include/functions_alerts.php index d8cbdeee40..c8822b8fc9 100644 --- a/pandora_console/include/functions_alerts.php +++ b/pandora_console/include/functions_alerts.php @@ -2937,7 +2937,6 @@ function alerts_get_alert_fired($filters=[], $groupsBy=[], $total=false) ); } - // TODO: ALL; $actions_names = alerts_get_actions_names($filters['actions'], true); $group_array = []; @@ -2979,20 +2978,12 @@ function alerts_get_alert_fired($filters=[], $groupsBy=[], $total=false) } } - if ($total === false) { - if (is_array($fields_actions) === true - && empty($fields_actions) === false - ) { - foreach ($fields_actions as $name => $field) { - $fields[] = $field; - } + if (is_array($fields_actions) === true + && empty($fields_actions) === false + ) { + foreach ($fields_actions as $name => $field) { + $fields[] = $field; } - - $names_modules = modules_get_agentmodule_name_array( - array_values($filters['modules']) - ); - } else { - $fields = ['COUNT(tevento.id_evento) as fired']; } $names_search = []; @@ -3001,41 +2992,39 @@ function alerts_get_alert_fired($filters=[], $groupsBy=[], $total=false) case 'module': $fields[] = 'tevento.id_agentmodule as module'; $group_array[] = 'tevento.id_agentmodule'; - $names_search = modules_get_agentmodule_name_array( - array_values($filters['modules']) - ); - break; - - case 'action': - if (is_array($fields_actions) === true - && empty($fields_actions) === false - ) { - foreach ($fields_actions as $name => $field) { - $fields[] = $field; - $group_array[] = '"'.$name.'"'; - } + if ($total === false) { + $names_search = modules_get_agentmodule_name_array( + array_values($filters['modules']) + ); } break; case 'template': $fields[] = 'talert_template_modules.id_alert_template as template'; $group_array[] = 'talert_template_modules.id_alert_template'; - $names_search = alerts_get_templates_name_array( - array_values($filters['templates']) - ); + if ($total === false) { + $names_search = alerts_get_templates_name_array( + array_values($filters['templates']) + ); + } break; case 'agent': $fields[] = 'tevento.id_agente as agent'; $group_array[] = 'tevento.id_agente'; - $names_search = agents_get_alias_array( - array_values($filters['agents']) - ); + if ($total === false) { + $names_search = agents_get_alias_array( + array_values($filters['agents']) + ); + } break; case 'group': $fields[] = 'tevento.id_grupo as `group`'; $group_array[] = 'tevento.id_grupo'; + if ($total === false) { + $names_search = users_get_groups($config['user'], 'AR', false); + } break; default: @@ -3044,13 +3033,17 @@ function alerts_get_alert_fired($filters=[], $groupsBy=[], $total=false) } } - if (isset($groupsBy['lapse']) === true) { - $fields[] = sprintf( - 'ROUND((CEILING(UNIX_TIMESTAMP(tevento.timestamp) / %d) * %d)) AS Period', - (int) $groupsBy['lapse'], - (int) $groupsBy['lapse'] - ); - $group_array[] = 'period'; + if ($total === false) { + if (isset($groupsBy['lapse']) === true + && empty($groupsBy['lapse']) === false + ) { + $fields[] = sprintf( + 'ROUND((CEILING(UNIX_TIMESTAMP(tevento.timestamp) / %d) * %d)) AS Period', + (int) $groupsBy['lapse'], + (int) $groupsBy['lapse'] + ); + $group_array[] = 'period'; + } } $group_by = ''; @@ -3096,7 +3089,7 @@ function alerts_get_alert_fired($filters=[], $groupsBy=[], $total=false) $data = array_reduce( $data, function ($carry, $item) use ($groupsBy) { - $period = $item['Period']; + $period = (isset($item['Period']) === true) ? $item['Period'] : 0; $grby = $item[$groupsBy['group_by']]; unset($item['Period']); unset($item[$groupsBy['group_by']]); @@ -3106,26 +3099,64 @@ function alerts_get_alert_fired($filters=[], $groupsBy=[], $total=false) [] ); - $first_element = array_shift($data); - $first_element = array_shift($first_element); + $intervals = []; + if (isset($groupsBy['lapse']) === true + && empty($groupsBy['lapse']) === false + ) { + $start_interval = round( + (ceil( + ((time() - $filters['period']) / (int) $groupsBy['lapse']) + ) * (int) $groupsBy['lapse']) + ); + + for ($interval = $start_interval; $interval < time(); ($interval = $interval + (int) $groupsBy['lapse'])) { + $intervals[] = $interval; + } + } + + $first_element = reset($data); + $first_element = reset($first_element); $clone = []; foreach ($first_element as $key_clone => $value_clone) { $clone[$key_clone] = 0; } $result = []; - foreach ($data as $period => $array_data) { - foreach ($names_search as $id => $name) { - foreach ($array_data as $grby => $values) { - if ($grby === $id) { - $values[$groupsBy['group_by']] = $name; - $result[$period][$id] = $values; + if (empty($intervals) === true) { + foreach ($data as $period => $array_data) { + foreach ($names_search as $id => $name) { + if (isset($array_data[$id]) === true) { + $result[$period][$id] = $array_data[$id]; + $result[$period][$id][$groupsBy['group_by']] = $name; } else { $clone[$groupsBy['group_by']] = $name; $result[$period][$id] = $clone; } } } + } else { + foreach ($intervals as $key => $inter) { + foreach ($data as $period => $array_data) { + if ((int) $inter === (int) $period) { + foreach ($names_search as $id => $name) { + if (isset($array_data[$id]) === true) { + $result[$period][$id] = $array_data[$id]; + $result[$period][$id][$groupsBy['group_by']] = $name; + } else { + $result[$period][$id] = $clone; + $result[$period][$id][$groupsBy['group_by']] = $name; + } + } + } else { + if (isset($result[$inter]) === false) { + foreach ($names_search as $id => $name) { + $result[$inter][$id] = $clone; + $result[$inter][$id][$groupsBy['group_by']] = $name; + } + } + } + } + } } $data = $result; diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index 34feeee092..85604200e1 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -2746,14 +2746,24 @@ function reporting_html_alert_report_actions($table, $item, $pdf=0) if (isset($data['data']) === true && empty($data['data']) === false ) { - if (isset($groupsBy['lapse']) === true - && empty($groupsBy['lapse']) === false - ) { - } - + // if (isset($groupsBy['lapse']) === true + // && empty($groupsBy['lapse']) === false + // ) { + // + // } foreach ($data['data'] as $period => $data_array) { + if (empty($period) === false) { + $output .= '

'; + $output .= date('d-m-Y H:i:s', ($period - (int) $groupsBy['lapse'])); + $output .= ' - '; + $output .= date('d-m-Y H:i:s', $period); + $output .= '

'; + } + $output .= get_alert_table($data_array); } + + hd($data['summary']); } else { // TODO: SMS FAIL. } @@ -2775,8 +2785,7 @@ function get_alert_table($data) $table->width = '100%'; $table->data = []; $table->head = []; - $head = array_shift($data); - hd($head); + $head = reset($data); foreach (array_reverse(array_keys($head)) as $name) { $table->head[$name] = $name; } From 40fc8c7308fba19a31e0bcd54a8f9dfa153236f4 Mon Sep 17 00:00:00 2001 From: Daniel Barbero Martin Date: Tue, 30 Nov 2021 13:07:37 +0100 Subject: [PATCH 14/31] wip reports alert actions --- .../reporting_builder.item_editor.php | 75 +++++++------- .../godmode/reporting/reporting_builder.php | 40 ++++++-- pandora_console/include/functions_alerts.php | 99 ++++++++++--------- pandora_console/include/functions_modules.php | 12 +++ .../include/functions_reporting.php | 36 +++++-- .../include/functions_reporting_html.php | 36 ++++--- pandora_console/include/styles/pandora.css | 6 ++ 7 files changed, 191 insertions(+), 113 deletions(-) diff --git a/pandora_console/godmode/reporting/reporting_builder.item_editor.php b/pandora_console/godmode/reporting/reporting_builder.item_editor.php index 5ae58cca8b..e7fcb700e6 100755 --- a/pandora_console/godmode/reporting/reporting_builder.item_editor.php +++ b/pandora_console/godmode/reporting/reporting_builder.item_editor.php @@ -186,6 +186,12 @@ $nothing_value = 0; $graph_render = (empty($config['type_mode_graph']) === true) ? 0 : $config['type_mode_graph']; $valuesGroupBy = [0 => __('None')]; +$valuesGroupByDefaultAlertActions = [ + 'agent' => __('Agent'), + 'module' => __('Module'), + 'group' => __('Group'), + 'template' => __('Template'), +]; switch ($action) { case 'new': @@ -735,16 +741,20 @@ switch ($action) { case 'agent_module': $description = $item['description']; $es = json_decode($item['external_source'], true); - $id_agents = $es['id_agents']; + + // Decode agents and modules. + $id_agents = json_decode( + io_safe_output(base64_decode($es['id_agents'])), + true + ); + $module = json_decode( + io_safe_output(base64_decode($es['module'])), + true + ); + $selection_a_m = get_parameter('selection'); $recursion = $item['recursion']; - if ((count($es['module']) == 1) && ($es['module'][0] == 0)) { - $module = ''; - } else { - $module = $es['module']; - } - $group = $item['id_group']; $modulegroup = $item['id_module_group']; $idAgentModule = $module; @@ -4614,7 +4624,6 @@ $(document).ready (function () { $("#module").html(''); // Check module all. $("#checkbox-module-check-all").prop('checked', false); - console.log(data); if(data){ jQuery.each (data, function (id, value) { option = $("") @@ -4737,7 +4746,13 @@ $(document).ready (function () { } switch (type){ + case 'agent_module': case 'alert_report_actions': + if ($("select#id_agents2>option:selected").val() == undefined) { + dialog_message('#message_no_agent'); + return false; + } + var agents_multiple = $('#id_agents2').val(); var modules_multiple = $('#module').val(); $('#hidden-id_agents2-multiple-text').val(JSON.stringify(agents_multiple)); @@ -4769,12 +4784,6 @@ $(document).ready (function () { return false; } break; - case 'agent_module': - if ($("select#id_agents2>option:selected").val() == undefined) { - dialog_message('#message_no_agent'); - return false; - } - break; case 'inventory': case 'inventory_changes': if ($("select#id_agents>option:selected").val() == undefined) { @@ -4819,18 +4828,11 @@ $(document).ready (function () { case 'sumatory': case 'historical_data': case 'increment': - if ($("#id_agent_module").val() == 0) { dialog_message('#message_no_module'); return false; } break; - case 'agent_module': - if ($("select#module>option:selected").val() == undefined) { - dialog_message('#message_no_module'); - return false; - } - break; case 'inventory': case 'inventory_changes': if ($("select#inventory_modules>option:selected").val() == 0) { @@ -4883,7 +4885,12 @@ $(document).ready (function () { return false; } switch (type){ + case 'agent_module': case 'alert_report_actions': + if ($("select#id_agents2>option:selected").val() == undefined) { + dialog_message('#message_no_agent'); + return false; + } var agents_multiple = $('#id_agents2').val(); var modules_multiple = $('#module').val(); $('#hidden-id_agents2-multiple-text').val(JSON.stringify(agents_multiple)); @@ -4915,12 +4922,6 @@ $(document).ready (function () { return false; } break; - case 'agent_module': - if ($("select#id_agents2>option:selected").val() == undefined) { - dialog_message('#message_no_agent'); - return false; - } - break; case 'inventory': if ($("select#id_agents>option:selected").val() == undefined) { dialog_message('#message_no_agent'); @@ -4960,18 +4961,11 @@ $(document).ready (function () { case 'sumatory': case 'historical_data': case 'increment': - if ($("#id_agent_module").val() == 0) { dialog_message('#message_no_module'); return false; } break; - case 'agent_module': - if ($("select#module>option:selected").val() == undefined) { - dialog_message('#message_no_module'); - return false; - } - break; case 'inventory': if ($("select#inventory_modules>option:selected").val() == 0) { dialog_message('#message_no_module'); @@ -6171,6 +6165,19 @@ function chooseType() { $("#row_lapse").show(); $("#row_show_summary").show(); $("#row_group_by").show(); + if('' === 'new'){ + $("#group_by").html(''); + var dataDefault = ''; + Object.entries(JSON.parse(dataDefault)).forEach(function (item) { + option = $("") + .attr ("value", item[0]) + .html (item[1]); + $("#group_by").append(option); + }); + + $("#lapse_select").attr('disabled', false); + $("#lapse_select").val(0).trigger('change'); + } break; case 'event_report_group': diff --git a/pandora_console/godmode/reporting/reporting_builder.php b/pandora_console/godmode/reporting/reporting_builder.php index 26be0e954d..f181058dd7 100755 --- a/pandora_console/godmode/reporting/reporting_builder.php +++ b/pandora_console/godmode/reporting/reporting_builder.php @@ -1676,17 +1676,27 @@ switch ($action) { break; case 'agent_module': - $agents_to_report = get_parameter('id_agents2'); - $modules_to_report = get_parameter( - 'module', - '' + $agents_to_report_text = get_parameter('id_agents2-multiple-text', ''); + $modules_to_report_text = get_parameter('module-multiple-text', ''); + + // Decode json check modules. + $agents_to_report = json_decode( + io_safe_output($agents_to_report_text), + true + ); + $modules_to_report = json_decode( + io_safe_output($modules_to_report_text), + true ); $es['module'] = get_same_modules( $agents_to_report, $modules_to_report ); - $es['id_agents'] = $agents_to_report; + + // Encode json modules and agents. + $es['module'] = base64_encode(json_encode($es['module'])); + $es['id_agents'] = base64_encode(json_encode($agents_to_report)); $values['external_source'] = json_encode($es); $good_format = true; @@ -2466,17 +2476,27 @@ switch ($action) { break; case 'agent_module': - $agents_to_report = get_parameter('id_agents2'); - $modules_to_report = get_parameter( - 'module', - '' + $agents_to_report_text = get_parameter('id_agents2-multiple-text'); + $modules_to_report_text = get_parameter('module-multiple-text', ''); + + // Decode json check modules. + $agents_to_report = json_decode( + io_safe_output($agents_to_report_text), + true + ); + $modules_to_report = json_decode( + io_safe_output($modules_to_report_text), + true ); $es['module'] = get_same_modules( $agents_to_report, $modules_to_report ); - $es['id_agents'] = $agents_to_report; + + // Encode json modules and agents. + $es['module'] = base64_encode(json_encode($es['module'])); + $es['id_agents'] = base64_encode(json_encode($agents_to_report)); $values['external_source'] = json_encode($es); $good_format = true; diff --git a/pandora_console/include/functions_alerts.php b/pandora_console/include/functions_alerts.php index c8822b8fc9..1ccfa9ada5 100644 --- a/pandora_console/include/functions_alerts.php +++ b/pandora_console/include/functions_alerts.php @@ -2992,39 +2992,31 @@ function alerts_get_alert_fired($filters=[], $groupsBy=[], $total=false) case 'module': $fields[] = 'tevento.id_agentmodule as module'; $group_array[] = 'tevento.id_agentmodule'; - if ($total === false) { - $names_search = modules_get_agentmodule_name_array( - array_values($filters['modules']) - ); - } + $names_search = modules_get_agentmodule_name_array( + array_values($filters['modules']) + ); break; case 'template': $fields[] = 'talert_template_modules.id_alert_template as template'; $group_array[] = 'talert_template_modules.id_alert_template'; - if ($total === false) { - $names_search = alerts_get_templates_name_array( - array_values($filters['templates']) - ); - } + $names_search = alerts_get_templates_name_array( + array_values($filters['templates']) + ); break; case 'agent': $fields[] = 'tevento.id_agente as agent'; $group_array[] = 'tevento.id_agente'; - if ($total === false) { - $names_search = agents_get_alias_array( - array_values($filters['agents']) - ); - } + $names_search = agents_get_alias_array( + array_values($filters['agents']) + ); break; case 'group': $fields[] = 'tevento.id_grupo as `group`'; $group_array[] = 'tevento.id_grupo'; - if ($total === false) { - $names_search = users_get_groups($config['user'], 'AR', false); - } + $names_search = users_get_groups($config['user'], 'AR', false); break; default: @@ -3038,9 +3030,7 @@ function alerts_get_alert_fired($filters=[], $groupsBy=[], $total=false) && empty($groupsBy['lapse']) === false ) { $fields[] = sprintf( - 'ROUND((CEILING(UNIX_TIMESTAMP(tevento.timestamp) / %d) * %d)) AS Period', - (int) $groupsBy['lapse'], - (int) $groupsBy['lapse'] + 'tevento.utimestamp AS Period' ); $group_array[] = 'period'; } @@ -3089,7 +3079,7 @@ function alerts_get_alert_fired($filters=[], $groupsBy=[], $total=false) $data = array_reduce( $data, function ($carry, $item) use ($groupsBy) { - $period = (isset($item['Period']) === true) ? $item['Period'] : 0; + $period = (isset($item['Period']) === true) ? (int) $item['Period'] : 0; $grby = $item[$groupsBy['group_by']]; unset($item['Period']); unset($item[$groupsBy['group_by']]); @@ -3103,14 +3093,10 @@ function alerts_get_alert_fired($filters=[], $groupsBy=[], $total=false) if (isset($groupsBy['lapse']) === true && empty($groupsBy['lapse']) === false ) { - $start_interval = round( - (ceil( - ((time() - $filters['period']) / (int) $groupsBy['lapse']) - ) * (int) $groupsBy['lapse']) - ); - - for ($interval = $start_interval; $interval < time(); ($interval = $interval + (int) $groupsBy['lapse'])) { - $intervals[] = $interval; + $tend = time(); + $tstart = ($tend - (int) $filters['period']); + for ($current_time = $tstart; $current_time <= $tend; ($current_time += $groupsBy['lapse'])) { + $intervals[] = (int) $current_time; } } @@ -3135,35 +3121,50 @@ function alerts_get_alert_fired($filters=[], $groupsBy=[], $total=false) } } } else { - foreach ($intervals as $key => $inter) { + $period_lapse = (int) $groupsBy['lapse']; + foreach ($intervals as $interval) { + $start_interval = $interval; + $end_interval = ($interval + $period_lapse); + foreach ($names_search as $id => $name) { + $result[$start_interval][$id] = $clone; + $result[$start_interval][$id][$groupsBy['group_by']] = $name; + } + foreach ($data as $period => $array_data) { - if ((int) $inter === (int) $period) { - foreach ($names_search as $id => $name) { - if (isset($array_data[$id]) === true) { - $result[$period][$id] = $array_data[$id]; - $result[$period][$id][$groupsBy['group_by']] = $name; - } else { - $result[$period][$id] = $clone; - $result[$period][$id][$groupsBy['group_by']] = $name; - } - } - } else { - if (isset($result[$inter]) === false) { - foreach ($names_search as $id => $name) { - $result[$inter][$id] = $clone; - $result[$inter][$id][$groupsBy['group_by']] = $name; + $period_time = (int) $period; + if ($start_interval < $period_time && $period_time <= $end_interval) { + foreach ($array_data as $id_data => $value_data) { + foreach ($value_data as $key_data => $v) { + if ($key_data !== $groupsBy['group_by']) { + if (isset($result[$start_interval][$id_data][$key_data])) { + $result[$start_interval][$id_data][$key_data] += $v; + } else { + $result[$start_interval][$id_data][$key_data] = $v; + } + } } } + + unset($data[$period]); } } } } - - $data = $result; } + } else { + $total_values = []; + $result = []; + foreach ($data as $key => $array_data) { + foreach ($array_data as $key_value => $v) { + $total_values[$key_value] = ($total_values[$key_value] + $v); + } + } + + $result['total'] = $total_values; + $result['total'][$groupsBy['group_by']] = __('Total'); } - return $data; + return $result; } diff --git a/pandora_console/include/functions_modules.php b/pandora_console/include/functions_modules.php index 6af27daa71..5993c60202 100755 --- a/pandora_console/include/functions_modules.php +++ b/pandora_console/include/functions_modules.php @@ -3508,8 +3508,20 @@ function modules_get_agentmodule_mininterval_no_async($id_agent) } +/** + * List all modules in agents selection. + * + * @param array $agents Agents ids array. + * @param array $modules Modules ids array. + * + * @return array + */ function get_same_modules($agents, $modules) { + if (is_array($agents) === false || empty($agents) === true) { + return []; + } + $name_modules = modules_get_agentmodule_name_array(array_values($modules)); $sql = sprintf( diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index a6c754598b..6db269c6a3 100755 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -2740,15 +2740,35 @@ function reporting_alert_report_actions($report, $content) } +/** + * Data report agent/module. + * + * @param array $report Report info. + * @param array $content Content info. + * + * @return array Structure Content. + */ function reporting_agent_module($report, $content) { global $config; - $agents_and_modules = json_decode($content['external_source'], true); - $agents = []; - $agents = $agents_and_modules['id_agents']; - $modules = $agents_and_modules['module']; - $id_group = $content['id_group']; - $id_module_group = $content['id_module_group']; + $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 + ); $return['type'] = 'agent_module'; @@ -2782,7 +2802,9 @@ function reporting_agent_module($report, $content) $cont = 0; foreach ($modules as $modul_id) { - $modules_by_name[$cont]['name'] = io_safe_output(modules_get_agentmodule_name($modul_id)); + $modules_by_name[$cont]['name'] = io_safe_output( + modules_get_agentmodule_name($modul_id) + ); $modules_by_name[$cont]['id'] = $modul_id; $cont++; } diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index 85604200e1..b845f025a3 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -2742,30 +2742,40 @@ function reporting_html_alert_report_actions($table, $item, $pdf=0) $groupsBy = $item['groupsBy']; $output = ''; - if (isset($data['data']) === true && empty($data['data']) === false ) { - // if (isset($groupsBy['lapse']) === true - // && empty($groupsBy['lapse']) === false - // ) { - // - // } foreach ($data['data'] as $period => $data_array) { if (empty($period) === false) { - $output .= '

'; - $output .= date('d-m-Y H:i:s', ($period - (int) $groupsBy['lapse'])); - $output .= ' - '; - $output .= date('d-m-Y H:i:s', $period); - $output .= '

'; + $output .= '

'; + $output .= __('From').' '; + $output .= date( + 'd-m-Y H:i:s', + $period + ); + $output .= ' '.__('to').' '; + $output .= date('d-m-Y H:i:s', ($period + (int) $groupsBy['lapse'])); + $output .= '

'; } $output .= get_alert_table($data_array); } - hd($data['summary']); + if (isset($data['summary']) === true + && empty($data['summary']) === false + ) { + $output .= '

'; + $output .= __('Total summary'); + $output .= '

'; + + $output .= get_alert_table($data['summary']); + } } else { - // TODO: SMS FAIL. + $output .= ui_print_empty_data( + __('No alerts fired'), + '', + true + ); } if ($pdf === 0) { diff --git a/pandora_console/include/styles/pandora.css b/pandora_console/include/styles/pandora.css index 41d6534cd4..4432222609 100644 --- a/pandora_console/include/styles/pandora.css +++ b/pandora_console/include/styles/pandora.css @@ -8378,3 +8378,9 @@ div.stat-win-spinner img { font-size: 1.2em; margin-right: 5px !important; } + +.h1-report-alert-actions { + text-transform: none; + text-align: left; + margin: 10px; +} From ef84b696b30242212c61dcc9ca601be1be9fc98d Mon Sep 17 00:00:00 2001 From: Daniel Barbero Martin Date: Tue, 30 Nov 2021 13:34:43 +0100 Subject: [PATCH 15/31] wip reports alert actions --- .../godmode/reporting/reporting_builder.item_editor.php | 9 --------- 1 file changed, 9 deletions(-) diff --git a/pandora_console/godmode/reporting/reporting_builder.item_editor.php b/pandora_console/godmode/reporting/reporting_builder.item_editor.php index e7fcb700e6..dc7600f8af 100755 --- a/pandora_console/godmode/reporting/reporting_builder.item_editor.php +++ b/pandora_console/godmode/reporting/reporting_builder.item_editor.php @@ -4748,11 +4748,6 @@ $(document).ready (function () { switch (type){ case 'agent_module': case 'alert_report_actions': - if ($("select#id_agents2>option:selected").val() == undefined) { - dialog_message('#message_no_agent'); - return false; - } - var agents_multiple = $('#id_agents2').val(); var modules_multiple = $('#module').val(); $('#hidden-id_agents2-multiple-text').val(JSON.stringify(agents_multiple)); @@ -4887,10 +4882,6 @@ $(document).ready (function () { switch (type){ case 'agent_module': case 'alert_report_actions': - if ($("select#id_agents2>option:selected").val() == undefined) { - dialog_message('#message_no_agent'); - return false; - } var agents_multiple = $('#id_agents2').val(); var modules_multiple = $('#module').val(); $('#hidden-id_agents2-multiple-text').val(JSON.stringify(agents_multiple)); From a02c8a7988c28e0d9e557c81c26938ec13177b8f Mon Sep 17 00:00:00 2001 From: Daniel Barbero Martin Date: Wed, 1 Dec 2021 15:15:45 +0100 Subject: [PATCH 16/31] wip reports alert actions --- .../reporting_builder.item_editor.php | 68 ++--- .../godmode/reporting/reporting_builder.php | 8 +- pandora_console/include/functions_agents.php | 131 ++++++-- pandora_console/include/functions_alerts.php | 286 ++++++++++++++---- pandora_console/include/functions_modules.php | 268 +++++++++++++++- .../operation/agentes/ver_agente.php | 122 +------- 6 files changed, 641 insertions(+), 242 deletions(-) diff --git a/pandora_console/godmode/reporting/reporting_builder.item_editor.php b/pandora_console/godmode/reporting/reporting_builder.item_editor.php index dc7600f8af..9fd5316eb1 100755 --- a/pandora_console/godmode/reporting/reporting_builder.item_editor.php +++ b/pandora_console/godmode/reporting/reporting_builder.item_editor.php @@ -1702,30 +1702,12 @@ $class = 'databox filters'; $group], ['id_agente', 'alias']); - foreach ($all_agent_log as $key => $value) { - $agents2[$value['id_agente']] = $value['alias']; - } - - if ((empty($agents2)) || $agents2 == -1) { - $agents = []; - } - - $agents_select = []; - if (is_array($id_agents) || is_object($id_agents)) { - foreach ($id_agents as $id) { - foreach ($agents2 as $key => $a) { - if ($key == (int) $id) { - $agents_select[$key] = $key; - } - } - } - } + $all_agents = agents_get_agents_selected($group); html_print_select( - $agents2, + $all_agents, 'id_agents2[]', - $agents_select, + $id_agents, $script = '', '', 0, @@ -1789,39 +1771,20 @@ $class = 'databox filters'; $group], + [ + 'id_tagente', + 'id_tmetaconsole_setup', + 'id_agente', + 'alias', + ], + 'AR', + [ + 'field' => 'alias', + 'order' => 'ASC', + ], + false, + 0, + true + ); + + $all = array_reduce( + $all, + function ($carry, $item) { + $carry[$item['id_tmetaconsole_setup'].'|'.$item['id_tagente']] = $item['alias']; + return $carry; + }, + [] + ); + } else { + $all = agents_get_agents( + ['id_grupo' => $group], + [ + 'id_agente', + 'alias', + ], + 'AR', + [ + 'field' => 'alias', + 'order' => 'ASC', + ] + ); + + $all = array_reduce( + $all, + function ($carry, $item) { + $carry[$item['id_agente']] = $item['alias']; + return $carry; + }, + [] + ); + } + + return $all; +} + + /** * Get all the alerts of an agent, simple and combined. * @@ -1662,27 +1719,67 @@ function agents_get_alias_array($array_ids) return []; } - $sql = sprintf( - 'SELECT id_agente as id, alias as `name` - FROM tagente - WHERE id_agente IN (%s)', - implode(',', $array_ids) - ); + if ((bool) is_metaconsole() === true) { + $agents = array_reduce( + $array_ids, + function ($carry, $item) { + $explode = explode('|', $item); - $result = db_get_all_rows_sql($sql); + $carry[$explode[0]][] = $explode[1]; + return $carry; + } + ); - if ($result === false) { $result = []; - } + foreach ($agents as $tserver => $id_agents) { + $sql = sprintf( + 'SELECT id_tagente as id, alias as `name` + FROM tmetaconsole_agent + WHERE id_tagente IN (%s) AND id_tmetaconsole_setup = %d', + implode(',', $id_agents), + $tserver + ); - $result = array_reduce( - $result, - function ($carry, $item) { - $carry[$item['id']] = $item['name']; - return $carry; - }, - [] - ); + $data_server = db_get_all_rows_sql($sql); + + if ($data_server === false) { + $data_server = []; + } + + $data_server = array_reduce( + $data_server, + function ($carry, $item) { + $carry[$item['id']] = $item['name']; + return $carry; + }, + [] + ); + + $result[$tserver] = $data_server; + } + } else { + $sql = sprintf( + 'SELECT id_agente as id, alias as `name` + FROM tagente + WHERE id_agente IN (%s)', + implode(',', $array_ids) + ); + + $result = db_get_all_rows_sql($sql); + + if ($result === false) { + $result = []; + } + + $result = array_reduce( + $result, + function ($carry, $item) { + $carry[$item['id']] = $item['name']; + return $carry; + }, + [] + ); + } return $result; } diff --git a/pandora_console/include/functions_alerts.php b/pandora_console/include/functions_alerts.php index 1ccfa9ada5..b1f6226a7f 100644 --- a/pandora_console/include/functions_alerts.php +++ b/pandora_console/include/functions_alerts.php @@ -2887,12 +2887,18 @@ function alerts_get_alert_fired($filters=[], $groupsBy=[], $total=false) hd(5); + $table = 'tevento'; + if (is_metaconsole() === true) { + $table = 'tmetaconsole_event'; + } + $filter_date = ''; if (isset($filters['period']) === true && empty($filters['period']) === false ) { $filter_date = sprintf( - 'AND tevento.utimestamp > %d', + 'AND %s.utimestamp > %d', + $table, (time() - $filters['period']) ); } @@ -2902,7 +2908,8 @@ function alerts_get_alert_fired($filters=[], $groupsBy=[], $total=false) && empty($filters['group']) === false ) { $filter_group = sprintf( - 'AND tevento.id_grupo = %d', + 'AND %s.id_grupo = %d', + $table, $filters['group'] ); } @@ -2911,30 +2918,98 @@ function alerts_get_alert_fired($filters=[], $groupsBy=[], $total=false) if (isset($filters['agents']) === true && empty($filters['agents']) === false ) { - $filter_agents = sprintf( - 'AND tevento.id_agente IN (%s)', - implode(',', $filters['agents']) - ); + if (is_metaconsole() === true) { + $agents = array_reduce( + $filters['agents'], + function ($carry, $item) { + $explode = explode('|', $item); + + $carry[$explode[0]][] = $explode[1]; + return $carry; + } + ); + + $filter_agents .= ' AND ( '; + $i = 0; + foreach ($agents as $tserver => $agent) { + if ($i !== 0) { + $filter_agents .= ' OR '; + } + + $filter_agents .= sprintf( + '( %s.id_agente IN (%s) AND %s.server_id = %d )', + $table, + implode(',', $agent), + $table, + (int) $tserver + ); + + $i++; + } + + $filter_agents .= ' )'; + } else { + $filter_agents = sprintf( + 'AND %s.id_agente IN (%s)', + $table, + implode(',', $filters['agents']) + ); + } } $filter_modules = ''; if (isset($filters['modules']) === true && empty($filters['modules']) === false ) { - $filter_modules = sprintf( - 'AND tevento.id_agentmodule IN (%s)', - implode(',', $filters['modules']) - ); + if (is_metaconsole() === true) { + $modules = array_reduce( + $filters['modules'], + function ($carry, $item) { + $explode = explode('|', $item); + + $carry[$explode[0]][] = $explode[1]; + return $carry; + } + ); + + $filter_modules .= ' AND ( '; + $i = 0; + foreach ($modules as $tserver => $module) { + if ($i !== 0) { + $filter_modules .= ' OR '; + } + + $filter_modules .= sprintf( + '( %s.id_agentmodule IN (%s) AND %s.server_id = %d )', + $table, + implode(',', $module), + $table, + (int) $tserver + ); + + $i++; + } + + $filter_modules .= ' )'; + } else { + $filter_modules = sprintf( + 'AND %s.id_agentmodule IN (%s)', + $table, + implode(',', $filters['modules']) + ); + } } $filter_templates = ''; if (isset($filters['templates']) === true && empty($filters['templates']) === false ) { - $filter_templates = sprintf( - 'AND talert_template_modules.id_alert_template IN (%s)', - implode(',', $filters['templates']) - ); + if (is_metaconsole() === false) { + $filter_templates = sprintf( + 'AND talert_template_modules.id_alert_template IN (%s)', + implode(',', $filters['templates']) + ); + } } $actions_names = alerts_get_actions_names($filters['actions'], true); @@ -2954,12 +3029,14 @@ function alerts_get_alert_fired($filters=[], $groupsBy=[], $total=false) } $filter_actions .= sprintf( - "JSON_CONTAINS(tevento.custom_data, '\"%s\"', '\$.actions')", + "JSON_CONTAINS(%s.custom_data, '\"%s\"', '\$.actions')", + $table, io_safe_output($name_action) ); $fields_actions[$name_action] = sprintf( - "SUM(JSON_CONTAINS(tevento.custom_data, '\"%s\"', '\$.actions')) as '%s'", + "SUM(JSON_CONTAINS(%s.custom_data, '\"%s\"', '\$.actions')) as '%s'", + $table, io_safe_output($name_action), io_safe_output($name_action) ); @@ -2971,7 +3048,8 @@ function alerts_get_alert_fired($filters=[], $groupsBy=[], $total=false) } else { foreach ($actions_names as $name_action) { $fields[] = sprintf( - "SUM(JSON_CONTAINS(tevento.custom_data, '\"%s\"', '\$.actions')) as '%s'", + "SUM(JSON_CONTAINS(%s.custom_data, '\"%s\"', '\$.actions')) as '%s'", + $table, io_safe_output($name_action), io_safe_output($name_action) ); @@ -2987,35 +3065,49 @@ function alerts_get_alert_fired($filters=[], $groupsBy=[], $total=false) } $names_search = []; + $names_server = []; if (isset($groupsBy['group_by']) === true) { switch ($groupsBy['group_by']) { case 'module': - $fields[] = 'tevento.id_agentmodule as module'; - $group_array[] = 'tevento.id_agentmodule'; + $fields[] = $table.'.id_agentmodule as module'; + $group_array[] = $table.'.id_agentmodule'; $names_search = modules_get_agentmodule_name_array( array_values($filters['modules']) ); + + if (is_metaconsole() === true && $total === false) { + $fields[] = $table.'.server_id as server'; + $group_array[] = $table.'.server_id'; + $names_server = metaconsole_get_names(); + } break; case 'template': - $fields[] = 'talert_template_modules.id_alert_template as template'; - $group_array[] = 'talert_template_modules.id_alert_template'; - $names_search = alerts_get_templates_name_array( - array_values($filters['templates']) - ); + if (is_metaconsole() === false) { + $fields[] = 'talert_template_modules.id_alert_template as template'; + $group_array[] = 'talert_template_modules.id_alert_template'; + $names_search = alerts_get_templates_name_array( + array_values($filters['templates']) + ); + } break; case 'agent': - $fields[] = 'tevento.id_agente as agent'; - $group_array[] = 'tevento.id_agente'; + $fields[] = $table.'.id_agente as agent'; + $group_array[] = $table.'.id_agente'; $names_search = agents_get_alias_array( array_values($filters['agents']) ); + if (is_metaconsole() === true && $total === false) { + $fields[] = $table.'.server_id as server'; + $group_array[] = $table.'.server_id'; + $names_server = metaconsole_get_names(); + } break; case 'group': - $fields[] = 'tevento.id_grupo as `group`'; - $group_array[] = 'tevento.id_grupo'; + $fields[] = $table.'.id_grupo as `group`'; + $group_array[] = $table.'.id_grupo'; $names_search = users_get_groups($config['user'], 'AR', false); break; @@ -3030,7 +3122,8 @@ function alerts_get_alert_fired($filters=[], $groupsBy=[], $total=false) && empty($groupsBy['lapse']) === false ) { $fields[] = sprintf( - 'tevento.utimestamp AS Period' + '%s.utimestamp AS Period', + $table ); $group_array[] = 'period'; } @@ -3041,16 +3134,22 @@ function alerts_get_alert_fired($filters=[], $groupsBy=[], $total=false) $group_by = sprintf(' GROUP BY %s', implode(", \n", $group_array)); } + $innerJoin = ''; + if (is_metaconsole() === false) { + $innerJoin = sprintf( + 'INNER JOIN talert_template_modules + ON talert_template_modules.id = %s.id_alert_am', + $table + ); + } + $query = sprintf( 'SELECT %s - FROM tevento - INNER JOIN talert_template_modules - ON talert_template_modules.id = tevento.id_alert_am - INNER JOIN talert_templates - ON talert_templates.id = talert_template_modules.id_alert_template + FROM %s + %s WHERE custom_data != "" - AND tevento.event_type="alert_fired" + AND %s.event_type="alert_fired" %s %s %s @@ -3059,6 +3158,9 @@ function alerts_get_alert_fired($filters=[], $groupsBy=[], $total=false) %s %s', implode(", \n", $fields), + $table, + $innerJoin, + $table, $filter_date, $filter_group, $filter_agents, @@ -3080,10 +3182,23 @@ function alerts_get_alert_fired($filters=[], $groupsBy=[], $total=false) $data, function ($carry, $item) use ($groupsBy) { $period = (isset($item['Period']) === true) ? (int) $item['Period'] : 0; - $grby = $item[$groupsBy['group_by']]; - unset($item['Period']); - unset($item[$groupsBy['group_by']]); - $carry[$period][$grby] = $item; + if (is_metaconsole() === true + && ($groupsBy['group_by'] === 'agent' + || $groupsBy['group_by'] === 'module') + ) { + $grby = $item[$groupsBy['group_by']]; + $server = $item['server']; + unset($item['Period']); + unset($item[$groupsBy['group_by']]); + unset($item['server']); + $carry[$period][$server][$grby] = $item; + } else { + $grby = $item[$groupsBy['group_by']]; + unset($item['Period']); + unset($item[$groupsBy['group_by']]); + $carry[$period][$grby] = $item; + } + return $carry; }, [] @@ -3095,13 +3210,20 @@ function alerts_get_alert_fired($filters=[], $groupsBy=[], $total=false) ) { $tend = time(); $tstart = ($tend - (int) $filters['period']); - for ($current_time = $tstart; $current_time <= $tend; ($current_time += $groupsBy['lapse'])) { + for ($current_time = $tstart; $current_time < $tend; ($current_time += $groupsBy['lapse'])) { $intervals[] = (int) $current_time; } } $first_element = reset($data); $first_element = reset($first_element); + if (is_metaconsole() === true + && ($groupsBy['group_by'] === 'agent' + || $groupsBy['group_by'] === 'module') + ) { + $first_element = reset($first_element); + } + $clone = []; foreach ($first_element as $key_clone => $value_clone) { $clone[$key_clone] = 0; @@ -3110,13 +3232,30 @@ function alerts_get_alert_fired($filters=[], $groupsBy=[], $total=false) $result = []; if (empty($intervals) === true) { foreach ($data as $period => $array_data) { - foreach ($names_search as $id => $name) { - if (isset($array_data[$id]) === true) { - $result[$period][$id] = $array_data[$id]; - $result[$period][$id][$groupsBy['group_by']] = $name; - } else { - $clone[$groupsBy['group_by']] = $name; - $result[$period][$id] = $clone; + if (is_metaconsole() === true + && ($groupsBy['group_by'] === 'agent' + || $groupsBy['group_by'] === 'module') + ) { + foreach ($names_search as $server => $names) { + foreach ($names as $id => $name) { + if (isset($array_data[$server][$id]) === true) { + $result[$period][$server.'|'.$id] = $array_data[$server][$id]; + $result[$period][$server.'|'.$id][$groupsBy['group_by']] = $name; + } else { + $clone[$groupsBy['group_by']] = $name; + $result[$period][$server.'|'.$id] = $clone; + } + } + } + } else { + foreach ($names_search as $id => $name) { + if (isset($array_data[$id]) === true) { + $result[$period][$id] = $array_data[$id]; + $result[$period][$id][$groupsBy['group_by']] = $name; + } else { + $clone[$groupsBy['group_by']] = $name; + $result[$period][$id] = $clone; + } } } } @@ -3125,21 +3264,54 @@ function alerts_get_alert_fired($filters=[], $groupsBy=[], $total=false) foreach ($intervals as $interval) { $start_interval = $interval; $end_interval = ($interval + $period_lapse); - foreach ($names_search as $id => $name) { - $result[$start_interval][$id] = $clone; - $result[$start_interval][$id][$groupsBy['group_by']] = $name; + + if (is_metaconsole() === true + && ($groupsBy['group_by'] === 'agent' + || $groupsBy['group_by'] === 'module') + ) { + foreach ($names_search as $server => $names) { + foreach ($names as $id => $name) { + $result_name = $names_server[$server].' » '.$name; + $result[$start_interval][$server.'|'.$id] = $clone; + $result[$start_interval][$server.'|'.$id][$groupsBy['group_by']] = $result_name; + } + } + } else { + foreach ($names_search as $id => $name) { + $result[$start_interval][$id] = $clone; + $result[$start_interval][$id][$groupsBy['group_by']] = $name; + } } foreach ($data as $period => $array_data) { $period_time = (int) $period; if ($start_interval < $period_time && $period_time <= $end_interval) { - foreach ($array_data as $id_data => $value_data) { - foreach ($value_data as $key_data => $v) { - if ($key_data !== $groupsBy['group_by']) { - if (isset($result[$start_interval][$id_data][$key_data])) { - $result[$start_interval][$id_data][$key_data] += $v; - } else { - $result[$start_interval][$id_data][$key_data] = $v; + if (is_metaconsole() === true + && ($groupsBy['group_by'] === 'agent' + || $groupsBy['group_by'] === 'module') + ) { + foreach ($array_data as $server => $datas) { + foreach ($datas as $id_data => $value_data) { + foreach ($value_data as $key_data => $v) { + if ($key_data !== $groupsBy['group_by']) { + if (isset($result[$start_interval][$server.'|'.$id_data][$key_data])) { + $result[$start_interval][$server.'|'.$id_data][$key_data] += $v; + } else { + $result[$start_interval][$server.'|'.$id_data][$key_data] = $v; + } + } + } + } + } + } else { + foreach ($array_data as $id_data => $value_data) { + foreach ($value_data as $key_data => $v) { + if ($key_data !== $groupsBy['group_by']) { + if (isset($result[$start_interval][$id_data][$key_data])) { + $result[$start_interval][$id_data][$key_data] += $v; + } else { + $result[$start_interval][$id_data][$key_data] = $v; + } } } } diff --git a/pandora_console/include/functions_modules.php b/pandora_console/include/functions_modules.php index 5993c60202..4f27b17896 100755 --- a/pandora_console/include/functions_modules.php +++ b/pandora_console/include/functions_modules.php @@ -26,6 +26,8 @@ * ============================================================================ */ +use PandoraFMS\Enterprise\Metaconsole\Node; + // Begin. require_once $config['homedir'].'/include/functions_agents.php'; require_once $config['homedir'].'/include/functions_users.php'; @@ -1448,6 +1450,51 @@ function modules_get_agentmodule_name_array($array_ids) return []; } + if ((bool) is_metaconsole() === true) { + $modules = array_reduce( + $array_ids, + function ($carry, $item) { + $explode = explode('|', $item); + + $carry[$explode[0]][] = $explode[1]; + return $carry; + } + ); + + $result = []; + foreach ($modules as $tserver => $id_modules) { + if (metaconsole_connect(null, $tserver) == NOERR) { + $result_modules = modules_get_agentmodule_name_array_data( + $id_modules + ); + + $result[$tserver] = $result_modules; + metaconsole_restore_db(); + } + } + } else { + $result = modules_get_agentmodule_name_array_data( + $array_ids + ); + } + + return $result; +} + + +/** + * Data names. + * + * @param array $array_ids Ids. + * + * @return array + */ +function modules_get_agentmodule_name_array_data($array_ids) +{ + if (is_array($array_ids) === false || empty($array_ids) === true) { + return []; + } + $sql = sprintf( 'SELECT id_agente_modulo as id, nombre as `name` FROM tagente_modulo @@ -3508,6 +3555,145 @@ function modules_get_agentmodule_mininterval_no_async($id_agent) } +function get_modules_agents($id_module_group, $id_agents, $selection, $select_mode=true) +{ + if ((bool) is_metaconsole() === true) { + if ($select_mode === true) { + $agents = array_reduce( + $id_agents, + function ($carry, $item) { + $explode = explode('|', $item); + + $carry[$explode[0]][] = $explode[1]; + return $carry; + } + ); + } else { + if (count($id_agents) > 0) { + $rows = db_get_all_rows_sql( + sprintf( + 'SELECT `id_agente`, `id_tagente`, `id_tmetaconsole_setup` + FROM `tmetaconsole_agent` + WHERE `id_agente` IN (%s)', + implode(',', $id_agents) + ) + ); + } else { + $rows = []; + } + + $agents = array_reduce( + $rows, + function ($carry, $item) { + if ($carry[$item['id_tmetaconsole_setup']] === null) { + $carry[$item['id_tmetaconsole_setup']] = []; + } + + $carry[$item['id_tmetaconsole_setup']][] = $item['id_tagente']; + return $carry; + }, + [] + ); + } + + $modules = []; + foreach ($agents as $tserver => $id_agents) { + if (metaconsole_connect(null, $tserver) == NOERR) { + $modules[$tserver] = select_modules_for_agent_group( + $id_module_group, + $id_agents, + $selection, + false, + false, + true + ); + + metaconsole_restore_db(); + } + } + + if (!$selection) { + // Common modules. + $final_modules = []; + $nodes_consulted = count($modules); + + foreach ($modules as $tserver => $mods) { + foreach ($mods as $module) { + if ($final_modules[$module['nombre']] === null) { + $final_modules[$module['nombre']] = 0; + } + + $final_modules[$module['nombre']]++; + } + } + + $modules = []; + foreach ($final_modules as $module_name => $occurrences) { + if ($occurrences === $nodes_consulted) { + // Module already present in ALL nodes. + $modules[] = [ + 'id_agente_modulo' => $module_name, + 'nombre' => $module_name, + ]; + } + } + } else { + // All modules. + $return = []; + $nodes = []; + foreach ($agents as $tserver => $id_agents) { + try { + $nodes[$tserver] = new Node($tserver); + } catch (Exception $e) { + hd($e); + } + + $return = array_reduce( + $modules[$tserver], + function ($carry, $item) use ($tserver, $nodes) { + $t = []; + foreach ($item as $k => $v) { + $t[$k] = $v; + } + + $t['id_node'] = $tserver; + if ($nodes[$tserver] !== null) { + $t['nombre'] = io_safe_output( + $nodes[$tserver]->server_name().' » '.$t['nombre'] + ); + } + + $carry[] = $t; + return $carry; + }, + $return + ); + } + + $modules = $return; + } + + $modules = array_reduce( + $modules, + function ($carry, $item) { + $carry[$item['id_node'].'|'.$item['id_agente_modulo']] = $item['nombre']; + return $carry; + }, + [] + ); + } else { + $modules = select_modules_for_agent_group( + $id_module_group, + $id_agents, + $selection, + false + ); + } + + return $modules; +} + + /** * List all modules in agents selection. * @@ -3522,7 +3708,9 @@ function get_same_modules($agents, $modules) return []; } - $name_modules = modules_get_agentmodule_name_array(array_values($modules)); + $name_modules = modules_get_agentmodule_name_array_data( + array_values($modules) + ); $sql = sprintf( 'SELECT id_agente_modulo as id, @@ -3557,6 +3745,84 @@ function get_same_modules($agents, $modules) } +/** + * List all modules in agents selection to metaconsole or node. + * + * @param array $agents Agents ids array. + * @param array $modules Modules ids array. + * + * @return array List modules [server|id_module, ...]. + */ +function get_same_modules_all($agents, $modules, $select_mode=true) +{ + if (is_array($agents) === false || empty($agents) === true) { + return []; + } + + if (is_metaconsole() === true) { + $modules = array_reduce( + $modules, + function ($carry, $item) { + $explode = explode('|', $item); + + $carry[$explode[0]][] = $explode[1]; + return $carry; + } + ); + + if ($select_mode === true) { + $agents = array_reduce( + $agents, + function ($carry, $item) { + $explode = explode('|', $item); + + $carry[$explode[0]][] = $explode[1]; + return $carry; + } + ); + } else { + $rows = db_get_all_rows_sql( + sprintf( + 'SELECT `id_agente`, `id_tagente`, `id_tmetaconsole_setup` + FROM `tmetaconsole_agent` + WHERE `id_agente` IN (%s)', + implode(',', $agents) + ) + ); + + $agents = array_reduce( + $rows, + function ($carry, $item) { + if ($carry[$item['id_tmetaconsole_setup']] === null) { + $carry[$item['id_tmetaconsole_setup']] = []; + } + + $carry[$item['id_tmetaconsole_setup']][] = $item['id_tagente']; + return $carry; + }, + [] + ); + } + + $result = []; + foreach ($agents as $tserver => $id_agents) { + if (metaconsole_connect(null, $tserver) == NOERR) { + $same_modules = get_same_modules($id_agents, $modules[$tserver]); + foreach ($same_modules as $id_module) { + $result[] = $tserver.'|'.$id_module; + } + + metaconsole_restore_db(); + } + } + } else { + $result = get_same_modules($agents, $modules); + } + + return $result; +} + + function get_hierachy_modules_tree($modules) { $new_modules = []; diff --git a/pandora_console/operation/agentes/ver_agente.php b/pandora_console/operation/agentes/ver_agente.php index cbbdd9e925..617f62b97b 100644 --- a/pandora_console/operation/agentes/ver_agente.php +++ b/pandora_console/operation/agentes/ver_agente.php @@ -192,127 +192,25 @@ if (is_ajax()) { return; } - if ($get_modules_group_json) { + if ($get_modules_group_json === true) { $id_group = (int) get_parameter('id_module_group', 0); $id_agents = get_parameter('id_agents', null); $selection = get_parameter('selection'); + $select_mode = (bool) get_parameter('select_mode', 0); if ($id_agents === null) { echo '[]'; return; } - if ((bool) is_metaconsole() === true) { - if (count($id_agents) > 0) { - $rows = db_get_all_rows_sql( - sprintf( - 'SELECT `id_agente`, `id_tagente`, `id_tmetaconsole_setup` - FROM `tmetaconsole_agent` - WHERE `id_agente` IN (%s)', - implode(',', $id_agents) - ) - ); - } else { - $rows = []; - } - - $agents = array_reduce( - $rows, - function ($carry, $item) { - if ($carry[$item['id_tmetaconsole_setup']] === null) { - $carry[$item['id_tmetaconsole_setup']] = []; - } - - $carry[$item['id_tmetaconsole_setup']][] = $item['id_tagente']; - return $carry; - }, - [] - ); - - $modules = []; - - foreach ($agents as $tserver => $id_agents) { - if (metaconsole_connect(null, $tserver) == NOERR) { - $modules[$tserver] = select_modules_for_agent_group( - $id_group, - $id_agents, - $selection, - false, - false, - true - ); - - metaconsole_restore_db(); - } - } - - - if (!$selection) { - // Common modules. - $final_modules = []; - $nodes_consulted = count($modules); - - foreach ($modules as $tserver => $mods) { - foreach ($mods as $module) { - if ($final_modules[$module['nombre']] === null) { - $final_modules[$module['nombre']] = 0; - } - - $final_modules[$module['nombre']]++; - } - } - - $modules = []; - foreach ($final_modules as $module_name => $occurrences) { - if ($occurrences === $nodes_consulted) { - // Module already present in ALL nodes. - $modules[] = [ - 'id_agente_modulo' => $module_name, - 'nombre' => $module_name, - ]; - } - } - } else { - // All modules. - $return = []; - $nodes = []; - foreach ($agents as $tserver => $id_agents) { - try { - $nodes[$tserver] = new Node($tserver); - } catch (Exception $e) { - hd($e); - } - - $return = array_reduce( - $modules[$tserver], - function ($carry, $item) use ($tserver, $nodes) { - $t = []; - foreach ($item as $k => $v) { - $t[$k] = $v; - } - - $t['id_node'] = $tserver; - if ($nodes[$tserver] !== null) { - $t['nombre'] = io_safe_output( - $nodes[$tserver]->server_name().' » '.$t['nombre'] - ); - } - - $carry[] = $t; - return $carry; - }, - $return - ); - } - - $modules = $return; - } - - echo json_encode($modules); - } else { - $modules = select_modules_for_agent_group($id_group, $id_agents, $selection, false); - echo json_encode($modules); - } + $modules = get_modules_agents( + $id_group, + $id_agents, + $selection, + $select_mode + ); + echo json_encode($modules); + return; } if ($filter_modules_group_json) { From 9b79fb826d5112b07ad1ab4d9bf4da7e229e0860 Mon Sep 17 00:00:00 2001 From: Daniel Barbero Martin Date: Thu, 2 Dec 2021 13:34:28 +0100 Subject: [PATCH 17/31] wip reports alert actions --- .../reporting_builder.item_editor.php | 37 ++++++++++++------- .../include/functions_reporting.php | 33 ++++++++++++----- pandora_console/include/functions_ui.php | 2 +- 3 files changed, 48 insertions(+), 24 deletions(-) diff --git a/pandora_console/godmode/reporting/reporting_builder.item_editor.php b/pandora_console/godmode/reporting/reporting_builder.item_editor.php index 9fd5316eb1..480495c2cf 100755 --- a/pandora_console/godmode/reporting/reporting_builder.item_editor.php +++ b/pandora_console/godmode/reporting/reporting_builder.item_editor.php @@ -187,11 +187,13 @@ $graph_render = (empty($config['type_mode_graph']) === true) ? 0 : $config['type $valuesGroupBy = [0 => __('None')]; $valuesGroupByDefaultAlertActions = [ - 'agent' => __('Agent'), - 'module' => __('Module'), - 'group' => __('Group'), - 'template' => __('Template'), + 'agent' => __('Agent'), + 'module' => __('Module'), + 'group' => __('Group'), ]; +if (is_metaconsole() === false) { + $valuesGroupByDefaultAlertActions['template'] = __('Template'); +} switch ($action) { case 'new': @@ -789,16 +791,21 @@ switch ($action) { $group_by = $es['group_by']; - $valuesGroupBy = [ - 'agent' => __('Agent'), - 'module' => __('Module'), - 'group' => __('Group'), - 'template' => __('Template'), - ]; - $period = $item['period']; $lapse = $item['lapse']; + + // Set values. + $valuesGroupBy = [ + 'agent' => __('Agent'), + 'module' => __('Module'), + 'group' => __('Group'), + ]; + + if (is_metaconsole() === false) { + $valuesGroupBy['template'] = __('Template'); + } + $lapse_calc = 1; break; @@ -5695,6 +5702,7 @@ function addGeneralRow() { } function chooseType() { + var meta = ''; type = $("#type").val(); $("#row_description").hide(); $("#row_label").hide(); @@ -6116,7 +6124,9 @@ function chooseType() { $("#select_agent_modules").show(); $("#agents_modules_row").show(); $("#modules_row").show(); - $("#row_alert_templates").show(); + if(meta == 0){ + $("#row_alert_templates").show(); + } $("#row_alert_actions").show(); $("#row_period").show(); $("#row_lapse").show(); @@ -6133,7 +6143,8 @@ function chooseType() { }); $("#lapse_select").attr('disabled', false); - $("#lapse_select").val(0).trigger('change'); + $("#lapse_select").val('0').trigger('change'); + $("#hidden-lapse").val('0'); } break; diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index 6db269c6a3..f2c325ead1 100755 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -2688,11 +2688,30 @@ function reporting_alert_report_actions($report, $content) $return['data'] = []; $es = json_decode($content['external_source'], true); + if (isset($report['id_template']) === true + && empty($resport['id_template']) === false + ) { + $modules = json_decode( + io_safe_output(base64_decode($es['module'])), + true + ); + $agents = json_decode( + io_safe_output(base64_decode($es['id_agents'])), + true + ); + } else { + if (is_metaconsole() === true) { + $server_id = metaconsole_get_id_server($content['server_name']); + $modules = [$server_id.'|'.$content['id_agent_module']]; + $agents = [$server_id.'|'.$content['id_agent']]; + } else { + $modules = [$content['id_agent_module']]; + $agents = [$content['id_agent']]; + } + } $period = $content['period']; $id_group = $content['id_group']; - $modules = $es['module']; - $agents = $es['id_agents']; $templates = $es['templates']; $actions = $es['actions']; $show_summary = $es['show_summary']; @@ -2701,14 +2720,8 @@ function reporting_alert_report_actions($report, $content) $filters = [ 'group' => $id_group, - 'agents' => json_decode( - io_safe_output(base64_decode($agents)), - true - ), - 'modules' => json_decode( - io_safe_output(base64_decode($modules)), - true - ), + 'agents' => $agents, + 'modules' => $modules, 'templates' => $templates, 'actions' => $actions, 'period' => $period, diff --git a/pandora_console/include/functions_ui.php b/pandora_console/include/functions_ui.php index 03ec3ee614..8e9fe01210 100755 --- a/pandora_console/include/functions_ui.php +++ b/pandora_console/include/functions_ui.php @@ -329,7 +329,7 @@ function ui_print_message($message, $class='', $attributes='', $return=false, $t if (!$no_close_bool) { // Use the no_meta parameter because this image is only in // the base console. - $output .= ''.html_print_image('images/blade.png', true, false, false, true).''; + $output .= ''.html_print_image('images/blade.png', true, false, false, false).''; } $output .= ' From 751cb7380bc452ccfe8733227997622cb2114814 Mon Sep 17 00:00:00 2001 From: Daniel Barbero Martin Date: Thu, 2 Dec 2021 13:52:56 +0100 Subject: [PATCH 18/31] wip reports alert actions --- .../include/functions_reporting.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index f2c325ead1..17d9824943 100755 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -2691,15 +2691,6 @@ function reporting_alert_report_actions($report, $content) if (isset($report['id_template']) === true && empty($resport['id_template']) === false ) { - $modules = json_decode( - io_safe_output(base64_decode($es['module'])), - true - ); - $agents = json_decode( - io_safe_output(base64_decode($es['id_agents'])), - true - ); - } else { if (is_metaconsole() === true) { $server_id = metaconsole_get_id_server($content['server_name']); $modules = [$server_id.'|'.$content['id_agent_module']]; @@ -2708,6 +2699,15 @@ function reporting_alert_report_actions($report, $content) $modules = [$content['id_agent_module']]; $agents = [$content['id_agent']]; } + } else { + $modules = json_decode( + io_safe_output(base64_decode($es['module'])), + true + ); + $agents = json_decode( + io_safe_output(base64_decode($es['id_agents'])), + true + ); } $period = $content['period']; From abedd879106a552b0ff5c93b0abb3f738b9f88b6 Mon Sep 17 00:00:00 2001 From: Daniel Barbero Martin Date: Thu, 2 Dec 2021 14:04:33 +0100 Subject: [PATCH 19/31] wip reports alert actions --- pandora_console/include/functions_alerts.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pandora_console/include/functions_alerts.php b/pandora_console/include/functions_alerts.php index b1f6226a7f..efcf3f21dc 100644 --- a/pandora_console/include/functions_alerts.php +++ b/pandora_console/include/functions_alerts.php @@ -3170,6 +3170,8 @@ function alerts_get_alert_fired($filters=[], $groupsBy=[], $total=false) $group_by ); + hd($query); + $data = db_get_all_rows_sql($query); if ($data === false) { From d030b3b924f7715fa5db3b02bcc51196c731c44d Mon Sep 17 00:00:00 2001 From: Daniel Barbero Martin Date: Thu, 2 Dec 2021 14:16:01 +0100 Subject: [PATCH 20/31] wip reports alert actions --- pandora_console/include/functions_alerts.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/pandora_console/include/functions_alerts.php b/pandora_console/include/functions_alerts.php index efcf3f21dc..8c69468b7f 100644 --- a/pandora_console/include/functions_alerts.php +++ b/pandora_console/include/functions_alerts.php @@ -3154,8 +3154,6 @@ function alerts_get_alert_fired($filters=[], $groupsBy=[], $total=false) %s %s %s - %s - %s %s', implode(", \n", $fields), $table, @@ -3163,8 +3161,8 @@ function alerts_get_alert_fired($filters=[], $groupsBy=[], $total=false) $table, $filter_date, $filter_group, - $filter_agents, - $filter_modules, + // $filter_agents, + // $filter_modules, $filter_actions, $filter_templates, $group_by From ec21d9d08a10009d544cd58a46b6c9df2b57127b Mon Sep 17 00:00:00 2001 From: Daniel Barbero Martin Date: Thu, 2 Dec 2021 14:27:24 +0100 Subject: [PATCH 21/31] wip reports alert actions --- pandora_console/include/functions_alerts.php | 47 +++++++++++++------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/pandora_console/include/functions_alerts.php b/pandora_console/include/functions_alerts.php index 8c69468b7f..a5d2f26152 100644 --- a/pandora_console/include/functions_alerts.php +++ b/pandora_console/include/functions_alerts.php @@ -3071,14 +3071,18 @@ function alerts_get_alert_fired($filters=[], $groupsBy=[], $total=false) case 'module': $fields[] = $table.'.id_agentmodule as module'; $group_array[] = $table.'.id_agentmodule'; - $names_search = modules_get_agentmodule_name_array( - array_values($filters['modules']) - ); + if ($total === false) { + $names_search = modules_get_agentmodule_name_array( + array_values($filters['modules']) + ); + } - if (is_metaconsole() === true && $total === false) { + if (is_metaconsole() === true) { $fields[] = $table.'.server_id as server'; $group_array[] = $table.'.server_id'; - $names_server = metaconsole_get_names(); + if ($total === false) { + $names_server = metaconsole_get_names(); + } } break; @@ -3086,29 +3090,38 @@ function alerts_get_alert_fired($filters=[], $groupsBy=[], $total=false) if (is_metaconsole() === false) { $fields[] = 'talert_template_modules.id_alert_template as template'; $group_array[] = 'talert_template_modules.id_alert_template'; - $names_search = alerts_get_templates_name_array( - array_values($filters['templates']) - ); + if ($total === false) { + $names_search = alerts_get_templates_name_array( + array_values($filters['templates']) + ); + } } break; case 'agent': $fields[] = $table.'.id_agente as agent'; $group_array[] = $table.'.id_agente'; - $names_search = agents_get_alias_array( - array_values($filters['agents']) - ); - if (is_metaconsole() === true && $total === false) { + if ($total === false) { + $names_search = agents_get_alias_array( + array_values($filters['agents']) + ); + } + + if (is_metaconsole() === true) { $fields[] = $table.'.server_id as server'; $group_array[] = $table.'.server_id'; - $names_server = metaconsole_get_names(); + if ($total === false) { + $names_server = metaconsole_get_names(); + } } break; case 'group': $fields[] = $table.'.id_grupo as `group`'; $group_array[] = $table.'.id_grupo'; - $names_search = users_get_groups($config['user'], 'AR', false); + if ($total === false) { + $names_search = users_get_groups($config['user'], 'AR', false); + } break; default: @@ -3154,6 +3167,8 @@ function alerts_get_alert_fired($filters=[], $groupsBy=[], $total=false) %s %s %s + %s + %s %s', implode(", \n", $fields), $table, @@ -3161,8 +3176,8 @@ function alerts_get_alert_fired($filters=[], $groupsBy=[], $total=false) $table, $filter_date, $filter_group, - // $filter_agents, - // $filter_modules, + $filter_agents, + $filter_modules, $filter_actions, $filter_templates, $group_by From 94bd55fd39e87629a66590e89cc8786ea4edc7ed Mon Sep 17 00:00:00 2001 From: Daniel Barbero Martin Date: Thu, 2 Dec 2021 16:55:53 +0100 Subject: [PATCH 22/31] wip reports alert actions --- .../reporting_builder.item_editor.php | 30 +- .../godmode/reporting/reporting_builder.php | 6 +- pandora_console/include/functions_alerts.php | 319 ++++++++++-------- .../include/functions_reporting.php | 40 +-- .../include/functions_reporting_html.php | 21 +- 5 files changed, 238 insertions(+), 178 deletions(-) diff --git a/pandora_console/godmode/reporting/reporting_builder.item_editor.php b/pandora_console/godmode/reporting/reporting_builder.item_editor.php index 480495c2cf..81b6877cc2 100755 --- a/pandora_console/godmode/reporting/reporting_builder.item_editor.php +++ b/pandora_console/godmode/reporting/reporting_builder.item_editor.php @@ -136,10 +136,10 @@ $percentil = false; $time_compare_overlapped = false; // Added for events items. -$show_summary_group = false; +$show_summary_group = false; $filter_event_severity = false; -$filter_event_type = false; -$filter_event_status = false; +$filter_event_type = false; +$filter_event_status = false; $event_graph_by_agent = false; $event_graph_by_user_validator = false; $event_graph_by_criticity = false; @@ -175,6 +175,8 @@ $agent_max_value = true; $agent_min_value = true; $uncompressed_module = true; +$only_data = false; + // Users. $id_users = []; $users_groups = []; @@ -763,7 +765,6 @@ switch ($action) { break; case 'alert_report_actions': - hd('1'); $description = $item['description']; $es = json_decode($item['external_source'], true); @@ -791,6 +792,8 @@ switch ($action) { $group_by = $es['group_by']; + $only_data = $es['only_data']; + $period = $item['period']; $lapse = $item['lapse']; @@ -2709,6 +2712,23 @@ $class = 'databox filters'; + + + + + + + + + @@ -5782,6 +5802,7 @@ function chooseType() { $("#select_agent_modules").hide(); $("#modules_row").hide(); $("#row_show_summary_group").hide(); + $("#row_show_only_data").hide(); $("#row_event_severity").hide(); $("#row_event_type").hide(); $("#row_event_status").hide(); @@ -6131,6 +6152,7 @@ function chooseType() { $("#row_period").show(); $("#row_lapse").show(); $("#row_show_summary").show(); + $("#row_show_only_data").show(); $("#row_group_by").show(); if('' === 'new'){ $("#group_by").html(''); diff --git a/pandora_console/godmode/reporting/reporting_builder.php b/pandora_console/godmode/reporting/reporting_builder.php index 674dd627a3..9421f120f2 100755 --- a/pandora_console/godmode/reporting/reporting_builder.php +++ b/pandora_console/godmode/reporting/reporting_builder.php @@ -1707,7 +1707,7 @@ switch ($action) { $alert_actions_to_report = get_parameter('alert_actions'); $show_summary = get_parameter('show_summary', 0); $group_by = get_parameter('group_by'); - hd('3'); + $only_data = get_parameter('only_data', 0); $agents_to_report_text = get_parameter('id_agents2-multiple-text'); $modules_to_report_text = get_parameter('module-multiple-text', ''); @@ -1734,6 +1734,7 @@ switch ($action) { $es['actions'] = $alert_actions_to_report; $es['show_summary'] = $show_summary; $es['group_by'] = $group_by; + $es['only_data'] = $only_data; $values['external_source'] = json_encode($es); @@ -2503,11 +2504,11 @@ switch ($action) { break; case 'alert_report_actions': - hd('2'); $alert_templates_to_report = get_parameter('alert_templates'); $alert_actions_to_report = get_parameter('alert_actions'); $show_summary = get_parameter('show_summary', 0); $group_by = get_parameter('group_by'); + $only_data = get_parameter('only_data', 0); $agents_to_report_text = get_parameter('id_agents2-multiple-text'); $modules_to_report_text = get_parameter('module-multiple-text', ''); @@ -2535,6 +2536,7 @@ switch ($action) { $es['actions'] = $alert_actions_to_report; $es['show_summary'] = $show_summary; $es['group_by'] = $group_by; + $es['only_data'] = $only_data; $values['external_source'] = json_encode($es); diff --git a/pandora_console/include/functions_alerts.php b/pandora_console/include/functions_alerts.php index a5d2f26152..1bb8ea002a 100644 --- a/pandora_console/include/functions_alerts.php +++ b/pandora_console/include/functions_alerts.php @@ -2881,12 +2881,18 @@ function alerts_get_actions_names($actions, $reduce=false) } -function alerts_get_alert_fired($filters=[], $groupsBy=[], $total=false) +/** + * Alert fired. + * + * @param array $filters Filters. + * @param array $groupsBy Groupby and lapse. + * + * @return array Result data. + */ +function alerts_get_alert_fired($filters=[], $groupsBy=[]) { global $config; - hd(5); - $table = 'tevento'; if (is_metaconsole() === true) { $table = 'tmetaconsole_event'; @@ -3012,6 +3018,9 @@ function alerts_get_alert_fired($filters=[], $groupsBy=[], $total=false) } } + $total = (bool) $filters['show_summary']; + $only_data = (bool) $filters['only_data']; + $actions_names = alerts_get_actions_names($filters['actions'], true); $group_array = []; @@ -3071,18 +3080,14 @@ function alerts_get_alert_fired($filters=[], $groupsBy=[], $total=false) case 'module': $fields[] = $table.'.id_agentmodule as module'; $group_array[] = $table.'.id_agentmodule'; - if ($total === false) { - $names_search = modules_get_agentmodule_name_array( - array_values($filters['modules']) - ); - } + $names_search = modules_get_agentmodule_name_array( + array_values($filters['modules']) + ); if (is_metaconsole() === true) { $fields[] = $table.'.server_id as server'; $group_array[] = $table.'.server_id'; - if ($total === false) { - $names_server = metaconsole_get_names(); - } + $names_server = metaconsole_get_names(); } break; @@ -3090,38 +3095,30 @@ function alerts_get_alert_fired($filters=[], $groupsBy=[], $total=false) if (is_metaconsole() === false) { $fields[] = 'talert_template_modules.id_alert_template as template'; $group_array[] = 'talert_template_modules.id_alert_template'; - if ($total === false) { - $names_search = alerts_get_templates_name_array( - array_values($filters['templates']) - ); - } + $names_search = alerts_get_templates_name_array( + array_values($filters['templates']) + ); } break; case 'agent': $fields[] = $table.'.id_agente as agent'; $group_array[] = $table.'.id_agente'; - if ($total === false) { - $names_search = agents_get_alias_array( - array_values($filters['agents']) - ); - } + $names_search = agents_get_alias_array( + array_values($filters['agents']) + ); if (is_metaconsole() === true) { $fields[] = $table.'.server_id as server'; $group_array[] = $table.'.server_id'; - if ($total === false) { - $names_server = metaconsole_get_names(); - } + $names_server = metaconsole_get_names(); } break; case 'group': $fields[] = $table.'.id_grupo as `group`'; $group_array[] = $table.'.id_grupo'; - if ($total === false) { - $names_search = users_get_groups($config['user'], 'AR', false); - } + $names_search = users_get_groups($config['user'], 'AR', false); break; default: @@ -3130,16 +3127,14 @@ function alerts_get_alert_fired($filters=[], $groupsBy=[], $total=false) } } - if ($total === false) { - if (isset($groupsBy['lapse']) === true - && empty($groupsBy['lapse']) === false - ) { - $fields[] = sprintf( - '%s.utimestamp AS Period', - $table - ); - $group_array[] = 'period'; - } + if (isset($groupsBy['lapse']) === true + && empty($groupsBy['lapse']) === false + ) { + $fields[] = sprintf( + '%s.utimestamp AS Period', + $table + ); + $group_array[] = 'period'; } $group_by = ''; @@ -3183,103 +3178,105 @@ function alerts_get_alert_fired($filters=[], $groupsBy=[], $total=false) $group_by ); - hd($query); + $data_query = db_get_all_rows_sql($query); - $data = db_get_all_rows_sql($query); - - if ($data === false) { - $data = []; + if ($data_query === false) { + $data_query = []; } - if ($total === false) { - if (empty($data) === false) { - $data = array_reduce( - $data, - function ($carry, $item) use ($groupsBy) { - $period = (isset($item['Period']) === true) ? (int) $item['Period'] : 0; - if (is_metaconsole() === true - && ($groupsBy['group_by'] === 'agent' - || $groupsBy['group_by'] === 'module') - ) { - $grby = $item[$groupsBy['group_by']]; - $server = $item['server']; - unset($item['Period']); - unset($item[$groupsBy['group_by']]); - unset($item['server']); - $carry[$period][$server][$grby] = $item; - } else { - $grby = $item[$groupsBy['group_by']]; - unset($item['Period']); - unset($item[$groupsBy['group_by']]); - $carry[$period][$grby] = $item; - } - - return $carry; - }, - [] - ); - - $intervals = []; - if (isset($groupsBy['lapse']) === true - && empty($groupsBy['lapse']) === false - ) { - $tend = time(); - $tstart = ($tend - (int) $filters['period']); - for ($current_time = $tstart; $current_time < $tend; ($current_time += $groupsBy['lapse'])) { - $intervals[] = (int) $current_time; + if (empty($data_query) === false) { + $data = array_reduce( + $data_query, + function ($carry, $item) use ($groupsBy) { + $period = (isset($item['Period']) === true) ? (int) $item['Period'] : 0; + if (is_metaconsole() === true + && ($groupsBy['group_by'] === 'agent' + || $groupsBy['group_by'] === 'module') + ) { + $grby = $item[$groupsBy['group_by']]; + $server = $item['server']; + unset($item['Period']); + unset($item[$groupsBy['group_by']]); + unset($item['server']); + $carry[$period][$server][$grby] = $item; + } else { + $grby = $item[$groupsBy['group_by']]; + unset($item['Period']); + unset($item[$groupsBy['group_by']]); + $carry[$period][$grby] = $item; } - } - $first_element = reset($data); - $first_element = reset($first_element); - if (is_metaconsole() === true - && ($groupsBy['group_by'] === 'agent' - || $groupsBy['group_by'] === 'module') - ) { - $first_element = reset($first_element); - } + return $carry; + }, + [] + ); - $clone = []; - foreach ($first_element as $key_clone => $value_clone) { - $clone[$key_clone] = 0; + $intervals = []; + if (isset($groupsBy['lapse']) === true + && empty($groupsBy['lapse']) === false + ) { + $tend = time(); + $tstart = ($tend - (int) $filters['period']); + for ($current_time = $tstart; $current_time < $tend; ($current_time += $groupsBy['lapse'])) { + $intervals[] = (int) $current_time; } + } - $result = []; - if (empty($intervals) === true) { - foreach ($data as $period => $array_data) { - if (is_metaconsole() === true - && ($groupsBy['group_by'] === 'agent' - || $groupsBy['group_by'] === 'module') - ) { - foreach ($names_search as $server => $names) { - foreach ($names as $id => $name) { - if (isset($array_data[$server][$id]) === true) { - $result[$period][$server.'|'.$id] = $array_data[$server][$id]; - $result[$period][$server.'|'.$id][$groupsBy['group_by']] = $name; - } else { + $first_element = reset($data); + $first_element = reset($first_element); + if (is_metaconsole() === true + && ($groupsBy['group_by'] === 'agent' + || $groupsBy['group_by'] === 'module') + ) { + $first_element = reset($first_element); + } + + $clone = []; + foreach ($first_element as $key_clone => $value_clone) { + $clone[$key_clone] = 0; + } + + $result = []; + if (empty($intervals) === true) { + foreach ($data as $period => $array_data) { + if (is_metaconsole() === true + && ($groupsBy['group_by'] === 'agent' + || $groupsBy['group_by'] === 'module') + ) { + foreach ($names_search as $server => $names) { + foreach ($names as $id => $name) { + if (isset($array_data[$server][$id]) === true) { + $result[$period][$server.'|'.$id] = $array_data[$server][$id]; + $result[$period][$server.'|'.$id][$groupsBy['group_by']] = $name; + } else { + if ($only_data === false) { $clone[$groupsBy['group_by']] = $name; $result[$period][$server.'|'.$id] = $clone; } } } - } else { - foreach ($names_search as $id => $name) { - if (isset($array_data[$id]) === true) { - $result[$period][$id] = $array_data[$id]; - $result[$period][$id][$groupsBy['group_by']] = $name; - } else { + } + } else { + foreach ($names_search as $id => $name) { + if (isset($array_data[$id]) === true) { + $result[$period][$id] = $array_data[$id]; + $result[$period][$id][$groupsBy['group_by']] = $name; + } else { + if ($only_data === false) { $clone[$groupsBy['group_by']] = $name; $result[$period][$id] = $clone; } } } } - } else { - $period_lapse = (int) $groupsBy['lapse']; - foreach ($intervals as $interval) { - $start_interval = $interval; - $end_interval = ($interval + $period_lapse); + } + } else { + $period_lapse = (int) $groupsBy['lapse']; + foreach ($intervals as $interval) { + $start_interval = $interval; + $end_interval = ($interval + $period_lapse); + if ($only_data === false) { if (is_metaconsole() === true && ($groupsBy['group_by'] === 'agent' || $groupsBy['group_by'] === 'module') @@ -3297,58 +3294,90 @@ function alerts_get_alert_fired($filters=[], $groupsBy=[], $total=false) $result[$start_interval][$id][$groupsBy['group_by']] = $name; } } - + } else { foreach ($data as $period => $array_data) { - $period_time = (int) $period; - if ($start_interval < $period_time && $period_time <= $end_interval) { - if (is_metaconsole() === true - && ($groupsBy['group_by'] === 'agent' - || $groupsBy['group_by'] === 'module') - ) { - foreach ($array_data as $server => $datas) { - foreach ($datas as $id_data => $value_data) { - foreach ($value_data as $key_data => $v) { - if ($key_data !== $groupsBy['group_by']) { - if (isset($result[$start_interval][$server.'|'.$id_data][$key_data])) { - $result[$start_interval][$server.'|'.$id_data][$key_data] += $v; - } else { - $result[$start_interval][$server.'|'.$id_data][$key_data] = $v; - } - } - } - } + if (is_metaconsole() === true + && ($groupsBy['group_by'] === 'agent' + || $groupsBy['group_by'] === 'module') + ) { + foreach ($array_data as $server => $datas) { + foreach ($datas as $id_data => $value_data) { + $name = $names_server[$server].' » '.$names_search[$server][$id_data]; + $result[$start_interval][$server.'|'.$id_data] = $clone; + $result[$start_interval][$server.'|'.$id_data][$groupsBy['group_by']] = $name; } - } else { - foreach ($array_data as $id_data => $value_data) { + } + } else { + foreach ($array_data as $id_data => $value_data) { + $name = $names_search[$id_data]; + $result[$start_interval][$id_data] = $clone; + $result[$start_interval][$id_data][$groupsBy['group_by']] = $name; + } + } + } + } + + foreach ($data as $period => $array_data) { + $period_time = (int) $period; + if ($start_interval < $period_time && $period_time <= $end_interval) { + if (is_metaconsole() === true + && ($groupsBy['group_by'] === 'agent' + || $groupsBy['group_by'] === 'module') + ) { + foreach ($array_data as $server => $datas) { + foreach ($datas as $id_data => $value_data) { foreach ($value_data as $key_data => $v) { if ($key_data !== $groupsBy['group_by']) { - if (isset($result[$start_interval][$id_data][$key_data])) { - $result[$start_interval][$id_data][$key_data] += $v; + if (isset($result[$start_interval][$server.'|'.$id_data][$key_data])) { + $result[$start_interval][$server.'|'.$id_data][$key_data] += $v; } else { - $result[$start_interval][$id_data][$key_data] = $v; + $result[$start_interval][$server.'|'.$id_data][$key_data] = $v; } } } } } - - unset($data[$period]); + } else { + foreach ($array_data as $id_data => $value_data) { + foreach ($value_data as $key_data => $v) { + if ($key_data !== $groupsBy['group_by']) { + if (isset($result[$start_interval][$id_data][$key_data])) { + $result[$start_interval][$id_data][$key_data] += $v; + } else { + $result[$start_interval][$id_data][$key_data] = $v; + } + } + } + } } + + unset($data[$period]); } } } } - } else { + } + + $result['data'] = $result; + + if ($total === true) { $total_values = []; - $result = []; - foreach ($data as $key => $array_data) { + foreach ($data_query as $key => $array_data) { foreach ($array_data as $key_value => $v) { $total_values[$key_value] = ($total_values[$key_value] + $v); } } - $result['total'] = $total_values; - $result['total'][$groupsBy['group_by']] = __('Total'); + if (is_metaconsole() === true + && ($groupsBy['group_by'] === 'agent' + || $groupsBy['group_by'] === 'module') + ) { + unset($total_values['Period']); + unset($total_values['server']); + } + + $result['summary']['total'] = $total_values; + $result['summary']['total'][$groupsBy['group_by']] = __('Total'); } return $result; diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index 17d9824943..ff12d6bdd9 100755 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -2665,13 +2665,18 @@ function reporting_inventory($report, $content, $type) } +/** + * Build data for report alert actions. + * + * @param array $report Report info. + * @param array $content Content. + * + * @return array Result data. + */ function reporting_alert_report_actions($report, $content) { - global $config; $return = []; - hd('4'); - $return['type'] = 'alert_report_actions'; if (empty($content['name']) === true) { $content['name'] = __('Alert actions'); @@ -2717,14 +2722,17 @@ function reporting_alert_report_actions($report, $content) $show_summary = $es['show_summary']; $group_by = $es['group_by']; $lapse = $content['lapse']; + $only_data = $es['only_data']; $filters = [ - 'group' => $id_group, - 'agents' => $agents, - 'modules' => $modules, - 'templates' => $templates, - 'actions' => $actions, - 'period' => $period, + 'group' => $id_group, + 'agents' => $agents, + 'modules' => $modules, + 'templates' => $templates, + 'actions' => $actions, + 'period' => $period, + 'show_summary' => (bool) $show_summary, + 'only_data' => (bool) $only_data, ]; $groupsBy = [ @@ -2735,19 +2743,7 @@ function reporting_alert_report_actions($report, $content) $return['filters'] = $filters; $return['groupsBy'] = $groupsBy; - $return['data']['data'] = alerts_get_alert_fired( - $filters, - $groupsBy, - false - ); - - if ((bool) $show_summary === true) { - $return['data']['summary'] = alerts_get_alert_fired( - $filters, - $groupsBy, - true - ); - } + $return['data'] = alerts_get_alert_fired($filters, $groupsBy); return reporting_check_structure_content($return); } diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index b845f025a3..7260843d29 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -2733,12 +2733,18 @@ function reporting_html_group_configuration($table, $item, $pdf=0) } +/** + * Html output report alert actions + * + * @param object $table Table. + * @param array $item Data for draw report. + * @param integer $pdf PDF output. + * + * @return string Html output. + */ function reporting_html_alert_report_actions($table, $item, $pdf=0) { - hd(6); - $data = $item['data']; - $filters = $item['filters']; $groupsBy = $item['groupsBy']; $output = ''; @@ -2795,14 +2801,19 @@ function get_alert_table($data) $table->width = '100%'; $table->data = []; $table->head = []; + $table->headstyle = []; + $table->cellstyle = []; + $table->headstyle[0] = 'text-align:left;'; + $head = reset($data); foreach (array_reverse(array_keys($head)) as $name) { - $table->head[$name] = $name; + $table->head[] = $name; } foreach ($data as $key => $params) { + $table->cellstyle[$key][0] = 'text-align:left;'; foreach (array_reverse($params) as $name => $value) { - $table->data[$key][$name] = $value; + $table->data[$key][] = $value; } } From 5a3e5aaac405d04f6cdac50aa44be05d1da05d9d Mon Sep 17 00:00:00 2001 From: Daniel Barbero Martin Date: Thu, 2 Dec 2021 16:57:31 +0100 Subject: [PATCH 23/31] wip reports alert actions --- pandora_console/include/styles/pandora.css | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandora_console/include/styles/pandora.css b/pandora_console/include/styles/pandora.css index 4432222609..169e3918ce 100644 --- a/pandora_console/include/styles/pandora.css +++ b/pandora_console/include/styles/pandora.css @@ -8382,5 +8382,6 @@ div.stat-win-spinner img { .h1-report-alert-actions { text-transform: none; text-align: left; - margin: 10px; + margin: 5px; + font-size: 12px; } From eb8b89f22e2e5e79f42a437c6d9651b83b6e1914 Mon Sep 17 00:00:00 2001 From: Daniel Barbero Martin Date: Thu, 2 Dec 2021 17:17:21 +0100 Subject: [PATCH 24/31] wip reports alert actions --- pandora_console/include/functions_alerts.php | 1 + 1 file changed, 1 insertion(+) diff --git a/pandora_console/include/functions_alerts.php b/pandora_console/include/functions_alerts.php index 1bb8ea002a..067e631bee 100644 --- a/pandora_console/include/functions_alerts.php +++ b/pandora_console/include/functions_alerts.php @@ -3245,6 +3245,7 @@ function alerts_get_alert_fired($filters=[], $groupsBy=[]) ) { foreach ($names_search as $server => $names) { foreach ($names as $id => $name) { + $name = $names_server[$server].' » '.$name; if (isset($array_data[$server][$id]) === true) { $result[$period][$server.'|'.$id] = $array_data[$server][$id]; $result[$period][$server.'|'.$id][$groupsBy['group_by']] = $name; From a94f6be37eb4a744654b6c6dde9dbb42c145ff57 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Fri, 3 Dec 2021 12:59:50 +0100 Subject: [PATCH 25/31] force db_process_sql --- pandora_console/extras/mr/51.sql | 2 +- .../pandoradb_migrate_6.0_to_7.0.mysql.sql | 1 + pandora_console/include/db/mysql.php | 51 ------- pandora_console/include/functions_db.php | 128 +++++++++--------- pandora_console/pandoradb.sql | 1 + 5 files changed, 70 insertions(+), 113 deletions(-) diff --git a/pandora_console/extras/mr/51.sql b/pandora_console/extras/mr/51.sql index 3398bed0c3..0575fea01e 100644 --- a/pandora_console/extras/mr/51.sql +++ b/pandora_console/extras/mr/51.sql @@ -8,7 +8,7 @@ ALTER TABLE `tlocal_component` ADD COLUMN `percentage_critical` tinyint(1) UNSIG ALTER TABLE `tlocal_component` ADD COLUMN `percentage_warning` tinyint(1) UNSIGNED DEFAULT 0; ALTER TABLE `tpolicy_modules` ADD COLUMN `percentage_warning` tinyint(1) UNSIGNED DEFAULT 0; ALTER TABLE `tpolicy_modules` ADD COLUMN `percentage_critical` tinyint(1) UNSIGNED DEFAULT 0; - +ALTER TABLE `tsync_queue` ADD COLUMN `result` TEXT; ALTER TABLE tagente_modulo MODIFY debug_content TEXT; CREATE TABLE IF NOT EXISTS `talert_calendar` ( 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 ba0c0c32e3..0cec1167dd 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 @@ -4089,6 +4089,7 @@ CREATE TABLE IF NOT EXISTS `tsync_queue` ( `operation` text, `table` text, `error` MEDIUMTEXT, + `result` TEXT, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/pandora_console/include/db/mysql.php b/pandora_console/include/db/mysql.php index ce6f814e95..dd3bc26846 100644 --- a/pandora_console/include/db/mysql.php +++ b/pandora_console/include/db/mysql.php @@ -1244,57 +1244,6 @@ function mysql_db_get_all_row_by_steps_sql($new=true, &$result, $sql=null) } -/** - * Starts a database transaction. - */ -function mysql_db_process_sql_begin() -{ - global $config; - - if ($config['mysqli']) { - mysqli_query($config['dbconnection'], 'SET AUTOCOMMIT = 0'); - mysqli_query($config['dbconnection'], 'START TRANSACTION'); - } else { - mysql_query('SET AUTOCOMMIT = 0'); - mysql_query('START TRANSACTION'); - } -} - - -/** - * Commits a database transaction. - */ -function mysql_db_process_sql_commit() -{ - global $config; - - if ($config['mysqli']) { - mysqli_query($config['dbconnection'], 'COMMIT'); - mysqli_query($config['dbconnection'], 'SET AUTOCOMMIT = 1'); - } else { - mysql_query('COMMIT'); - mysql_query('SET AUTOCOMMIT = 1'); - } -} - - -/** - * Rollbacks a database transaction. - */ -function mysql_db_process_sql_rollback() -{ - global $config; - - if ($config['mysqli']) { - mysqli_query($config['dbconnection'], 'ROLLBACK '); - mysqli_query($config['dbconnection'], 'SET AUTOCOMMIT = 1'); - } else { - mysql_query('ROLLBACK '); - mysql_query('SET AUTOCOMMIT = 1'); - } -} - - /** * Get last error. * diff --git a/pandora_console/include/functions_db.php b/pandora_console/include/functions_db.php index a4c21d3bc6..a60dc87b02 100644 --- a/pandora_console/include/functions_db.php +++ b/pandora_console/include/functions_db.php @@ -1377,42 +1377,56 @@ function db_process_sql($sql, $rettype='affected_rows', $dbconnection='', $cache break; } - if ($rc !== false) { - if (enterprise_hook('is_metaconsole') === true - && isset($config['centralized_management']) === true - && (bool) $config['centralized_management'] === true - && $dbconnection === '' - ) { - $errors = null; - try { - // Synchronize changes to nodes if needed. - $sync = new Synchronizer(); - if ($sync !== null) { - if ($sync->queue($sql) === false) { - // Launch events per failed query. - $errors = $sync->getLatestErrors(); - if ($errors !== null) { - $errors = join(', ', $errors); - } else { - $errors = ''; - } - } - } - } catch (\Exception $e) { - $errors = $e->getMessage(); - } - - if ($errors !== null) { - // TODO: Generate pandora event. - error_log($errors); - } - } - } + db_sync($dbconnection, $sql, $rc); return $rc; } +/** + * Propagate to nodes. + * + * @param mixed $dbconnection Dbconnection. + * @param mixed $sql Sql. + * @param mixed $rc Rc. + * + * @return void + */ +function db_sync($dbconnection, $sql, $rc) +{ + global $config; + if (enterprise_hook('is_metaconsole') === true + && isset($config['centralized_management']) === true + && (bool) $config['centralized_management'] === true + && $dbconnection === '' + ) { + $errors = null; + try { + // Synchronize changes to nodes if needed. + $sync = new Synchronizer(); + if ($sync !== null) { + if ($sync->queue($sql, $rc) === false) { + // Launch events per failed query. + $errors = $sync->getLatestErrors(); + if ($errors !== null) { + $errors = join(', ', $errors); + } else { + $errors = ''; + } + } + } + } catch (\Exception $e) { + $errors = $e->getMessage(); + } + + if ($errors !== null) { + // TODO: Generate pandora event. + error_log($errors); + } + } +} + + /** * Get all the rows in a table of the database. * @@ -1810,18 +1824,17 @@ function db_process_sql_begin() global $config; switch ($config['dbtype']) { - case 'mysql': - return mysql_db_process_sql_begin(); - - break; case 'postgresql': return postgresql_db_process_sql_begin(); - break; case 'oracle': return oracle_db_process_sql_begin(); - break; + default: + case 'mysql': + db_process_sql('SET AUTOCOMMIT = 0', 'affected_rows', '', false, null, false); + db_process_sql('START TRANSACTION', 'affected_rows', '', false, null, false); + break; } } @@ -1834,18 +1847,17 @@ function db_process_sql_commit() global $config; switch ($config['dbtype']) { - case 'mysql': - return mysql_db_process_sql_commit(); - - break; case 'postgresql': return postgresql_db_process_sql_commit(); - break; case 'oracle': return oracle_db_process_sql_commit(); - break; + default: + case 'mysql': + db_process_sql('COMMIT', 'affected_rows', '', false, null, false); + db_process_sql('SET AUTOCOMMIT = 1', 'affected_rows', '', false, null, false); + break; } } @@ -1858,18 +1870,17 @@ function db_process_sql_rollback() global $config; switch ($config['dbtype']) { - case 'mysql': - return mysql_db_process_sql_rollback(); - - break; case 'postgresql': return postgresql_db_process_sql_rollback(); - break; case 'oracle': return oracle_db_process_sql_rollback(); - break; + default: + case 'mysql': + db_process_sql('ROLLBACK', 'affected_rows', '', false, null, false); + db_process_sql('SET AUTOCOMMIT = 1', 'affected_rows', '', false, null, false); + break; } } @@ -1889,6 +1900,7 @@ function db_print_database_debug() echo '
'.__('Database debug').'
'; + $table = new stdClass(); $table->id = 'database_debug'; $table->cellpadding = '0'; $table->width = '95%'; @@ -1946,18 +1958,15 @@ function db_get_last_error() global $config; switch ($config['dbtype']) { - case 'mysql': - return mysql_db_get_last_error(); - - break; case 'postgresql': return postgresql_db_get_last_error(); - break; case 'oracle': return oracle_db_get_last_error(); - break; + case 'mysql': + default: + return mysql_db_get_last_error(); } } @@ -1975,18 +1984,15 @@ function db_get_type_field_table($table, $field) global $config; switch ($config['dbtype']) { - case 'mysql': - return mysql_db_get_type_field_table($table, $field); - - break; case 'postgresql': return postgresql_db_get_type_field_table($table, $field); - break; case 'oracle': return oracle_db_get_type_field_table($table, $field); - break; + case 'mysql': + default: + return mysql_db_get_type_field_table($table, $field); } } diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql index f8b675c9d6..fe475df931 100644 --- a/pandora_console/pandoradb.sql +++ b/pandora_console/pandoradb.sql @@ -4069,6 +4069,7 @@ CREATE TABLE IF NOT EXISTS `tsync_queue` ( `operation` text, `table` text, `error` MEDIUMTEXT, + `result` TEXT, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; From 5b0641523593e5e60397dc355ff42cbf3ac74cca Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Fri, 3 Dec 2021 13:58:14 +0100 Subject: [PATCH 26/31] errata fix --- pandora_console/include/functions_db.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/pandora_console/include/functions_db.php b/pandora_console/include/functions_db.php index a60dc87b02..34bb53ef26 100644 --- a/pandora_console/include/functions_db.php +++ b/pandora_console/include/functions_db.php @@ -1822,6 +1822,7 @@ function db_process_sql_delete($table, $where, $where_join='AND') function db_process_sql_begin() { global $config; + $null = null; switch ($config['dbtype']) { case 'postgresql': @@ -1832,8 +1833,8 @@ function db_process_sql_begin() default: case 'mysql': - db_process_sql('SET AUTOCOMMIT = 0', 'affected_rows', '', false, null, false); - db_process_sql('START TRANSACTION', 'affected_rows', '', false, null, false); + db_process_sql('SET AUTOCOMMIT = 0', 'affected_rows', '', false, $null, false); + db_process_sql('START TRANSACTION', 'affected_rows', '', false, $null, false); break; } } @@ -1845,6 +1846,7 @@ function db_process_sql_begin() function db_process_sql_commit() { global $config; + $null = null; switch ($config['dbtype']) { case 'postgresql': @@ -1855,8 +1857,8 @@ function db_process_sql_commit() default: case 'mysql': - db_process_sql('COMMIT', 'affected_rows', '', false, null, false); - db_process_sql('SET AUTOCOMMIT = 1', 'affected_rows', '', false, null, false); + db_process_sql('COMMIT', 'affected_rows', '', false, $null, false); + db_process_sql('SET AUTOCOMMIT = 1', 'affected_rows', '', false, $null, false); break; } } @@ -1868,6 +1870,7 @@ function db_process_sql_commit() function db_process_sql_rollback() { global $config; + $null = null; switch ($config['dbtype']) { case 'postgresql': @@ -1878,8 +1881,8 @@ function db_process_sql_rollback() default: case 'mysql': - db_process_sql('ROLLBACK', 'affected_rows', '', false, null, false); - db_process_sql('SET AUTOCOMMIT = 1', 'affected_rows', '', false, null, false); + db_process_sql('ROLLBACK', 'affected_rows', '', false, $null, false); + db_process_sql('SET AUTOCOMMIT = 1', 'affected_rows', '', false, $null, false); break; } } From 6d469912fad3be57954a01e4f289f3d1ec08601c Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Fri, 3 Dec 2021 14:24:00 +0100 Subject: [PATCH 27/31] some fixes --- pandora_console/include/db/mysql.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pandora_console/include/db/mysql.php b/pandora_console/include/db/mysql.php index dd3bc26846..872f4a0496 100644 --- a/pandora_console/include/db/mysql.php +++ b/pandora_console/include/db/mysql.php @@ -1339,7 +1339,7 @@ function mysql_db_process_file($path, $handle_error=true) $query = ''; // Begin the transaction - mysql_db_process_sql_begin(); + db_process_sql_begin(); foreach ($file_content as $sql_line) { if (trim($sql_line) != '' && strpos($sql_line, '--') === false) { @@ -1354,7 +1354,7 @@ function mysql_db_process_file($path, $handle_error=true) if (!$result = $query_result) { // Error. Rollback the transaction - mysql_db_process_sql_rollback(); + db_process_sql_rollback(); if ($config['mysqli']) { $error_message = mysqli_error($config['dbconnection']); @@ -1391,7 +1391,7 @@ function mysql_db_process_file($path, $handle_error=true) } // No errors. Commit the transaction - mysql_db_process_sql_commit(); + db_process_sql_commit(); return true; } else { return false; @@ -1430,7 +1430,7 @@ function db_run_sql_file($location) $mysqli->query($config['dbconnection'], 'START TRANSACTION'); } else { // Run commands - mysql_db_process_sql_begin(); + db_process_sql_begin(); // Begin transaction } @@ -1456,7 +1456,7 @@ function db_run_sql_file($location) $mysqli->query($config['dbconnection'], 'COMMIT'); $mysqli->query($config['dbconnection'], 'SET AUTOCOMMIT = 1'); } else { - mysql_db_process_sql_commit(); + db_process_sql_commit(); // Save results } @@ -1466,7 +1466,7 @@ function db_run_sql_file($location) $mysqli->query($config['dbconnection'], 'ROLLBACK '); $mysqli->query($config['dbconnection'], 'SET AUTOCOMMIT = 1'); } else { - mysql_db_process_sql_rollback(); + db_process_sql_rollback(); // Undo results } From b19bc9c8abe9690ecb58eb7864dd20fafd46fa05 Mon Sep 17 00:00:00 2001 From: Daniel Barbero Martin Date: Tue, 7 Dec 2021 09:05:50 +0100 Subject: [PATCH 28/31] wip reports alert actions --- pandora_console/extensions/agents_modules.php | 48 +++++++++---------- 1 file changed, 22 insertions(+), 26 deletions(-) diff --git a/pandora_console/extensions/agents_modules.php b/pandora_console/extensions/agents_modules.php index 3c5defe04d..815a0ed8d0 100644 --- a/pandora_console/extensions/agents_modules.php +++ b/pandora_console/extensions/agents_modules.php @@ -89,14 +89,13 @@ function agents_modules_load_js() var controls = document.getElementById('vc-controls'); autoHideElement(controls, 1000); - + $('select#refresh').change(function (event) { refr = Number.parseInt(event.target.value, 10); startCountDown(refr, false); }); } else { - var agentes_id = $("#id_agents2").val(); var id_agentes = getQueryParam("full_agents_id"); if (agentes_id === null && id_agentes !== null) { @@ -104,15 +103,15 @@ function agents_modules_load_js() id_agentes.forEach(function(element) { $("#id_agents2 option[value="+ element +"]").attr("selected",true); }); - + selection_agent_module(); } - + $('#refresh').change(function () { $('#hidden-vc_refr').val($('#refresh option:selected').val()); }); } - + $("#group_id").change (function () { jQuery.post ("ajax.php", {"page" : "operation/agentes/ver_agente", @@ -128,7 +127,6 @@ function agents_modules_load_js() jQuery.each (data, function (id, value) { // Remove keys_prefix from the index id = id.substring(1); - option = $("") .attr ("value", value["id_agente"]) .html (value["alias"]); @@ -139,7 +137,7 @@ function agents_modules_load_js() "json" ); }); - + $("#checkbox-recursion").change (function () { jQuery.post ("ajax.php", {"page" : "operation/agentes/ver_agente", @@ -155,7 +153,6 @@ function agents_modules_load_js() jQuery.each (data, function (id, value) { // Remove keys_prefix from the index id = id.substring(1); - option = $("") .attr ("value", value["id_agente"]) .html (value["alias"]); @@ -166,7 +163,7 @@ function agents_modules_load_js() "json" ); }); - + $("#modulegroup").change (function () { jQuery.post ("ajax.php", {"page" : "operation/agentes/ver_agente", @@ -180,8 +177,8 @@ function agents_modules_load_js() if(data){ jQuery.each (data, function (id, value) { option = $("") - .attr ("value", value["id_agente_modulo"]) - .html (value["nombre"]); + .attr ("value", id) + .html (value); $("#module").append (option); }); } @@ -207,8 +204,8 @@ function agents_modules_load_js() if(data){ jQuery.each (data, function (id, value) { option = $("") - .attr ("value", value["id_agente_modulo"]) - .html (value["nombre"]); + .attr ("value", id) + .html (value); $("#module").append (option); }); } @@ -231,11 +228,11 @@ function agents_modules_load_js() if(data){ jQuery.each (data, function (id, value) { option = $("") - .attr ("value", value["id_agente_modulo"]) - .html (value["nombre"]); + .attr ("value", id) + .html (value); $("#module").append (option); }); - + var id_modules = getQueryParam("full_modules_selected"); if(id_modules !== null) { id_modules = id_modules.split(";"); @@ -249,20 +246,19 @@ function agents_modules_load_js() ); } - function getQueryParam (key) { - key = key.replace(/[[]/, '['); - key = key.replace(/[]]/, ']'); - var pattern = "[?&]" + key + "=([^&#]*)"; + function getQueryParam (key) { + key = key.replace(/[[]/, '['); + key = key.replace(/[]]/, ']'); + var pattern = "[?&]" + key + "=([^&#]*)"; var regex = new RegExp(pattern); var url = unescape(window.location.href); var results = regex.exec(url); - if (results === null) { - return null; - } else { - return results[1]; - } + if (results === null) { + return null; + } else { + return results[1]; + } } - Date: Tue, 7 Dec 2021 11:00:48 +0100 Subject: [PATCH 29/31] wip reports alert actions --- pandora_console/include/functions_alerts.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandora_console/include/functions_alerts.php b/pandora_console/include/functions_alerts.php index 067e631bee..f308acaa0a 100644 --- a/pandora_console/include/functions_alerts.php +++ b/pandora_console/include/functions_alerts.php @@ -3373,10 +3373,10 @@ function alerts_get_alert_fired($filters=[], $groupsBy=[]) && ($groupsBy['group_by'] === 'agent' || $groupsBy['group_by'] === 'module') ) { - unset($total_values['Period']); unset($total_values['server']); } + unset($total_values['Period']); $result['summary']['total'] = $total_values; $result['summary']['total'][$groupsBy['group_by']] = __('Total'); } From ffc3728f2a8daebe83b8bb56b368ce85414578f4 Mon Sep 17 00:00:00 2001 From: Daniel Barbero Martin Date: Tue, 7 Dec 2021 15:50:34 +0100 Subject: [PATCH 30/31] fix minor error --- pandora_console/include/functions_reporting.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index ff12d6bdd9..231684c90a 100755 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -2694,7 +2694,7 @@ function reporting_alert_report_actions($report, $content) $es = json_decode($content['external_source'], true); if (isset($report['id_template']) === true - && empty($resport['id_template']) === false + && empty($report['id_template']) === false ) { if (is_metaconsole() === true) { $server_id = metaconsole_get_id_server($content['server_name']); From 3dd92397f904654d2a35a8149310e75374abd3f7 Mon Sep 17 00:00:00 2001 From: artica Date: Fri, 10 Dec 2021 01:00:20 +0100 Subject: [PATCH 31/31] Auto-updated build strings. --- pandora_agents/unix/DEBIAN/control | 2 +- pandora_agents/unix/DEBIAN/make_deb_package.sh | 2 +- pandora_agents/unix/pandora_agent | 2 +- pandora_agents/unix/pandora_agent.redhat.spec | 2 +- pandora_agents/unix/pandora_agent.spec | 2 +- pandora_agents/unix/pandora_agent_installer | 2 +- pandora_agents/win32/installer/pandora.mpi | 2 +- pandora_agents/win32/pandora.cc | 2 +- pandora_agents/win32/versioninfo.rc | 2 +- pandora_console/DEBIAN/control | 2 +- pandora_console/DEBIAN/make_deb_package.sh | 2 +- pandora_console/include/config_process.php | 2 +- pandora_console/install.php | 2 +- pandora_console/pandora_console.redhat.spec | 2 +- pandora_console/pandora_console.rhel7.spec | 2 +- pandora_console/pandora_console.spec | 2 +- pandora_server/DEBIAN/control | 2 +- pandora_server/DEBIAN/make_deb_package.sh | 2 +- pandora_server/lib/PandoraFMS/Config.pm | 2 +- pandora_server/lib/PandoraFMS/PluginTools.pm | 2 +- pandora_server/pandora_server.redhat.spec | 2 +- pandora_server/pandora_server.spec | 2 +- pandora_server/pandora_server_installer | 2 +- pandora_server/util/pandora_db.pl | 2 +- pandora_server/util/pandora_manage.pl | 2 +- 25 files changed, 25 insertions(+), 25 deletions(-) diff --git a/pandora_agents/unix/DEBIAN/control b/pandora_agents/unix/DEBIAN/control index b85bad5f8b..57b1b77d69 100644 --- a/pandora_agents/unix/DEBIAN/control +++ b/pandora_agents/unix/DEBIAN/control @@ -1,5 +1,5 @@ package: pandorafms-agent-unix -Version: 7.0NG.758.1-211209 +Version: 7.0NG.758.1-211210 Architecture: all Priority: optional Section: admin diff --git a/pandora_agents/unix/DEBIAN/make_deb_package.sh b/pandora_agents/unix/DEBIAN/make_deb_package.sh index 78c2f450bf..a7c88922c7 100644 --- a/pandora_agents/unix/DEBIAN/make_deb_package.sh +++ b/pandora_agents/unix/DEBIAN/make_deb_package.sh @@ -14,7 +14,7 @@ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -pandora_version="7.0NG.758.1-211209" +pandora_version="7.0NG.758.1-211210" echo "Test if you has the tools for to make the packages." whereis dpkg-deb | cut -d":" -f2 | grep dpkg-deb > /dev/null diff --git a/pandora_agents/unix/pandora_agent b/pandora_agents/unix/pandora_agent index 8785e3288a..e01e061a44 100755 --- a/pandora_agents/unix/pandora_agent +++ b/pandora_agents/unix/pandora_agent @@ -1015,7 +1015,7 @@ my $Sem = undef; my $ThreadSem = undef; use constant AGENT_VERSION => '7.0NG.758.1'; -use constant AGENT_BUILD => '211209'; +use constant AGENT_BUILD => '211210'; # Agent log default file size maximum and instances use constant DEFAULT_MAX_LOG_SIZE => 600000; diff --git a/pandora_agents/unix/pandora_agent.redhat.spec b/pandora_agents/unix/pandora_agent.redhat.spec index b719f93ca2..c92fcf61b4 100644 --- a/pandora_agents/unix/pandora_agent.redhat.spec +++ b/pandora_agents/unix/pandora_agent.redhat.spec @@ -3,7 +3,7 @@ # %define name pandorafms_agent_unix %define version 7.0NG.758.1 -%define release 211209 +%define release 211210 Summary: Pandora FMS Linux agent, PERL version Name: %{name} diff --git a/pandora_agents/unix/pandora_agent.spec b/pandora_agents/unix/pandora_agent.spec index aee4484e05..16f4b6fee4 100644 --- a/pandora_agents/unix/pandora_agent.spec +++ b/pandora_agents/unix/pandora_agent.spec @@ -3,7 +3,7 @@ # %define name pandorafms_agent_unix %define version 7.0NG.758.1 -%define release 211209 +%define release 211210 Summary: Pandora FMS Linux agent, PERL version Name: %{name} diff --git a/pandora_agents/unix/pandora_agent_installer b/pandora_agents/unix/pandora_agent_installer index acc2227413..adca572c73 100755 --- a/pandora_agents/unix/pandora_agent_installer +++ b/pandora_agents/unix/pandora_agent_installer @@ -10,7 +10,7 @@ # ********************************************************************** PI_VERSION="7.0NG.758.1" -PI_BUILD="211209" +PI_BUILD="211210" OS_NAME=`uname -s` FORCE=0 diff --git a/pandora_agents/win32/installer/pandora.mpi b/pandora_agents/win32/installer/pandora.mpi index 7cfdde9d37..ffc71aaccb 100644 --- a/pandora_agents/win32/installer/pandora.mpi +++ b/pandora_agents/win32/installer/pandora.mpi @@ -186,7 +186,7 @@ UpgradeApplicationID {} Version -{211209} +{211210} ViewReadme {Yes} diff --git a/pandora_agents/win32/pandora.cc b/pandora_agents/win32/pandora.cc index 9c169ee9b8..7b6560677e 100644 --- a/pandora_agents/win32/pandora.cc +++ b/pandora_agents/win32/pandora.cc @@ -30,7 +30,7 @@ using namespace Pandora; using namespace Pandora_Strutils; #define PATH_SIZE _MAX_PATH+1 -#define PANDORA_VERSION ("7.0NG.758.1 Build 211209") +#define PANDORA_VERSION ("7.0NG.758.1 Build 211210") string pandora_path; string pandora_dir; diff --git a/pandora_agents/win32/versioninfo.rc b/pandora_agents/win32/versioninfo.rc index 77def11f3d..43106ff959 100644 --- a/pandora_agents/win32/versioninfo.rc +++ b/pandora_agents/win32/versioninfo.rc @@ -11,7 +11,7 @@ BEGIN VALUE "LegalCopyright", "Artica ST" VALUE "OriginalFilename", "PandoraAgent.exe" VALUE "ProductName", "Pandora FMS Windows Agent" - VALUE "ProductVersion", "(7.0NG.758.1(Build 211209))" + VALUE "ProductVersion", "(7.0NG.758.1(Build 211210))" VALUE "FileVersion", "1.0.0.0" END END diff --git a/pandora_console/DEBIAN/control b/pandora_console/DEBIAN/control index f728ce6013..98a48ae7c0 100644 --- a/pandora_console/DEBIAN/control +++ b/pandora_console/DEBIAN/control @@ -1,5 +1,5 @@ package: pandorafms-console -Version: 7.0NG.758.1-211209 +Version: 7.0NG.758.1-211210 Architecture: all Priority: optional Section: admin diff --git a/pandora_console/DEBIAN/make_deb_package.sh b/pandora_console/DEBIAN/make_deb_package.sh index e166255f37..d0fcd0a5b6 100644 --- a/pandora_console/DEBIAN/make_deb_package.sh +++ b/pandora_console/DEBIAN/make_deb_package.sh @@ -14,7 +14,7 @@ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -pandora_version="7.0NG.758.1-211209" +pandora_version="7.0NG.758.1-211210" package_pear=0 package_pandora=1 diff --git a/pandora_console/include/config_process.php b/pandora_console/include/config_process.php index cc993ea8db..fb12849375 100644 --- a/pandora_console/include/config_process.php +++ b/pandora_console/include/config_process.php @@ -20,7 +20,7 @@ /** * Pandora build version and version */ -$build_version = 'PC211209'; +$build_version = 'PC211210'; $pandora_version = 'v7.0NG.758.1'; // Do not overwrite default timezone set if defined. diff --git a/pandora_console/install.php b/pandora_console/install.php index fa22b799d2..9409f2e16a 100644 --- a/pandora_console/install.php +++ b/pandora_console/install.php @@ -129,7 +129,7 @@
[ qw() ] ); diff --git a/pandora_server/pandora_server.redhat.spec b/pandora_server/pandora_server.redhat.spec index b2c23967b4..fa361febce 100644 --- a/pandora_server/pandora_server.redhat.spec +++ b/pandora_server/pandora_server.redhat.spec @@ -3,7 +3,7 @@ # %define name pandorafms_server %define version 7.0NG.758.1 -%define release 211209 +%define release 211210 Summary: Pandora FMS Server Name: %{name} diff --git a/pandora_server/pandora_server.spec b/pandora_server/pandora_server.spec index c620bf046b..bee4d6e6af 100644 --- a/pandora_server/pandora_server.spec +++ b/pandora_server/pandora_server.spec @@ -3,7 +3,7 @@ # %define name pandorafms_server %define version 7.0NG.758.1 -%define release 211209 +%define release 211210 Summary: Pandora FMS Server Name: %{name} diff --git a/pandora_server/pandora_server_installer b/pandora_server/pandora_server_installer index a5113530fd..d4c119cc3c 100755 --- a/pandora_server/pandora_server_installer +++ b/pandora_server/pandora_server_installer @@ -9,7 +9,7 @@ # ********************************************************************** PI_VERSION="7.0NG.758.1" -PI_BUILD="211209" +PI_BUILD="211210" MODE=$1 if [ $# -gt 1 ]; then diff --git a/pandora_server/util/pandora_db.pl b/pandora_server/util/pandora_db.pl index 82d95ba626..0c25f4e03d 100755 --- a/pandora_server/util/pandora_db.pl +++ b/pandora_server/util/pandora_db.pl @@ -35,7 +35,7 @@ use PandoraFMS::Config; use PandoraFMS::DB; # version: define current version -my $version = "7.0NG.758.1 Build 211209"; +my $version = "7.0NG.758.1 Build 211210"; # Pandora server configuration my %conf; diff --git a/pandora_server/util/pandora_manage.pl b/pandora_server/util/pandora_manage.pl index 99eec58391..b1a59eac21 100755 --- a/pandora_server/util/pandora_manage.pl +++ b/pandora_server/util/pandora_manage.pl @@ -36,7 +36,7 @@ use Encode::Locale; Encode::Locale::decode_argv; # version: define current version -my $version = "7.0NG.758.1 Build 211209"; +my $version = "7.0NG.758.1 Build 211210"; # save program name for logging my $progname = basename($0);