Merge branch 'ent-2169-REDIRIS-modificacion-de-comandos-en-alertas' into 'develop'
Ent 2169 rediris modificacion de comandos en alertas See merge request artica/pandorafms!1878
This commit is contained in:
commit
5ac947c2fd
|
@ -1,5 +1,7 @@
|
|||
START TRANSACTION;
|
||||
|
||||
ALTER TABLE `talert_commands` ADD COLUMN `id_group` mediumint(8) unsigned NULL default 0;
|
||||
|
||||
ALTER TABLE `tusuario` DROP COLUMN `flash_chart`;
|
||||
|
||||
ALTER TABLE `tusuario` ADD COLUMN `default_custom_view` int(10) unsigned NULL default '0';
|
||||
|
|
|
@ -1159,8 +1159,8 @@ ALTER TABLE talert_actions ADD COLUMN `field15_recovery` TEXT NOT NULL DEFAULT "
|
|||
-- Table `talert_commands`
|
||||
-- ---------------------------------------------------------------------
|
||||
UPDATE `talert_commands` SET `fields_descriptions` = '[\"Integria IMS API path\",\"Integria IMS API pass\",\"Integria IMS user\",\"Integria IMS user pass\",\"Ticket title\",\"Ticket group ID\",\"Ticket priority\",\"Email copy\",\"Ticket owner\",\"Ticket description\"]', `fields_values` = '[\"\",\"\",\"\",\"\",\"\",\"\",\"10,Maintenance;0,Informative;1,Low;2,Medium;3,Serious;4,Very Serious\",\"\",\"\",\"\"]' WHERE `id` = 11 AND `name` = 'Integria IMS Ticket';
|
||||
|
||||
UPDATE `talert_commands` SET `description` = 'This alert send an email using internal Pandora FMS Server SMTP capabilities (defined in each server, using:
_field1_ as destination email address, and
_field2_ as subject for message. 
_field3_ as text of message. 
_field4_ as content type (text/plain or html/text).', `fields_descriptions` = '[\"Destination address\",\"Subject\",\"Text\",\"Content Type\",\"\",\"\",\"\",\"\",\"\",\"\"]', `fields_values` = '[\"\",\"\",\"_html_editor_\",\"_content_type_\",\"\",\"\",\"\",\"\",\"\",\"\"]' WHERE id=1;
|
||||
ALTER TABLE `talert_commands` ADD COLUMN `id_group` mediumint(8) unsigned NULL default 0;
|
||||
|
||||
UPDATE `talert_actions` SET `field4` = 'text/html', `field4_recovery` = 'text/html' WHERE id = 1;
|
||||
|
||||
|
|
|
@ -57,7 +57,7 @@ else {
|
|||
$sec = 'galertas';
|
||||
}
|
||||
|
||||
if ((!$copy_action) && (!$delete_action) && (!$update_action)) {
|
||||
if ((!$copy_action) && (!$delete_action)) {
|
||||
// Header
|
||||
if (defined('METACONSOLE')) {
|
||||
alerts_meta_print_header ();
|
||||
|
@ -141,135 +141,8 @@ if ($copy_action) {
|
|||
__('Could not be copied'));
|
||||
}
|
||||
|
||||
if ($create_action) {
|
||||
$name = (string) get_parameter ('name');
|
||||
$id_alert_command = (int) get_parameter ('id_command');
|
||||
|
||||
$fields_descriptions = array();
|
||||
$fields_values = array();
|
||||
$info_fields = '';
|
||||
$values = array();
|
||||
for($i=1;$i<=$config['max_macro_fields'];$i++) {
|
||||
$values['field'.$i] = (string) get_parameter ('field'.$i.'_value');
|
||||
$info_fields .= ' Field'.$i.': ' . $values['field'.$i];
|
||||
$values['field'.$i.'_recovery'] = (string) get_parameter ('field'.$i.'_recovery_value');
|
||||
$info_fields .= ' Field'.$i.'Recovery: ' . $values['field'.$i.'_recovery'];
|
||||
}
|
||||
|
||||
$values['id_group'] = (string) get_parameter ('group');
|
||||
$values['action_threshold'] = (int) get_parameter ('action_threshold');
|
||||
|
||||
$name_check = db_get_value ('name', 'talert_actions', 'name', $name);
|
||||
|
||||
if ($name_check) {
|
||||
$result = '';
|
||||
}
|
||||
else {
|
||||
$result = alerts_create_alert_action ($name, $id_alert_command,
|
||||
$values);
|
||||
|
||||
$info = '{"Name":"'.$name.'", "ID alert Command":"'.$id_alert_command.'", "Field information":"'.$info_fields.'", "Group":"'.$values['id_group'].'",
|
||||
"Action threshold":"'.$values['action_threshold'].'"}';
|
||||
}
|
||||
|
||||
if ($result) {
|
||||
db_pandora_audit("Command management", "Create alert action #" . $result, false, false, $info);
|
||||
}
|
||||
else {
|
||||
db_pandora_audit("Command management", "Fail try to create alert action", false, false);
|
||||
}
|
||||
|
||||
|
||||
/* Show errors */
|
||||
if (!isset($messageAction)) {
|
||||
$messageAction = __('Could not be created');
|
||||
}
|
||||
|
||||
if ($name == "") {
|
||||
$messageAction = __('No name specified');
|
||||
}
|
||||
|
||||
if ($id_alert_command == "") {
|
||||
$messageAction = __('No command specified');
|
||||
}
|
||||
|
||||
$messageAction = ui_print_result_message ($result,
|
||||
__('Successfully created'),
|
||||
$messageAction);
|
||||
}
|
||||
|
||||
if ($update_action) {
|
||||
$id = (string) get_parameter ('id');
|
||||
|
||||
$al_action = alerts_get_alert_action ($id);
|
||||
|
||||
if ($al_action !== false) {
|
||||
if ($al_action['id_group'] == 0) {
|
||||
if (! check_acl ($config['id_user'], 0, "PM")) {
|
||||
db_pandora_audit("ACL Violation",
|
||||
"Trying to access Alert Management");
|
||||
require ("general/noaccess.php");
|
||||
exit;
|
||||
}
|
||||
else {
|
||||
// Header
|
||||
if (defined('METACONSOLE')) {
|
||||
alerts_meta_print_header ();
|
||||
}
|
||||
else {
|
||||
ui_print_page_header (__('Alerts').' » '.__('Alert actions'), "images/gm_alerts.png", false, "alerts_config", true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Header
|
||||
if (defined('METACONSOLE')) {
|
||||
alerts_meta_print_header ();
|
||||
}
|
||||
else {
|
||||
ui_print_page_header (__('Alerts').' » '.__('Alert actions'), "images/gm_alerts.png", false, "alerts_config", true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$name = (string) get_parameter ('name');
|
||||
$id_alert_command = (int) get_parameter ('id_command');
|
||||
$group = get_parameter ('group');
|
||||
$action_threshold = (int) get_parameter ('action_threshold');
|
||||
|
||||
$info_fields = '';
|
||||
$values = array();
|
||||
|
||||
for ($i = 1; $i <= $config['max_macro_fields']; $i++) {
|
||||
$values['field'.$i] = (string) get_parameter ('field'.$i.'_value');
|
||||
$info_fields .= ' Field1: ' . $values['field'.$i];
|
||||
$values['field'.$i.'_recovery'] = (string) get_parameter ('field'.$i.'_recovery_value');
|
||||
$info_fields .= ' Field'.$i.'Recovery: ' . $values['field'.$i.'_recovery'];
|
||||
}
|
||||
|
||||
$values['name'] = $name;
|
||||
$values['id_alert_command'] = $id_alert_command;
|
||||
$values['id_group'] = $group;
|
||||
$values['action_threshold'] = $action_threshold;
|
||||
|
||||
if (!$name) {
|
||||
$result = '';
|
||||
}
|
||||
else {
|
||||
$result = alerts_update_alert_action ($id, $values);
|
||||
}
|
||||
|
||||
if ($result) {
|
||||
db_pandora_audit("Command management", "Update alert action #" . $id, false, false, json_encode($values));
|
||||
}
|
||||
else {
|
||||
db_pandora_audit("Command management", "Fail try to update alert action #" . $id, false, false, json_encode($values));
|
||||
}
|
||||
|
||||
ui_print_result_message ($result,
|
||||
__('Successfully updated'),
|
||||
__('Could not be updated'));
|
||||
if ($update_action || $create_action) {
|
||||
alerts_ui_update_or_create_actions($update_action);
|
||||
}
|
||||
|
||||
if ($delete_action) {
|
||||
|
@ -363,9 +236,13 @@ $table->align[3] = 'left';
|
|||
|
||||
$filter = array();
|
||||
if (!is_user_admin($config['id_user']))
|
||||
$filter['id_group'] = array_keys(users_get_groups(false, "LM"));
|
||||
$filter['talert_actions.id_group'] = array_keys(users_get_groups(false, "LM"));
|
||||
|
||||
$actions = db_get_all_rows_filter ('talert_actions', $filter);
|
||||
$actions = db_get_all_rows_filter (
|
||||
'talert_actions INNER JOIN talert_commands ON talert_actions.id_alert_command = talert_commands.id',
|
||||
$filter,
|
||||
'talert_actions.* , talert_commands.id_group AS command_group'
|
||||
);
|
||||
if ($actions === false)
|
||||
$actions = array ();
|
||||
|
||||
|
@ -380,11 +257,19 @@ foreach ($actions as $action) {
|
|||
$iterator++;
|
||||
|
||||
$data = array ();
|
||||
|
||||
|
||||
$data[0] = '<a href="index.php?sec='.$sec.'&sec2=godmode/alerts/configure_alert_action&id='.$action['id'].'&pure='.$pure.'">'.
|
||||
$action['name'].'</a>';
|
||||
$data[1] = ui_print_group_icon ($action["id_group"], true) .' ';
|
||||
|
||||
if (!alerts_validate_command_to_action($action["id_group"], $action["command_group"])) {
|
||||
$data[1].= html_print_image(
|
||||
"images/error.png",
|
||||
true,
|
||||
// FIXME: Translation.
|
||||
array("title" => __("The action and the command associated with it do not have the same group. Please contact an administrator to fix it.")
|
||||
));
|
||||
}
|
||||
|
||||
if (check_acl($config['id_user'], $action["id_group"], "LM")) {
|
||||
$data[2] = '<a href="index.php?sec='.$sec.'&sec2=godmode/alerts/alert_actions&copy_action=1&id='.$action['id'].'&pure='.$pure.'"
|
||||
onClick="if (!confirm(\''.__('Are you sure?').'\')) return false;">' .
|
||||
|
@ -393,7 +278,7 @@ foreach ($actions as $action) {
|
|||
onClick="if (!confirm(\''.__('Are you sure?').'\')) return false;">'.
|
||||
html_print_image("images/cross.png", true) . '</a>';
|
||||
}
|
||||
|
||||
|
||||
array_push ($table->data, $data);
|
||||
}
|
||||
if (isset($data)) {
|
||||
|
|
|
@ -38,6 +38,7 @@ $pure = (int)get_parameter('pure', 0);
|
|||
$update_command = (bool) get_parameter ('update_command');
|
||||
$create_command = (bool) get_parameter ('create_command');
|
||||
$delete_command = (bool) get_parameter ('delete_command');
|
||||
$copy_command = (bool) get_parameter ('copy_command');
|
||||
|
||||
if (is_ajax ()) {
|
||||
$get_alert_command = (bool) get_parameter ('get_alert_command');
|
||||
|
@ -57,37 +58,13 @@ if (is_ajax ()) {
|
|||
if (isset($command['description'])) {
|
||||
$command['description'] = io_safe_input(str_replace("\r\n","<br>", io_safe_output($command['description'])));
|
||||
}
|
||||
|
||||
// Get the html rows of the fields form
|
||||
switch ($config["dbtype"]) {
|
||||
case "mysql":
|
||||
case "postgresql":
|
||||
// Descriptions are stored in json
|
||||
$fields_descriptions = empty($command['fields_descriptions']) ?
|
||||
'' : json_decode(io_safe_output($command['fields_descriptions']), true);
|
||||
|
||||
// Fields values are stored in json
|
||||
$fields_values = empty($command['fields_values']) ?
|
||||
'' : io_safe_output(json_decode($command['fields_values'], true));
|
||||
break;
|
||||
case "oracle":
|
||||
// Descriptions are stored in json
|
||||
$description_field = str_replace("\\\"","\"",$command['fields_descriptions']);
|
||||
$description_field = str_replace("\\","",$description_field);
|
||||
|
||||
$fields_descriptions = empty($command['fields_descriptions']) ?
|
||||
'' : json_decode(io_safe_output($description_field), true);
|
||||
|
||||
// Fields values are stored in json
|
||||
$values_fields = str_replace("\\\"","\"",$command['fields_values']);
|
||||
$values_fields = str_replace("\\","",$values_fields);
|
||||
|
||||
$fields_values = empty($command['fields_values']) ?
|
||||
'' : io_safe_output(json_decode($values_fields, true));
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
// Descriptions are stored in json
|
||||
$fields_descriptions = empty($command['fields_descriptions']) ?
|
||||
'' : json_decode(io_safe_output($command['fields_descriptions']), true);
|
||||
// Fields values are stored in json
|
||||
$fields_values = empty($command['fields_values']) ?
|
||||
'' : io_safe_output(json_decode($command['fields_values'], true));
|
||||
|
||||
$fields_rows = array();
|
||||
for ($i = 1; $i <= $config['max_macro_fields']; $i++) {
|
||||
|
||||
|
@ -266,13 +243,11 @@ if (defined('METACONSOLE'))
|
|||
else
|
||||
ui_print_page_header (__('Alerts').' » '.__('Alert commands'), "images/gm_alerts.png", false, "alerts_config", true);
|
||||
|
||||
|
||||
|
||||
|
||||
if ($create_command) {
|
||||
$name = (string) get_parameter ('name');
|
||||
$command = (string) get_parameter ('command');
|
||||
$description = (string) get_parameter ('description');
|
||||
$id_group = (string) get_parameter ('id_group', 0);
|
||||
|
||||
$fields_descriptions = array();
|
||||
$fields_values = array();
|
||||
|
@ -287,7 +262,8 @@ if ($create_command) {
|
|||
$values['fields_values'] = io_json_mb_encode($fields_values);
|
||||
$values['fields_descriptions'] = io_json_mb_encode($fields_descriptions);
|
||||
$values['description'] = $description;
|
||||
|
||||
$values['id_group'] = $id_group;
|
||||
|
||||
$name_check = db_get_value ('name', 'talert_commands', 'name', $name);
|
||||
|
||||
if (!$name_check) {
|
||||
|
@ -349,8 +325,27 @@ if ($delete_command) {
|
|||
ui_print_result_message ($result,
|
||||
__('Successfully deleted'),
|
||||
__('Could not be deleted'));
|
||||
|
||||
|
||||
}
|
||||
|
||||
if ($copy_command) {
|
||||
$id = (int) get_parameter ('id');
|
||||
|
||||
// Get the info from the source command
|
||||
$command_to_copy = db_get_row('talert_commands', 'id', $id);
|
||||
if ($command_to_copy === false) {
|
||||
ui_print_error_message(__("Command with id $id does not found."));
|
||||
} else {
|
||||
// Prepare to insert the copy with same values
|
||||
unset ($command_to_copy['id']);
|
||||
$command_to_copy['name'].= __(' (copy)');
|
||||
$result = db_process_sql_insert('talert_commands', $command_to_copy);
|
||||
|
||||
// Print the result
|
||||
ui_print_result_message ($result,
|
||||
__('Successfully copied'),
|
||||
__('Could not be copied')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$table->width = '100%';
|
||||
|
@ -358,45 +353,54 @@ $table->class = 'databox data';
|
|||
|
||||
$table->data = array ();
|
||||
$table->head = array ();
|
||||
$table->head[0] = __('Name');
|
||||
$table->head[1] = __('ID');
|
||||
$table->head[2] = __('Description');
|
||||
$table->head[3] = __('Delete');
|
||||
$table->head['name'] = __('Name');
|
||||
$table->head['id'] = __('ID');
|
||||
$table->head['group'] = __('Group');
|
||||
$table->head['description'] = __('Description');
|
||||
$table->head['action'] = __('Actions');
|
||||
$table->style = array ();
|
||||
$table->style[0] = 'font-weight: bold';
|
||||
$table->style['name'] = 'font-weight: bold';
|
||||
$table->size = array ();
|
||||
$table->size[3] = '40px';
|
||||
$table->size['action'] = '40px';
|
||||
$table->align = array ();
|
||||
$table->align[3] = 'left';
|
||||
$table->align['action'] = 'left';
|
||||
|
||||
$commands = db_get_all_rows_in_table ('talert_commands');
|
||||
if ($commands === false)
|
||||
$commands = array ();
|
||||
$commands = db_get_all_rows_filter(
|
||||
'talert_commands',
|
||||
array('id_group' => array_keys(users_get_groups(false, "LM")))
|
||||
);
|
||||
if ($commands === false) $commands = array ();
|
||||
|
||||
foreach ($commands as $command) {
|
||||
$data = array ();
|
||||
|
||||
$data[0] = '<span style="font-size: 7.5pt">';
|
||||
|
||||
$data['name'] = '<span style="font-size: 7.5pt">';
|
||||
if (! $command['internal'])
|
||||
$data[0] .= '<a href="index.php?sec='.$sec.'&sec2=godmode/alerts/configure_alert_command&id='.$command['id'].'&pure='.$pure.'">'.
|
||||
$data['name'] .= '<a href="index.php?sec='.$sec.'&sec2=godmode/alerts/configure_alert_command&id='.$command['id'].'&pure='.$pure.'">'.
|
||||
$command['name'].'</a>';
|
||||
else
|
||||
$data[0] .= $command['name'];
|
||||
$data[0] .= '</span>';
|
||||
$data[1] = $command['id'];
|
||||
$data[2] = str_replace("\r\n","<br>",
|
||||
$data['name'] .= $command['name'];
|
||||
$data['name'] .= '</span>';
|
||||
$data['id'] = $command['id'];
|
||||
$data['group'] = ui_print_group_icon ($command["id_group"], true);
|
||||
$data['description'] = str_replace("\r\n","<br>",
|
||||
io_safe_output($command['description']));
|
||||
$data[3] = '';
|
||||
$data['action'] = '';
|
||||
if (! $command['internal']) {
|
||||
$data[3] = '<a href="index.php?sec='.$sec.'&sec2=godmode/alerts/alert_commands&delete_command=1&id='.$command['id'].'&pure='.$pure.'"
|
||||
$data['action'] = '<span style="display: inline-flex">';
|
||||
$data['action'].= '<a href="index.php?sec='.$sec.'&sec2=godmode/alerts/alert_commands&copy_command=1&id='.$command['id'].'&pure='.$pure.'"
|
||||
onClick="if (!confirm(\''.__('Are you sure?').'\')) return false;">'.
|
||||
html_print_image("images/copy.png", true) . '</a>';
|
||||
$data['action'].= '<a href="index.php?sec='.$sec.'&sec2=godmode/alerts/alert_commands&delete_command=1&id='.$command['id'].'&pure='.$pure.'"
|
||||
onClick="if (!confirm(\''.__('Are you sure?').'\')) return false;">'.
|
||||
html_print_image("images/cross.png", true) . '</a>';
|
||||
$data['action'].= '</span>';
|
||||
}
|
||||
|
||||
|
||||
array_push ($table->data, $data);
|
||||
}
|
||||
|
||||
if (isset($data)) {
|
||||
if (count($table->data) > 0) {
|
||||
html_print_table ($table);
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -122,7 +122,6 @@ $table->colspan[0][1] = 2;
|
|||
|
||||
$table->data[1][0] = __('Group');
|
||||
|
||||
$groups = users_get_groups ();
|
||||
$own_info = get_user_info ($config['id_user']);
|
||||
// Only display group "All" if user is administrator or has "PM" privileges
|
||||
if ($own_info['is_admin'] || check_acl ($config['id_user'], 0, "PM"))
|
||||
|
@ -133,9 +132,17 @@ $table->data[1][1] = html_print_select_groups(false, "LW", $display_all_group, '
|
|||
$table->colspan[1][1] = 2;
|
||||
|
||||
$table->data[2][0] = __('Command');
|
||||
$table->data[2][1] = html_print_select_from_sql ('SELECT id, name
|
||||
FROM talert_commands',
|
||||
'id_command', $id_command, '', __('None'), 0, true);
|
||||
$commands_sql = db_get_all_rows_filter(
|
||||
'talert_commands',
|
||||
array('id_group' => array_keys(users_get_groups(false, "LW"))),
|
||||
array('id', 'name'),
|
||||
'AND',
|
||||
false,
|
||||
true
|
||||
);
|
||||
$table->data[2][1] = html_print_select_from_sql ($commands_sql, 'id_command', $id_command,
|
||||
'', __('None'), 0, true
|
||||
);
|
||||
$table->data[2][1] .= ' ';
|
||||
if (check_acl ($config['id_user'], 0, "PM")) {
|
||||
$table->data[2][1] .= html_print_image ('images/add.png', true);
|
||||
|
@ -282,6 +289,19 @@ $(document).ready (function () {
|
|||
|
||||
var max_fields = parseInt('<?php echo $config["max_macro_fields"]; ?>');
|
||||
|
||||
// Change the selected group
|
||||
$("#group option").each(function(index, value) {
|
||||
var current_group = $(value).val();
|
||||
if (data.id_group != 0 && current_group != 0 && current_group != data.id_group) {
|
||||
$(value).hide();
|
||||
} else {
|
||||
$(value).show();
|
||||
}
|
||||
});
|
||||
if (data.id_group != 0 && $("#group").val() != data.id_group) {
|
||||
$("#group").val(0);
|
||||
}
|
||||
|
||||
for (i = 1; i <= max_fields; i++) {
|
||||
var old_value = '';
|
||||
var old_recovery_value = '';
|
||||
|
|
|
@ -54,6 +54,7 @@ if ($update_command) {
|
|||
$name = (string) get_parameter ('name');
|
||||
$command = (string) get_parameter ('command');
|
||||
$description = (string) get_parameter ('description');
|
||||
$id_group = (string) get_parameter ('id_group', 0);
|
||||
|
||||
$fields_descriptions = array();
|
||||
$fields_values = array();
|
||||
|
@ -71,7 +72,8 @@ if ($update_command) {
|
|||
$values['name'] = $name;
|
||||
$values['command'] = $command;
|
||||
$values['description'] = $description;
|
||||
|
||||
$values['id_group'] = $id_group;
|
||||
|
||||
//Check it the new name is used in the other command.
|
||||
$id_check = db_get_value ('id', 'talert_commands', 'name', $name);
|
||||
if (($id_check != $id) && (!empty($id_check))) {
|
||||
|
@ -100,12 +102,13 @@ $command = '';
|
|||
$description = '';
|
||||
$fields_descriptions = '';
|
||||
$fields_values = '';
|
||||
$id_group = 0;
|
||||
if ($id) {
|
||||
$alert = alerts_get_alert_command ($id);
|
||||
$name = $alert['name'];
|
||||
$command = $alert['command'];
|
||||
$description = $alert['description'];
|
||||
|
||||
$id_group = $alert['id_group'];
|
||||
$fields_descriptions = $alert['fields_descriptions'];
|
||||
$fields_values = $alert['fields_values'];
|
||||
}
|
||||
|
@ -123,13 +126,7 @@ $table->width = '100%';
|
|||
$table->class = 'databox filters';
|
||||
|
||||
if (defined('METACONSOLE')) {
|
||||
if ($id) {
|
||||
$table->head[0] = __('Update Command');
|
||||
}
|
||||
else {
|
||||
$table->head[0] = __('Create Command');
|
||||
}
|
||||
|
||||
$table->head[0] = ($id) ? __('Update Command') : __('Create Command');
|
||||
$table->head_colspan[0] = 4;
|
||||
$table->headstyle[0] = 'text-align: center';
|
||||
}
|
||||
|
@ -142,18 +139,25 @@ $table->size = array ();
|
|||
$table->size[0] = '20%';
|
||||
$table->data = array ();
|
||||
|
||||
$table->colspan[0][1] = 3;
|
||||
$table->data[0][0] = __('Name');
|
||||
$table->data[0][2] = html_print_input_text ('name', $name, '', 35, 255, true);
|
||||
$table->colspan['name'][1] = 3;
|
||||
$table->data['name'][0] = __('Name');
|
||||
$table->data['name'][2] = html_print_input_text ('name', $name, '', 35, 255, true);
|
||||
|
||||
$table->colspan[1][1] = 3;
|
||||
$table->data[1][0] = __('Command');
|
||||
$table->data[1][0] .= ui_print_help_icon ('alert_macros', true);
|
||||
$table->data[1][1] = html_print_textarea ('command', 8, 30, $command, '', true);
|
||||
$table->colspan['command'][1] = 3;
|
||||
$table->data['command'][0] = __('Command');
|
||||
$table->data['command'][0] .= ui_print_help_icon ('alert_macros', true);
|
||||
$table->data['command'][1] = html_print_textarea ('command', 8, 30, $command, '', true);
|
||||
|
||||
$table->colspan['group'][1] = 3;
|
||||
$table->data['group'][0] = __('Group');
|
||||
$table->data['group'][1] = html_print_select_groups(false, "LM",
|
||||
true, 'id_group', $id_group, false,
|
||||
'', 0, true);
|
||||
|
||||
$table->colspan['description'][1] = 3;
|
||||
$table->data['description'][0] = __('Description');
|
||||
$table->data['description'][1] = html_print_textarea ('description', 10, 30, $description, '', true);
|
||||
|
||||
$table->colspan[2][1] = 3;
|
||||
$table->data[2][0] = __('Description');
|
||||
$table->data[2][1] = html_print_textarea ('description', 10, 30, $description, '', true);
|
||||
|
||||
for ($i = 1; $i <= $config['max_macro_fields']; $i++) {
|
||||
|
||||
|
|
|
@ -2268,5 +2268,121 @@ function alerts_normalize_actions_escalation($escalation) {
|
|||
|
||||
return $escalation;
|
||||
}
|
||||
/**
|
||||
* Check if a command can be added to an action.
|
||||
*
|
||||
* @param int Action group id
|
||||
* @param int Command group id
|
||||
*
|
||||
* @return False if command group and alert group are distint of 0 and they are not equal
|
||||
*/
|
||||
function alerts_validate_command_to_action($action_group, $command_group) {
|
||||
// If action group or command group is All, all commands can be applicated.
|
||||
if ($action_group == 0 || $command_group == 0) return true;
|
||||
return $action_group == $command_group;
|
||||
}
|
||||
|
||||
/**
|
||||
* Print the UI update actions
|
||||
*
|
||||
* @param bool Update or create
|
||||
*/
|
||||
function alerts_ui_update_or_create_actions($update = true) {
|
||||
global $config;
|
||||
$id = (string) get_parameter ('id');
|
||||
|
||||
// Check ACL of existing aler action
|
||||
if($update) {
|
||||
$al_action = alerts_get_alert_action ($id);
|
||||
if ($al_action !== false) {
|
||||
if ($al_action['id_group'] == 0) {
|
||||
if (! check_acl ($config['id_user'], 0, "PM")) {
|
||||
db_pandora_audit("ACL Violation",
|
||||
"Trying to access Alert Management");
|
||||
require ("general/noaccess.php");
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$name = (string) get_parameter ('name');
|
||||
$id_alert_command = (int) get_parameter ('id_command');
|
||||
$group = get_parameter ('group');
|
||||
$action_threshold = (int) get_parameter ('action_threshold');
|
||||
|
||||
// Validate some values
|
||||
if (!$id_alert_command) {
|
||||
ui_print_error_message(__('No command specified'));
|
||||
return;
|
||||
}
|
||||
if (!$name) {
|
||||
ui_print_error_message(__('No name specified'));
|
||||
return;
|
||||
}
|
||||
$comamnd_group = db_get_value('id_group', 'talert_commands', 'id', $id_alert_command);
|
||||
if(!alerts_validate_command_to_action($group, $comamnd_group)) {
|
||||
ui_print_error_message(__("Alert and command group does not match"));
|
||||
return;
|
||||
}
|
||||
|
||||
// Fill fields info
|
||||
$info_fields = '';
|
||||
$values = array();
|
||||
for ($i = 1; $i <= $config['max_macro_fields']; $i++) {
|
||||
$values['field'.$i] = (string) get_parameter ('field'.$i.'_value');
|
||||
$info_fields .= ' Field'.$i.': ' . $values['field'.$i];
|
||||
$values['field'.$i.'_recovery'] = (string) get_parameter ('field'.$i.'_recovery_value');
|
||||
$info_fields .= ' Field'.$i.'Recovery: ' . $values['field'.$i.'_recovery'];
|
||||
}
|
||||
|
||||
$values['id_group'] = $group;
|
||||
$values['action_threshold'] = $action_threshold;
|
||||
if ($update) {
|
||||
$values['name'] = $name;
|
||||
$values['id_alert_command'] = $id_alert_command;
|
||||
$result = (!$name) ? '' : alerts_update_alert_action ($id, $values);
|
||||
} else {
|
||||
$name_check = db_get_value ('name', 'talert_actions', 'name', $name);
|
||||
if ($name_check) {
|
||||
$result = '';
|
||||
}
|
||||
else {
|
||||
$result = alerts_create_alert_action ($name, $id_alert_command,
|
||||
$values);
|
||||
$values = array(
|
||||
"Name" => $name,
|
||||
"ID alert Command" => $id_alert_command,
|
||||
"Field information" => $info_fields,
|
||||
"Group" => $values['id_group'],
|
||||
"Action threshold" => $values['action_threshold']
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if ($result) {
|
||||
db_pandora_audit(
|
||||
"Command management",
|
||||
$update ? "Update alert action #" . $id : "Create alert action #" . $result,
|
||||
false,
|
||||
false,
|
||||
json_encode($values)
|
||||
);
|
||||
}
|
||||
else {
|
||||
db_pandora_audit(
|
||||
"Command management",
|
||||
$update ? "Fail try to update alert action #" . $id : "Fail try to create alert action",
|
||||
false,
|
||||
false,
|
||||
$update ? json_encode($values) : ''
|
||||
);
|
||||
}
|
||||
|
||||
ui_print_result_message ($result,
|
||||
$update ? __('Successfully updated') : __('Successfully created'),
|
||||
$update ? __('Could not be updated') : __('Could not be created')
|
||||
);
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -369,6 +369,7 @@ CREATE TABLE IF NOT EXISTS `talert_commands` (
|
|||
`id` int(10) unsigned NOT NULL auto_increment,
|
||||
`name` varchar(100) NOT NULL default '',
|
||||
`command` text,
|
||||
`id_group` mediumint(8) unsigned NULL default 0,
|
||||
`description` text,
|
||||
`internal` tinyint(1) default 0,
|
||||
`fields_descriptions` TEXT,
|
||||
|
|
Loading…
Reference in New Issue