diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php index 02690b5fd2..8ec920530a 100644 --- a/pandora_console/include/functions_api.php +++ b/pandora_console/include/functions_api.php @@ -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 ; and separator (pass in param + * othermode as othermode=url_encode_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. * diff --git a/pandora_server/util/pandora_manage.pl b/pandora_server/util/pandora_manage.pl index 073b74c924..05547a779f 100644 --- a/pandora_server/util/pandora_manage.pl +++ b/pandora_server/util/pandora_manage.pl @@ -164,6 +164,8 @@ sub help_screen{ help_screen_line('--enable_alerts', '', 'Enable alerts in all groups (system wide)'); help_screen_line('--create_alert_template', " \n\t [ \n\t \n\t \n\t ]", 'Create alert template'); help_screen_line('--delete_alert_template', '', 'Delete alert template'); + help_screen_line('--get_alert_actions', '[ ]', 'get all alert actions'); + help_screen_line('--get_alert_actions_meta', '[ ]', 'get all alert actions in nodes'); help_screen_line('--update_alert_template', " \n\t ", 'Update a field of an alert template'); help_screen_line('--validate_all_alerts', '', 'Validate all the alerts'); help_screen_line('--create_special_day', " ", 'Create special day'); @@ -3080,6 +3082,35 @@ sub cli_delete_alert_template() { 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. # Related option: --add_profile @@ -5974,6 +6005,14 @@ sub pandora_manage_main ($$$) { param_check($ltotal, 1); 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') { param_check($ltotal, 3); cli_alert_template_update();