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']; $graph_render = (empty($config['type_mode_graph']) === true) ? 0 : $config['type_mode_graph'];
$valuesGroupBy = [0 => __('None')]; $valuesGroupBy = [0 => __('None')];
$valuesGroupByDefaultAlertActions = [
'agent' => __('Agent'),
'module' => __('Module'),
'group' => __('Group'),
'template' => __('Template'),
];
switch ($action) { switch ($action) {
case 'new': case 'new':
@ -735,16 +741,20 @@ switch ($action) {
case 'agent_module': case 'agent_module':
$description = $item['description']; $description = $item['description'];
$es = json_decode($item['external_source'], true); $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'); $selection_a_m = get_parameter('selection');
$recursion = $item['recursion']; $recursion = $item['recursion'];
if ((count($es['module']) == 1) && ($es['module'][0] == 0)) {
$module = '';
} else {
$module = $es['module'];
}
$group = $item['id_group']; $group = $item['id_group'];
$modulegroup = $item['id_module_group']; $modulegroup = $item['id_module_group'];
$idAgentModule = $module; $idAgentModule = $module;
@ -4614,7 +4624,6 @@ $(document).ready (function () {
$("#module").html(''); $("#module").html('');
// Check module all. // Check module all.
$("#checkbox-module-check-all").prop('checked', false); $("#checkbox-module-check-all").prop('checked', false);
console.log(data);
if(data){ if(data){
jQuery.each (data, function (id, value) { jQuery.each (data, function (id, value) {
option = $("<option></option>") option = $("<option></option>")
@ -4737,7 +4746,13 @@ $(document).ready (function () {
} }
switch (type){ switch (type){
case 'agent_module':
case 'alert_report_actions': 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 agents_multiple = $('#id_agents2').val();
var modules_multiple = $('#module').val(); var modules_multiple = $('#module').val();
$('#hidden-id_agents2-multiple-text').val(JSON.stringify(agents_multiple)); $('#hidden-id_agents2-multiple-text').val(JSON.stringify(agents_multiple));
@ -4769,12 +4784,6 @@ $(document).ready (function () {
return false; return false;
} }
break; break;
case 'agent_module':
if ($("select#id_agents2>option:selected").val() == undefined) {
dialog_message('#message_no_agent');
return false;
}
break;
case 'inventory': case 'inventory':
case 'inventory_changes': case 'inventory_changes':
if ($("select#id_agents>option:selected").val() == undefined) { if ($("select#id_agents>option:selected").val() == undefined) {
@ -4819,18 +4828,11 @@ $(document).ready (function () {
case 'sumatory': case 'sumatory':
case 'historical_data': case 'historical_data':
case 'increment': case 'increment':
if ($("#id_agent_module").val() == 0) { if ($("#id_agent_module").val() == 0) {
dialog_message('#message_no_module'); dialog_message('#message_no_module');
return false; return false;
} }
break; break;
case 'agent_module':
if ($("select#module>option:selected").val() == undefined) {
dialog_message('#message_no_module');
return false;
}
break;
case 'inventory': case 'inventory':
case 'inventory_changes': case 'inventory_changes':
if ($("select#inventory_modules>option:selected").val() == 0) { if ($("select#inventory_modules>option:selected").val() == 0) {
@ -4883,7 +4885,12 @@ $(document).ready (function () {
return false; return false;
} }
switch (type){ switch (type){
case 'agent_module':
case 'alert_report_actions': 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 agents_multiple = $('#id_agents2').val();
var modules_multiple = $('#module').val(); var modules_multiple = $('#module').val();
$('#hidden-id_agents2-multiple-text').val(JSON.stringify(agents_multiple)); $('#hidden-id_agents2-multiple-text').val(JSON.stringify(agents_multiple));
@ -4915,12 +4922,6 @@ $(document).ready (function () {
return false; return false;
} }
break; break;
case 'agent_module':
if ($("select#id_agents2>option:selected").val() == undefined) {
dialog_message('#message_no_agent');
return false;
}
break;
case 'inventory': case 'inventory':
if ($("select#id_agents>option:selected").val() == undefined) { if ($("select#id_agents>option:selected").val() == undefined) {
dialog_message('#message_no_agent'); dialog_message('#message_no_agent');
@ -4960,18 +4961,11 @@ $(document).ready (function () {
case 'sumatory': case 'sumatory':
case 'historical_data': case 'historical_data':
case 'increment': case 'increment':
if ($("#id_agent_module").val() == 0) { if ($("#id_agent_module").val() == 0) {
dialog_message('#message_no_module'); dialog_message('#message_no_module');
return false; return false;
} }
break; break;
case 'agent_module':
if ($("select#module>option:selected").val() == undefined) {
dialog_message('#message_no_module');
return false;
}
break;
case 'inventory': case 'inventory':
if ($("select#inventory_modules>option:selected").val() == 0) { if ($("select#inventory_modules>option:selected").val() == 0) {
dialog_message('#message_no_module'); dialog_message('#message_no_module');
@ -6171,6 +6165,19 @@ function chooseType() {
$("#row_lapse").show(); $("#row_lapse").show();
$("#row_show_summary").show(); $("#row_show_summary").show();
$("#row_group_by").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; break;
case 'event_report_group': case 'event_report_group':

View File

@ -1676,17 +1676,27 @@ switch ($action) {
break; break;
case 'agent_module': case 'agent_module':
$agents_to_report = get_parameter('id_agents2'); $agents_to_report_text = get_parameter('id_agents2-multiple-text', '');
$modules_to_report = get_parameter( $modules_to_report_text = get_parameter('module-multiple-text', '');
'module',
'' // 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( $es['module'] = get_same_modules(
$agents_to_report, $agents_to_report,
$modules_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); $values['external_source'] = json_encode($es);
$good_format = true; $good_format = true;
@ -2466,17 +2476,27 @@ switch ($action) {
break; break;
case 'agent_module': case 'agent_module':
$agents_to_report = get_parameter('id_agents2'); $agents_to_report_text = get_parameter('id_agents2-multiple-text');
$modules_to_report = get_parameter( $modules_to_report_text = get_parameter('module-multiple-text', '');
'module',
'' // 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( $es['module'] = get_same_modules(
$agents_to_report, $agents_to_report,
$modules_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); $values['external_source'] = json_encode($es);
$good_format = true; $good_format = true;

View File

@ -2992,39 +2992,31 @@ 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';
if ($total === false) {
$names_search = modules_get_agentmodule_name_array( $names_search = modules_get_agentmodule_name_array(
array_values($filters['modules']) array_values($filters['modules'])
); );
}
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';
if ($total === false) {
$names_search = alerts_get_templates_name_array( $names_search = alerts_get_templates_name_array(
array_values($filters['templates']) 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';
if ($total === false) {
$names_search = agents_get_alias_array( $names_search = agents_get_alias_array(
array_values($filters['agents']) 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); $names_search = users_get_groups($config['user'], 'AR', false);
}
break; break;
default: default:
@ -3038,9 +3030,7 @@ function alerts_get_alert_fired($filters=[], $groupsBy=[], $total=false)
&& empty($groupsBy['lapse']) === false && empty($groupsBy['lapse']) === false
) { ) {
$fields[] = sprintf( $fields[] = sprintf(
'ROUND((CEILING(UNIX_TIMESTAMP(tevento.timestamp) / %d) * %d)) AS Period', 'tevento.utimestamp AS Period'
(int) $groupsBy['lapse'],
(int) $groupsBy['lapse']
); );
$group_array[] = 'period'; $group_array[] = 'period';
} }
@ -3089,7 +3079,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 = (isset($item['Period']) === true) ? $item['Period'] : 0; $period = (isset($item['Period']) === true) ? (int) $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']]);
@ -3103,14 +3093,10 @@ function alerts_get_alert_fired($filters=[], $groupsBy=[], $total=false)
if (isset($groupsBy['lapse']) === true if (isset($groupsBy['lapse']) === true
&& empty($groupsBy['lapse']) === false && empty($groupsBy['lapse']) === false
) { ) {
$start_interval = round( $tend = time();
(ceil( $tstart = ($tend - (int) $filters['period']);
((time() - $filters['period']) / (int) $groupsBy['lapse']) for ($current_time = $tstart; $current_time <= $tend; ($current_time += $groupsBy['lapse'])) {
) * (int) $groupsBy['lapse']) $intervals[] = (int) $current_time;
);
for ($interval = $start_interval; $interval < time(); ($interval = $interval + (int) $groupsBy['lapse'])) {
$intervals[] = $interval;
} }
} }
@ -3135,35 +3121,50 @@ function alerts_get_alert_fired($filters=[], $groupsBy=[], $total=false)
} }
} }
} else { } 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) { foreach ($data as $period => $array_data) {
if ((int) $inter === (int) $period) { $period_time = (int) $period;
foreach ($names_search as $id => $name) { if ($start_interval < $period_time && $period_time <= $end_interval) {
if (isset($array_data[$id]) === true) { foreach ($array_data as $id_data => $value_data) {
$result[$period][$id] = $array_data[$id]; foreach ($value_data as $key_data => $v) {
$result[$period][$id][$groupsBy['group_by']] = $name; if ($key_data !== $groupsBy['group_by']) {
if (isset($result[$start_interval][$id_data][$key_data])) {
$result[$start_interval][$id_data][$key_data] += $v;
} else { } else {
$result[$period][$id] = $clone; $result[$start_interval][$id_data][$key_data] = $v;
$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; unset($data[$period]);
}
}
}
}
}
} 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);
} }
} }
return $data; $result['total'] = $total_values;
$result['total'][$groupsBy['group_by']] = __('Total');
}
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) 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)); $name_modules = modules_get_agentmodule_name_array(array_values($modules));
$sql = sprintf( $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) function reporting_agent_module($report, $content)
{ {
global $config; global $config;
$agents_and_modules = json_decode($content['external_source'], true); $external_source = json_decode(
$agents = []; $content['external_source'],
$agents = $agents_and_modules['id_agents']; true
$modules = $agents_and_modules['module']; );
$id_group = $content['id_group'];
$id_module_group = $content['id_module_group']; $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'; $return['type'] = 'agent_module';
@ -2782,7 +2802,9 @@ function reporting_agent_module($report, $content)
$cont = 0; $cont = 0;
foreach ($modules as $modul_id) { 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; $modules_by_name[$cont]['id'] = $modul_id;
$cont++; $cont++;
} }

View File

@ -2742,30 +2742,40 @@ function reporting_html_alert_report_actions($table, $item, $pdf=0)
$groupsBy = $item['groupsBy']; $groupsBy = $item['groupsBy'];
$output = ''; $output = '';
if (isset($data['data']) === true if (isset($data['data']) === true
&& empty($data['data']) === false && empty($data['data']) === false
) { ) {
// if (isset($groupsBy['lapse']) === true
// && empty($groupsBy['lapse']) === false
// ) {
//
// }
foreach ($data['data'] as $period => $data_array) { foreach ($data['data'] as $period => $data_array) {
if (empty($period) === false) { if (empty($period) === false) {
$output .= '<p>'; $output .= '<h1 class="h1-report-alert-actions">';
$output .= date('d-m-Y H:i:s', ($period - (int) $groupsBy['lapse'])); $output .= __('From').' ';
$output .= ' - '; $output .= date(
$output .= date('d-m-Y H:i:s', $period); 'd-m-Y H:i:s',
$output .= '</p>'; $period
);
$output .= ' '.__('to').' ';
$output .= date('d-m-Y H:i:s', ($period + (int) $groupsBy['lapse']));
$output .= '</h1>';
} }
$output .= get_alert_table($data_array); $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 { } else {
// TODO: SMS FAIL. $output .= ui_print_empty_data(
__('No alerts fired'),
'',
true
);
} }
if ($pdf === 0) { if ($pdf === 0) {

View File

@ -8378,3 +8378,9 @@ div.stat-win-spinner img {
font-size: 1.2em; font-size: 1.2em;
margin-right: 5px !important; margin-right: 5px !important;
} }
.h1-report-alert-actions {
text-transform: none;
text-align: left;
margin: 10px;
}