summaryrefslogtreecommitdiff
path: root/res/ari
diff options
context:
space:
mode:
authorScott Emidy <jemidy@digium.com>2015-08-07 11:14:06 -0500
committerScott Emidy <jemidy@digium.com>2015-08-07 11:15:08 -0500
commite9f1bc08cbda7759707c30b8883b266555d0fefc (patch)
tree0a2ff61c1f4b4d8d6ae0c426be73ef66dffc35ae /res/ari
parentcf272003919f04c1aaf3d0e921a0385be1e45e4b (diff)
ARI: Creating log channels
An http request can be sent to create a log channel in Asterisk. The command "curl -v -u user:pass -X POST 'http://localhost:088/ari/asterisk/logging/mylog? configuration=notice,warning'" can be run in the terminal to access the newly implemented functionality for ARI. * Ability to create log channels using ARI ASTERISK-25252 Change-Id: I9a20e5c75716dfbb6b62fd3474faf55be20bd782
Diffstat (limited to 'res/ari')
-rw-r--r--res/ari/ari_model_validators.c22
-rw-r--r--res/ari/ari_model_validators.h2
-rw-r--r--res/ari/resource_asterisk.c27
-rw-r--r--res/ari/resource_asterisk.h26
4 files changed, 65 insertions, 12 deletions
diff --git a/res/ari/ari_model_validators.c b/res/ari/ari_model_validators.c
index 26e9b74b7..74611750e 100644
--- a/res/ari/ari_model_validators.c
+++ b/res/ari/ari_model_validators.c
@@ -366,29 +366,29 @@ int ast_ari_validate_log_channel(struct ast_json *json)
{
int res = 1;
struct ast_json_iter *iter;
+ int has_channel = 0;
int has_configuration = 0;
- int has_name = 0;
int has_status = 0;
int has_type = 0;
for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
- if (strcmp("configuration", ast_json_object_iter_key(iter)) == 0) {
+ if (strcmp("channel", ast_json_object_iter_key(iter)) == 0) {
int prop_is_valid;
- has_configuration = 1;
+ has_channel = 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 configuration failed validation\n");
+ ast_log(LOG_ERROR, "ARI LogChannel field channel failed validation\n");
res = 0;
}
} else
- if (strcmp("name", ast_json_object_iter_key(iter)) == 0) {
+ if (strcmp("configuration", ast_json_object_iter_key(iter)) == 0) {
int prop_is_valid;
- has_name = 1;
+ has_configuration = 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");
+ ast_log(LOG_ERROR, "ARI LogChannel field configuration failed validation\n");
res = 0;
}
} else
@@ -420,13 +420,13 @@ int ast_ari_validate_log_channel(struct ast_json *json)
}
}
- if (!has_configuration) {
- ast_log(LOG_ERROR, "ARI LogChannel missing required field configuration\n");
+ if (!has_channel) {
+ ast_log(LOG_ERROR, "ARI LogChannel missing required field channel\n");
res = 0;
}
- if (!has_name) {
- ast_log(LOG_ERROR, "ARI LogChannel missing required field name\n");
+ if (!has_configuration) {
+ ast_log(LOG_ERROR, "ARI LogChannel missing required field configuration\n");
res = 0;
}
diff --git a/res/ari/ari_model_validators.h b/res/ari/ari_model_validators.h
index b181506d2..1803f57c9 100644
--- a/res/ari/ari_model_validators.h
+++ b/res/ari/ari_model_validators.h
@@ -1302,8 +1302,8 @@ ari_validator ast_ari_validate_application_fn(void);
* - attribute: string (required)
* - value: string (required)
* LogChannel
+ * - channel: string (required)
* - configuration: string (required)
- * - name: string (required)
* - status: string (required)
* - type: string (required)
* Module
diff --git a/res/ari/resource_asterisk.c b/res/ari/resource_asterisk.c
index d2e77f504..070a1aa3d 100644
--- a/res/ari/resource_asterisk.c
+++ b/res/ari/resource_asterisk.c
@@ -628,6 +628,33 @@ void ast_ari_asterisk_reload_module(struct ast_variable *headers,
ast_ari_response_no_content(response);
}
+void ast_ari_asterisk_add_log(struct ast_variable *headers,
+ struct ast_ari_asterisk_add_log_args *args,
+ struct ast_ari_response *response)
+{
+ int res;
+
+ ast_assert(response != NULL);
+
+ res = ast_logger_create_channel(args->log_channel_name, args->configuration);
+
+ if (res == AST_LOGGER_DECLINE) {
+ ast_ari_response_error(response, 400, "Bad Request",
+ "Configuration levels are required");
+ return;
+ } else if (res == AST_LOGGER_FAILURE) {
+ ast_ari_response_error(response, 409, "Conflict",
+ "Log channel already exists");
+ return;
+ } else if (res == AST_LOGGER_ALLOC_ERROR) {
+ ast_ari_response_error(response, 500, "Internal Server Error",
+ "Allocation failed");
+ return;
+ }
+
+ 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)
diff --git a/res/ari/resource_asterisk.h b/res/ari/resource_asterisk.h
index 00f463cee..5f84d0761 100644
--- a/res/ari/resource_asterisk.h
+++ b/res/ari/resource_asterisk.h
@@ -194,6 +194,32 @@ 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_add_log() */
+struct ast_ari_asterisk_add_log_args {
+ /*! The log channel to add */
+ const char *log_channel_name;
+ /*! levels of the log channel */
+ const char *configuration;
+};
+/*!
+ * \brief Body parsing function for /asterisk/logging/{logChannelName}.
+ * \param body The JSON body from which to parse parameters.
+ * \param[out] args The args structure to parse into.
+ * \retval zero on success
+ * \retval non-zero on failure
+ */
+int ast_ari_asterisk_add_log_parse_body(
+ struct ast_json *body,
+ struct ast_ari_asterisk_add_log_args *args);
+
+/*!
+ * \brief Adds a log channel.
+ *
+ * \param headers HTTP headers
+ * \param args Swagger parameters
+ * \param[out] response HTTP response
+ */
+void ast_ari_asterisk_add_log(struct ast_variable *headers, struct ast_ari_asterisk_add_log_args *args, struct ast_ari_response *response);
/*! Argument struct for ast_ari_asterisk_delete_log() */
struct ast_ari_asterisk_delete_log_args {
/*! Log channels name */