ARI: Rotate log channels.
[asterisk/asterisk.git] / res / ari / resource_asterisk.c
index 8006862..115adb3 100644 (file)
@@ -33,6 +33,7 @@ ASTERISK_REGISTER_FILE()
 
 #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)