wip reports alert actions

This commit is contained in:
Daniel Barbero Martin 2021-11-30 13:07:37 +01:00
parent 33d9db657e
commit 40fc8c7308
7 changed files with 191 additions and 113 deletions

View File

@ -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 = $("<option></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('<?php echo $action; ?>' === 'new'){
$("#group_by").html('');
var dataDefault = '<?php echo json_encode($valuesGroupByDefaultAlertActions); ?>';
Object.entries(JSON.parse(dataDefault)).forEach(function (item) {
option = $("<option></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':

View File

@ -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;

View File

@ -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;
}

View File

@ -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(

View File

@ -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++;
}

View File

@ -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 .= '<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 .= '<h1 class="h1-report-alert-actions">';
$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 .= '</h1>';
}
$output .= get_alert_table($data_array);
}
hd($data['summary']);
if (isset($data['summary']) === true
&& empty($data['summary']) === false
) {
$output .= '<h1 class="h1-report-alert-actions">';
$output .= __('Total summary');
$output .= '</h1>';
$output .= get_alert_table($data['summary']);
}
} else {
// TODO: SMS FAIL.
$output .= ui_print_empty_data(
__('No alerts fired'),
'',
true
);
}
if ($pdf === 0) {

View File

@ -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;
}