mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-06 12:36:58 +00:00
Merge agent callback login/logoff events and logging (bug #1775)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@3139 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -113,6 +113,7 @@ static struct agent_pvt {
|
|||||||
int abouttograb; /* About to grab */
|
int abouttograb; /* About to grab */
|
||||||
int autologoff; /* Auto timeout time */
|
int autologoff; /* Auto timeout time */
|
||||||
int ackcall; /* ackcall */
|
int ackcall; /* ackcall */
|
||||||
|
time_t loginstart; /* When agent first logged in (0 when logged off) */
|
||||||
time_t start; /* When call started */
|
time_t start; /* When call started */
|
||||||
struct timeval lastdisc; /* When last disconnected */
|
struct timeval lastdisc; /* When last disconnected */
|
||||||
int wrapuptime; /* Wrapup time in ms */
|
int wrapuptime; /* Wrapup time in ms */
|
||||||
@@ -518,7 +519,19 @@ static int agent_hangup(struct ast_channel *ast)
|
|||||||
}
|
}
|
||||||
ast_log(LOG_DEBUG, "Hungup, howlong is %d, autologoff is %d\n", howlong, p->autologoff);
|
ast_log(LOG_DEBUG, "Hungup, howlong is %d, autologoff is %d\n", howlong, p->autologoff);
|
||||||
if (howlong && p->autologoff && (howlong > p->autologoff)) {
|
if (howlong && p->autologoff && (howlong > p->autologoff)) {
|
||||||
|
char agent[AST_MAX_AGENT] = "";
|
||||||
|
long logintime = time(NULL) - p->loginstart;
|
||||||
|
p->loginstart = 0;
|
||||||
ast_log(LOG_NOTICE, "Agent '%s' didn't answer/confirm within %d seconds (waited %d)\n", p->name, p->autologoff, howlong);
|
ast_log(LOG_NOTICE, "Agent '%s' didn't answer/confirm within %d seconds (waited %d)\n", p->name, p->autologoff, howlong);
|
||||||
|
manager_event(EVENT_FLAG_AGENT, "Agentcallbacklogoff",
|
||||||
|
"Agent: %s\r\n"
|
||||||
|
"Loginchan: %s\r\n"
|
||||||
|
"Logintime: %ld\r\n"
|
||||||
|
"Reason: Autologoff\r\n"
|
||||||
|
"Uniqueid: %s\r\n",
|
||||||
|
p->agent, p->loginchan, logintime, ast->uniqueid);
|
||||||
|
snprintf(agent, sizeof(agent), "Agent/%s", p->agent);
|
||||||
|
ast_queue_log("NONE", ast->uniqueid, agent, "AGENTCALLBACKLOGOFF", "%s|%ld|%s", p->loginchan, logintime, "Autologoff");
|
||||||
strcpy(p->loginchan, "");
|
strcpy(p->loginchan, "");
|
||||||
}
|
}
|
||||||
} else if (p->dead) {
|
} else if (p->dead) {
|
||||||
@@ -1120,7 +1133,6 @@ static int __login_exec(struct ast_channel *chan, void *data, int callbackmode)
|
|||||||
struct agent_pvt *p;
|
struct agent_pvt *p;
|
||||||
struct localuser *u;
|
struct localuser *u;
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
time_t start;
|
|
||||||
char user[AST_MAX_AGENT];
|
char user[AST_MAX_AGENT];
|
||||||
char pass[AST_MAX_AGENT];
|
char pass[AST_MAX_AGENT];
|
||||||
char agent[AST_MAX_AGENT] = "";
|
char agent[AST_MAX_AGENT] = "";
|
||||||
@@ -1196,6 +1208,10 @@ static int __login_exec(struct ast_channel *chan, void *data, int callbackmode)
|
|||||||
if (!strcmp(p->agent, user) &&
|
if (!strcmp(p->agent, user) &&
|
||||||
!strcmp(p->password, pass) && !p->pending) {
|
!strcmp(p->password, pass) && !p->pending) {
|
||||||
if (!p->chan) {
|
if (!p->chan) {
|
||||||
|
char last_loginchan[80] = "";
|
||||||
|
long logintime;
|
||||||
|
snprintf(agent, sizeof(agent), "Agent/%s", p->agent);
|
||||||
|
|
||||||
if (callbackmode) {
|
if (callbackmode) {
|
||||||
char tmpchan[AST_MAX_BUF] = "";
|
char tmpchan[AST_MAX_BUF] = "";
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
@@ -1230,8 +1246,10 @@ static int __login_exec(struct ast_channel *chan, void *data, int callbackmode)
|
|||||||
if (!res) {
|
if (!res) {
|
||||||
if (context && !ast_strlen_zero(context) && !ast_strlen_zero(tmpchan))
|
if (context && !ast_strlen_zero(context) && !ast_strlen_zero(tmpchan))
|
||||||
snprintf(p->loginchan, sizeof(p->loginchan), "%s@%s", tmpchan, context);
|
snprintf(p->loginchan, sizeof(p->loginchan), "%s@%s", tmpchan, context);
|
||||||
else
|
else {
|
||||||
|
strncpy(last_loginchan, p->loginchan, sizeof(last_loginchan) - 1);
|
||||||
strncpy(p->loginchan, tmpchan, sizeof(p->loginchan) - 1);
|
strncpy(p->loginchan, tmpchan, sizeof(p->loginchan) - 1);
|
||||||
|
}
|
||||||
if (ast_strlen_zero(p->loginchan))
|
if (ast_strlen_zero(p->loginchan))
|
||||||
filename = "agent-loggedoff";
|
filename = "agent-loggedoff";
|
||||||
p->acknowledged = 0;
|
p->acknowledged = 0;
|
||||||
@@ -1279,6 +1297,30 @@ static int __login_exec(struct ast_channel *chan, void *data, int callbackmode)
|
|||||||
res = -1;
|
res = -1;
|
||||||
if (callbackmode && !res) {
|
if (callbackmode && !res) {
|
||||||
/* Just say goodbye and be done with it */
|
/* Just say goodbye and be done with it */
|
||||||
|
if (!ast_strlen_zero(p->loginchan)) {
|
||||||
|
if (p->loginstart == 0)
|
||||||
|
time(&p->loginstart);
|
||||||
|
manager_event(EVENT_FLAG_AGENT, "Agentcallbacklogin",
|
||||||
|
"Agent: %s\r\n"
|
||||||
|
"Loginchan: %s\r\n"
|
||||||
|
"Uniqueid: %s\r\n",
|
||||||
|
p->agent, p->loginchan, chan->uniqueid);
|
||||||
|
ast_queue_log("NONE", chan->uniqueid, agent, "AGENTCALLBACKLOGIN", "%s", p->loginchan);
|
||||||
|
if (option_verbose > 2)
|
||||||
|
ast_verbose(VERBOSE_PREFIX_3 "Callback Agent '%s' logged in on %s\n", p->agent, p->loginchan);
|
||||||
|
} else {
|
||||||
|
logintime = time(NULL) - p->loginstart;
|
||||||
|
p->loginstart = 0;
|
||||||
|
manager_event(EVENT_FLAG_AGENT, "Agentcallbacklogoff",
|
||||||
|
"Agent: %s\r\n"
|
||||||
|
"Loginchan: %s\r\n"
|
||||||
|
"Logintime: %ld\r\n"
|
||||||
|
"Uniqueid: %s\r\n",
|
||||||
|
p->agent, last_loginchan, logintime, chan->uniqueid);
|
||||||
|
ast_queue_log("NONE", chan->uniqueid, agent, "AGENTCALLBACKLOGOFF", "%s|%ld|", last_loginchan, logintime);
|
||||||
|
if (option_verbose > 2)
|
||||||
|
ast_verbose(VERBOSE_PREFIX_3 "Callback Agent '%s' logged out\n", p->agent);
|
||||||
|
}
|
||||||
ast_mutex_unlock(&agentlock);
|
ast_mutex_unlock(&agentlock);
|
||||||
if (!res)
|
if (!res)
|
||||||
res = ast_safe_sleep(chan, 500);
|
res = ast_safe_sleep(chan, 500);
|
||||||
@@ -1295,12 +1337,13 @@ static int __login_exec(struct ast_channel *chan, void *data, int callbackmode)
|
|||||||
strncpy(p->moh, chan->musicclass, sizeof(p->moh) - 1);
|
strncpy(p->moh, chan->musicclass, sizeof(p->moh) - 1);
|
||||||
#endif
|
#endif
|
||||||
ast_moh_start(chan, p->moh);
|
ast_moh_start(chan, p->moh);
|
||||||
|
if (p->loginstart == 0)
|
||||||
|
time(&p->loginstart);
|
||||||
manager_event(EVENT_FLAG_AGENT, "Agentlogin",
|
manager_event(EVENT_FLAG_AGENT, "Agentlogin",
|
||||||
"Agent: %s\r\n"
|
"Agent: %s\r\n"
|
||||||
"Channel: %s\r\n",
|
"Channel: %s\r\n"
|
||||||
p->agent, chan->name);
|
"Uniqueid: %s\r\n",
|
||||||
time(&start);
|
p->agent, chan->name, chan->uniqueid);
|
||||||
snprintf(agent, sizeof(agent), "Agent/%s", p->agent);
|
|
||||||
if (updatecdr && chan->cdr)
|
if (updatecdr && chan->cdr)
|
||||||
snprintf(chan->cdr->channel, sizeof(chan->cdr->channel), "Agent/%s", p->agent);
|
snprintf(chan->cdr->channel, sizeof(chan->cdr->channel), "Agent/%s", p->agent);
|
||||||
ast_queue_log("NONE", chan->uniqueid, agent, "AGENTLOGIN", "%s", chan->name);
|
ast_queue_log("NONE", chan->uniqueid, agent, "AGENTLOGIN", "%s", chan->name);
|
||||||
@@ -1370,13 +1413,17 @@ static int __login_exec(struct ast_channel *chan, void *data, int callbackmode)
|
|||||||
if (p->chan == chan)
|
if (p->chan == chan)
|
||||||
p->chan = NULL;
|
p->chan = NULL;
|
||||||
p->acknowledged = 0;
|
p->acknowledged = 0;
|
||||||
|
logintime = time(NULL) - p->loginstart;
|
||||||
|
p->loginstart = 0;
|
||||||
ast_mutex_unlock(&p->lock);
|
ast_mutex_unlock(&p->lock);
|
||||||
|
manager_event(EVENT_FLAG_AGENT, "Agentlogoff",
|
||||||
|
"Agent: %s\r\n"
|
||||||
|
"Logintime: %ld\r\n"
|
||||||
|
"Uniqueid: %s\r\n",
|
||||||
|
p->agent, logintime, chan->uniqueid);
|
||||||
|
ast_queue_log("NONE", chan->uniqueid, agent, "AGENTLOGOFF", "%s|%ld", chan->name, logintime);
|
||||||
if (option_verbose > 2)
|
if (option_verbose > 2)
|
||||||
ast_verbose(VERBOSE_PREFIX_3 "Agent '%s' logged out\n", p->agent);
|
ast_verbose(VERBOSE_PREFIX_3 "Agent '%s' logged out\n", p->agent);
|
||||||
ast_queue_log("NONE", chan->uniqueid, agent, "AGENTLOGOFF", "%s|%ld", chan->name, (long)(time(NULL) - start));
|
|
||||||
manager_event(EVENT_FLAG_AGENT, "Agentlogoff",
|
|
||||||
"Agent: %s\r\n",
|
|
||||||
p->agent);
|
|
||||||
/* If there is no owner, go ahead and kill it now */
|
/* If there is no owner, go ahead and kill it now */
|
||||||
if (p->dead && !p->owner)
|
if (p->dead && !p->owner)
|
||||||
free(p);
|
free(p);
|
||||||
|
@@ -22,10 +22,18 @@ The agent dumped the caller while listening to the queue announcement.
|
|||||||
AGENTLOGIN(channel)
|
AGENTLOGIN(channel)
|
||||||
The agent logged in. The channel is recorded.
|
The agent logged in. The channel is recorded.
|
||||||
|
|
||||||
|
AGENTCALLBACKLOGIN(exten@context)
|
||||||
|
The callback agent logged in. The login extension and context is recorded.
|
||||||
|
|
||||||
AGENTLOGOFF(channel|logintime)
|
AGENTLOGOFF(channel|logintime)
|
||||||
The agent logged off. The channel is recorded, along with the total time
|
The agent logged off. The channel is recorded, along with the total time
|
||||||
the agent was logged in.
|
the agent was logged in.
|
||||||
|
|
||||||
|
AGENTCALLBACKLOGOFF(exten@context|logintime|reason)
|
||||||
|
The callback agent logged off. The last login extension and context is
|
||||||
|
recorded, along with the total time the agent was logged in, and the
|
||||||
|
reason for the logoff if it was not a normal logoff (e.g., Autologoff)
|
||||||
|
|
||||||
COMPLETEAGENT(holdtime|calltime|origposition)
|
COMPLETEAGENT(holdtime|calltime|origposition)
|
||||||
The caller was connected to an agent, and the call was terminated normally
|
The caller was connected to an agent, and the call was terminated normally
|
||||||
by the *agent*. The caller's hold time and the length of the call are both
|
by the *agent*. The caller's hold time and the length of the call are both
|
||||||
|
Reference in New Issue
Block a user