From 33d9db657e0e9b9061c96a94e2b9ec2553e050e2 Mon Sep 17 00:00:00 2001 From: Daniel Barbero Martin Date: Mon, 29 Nov 2021 20:45:35 +0100 Subject: [PATCH] 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; }