mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-04-08 18:55:09 +02:00
#9478 creation alerts to nodes on metaconsole
This commit is contained in:
parent
8f227233fd
commit
a385ff93a3
@ -281,6 +281,19 @@ if ($delete_alert) {
|
||||
}
|
||||
|
||||
if ($add_action) {
|
||||
if (is_metaconsole()) {
|
||||
if (enterprise_include_once('include/functions_metaconsole.php') !== ENTERPRISE_NOT_HOOK) {
|
||||
$server_name = explode(' ', io_safe_output(get_parameter('id_agent')))[0];
|
||||
$connection = metaconsole_get_connection($server_name);
|
||||
if (metaconsole_load_external_db($connection) !== NOERR) {
|
||||
echo json_encode(false);
|
||||
// Restore db connection.
|
||||
metaconsole_restore_db();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$id_action = (int) get_parameter('action_select');
|
||||
$id_alert_module = (int) get_parameter('id_alert_module');
|
||||
$fires_min = (int) get_parameter('fires_min');
|
||||
@ -317,6 +330,12 @@ if ($add_action) {
|
||||
'',
|
||||
true
|
||||
);
|
||||
|
||||
if (is_metaconsole()) {
|
||||
// Restore db connection.
|
||||
metaconsole_restore_db();
|
||||
echo '<script>window.location.assign("index.php?sec=estado&sec2=operation/agentes/alerts_status")</script>';
|
||||
}
|
||||
}
|
||||
|
||||
if ($update_action) {
|
||||
@ -421,6 +440,7 @@ if ($delete_action) {
|
||||
if (is_metaconsole()) {
|
||||
// Restore db connection.
|
||||
metaconsole_restore_db();
|
||||
echo '<script>window.location.assign("index.php?sec=estado&sec2=operation/agentes/alerts_status")</script>';
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -571,6 +571,11 @@ if ($show_update_action_menu) {
|
||||
);
|
||||
$data .= '</td>';
|
||||
$data .= '</tr>';
|
||||
|
||||
if (isset($action_option['module_action_threshold']) === false) {
|
||||
$action_option['module_action_threshold'] = '300';
|
||||
}
|
||||
|
||||
$data .= '<tr class="datos2">';
|
||||
$data .= '<td class="datos2 bolder pdd_6px font_10pt">';
|
||||
$data .= __('Threshold').ui_print_help_tip(__('If a value of 0 is assigned, the Threshold of the action will be used.'), true);
|
||||
@ -591,7 +596,7 @@ if ($show_update_action_menu) {
|
||||
false,
|
||||
'',
|
||||
false,
|
||||
true
|
||||
false
|
||||
);
|
||||
$data .= '</td>';
|
||||
$data .= '</tr>';
|
||||
|
@ -1562,13 +1562,13 @@ function alerts_delete_alert_agent_module_action($id_alert_agent_module_action)
|
||||
*
|
||||
* @return mixed Actions associated or false if something goes wrong.
|
||||
*/
|
||||
function alerts_get_alert_agent_module_actions($id_alert_agent_module, $fields=false, $server_id=-1)
|
||||
function alerts_get_alert_agent_module_actions($id_alert_agent_module, $fields=false, $server_id=-1, $ignore_metaconsole=false)
|
||||
{
|
||||
if (empty($id_alert_agent_module)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (defined('METACONSOLE')) {
|
||||
if (defined('METACONSOLE') && $ignore_metaconsole === false) {
|
||||
$server = db_get_row('tmetaconsole_setup', 'id', $server_id);
|
||||
|
||||
if (metaconsole_connect($server) == NOERR) {
|
||||
@ -1602,6 +1602,7 @@ function alerts_get_alert_agent_module_actions($id_alert_agent_module, $fields=f
|
||||
$action['fires_min'] = $element['fires_min'];
|
||||
$action['fires_max'] = $element['fires_max'];
|
||||
$action['module_action_threshold'] = $element['module_action_threshold'];
|
||||
$action['original_id'] = $element['id'];
|
||||
|
||||
if (isset($element['id'])) {
|
||||
$retval[$element['id']] = $action;
|
||||
|
@ -1418,7 +1418,8 @@ function ui_format_alert_row(
|
||||
);
|
||||
}
|
||||
|
||||
$data[$index['module_name']] = ui_print_truncate_text(isset($alert['agent_module_name']) ? $alert['agent_module_name'] : modules_get_agentmodule_name($alert['id_agent_module']), 'module_small', false, true, true, '[…]', '');
|
||||
$alert_module_name = isset($alert['agent_module_name']) ? $alert['agent_module_name'] : modules_get_agentmodule_name($alert['id_agent_module']);
|
||||
$data[$index['module_name']] = ui_print_truncate_text($alert_module_name, 'module_small', false, true, true, '[…]', '');
|
||||
}
|
||||
|
||||
$data[$index['agent_name']] .= $disabledHtmlEnd;
|
||||
@ -1432,7 +1433,24 @@ function ui_format_alert_row(
|
||||
|
||||
$data[$index['description']] .= $disabledHtmlStart.ui_print_truncate_text(io_safe_output($description), 'description', false, true, true, '[…]', '').$disabledHtmlEnd;
|
||||
|
||||
$actions = alerts_get_alert_agent_module_actions($alert['id'], false, $alert['server_data']['id']);
|
||||
if (is_metaconsole()) {
|
||||
if (enterprise_include_once('include/functions_metaconsole.php') !== ENTERPRISE_NOT_HOOK) {
|
||||
$connection = metaconsole_get_connection($agente['server_name']);
|
||||
if (metaconsole_load_external_db($connection) !== NOERR) {
|
||||
echo json_encode(false);
|
||||
// Restore db connection.
|
||||
metaconsole_restore_db();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$actions = alerts_get_alert_agent_module_actions($alert['id'], false, -1, true);
|
||||
|
||||
if (is_metaconsole()) {
|
||||
// Restore db connection.
|
||||
metaconsole_restore_db();
|
||||
}
|
||||
|
||||
if (empty($actions) === false || $actionDefault != '') {
|
||||
$actionText = '<div><ul class="action_list">';
|
||||
@ -1442,12 +1460,50 @@ function ui_format_alert_row(
|
||||
$actionText .= ' ('.$action['fires_min'].' / '.$action['fires_max'].')';
|
||||
}
|
||||
|
||||
$actionText .= ui_print_help_tip(__('The default actions will be executed every time that the alert is fired and no other action is executed'), true);
|
||||
// Is possible manage actions if have LW permissions in the agent group of the alert module.
|
||||
if (check_acl($config['id_user'], $id_group, 'LW') || check_acl($config['id_user'], $id_group, 'LM')) {
|
||||
$actionText .= '<form method="post" action="index.php?sec=galertas&sec2=godmode/alerts/alert_list" class="delete_link display_in">';
|
||||
$actionText .= html_print_input_image(
|
||||
'delete',
|
||||
'images/delete.svg',
|
||||
1,
|
||||
'padding:0px; margin-left:5px; margin-right:5px; width: 22px;',
|
||||
true,
|
||||
[
|
||||
'title' => __('Delete action'),
|
||||
'class' => 'main_menu_icon invert_filter',
|
||||
]
|
||||
);
|
||||
|
||||
$actionText .= html_print_input_hidden('id_agent', $agente['alias'], true);
|
||||
$actionText .= html_print_input_hidden('delete_action', 1, true);
|
||||
$actionText .= html_print_input_hidden('id_alert', $alert['id'], true);
|
||||
$actionText .= html_print_input_hidden('id_action', $action['original_id'], true);
|
||||
$actionText .= '</form>';
|
||||
$actionText .= html_print_input_image(
|
||||
'update_action',
|
||||
'/images/edit.svg',
|
||||
1,
|
||||
'padding:0px;',
|
||||
true,
|
||||
[
|
||||
'title' => __('Update action'),
|
||||
'class' => 'main_menu_icon invert_filter',
|
||||
'onclick' => 'show_display_update_action(\''.$action['original_id'].'\',\''.$alert['id'].'\',\''.$alert['id_agent_module'].'\',\''.$action['original_id'].'\',\''.$alert['agent_name'].'\')',
|
||||
]
|
||||
);
|
||||
$actionText .= html_print_input_hidden('id_agent_module', $alert['id_agent_module'], true);
|
||||
}
|
||||
|
||||
$actionText .= '<div id="update_action-div-'.$alert['id'].'" class="invisible">';
|
||||
$actionText .= '</div>';
|
||||
$actionText .= '</li></span></div>';
|
||||
}
|
||||
|
||||
$actionText .= '</ul></div>';
|
||||
|
||||
if ($actionDefault !== '') {
|
||||
if ($actionDefault !== '' && $actionDefault !== false) {
|
||||
$actionDefault_name = db_get_sql(
|
||||
sprintf(
|
||||
'SELECT name FROM talert_actions WHERE id = %d',
|
||||
@ -1457,6 +1513,8 @@ function ui_format_alert_row(
|
||||
foreach ($actions as $action) {
|
||||
if ($actionDefault_name === $action['name']) {
|
||||
$hide_actionDefault = true;
|
||||
} else {
|
||||
$hide_actionDefault = false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1509,34 +1567,34 @@ function ui_format_alert_row(
|
||||
metaconsole_restore_db();
|
||||
}
|
||||
|
||||
$tableActionButtons[] = '';
|
||||
|
||||
// Edit.
|
||||
if (check_acl($config['id_user'], $id_group, 'LW')
|
||||
|| check_acl($config['id_user'], $id_group, 'LM')
|
||||
) {
|
||||
$tableActionButtons[] = html_print_input_image(
|
||||
'update_action',
|
||||
'/images/edit.svg',
|
||||
1,
|
||||
'padding:0px;',
|
||||
true,
|
||||
[
|
||||
'title' => __('Update action'),
|
||||
'class' => 'main_menu_icon invert_filter',
|
||||
'onclick' => 'show_display_update_action(\''.$action['id'].'\',\''.$alert['id'].'\',\''.$alert['id_agent_module'].'\',\''.$action['id'].'\',\''.$alert['agent_name'].'\')',
|
||||
]
|
||||
);
|
||||
$tableActionButtons[] = html_print_input_hidden('id_agent_module', $alert['id_agent_module'], true);
|
||||
}
|
||||
|
||||
if (check_acl($config['id_user'], $id_group, 'LM')
|
||||
) {
|
||||
$tableActionButtons[] = '<a href="index.php?sec=galertas&sec2=godmode/alerts/alert_list&tab=list&delete_alert=1&id_alert='.$alert['id'].'&id_agent='.$alert['agent_name'].'" onClick="if (!confirm(\' '.__('Are you sure you want to delete alert?').'\')) return false;">'.html_print_image(
|
||||
'images/delete.svg',
|
||||
if (check_acl($config['id_user'], $id_group, 'LM')
|
||||
) {
|
||||
$tableActionButtons[] = '<a href="index.php?sec=galertas&sec2=godmode/alerts/alert_list&tab=list&delete_alert=1&id_alert='.$alert['id'].'&id_agent='.$alert['agent_name'].'" onClick="if (!confirm(\' '.__('Are you sure you want to delete alert?').'\')) return false;">'.html_print_image(
|
||||
'images/delete.svg',
|
||||
true,
|
||||
[
|
||||
'alt' => __('Delete'),
|
||||
'title' => __('Delete'),
|
||||
'class' => 'main_menu_icon invert_filter vertical_baseline',
|
||||
]
|
||||
).'</a>';
|
||||
}
|
||||
|
||||
$tableActionButtons[] = '<a href="javascript:show_add_action(\''.$alert['id'].'\');">'.html_print_image(
|
||||
'images/plus-black.svg',
|
||||
true,
|
||||
[
|
||||
'alt' => __('Delete'),
|
||||
'title' => __('Delete'),
|
||||
'class' => 'main_menu_icon invert_filter vertical_baseline',
|
||||
'title' => __('Add action'),
|
||||
'class' => 'invert_filter main_menu_icon',
|
||||
'style' => 'margin-bottom: 12px;',
|
||||
]
|
||||
).'</a>';
|
||||
}
|
||||
@ -1550,6 +1608,123 @@ function ui_format_alert_row(
|
||||
);
|
||||
}
|
||||
|
||||
// Is possible manage actions if have LW permissions in the agent group of the alert module.
|
||||
if (check_acl_one_of_groups($config['id_user'], $all_groups, 'LW') || check_acl($config['id_user'], $template_group, 'LM')) {
|
||||
if (check_acl($config['id_user'], $template_group, 'LW')) {
|
||||
$own_groups = users_get_groups($config['id_user'], 'LW', true);
|
||||
} else if (check_acl($config['id_user'], $template_group, 'LM')) {
|
||||
$own_groups = users_get_groups($config['id_user'], 'LM', true);
|
||||
}
|
||||
|
||||
$filter_groups = '';
|
||||
$filter_groups = implode(',', array_keys($own_groups));
|
||||
if ($filter_groups != null) {
|
||||
$actions = alerts_get_alert_actions_filter(true, 'id_group IN ('.$filter_groups.')');
|
||||
}
|
||||
|
||||
$data[$index['actions']] .= '<div id="add_action-div-'.$alert['id'].'" class="invisible">';
|
||||
$data[$index['actions']] .= '<form id="add_action_form-'.$alert['id'].'" method="post" style="height:85%;" action="index.php?sec=galertas&sec2=godmode/alerts/alert_list">';
|
||||
$data[$index['actions']] .= '<table class="w100p bg_color222 filter-table-adv">';
|
||||
$data[$index['actions']] .= html_print_input_hidden('add_action', 1, true);
|
||||
$data[$index['actions']] .= html_print_input_hidden('id_agent', $agente['alias'], true);
|
||||
$data[$index['actions']] .= html_print_input_hidden('id_alert_module', $alert['id'], true);
|
||||
|
||||
if (! $id_agente) {
|
||||
$data[$index['actions']] .= '<tr class="datos2">';
|
||||
$data[$index['actions']] .= '<td class="w50p">'.html_print_label_input_block(
|
||||
__('Agent'),
|
||||
ui_print_truncate_text($agente['alias'], 'agent_small', false, true, true, '[…]')
|
||||
).'</td>';
|
||||
$data[$index['actions']] .= '<td class="w50p">'.html_print_label_input_block(
|
||||
__('Module'),
|
||||
ui_print_truncate_text($alert_module_name, 'module_small', false, true, true, '[…]')
|
||||
).'</td>';
|
||||
$data[$index['actions']] .= '</tr>';
|
||||
}
|
||||
|
||||
$data[$index['actions']] .= '<tr class="datos2">';
|
||||
$data[$index['actions']] .= '<td class="w50p">'.html_print_label_input_block(
|
||||
__('Action'),
|
||||
html_print_select(
|
||||
$actions,
|
||||
'action_select',
|
||||
'',
|
||||
'',
|
||||
__('None'),
|
||||
0,
|
||||
true,
|
||||
false,
|
||||
true,
|
||||
'',
|
||||
false,
|
||||
'width:100%'
|
||||
)
|
||||
).'</td>';
|
||||
|
||||
$data[$index['actions']] .= '<td class="w50p">'.html_print_label_input_block(
|
||||
__('Number of alerts match from'),
|
||||
'<div class="inline">'.html_print_input_text(
|
||||
'fires_min',
|
||||
0,
|
||||
'',
|
||||
4,
|
||||
10,
|
||||
true,
|
||||
false,
|
||||
false,
|
||||
'',
|
||||
'w40p'
|
||||
).' '.__('to').' '.html_print_input_text(
|
||||
'fires_max',
|
||||
0,
|
||||
'',
|
||||
4,
|
||||
10,
|
||||
true,
|
||||
false,
|
||||
false,
|
||||
'',
|
||||
'w40p'
|
||||
).'</div>'
|
||||
).'</td>';
|
||||
$data[$index['actions']] .= '</tr>';
|
||||
$data[$index['actions']] .= '<tr class="datos2">';
|
||||
$data[$index['actions']] .= '<td class="w50p">'.html_print_label_input_block(
|
||||
__('Threshold'),
|
||||
html_print_extended_select_for_time(
|
||||
'module_action_threshold',
|
||||
0,
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
true,
|
||||
'',
|
||||
false,
|
||||
false,
|
||||
'',
|
||||
false,
|
||||
true
|
||||
)
|
||||
).'</td>';
|
||||
$data[$index['actions']] .= '</tr>';
|
||||
$data[$index['actions']] .= '</table>';
|
||||
$data[$index['actions']] .= html_print_submit_button(
|
||||
__('Add'),
|
||||
'addbutton',
|
||||
false,
|
||||
[
|
||||
'icon' => 'next',
|
||||
'class' => 'mini float-right',
|
||||
],
|
||||
true
|
||||
);
|
||||
$data[$index['actions']] .= '</form>';
|
||||
$data[$index['actions']] .= '</div>';
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
@ -656,4 +656,21 @@ function show_display_update_action(id_module_action, alert_id, alert_id_agent_m
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
function show_add_action(id_alert) {
|
||||
$("#add_action-div-" + id_alert).hide ()
|
||||
.dialog ({
|
||||
resizable: true,
|
||||
draggable: true,
|
||||
modal: true,
|
||||
width: 700,
|
||||
title: '<?php echo __('Add action'); ?>',
|
||||
modal: true,
|
||||
overlay: {
|
||||
opacity: 0.5,
|
||||
background: "black"
|
||||
}
|
||||
})
|
||||
.show ();
|
||||
}
|
||||
</script>
|
Loading…
x
Reference in New Issue
Block a user