From 3f28a9874486bc0cc59bf5b1f0d53aa62a9711c3 Mon Sep 17 00:00:00 2001 From: Jose Gonzalez Date: Wed, 13 Oct 2021 14:58:31 +0200 Subject: [PATCH 01/59] Added feature for read comments in grouped events --- pandora_console/include/ajax/events.php | 40 ++++++++--- pandora_console/include/functions_events.php | 72 +++++++++++++------- 2 files changed, 78 insertions(+), 34 deletions(-) diff --git a/pandora_console/include/ajax/events.php b/pandora_console/include/ajax/events.php index 11811eda38..c3678ab90f 100644 --- a/pandora_console/include/ajax/events.php +++ b/pandora_console/include/ajax/events.php @@ -83,10 +83,10 @@ $in_process_event = get_parameter('in_process_event', 0); $validate_event = get_parameter('validate_event', 0); $delete_event = get_parameter('delete_event', 0); $get_event_filters = get_parameter('get_event_filters', 0); -$get_comments = get_parameter('get_comments', 0); +$get_comments = (bool) get_parameter('get_comments', false); $get_events_fired = (bool) get_parameter('get_events_fired'); $get_id_source_event = get_parameter('get_id_source_event'); -if ($get_comments) { +if ($get_comments === true) { $event = get_parameter('event', false); $filter = get_parameter('filter', false); @@ -94,6 +94,8 @@ if ($get_comments) { return __('Failed to retrieve comments'); } + $eventsGrouped = []; + if ($filter['group_rep'] == 1) { $events = events_get_all( ['te.*'], @@ -119,23 +121,39 @@ if ($get_comments) { // True for show comments of validated events. true ); + if ($events !== false) { $event = $events[0]; } } else { - $events = events_get_event( - $event['id_evento'], - false, - $meta, - $history - ); + // Consider if the event is grouped. + if (isset($event['event_rep']) === true && $event['event_rep'] > 0) { + $eventsGrouped = db_get_all_rows_sql( + sprintf( + 'SELECT `user_comment` + FROM `tevento` + WHERE `id_agente` = "%d" AND `data` = "%d" AND `estado` = "%d"', + $event['id_agente'], + $event['data'], + $event['estado'] + ) + ); + } else { + $events = events_get_event( + $event['id_evento'], + false, + $meta, + $history + ); - if ($events !== false) { - $event = $events; + if ($events !== false) { + $event = $events; + } } } - echo events_page_comments($event, true); + // End of get_comments. + echo events_page_comments($event, true, $eventsGrouped); return; } diff --git a/pandora_console/include/functions_events.php b/pandora_console/include/functions_events.php index 5e727cf08c..21ca42d1c9 100644 --- a/pandora_console/include/functions_events.php +++ b/pandora_console/include/functions_events.php @@ -1619,14 +1619,14 @@ function events_get_events($filter=false, $fields=false) */ function events_get_event($id, $fields=false, $meta=false, $history=false) { - if (empty($id)) { + if (empty($id) === true) { return false; } global $config; - if (is_array($fields)) { - if (! in_array('id_grupo', $fields)) { + if (is_array($fields) === true) { + if (in_array('id_grupo', $fields) === false) { $fields[] = 'id_grupo'; } } @@ -1634,7 +1634,7 @@ function events_get_event($id, $fields=false, $meta=false, $history=false) $table = events_get_events_table($meta, $history); $event = db_get_row($table, 'id_evento', $id, $fields); - if (! check_acl($config['id_user'], $event['id_grupo'], 'ER')) { + if ((bool) check_acl($config['id_user'], $event['id_grupo'], 'ER') === false) { return false; } @@ -2255,7 +2255,7 @@ function events_comment( // If comments are not stored in json, the format is old. $event_comments_array = json_decode($event_comments[0]['user_comment']); - if (empty($event_comments_array)) { + if (empty($event_comments_array) === true) { $comments_format = 'old'; } else { $comments_format = 'new'; @@ -2268,6 +2268,7 @@ function events_comment( $comment_for_json['action'] = $action; $comment_for_json['id_user'] = $config['id_user']; $comment_for_json['utimestamp'] = time(); + $comment_for_json['event_id'] = $first_event; $event_comments_array[] = $comment_for_json; @@ -2282,11 +2283,11 @@ function events_comment( break; case 'old': - // Give old ugly format to comment. TODO: Change this method for - // aux table or json. + // Give old ugly format to comment. + // Change this method for aux table or json. $comment = str_replace(["\r\n", "\r", "\n"], '
', $comment); - if ($comment != '') { + if ($comment !== '') { $commentbox = '
'.io_safe_input($comment).'
'; } else { $commentbox = ''; @@ -5082,11 +5083,13 @@ function events_page_general($event) /** * Generate 'comments' page for event viewer. * - * @param array $event Event. + * @param array $event Event. + * @param boolean $ajax If the query come from AJAX. + * @param boolean $grouped If the event must shown comments grouped. * * @return string HTML. */ -function events_page_comments($event, $ajax=false) +function events_page_comments($event, $ajax=false, $groupedComments=[]) { // Comments. global $config; @@ -5097,23 +5100,36 @@ function events_page_comments($event, $ajax=false) $table_comments->head = []; $table_comments->class = 'table_modal_alternate'; - $comments = ($event['user_comment'] ?? ''); + $comments = (empty($groupedComments) === true) ? $event['user_comment'] : $groupedComments; - if (empty($comments)) { + if (empty($comments) === true) { $table_comments->style[0] = 'text-align:center;'; $table_comments->colspan[0][0] = 2; $data = []; $data[0] = __('There are no comments'); $table_comments->data[] = $data; } else { - if (is_array($comments)) { + if (is_array($comments) === true) { + $comments_array = []; foreach ($comments as $comm) { - if (empty($comm)) { + if (empty($comm) === true) { continue; } + // If exists user_comments, come from grouped events and must be handled like this. + if (isset($comm['user_comment']) === true) { + $comm = $comm['user_comment']; + } + $comments_array[] = io_safe_output(json_decode($comm, true)); } + + usort( + $comments_array, + function ($a, $b) { + return ($a[(count($a) - 1)]['utimestamp'] < $b[(count($b) - 1)]['utimestamp']); + } + ); } else { $comments = str_replace(["\n", ' '], '
', $comments); // If comments are not stored in json, the format is old. @@ -5122,22 +5138,32 @@ function events_page_comments($event, $ajax=false) foreach ($comments_array as $comm) { // Show the comments more recent first. - if (is_array($comm)) { + if (is_array($comm) === true) { $comm = array_reverse($comm); } - if (empty($comm)) { - $comments_format = 'old'; - } else { - $comments_format = 'new'; - } + $comments_format = (empty($comm) === true ? 'old' : 'new'); switch ($comments_format) { case 'new': foreach ($comm as $c) { - $data[0] = ''.$c['action'].' by '.$c['id_user'].''; - $data[0] .= '

'.date($config['date_format'], $c['utimestamp']).''; + $eventIdExplanation = (empty($groupedComments) === false) ? sprintf(' (#%d)', $c['event_id']) : ''; + + $data[0] = sprintf( + '%s %s %s%s', + $c['action'], + __('by'), + $c['id_user'], + $eventIdExplanation + ); + + $data[0] .= sprintf( + '

%s', + date($config['date_format'], $c['utimestamp']) + ); + $data[1] = '

'.stripslashes(str_replace(['\n', '\r'], '
', $c['comment'])).'

'; + $table_comments->data[] = $data; } break; @@ -5227,7 +5253,7 @@ function events_page_comments($event, $ajax=false) ); } - if ($ajax) { + if ($ajax === true) { return $comments_form.html_print_table($table_comments, true); } From e70ecd461edac18a241a32b087ee951f6fbe54a8 Mon Sep 17 00:00:00 2001 From: Daniel Barbero Martin Date: Fri, 12 Nov 2021 13:11:49 +0100 Subject: [PATCH 02/59] 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 03/59] 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 04/59] 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 b151b3996dcdbd64a46885a7a9b9095bc59c24ec Mon Sep 17 00:00:00 2001 From: Jose Gonzalez Date: Thu, 25 Nov 2021 13:52:53 +0100 Subject: [PATCH 05/59] Fixed issue with events --- pandora_console/include/ajax/events.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/pandora_console/include/ajax/events.php b/pandora_console/include/ajax/events.php index c3678ab90f..af304d9319 100644 --- a/pandora_console/include/ajax/events.php +++ b/pandora_console/include/ajax/events.php @@ -132,10 +132,8 @@ if ($get_comments === true) { sprintf( 'SELECT `user_comment` FROM `tevento` - WHERE `id_agente` = "%d" AND `data` = "%d" AND `estado` = "%d"', - $event['id_agente'], - $event['data'], - $event['estado'] + WHERE `evento` = "%s"', + io_safe_output($event['evento']) ) ); } else { From dae6182ef0e3aa5d4289b8a5f5175ff1654ea83a Mon Sep 17 00:00:00 2001 From: Daniel Barbero Martin Date: Thu, 25 Nov 2021 17:28:00 +0100 Subject: [PATCH 06/59] 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 07/59] 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 5eb4a869cc8dd3231b9777e55237a9d14eb99e1f Mon Sep 17 00:00:00 2001 From: Jose Gonzalez Date: Fri, 26 Nov 2021 11:51:27 +0100 Subject: [PATCH 08/59] Fix issue with metaconsole comments --- pandora_console/include/ajax/events.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pandora_console/include/ajax/events.php b/pandora_console/include/ajax/events.php index af304d9319..8533902238 100644 --- a/pandora_console/include/ajax/events.php +++ b/pandora_console/include/ajax/events.php @@ -128,11 +128,13 @@ if ($get_comments === true) { } else { // Consider if the event is grouped. if (isset($event['event_rep']) === true && $event['event_rep'] > 0) { + $eventTable = (is_metaconsole() === true) ? 'tmetaconsole_event' : 'tevento'; $eventsGrouped = db_get_all_rows_sql( sprintf( 'SELECT `user_comment` - FROM `tevento` + FROM `%s` WHERE `evento` = "%s"', + $eventTable, io_safe_output($event['evento']) ) ); @@ -140,7 +142,7 @@ if ($get_comments === true) { $events = events_get_event( $event['id_evento'], false, - $meta, + is_metaconsole(), $history ); From 0b04ba44f2e9fcec9ec2d3b1912c285192eee5c9 Mon Sep 17 00:00:00 2001 From: Daniel Barbero Martin Date: Fri, 26 Nov 2021 12:15:39 +0100 Subject: [PATCH 09/59] 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 10/59] 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 11/59] 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 12/59] 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 13/59] 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 14/59] 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 7d8a5b029ec5cc4609560569841551bf7b1aa32a Mon Sep 17 00:00:00 2001 From: Calvo Date: Mon, 29 Nov 2021 14:45:19 +0100 Subject: [PATCH 15/59] Changed radio buttons to select on prediction modules --- .../agentes/module_manager_editor_prediction.php | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/pandora_console/godmode/agentes/module_manager_editor_prediction.php b/pandora_console/godmode/agentes/module_manager_editor_prediction.php index 7c319fa531..70ad75bb01 100644 --- a/pandora_console/godmode/agentes/module_manager_editor_prediction.php +++ b/pandora_console/godmode/agentes/module_manager_editor_prediction.php @@ -38,7 +38,7 @@ if ($row !== false && is_array($row)) { switch ($prediction_module) { case MODULE_PREDICTION_SERVICE: - $is_service = true; + $selected = 'service_selected'; $custom_integer_2 = 0; break; @@ -61,9 +61,9 @@ if ($row !== false && is_array($row)) { if (isset($first_op[1]) && $first_op[1] == 'avg') { - $is_synthetic_avg = true; + $selected = 'synthetic_selected'; } else { - $is_synthetic = true; + $selected = 'synthetic_avg_selected'; } $custom_integer_1 = 0; @@ -97,7 +97,7 @@ $data[0] = __('Source module'); $data[0] .= ui_print_help_icon('prediction_source_module', true); $data[1] = ''; // Services and Synthetic are an Enterprise feature. -$module_service_synthetic_selector = enterprise_hook('get_module_service_synthetic_selector', [$is_service, $is_synthetic, $is_synthetic_avg]); +$module_service_synthetic_selector = enterprise_hook('get_module_service_synthetic_selector', [$selected]); if ($module_service_synthetic_selector !== ENTERPRISE_NOT_HOOK) { $data[1] = $module_service_synthetic_selector; @@ -214,10 +214,7 @@ unset($table_advanced->data[3]); enterprise_hook( 'setup_services_synth', [ - $is_service, - $is_synthetic, - $is_synthetic_avg, - $is_netflow, + $type, $ops, ] ); From 7918b883aa7d549e48c8c17a5eb87ca407ddd611 Mon Sep 17 00:00:00 2001 From: Jose Gonzalez Date: Mon, 29 Nov 2021 16:12:15 +0100 Subject: [PATCH 16/59] Set the last grouped comments to last events fired --- pandora_console/include/ajax/events.php | 23 +++++++------------ .../include/javascript/pandora_events.js | 7 ++++-- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/pandora_console/include/ajax/events.php b/pandora_console/include/ajax/events.php index 8533902238..c8813ab01c 100644 --- a/pandora_console/include/ajax/events.php +++ b/pandora_console/include/ajax/events.php @@ -1225,26 +1225,19 @@ if ($dialogue_event_response) { } } -if ($add_comment) { - $aviability_comment = true; - $comment = get_parameter('comment'); +if ($add_comment === true) { + $comment = (string) get_parameter('comment'); + $eventId = (int) get_parameter('event_id'); + + // Safe comments for hacks. if (preg_match('/script/i', io_safe_output($comment))) { - $aviability_comment = false; $return = false; - } - - $event_id = get_parameter('event_id'); - - if ($aviability_comment !== false) { - $return = events_comment($event_id, $comment, 'Added comment', $meta, $history); - } - - if ($return) { - echo 'comment_ok'; } else { - echo 'comment_error'; + $return = events_comment($eventId, $comment, 'Added comment', $meta, $history); } + echo ($return === true) ? 'comment_ok' : 'comment_error'; + return; } diff --git a/pandora_console/include/javascript/pandora_events.js b/pandora_console/include/javascript/pandora_events.js index b5d684324c..19970e76dc 100644 --- a/pandora_console/include/javascript/pandora_events.js +++ b/pandora_console/include/javascript/pandora_events.js @@ -576,7 +576,6 @@ function event_comment(current_event) { return; } - var event_id = event.id_evento; var comment = $("#textarea_comment").val(); var meta = 0; if ($("#hidden-meta").val() != undefined) { @@ -596,7 +595,11 @@ function event_comment(current_event) { var params = []; params.push("page=include/ajax/events"); params.push("add_comment=1"); - params.push("event_id=" + event_id); + if (event.event_rep > 0) { + params.push("event_id=" + event.max_id_evento); + } else { + params.push("event_id=" + event.id_evento); + } params.push("comment=" + comment); params.push("meta=" + meta); params.push("history=" + history); From e8bf86a789ec565d1b598fcc591cfbbe1e95fe39 Mon Sep 17 00:00:00 2001 From: Daniel Barbero Martin Date: Mon, 29 Nov 2021 17:55:09 +0100 Subject: [PATCH 17/59] 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 18/59] 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 64e08d7124ae26fbb33f39f39c921d0445a8f331 Mon Sep 17 00:00:00 2001 From: Jose Gonzalez Date: Tue, 30 Nov 2021 10:50:40 +0100 Subject: [PATCH 19/59] Fixed grouped comments with id_agent --- pandora_console/include/ajax/events.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/pandora_console/include/ajax/events.php b/pandora_console/include/ajax/events.php index c8813ab01c..55a4f05500 100644 --- a/pandora_console/include/ajax/events.php +++ b/pandora_console/include/ajax/events.php @@ -128,14 +128,23 @@ if ($get_comments === true) { } else { // Consider if the event is grouped. if (isset($event['event_rep']) === true && $event['event_rep'] > 0) { + // Evaluate if we are in metaconsole or not. $eventTable = (is_metaconsole() === true) ? 'tmetaconsole_event' : 'tevento'; + // Default grouped message filtering. + $whereGrouped = sprintf('`evento` = "%s"', io_safe_output($event['evento'])); + // If id_agente is reported, filter the messages by them as well. + if ((int) $event['id_agente'] > 0) { + $whereGrouped .= sprintf(' AND `id_agente` = "%s"', $event['id_agente']); + } + + // Get grouped comments. $eventsGrouped = db_get_all_rows_sql( sprintf( 'SELECT `user_comment` FROM `%s` - WHERE `evento` = "%s"', + WHERE %s', $eventTable, - io_safe_output($event['evento']) + $whereGrouped ) ); } else { From 40fc8c7308fba19a31e0bcd54a8f9dfa153236f4 Mon Sep 17 00:00:00 2001 From: Daniel Barbero Martin Date: Tue, 30 Nov 2021 13:07:37 +0100 Subject: [PATCH 20/59] 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 21/59] 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 a38503491aae3eaf6e659b10e0ee22908d949b94 Mon Sep 17 00:00:00 2001 From: Calvo Date: Wed, 1 Dec 2021 11:34:11 +0100 Subject: [PATCH 22/59] Wip: trending prediction modules --- .../godmode/agentes/configurar_agente.php | 6 +++--- .../module_manager_editor_prediction.php | 21 ++++++++++++++----- pandora_console/include/constants.php | 3 +++ 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/pandora_console/godmode/agentes/configurar_agente.php b/pandora_console/godmode/agentes/configurar_agente.php index f73e4d5b5c..6108730a5c 100644 --- a/pandora_console/godmode/agentes/configurar_agente.php +++ b/pandora_console/godmode/agentes/configurar_agente.php @@ -1788,7 +1788,7 @@ if ($update_module) { "Fail to try update module '".io_safe_output($name)."' for agent ".io_safe_output($agent['alias']) ); } else { - if ($prediction_module == 3) { + if ($prediction_module == MODULE_PREDICTION_SYNTHETIC) { enterprise_hook( 'modules_create_synthetic_operations', [ @@ -1931,7 +1931,7 @@ if ($create_module) { } } - if ($prediction_module == 3 && $serialize_ops == '') { + if ($prediction_module == MODULE_PREDICTION_SYNTHETIC && $serialize_ops == '') { $id_agent_module = false; } else { $id_agent_module = modules_create_agent_module( @@ -1972,7 +1972,7 @@ if ($create_module) { "Fail to try added module '".io_safe_output($name)."' for agent ".io_safe_output($agent['alias']) ); } else { - if ($prediction_module == 3) { + if ($prediction_module == MODULE_PREDICTION_SYNTHETIC) { enterprise_hook( 'modules_create_synthetic_operations', [ diff --git a/pandora_console/godmode/agentes/module_manager_editor_prediction.php b/pandora_console/godmode/agentes/module_manager_editor_prediction.php index 70ad75bb01..f84ca2b096 100644 --- a/pandora_console/godmode/agentes/module_manager_editor_prediction.php +++ b/pandora_console/godmode/agentes/module_manager_editor_prediction.php @@ -61,20 +61,29 @@ if ($row !== false && is_array($row)) { if (isset($first_op[1]) && $first_op[1] == 'avg') { - $selected = 'synthetic_selected'; - } else { $selected = 'synthetic_avg_selected'; + } else { + $selected = 'synthetic_selected'; } $custom_integer_1 = 0; $custom_integer_2 = 0; break; + case MODULE_PREDICTION_TRENDING: + $selected = 'module_selected'; + case MODULE_PREDICTION_MODULE: + $selected = 'trending_selected'; + $prediction_module = $custom_integer_1; + break; + default: + $prediction_module = $custom_integer_1; break; } } else { + $selected = 'module_selected'; $custom_integer_1 = 0; } @@ -135,7 +144,8 @@ $params['use_hidden_input_idagent'] = true; $params['hidden_input_idagent_id'] = 'hidden-id_agente_module_prediction'; $data[1] .= ui_print_agent_autocomplete_input($params); -$data[1] .= html_print_label(__('Module'), 'prediction_module', true); +$data[1] .= '
'; +$data[1] .= html_print_label(__('Module'), 'prediction_module', true).'
'; if ($id_agente) { $sql = 'SELECT id_agente_modulo, nombre FROM tagente_modulo @@ -156,6 +166,7 @@ if ($id_agente) { $data[1] .= ''; } +$data[1] .= '
'; $data[1] .= html_print_label(__('Period'), 'custom_integer_2', true).'
'; $periods[0] = __('Weekly'); @@ -187,7 +198,6 @@ if ($synthetic_module_form !== ENTERPRISE_NOT_HOOK) { $data[0] = ''; $data[1] = $synthetic_module_form; - $table_simple->colspan['synthetic_module'][1] = 3; push_table_simple($data, 'synthetic_module'); } @@ -214,7 +224,8 @@ unset($table_advanced->data[3]); enterprise_hook( 'setup_services_synth', [ - $type, + $selected, + $is_netflow, $ops, ] ); diff --git a/pandora_console/include/constants.php b/pandora_console/include/constants.php index 164c6f3983..07d14e816d 100644 --- a/pandora_console/include/constants.php +++ b/pandora_console/include/constants.php @@ -368,12 +368,15 @@ define('MODULE_WUX', 8); define('MODULE_WIZARD', 9); // Type of Modules of Prediction. +define('MODULE_PREDICTION_MODULE', 1); define('MODULE_PREDICTION_SERVICE', 2); define('MODULE_PREDICTION_SYNTHETIC', 3); define('MODULE_PREDICTION_NETFLOW', 4); define('MODULE_PREDICTION_CLUSTER', 5); define('MODULE_PREDICTION_CLUSTER_AA', 6); define('MODULE_PREDICTION_CLUSTER_AP', 7); +define('MODULE_PREDICTION_TRENDING', 8); + // Forced agent OS ID for cluster agents. define('CLUSTER_OS_ID', 100); From 3238811f96834891e2cd0863563404711383460a Mon Sep 17 00:00:00 2001 From: Jose Gonzalez Date: Wed, 1 Dec 2021 13:15:34 +0100 Subject: [PATCH 23/59] Fixed comments issues --- pandora_console/include/ajax/events.php | 8 +++-- pandora_console/include/functions_events.php | 32 ++++++++++++++------ 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/pandora_console/include/ajax/events.php b/pandora_console/include/ajax/events.php index 55a4f05500..a0b5cc6680 100644 --- a/pandora_console/include/ajax/events.php +++ b/pandora_console/include/ajax/events.php @@ -130,8 +130,12 @@ if ($get_comments === true) { if (isset($event['event_rep']) === true && $event['event_rep'] > 0) { // Evaluate if we are in metaconsole or not. $eventTable = (is_metaconsole() === true) ? 'tmetaconsole_event' : 'tevento'; - // Default grouped message filtering. - $whereGrouped = sprintf('`evento` = "%s"', io_safe_output($event['evento'])); + // Default grouped message filtering (evento and estado). + $whereGrouped = sprintf( + '`evento` = "%s" AND `estado` = "%s"', + io_safe_output($event['evento']), + $event['estado'] + ); // If id_agente is reported, filter the messages by them as well. if ((int) $event['id_agente'] > 0) { $whereGrouped .= sprintf(' AND `id_agente` = "%s"', $event['id_agente']); diff --git a/pandora_console/include/functions_events.php b/pandora_console/include/functions_events.php index 21ca42d1c9..7a0d1eac49 100644 --- a/pandora_console/include/functions_events.php +++ b/pandora_console/include/functions_events.php @@ -25,6 +25,8 @@ * GNU General Public License for more details. * ============================================================================ */ + +// Begin. global $config; require_once $config['homedir'].'/include/functions_ui.php'; @@ -35,7 +37,7 @@ enterprise_include_once('include/functions_metaconsole.php'); enterprise_include_once('meta/include/functions_events_meta.php'); enterprise_include_once('meta/include/functions_agents_meta.php'); enterprise_include_once('meta/include/functions_modules_meta.php'); -if (is_metaconsole()) { +if (is_metaconsole() === true) { $id_source_event = get_parameter('id_source_event'); } @@ -5124,12 +5126,29 @@ function events_page_comments($event, $ajax=false, $groupedComments=[]) $comments_array[] = io_safe_output(json_decode($comm, true)); } + // Plain comments. Can be improved. + $sortedCommentsArray = []; + foreach ($comments_array as $comm) { + foreach ($comm as $subComm) { + $sortedCommentsArray[] = $subComm; + } + } + + // Sorting the comments by utimestamp (newer is first). usort( - $comments_array, + $sortedCommentsArray, function ($a, $b) { - return ($a[(count($a) - 1)]['utimestamp'] < $b[(count($b) - 1)]['utimestamp']); + if ($a['utimestamp'] == $b['utimestamp']) { + return 0; + } + + return ($a['utimestamp'] > $b['utimestamp']) ? -1 : 1; } ); + + // Clean the unsorted comments and return it to the original array. + $comments_array = []; + $comments_array[] = $sortedCommentsArray; } else { $comments = str_replace(["\n", ' '], '
', $comments); // If comments are not stored in json, the format is old. @@ -5137,12 +5156,7 @@ function events_page_comments($event, $ajax=false, $groupedComments=[]) } foreach ($comments_array as $comm) { - // Show the comments more recent first. - if (is_array($comm) === true) { - $comm = array_reverse($comm); - } - - $comments_format = (empty($comm) === true ? 'old' : 'new'); + $comments_format = (empty($comm) === true) ? 'old' : 'new'; switch ($comments_format) { case 'new': From a02c8a7988c28e0d9e557c81c26938ec13177b8f Mon Sep 17 00:00:00 2001 From: Daniel Barbero Martin Date: Wed, 1 Dec 2021 15:15:45 +0100 Subject: [PATCH 24/59] 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 25/59] 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 26/59] 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 27/59] 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 66c40876799db8654ffd46158c488b6c26803b86 Mon Sep 17 00:00:00 2001 From: Calvo Date: Thu, 2 Dec 2021 14:12:19 +0100 Subject: [PATCH 28/59] Added module interval control and percentage checkbox --- .../module_manager_editor_prediction.php | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/pandora_console/godmode/agentes/module_manager_editor_prediction.php b/pandora_console/godmode/agentes/module_manager_editor_prediction.php index f84ca2b096..2abe885541 100644 --- a/pandora_console/godmode/agentes/module_manager_editor_prediction.php +++ b/pandora_console/godmode/agentes/module_manager_editor_prediction.php @@ -14,6 +14,7 @@ enterprise_include_once('include/functions_policies.php'); enterprise_include_once('godmode/agentes/module_manager_editor_prediction.php'); require_once 'include/functions_agents.php'; +ui_require_jquery_file('validate'); $disabledBecauseInPolicy = false; $disabledTextBecauseInPolicy = ''; @@ -71,12 +72,15 @@ if ($row !== false && is_array($row)) { break; case MODULE_PREDICTION_TRENDING: - $selected = 'module_selected'; - case MODULE_PREDICTION_MODULE: $selected = 'trending_selected'; $prediction_module = $custom_integer_1; break; + case MODULE_PREDICTION_MODULE: + $selected = 'module_selected'; + $prediction_module = $custom_integer_1; + break; + default: $prediction_module = $custom_integer_1; @@ -201,6 +205,17 @@ if ($synthetic_module_form !== ENTERPRISE_NOT_HOOK) { push_table_simple($data, 'synthetic_module'); } +$trending_module_form = enterprise_hook('get_trending_module_form', [$custom_string_1]); +if ($trending_module_form !== ENTERPRISE_NOT_HOOK) { + $data = []; + $data[0] = ''; + $data[1] .= $trending_module_form; + + push_table_simple($data, 'trending_module'); +} + + + // Netflow modules are an Enterprise feature. $netflow_module_form = enterprise_hook('get_netflow_module_form', [$custom_integer_1]); if ($netflow_module_form !== ENTERPRISE_NOT_HOOK) { From d030b3b924f7715fa5db3b02bcc51196c731c44d Mon Sep 17 00:00:00 2001 From: Daniel Barbero Martin Date: Thu, 2 Dec 2021 14:16:01 +0100 Subject: [PATCH 29/59] 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 30/59] 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 31/59] 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 32/59] 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 33/59] 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 7139b9e1b18b57182291003d2b517de25a69a467 Mon Sep 17 00:00:00 2001 From: Calvo Date: Fri, 3 Dec 2021 10:38:25 +0100 Subject: [PATCH 34/59] Switch prediction module to prediction planning --- .../godmode/agentes/configurar_agente.php | 5 ++ .../module_manager_editor_prediction.php | 65 +++++++++++++++---- pandora_console/include/constants.php | 2 +- 3 files changed, 58 insertions(+), 14 deletions(-) diff --git a/pandora_console/godmode/agentes/configurar_agente.php b/pandora_console/godmode/agentes/configurar_agente.php index 6108730a5c..1d7bec840c 100644 --- a/pandora_console/godmode/agentes/configurar_agente.php +++ b/pandora_console/godmode/agentes/configurar_agente.php @@ -1605,6 +1605,11 @@ if ($update_module || $create_module) { ); } + if ($prediction_module === MODULE_PREDICTION_PLANNING) { + $custom_string_1 = get_parameter('estimation_interval', '300'); + $custom_string_2 = get_parameter('estimation_type', 'estimation_calculation'); + } + $active_snmp_v3 = get_parameter('active_snmp_v3'); /* diff --git a/pandora_console/godmode/agentes/module_manager_editor_prediction.php b/pandora_console/godmode/agentes/module_manager_editor_prediction.php index 2abe885541..acbc78be32 100644 --- a/pandora_console/godmode/agentes/module_manager_editor_prediction.php +++ b/pandora_console/godmode/agentes/module_manager_editor_prediction.php @@ -37,7 +37,7 @@ if ($row !== false && is_array($row)) { // Services are an Enterprise feature. $custom_integer_1 = $row['custom_integer_1']; - switch ($prediction_module) { + switch ((int) $prediction_module) { case MODULE_PREDICTION_SERVICE: $selected = 'service_selected'; $custom_integer_2 = 0; @@ -76,18 +76,19 @@ if ($row !== false && is_array($row)) { $prediction_module = $custom_integer_1; break; - case MODULE_PREDICTION_MODULE: - $selected = 'module_selected'; + case MODULE_PREDICTION_PLANNING: + $selected = 'capacity_planning'; $prediction_module = $custom_integer_1; + $estimation_interval = $custom_string_1; + $estimation_type = $custom_string_2; break; default: - $prediction_module = $custom_integer_1; break; } } else { - $selected = 'module_selected'; + $selected = 'capacity_planning'; $custom_integer_1 = 0; } @@ -157,14 +158,17 @@ if ($id_agente) { AND history_data = 1 AND id_agente = '.$id_agente_clean.' AND id_agente_modulo <> '.$id_agente_modulo; - $data[1] .= html_print_select_from_sql( - $sql, - 'prediction_module', - $prediction_module, - false, - __('Select Module'), - 0, - true + + $data[1] .= html_print_input( + [ + 'type' => 'select_from_sql', + 'sql' => $sql, + 'name' => 'prediction_module', + 'selected' => $prediction_module, + 'nothing' => __('Select Module'), + 'nothing_value' => 0, + 'return' => true, + ] ); } else { $data[1] .= ''; @@ -184,6 +188,41 @@ $data[1] .= ''; $table_simple->colspan['prediction_module'][1] = 3; push_table_simple($data, 'prediction_module'); +$data = []; +$data[0] = ''; + +$data[1] .= html_print_label(__('Future estimation'), 'estimation_interval', true).'
'; +$data[1] .= html_print_input( + [ + 'type' => 'interval', + 'return' => 'true', + 'name' => 'estimation_interval', + 'value' => $estimation_interval, + ], + 'div', + false +); + +$data[1] .= '
'; +$data[1] .= html_print_label(__('Calculation type'), 'estimation_type', true).'
'; +$data[1] .= html_print_input( + [ + 'type' => 'select', + 'return' => 'true', + 'name' => 'estimation_type', + 'class' => 'w250px', + 'fields' => [ + 'estimation_absolute' => __('Estimated absolute value'), + 'estimation_calculation' => __('Calculation of days to reach limit'), + ], + 'selected' => $estimation_type, + ], + 'div', + false +); + +push_table_simple($data, 'capacity_planning'); + // Services are an Enterprise feature. $selector_form = enterprise_hook('get_selector_form', [$custom_integer_1]); if ($selector_form !== ENTERPRISE_NOT_HOOK) { diff --git a/pandora_console/include/constants.php b/pandora_console/include/constants.php index 07d14e816d..0b05df89fb 100644 --- a/pandora_console/include/constants.php +++ b/pandora_console/include/constants.php @@ -368,7 +368,7 @@ define('MODULE_WUX', 8); define('MODULE_WIZARD', 9); // Type of Modules of Prediction. -define('MODULE_PREDICTION_MODULE', 1); +define('MODULE_PREDICTION_PLANNING', 1); define('MODULE_PREDICTION_SERVICE', 2); define('MODULE_PREDICTION_SYNTHETIC', 3); define('MODULE_PREDICTION_NETFLOW', 4); From f382a5bf153b41256207e404aec60647783bbe42 Mon Sep 17 00:00:00 2001 From: Calvo Date: Fri, 3 Dec 2021 11:02:11 +0100 Subject: [PATCH 35/59] Fix trending module bugs --- .../godmode/agentes/module_manager_editor_prediction.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pandora_console/godmode/agentes/module_manager_editor_prediction.php b/pandora_console/godmode/agentes/module_manager_editor_prediction.php index acbc78be32..6d81dbb3b5 100644 --- a/pandora_console/godmode/agentes/module_manager_editor_prediction.php +++ b/pandora_console/godmode/agentes/module_manager_editor_prediction.php @@ -126,16 +126,17 @@ $data[1] = '
'; $data[1] .= html_print_label(__('Agent'), 'agent_name', true).'
'; // Get module and agent of the target prediction module -if (!empty($prediction_module)) { +if (empty($prediction_module) === false) { $id_agente_clean = modules_get_agentmodule_agent($prediction_module); $prediction_module_agent = modules_get_agentmodule_agent_name($prediction_module); $agent_name_clean = $prediction_module_agent; + $agent_alias = agents_get_alias($id_agente_clean); } else { - $id_agente_clean = $id_agente; - $agent_name_clean = $agent_name; + $id_agente_clean = 0; + $agent_name_clean = ''; + $agent_alias = ''; } -$agent_alias = agents_get_alias($id_agente_clean); $params = []; $params['return'] = true; From 642af39395ff75b9772eda69cb176cb733a1b196 Mon Sep 17 00:00:00 2001 From: Ramon Novoa Date: Fri, 3 Dec 2021 11:47:58 +0100 Subject: [PATCH 36/59] Add support for trend modules. Ref. pandora_enterprise#7456. --- pandora_server/lib/PandoraFMS/PredictionServer.pm | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pandora_server/lib/PandoraFMS/PredictionServer.pm b/pandora_server/lib/PandoraFMS/PredictionServer.pm index f7c557128d..6800561317 100644 --- a/pandora_server/lib/PandoraFMS/PredictionServer.pm +++ b/pandora_server/lib/PandoraFMS/PredictionServer.pm @@ -224,6 +224,13 @@ sub exec_prediction_module ($$$$) { return; } + # Trend module. + if ($agent_module->{'prediction_module'} == 8) { + logger ($pa_config, "Executing trend module " . $agent_module->{'nombre'}, 10); + enterprise_hook ('exec_trend_module', [$pa_config, $agent_module, $server_id, $dbh]); + return; + } + # Get a full hash for target agent_module record reference ($target_module) my $target_module = get_db_single_row ($dbh, 'SELECT * FROM tagente_modulo WHERE id_agente_modulo = ?', $agent_module->{'custom_integer_1'}); return unless defined $target_module; From a94f6be37eb4a744654b6c6dde9dbb42c145ff57 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Fri, 3 Dec 2021 12:59:50 +0100 Subject: [PATCH 37/59] 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 38/59] 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 39/59] 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 40/59] 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 41/59] 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 42/59] 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 67c8a846b9664b9e31ab6674c1466ba7618c0761 Mon Sep 17 00:00:00 2001 From: artica Date: Wed, 8 Dec 2021 01:00:17 +0100 Subject: [PATCH 43/59] 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 c702a48c9a..38ad154d6f 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-211207 +Version: 7.0NG.758.1-211208 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 a63da23a2d..3c244c7677 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-211207" +pandora_version="7.0NG.758.1-211208" 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 93d9273cbd..07641c0333 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 => '211207'; +use constant AGENT_BUILD => '211208'; # 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 8ad4e37a1b..de893bbb6d 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 211207 +%define release 211208 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 e01fef3ae4..5f0b68607b 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 211207 +%define release 211208 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 9845156651..423374fd00 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="211207" +PI_BUILD="211208" OS_NAME=`uname -s` FORCE=0 diff --git a/pandora_agents/win32/installer/pandora.mpi b/pandora_agents/win32/installer/pandora.mpi index e601f56be2..12a9dde078 100644 --- a/pandora_agents/win32/installer/pandora.mpi +++ b/pandora_agents/win32/installer/pandora.mpi @@ -186,7 +186,7 @@ UpgradeApplicationID {} Version -{211207} +{211208} ViewReadme {Yes} diff --git a/pandora_agents/win32/pandora.cc b/pandora_agents/win32/pandora.cc index 51c9616f07..3b1bbd0cd1 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 211207") +#define PANDORA_VERSION ("7.0NG.758.1 Build 211208") string pandora_path; string pandora_dir; diff --git a/pandora_agents/win32/versioninfo.rc b/pandora_agents/win32/versioninfo.rc index 2a472c876f..f41a0b7640 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 211207))" + VALUE "ProductVersion", "(7.0NG.758.1(Build 211208))" VALUE "FileVersion", "1.0.0.0" END END diff --git a/pandora_console/DEBIAN/control b/pandora_console/DEBIAN/control index f80f9658dd..0c428f90d2 100644 --- a/pandora_console/DEBIAN/control +++ b/pandora_console/DEBIAN/control @@ -1,5 +1,5 @@ package: pandorafms-console -Version: 7.0NG.758.1-211207 +Version: 7.0NG.758.1-211208 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 554868af7e..a5a1d82729 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-211207" +pandora_version="7.0NG.758.1-211208" package_pear=0 package_pandora=1 diff --git a/pandora_console/include/config_process.php b/pandora_console/include/config_process.php index 8d481c2f15..615710fd9b 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 = 'PC211207'; +$build_version = 'PC211208'; $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 aa9d082d38..748c21c366 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 0f24a658d6..72f55b986d 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 211207 +%define release 211208 Summary: Pandora FMS Server Name: %{name} diff --git a/pandora_server/pandora_server.spec b/pandora_server/pandora_server.spec index e5edbb43d0..caa51796e7 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 211207 +%define release 211208 Summary: Pandora FMS Server Name: %{name} diff --git a/pandora_server/pandora_server_installer b/pandora_server/pandora_server_installer index 7fc10138d6..d1d55e9fae 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="211207" +PI_BUILD="211208" MODE=$1 if [ $# -gt 1 ]; then diff --git a/pandora_server/util/pandora_db.pl b/pandora_server/util/pandora_db.pl index 324410f0c0..cd47ab1b39 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 211207"; +my $version = "7.0NG.758.1 Build 211208"; # Pandora server configuration my %conf; diff --git a/pandora_server/util/pandora_manage.pl b/pandora_server/util/pandora_manage.pl index e957384fa4..ad395c7d94 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 211207"; +my $version = "7.0NG.758.1 Build 211208"; # save program name for logging my $progname = basename($0); From e7b1bfd368fe2dfefbe9d354ae6f5ea9d72d9e5d Mon Sep 17 00:00:00 2001 From: artica Date: Thu, 9 Dec 2021 01:00:16 +0100 Subject: [PATCH 44/59] 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 38ad154d6f..b85bad5f8b 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-211208 +Version: 7.0NG.758.1-211209 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 3c244c7677..78c2f450bf 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-211208" +pandora_version="7.0NG.758.1-211209" 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 07641c0333..8785e3288a 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 => '211208'; +use constant AGENT_BUILD => '211209'; # 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 de893bbb6d..b719f93ca2 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 211208 +%define release 211209 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 5f0b68607b..aee4484e05 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 211208 +%define release 211209 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 423374fd00..acc2227413 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="211208" +PI_BUILD="211209" OS_NAME=`uname -s` FORCE=0 diff --git a/pandora_agents/win32/installer/pandora.mpi b/pandora_agents/win32/installer/pandora.mpi index 12a9dde078..7cfdde9d37 100644 --- a/pandora_agents/win32/installer/pandora.mpi +++ b/pandora_agents/win32/installer/pandora.mpi @@ -186,7 +186,7 @@ UpgradeApplicationID {} Version -{211208} +{211209} ViewReadme {Yes} diff --git a/pandora_agents/win32/pandora.cc b/pandora_agents/win32/pandora.cc index 3b1bbd0cd1..9c169ee9b8 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 211208") +#define PANDORA_VERSION ("7.0NG.758.1 Build 211209") string pandora_path; string pandora_dir; diff --git a/pandora_agents/win32/versioninfo.rc b/pandora_agents/win32/versioninfo.rc index f41a0b7640..77def11f3d 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 211208))" + VALUE "ProductVersion", "(7.0NG.758.1(Build 211209))" VALUE "FileVersion", "1.0.0.0" END END diff --git a/pandora_console/DEBIAN/control b/pandora_console/DEBIAN/control index 0c428f90d2..f728ce6013 100644 --- a/pandora_console/DEBIAN/control +++ b/pandora_console/DEBIAN/control @@ -1,5 +1,5 @@ package: pandorafms-console -Version: 7.0NG.758.1-211208 +Version: 7.0NG.758.1-211209 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 a5a1d82729..e166255f37 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-211208" +pandora_version="7.0NG.758.1-211209" package_pear=0 package_pandora=1 diff --git a/pandora_console/include/config_process.php b/pandora_console/include/config_process.php index 615710fd9b..cc993ea8db 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 = 'PC211208'; +$build_version = 'PC211209'; $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 748c21c366..fa22b799d2 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 72f55b986d..b2c23967b4 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 211208 +%define release 211209 Summary: Pandora FMS Server Name: %{name} diff --git a/pandora_server/pandora_server.spec b/pandora_server/pandora_server.spec index caa51796e7..c620bf046b 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 211208 +%define release 211209 Summary: Pandora FMS Server Name: %{name} diff --git a/pandora_server/pandora_server_installer b/pandora_server/pandora_server_installer index d1d55e9fae..a5113530fd 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="211208" +PI_BUILD="211209" MODE=$1 if [ $# -gt 1 ]; then diff --git a/pandora_server/util/pandora_db.pl b/pandora_server/util/pandora_db.pl index cd47ab1b39..82d95ba626 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 211208"; +my $version = "7.0NG.758.1 Build 211209"; # Pandora server configuration my %conf; diff --git a/pandora_server/util/pandora_manage.pl b/pandora_server/util/pandora_manage.pl index ad395c7d94..99eec58391 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 211208"; +my $version = "7.0NG.758.1 Build 211209"; # save program name for logging my $progname = basename($0); From 2cbfca2cdd374aff406edb74df994db95f2267b8 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Thu, 9 Dec 2021 13:51:20 +0100 Subject: [PATCH 45/59] mr rev + timap_sites --- pandora_console/extras/mr/51.sql | 43 +++++++++++-------- .../pandoradb_migrate_6.0_to_7.0.mysql.sql | 9 ++++ pandora_console/pandoradb.sql | 12 ++++++ 3 files changed, 45 insertions(+), 19 deletions(-) diff --git a/pandora_console/extras/mr/51.sql b/pandora_console/extras/mr/51.sql index 3398bed0c3..479305227d 100644 --- a/pandora_console/extras/mr/51.sql +++ b/pandora_console/extras/mr/51.sql @@ -12,31 +12,39 @@ ALTER TABLE `tpolicy_modules` ADD COLUMN `percentage_critical` tinyint(1) UNSIGN ALTER TABLE tagente_modulo MODIFY debug_content TEXT; CREATE TABLE IF NOT EXISTS `talert_calendar` ( - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(100) NOT NULL default '', - `id_group` INT(10) NOT NULL DEFAULT 0, - `description` text, - PRIMARY KEY (`id`), - UNIQUE (`name`) + `id_group` INT(10) NOT NULL DEFAULT 0, + `description` text, + PRIMARY KEY (`id`), + UNIQUE (`name`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -INSERT IGNORE INTO `talert_calendar` VALUES (1, 'Default', 0, 'Default calendar'); - CREATE TABLE IF NOT EXISTS `tipam_network_location` ( - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `name` varchar(100) NOT NULL default '', - PRIMARY KEY (`id`), - UNIQUE (`name`) + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `name` varchar(100) NOT NULL default '', + PRIMARY KEY (`id`), + UNIQUE (`name`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE IF NOT EXISTS `tipam_sites` ( + `id` serial, + `name` varchar(100) UNIQUE NOT NULL default '', + `description` text, + `parent` bigint unsigned null, + PRIMARY KEY (`id`), + FOREIGN KEY (`parent`) REFERENCES `tipam_sites`.`id` ON UPDATE CASCADE ON DELETE SET NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -INSERT IGNORE INTO `tipam_network_location` (`name`) SELECT `location` FROM `tipam_network` WHERE `location` <> ''; -UPDATE `tipam_network` INNER JOIN `tipam_network_location` ON tipam_network_location.name=tipam_network.location SET tipam_network.location=tipam_network_location.id; ALTER TABLE `tipam_network` MODIFY `location` int(10) unsigned NULL; ALTER TABLE `tipam_network` ADD FOREIGN KEY (`location`) REFERENCES `tipam_network_location`(`id`) ON DELETE CASCADE; - +ALTER TABLE `tagent_repository` ADD COLUMN `deployment_timeout` INT UNSIGNED DEFAULT 600 AFTER `path`; ALTER TABLE `talert_special_days` ADD COLUMN `id_calendar` int(10) unsigned NOT NULL DEFAULT 1; ALTER TABLE `talert_special_days` ADD COLUMN `day_code` tinyint(2) unsigned NOT NULL DEFAULT 0; +ALTER TABLE `talert_special_days` DROP COLUMN `same_day`; +ALTER TABLE `talert_special_days` ADD FOREIGN KEY (`id_calendar`) REFERENCES `talert_calendar`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; +INSERT IGNORE INTO `talert_calendar` VALUES (1, 'Default', 0, 'Default calendar'); UPDATE `talert_special_days` set `day_code` = 1 WHERE `same_day` = 'monday'; UPDATE `talert_special_days` set `day_code` = 2 WHERE `same_day` = 'tuesday'; UPDATE `talert_special_days` set `day_code` = 3 WHERE `same_day` = 'wednesday'; @@ -45,11 +53,8 @@ UPDATE `talert_special_days` set `day_code` = 5 WHERE `same_day` = 'friday'; UPDATE `talert_special_days` set `day_code` = 6 WHERE `same_day` = 'saturday'; UPDATE `talert_special_days` set `day_code` = 7 WHERE `same_day` = 'sunday'; -ALTER TABLE `talert_special_days` DROP COLUMN `same_day`; -ALTER TABLE `talert_special_days` ADD FOREIGN KEY (`id_calendar`) REFERENCES `talert_calendar`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; - -ALTER TABLE `tagent_repository` ADD COLUMN `deployment_timeout` INT UNSIGNED DEFAULT 600 AFTER `path`; - +INSERT IGNORE INTO `tipam_network_location` (`name`) SELECT `location` FROM `tipam_network` WHERE `location` <> ''; +UPDATE `tipam_network` INNER JOIN `tipam_network_location` ON tipam_network_location.name=tipam_network.location SET tipam_network.location=tipam_network_location.id; UPDATE `tconfig` c1 JOIN (select count(*) as n FROM `tconfig` c2 WHERE (c2.`token` = "node_metaconsole" AND c2.`value` = 1) OR (c2.`token` = "centralized_management" AND c2.`value` = 1) ) v SET c1. `value` = 0 WHERE c1.token = "autocreate_remote_users" AND v.n = 2; COMMIT; 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..a385b8def0 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 @@ -4052,6 +4052,15 @@ CREATE TABLE IF NOT EXISTS `tipam_network_location` ( UNIQUE (`name`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; +CREATE TABLE IF NOT EXISTS `tipam_sites` ( + `id` serial, + `name` varchar(100) UNIQUE NOT NULL default '', + `description` text, + `parent` bigint unsigned null, + PRIMARY KEY (`id`), + FOREIGN KEY (`parent`) REFERENCES `tipam_sites`(`id`) ON UPDATE CASCADE ON DELETE SET NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + INSERT IGNORE INTO `tipam_network_location` (`name`) SELECT `location` FROM `tipam_network` WHERE `location` <> ''; UPDATE `tipam_network` INNER JOIN `tipam_network_location` ON tipam_network_location.name=tipam_network.location SET tipam_network.location=tipam_network_location.id; ALTER TABLE `tipam_network` MODIFY `location` int(10) unsigned NULL; diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql index f8b675c9d6..48c7c4a6d2 100644 --- a/pandora_console/pandoradb.sql +++ b/pandora_console/pandoradb.sql @@ -3959,6 +3959,18 @@ CREATE TABLE IF NOT EXISTS `tipam_network_location` ( UNIQUE (`name`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; +-- ---------------------------------------------------------------------- +-- Table `tipam_sites` +-- ---------------------------------------------------------------------- +CREATE TABLE IF NOT EXISTS `tipam_sites` ( + `id` serial, + `name` varchar(100) UNIQUE NOT NULL default '', + `description` text, + `parent` bigint unsigned null, + PRIMARY KEY (`id`), + FOREIGN KEY (`parent`) REFERENCES `tipam_sites`(`id`) ON UPDATE CASCADE ON DELETE SET NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + -- ---------------------------------------------------------------------- -- Table `tipam_network` -- ---------------------------------------------------------------------- From cb6184a9434d380ca03ded812333cadef49dbefb Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Thu, 9 Dec 2021 14:02:06 +0100 Subject: [PATCH 46/59] mr fix --- pandora_console/extras/mr/51.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandora_console/extras/mr/51.sql b/pandora_console/extras/mr/51.sql index 479305227d..6e256b2cd8 100644 --- a/pandora_console/extras/mr/51.sql +++ b/pandora_console/extras/mr/51.sql @@ -33,7 +33,7 @@ CREATE TABLE IF NOT EXISTS `tipam_sites` ( `description` text, `parent` bigint unsigned null, PRIMARY KEY (`id`), - FOREIGN KEY (`parent`) REFERENCES `tipam_sites`.`id` ON UPDATE CASCADE ON DELETE SET NULL + FOREIGN KEY (`parent`) REFERENCES `tipam_sites`(`id`) ON UPDATE CASCADE ON DELETE SET NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8; ALTER TABLE `tipam_network` MODIFY `location` int(10) unsigned NULL; From e37cdc4459cca06b45dbe6101f4aa5c74a5f96c1 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Thu, 9 Dec 2021 14:57:37 +0100 Subject: [PATCH 47/59] Improvements in Entity class --- pandora_console/include/lib/Entity.php | 97 +++++++++++++++++++++++++- 1 file changed, 96 insertions(+), 1 deletion(-) diff --git a/pandora_console/include/lib/Entity.php b/pandora_console/include/lib/Entity.php index 59306db0ca..4e7bc14153 100644 --- a/pandora_console/include/lib/Entity.php +++ b/pandora_console/include/lib/Entity.php @@ -43,6 +43,13 @@ abstract class Entity */ protected $existsInDB; + /** + * Fields to identify register. + * + * @var array + */ + protected $primaryKeys; + /** * Entity fields (from table). * @@ -126,6 +133,8 @@ abstract class Entity if (is_array($filters) === true) { // New one. + $this->primaryKeys = array_keys($filters); + $data = \db_get_row_filter( $this->table, $filters, @@ -292,8 +301,94 @@ abstract class Entity * Saves current object definition to database. * * @return boolean Success or not. + * @throws \Exception On error. */ - public abstract function save(); + public function save() + { + $updates = $this->fields; + // Clean null fields. + foreach ($updates as $k => $v) { + if ($v === null) { + unset($updates[$k]); + } + } + + if ($this->existsInDB === true) { + // Update. + $where = []; + + foreach ($this->primaryKeys as $key) { + $where[$key] = $this->fields[$key]; + } + + if (empty($where) === true) { + throw new \Exception( + __METHOD__.' error: Cannot identify object' + ); + } + + $rs = \db_process_sql_update( + $this->table, + $updates, + $where + ); + + if ($rs === false) { + global $config; + throw new \Exception( + __METHOD__.' error: '.$config['dbconnection']->error + ); + } + } else { + // New register. + $rs = \db_process_sql_insert( + $this->table, + $updates + ); + + if ($rs === false) { + global $config; + + throw new \Exception( + __METHOD__.' error: '.$config['dbconnection']->error + ); + } + + $this->existsInDB = true; + } + + return true; + + } + + + /** + * Remove this entity. + * + * @return void + * @throws \Exception If no primary keys are defined. + */ + public function delete() + { + if ($this->existsInDB === true) { + $where = []; + + foreach ($this->primaryKeys as $key) { + $where[$key] = $this->fields[$key]; + } + + if (empty($where) === true) { + throw new \Exception( + __METHOD__.' error: Cannot identify object on deletion' + ); + } + + \db_process_sql_delete( + $this->table, + $where + ); + } + } } From 5c25fa840651348a4fd1fa7dadbd8948f4263776 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Thu, 9 Dec 2021 15:07:35 +0100 Subject: [PATCH 48/59] mr updates and a pretty icon --- pandora_console/extras/mr/51.sql | 5 +++++ .../pandoradb_migrate_6.0_to_7.0.mysql.sql | 14 ++++++++------ pandora_console/images/building.png | Bin 0 -> 5990 bytes pandora_console/pandoradb.sql | 8 ++++++-- 4 files changed, 19 insertions(+), 8 deletions(-) create mode 100644 pandora_console/images/building.png diff --git a/pandora_console/extras/mr/51.sql b/pandora_console/extras/mr/51.sql index 6e256b2cd8..e92d9b853c 100644 --- a/pandora_console/extras/mr/51.sql +++ b/pandora_console/extras/mr/51.sql @@ -44,6 +44,11 @@ ALTER TABLE `talert_special_days` ADD COLUMN `day_code` tinyint(2) unsigned NOT ALTER TABLE `talert_special_days` DROP COLUMN `same_day`; ALTER TABLE `talert_special_days` ADD FOREIGN KEY (`id_calendar`) REFERENCES `talert_calendar`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; +ALTER TABLE `tipam_network` ADD COLUMN `id_site` bigint unsigned; +ALTER TABLE `tipam_network` ADD CONSTRAINT FOREIGN KEY (`id_site`) REFERENCES `tipam_sites`(`id`) ON DELETE SET NULL ON UPDATE CASCADE; +ALTER TABLE `tipam_supernet` ADD COLUMN `id_site` bigint unsigned; +ALTER TABLE `tipam_supernet` ADD CONSTRAINT FOREIGN KEY (`id_site`) REFERENCES `tipam_sites`(`id`) ON DELETE SET NULL ON UPDATE CASCADE; + INSERT IGNORE INTO `talert_calendar` VALUES (1, 'Default', 0, 'Default calendar'); UPDATE `talert_special_days` set `day_code` = 1 WHERE `same_day` = 'monday'; UPDATE `talert_special_days` set `day_code` = 2 WHERE `same_day` = 'tuesday'; 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 a385b8def0..f8c14f5f7f 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 @@ -3970,15 +3970,18 @@ CREATE TABLE IF NOT EXISTS `tipam_network` ( `network` varchar(100) NOT NULL default '', `name_network` varchar(255) default '', `description` text NOT NULL, - `location` tinytext NOT NULL, + `location` int(10) unsigned NULL, `id_recon_task` int(10) unsigned NOT NULL, `scan_interval` tinyint(2) default 1, `monitoring` tinyint(2) default 0, `id_group` mediumint(8) unsigned NULL default 0, `lightweight_mode` tinyint(2) default 0, `users_operator` text, + `id_site` bigint unsigned, PRIMARY KEY (`id`), - FOREIGN KEY (`id_recon_task`) REFERENCES trecon_task(`id_rt`) ON DELETE CASCADE + FOREIGN KEY (`id_recon_task`) REFERENCES trecon_task(`id_rt`) ON DELETE CASCADE, + FOREIGN KEY (`location`) REFERENCES `tipam_network_location`(`id`) ON DELETE CASCADE, + FOREIGN KEY (`id_site`) REFERENCES `tipam_sites`(`id`) ON DELETE SET NULL ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE IF NOT EXISTS `tipam_ip` ( @@ -4033,7 +4036,9 @@ CREATE TABLE IF NOT EXISTS `tipam_supernet` ( `address` varchar(250) NOT NULL, `mask` varchar(250) NOT NULL, `subneting_mask` varchar(250) default '', - PRIMARY KEY (`id`) + `id_site` bigint unsigned, + PRIMARY KEY (`id`), + FOREIGN KEY (`id_site`) REFERENCES `tipam_sites`(`id`) ON DELETE SET NULL ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE IF NOT EXISTS `tipam_supernet_network` ( @@ -4062,9 +4067,6 @@ CREATE TABLE IF NOT EXISTS `tipam_sites` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8; INSERT IGNORE INTO `tipam_network_location` (`name`) SELECT `location` FROM `tipam_network` WHERE `location` <> ''; -UPDATE `tipam_network` INNER JOIN `tipam_network_location` ON tipam_network_location.name=tipam_network.location SET tipam_network.location=tipam_network_location.id; -ALTER TABLE `tipam_network` MODIFY `location` int(10) unsigned NULL; -ALTER TABLE `tipam_network` ADD FOREIGN KEY (`location`) REFERENCES `tipam_network_location`(`id`) ON DELETE CASCADE; SET @insert_type = 3; SET @insert_name = 'IPAM Recon'; diff --git a/pandora_console/images/building.png b/pandora_console/images/building.png new file mode 100644 index 0000000000000000000000000000000000000000..9083a60215593e7e3b53027e2affb971ed27d85f GIT binary patch literal 5990 zcmeHKdpJ~E8=r1&;~r8}W9UN0Tro4o{Wen#LT;h<%jCoUunklDs2Y9nRw=bejM$T#+Fpsiz?_G4j*rnq`M{fGeq39^EDoVRZ+Prp> zdF(zqOE}h{mNwmAO=CR?$C$_)PJD>B((RcE*ka<(KixUlzjFN2vawZR4h>5_Gz)f5 zxLhTT%&=PZ0y?6X#JzlxyiSL5XFuG6%uf3qey8!{Hn}~y!^3|WXHe-q!i&SIzrDDg z*Kx}*plRinDf=74ckc7FhnS5)_;d%=E?^?kJqatM~L6uk4V;?HbU!4 zAM7rmvvsz{hBTx5p7g*m`nkJ#@*~{PU@-he-cg6bs8=4Lcy=Kw5~CaO4DDf7$zfyp!o36f;`V z`$%5x>VeFpG)i0fE&AbZWqdmU9Q0>zKAeN&be7YcYjjTe_Ne;VQrrs$RePo#+AP|% z&HqdZ^drL8bYT{3I~u>>F+;tvpdP3Nm&98RDA$~lN}b2mam(1vOBr^UjYCBj;gJJT zPAV793k?;c>fZZi8YYa=25cTjCf%tb^ekaqT9V^wnKTLPu;^+(IrY?@eXyowgyEG_ zS^n75BK3NyM%rq=-|LX!*Jak$8woyDzBe%jCk;_XX{gpLW|l=jPc~zC73Wr#mWl2K z_tjHXZUZ5`js%VU(wob#Qn-`_eB51_gZb)zZSt-iEYAAf^PX-Uo!^qF%8J^Wv|wdl z;B=+?3DQ1?UX|gdVXDfcdP&J8NAZRzb$)EeD@XTyQ-x;h@P%(^>Q+V*rb>%j_q+Eh zq-GdYV3U2)VsAO_hle%-9_-g8D9Q)OF+!tsqE~2gGdEM?cmf#L}CsAKR%V~nZI^n;L$Cb zePQLN3J}}!<~`~{1lj0j$Z2@+RSKix9IeQ9y`8V^%GB&x{;6xi$~&ie@}4c-^;cV- z^0~)5jvA*AZf~pMd({SO%yY53em94dkd$Usm{GyA^zN!{0e6{?$Qdt=v6^Teu`R*u zLFa6VKk{DdB z#GJ}n_U2XV)0-v(!nZf?xtw25slIQ$f2VTg$}?-Ne{);;NIdx7hIY$EJ0j^&+9CNr z2G<7bug|yNDcaKsX`ik-rco$`w4X}f(T=6HB5moja%kq?K{wJd2$B+IRyr#aa zc!;)`;lRoDcXclE?Wr?U;YqB$SYUUTH%L57VcM5pE74;o)ms;-F>Sd(w z+;-OX`LMIYgKKu1Q^JZXQ40+!vKJm2F=*0F@X7KbZ`W0}2T#T*0*<#0e%FJymo?Bj z$U`ABscs(>i&D?#GvCygXYHaDpI*A7un%9~eOFF0K5p`;D0o=A<>K|UMKvtk<7R`_r;}J#S}_0CjSh*X;1XkW{~Zit2h=)26$tBJqF( zvTeA$zTyb{Ycu<3HrSJEGL8m*ZMV@A^&f=6<|T3*9X)7{j$gh$&^IS{N2V3E*+VO7 zwlqb}L^V=fODHxVB)<4v;DI}_r&v#1+#N*V^u>h@=7(su?K^+F9mBjsBP9V#MPvc zXzQ;;?YM8)IC)98jsP4SBUazL`xQ4rit2ezY*5FBXTXbrTPvseQ{`8(>xeaIj zj5q-pRVA;Ysvj#z(QK>IC<=kL#X61&pM?a4v~n+3ixH@6;NfX^@P4G0)ec=kZfta3}v8Tr6b zSb}>Jx2;mESo2Nv!}iUAd&P{9eFRX_T6badjv%=R+U z<&_*oQITubJu$RPSjK^N1Ag?4WTt>;2CxJS&`in`Lc0YRjAAPl0?aT_f?$9l9KJR3 z)uqcw1czmf^fjkr=t4&@ltYaXfnG6g-prUVCW(c#wNau-$q)b!lmG}RkINU6rPjzf zTr%`5>qa9Hb0U&3Yos6D1K}tTfe3;b!3=|PmU1F-NE;;tMZ{v0J)K-WLqKoV$WVzy zNJgWhqN2>A@MZ#02pUTwkjYLA@h%f%}gmn5>c)s{E3lJY@DIi2+%`j*l5B;r%SmGQBfqZu8A2r0@(54FQ z35o>~A|~h@3GyX|-$JmMU-g9%BJNx`EG8P{f;>o63|Yl~XVR5M_xP$IqacLC6V7Qt zWPc|q;jsTE>pS0MBXi+=>j5vPR16lUV{Lhee)y zB$6;B5Jx1U2t*PVMZlSZC=!STP#_D>uwY`$aU?AB8z>rIECKjTPzD8on{glj_pC>8_-Vp$B9IUb8* zku1$2Z!k<0q)&tzCSZxhfdqg^n1f<5$u0sB4}j9i;Q=8aTF4KX8;}uBw)db}BXMS! zzk58mfP@VxSR*%b_z}{-2fR5v&`Scy*u+}kNf>jyIgx;|G$&eqGBk(h1B%2@CCV_d z7&9DkPF2w<)siiPYb0s)CY5C7a0EO?b8(Ca^{8*h`F*Q1I$lG#6Tp-nll9HeHvnh0{jpVn%|!b>PtW8ACkqe zV6ZKj7EBbDjj@E1MPQ-;3=xMix5QeKFgObftR?t8x>&%LL;)huJ_L#siUum6xo8k; z=cqLPUOFlil<|bYVNqBd3PbY7;>matnLt>F!ICi;B>Ho}XxXg(5-|n+Uz||p1io1Y zAiYn0(DDMUR_L$G)o0FRH2xodpL6klv;aZ>H1b3I{-ocx@o$?YI-C6#rvZC@D(_4ilQ_y+$GR?`}n|SkF4?TH5pd~-{V5X55n|PIRZKxiu z)Z*a(?3iiR?W|Mm7B^$?Sk>>h`>M|rYNZD~=32dlYkhtH z_94&7pHA(Lnbm)glb`p( z|8k`?T2Wd(W7Y27)UV9;Jn`FD#2M4DCA54%-+gS}`PU@wEz-T9X;TAUaaK;tSkx1_ ziN~gu%!t190inF%tX{PuovTo0@@{tH-HXW#{ksWc4(A=ty*8Y#2XNV}|;02%f-ahRqmwP)7FrB*(Vu^#xpJQ9t8`@nv-#f-&?;L*+ j9ZpKwT-%_+puSgeVln}1?DjY)yD*xwn^UF3w)p=5R=;O3 literal 0 HcmV?d00001 diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql index 48c7c4a6d2..5a91e0b8bc 100644 --- a/pandora_console/pandoradb.sql +++ b/pandora_console/pandoradb.sql @@ -3986,9 +3986,11 @@ CREATE TABLE IF NOT EXISTS `tipam_network` ( `id_group` mediumint(8) unsigned NULL default 0, `lightweight_mode` tinyint(2) default 0, `users_operator` text, + `id_site` bigint unsigned, PRIMARY KEY (`id`), FOREIGN KEY (`id_recon_task`) REFERENCES trecon_task(`id_rt`) ON DELETE CASCADE, - FOREIGN KEY (`location`) REFERENCES `tipam_network_location`(`id`) ON DELETE CASCADE + FOREIGN KEY (`location`) REFERENCES `tipam_network_location`(`id`) ON DELETE CASCADE, + FOREIGN KEY (`id_site`) REFERENCES `tipam_sites`(`id`) ON DELETE SET NULL ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- ---------------------------------------------------------------------- @@ -4055,7 +4057,9 @@ CREATE TABLE IF NOT EXISTS `tipam_supernet` ( `address` varchar(250) NOT NULL, `mask` varchar(250) NOT NULL, `subneting_mask` varchar(250) default '', - PRIMARY KEY (`id`) + `id_site` bigint unsigned, + PRIMARY KEY (`id`), + FOREIGN KEY (`id_site`) REFERENCES `tipam_sites`(`id`) ON DELETE SET NULL ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- ---------------------------------------------------------------------- From b97ecda12bdf844e7263a69491d4bd555228c8d0 Mon Sep 17 00:00:00 2001 From: Daniel Barbero Martin Date: Thu, 9 Dec 2021 16:19:05 +0100 Subject: [PATCH 49/59] db changes --- pandora_console/extras/mr/51.sql | 2 ++ pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql | 4 +++- pandora_console/pandoradb.sql | 4 +++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/pandora_console/extras/mr/51.sql b/pandora_console/extras/mr/51.sql index e92d9b853c..6052b5f95a 100644 --- a/pandora_console/extras/mr/51.sql +++ b/pandora_console/extras/mr/51.sql @@ -48,6 +48,8 @@ ALTER TABLE `tipam_network` ADD COLUMN `id_site` bigint unsigned; ALTER TABLE `tipam_network` ADD CONSTRAINT FOREIGN KEY (`id_site`) REFERENCES `tipam_sites`(`id`) ON DELETE SET NULL ON UPDATE CASCADE; ALTER TABLE `tipam_supernet` ADD COLUMN `id_site` bigint unsigned; ALTER TABLE `tipam_supernet` ADD CONSTRAINT FOREIGN KEY (`id_site`) REFERENCES `tipam_sites`(`id`) ON DELETE SET NULL ON UPDATE CASCADE; +ALTER TABLE `tipam_network` ADD COLUMN `vrf` int(10) unsigned; +ALTER TABLE `tipam_network` ADD CONSTRAINT FOREIGN KEY (`vrf`) REFERENCES `tagente`(`id_agente`) ON DELETE SET NULL ON UPDATE CASCADE; INSERT IGNORE INTO `talert_calendar` VALUES (1, 'Default', 0, 'Default calendar'); UPDATE `talert_special_days` set `day_code` = 1 WHERE `same_day` = 'monday'; 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 f8c14f5f7f..0a33a9f1ff 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 @@ -3978,10 +3978,12 @@ CREATE TABLE IF NOT EXISTS `tipam_network` ( `lightweight_mode` tinyint(2) default 0, `users_operator` text, `id_site` bigint unsigned, + `vrf` int(10) unsigned, PRIMARY KEY (`id`), FOREIGN KEY (`id_recon_task`) REFERENCES trecon_task(`id_rt`) ON DELETE CASCADE, FOREIGN KEY (`location`) REFERENCES `tipam_network_location`(`id`) ON DELETE CASCADE, - FOREIGN KEY (`id_site`) REFERENCES `tipam_sites`(`id`) ON DELETE SET NULL ON UPDATE CASCADE + FOREIGN KEY (`id_site`) REFERENCES `tipam_sites`(`id`) ON DELETE SET NULL ON UPDATE CASCADE, + FOREIGN KEY (`vrf`) REFERENCES `tagente`(`id_agente`) ON DELETE SET NULL ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE IF NOT EXISTS `tipam_ip` ( diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql index 5a91e0b8bc..258f9409f1 100644 --- a/pandora_console/pandoradb.sql +++ b/pandora_console/pandoradb.sql @@ -3987,10 +3987,12 @@ CREATE TABLE IF NOT EXISTS `tipam_network` ( `lightweight_mode` tinyint(2) default 0, `users_operator` text, `id_site` bigint unsigned, + `vrf` int(10) unsigned, PRIMARY KEY (`id`), FOREIGN KEY (`id_recon_task`) REFERENCES trecon_task(`id_rt`) ON DELETE CASCADE, FOREIGN KEY (`location`) REFERENCES `tipam_network_location`(`id`) ON DELETE CASCADE, - FOREIGN KEY (`id_site`) REFERENCES `tipam_sites`(`id`) ON DELETE SET NULL ON UPDATE CASCADE + FOREIGN KEY (`id_site`) REFERENCES `tipam_sites`(`id`) ON DELETE SET NULL ON UPDATE CASCADE, + FOREIGN KEY (`vrf`) REFERENCES `tagente`(`id_agente`) ON DELETE SET NULL ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- ---------------------------------------------------------------------- From 3dd92397f904654d2a35a8149310e75374abd3f7 Mon Sep 17 00:00:00 2001 From: artica Date: Fri, 10 Dec 2021 01:00:20 +0100 Subject: [PATCH 50/59] 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); From f8883151f346fe481fb9d2d6ad3875f0b3e999d8 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Fri, 10 Dec 2021 13:43:05 +0100 Subject: [PATCH 51/59] allow datatable to export all columns but latest one --- pandora_console/include/functions_ui.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pandora_console/include/functions_ui.php b/pandora_console/include/functions_ui.php index 8e9fe01210..c143324c6a 100755 --- a/pandora_console/include/functions_ui.php +++ b/pandora_console/include/functions_ui.php @@ -3459,6 +3459,11 @@ function ui_print_datatable(array $parameters) } } + $export_columns = ''; + if ($parameters['csv_exclude_latest'] === true) { + $export_columns = ',columns: \'th:not(:last-child)\''; + } + $js .= ' if (dt_'.$table_id.'.page.info().pages > 1) { $("#'.$table_id.'_wrapper > .dataTables_paginate.paging_simple_numbers").show() @@ -3489,8 +3494,7 @@ function ui_print_datatable(array $parameters) order : "current", page : "All", search : "applied" - }, - columns: [1,'.$columns.'] + }'.$export_columns.' } } ], From f6c0f50a90ad36bb8883be72d1acb10aca26802e Mon Sep 17 00:00:00 2001 From: Calvo Date: Fri, 10 Dec 2021 18:00:33 +0100 Subject: [PATCH 52/59] Added missin param and Fixed error message and default interval --- .../godmode/agentes/configurar_agente.php | 6 +++++- .../module_manager_editor_prediction.php | 18 +++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/pandora_console/godmode/agentes/configurar_agente.php b/pandora_console/godmode/agentes/configurar_agente.php index 1d7bec840c..5845cffc32 100644 --- a/pandora_console/godmode/agentes/configurar_agente.php +++ b/pandora_console/godmode/agentes/configurar_agente.php @@ -1606,8 +1606,12 @@ if ($update_module || $create_module) { } if ($prediction_module === MODULE_PREDICTION_PLANNING) { - $custom_string_1 = get_parameter('estimation_interval', '300'); $custom_string_2 = get_parameter('estimation_type', 'estimation_calculation'); + if ($custom_string_2 === 'estimation_calculation') { + $custom_string_1 = get_parameter('estimation_days', -1); + } else { + $custom_string_1 = get_parameter('estimation_interval', '300'); + } } $active_snmp_v3 = get_parameter('active_snmp_v3'); diff --git a/pandora_console/godmode/agentes/module_manager_editor_prediction.php b/pandora_console/godmode/agentes/module_manager_editor_prediction.php index 6d81dbb3b5..c033298045 100644 --- a/pandora_console/godmode/agentes/module_manager_editor_prediction.php +++ b/pandora_console/godmode/agentes/module_manager_editor_prediction.php @@ -192,6 +192,7 @@ push_table_simple($data, 'prediction_module'); $data = []; $data[0] = ''; +$data[1] .= '
'; $data[1] .= html_print_label(__('Future estimation'), 'estimation_interval', true).'
'; $data[1] .= html_print_input( [ @@ -203,8 +204,23 @@ $data[1] .= html_print_input( 'div', false ); +$data[1] .= '
'; + + +$data[1] .= '
'; +$data[1] .= html_print_label(__('Limit value'), 'estimation_days', true).'
'; +$data[1] .= html_print_input( + [ + 'type' => 'number', + 'return' => 'true', + 'id' => 'estimation_days', + 'name' => 'estimation_days', + 'value' => $estimation_interval, + ] +); +$data[1] .= '
'; + -$data[1] .= '
'; $data[1] .= html_print_label(__('Calculation type'), 'estimation_type', true).'
'; $data[1] .= html_print_input( [ From 8ba6a05d1fedfcbd95b496446758f72a269c408c Mon Sep 17 00:00:00 2001 From: artica Date: Sat, 11 Dec 2021 01:00:19 +0100 Subject: [PATCH 53/59] 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 57b1b77d69..99bbba3d41 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-211210 +Version: 7.0NG.758.1-211211 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 a7c88922c7..45f308da24 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-211210" +pandora_version="7.0NG.758.1-211211" 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 e01e061a44..436b6ef815 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 => '211210'; +use constant AGENT_BUILD => '211211'; # 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 c92fcf61b4..eb79943cc2 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 211210 +%define release 211211 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 16f4b6fee4..c7ab66bc8c 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 211210 +%define release 211211 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 adca572c73..a138d6afde 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="211210" +PI_BUILD="211211" OS_NAME=`uname -s` FORCE=0 diff --git a/pandora_agents/win32/installer/pandora.mpi b/pandora_agents/win32/installer/pandora.mpi index ffc71aaccb..461717d79e 100644 --- a/pandora_agents/win32/installer/pandora.mpi +++ b/pandora_agents/win32/installer/pandora.mpi @@ -186,7 +186,7 @@ UpgradeApplicationID {} Version -{211210} +{211211} ViewReadme {Yes} diff --git a/pandora_agents/win32/pandora.cc b/pandora_agents/win32/pandora.cc index 7b6560677e..ba2b606504 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 211210") +#define PANDORA_VERSION ("7.0NG.758.1 Build 211211") string pandora_path; string pandora_dir; diff --git a/pandora_agents/win32/versioninfo.rc b/pandora_agents/win32/versioninfo.rc index 43106ff959..045415725e 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 211210))" + VALUE "ProductVersion", "(7.0NG.758.1(Build 211211))" VALUE "FileVersion", "1.0.0.0" END END diff --git a/pandora_console/DEBIAN/control b/pandora_console/DEBIAN/control index 98a48ae7c0..97a8c36563 100644 --- a/pandora_console/DEBIAN/control +++ b/pandora_console/DEBIAN/control @@ -1,5 +1,5 @@ package: pandorafms-console -Version: 7.0NG.758.1-211210 +Version: 7.0NG.758.1-211211 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 d0fcd0a5b6..e99e72a6e4 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-211210" +pandora_version="7.0NG.758.1-211211" package_pear=0 package_pandora=1 diff --git a/pandora_console/include/config_process.php b/pandora_console/include/config_process.php index fb12849375..5797f3c8be 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 = 'PC211210'; +$build_version = 'PC211211'; $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 9409f2e16a..66d1ffba6d 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 fa361febce..8dd739462c 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 211210 +%define release 211211 Summary: Pandora FMS Server Name: %{name} diff --git a/pandora_server/pandora_server.spec b/pandora_server/pandora_server.spec index bee4d6e6af..5428616644 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 211210 +%define release 211211 Summary: Pandora FMS Server Name: %{name} diff --git a/pandora_server/pandora_server_installer b/pandora_server/pandora_server_installer index d4c119cc3c..362db72342 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="211210" +PI_BUILD="211211" MODE=$1 if [ $# -gt 1 ]; then diff --git a/pandora_server/util/pandora_db.pl b/pandora_server/util/pandora_db.pl index 0c25f4e03d..0253a9668a 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 211210"; +my $version = "7.0NG.758.1 Build 211211"; # Pandora server configuration my %conf; diff --git a/pandora_server/util/pandora_manage.pl b/pandora_server/util/pandora_manage.pl index b1a59eac21..bae0e80fdd 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 211210"; +my $version = "7.0NG.758.1 Build 211211"; # save program name for logging my $progname = basename($0); From 19b8730c07f40489be9cce16e41363615f901371 Mon Sep 17 00:00:00 2001 From: artica Date: Sun, 12 Dec 2021 01:00:17 +0100 Subject: [PATCH 54/59] 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 99bbba3d41..caf24dac89 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-211211 +Version: 7.0NG.758.1-211212 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 45f308da24..5ec987e7f6 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-211211" +pandora_version="7.0NG.758.1-211212" 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 436b6ef815..15cfc6be2e 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 => '211211'; +use constant AGENT_BUILD => '211212'; # 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 eb79943cc2..a4d20b73f7 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 211211 +%define release 211212 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 c7ab66bc8c..aac8b6efb1 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 211211 +%define release 211212 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 a138d6afde..2b1d30cc91 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="211211" +PI_BUILD="211212" OS_NAME=`uname -s` FORCE=0 diff --git a/pandora_agents/win32/installer/pandora.mpi b/pandora_agents/win32/installer/pandora.mpi index 461717d79e..5eb52c9500 100644 --- a/pandora_agents/win32/installer/pandora.mpi +++ b/pandora_agents/win32/installer/pandora.mpi @@ -186,7 +186,7 @@ UpgradeApplicationID {} Version -{211211} +{211212} ViewReadme {Yes} diff --git a/pandora_agents/win32/pandora.cc b/pandora_agents/win32/pandora.cc index ba2b606504..17f3e8e7dc 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 211211") +#define PANDORA_VERSION ("7.0NG.758.1 Build 211212") string pandora_path; string pandora_dir; diff --git a/pandora_agents/win32/versioninfo.rc b/pandora_agents/win32/versioninfo.rc index 045415725e..7b827e886c 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 211211))" + VALUE "ProductVersion", "(7.0NG.758.1(Build 211212))" VALUE "FileVersion", "1.0.0.0" END END diff --git a/pandora_console/DEBIAN/control b/pandora_console/DEBIAN/control index 97a8c36563..aa8f551d4b 100644 --- a/pandora_console/DEBIAN/control +++ b/pandora_console/DEBIAN/control @@ -1,5 +1,5 @@ package: pandorafms-console -Version: 7.0NG.758.1-211211 +Version: 7.0NG.758.1-211212 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 e99e72a6e4..849f59177c 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-211211" +pandora_version="7.0NG.758.1-211212" package_pear=0 package_pandora=1 diff --git a/pandora_console/include/config_process.php b/pandora_console/include/config_process.php index 5797f3c8be..184b293db9 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 = 'PC211211'; +$build_version = 'PC211212'; $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 66d1ffba6d..4f6d0ce961 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 8dd739462c..c0852fdc75 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 211211 +%define release 211212 Summary: Pandora FMS Server Name: %{name} diff --git a/pandora_server/pandora_server.spec b/pandora_server/pandora_server.spec index 5428616644..71d4465642 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 211211 +%define release 211212 Summary: Pandora FMS Server Name: %{name} diff --git a/pandora_server/pandora_server_installer b/pandora_server/pandora_server_installer index 362db72342..6bac764dc1 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="211211" +PI_BUILD="211212" MODE=$1 if [ $# -gt 1 ]; then diff --git a/pandora_server/util/pandora_db.pl b/pandora_server/util/pandora_db.pl index 0253a9668a..91ce9206f9 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 211211"; +my $version = "7.0NG.758.1 Build 211212"; # Pandora server configuration my %conf; diff --git a/pandora_server/util/pandora_manage.pl b/pandora_server/util/pandora_manage.pl index bae0e80fdd..c19a42476b 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 211211"; +my $version = "7.0NG.758.1 Build 211212"; # save program name for logging my $progname = basename($0); From 88fe0b69cc8188ba14fd7ee4aacea361b5a10a28 Mon Sep 17 00:00:00 2001 From: artica Date: Mon, 13 Dec 2021 01:00:16 +0100 Subject: [PATCH 55/59] 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 caf24dac89..98f1d0fdfb 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-211212 +Version: 7.0NG.758.1-211213 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 5ec987e7f6..a5c86d3679 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-211212" +pandora_version="7.0NG.758.1-211213" 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 15cfc6be2e..723a47a2a1 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 => '211212'; +use constant AGENT_BUILD => '211213'; # 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 a4d20b73f7..a70049e287 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 211212 +%define release 211213 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 aac8b6efb1..8c0f409256 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 211212 +%define release 211213 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 2b1d30cc91..d86e948ae3 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="211212" +PI_BUILD="211213" OS_NAME=`uname -s` FORCE=0 diff --git a/pandora_agents/win32/installer/pandora.mpi b/pandora_agents/win32/installer/pandora.mpi index 5eb52c9500..693218a7eb 100644 --- a/pandora_agents/win32/installer/pandora.mpi +++ b/pandora_agents/win32/installer/pandora.mpi @@ -186,7 +186,7 @@ UpgradeApplicationID {} Version -{211212} +{211213} ViewReadme {Yes} diff --git a/pandora_agents/win32/pandora.cc b/pandora_agents/win32/pandora.cc index 17f3e8e7dc..4ec63d7668 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 211212") +#define PANDORA_VERSION ("7.0NG.758.1 Build 211213") string pandora_path; string pandora_dir; diff --git a/pandora_agents/win32/versioninfo.rc b/pandora_agents/win32/versioninfo.rc index 7b827e886c..f4660c96d2 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 211212))" + VALUE "ProductVersion", "(7.0NG.758.1(Build 211213))" VALUE "FileVersion", "1.0.0.0" END END diff --git a/pandora_console/DEBIAN/control b/pandora_console/DEBIAN/control index aa8f551d4b..5602ae3ae7 100644 --- a/pandora_console/DEBIAN/control +++ b/pandora_console/DEBIAN/control @@ -1,5 +1,5 @@ package: pandorafms-console -Version: 7.0NG.758.1-211212 +Version: 7.0NG.758.1-211213 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 849f59177c..b1eee3d6c3 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-211212" +pandora_version="7.0NG.758.1-211213" package_pear=0 package_pandora=1 diff --git a/pandora_console/include/config_process.php b/pandora_console/include/config_process.php index 184b293db9..cd14469c85 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 = 'PC211212'; +$build_version = 'PC211213'; $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 4f6d0ce961..25b1ad32be 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 c0852fdc75..80af886a90 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 211212 +%define release 211213 Summary: Pandora FMS Server Name: %{name} diff --git a/pandora_server/pandora_server.spec b/pandora_server/pandora_server.spec index 71d4465642..a689069e9e 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 211212 +%define release 211213 Summary: Pandora FMS Server Name: %{name} diff --git a/pandora_server/pandora_server_installer b/pandora_server/pandora_server_installer index 6bac764dc1..80af02e267 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="211212" +PI_BUILD="211213" MODE=$1 if [ $# -gt 1 ]; then diff --git a/pandora_server/util/pandora_db.pl b/pandora_server/util/pandora_db.pl index 91ce9206f9..ee0b76247c 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 211212"; +my $version = "7.0NG.758.1 Build 211213"; # Pandora server configuration my %conf; diff --git a/pandora_server/util/pandora_manage.pl b/pandora_server/util/pandora_manage.pl index c19a42476b..f31453d6af 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 211212"; +my $version = "7.0NG.758.1 Build 211213"; # save program name for logging my $progname = basename($0); From 6c94cc5e15bfca4869b917a0bff078ef3851cd6c Mon Sep 17 00:00:00 2001 From: Calvo Date: Mon, 13 Dec 2021 12:00:24 +0100 Subject: [PATCH 56/59] Fix visual bug --- .../module_manager_editor_prediction.php | 35 +++++++++---------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/pandora_console/godmode/agentes/module_manager_editor_prediction.php b/pandora_console/godmode/agentes/module_manager_editor_prediction.php index c033298045..cf35c8b0bf 100644 --- a/pandora_console/godmode/agentes/module_manager_editor_prediction.php +++ b/pandora_console/godmode/agentes/module_manager_editor_prediction.php @@ -192,6 +192,23 @@ push_table_simple($data, 'prediction_module'); $data = []; $data[0] = ''; +$data[1] .= html_print_label(__('Calculation type'), 'estimation_type', true).'
'; +$data[1] .= html_print_input( + [ + 'type' => 'select', + 'return' => 'true', + 'name' => 'estimation_type', + 'class' => 'w250px', + 'fields' => [ + 'estimation_absolute' => __('Estimated absolute value'), + 'estimation_calculation' => __('Calculation of days to reach limit'), + ], + 'selected' => $estimation_type, + ], + 'div', + false +); + $data[1] .= '
'; $data[1] .= html_print_label(__('Future estimation'), 'estimation_interval', true).'
'; $data[1] .= html_print_input( @@ -220,24 +237,6 @@ $data[1] .= html_print_input( ); $data[1] .= '
'; - -$data[1] .= html_print_label(__('Calculation type'), 'estimation_type', true).'
'; -$data[1] .= html_print_input( - [ - 'type' => 'select', - 'return' => 'true', - 'name' => 'estimation_type', - 'class' => 'w250px', - 'fields' => [ - 'estimation_absolute' => __('Estimated absolute value'), - 'estimation_calculation' => __('Calculation of days to reach limit'), - ], - 'selected' => $estimation_type, - ], - 'div', - false -); - push_table_simple($data, 'capacity_planning'); // Services are an Enterprise feature. From b8565d59dcb9963244d0cbe54b15e84151f025f9 Mon Sep 17 00:00:00 2001 From: Ramon Novoa Date: Mon, 13 Dec 2021 12:28:58 +0100 Subject: [PATCH 57/59] Add support for capacity planning modules. Capacity planning modules replace traditional prediction modules. Ref. pandora_enterprise#3220. --- .../lib/PandoraFMS/PredictionServer.pm | 234 +++--- .../lib/PandoraFMS/Statistics/Regression.pm | 776 ++++++++++++++++++ 2 files changed, 891 insertions(+), 119 deletions(-) create mode 100644 pandora_server/lib/PandoraFMS/Statistics/Regression.pm diff --git a/pandora_server/lib/PandoraFMS/PredictionServer.pm b/pandora_server/lib/PandoraFMS/PredictionServer.pm index 6800561317..45d9a8fb2f 100644 --- a/pandora_server/lib/PandoraFMS/PredictionServer.pm +++ b/pandora_server/lib/PandoraFMS/PredictionServer.pm @@ -26,7 +26,7 @@ use Thread::Semaphore; use IO::Socket::INET; use Net::Ping; -use POSIX qw(strftime); +use POSIX qw(floor strftime); # Default lib dir for RPM and DEB packages use lib '/usr/lib/perl5'; @@ -35,6 +35,7 @@ use PandoraFMS::Tools; use PandoraFMS::DB; use PandoraFMS::Core; use PandoraFMS::ProducerConsumerServer; +use PandoraFMS::Statistics::Regression; #For debug #use Data::Dumper; @@ -231,134 +232,129 @@ sub exec_prediction_module ($$$$) { return; } - # Get a full hash for target agent_module record reference ($target_module) - my $target_module = get_db_single_row ($dbh, 'SELECT * FROM tagente_modulo WHERE id_agente_modulo = ?', $agent_module->{'custom_integer_1'}); - return unless defined $target_module; - - # Prediction mode explanation - # - # 0 is for target type of generic_proc. It compares latest data with current data. Needs to get - # data on a "middle" interval, so if interval is 300, get data to compare with 150 before - # and 150 in the future. If current data is ABOVE or BELOW average +- typical_deviation - # this is a BAD value (0), if not is ok (1) and written in target module as is. - # more interval configured for this module, more "margin" has to compare data. - # - # 1 is for target type of generic_data. It get's data in the future, using the interval given in - # module. It gets average from current timestamp to INTERVAL in the future and gets average - # value. Typical deviation is not used here. - - # 0 proc, 1 data - my $prediction_mode = ($agent_module->{'id_tipo_modulo'} == 2) ? 0 : 1; - - # Initialize another global sub variables. - my $module_data = 0; # 0 data for default - - # Get current timestamp - my $utimestamp = time (); - my $timestamp = strftime ("%Y-%m-%d %H:%M:%S", localtime($utimestamp)); - - # Get different data from each week one month ago (4 values) - # $agent_module->{'module_interval'} uses a margin of interval to get average data from the past - my @week_data; - my @week_utimestamp; - - for (my $i=0; $i<4; $i++) { - $week_utimestamp[$i] = $utimestamp - (84600*7*($i+1)); - # Adjust for proc prediction - if ($prediction_mode == 0) { - $week_utimestamp[$i] = $week_utimestamp[$i] - ($agent_module->{'module_interval'} / 2); - } + # Capacity planning module. + exec_capacity_planning_module($pa_config, $agent_module, $server_id, $dbh); +} + +######################################################################## +# Execute a capacity planning module. +######################################################################## +sub exec_capacity_planning_module($$$$) { + my ($pa_config, $module, $server_id, $dbh) = @_; + my $pred; + + # Retrieve the target module. + my $target_module = get_db_single_row($dbh, 'SELECT * FROM tagente_modulo WHERE id_agente_modulo = ?', $module->{'custom_integer_1'}); + if (!defined($target_module)) { + pandora_update_module_on_error ($pa_config, $module, $dbh); + return; } - - # Let's calculate statistical average using past data - # n = total of real data values - my ($n, $average, $temp1) = (0, 0, 0); - for (my $i=0; $i < 4; $i++) { - my ($first_data, $last_data, $average_interval); - my $sum_data = 0; - - $temp1 = $week_utimestamp[$i] + $agent_module->{'module_interval'}; - # Get data for week $i in the past - - $average_interval = get_db_value ($dbh, 'SELECT AVG(datos) - FROM tagente_datos - WHERE id_agente_modulo = ? - AND utimestamp > ? - AND utimestamp < ?', $target_module->{'id_agente_modulo'}, $week_utimestamp[$i], $temp1); - - # Need to get data outside interval because no data. - if (!(defined($average_interval)) || ($average_interval == 0)) { - $last_data = get_db_value ($dbh, 'SELECT datos - FROM tagente_datos - WHERE id_agente_modulo = ? - AND utimestamp > ? - LIMIT 1', $target_module->{'id_agente_modulo'}, $week_utimestamp[$i]); - next unless defined ($last_data); - $first_data = get_db_value ($dbh, 'SELECT datos - FROM tagente_datos - WHERE id_agente_modulo = ? - AND utimestamp < ? - LIMIT 1', $target_module->{'id_agente_modulo'}, $temp1); - next unless defined ($first_data); - $sum_data++ if ($last_data != 0); - $sum_data++ if ($first_data != 0); - $week_data[$i] = ($sum_data > 0) ? (($last_data + $first_data) / $sum_data) : 0; - } - else { - $week_data[$i] = $average_interval; - } - - # It's possible that one of the week_data[i] values was not valid (NULL) - # so recheck it and relay on n=0 for "no data" values set to 0 in result - # Calculate total ammount of valida data for each data sample - if ((is_numeric($week_data[$i])) && ($week_data[$i] > 0)) { - $n++; - # Average SUM - $average = $average + $week_data[$i]; - } + + # Set the period. + my $period; + + # Weekly. + if ($module->{'custom_integer_2'} == 0) { + $period = 604800; } - - # Real average value - $average = ($n > 0) ? ($average / $n) : 0; - - # (PROC) Compare with current data - if ($prediction_mode == 0) { - # Calculate typical deviation - my $typical_deviation = 0; - for (my $i=0; $i< $n; $i++) { - if ((is_numeric($week_data[$i])) && ($week_data[$i] > 0)) { - $typical_deviation = $typical_deviation + (($week_data[$i] - $average)**2); + # Monthly. + elsif ($module->{'custom_integer_2'} == 1) { + $period = 2678400; + } + # Daily. + else { + $period = 86400; + } + + # Set other parameters. + my $now = time(); + my $from = $now - $period; + my $type = $module->{'custom_string_2'}; + my $target_value = $module->{'custom_string_1'}; + + # Fit a line of the form: y = theta_0 + x * theta_1 + my ($theta_0, $theta_1); + eval { + ($theta_0, $theta_1) = linear_regression($target_module, $from, $now, $dbh); + }; + if (!defined($theta_0) || !defined($theta_1)) { + pandora_update_module_on_error ($pa_config, $module, $dbh); + return; + } + + # Predict the value. + if ($type eq 'estimation_absolute') { + # y = theta_0 + x * theta_1 + $pred = $theta_0 + ($now + $target_value) * $theta_1; + } + # Predict the date. + else { + # Infinity. + if ($theta_1 == 0) { + $pred = -1; + } else { + # x = (y - theta_0) / theta_1 + $pred = ($target_value - $theta_0) / $theta_1; + + # Convert the prediction from a unix timestamp to days from now. + $pred = ($pred - $now) / 86400; + + # We are not interested in past dates. + if ($pred < 0) { + $pred = -1; } } - $typical_deviation = ($n > 1) ? sqrt ($typical_deviation / ($n-1)) : 0; - - my $current_value = get_db_value ($dbh, 'SELECT datos - FROM tagente_estado - WHERE id_agente_modulo = ?', $target_module->{'id_agente_modulo'}); - if ( ($current_value > ($average - $typical_deviation)) && ($current_value < ($average + $typical_deviation)) ){ - $module_data = 1; # OK !! - } - else { - $module_data = 0; # Out of predictions - } - } - else { - # Prediction based on data - $module_data = $average; } - my %data = ("data" => $module_data); - pandora_process_module ($pa_config, \%data, '', $agent_module, '', $timestamp, $utimestamp, $server_id, $dbh); - - my $agent_os_version = get_db_value ($dbh, 'SELECT os_version - FROM tagente - WHERE id_agente = ?', $agent_module->{'id_agente'}); + # Update the module. + my %data = ("data" => $pred); + my $utimestamp = time (); + my $timestamp = strftime ("%Y-%m-%d %H:%M:%S", localtime($utimestamp)); + pandora_process_module ($pa_config, \%data, '', $module, '', $timestamp, $utimestamp, $server_id, $dbh); + # Update the agent. + my $agent_os_version = get_db_value ($dbh, 'SELECT os_version FROM tagente WHERE id_agente = ?', $module->{'id_agente'}); if ($agent_os_version eq ''){ $agent_os_version = $pa_config->{'servername'}.'_Prediction'; } - - pandora_update_agent ($pa_config, $timestamp, $agent_module->{'id_agente'}, undef, undef, -1, $dbh); + pandora_update_agent ($pa_config, $timestamp, $module->{'id_agente'}, undef, undef, -1, $dbh); +} + +######################################################################## +# Perform linear regression on the given module. +######################################################################## +sub linear_regression($$$$) { + my ($module, $from, $to, $dbh) = @_; + + # Should not happen. + return if ($module->{'module_interval'} < 1); + + # Retrieve the data. + my @rows = get_db_rows($dbh, 'SELECT datos, utimestamp FROM tagente_datos WHERE id_agente_modulo = ? AND utimestamp > ? AND utimestamp < ? ORDER BY utimestamp ASC', $module->{'id_agente_modulo'}, $from, $to); + return if scalar(@rows) <= 0; + + # Perform linear regression on the data. + my $reg = PandoraFMS::Statistics::Regression->new( "linear regression", ["const", "x"] ); + my $prev_utimestamp = $from; + foreach my $row (@rows) { + my ($utimestamp, $data) = ($row->{'utimestamp'}, $row->{'datos'}); + + # Elapsed time. + my $elapsed = $utimestamp - $prev_utimestamp; + $elapsed = 1 unless $elapsed > 0; + $prev_utimestamp = $utimestamp; + + # Number of points (Pandora compresses data!) + my $local_count = floor($elapsed / $module->{'module_interval'}); + $local_count = 1 if $local_count <= 0; + + # Add the points. + for (my $i = 0; $i < $local_count; $i++) { + $reg->include($data, [1.0, $utimestamp]); + } + } + + return $reg->theta(); } 1; diff --git a/pandora_server/lib/PandoraFMS/Statistics/Regression.pm b/pandora_server/lib/PandoraFMS/Statistics/Regression.pm new file mode 100644 index 0000000000..832df4d648 --- /dev/null +++ b/pandora_server/lib/PandoraFMS/Statistics/Regression.pm @@ -0,0 +1,776 @@ +################################################################ +# Statistics::Regression package included in Pandora FMS. +# See: https://metacpan.org/pod/Statistics::Regression +################################################################ +package PandoraFMS::Statistics::Regression; + +$VERSION = '0.53'; +my $DATE = "2007/07/07"; +my $MNAME= "$0::Statistics::Regression"; + +use strict; +use warnings FATAL => qw{ uninitialized }; + +use Carp; + +################################################################ +=pod + +=head1 NAME + + Regression.pm - weighted linear regression package (line+plane fitting) + + +=head1 SYNOPSIS + + use Statistics::Regression; + + # Create regression object + my $reg = Statistics::Regression->new( "sample regression", [ "const", "someX", "someY" ] ); + + # Add data points + $reg->include( 2.0, [ 1.0, 3.0, -1.0 ] ); + $reg->include( 1.0, [ 1.0, 5.0, 2.0 ] ); + $reg->include( 20.0, [ 1.0, 31.0, 0.0 ] ); + $reg->include( 15.0, [ 1.0, 11.0, 2.0 ] ); + +or + + my %d; + $d{const} = 1.0; $d{someX}= 5.0; $d{someY}= 2.0; $d{ignored}="anything else"; + $reg->include( 3.0, \%d ); # names are picked off the Regression specification + +Please note that *you* must provide the constant if you want one. + + # Finally, print the result + $reg->print(); + +This prints the following: + + **************************************************************** + Regression 'sample regression' + **************************************************************** + Name Theta StdErr T-stat + [0='const'] 0.2950 6.0512 0.05 + [1='someX'] 0.6723 0.3278 2.05 + [2='someY'] 1.0688 2.7954 0.38 + + R^2= 0.808, N= 4 + **************************************************************** + + + +The hash input method has the advantage that you can now just +fill the observation hashes with all your variables, and use the +same code to run regression, changing the regression +specification at one and only one spot (the new() invokation). +You do not need to change the inputs in the include() statement. +For example, + + my @obs; ## a global variable. observations are like: %oneobs= %{$obs[1]}; + + sub run_regression { + my $reg = Statistics::Regression->new( $_[0], $_[2] ); + foreach my $obshashptr (@obs) { $reg->include( $_[1], $_[3] ); } + $reg->print(); + } + + run_regression("bivariate regression", $obshashptr->{someY}, [ "const", "someX" ] ); + run_regression("trivariate regression", $obshashptr->{someY}, [ "const", "someX", "someZ" ] ); + + + +Of course, you can use the subroutines to do the printing work yourself: + + my @theta = $reg->theta(); + my @se = $reg->standarderrors(); + my $rsq = $reg->rsq(); + my $adjrsq = $reg->adjrsq(); + my $ybar = $reg->ybar(); ## the average of the y vector + my $sst = $reg->sst(); ## the sum-squares-total + my $sigmasq= $reg->sigmasq(); ## the variance of the residual + my $k = $reg->k(); ## the number of variables + my $n = $reg->n(); ## the number of observations + +In addition, there are some other helper routines, and a +subroutine linearcombination_variance(). If you don't know what +this is, don't use it. + + +=head1 BACKGROUND WARNING + +You should have an understanding of OLS regressions if you want +to use this package. You can get this from an introductory +college econometrics class and/or from most intermediate college +statistics classes. If you do not have this background +knowledge, then this package will remain a mystery to you. +There is no support for this package--please don't expect any. + + +=head1 DESCRIPTION + +Regression.pm is a multivariate linear regression package. That +is, it estimates the c coefficients for a line-fit of the type + + y= c(0)*x(0) + c(1)*x1 + c(2)*x2 + ... + c(k)*xk + +given a data set of N observations, each with k independent x +variables and one y variable. Naturally, N must be greater than +k---and preferably considerably greater. Any reasonable +undergraduate statistics book will explain what a regression is. +Most of the time, the user will provide a constant ('1') as x(0) +for each observation in order to allow the regression package to +fit an intercept. + + +=head1 ALGORITHM + +=head2 Original Algorithm (ALGOL-60): + + W. M. Gentleman, University of Waterloo, "Basic + Description For Large, Sparse Or Weighted Linear Least + Squares Problems (Algorithm AS 75)," Applied Statistics + (1974) Vol 23; No. 3 + +Gentleman's algorithm is I statistical standard. Insertion +of a new observation can be done one observation at any time +(WITH A WEIGHT!), and still only takes a low quadratic time. +The storage space requirement is of quadratic order (in the +indep variables). A practically infinite number of observations +can easily be processed! + +=head2 Internal Data Structures + +R=Rbar is an upperright triangular matrix, kept in normalized +form with implicit 1's on the diagonal. D is a diagonal scaling +matrix. These correspond to "standard Regression usage" as + + X' X = R' D R + +A backsubsitution routine (in thetacov) allows to invert the R +matrix (the inverse is upper-right triangular, too!). Call this +matrix H, that is H=R^(-1). + + (X' X)^(-1) = [(R' D^(1/2)') (D^(1/2) R)]^(-1) + = [ R^-1 D^(-1/2) ] [ R^-1 D^(-1/2) ]' + + +=head1 BUGS/PROBLEMS + +None known. + +=over 4 + +=item Perl Problem + +Unfortunately, perl is unaware of IEEE number representations. +This makes it a pain to test whether an observation contains any +missing variables (coded as 'NaN' in Regression.pm). + +=back + +=for comment +pod2html -noindex -title "perl weighted least squares regression package" Regression.pm > Regression.html + + +=head1 VERSION and RECENT CHANGES + +2007/04/04: Added Coefficient Standard Errors + +2007/07/01: Added self-test use (if invoked as perl Regression.pm) + at the end. cleaned up some print sprintf. + changed syntax on new() to eliminate passing K. + +2007/07/07: allowed passing hash with names to include(). + + +=head1 AUTHOR + +Naturally, Gentleman invented this algorithm. It was adaptated +by Ivo Welch. Alan Miller (alan\@dmsmelb.mel.dms.CSIRO.AU) +pointed out nicer ways to compute the R^2. Ivan Tubert-Brohman +helped wrap the module as as a standard CPAN distribution. + +=head1 LICENSE + +This module is released for free public use under a GPL license. + +(C) Ivo Welch, 2001,2004, 2007. + +=cut + + +################################################################ +#### let's start with handling of missing data ("nan" or "NaN") +################################################################ +use constant TINY => 1e-8; +my $nan= "NaN"; + +sub isNaN { + if ($_[0] !~ /[0-9nan]/) { confess "$MNAME:isNaN: definitely not a number in NaN: '$_[0]'"; } + return ($_[0]=~ /NaN/i) || ($_[0] != $_[0]); +} + + +################################################################ +### my $reg = Statistics::Regression->new($regname, \@var_names) +### +### Receives the number of variables on each observations (i.e., +### an integer) and returns the blessed data structure as a +### Statistics::Regression object. Also takes an optional name +### for this regression to remember, as well as a reference to a +### k*1 array of names for the X coefficients. +### +### I have now made it mandatory to give some names. +### +################################################################ +sub new { + my $classname= shift; (!ref($classname)) or confess "$MNAME:new: bad class call to new ($classname).\n"; + my $regname= shift || "no-name"; + my $xnameptr= shift; + + (defined($regname)) or confess "$MNAME:new: bad name in for regression. no undef allowed.\n"; + (!ref($regname)) or confess "$MNAME:new: bad name in for regression.\n"; + (defined($xnameptr)) or confess "$MNAME:new: You must provide variable names, because this tells me the number of columns. no undef allowed.\n"; + (ref($xnameptr) eq "ARRAY") or confess "$MNAME:new: bad xnames for regression. Must be pointer.\n"; + + my $K= (@{$xnameptr}); + + if (!defined($K)) { confess "$MNAME:new: cannot determine the number of variables"; } + if ($K<=1) { confess "$MNAME:new: Cannot run a regression without at least two variables."; } + + sub zerovec { + my @rv; + for (my $i=0; $i<=$_[0]; ++$i) { $rv[$i]=0; } + return \@rv; + } + + bless { + k => $K, + regname => $regname, + xnames => $xnameptr, + + # constantly updated + n => 0, + sse => 0, + syy => 0, + sy => 0, + wghtn => 0, + d => zerovec($K), + thetabar => zerovec($K), + rbarsize => ($K+1)*$K/2+1, + rbar => zerovec(($K+1)*$K/2+1), + + # other constants + neverabort => 0, + + # computed on demand + theta => undef, + sigmasq => undef, + rsq => undef, + adjrsq => undef + }, $classname; +} + + +################################################################ +### $reg->include( $y, [ $x1, $x2, $x3 ... $xk ], $weight ); +### +### Add one new observation. The weight is optional. Note that +### inclusion with a weight of -1 can be used to delete an +### observation. +### +### The error checking and transfer of arguments is clutzy, but +### works. if I had POSIX assured, I could do better number +### checking. right now, I don't do any. +### +### Returns the number of observations so far included. +################################################################ +sub include { + my $this = shift; + my $yelement= shift; + my $xin= shift; + my $weight= shift || 1.0; + + # modest input checking; + (ref($this)) or confess "$MNAME:include: bad class call to include.\n"; + (defined($yelement)) or confess "$MNAME:include: bad call for y to include. no undef allowed.\n"; + (!ref($yelement)) or confess "$MNAME:include: bad call for y to include. need scalar.\n"; + (defined($xin)) or confess "$MNAME:include: bad call for x to include. no undef allowed.\n"; + (ref($xin)) or confess "$MNAME:include: bad call for x to include. need reference.\n"; + (!ref($weight)) or confess "$MNAME:include: bad call for weight to include. need scalar.\n"; + + + # omit observations with missing observations; + (defined($yelement)) or confess "$MNAME:include: you must give a y value (predictor)."; + (isNaN($yelement)) and return $this->{n}; # ignore this observation; + ## should check for number, not string + + + # check and transfer the X vector + my @xrow; + if (ref($xin) eq "ARRAY") { @xrow= @{$xin}; } + else { + my $xctr=0; + foreach my $nm (@{$this->{xnames}}) { + (defined($xin->{$nm})) or confess "$MNAME:include: Variable '$nm' needs to be set in hash.\n"; + $xrow[$xctr]= $xin->{$nm}; + ++$xctr; + } + } + + my @xcopy; + for (my $i=1; $i<=$this->{k}; ++$i) { + (defined($xrow[$i-1])) + or confess "$MNAME:include: Internal Error: at N=".($this->{n}).", the x[".($i-1)."] is undef. use NaN for missing."; + (isNaN($xrow[$i-1])) and return $this->{n}; + $xcopy[$i]= $xrow[$i-1]; + ## should check for number, not string + } + + ################ now comes the real routine + + $this->{syy}+= ($weight*($yelement*$yelement)); + $this->{sy}+= ($weight*($yelement)); + if ($weight>=0.0) { ++$this->{n}; } else { --$this->{n}; } + + $this->{wghtn}+= $weight; + + for (my $i=1; $i<=$this->{k};++$i) { + if ($weight==0.0) { return $this->{n}; } + if (abs($xcopy[$i])>(TINY)) { + my $xi=$xcopy[$i]; + + my $di=$this->{d}->[$i]; + my $dprimei=$di+$weight*($xi*$xi); + my $cbar= $di/$dprimei; + my $sbar= $weight*$xi/$dprimei; + $weight*=($cbar); + $this->{d}->[$i]=$dprimei; + my $nextr=int( (($i-1)*( (2.0*$this->{k}-$i))/2.0+1) ); + if (!($nextr<=$this->{rbarsize}) ) { confess "$MNAME:include: Internal Error 2"; } + my $xk; + for (my $kc=$i+1;$kc<=$this->{k};++$kc) { + $xk=$xcopy[$kc]; $xcopy[$kc]=$xk-$xi*$this->{rbar}->[$nextr]; + $this->{rbar}->[$nextr]= $cbar * $this->{rbar}->[$nextr]+$sbar*$xk; + ++$nextr; + } + $xk=$yelement; $yelement-= $xi*$this->{thetabar}->[$i]; + $this->{thetabar}->[$i]= $cbar*$this->{thetabar}->[$i]+$sbar*$xk; + } + } + $this->{sse}+=$weight*($yelement*$yelement); + + # indicate that Theta is garbage now + $this->{theta}= undef; + $this->{sigmasq}= undef; $this->{rsq}= undef; $this->{adjrsq}= undef; + + return $this->{n}; +} + + +################################################################ +### +### $reg->rsq(), $reg->adjrsq(), $reg->sigmasq(), $reg->ybar(), +### $reg->sst(), $reg->k(), $reg->n() +### +### These methods provide common auxiliary information. rsq, +### adjrsq, sigmasq, sst, and ybar have not been checked but are +### likely correct. The results are stored for later usage, +### although this is somewhat unnecessary because the +### computation is so simple anyway. +################################################################ + +sub rsq { + my $this= shift; + return $this->{rsq}= 1.0- $this->{sse} / $this->sst(); +} + +sub adjrsq { + my $this= shift; + return $this->{adjrsq}= 1.0- (1.0- $this->rsq())*($this->{n}-1)/($this->{n} - $this->{k}); +} + +sub sigmasq { + my $this= shift; + return $this->{sigmasq}= ($this->{n}<=$this->{k}) ? "Inf" : ($this->{sse}/($this->{n} - $this->{k})); +} + +sub ybar { + my $this= shift; + return $this->{ybar}= $this->{sy}/$this->{wghtn}; +} + +sub sst { + my $this= shift; + return $this->{sst}= ($this->{syy} - $this->{wghtn}*($this->ybar())**2); +} + +sub k { + my $this= shift; + return $this->{k}; +} +sub n { + my $this= shift; + return $this->{n}; +} + + + +################################################################ +### $reg->print() [no arguments!] +### +### prints the estimated coefficients, and R^2 and N. For an +### example see the Synopsis. +################################################################ +sub print { + my $this= shift; + + print "****************************************************************\n"; + print "Regression '$this->{regname}'\n"; + print "****************************************************************\n"; + + my $theta= $this->theta(); + my @standarderrors= $this->standarderrors(); + + printf "%-15s\t%12s\t%12s\t%7s\n", "Name", "Theta", "StdErr", "T-stat"; + for (my $i=0; $i< $this->k(); ++$i) { + my $name= "[$i".(defined($this->{xnames}->[$i]) ? "='$this->{xnames}->[$i]'":"")."]"; + printf "%-15s\t", $name; + printf "%12.4f\t", $theta->[$i]; + printf "%12.4f\t", $standarderrors[$i]; + printf "%7.2f", ($theta->[$i]/$standarderrors[$i]); + printf "\n"; + } + + print "\nR^2= ".sprintf("%.3f", $this->rsq()).", N= ".$this->n().", K= ".$this->k()."\n"; + print "****************************************************************\n"; +} + + + +################################################################ +### $theta = $reg->theta or @theta = $reg->theta +### +### This is the work horse. It estimates and returns the vector +### of coefficients. In scalar context returns an array +### reference; in list context it returns the list of +### coefficients. +################################################################ +sub theta { + my $this= shift; + + if (defined($this->{theta})) { + return wantarray ? @{$this->{theta}} : $this->{theta}; + } + + if ($this->{n} < $this->{k}) { return; } + for (my $i=($this->{k}); $i>=1; --$i) { + $this->{theta}->[$i]= $this->{thetabar}->[$i]; + my $nextr= int (($i-1)*((2.0*$this->{k}-$i))/2.0+1); + if (!($nextr<=$this->{rbarsize})) { confess "$MNAME:theta: Internal Error 3"; } + for (my $kc=$i+1;$kc<=$this->{k};++$kc) { + $this->{theta}->[$i]-=($this->{rbar}->[$nextr]*$this->{theta}->[$kc]); + ++$nextr; + } + } + + + my $ref = $this->{theta}; shift(@$ref); # we are counting from 0 + + # if in a scalar context, otherwise please return the array directly + wantarray ? @{$this->{theta}} : $this->{theta}; +} + +################################################################ +### @se= $reg->standarderrors() +### +### This is the most difficult routine. Take it on faith. +### +### R=Rbar is an upperright triangular matrix, kept in normalized +### form with implicit 1's on the diagonal. D is a diagonal scaling +### matrix. These correspond to "standard Regression usage" as +### +### X' X = R' D R +### +### A backsubsitution routine (in thetacov) allows to invert the R +### matrix (the inverse is upper-right triangular, too!). Call this +### matrix H, that is H=R^(-1). +### +### (X' X)^(-1) = [(R' D^(1/2)') (D^(1/2) R)]^(-1) +### = [ R^-1 D^(-1/2) ] [ R^-1 D^(-1/2) ]' +### +### Let's work this for our example, where +### +### $reg->include( 2.0, [ 1.0, 3.0, -1.0 ] ); +### $reg->include( 1.0, [ 1.0, 5.0, 2.0 ] ); +### $reg->include( 20.0, [ 1.0, 31.0, 0.0 ] ); +### $reg->include( 15.0, [ 1.0, 11.0, 2.0 ] ); +### +### For debuggin, the X'X matrix for our example is +### 4, 50, 3 +### 50 1116 29 +### 3 29 9 +### +### Its inverse is +### 0.70967 -0.027992 -0.146360 +### -0.02799 0.002082 0.002622 +### -0.14636 0.002622 0.151450 +### +### Internally, this is kept as follows +### +### R is 1, 0, 0 +### 12.5 1 0 +### 0.75 -0.0173 1 +### +### d is the diagonal(4,491,6.603) matrix, which as 1/sqrt becomes dhi= 0.5, 0.04513, 0.3892 +### +### R * d * R' is indeed the X' X matrix. +### +### The inverse of R is +### +### 1, 0, 0 +### -12.5 1 0 +### -0.9664 0.01731 1 +### +### in R, t(solve(R) %*% dhi) %*% t( t(solve(R) %*% dhi) ) is the correct inverse. +### +### The routine has a debug switch which makes it come out very verbose. +################################################################ +my $debug=0; + +sub standarderrors { + my $this= shift; + our $K= $this->{k}; # convenience + + our @u; + sub ui { + if ($debug) { + ($_[0]<1)||($_[0]>$K) and confess "$MNAME:standarderrors: bad index 0 $_[0]\n"; + ($_[1]<1)||($_[1]>$K) and confess "$MNAME:standarderrors: bad index 1 $_[0]\n"; + } + return (($K*($_[0]-1))+($_[1]-1)); + } + sub giveuclear { + for (my $i=0; $i<($K**2); ++$i) { $u[$i]=0.0; } + return (wantarray) ? @u : \@u; + } + + sub u { return $u[ui($_[0], $_[1])]; } + sub setu { return $u[ui($_[0], $_[1])]= $_[2]; } + sub add2u { return $u[ui($_[0], $_[1])]+= $_[2]; } + sub mult2u { return $u[ui($_[0], $_[1])]*= $_[2]; } + + (defined($K)) or confess "$MNAME:standarderrors: Internal Error: I forgot the number of variables.\n"; + if ($debug) { + print "The Start Matrix is:\n"; + for (my $i=1; $i<=$K; ++$i) { + print "[$i]:\t"; + for (my $j=1; $j<=$K; ++$j) { + print $this->rbr($i, $j)."\t"; + } + print "\n"; + } + print "The Start d vector is:\n"; + for (my $i=1; $i<=$K; ++$i) { + print "".$this->{d}[$i]."\t"; + } + print "\n"; + } + + sub rbrindex { + return ($_[0] == $_[1]) ? -9 : + ($_[0]>$_[1]) ? -8 : + ((($_[0]-1.0)* (2.0*$K-$_[0])/2.0+1.0) + $_[1] - 1 - $_[0] ); } + + # now a real member routine; + sub rbr { + my $this= shift; + return ($_[0] == $_[1]) ? 1 : ( ($_[0]>$_[1]) ? 0 : ($this->{rbar}[rbrindex($_[0],$_[1])])); + } + + my $u= giveuclear(); + + for (my $j=$K; $j>=1; --$j) { + setu($j,$j, 1.0/($this->rbr($j,$j))); + for (my $k=$j-1; $k>=1; --$k) { + setu($k,$j,0); + for (my $i=$k+1; $i<=$j; ++$i) { add2u($k,$j, $this->rbr($k,$i)*u($i,$j)); } + mult2u($k,$j, (-1.0)/$this->rbr($k,$k)); + } + } + + if ($debug) { + print "The Inverse Matrix of R is:\n"; + for (my $i=1; $i<=$K; ++$i) { + print "[$i]:\t"; + for (my $j=1; $j<=$K; ++$j) { + print $u[ui($i,$j)]."\t"; + } + print "\n"; + } + } + + for (my $i=1;$i<=$K;++$i) { + for (my $j=1;$j<=$K;++$j) { + if (abs($this->{d}[$j]){d}[$j])==0.0) { + if ($this->{neverabort}) { + for (my $i=0; $i<($K**2); ++$i) { $u[$i]= "NaN"; } + return undef; + } + else { confess "$MNAME:standarderrors: I cannot compute the theta-covariance matrix for variable $j ".($this->{d}[$j])."\n"; } + } + } + else { mult2u($i,$j, sqrt(1.0/$this->{d}[$j])); } + } + } + + if ($debug) { + print "The Inverse Matrix of R multipled by D^(-1/2) is:\n"; + for (my $i=1; $i<=$K; ++$i) { + print "[$i]:\t"; + for (my $j=1; $j<=$K; ++$j) { + print $u[ui($i,$j)]."\t"; + } + print "\n"; + } + } + + $this->{sigmasq}= ($this->{n}<=$K) ? "Inf" : ($this->{sse}/($this->{n} - $K)); + my @xpxinv; + for (my $i=1;$i<=$K; ++$i) { + for (my $j=$i;$j<=$K;++$j) { + my $indexij= ui($i,$j); + $xpxinv[$indexij]= 0.0; + for (my $k=1;$k<=$K;++$k) { + $xpxinv[$indexij] += $u[ui($i,$k)]*$u[ui($j,$k)]; + } + $xpxinv[ui($j,$i)]= $xpxinv[$indexij]; # this is symmetric + } + } + + if ($debug) { + print "The full inverse matrix of X'X is:\n"; + for (my $i=1; $i<=$K; ++$i) { + print "[$i]:\t"; + for (my $j=1; $j<=$K; ++$j) { + print $xpxinv[ui($i,$j)]."\t"; + } + print "\n"; + } + print "The sigma^2 is ".$this->{sigmasq}."\n"; + } + + ## 99% of the usage here will be to print the diagonal elements of sqrt ( (X' X) sigma^2 ) + ## so, let's make this our first returned object; + + my @secoefs; + for (my $i=1; $i<=$K; ++$i) { + $secoefs[$i-1]= sqrt($xpxinv[ui($i,$i)] * $this->{sigmasq}); + } + if ($debug) { for (my $i=0; $i<$K; ++$i) { print " $secoefs[$i] "; } print "\n"; } + + # the following are clever return methods; if the user goes over the secoefs, + # almost surely an error will result, because he will run into xpxinv. For special + # usage, however, xpxinv may still be useful. + + return ( @secoefs, \@xpxinv, $this->sigmasq ); +} + + +################################ +sub linearcombination_variance { + my $this= shift; + our $K= $this->{k}; # convenience + + my @linear= @_; + + ($#linear+1 == $K) or confess "$MNAME:linearcombination_variance: ". + "Sorry, you must give a vector of length $K, not ".($#linear+1)."\n"; + + my @allback= $this->standarderrors(); # compute everything we need; + + my $xpxinv= $allback[$this->{k}]; + my $sigmasq= $allback[$this->{k}+1]; + + my $sum=0; + for (my $i=1; $i<=$K; ++$i) { + for (my $j=1; $j<=$K; ++$j) { + $sum+= $linear[$i-1]*$linear[$j-1]*$xpxinv->[ui($i,$j)]; + } + } + $sum*=$sigmasq; + return $sum; +} + + +################################################################ +### sub dump() was used internally for debugging. +################################################################ +sub dump { + my $this= $_[0]; + print "****************************************************************\n"; + print "Regression '$this->{regname}'\n"; + print "****************************************************************\n"; + sub print1val { + no strict; + print "$_[1]($_[2])=\t". ((defined($_[0]->{ $_[2] }) ? $_[0]->{ $_[2] } : "intentionally undef")); + + my $ref=$_[0]->{ $_[2] }; + + if (ref($ref) eq 'ARRAY') { + my $arrayref= $ref; + print " $#$arrayref+1 elements:\n"; + if ($#$arrayref>30) { + print "\t"; + for(my $i=0; $i<$#$arrayref+1; ++$i) { print "$i='$arrayref->[$i]';"; } + print "\n"; + } + else { + for(my $i=0; $i<$#$arrayref+1; ++$i) { print "\t$i=\t'$arrayref->[$i]'\n"; } + } + } + elsif (ref($ref) eq 'HASH') { + my $hashref= $ref; + print " ".scalar(keys(%$hashref))." elements\n"; + while (my ($key, $val) = each(%$hashref)) { + print "\t'$key'=>'$val';\n"; + } + } + else { + print " [was scalar]\n"; } + } + + while (my ($key, $val) = each(%$this)) { + $this->print1val($key, $key); + } + print "****************************************************************\n"; +} + +################################################################ +### The Test Program. Invoke as "perl Regression.pm". +################################################################ + + +if ($0 eq "Regression.pm") { + + # Create regression object + my $reg = Statistics::Regression->new( "sample regression", [ "const", "someX", "someY" ] ); + + # Add data points + $reg->include( 2.0, [ 1.0, 3.0, -1.0 ] ); + $reg->include( 1.0, [ 1.0, 5.0, 2.0 ] ); + $reg->include( 20.0, [ 1.0, 31.0, 0.0 ] ); + + my %inhash= ( const => 1.0, someX => 11.0, someY => 2.0, ignored => "ignored" ); + $reg->include( 15.0, \%inhash ); + # $reg->include( 15.0, [ 1.0, 11.0, 2.0 ] ); + + # Print the result + $reg->print(); +} + + +1; From 859c632132fa61496a1d825195ef1c9184dccdbb Mon Sep 17 00:00:00 2001 From: artica Date: Tue, 14 Dec 2021 01:00:20 +0100 Subject: [PATCH 58/59] 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 98f1d0fdfb..78caee173d 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-211213 +Version: 7.0NG.758.1-211214 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 a5c86d3679..5dd00feb30 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-211213" +pandora_version="7.0NG.758.1-211214" 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 723a47a2a1..5a4c399abb 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 => '211213'; +use constant AGENT_BUILD => '211214'; # 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 a70049e287..15080a0256 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 211213 +%define release 211214 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 8c0f409256..dfa784b400 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 211213 +%define release 211214 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 d86e948ae3..afa21025a6 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="211213" +PI_BUILD="211214" OS_NAME=`uname -s` FORCE=0 diff --git a/pandora_agents/win32/installer/pandora.mpi b/pandora_agents/win32/installer/pandora.mpi index 693218a7eb..87713aac97 100644 --- a/pandora_agents/win32/installer/pandora.mpi +++ b/pandora_agents/win32/installer/pandora.mpi @@ -186,7 +186,7 @@ UpgradeApplicationID {} Version -{211213} +{211214} ViewReadme {Yes} diff --git a/pandora_agents/win32/pandora.cc b/pandora_agents/win32/pandora.cc index 4ec63d7668..3d91e44acc 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 211213") +#define PANDORA_VERSION ("7.0NG.758.1 Build 211214") string pandora_path; string pandora_dir; diff --git a/pandora_agents/win32/versioninfo.rc b/pandora_agents/win32/versioninfo.rc index f4660c96d2..4b1783bac1 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 211213))" + VALUE "ProductVersion", "(7.0NG.758.1(Build 211214))" VALUE "FileVersion", "1.0.0.0" END END diff --git a/pandora_console/DEBIAN/control b/pandora_console/DEBIAN/control index 5602ae3ae7..56205122ec 100644 --- a/pandora_console/DEBIAN/control +++ b/pandora_console/DEBIAN/control @@ -1,5 +1,5 @@ package: pandorafms-console -Version: 7.0NG.758.1-211213 +Version: 7.0NG.758.1-211214 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 b1eee3d6c3..cefd064268 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-211213" +pandora_version="7.0NG.758.1-211214" package_pear=0 package_pandora=1 diff --git a/pandora_console/include/config_process.php b/pandora_console/include/config_process.php index cd14469c85..972bf6e505 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 = 'PC211213'; +$build_version = 'PC211214'; $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 25b1ad32be..70ccb5807e 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 80af886a90..e30b175537 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 211213 +%define release 211214 Summary: Pandora FMS Server Name: %{name} diff --git a/pandora_server/pandora_server.spec b/pandora_server/pandora_server.spec index a689069e9e..0612cdd696 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 211213 +%define release 211214 Summary: Pandora FMS Server Name: %{name} diff --git a/pandora_server/pandora_server_installer b/pandora_server/pandora_server_installer index 80af02e267..643f737290 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="211213" +PI_BUILD="211214" MODE=$1 if [ $# -gt 1 ]; then diff --git a/pandora_server/util/pandora_db.pl b/pandora_server/util/pandora_db.pl index ee0b76247c..76b67aa2c4 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 211213"; +my $version = "7.0NG.758.1 Build 211214"; # Pandora server configuration my %conf; diff --git a/pandora_server/util/pandora_manage.pl b/pandora_server/util/pandora_manage.pl index f31453d6af..6a5834e132 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 211213"; +my $version = "7.0NG.758.1 Build 211214"; # save program name for logging my $progname = basename($0); From 6cb26d25477861468a87ad409d272af9f0f79b7e Mon Sep 17 00:00:00 2001 From: Daniel Barbero Martin Date: Tue, 14 Dec 2021 08:33:24 +0100 Subject: [PATCH 59/59] report alert action ucfirst th table #8368 --- pandora_console/include/functions_reporting_html.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index 7260843d29..0a146969b4 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -2795,6 +2795,13 @@ function reporting_html_alert_report_actions($table, $item, $pdf=0) } +/** + * Draw alert action table. + * + * @param array $data Data. + * + * @return string Html output. + */ function get_alert_table($data) { $table = new StdCLass(); @@ -2807,7 +2814,7 @@ function get_alert_table($data) $head = reset($data); foreach (array_reverse(array_keys($head)) as $name) { - $table->head[] = $name; + $table->head[] = ucfirst($name); } foreach ($data as $key => $params) {