Merge branch '2526_Listar_acciones_de_alerta_desde_la_API' into 'develop'
List alert actions in nodes with CLI and API See merge request artica/pandorafms!2085 Former-commit-id: 9732161ea417a1518e508cb9e2d20438d34ec3b2
This commit is contained in:
commit
042bf1c6e7
|
@ -4563,6 +4563,62 @@ function api_get_alert_template($id_template, $thrash1, $other, $thrash3) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List of alert actions.
|
||||||
|
*
|
||||||
|
* @param array $other it's array, $other as param is <action_name>;<separator_data> and separator (pass in param
|
||||||
|
* othermode as othermode=url_encode_separator_<separator>)
|
||||||
|
* @param $returnType (csv, string or json).
|
||||||
|
*
|
||||||
|
* example:
|
||||||
|
*
|
||||||
|
* api.php?op=get&op2=alert_actions&apipass=1234&user=admin&pass=pandora&other=Create|;&other_mode=url_encode_separator_|&return_type=json
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function api_get_alert_actions($thrash1, $thrash2, $other, $returnType) {
|
||||||
|
global $config;
|
||||||
|
if (!check_acl($config['id_user'], 0, "LM")) {
|
||||||
|
returnError('forbidden', 'string');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isset($other['data'][0]))
|
||||||
|
$other['data'][1] = '';
|
||||||
|
if (!isset($other['data'][1]))
|
||||||
|
$separator = ';'; //by default
|
||||||
|
else
|
||||||
|
$separator = $other['data'][1];
|
||||||
|
|
||||||
|
$action_name = $other['data'][0];
|
||||||
|
|
||||||
|
|
||||||
|
$filter = array();
|
||||||
|
if (!is_user_admin($config['id_user']))
|
||||||
|
$filter['talert_actions.id_group'] = array_keys(users_get_groups(false, "LM"));
|
||||||
|
$filter['talert_actions.name'] = "%$action_name%";
|
||||||
|
|
||||||
|
$actions = db_get_all_rows_filter (
|
||||||
|
'talert_actions INNER JOIN talert_commands ON talert_actions.id_alert_command = talert_commands.id',
|
||||||
|
$filter,
|
||||||
|
'talert_actions.id, talert_actions.name'
|
||||||
|
);
|
||||||
|
if ($actions === false)
|
||||||
|
$actions = array ();
|
||||||
|
|
||||||
|
if ($actions !== false) {
|
||||||
|
$data['type'] = 'array';
|
||||||
|
$data['data'] = $actions;
|
||||||
|
}
|
||||||
|
if (!$actions) {
|
||||||
|
returnError('error_get_alert_actions',
|
||||||
|
__('Error getting alert actions.'));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
returnData($returnType, $data, $separator);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get module groups, and print all the result like a csv.
|
* Get module groups, and print all the result like a csv.
|
||||||
*
|
*
|
||||||
|
|
|
@ -164,6 +164,8 @@ sub help_screen{
|
||||||
help_screen_line('--enable_alerts', '', 'Enable alerts in all groups (system wide)');
|
help_screen_line('--enable_alerts', '', 'Enable alerts in all groups (system wide)');
|
||||||
help_screen_line('--create_alert_template', "<template_name> <condition_type_serialized>\n\t <time_from> <time_to> [<description> <group_name> <field1> <field2> \n\t <field3> <priority> <default_action> <days> <time_threshold> <min_alerts> \n\t <max_alerts> <alert_recovery> <field2_recovery> <field3_recovery> \n\t <condition_type_separator>]", 'Create alert template');
|
help_screen_line('--create_alert_template', "<template_name> <condition_type_serialized>\n\t <time_from> <time_to> [<description> <group_name> <field1> <field2> \n\t <field3> <priority> <default_action> <days> <time_threshold> <min_alerts> \n\t <max_alerts> <alert_recovery> <field2_recovery> <field3_recovery> \n\t <condition_type_separator>]", 'Create alert template');
|
||||||
help_screen_line('--delete_alert_template', '<template_name>', 'Delete alert template');
|
help_screen_line('--delete_alert_template', '<template_name>', 'Delete alert template');
|
||||||
|
help_screen_line('--get_alert_actions', '[<action_name> <separator> <return_type>]', 'get all alert actions');
|
||||||
|
help_screen_line('--get_alert_actions_meta', '[<server_name> <action_name> <separator> <return_type>]', 'get all alert actions in nodes');
|
||||||
help_screen_line('--update_alert_template', "<template_name> <field_to_change> \n\t <new_value>", 'Update a field of an alert template');
|
help_screen_line('--update_alert_template', "<template_name> <field_to_change> \n\t <new_value>", 'Update a field of an alert template');
|
||||||
help_screen_line('--validate_all_alerts', '', 'Validate all the alerts');
|
help_screen_line('--validate_all_alerts', '', 'Validate all the alerts');
|
||||||
help_screen_line('--create_special_day', "<special_day> <same_day> <description> <group>", 'Create special day');
|
help_screen_line('--create_special_day', "<special_day> <same_day> <description> <group>", 'Create special day');
|
||||||
|
@ -3080,6 +3082,35 @@ sub cli_delete_alert_template() {
|
||||||
exist_check($result,'alert template',$template_name);
|
exist_check($result,'alert template',$template_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
##############################################################################
|
||||||
|
# Get alert actions.
|
||||||
|
# Related option: --get_alert_actions
|
||||||
|
##############################################################################
|
||||||
|
|
||||||
|
sub cli_get_alert_actions() {
|
||||||
|
my ($action_name,$separator,$return_type) = @ARGV[2..4];
|
||||||
|
if ($return_type eq '') {
|
||||||
|
$return_type = 'csv';
|
||||||
|
}
|
||||||
|
my $result = api_call(\%conf,'get', 'alert_actions', undef, undef, "$action_name|$separator",$return_type);
|
||||||
|
print "$result \n\n ";
|
||||||
|
}
|
||||||
|
|
||||||
|
##############################################################################
|
||||||
|
# Get alert actions in nodes.
|
||||||
|
# Related option: --get_alert_actions_meta
|
||||||
|
##############################################################################
|
||||||
|
|
||||||
|
sub cli_get_alert_actions_meta() {
|
||||||
|
my ($server_name,$action_name,$separator,$return_type) = @ARGV[2..5];
|
||||||
|
if ($return_type eq '') {
|
||||||
|
$return_type = 'csv';
|
||||||
|
}
|
||||||
|
|
||||||
|
my $result = api_call(\%conf,'get', 'alert_actions_meta', undef, undef, "$server_name|$action_name|$separator",$return_type);
|
||||||
|
print "$result \n\n ";
|
||||||
|
}
|
||||||
|
|
||||||
##############################################################################
|
##############################################################################
|
||||||
# Add profile.
|
# Add profile.
|
||||||
# Related option: --add_profile
|
# Related option: --add_profile
|
||||||
|
@ -5974,6 +6005,14 @@ sub pandora_manage_main ($$$) {
|
||||||
param_check($ltotal, 1);
|
param_check($ltotal, 1);
|
||||||
cli_delete_alert_template();
|
cli_delete_alert_template();
|
||||||
}
|
}
|
||||||
|
elsif ($param eq '--get_alert_actions') {
|
||||||
|
param_check($ltotal, 3, 3);
|
||||||
|
cli_get_alert_actions();
|
||||||
|
}
|
||||||
|
elsif ($param eq '--get_alert_actions_meta') {
|
||||||
|
param_check($ltotal, 4, 4);
|
||||||
|
cli_get_alert_actions_meta();
|
||||||
|
}
|
||||||
elsif ($param eq '--update_alert_template') {
|
elsif ($param eq '--update_alert_template') {
|
||||||
param_check($ltotal, 3);
|
param_check($ltotal, 3);
|
||||||
cli_alert_template_update();
|
cli_alert_template_update();
|
||||||
|
|
Loading…
Reference in New Issue