mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-05 20:20:07 +00:00
Merge manager action and example (bug #2701)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@4363 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -82,6 +82,10 @@ static char *descrip3 =
|
|||||||
" 'd' - make the app return -1 if there is an error condition and there is no extension n+101\n"
|
" 'd' - make the app return -1 if there is an error condition and there is no extension n+101\n"
|
||||||
" 'n' - don't generate the warnings when there is no callerid or the agentid is not known. It's handy if you want to have one context for agent and non-agent calls.\n";
|
" 'n' - don't generate the warnings when there is no callerid or the agentid is not known. It's handy if you want to have one context for agent and non-agent calls.\n";
|
||||||
|
|
||||||
|
static char mandescr_agents[] =
|
||||||
|
"Description: Will list info about all possible agents.\n"
|
||||||
|
"Variables: NONE\n";
|
||||||
|
|
||||||
static char moh[80] = "default";
|
static char moh[80] = "default";
|
||||||
|
|
||||||
#define AST_MAX_AGENT 80 /* Agent ID or Password max length */
|
#define AST_MAX_AGENT 80 /* Agent ID or Password max length */
|
||||||
@@ -1161,6 +1165,71 @@ static int powerof(unsigned int v)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int action_agents(struct mansession *s, struct message *m)
|
||||||
|
{
|
||||||
|
struct agent_pvt *p;
|
||||||
|
char *username = NULL;
|
||||||
|
char *loginChan = NULL;
|
||||||
|
char *talkingtoChan = NULL;
|
||||||
|
char *status = NULL;
|
||||||
|
ast_mutex_lock(&agentlock);
|
||||||
|
p = agents;
|
||||||
|
while(p) {
|
||||||
|
ast_mutex_lock(&p->lock);
|
||||||
|
|
||||||
|
/* Status Values: AGENT_LOGGEDOFF - Agent isn't logged in
|
||||||
|
AGENT_IDLE - Agent is logged in, and waiting for call
|
||||||
|
AGENT_ONCALL - Agent is logged in, and on a call
|
||||||
|
AGENT_UNKNOWN - Don't know anything about agent. Shouldn't ever get this. */
|
||||||
|
|
||||||
|
if(!ast_strlen_zero(p->name)) {
|
||||||
|
username = p->name;
|
||||||
|
} else {
|
||||||
|
username = "None";
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Set a default status. It 'should' get changed. */
|
||||||
|
status = "AGENT_UNKNOWN";
|
||||||
|
|
||||||
|
if(p->chan) {
|
||||||
|
loginChan = p->loginchan;
|
||||||
|
if(p->owner && p->owner->_bridge) {
|
||||||
|
talkingtoChan = p->chan->cid.cid_num;
|
||||||
|
status = "AGENT_ONCALL";
|
||||||
|
} else {
|
||||||
|
talkingtoChan = "n/a";
|
||||||
|
status = "AGENT_IDLE";
|
||||||
|
}
|
||||||
|
} else if(!ast_strlen_zero(p->loginchan)) {
|
||||||
|
loginChan = p->loginchan;
|
||||||
|
talkingtoChan = "n/a";
|
||||||
|
status = "AGENT_IDLE";
|
||||||
|
if(p->acknowledged) {
|
||||||
|
sprintf(loginChan, " %s (Confirmed)", loginChan);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
loginChan = "n/a";
|
||||||
|
talkingtoChan = "n/a";
|
||||||
|
status = "AGENT_LOGGEDOFF";
|
||||||
|
}
|
||||||
|
|
||||||
|
ast_cli(s->fd, "Event: Agents\r\n"
|
||||||
|
"Agent: %s\r\n"
|
||||||
|
"Name: %s\r\n"
|
||||||
|
"Status: %s\r\n"
|
||||||
|
"LoggedInChan: %s\r\n"
|
||||||
|
"LoggedInTime: %ld\r\n"
|
||||||
|
"TalkingTo: %s\r\n"
|
||||||
|
"\r\n",
|
||||||
|
p->agent,p->name,status,loginChan,p->loginstart,talkingtoChan);
|
||||||
|
ast_mutex_unlock(&p->lock);
|
||||||
|
p = p->next;
|
||||||
|
}
|
||||||
|
ast_mutex_unlock(&agentlock);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static int agents_show(int fd, int argc, char **argv)
|
static int agents_show(int fd, int argc, char **argv)
|
||||||
{
|
{
|
||||||
struct agent_pvt *p;
|
struct agent_pvt *p;
|
||||||
@@ -1784,6 +1853,7 @@ int load_module()
|
|||||||
ast_register_application(app, login_exec, synopsis, descrip);
|
ast_register_application(app, login_exec, synopsis, descrip);
|
||||||
ast_register_application(app2, callback_exec, synopsis2, descrip2);
|
ast_register_application(app2, callback_exec, synopsis2, descrip2);
|
||||||
ast_register_application(app3, agentmonitoroutgoing_exec, synopsis3, descrip3);
|
ast_register_application(app3, agentmonitoroutgoing_exec, synopsis3, descrip3);
|
||||||
|
ast_manager_register2("Agents", 0, action_agents, "Agents", mandescr_agents);
|
||||||
ast_cli_register(&cli_show_agents);
|
ast_cli_register(&cli_show_agents);
|
||||||
/* Read in the config */
|
/* Read in the config */
|
||||||
read_agent_config();
|
read_agent_config();
|
||||||
@@ -1805,6 +1875,7 @@ int unload_module()
|
|||||||
ast_unregister_application(app2);
|
ast_unregister_application(app2);
|
||||||
ast_unregister_application(app3);
|
ast_unregister_application(app3);
|
||||||
ast_channel_unregister(type);
|
ast_channel_unregister(type);
|
||||||
|
ast_manager_unregister("Agents");
|
||||||
if (!ast_mutex_lock(&agentlock)) {
|
if (!ast_mutex_lock(&agentlock)) {
|
||||||
/* Hangup all interfaces if they have an owner */
|
/* Hangup all interfaces if they have an owner */
|
||||||
p = agents;
|
p = agents;
|
||||||
|
73
contrib/scripts/agents.php
Executable file
73
contrib/scripts/agents.php
Executable file
@@ -0,0 +1,73 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
ob_implicit_flush(false);
|
||||||
|
|
||||||
|
$username = "drmac";
|
||||||
|
$secret = "secret";
|
||||||
|
|
||||||
|
$socket = fsockopen("127.0.0.1","5038", $errornum, $errorstr);
|
||||||
|
|
||||||
|
$agents = array();
|
||||||
|
$curr_agent = "";
|
||||||
|
$better_status = array( 'AGENT_UNKNOWN' => 'Unknown',
|
||||||
|
'AGENT_IDLE' => 'Idle',
|
||||||
|
'AGENT_ONCALL' => 'On Call',
|
||||||
|
'AGENT_LOGGEDOFF' => 'Not Logged In' );
|
||||||
|
|
||||||
|
if(!$socket) {
|
||||||
|
print "Couldn't open socket. Error #" . $errornum . ": " . $errorstr;
|
||||||
|
} else {
|
||||||
|
fputs($socket, "Action: Login\r\n");
|
||||||
|
fputs($socket, "UserName: $username\r\n");
|
||||||
|
fputs($socket, "Secret: $secret\r\n\r\n");
|
||||||
|
fputs($socket, "Action: Agents\r\n\r\n");
|
||||||
|
fputs($socket, "Action: Logoff\r\n\r\n");
|
||||||
|
|
||||||
|
while(!feof($socket)) {
|
||||||
|
$info = fscanf($socket, "%s\t%s\r\n");
|
||||||
|
switch($info[0]) {
|
||||||
|
case "Agent:":
|
||||||
|
$curr_agent = $info[1];
|
||||||
|
$agents[$curr_agent] = array();
|
||||||
|
break;
|
||||||
|
case "Name:":
|
||||||
|
$agents[$curr_agent]['Name'] = $info[1];
|
||||||
|
break;
|
||||||
|
case "Status:":
|
||||||
|
$agents[$curr_agent]['Status'] = $better_status[$info[1]];
|
||||||
|
break;
|
||||||
|
case "LoggedInChan:":
|
||||||
|
$agents[$curr_agent]['LoggedInChan'] = $info[1];
|
||||||
|
break;
|
||||||
|
case "LoggedInTime:":
|
||||||
|
if($info[1] != "0") {
|
||||||
|
$agents[$curr_agent]['LoggedInTime'] = date("D, M d Y g:ia", $info[1]);
|
||||||
|
} else {
|
||||||
|
$agents[$curr_agent]['LoggedInTime'] = "n/a";
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "TalkingTo:":
|
||||||
|
$agents[$curr_agent]['TalkingTo'] = $info[1];
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fclose($socket);
|
||||||
|
|
||||||
|
print "<html><head><title>Agents Status</title></head>\n<body>\n";
|
||||||
|
print "<table width=\"800px\" border=\"1\">\n";
|
||||||
|
print " <tr><th>Agent #</th><th>Agent Name</th><th>Agent Location</th><th>Agent Status</th><th>Agent Talking To</th><th>Agent Login Time</th></tr>\n";
|
||||||
|
|
||||||
|
foreach( $agents as $agent=>$curr ) {
|
||||||
|
print " <tr>\n <td>" . $agent . "</td>\n";
|
||||||
|
print " <td>" . $curr['Name'] . "</td>\n";
|
||||||
|
print " <td>" . $curr['LoggedInChan'] . "</td>\n";
|
||||||
|
print " <td>" . $curr['Status'] . "</td>\n";
|
||||||
|
print " <td>" . $curr['TalkingTo'] . "</td>\n";
|
||||||
|
print " <td>" . $curr['LoggedInTime'] . "</td>\n </tr>\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
print "</table>\n</body>\n</html>\n";
|
||||||
|
}
|
||||||
|
?>
|
Reference in New Issue
Block a user