From 1ae762634c317fbcbd98a8c34d2474f7d4b654ed Mon Sep 17 00:00:00 2001 From: Benjamin Ford Date: Wed, 29 Jul 2015 14:17:09 -0500 Subject: ARI: Rotate log channels. An http request can be sent to rotate a specified log channel. If the channel does not exist, an error response will be returned. The command "curl -v -u user:pass -X PUT 'http://localhost:8088 /ari/asterisk/logging/logChannelName/rotate'" can be run in the terminal to access this new functionality. * Added the ability to rotate log files through ARI ASTERISK-25252 Change-Id: Iaefa21cbbc1b29effb33004ee3d89c977e76ab01 --- res/ari/ari_model_validators.c | 55 ++++++++++++++++++++++++++++++++++++++++++ res/ari/ari_model_validators.h | 21 ++++++++++++++++ res/ari/resource_asterisk.c | 26 ++++++++++++++++++++ res/ari/resource_asterisk.h | 13 ++++++++++ 4 files changed, 115 insertions(+) (limited to 'res/ari') diff --git a/res/ari/ari_model_validators.c b/res/ari/ari_model_validators.c index 667589601..120daf546 100644 --- a/res/ari/ari_model_validators.c +++ b/res/ari/ari_model_validators.c @@ -362,6 +362,61 @@ ari_validator ast_ari_validate_config_tuple_fn(void) return ast_ari_validate_config_tuple; } +int ast_ari_validate_log_channel(struct ast_json *json) +{ + int res = 1; + struct ast_json_iter *iter; + int has_logging_levels = 0; + int has_name = 0; + + for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) { + if (strcmp("logging_levels", ast_json_object_iter_key(iter)) == 0) { + int prop_is_valid; + has_logging_levels = 1; + prop_is_valid = ast_ari_validate_list( + ast_json_object_iter_value(iter), + ast_ari_validate_string); + if (!prop_is_valid) { + ast_log(LOG_ERROR, "ARI LogChannel field logging_levels failed validation\n"); + res = 0; + } + } else + if (strcmp("name", ast_json_object_iter_key(iter)) == 0) { + int prop_is_valid; + has_name = 1; + prop_is_valid = ast_ari_validate_string( + ast_json_object_iter_value(iter)); + if (!prop_is_valid) { + ast_log(LOG_ERROR, "ARI LogChannel field name failed validation\n"); + res = 0; + } + } else + { + ast_log(LOG_ERROR, + "ARI LogChannel has undocumented field %s\n", + ast_json_object_iter_key(iter)); + res = 0; + } + } + + if (!has_logging_levels) { + ast_log(LOG_ERROR, "ARI LogChannel missing required field logging_levels\n"); + res = 0; + } + + if (!has_name) { + ast_log(LOG_ERROR, "ARI LogChannel missing required field name\n"); + res = 0; + } + + return res; +} + +ari_validator ast_ari_validate_log_channel_fn(void) +{ + return ast_ari_validate_log_channel; +} + int ast_ari_validate_module(struct ast_json *json) { int res = 1; diff --git a/res/ari/ari_model_validators.h b/res/ari/ari_model_validators.h index e122ded34..fa393448d 100644 --- a/res/ari/ari_model_validators.h +++ b/res/ari/ari_model_validators.h @@ -224,6 +224,24 @@ int ast_ari_validate_config_tuple(struct ast_json *json); */ ari_validator ast_ari_validate_config_tuple_fn(void); +/*! + * \brief Validator for LogChannel. + * + * Details of an Asterisk log channel + * + * \param json JSON object to validate. + * \returns True (non-zero) if valid. + * \returns False (zero) if invalid. + */ +int ast_ari_validate_log_channel(struct ast_json *json); + +/*! + * \brief Function pointer to ast_ari_validate_log_channel(). + * + * See \ref ast_ari_model_validators.h for more details. + */ +ari_validator ast_ari_validate_log_channel_fn(void); + /*! * \brief Validator for Module. * @@ -1283,6 +1301,9 @@ ari_validator ast_ari_validate_application_fn(void); * ConfigTuple * - attribute: string (required) * - value: string (required) + * LogChannel + * - logging_levels: List[string] (required) + * - name: string (required) * Module * - description: string (required) * - name: string (required) diff --git a/res/ari/resource_asterisk.c b/res/ari/resource_asterisk.c index 2b6b6bc6e..e227951e2 100644 --- a/res/ari/resource_asterisk.c +++ b/res/ari/resource_asterisk.c @@ -33,6 +33,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") #include "asterisk/ast_version.h" #include "asterisk/buildinfo.h" +#include "asterisk/logger.h" #include "asterisk/module.h" #include "asterisk/paths.h" #include "asterisk/pbx.h" @@ -627,6 +628,31 @@ void ast_ari_asterisk_reload_module(struct ast_variable *headers, ast_ari_response_no_content(response); } +void ast_ari_asterisk_rotate_log(struct ast_variable *headers, + struct ast_ari_asterisk_rotate_log_args *args, + struct ast_ari_response *response) +{ + int success; + + ast_assert(response != NULL); + + success = ast_logger_rotate_channel(args->log_channel_name); + + if (success == 0) { + ast_ari_response_error( + response, 404, "Not Found", + "Log channel does not exist"); + return; + } else if (success == -1) { + ast_ari_response_error( + response, 500, "Internal Server Error", + "Allocation failed"); + return; + } + + ast_ari_response_no_content(response); +} + void ast_ari_asterisk_get_global_var(struct ast_variable *headers, struct ast_ari_asterisk_get_global_var_args *args, struct ast_ari_response *response) diff --git a/res/ari/resource_asterisk.h b/res/ari/resource_asterisk.h index 1afc09317..e271b0547 100644 --- a/res/ari/resource_asterisk.h +++ b/res/ari/resource_asterisk.h @@ -194,6 +194,19 @@ struct ast_ari_asterisk_reload_module_args { * \param[out] response HTTP response */ void ast_ari_asterisk_reload_module(struct ast_variable *headers, struct ast_ari_asterisk_reload_module_args *args, struct ast_ari_response *response); +/*! Argument struct for ast_ari_asterisk_rotate_log() */ +struct ast_ari_asterisk_rotate_log_args { + /*! Log channel's name */ + const char *log_channel_name; +}; +/*! + * \brief Rotates a log channel. + * + * \param headers HTTP headers + * \param args Swagger parameters + * \param[out] response HTTP response + */ +void ast_ari_asterisk_rotate_log(struct ast_variable *headers, struct ast_ari_asterisk_rotate_log_args *args, struct ast_ari_response *response); /*! Argument struct for ast_ari_asterisk_get_global_var() */ struct ast_ari_asterisk_get_global_var_args { /*! The variable to get */ -- cgit v1.2.3