aboutsummaryrefslogtreecommitdiffstats
path: root/channels/chan_agent.c
diff options
context:
space:
mode:
authormogorman <mogorman@f38db490-d61c-443f-a65b-d21fe96a405b>2006-05-08 11:08:38 +0000
committermogorman <mogorman@f38db490-d61c-443f-a65b-d21fe96a405b>2006-05-08 11:08:38 +0000
commit7fa2d5ed400233b8496040253316d29c61f366c0 (patch)
treeafc49e86f1b66a5a906e429e063a9b6be44280df /channels/chan_agent.c
parent2cb0bcd41699e8bce92c3aa876b9f3098d90f27e (diff)
woohoo asterdevcon first commit, adds feature to
cli for agents, show agents online , patch from bug 7096 git-svn-id: http://svn.digium.com/svn/asterisk/trunk@25441 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'channels/chan_agent.c')
-rw-r--r--channels/chan_agent.c66
1 files changed, 66 insertions, 0 deletions
diff --git a/channels/chan_agent.c b/channels/chan_agent.c
index ae358eeca..585b85f35 100644
--- a/channels/chan_agent.c
+++ b/channels/chan_agent.c
@@ -1631,10 +1631,70 @@ static int agents_show(int fd, int argc, char **argv)
return RESULT_SUCCESS;
}
+
+static int agents_show_online(int fd, int argc, char **argv)
+{
+ struct agent_pvt *p;
+ char username[AST_MAX_BUF];
+ char location[AST_MAX_BUF] = "";
+ char talkingto[AST_MAX_BUF] = "";
+ char moh[AST_MAX_BUF];
+ int count_agents = 0; /* Number of agents configured */
+ int online_agents = 0; /* Number of online agents */
+ int agent_status = 0; /* 0 means offline, 1 means online */
+ if (argc != 3)
+ return RESULT_SHOWUSAGE;
+ AST_LIST_LOCK(&agents);
+ AST_LIST_TRAVERSE(&agents, p, list) {
+ agent_status = 0; /* reset it to offline */
+ ast_mutex_lock(&p->lock);
+ if (!ast_strlen_zero(p->name))
+ snprintf(username, sizeof(username), "(%s) ", p->name);
+ else
+ username[0] = '\0';
+ if (p->chan) {
+ snprintf(location, sizeof(location), "logged in on %s", p->chan->name);
+ if (p->owner && ast_bridged_channel(p->owner)) {
+ snprintf(talkingto, sizeof(talkingto), " talking to %s", ast_bridged_channel(p->owner)->name);
+ } else {
+ strcpy(talkingto, " is idle");
+ }
+ agent_status = 1;
+ online_agents++;
+ } else if (!ast_strlen_zero(p->loginchan)) {
+ snprintf(location, sizeof(location) - 20, "available at '%s'", p->loginchan);
+ talkingto[0] = '\0';
+ agent_status = 1;
+ online_agents++;
+ if (p->acknowledged)
+ strncat(location, " (Confirmed)", sizeof(location) - strlen(location) - 1);
+ }
+ if (!ast_strlen_zero(p->moh))
+ snprintf(moh, sizeof(moh), " (musiconhold is '%s')", p->moh);
+ if (agent_status)
+ ast_cli(fd, "%-12.12s %s%s%s%s\n", p->agent, username, location, talkingto, moh);
+ count_agents++;
+ ast_mutex_unlock(&p->lock);
+ }
+ AST_LIST_UNLOCK(&agents);
+ if ( !count_agents )
+ ast_cli(fd, "No Agents are configured in %s\n",config);
+ else
+ ast_cli(fd, "%d agents online\n",online_agents);
+ ast_cli(fd, "\n");
+ return RESULT_SUCCESS;
+}
+
+
+
static char show_agents_usage[] =
"Usage: show agents\n"
" Provides summary information on agents.\n";
+static char show_agents_online_usage[] =
+"Usage: show agents\n"
+" Provides a list of all online agents.\n";
+
static char agent_logoff_usage[] =
"Usage: agent logoff <channel> [soft]\n"
" Sets an agent as no longer logged in.\n"
@@ -1644,6 +1704,10 @@ static struct ast_cli_entry cli_show_agents = {
{ "show", "agents", NULL }, agents_show,
"Show status of agents", show_agents_usage, NULL };
+static struct ast_cli_entry cli_show_agents_online = {
+ { "show", "agents", "online" }, agents_show_online,
+ "Show all online agents", show_agents_online_usage, NULL };
+
static struct ast_cli_entry cli_agent_logoff = {
{ "agent", "logoff", NULL }, agent_logoff_cmd,
"Sets an agent offline", agent_logoff_usage, complete_agent_logoff_cmd };
@@ -2497,6 +2561,7 @@ static int load_module(void *mod)
ast_manager_register2("AgentCallbackLogin", EVENT_FLAG_AGENT, action_agent_callback_login, "Sets an agent as logged in by callback", mandescr_agent_callback_login);
/* CLI Commands */
ast_cli_register(&cli_show_agents);
+ ast_cli_register(&cli_show_agents_online);
ast_cli_register(&cli_agent_logoff);
/* Dialplan Functions */
ast_custom_function_register(&agent_function);
@@ -2523,6 +2588,7 @@ static int unload_module(void *mod)
ast_custom_function_unregister(&agent_function);
/* Unregister CLI commands */
ast_cli_unregister(&cli_show_agents);
+ ast_cli_unregister(&cli_show_agents_online);
ast_cli_unregister(&cli_agent_logoff);
/* Unregister dialplan applications */
ast_unregister_application(app);