From 0fc70140a5b0dd20b58ed249214eaf5eca5cd09d Mon Sep 17 00:00:00 2001 From: Tilghman Lesher Date: Fri, 14 Dec 2007 17:29:27 +0000 Subject: Publish the AGI events to manager. Reported by: moy Patch by: moy,tilghman (Closes issue #11337) git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@92999 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- res/res_agi.c | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) (limited to 'res/res_agi.c') diff --git a/res/res_agi.c b/res/res_agi.c index 61bd9f5b7..9747bdb11 100644 --- a/res/res_agi.c +++ b/res/res_agi.c @@ -53,6 +53,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") #include "asterisk/agi.h" #include "asterisk/version.h" #include "asterisk/speech.h" +#include "asterisk/manager.h" #define MAX_ARGS 128 #define AGI_NANDFS_RETRY 3 @@ -2150,7 +2151,15 @@ static int agi_handle_command(struct ast_channel *chan, AGI *agi, char *buf, int char *argv[MAX_ARGS]; int argc = MAX_ARGS, res; agi_command *c; - + const char *ami_res = "Unknown Result"; + char *ami_cmd = ast_strdupa(buf); + int command_id = ast_random(), resultcode = 200; + + manager_event(EVENT_FLAG_CALL, "AGIExec", + "SubEvent: Start\r\n" + "Channel: %s\r\n" + "CommandId: %d\r\n" + "Command: %s\r\n", chan->name, command_id, ami_cmd); parse_args(buf, &argc, argv); if ((c = find_command(argv, 0)) && (!dead || (dead && c->dead))) { /* if this command wasnt registered by res_agi, be sure to usecount @@ -2160,6 +2169,19 @@ static int agi_handle_command(struct ast_channel *chan, AGI *agi, char *buf, int res = c->handler(chan, agi, argc, argv); if (c->mod != ast_module_info->self) ast_module_unref(c->mod); + switch (res) { + case RESULT_SHOWUSAGE: ami_res = "Usage"; resultcode = 520; break; + case AST_PBX_KEEPALIVE: ami_res = "KeepAlive"; resultcode = 210; break; + case RESULT_FAILURE: ami_res = "Failure"; resultcode = -1; break; + case RESULT_SUCCESS: ami_res = "Success"; resultcode = 200; break; + } + manager_event(EVENT_FLAG_CALL, "AGIExec", + "SubEvent: End\r\n" + "Channel: %s\r\n" + "CommandId: %d\r\n" + "Command: %s\r\n" + "ResultCode: %d\r\n" + "Result: %s\r\n", chan->name, command_id, ami_cmd, resultcode, ami_res); switch(res) { case RESULT_SHOWUSAGE: ast_agi_fdprintf(chan, agi->fd, "520-Invalid command syntax. Proper usage follows:\n"); @@ -2177,8 +2199,22 @@ static int agi_handle_command(struct ast_channel *chan, AGI *agi, char *buf, int } } else if ((c = find_command(argv, 0))) { ast_agi_fdprintf(chan, agi->fd, "511 Command Not Permitted on a dead channel\n"); + manager_event(EVENT_FLAG_CALL, "AGIExec", + "SubEvent: End\r\n" + "Channel: %s\r\n" + "CommandId: %d\r\n" + "Command: %s\r\n" + "ResultCode: 511\r\n" + "Result: Command not permitted on a dead channel\r\n", chan->name, command_id, ami_cmd); } else { ast_agi_fdprintf(chan, agi->fd, "510 Invalid or unknown command\n"); + manager_event(EVENT_FLAG_CALL, "AGIExec", + "SubEvent: End\r\n" + "Channel: %s\r\n" + "CommandId: %d\r\n" + "Command: %s\r\n" + "ResultCode: 510\r\n" + "Result: Invalid or unknown command\r\n", chan->name, command_id, ami_cmd); } return 0; } -- cgit v1.2.3