mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-29 16:55:05 +02:00
wip reports alert actions
This commit is contained in:
parent
e8bf86a789
commit
33d9db657e
@ -185,6 +185,8 @@ $nothing_value = 0;
|
|||||||
|
|
||||||
$graph_render = (empty($config['type_mode_graph']) === true) ? 0 : $config['type_mode_graph'];
|
$graph_render = (empty($config['type_mode_graph']) === true) ? 0 : $config['type_mode_graph'];
|
||||||
|
|
||||||
|
$valuesGroupBy = [0 => __('None')];
|
||||||
|
|
||||||
switch ($action) {
|
switch ($action) {
|
||||||
case 'new':
|
case 'new':
|
||||||
$actionParameter = 'save';
|
$actionParameter = 'save';
|
||||||
@ -777,6 +779,13 @@ switch ($action) {
|
|||||||
|
|
||||||
$group_by = $es['group_by'];
|
$group_by = $es['group_by'];
|
||||||
|
|
||||||
|
$valuesGroupBy = [
|
||||||
|
'agent' => __('Agent'),
|
||||||
|
'module' => __('Module'),
|
||||||
|
'group' => __('Group'),
|
||||||
|
'template' => __('Template'),
|
||||||
|
];
|
||||||
|
|
||||||
$period = $item['period'];
|
$period = $item['period'];
|
||||||
|
|
||||||
$lapse = $item['lapse'];
|
$lapse = $item['lapse'];
|
||||||
@ -3088,8 +3097,7 @@ $class = 'databox filters';
|
|||||||
echo __('Time lapse intervals');
|
echo __('Time lapse intervals');
|
||||||
ui_print_help_tip(
|
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',
|
||||||
$lapse,
|
$lapse,
|
||||||
'',
|
'',
|
||||||
'',
|
__('None'),
|
||||||
'0',
|
'0',
|
||||||
10,
|
10,
|
||||||
'',
|
'',
|
||||||
@ -3302,19 +3310,12 @@ $class = 'databox filters';
|
|||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<?php
|
<?php
|
||||||
$valuesGroupBy = [
|
|
||||||
'agent' => __('Agent'),
|
|
||||||
'module' => __('Module'),
|
|
||||||
'group' => __('Group'),
|
|
||||||
'template' => __('Template'),
|
|
||||||
];
|
|
||||||
|
|
||||||
html_print_select(
|
html_print_select(
|
||||||
$valuesGroupBy,
|
$valuesGroupBy,
|
||||||
'group_by',
|
'group_by',
|
||||||
$group_by,
|
$group_by,
|
||||||
'',
|
'',
|
||||||
__('None'),
|
'',
|
||||||
0,
|
0,
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
|
@ -2937,7 +2937,6 @@ function alerts_get_alert_fired($filters=[], $groupsBy=[], $total=false)
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: ALL;
|
|
||||||
$actions_names = alerts_get_actions_names($filters['actions'], true);
|
$actions_names = alerts_get_actions_names($filters['actions'], true);
|
||||||
|
|
||||||
$group_array = [];
|
$group_array = [];
|
||||||
@ -2979,20 +2978,12 @@ function alerts_get_alert_fired($filters=[], $groupsBy=[], $total=false)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($total === false) {
|
if (is_array($fields_actions) === true
|
||||||
if (is_array($fields_actions) === true
|
&& empty($fields_actions) === false
|
||||||
&& empty($fields_actions) === false
|
) {
|
||||||
) {
|
foreach ($fields_actions as $name => $field) {
|
||||||
foreach ($fields_actions as $name => $field) {
|
$fields[] = $field;
|
||||||
$fields[] = $field;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$names_modules = modules_get_agentmodule_name_array(
|
|
||||||
array_values($filters['modules'])
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
$fields = ['COUNT(tevento.id_evento) as fired'];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$names_search = [];
|
$names_search = [];
|
||||||
@ -3001,41 +2992,39 @@ function alerts_get_alert_fired($filters=[], $groupsBy=[], $total=false)
|
|||||||
case 'module':
|
case 'module':
|
||||||
$fields[] = 'tevento.id_agentmodule as module';
|
$fields[] = 'tevento.id_agentmodule as module';
|
||||||
$group_array[] = 'tevento.id_agentmodule';
|
$group_array[] = 'tevento.id_agentmodule';
|
||||||
$names_search = modules_get_agentmodule_name_array(
|
if ($total === false) {
|
||||||
array_values($filters['modules'])
|
$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;
|
break;
|
||||||
|
|
||||||
case 'template':
|
case 'template':
|
||||||
$fields[] = 'talert_template_modules.id_alert_template as template';
|
$fields[] = 'talert_template_modules.id_alert_template as template';
|
||||||
$group_array[] = 'talert_template_modules.id_alert_template';
|
$group_array[] = 'talert_template_modules.id_alert_template';
|
||||||
$names_search = alerts_get_templates_name_array(
|
if ($total === false) {
|
||||||
array_values($filters['templates'])
|
$names_search = alerts_get_templates_name_array(
|
||||||
);
|
array_values($filters['templates'])
|
||||||
|
);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'agent':
|
case 'agent':
|
||||||
$fields[] = 'tevento.id_agente as agent';
|
$fields[] = 'tevento.id_agente as agent';
|
||||||
$group_array[] = 'tevento.id_agente';
|
$group_array[] = 'tevento.id_agente';
|
||||||
$names_search = agents_get_alias_array(
|
if ($total === false) {
|
||||||
array_values($filters['agents'])
|
$names_search = agents_get_alias_array(
|
||||||
);
|
array_values($filters['agents'])
|
||||||
|
);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'group':
|
case 'group':
|
||||||
$fields[] = 'tevento.id_grupo as `group`';
|
$fields[] = 'tevento.id_grupo as `group`';
|
||||||
$group_array[] = 'tevento.id_grupo';
|
$group_array[] = 'tevento.id_grupo';
|
||||||
|
if ($total === false) {
|
||||||
|
$names_search = users_get_groups($config['user'], 'AR', false);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -3044,13 +3033,17 @@ function alerts_get_alert_fired($filters=[], $groupsBy=[], $total=false)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($groupsBy['lapse']) === true) {
|
if ($total === false) {
|
||||||
$fields[] = sprintf(
|
if (isset($groupsBy['lapse']) === true
|
||||||
'ROUND((CEILING(UNIX_TIMESTAMP(tevento.timestamp) / %d) * %d)) AS Period',
|
&& empty($groupsBy['lapse']) === false
|
||||||
(int) $groupsBy['lapse'],
|
) {
|
||||||
(int) $groupsBy['lapse']
|
$fields[] = sprintf(
|
||||||
);
|
'ROUND((CEILING(UNIX_TIMESTAMP(tevento.timestamp) / %d) * %d)) AS Period',
|
||||||
$group_array[] = 'period';
|
(int) $groupsBy['lapse'],
|
||||||
|
(int) $groupsBy['lapse']
|
||||||
|
);
|
||||||
|
$group_array[] = 'period';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$group_by = '';
|
$group_by = '';
|
||||||
@ -3096,7 +3089,7 @@ function alerts_get_alert_fired($filters=[], $groupsBy=[], $total=false)
|
|||||||
$data = array_reduce(
|
$data = array_reduce(
|
||||||
$data,
|
$data,
|
||||||
function ($carry, $item) use ($groupsBy) {
|
function ($carry, $item) use ($groupsBy) {
|
||||||
$period = $item['Period'];
|
$period = (isset($item['Period']) === true) ? $item['Period'] : 0;
|
||||||
$grby = $item[$groupsBy['group_by']];
|
$grby = $item[$groupsBy['group_by']];
|
||||||
unset($item['Period']);
|
unset($item['Period']);
|
||||||
unset($item[$groupsBy['group_by']]);
|
unset($item[$groupsBy['group_by']]);
|
||||||
@ -3106,26 +3099,64 @@ function alerts_get_alert_fired($filters=[], $groupsBy=[], $total=false)
|
|||||||
[]
|
[]
|
||||||
);
|
);
|
||||||
|
|
||||||
$first_element = array_shift($data);
|
$intervals = [];
|
||||||
$first_element = array_shift($first_element);
|
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 = [];
|
$clone = [];
|
||||||
foreach ($first_element as $key_clone => $value_clone) {
|
foreach ($first_element as $key_clone => $value_clone) {
|
||||||
$clone[$key_clone] = 0;
|
$clone[$key_clone] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = [];
|
$result = [];
|
||||||
foreach ($data as $period => $array_data) {
|
if (empty($intervals) === true) {
|
||||||
foreach ($names_search as $id => $name) {
|
foreach ($data as $period => $array_data) {
|
||||||
foreach ($array_data as $grby => $values) {
|
foreach ($names_search as $id => $name) {
|
||||||
if ($grby === $id) {
|
if (isset($array_data[$id]) === true) {
|
||||||
$values[$groupsBy['group_by']] = $name;
|
$result[$period][$id] = $array_data[$id];
|
||||||
$result[$period][$id] = $values;
|
$result[$period][$id][$groupsBy['group_by']] = $name;
|
||||||
} else {
|
} else {
|
||||||
$clone[$groupsBy['group_by']] = $name;
|
$clone[$groupsBy['group_by']] = $name;
|
||||||
$result[$period][$id] = $clone;
|
$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;
|
$data = $result;
|
||||||
|
@ -2746,14 +2746,24 @@ function reporting_html_alert_report_actions($table, $item, $pdf=0)
|
|||||||
if (isset($data['data']) === true
|
if (isset($data['data']) === true
|
||||||
&& empty($data['data']) === false
|
&& empty($data['data']) === false
|
||||||
) {
|
) {
|
||||||
if (isset($groupsBy['lapse']) === true
|
// if (isset($groupsBy['lapse']) === true
|
||||||
&& empty($groupsBy['lapse']) === false
|
// && empty($groupsBy['lapse']) === false
|
||||||
) {
|
// ) {
|
||||||
}
|
//
|
||||||
|
// }
|
||||||
foreach ($data['data'] as $period => $data_array) {
|
foreach ($data['data'] as $period => $data_array) {
|
||||||
|
if (empty($period) === false) {
|
||||||
|
$output .= '<p>';
|
||||||
|
$output .= date('d-m-Y H:i:s', ($period - (int) $groupsBy['lapse']));
|
||||||
|
$output .= ' - ';
|
||||||
|
$output .= date('d-m-Y H:i:s', $period);
|
||||||
|
$output .= '</p>';
|
||||||
|
}
|
||||||
|
|
||||||
$output .= get_alert_table($data_array);
|
$output .= get_alert_table($data_array);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hd($data['summary']);
|
||||||
} else {
|
} else {
|
||||||
// TODO: SMS FAIL.
|
// TODO: SMS FAIL.
|
||||||
}
|
}
|
||||||
@ -2775,8 +2785,7 @@ function get_alert_table($data)
|
|||||||
$table->width = '100%';
|
$table->width = '100%';
|
||||||
$table->data = [];
|
$table->data = [];
|
||||||
$table->head = [];
|
$table->head = [];
|
||||||
$head = array_shift($data);
|
$head = reset($data);
|
||||||
hd($head);
|
|
||||||
foreach (array_reverse(array_keys($head)) as $name) {
|
foreach (array_reverse(array_keys($head)) as $name) {
|
||||||
$table->head[$name] = $name;
|
$table->head[$name] = $name;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user