Ent 4515 filtro de alertas en vista de agente

This commit is contained in:
Tatiana Llorente 2020-03-12 10:47:59 +01:00 committed by Daniel Rodriguez
parent e1ff103826
commit 04f2ebeaf1
3 changed files with 388 additions and 23 deletions

View File

@ -24,6 +24,7 @@ $disable_alert = (bool) get_parameter('disable_alert');
$enable_alert = (bool) get_parameter('enable_alert');
$get_actions_module = (bool) get_parameter('get_actions_module');
$show_update_action_menu = (bool) get_parameter('show_update_action_menu');
$get_agent_alerts_agent_view = (bool) get_parameter('get_agent_alerts_agent_view');
if ($get_agent_alerts_simple) {
$id_agent = (int) get_parameter('id_agent');
@ -75,6 +76,258 @@ if ($get_agent_alerts_simple) {
return;
}
if ($get_agent_alerts_agent_view) {
include_once $config['homedir'].'/include/functions_agents.php';
include_once $config['homedir'].'/operation/agentes/alerts_status.functions.php';
include_once $config['homedir'].'/include/functions_users.php';
$agent_a = check_acl($config['id_user'], 0, 'AR');
$agent_w = check_acl($config['id_user'], 0, 'AW');
$access = ($agent_a == true) ? 'AR' : (($agent_w == true) ? 'AW' : 'AR');
$free_search_alert = get_parameter('free_search_alert', '');
$all_groups = json_decode(io_safe_output(get_parameter('all_groups')));
$idAgent = (int) get_parameter('id_agent');
$filter = get_parameter('filter', 'all_enabled');
$url = 'index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente='.$idAgent;
$sortField = get_parameter('sort_field');
$sort = get_parameter('sort', 'none');
$selected = true;
$selectModuleUp = false;
$selectModuleDown = false;
$selectTemplateUp = false;
$selectTemplateDown = false;
$selectLastFiredUp = false;
$selectLastFiredDown = false;
switch ($sortField) {
case 'module':
switch ($sort) {
case 'up':
$selectModuleUp = $selected;
$order = [
'field' => 'agent_module_name',
'order' => 'ASC',
];
break;
case 'down':
$selectModuleDown = $selected;
$order = [
'field' => 'agent_module_name',
'order' => 'DESC',
];
break;
}
break;
case 'template':
switch ($sort) {
case 'up':
$selectTemplateUp = $selected;
$order = [
'field' => 'template_name',
'order' => 'ASC',
];
break;
case 'down':
$selectTemplateDown = $selected;
$order = [
'field' => 'template_name',
'order' => 'DESC',
];
break;
}
break;
case 'last_fired':
switch ($sort) {
case 'up':
$selectLastFiredUp = $selected;
$order = [
'field' => 'last_fired',
'order' => 'ASC',
];
break;
case 'down':
$selectLastFiredDown = $selected;
$order = [
'field' => 'last_fired',
'order' => 'DESC',
];
break;
}
break;
default:
$selectDisabledUp = '';
$selectDisabledDown = '';
$selectModuleUp = $selected;
$selectModuleDown = false;
$selectTemplateUp = false;
$selectTemplateDown = false;
$selectLastFiredUp = false;
$selectLastFiredDown = false;
$order = [
'field' => 'agent_module_name',
'order' => 'ASC',
];
break;
}
if ($free_search_alert != '') {
$whereAlertSimple = 'AND ('.'id_alert_template IN (
SELECT id
FROM talert_templates
WHERE name LIKE "%'.$free_search_alert.'%") OR '.'id_alert_template IN (
SELECT id
FROM talert_templates
WHERE id_alert_action IN (
SELECT id
FROM talert_actions
WHERE name LIKE "%'.$free_search_alert.'%")) OR '.'talert_template_modules.id IN (
SELECT id_alert_template_module
FROM talert_template_module_actions
WHERE id_alert_action IN (
SELECT id
FROM talert_actions
WHERE name LIKE "%'.$free_search_alert.'%")) OR '.'id_agent_module IN (
SELECT id_agente_modulo
FROM tagente_modulo
WHERE nombre LIKE "%'.$free_search_alert.'%") OR '.'id_agent_module IN (
SELECT id_agente_modulo
FROM tagente_modulo
WHERE alias LIKE "%'.$free_search_alert.'%")'.')';
} else {
$whereAlertSimple = '';
}
// Add checks for user ACL.
$groups = users_get_groups($config['id_user'], $access);
$id_groups = array_keys($groups);
if (empty($id_groups)) {
$whereAlertSimple .= ' AND (1 = 0) ';
} else {
$whereAlertSimple .= sprintf(
' AND id_agent_module IN (
SELECT tam.id_agente_modulo
FROM tagente_modulo tam
WHERE tam.id_agente IN (SELECT ta.id_agente
FROM tagente ta LEFT JOIN tagent_secondary_group tasg ON
ta.id_agente = tasg.id_agent
WHERE (ta.id_grupo IN (%s) OR tasg.id_group IN (%s)))) ',
implode(',', $id_groups),
implode(',', $id_groups)
);
}
$alerts = [];
$filter_alert = [];
if ($filter_standby == 'standby_on') {
$filter_alert['disabled'] = $filter;
$filter_alert['standby'] = '1';
} else if ($filter_standby == 'standby_off') {
$filter_alert['disabled'] = $filter;
$filter_alert['standby'] = '0';
} else {
$filter_alert['disabled'] = $filter;
}
$options_simple = ['order' => $order];
$alerts['alerts_simple'] = agents_get_alerts_simple($idAgent, $filter_alert, $options_simple, $whereAlertSimple, false, false, false, false, $strict_user, $tag_filter);
$countAlertsSimple = agents_get_alerts_simple($idAgent, $filter_alert, false, $whereAlertSimple, false, false, false, true, $strict_user, $tag_filter);
// Urls to sort the table.
$url_up_module = $url.'&sort_field=module&sort=up';
$url_down_module = $url.'&sort_field=module&sort=down';
$url_up_template = $url.'&sort_field=template&sort=up';
$url_down_template = $url.'&sort_field=template&sort=down';
$url_up_lastfired = $url.'&sort_field=last_fired&sort=up';
$url_down_lastfired = $url.'&sort_field=last_fired&sort=down';
$table = new stdClass();
$table->width = '100%';
$table->class = 'info_table';
$table->cellpadding = '0';
$table->cellspacing = '0';
$table->size = [];
$table->head = [];
$table->align = [];
if ($isFunctionPolicies !== ENTERPRISE_NOT_HOOK) {
$table->size[7] = '5%';
if (check_acl_one_of_groups($config['id_user'], $all_groups, 'LW') || check_acl_one_of_groups($config['id_user'], $all_groups, 'LM')) {
$table->head[8] = __('Validate');
$table->align[8] = 'left';
$table->size[8] = '5%';
}
$table->head[0] = "<span title='".__('Policy')."'>".__('P.').'</span>';
$table->head[1] = "<span title='".__('Standby')."'>".__('S.').'</span>';
if (check_acl_one_of_groups($config['id_user'], $all_groups, 'AW') || check_acl_one_of_groups($config['id_user'], $all_groups, 'LM')) {
$table->head[2] = "<span title='".__('Force execution')."'>".__('F.').'</span>';
}
$table->head[3] = __('Module');
$table->head[4] = __('Template');
$table->head[5] = __('Action');
$table->head[6] = __('Last fired');
$table->head[7] = __('Status');
$table->align[7] = 'center';
$table->head[3] .= ui_get_sorting_arrows($url_up_module, $url_down_module, $selectModuleUp, $selectModuleDown);
$table->head[4] .= ui_get_sorting_arrows($url_up_template, $url_down_template, $selectTemplateUp, $selectTemplateDown);
$table->head[6] .= ui_get_sorting_arrows($url_up_lastfired, $url_down_lastfired, $selectLastFiredUp, $selectLastFiredDown);
} else {
$table->size[6] = '5%';
if (check_acl($config['id_user'], $id_group, 'LW') || check_acl($config['id_user'], $id_group, 'LM')) {
$table->head[7] = __('Validate');
$table->align[7] = 'left';
$table->size[7] = '5%';
}
$table->head[0] = "<span title='".__('Standby')."'>".__('S.').'</span>';
if (check_acl($config['id_user'], $id_group, 'AW') || check_acl($config['id_user'], $id_group, 'LM')) {
$table->head[1] = "<span title='".__('Force execution')."'>".__('F.').'</span>';
}
$table->head[2] = __('Module');
$table->head[3] = __('Template');
$table->head[4] = __('Action');
$table->head[5] = __('Last fired');
$table->head[6] = __('Status');
$table->align[6] = 'center';
$table->head[2] .= ui_get_sorting_arrows($url_up_module, $url_down_module, $selectModuleUp, $selectModuleDown);
$table->head[3] .= ui_get_sorting_arrows($url_up_template, $url_down_template, $selectTemplateUp, $selectTemplateDown);
$table->head[5] .= ui_get_sorting_arrows($url_up_lastfired, $url_down_lastfired, $selectLastFiredUp, $selectLastFiredDown);
}
$table->data = [];
$rowPair = true;
$iterator = 0;
foreach ($alerts['alerts_simple'] as $alert) {
$row = ui_format_alert_row($alert, false, $url, 'font-size: 7pt;');
$table->data[] = $row;
}
if (!empty($table->data)) {
html_print_table($table);
} else {
ui_print_info_message(['no_close' => true, 'message' => __('No alerts found') ]);
}
}
if ($enable_alert) {
if (! check_acl($config['id_user'], 0, 'LW')) {
db_pandora_audit(

View File

@ -138,3 +138,75 @@ function printFormFilterAlert($id_group, $filter, $free_search, $url, $filter_st
echo $data;
}
}
function printFormFilterAlertAgent($agent_view_page, $free_search, $id_agent)
{
$table_filter = new stdClass();
$table_filter->width = '100%';
if ($agent_view_page === true) {
$table_filter->class = 'info_table';
$table_filter->styleTable = 'border-radius: 0;padding: 0;margin: 0;';
$free_search_name = 'free_search_alert';
} else {
$table_filter->class = 'databox filters';
$free_search_name = 'free_search';
}
$table_filter->style = [];
$table_filter->style[0] = 'font-weight: bold';
$table_filter->data = [];
$table_filter->data[0][0] = __('Free text for search (*):').ui_print_help_tip(
__('Filter by module name, template name or action name'),
true
);
$table_filter->data[0][0] .= '<span style="margin-left:10px;">'.html_print_input_text(
$free_search_name,
$free_search,
'',
20,
100,
true
).'</span>';
$table_filter->data[0][1] = '<div class="action-buttons">';
if ($agent_view_page === true) {
$table_filter->data[0][1] .= html_print_button(
__('Search'),
'',
false,
'filter_agent_alerts('.$id_agent.');',
'class="sub search"',
true
);
} else {
$table_filter->data[0][1] .= html_print_submit_button(
__('Search'),
'',
false,
'class="sub search"',
true
);
}
$table_filter->data[0][1] .= '</div>';
if ($agent_view_page === true) {
echo html_print_table($table_filter);
} else {
$sortField = get_parameter('sort_field');
$sort = get_parameter('sort', 'none');
$order = '';
if ($sortField != '' && $sort != '') {
$order = '&sort_field='.$sortField.'&sort='.$sort;
}
echo '<form method="post" action="index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente='.$id_agent.'&tab=alert'.$order.'">';
echo html_print_table($table_filter);
echo '</form>';
}
}

View File

@ -371,11 +371,15 @@ if (empty($id_groups)) {
$alerts = [];
$options_simple = [
'offset' => $offset_simple,
'limit' => $config['block_size'],
'order' => $order,
];
if ($agent_view_page === true) {
$options_simple = ['order' => $order];
} else {
$options_simple = [
'offset' => $offset_simple,
'limit' => $config['block_size'],
'order' => $order,
];
}
$filter_alert = [];
if ($filter_standby == 'standby_on') {
@ -648,29 +652,38 @@ if (!empty($table->data)) {
$class = '';
if ($agent_view_page === true) {
$class = 'w100p no-padding-imp';
printFormFilterAlertAgent($agent_view_page, $free_search, $idAgent);
}
echo '<form class="'.$class.'" method="post" action="'.$url.'">';
ui_pagination(
$countAlertsSimple,
$url,
$offset_simple,
0,
false,
'offset_simple'
);
if ($agent_view_page !== true) {
ui_pagination(
$countAlertsSimple,
$url,
$offset_simple,
0,
false,
'offset_simple'
);
}
echo '<div id="alerts_list" style="width:100%;">';
html_print_table($table);
ui_pagination(
$countAlertsSimple,
$url,
$offset_simple,
0,
false,
'offset_simple',
true,
'pagination-bottom'
);
echo '</div>';
if ($agent_view_page !== true) {
ui_pagination(
$countAlertsSimple,
$url,
$offset_simple,
0,
false,
'offset_simple',
true,
'pagination-bottom'
);
}
if (!is_metaconsole()) {
if (check_acl($config['id_user'], $id_group, 'AW') || check_acl($config['id_user'], $id_group, 'LM')) {
@ -703,6 +716,10 @@ if ($agent_view_page === true) {
'white_table_graph_content no-padding-imp'
);
} else {
if (!$print_agent) {
printFormFilterAlertAgent($agent_view_page, $free_search, $idAgent);
}
// Dump entire content.
echo $html_content;
}
@ -777,4 +794,27 @@ ui_require_jquery_file('cluetip');
}
}).change();
function filter_agent_alerts(){
var free_search_alert = $("input[name='free_search_alert']").val();
$("#alerts_list").empty();
jQuery.ajax ({
data: {
get_agent_alerts_agent_view: 1,
id_agent: '<?php echo $idAgent; ?>',
free_search_alert: free_search_alert,
all_groups: '<?php echo json_encode($all_groups); ?>',
sort_field: '<?php echo $sortField; ?>',
sort: '<?php echo $sort; ?>',
page: 'include/ajax/alert_list.ajax'
},
type: 'POST',
url: "ajax.php",
dataType: 'html',
success: function (data) {
$("#alerts_list").empty();
$("#alerts_list").html(data);
}
});
}
</script>