mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-06 12:36:58 +00:00
Add "show channels concise" for machine readable format
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@3187 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
29
cli.c
29
cli.c
@@ -69,9 +69,10 @@ static char help_help[] =
|
|||||||
" topic, it provides a list of commands.\n";
|
" topic, it provides a list of commands.\n";
|
||||||
|
|
||||||
static char chanlist_help[] =
|
static char chanlist_help[] =
|
||||||
"Usage: show channels\n"
|
"Usage: show channels [concise]\n"
|
||||||
" Lists currently defined channels and some information about\n"
|
" Lists currently defined channels and some information about\n"
|
||||||
" them.\n";
|
" them. If 'concise' is specified, format is abridged and in\n"
|
||||||
|
" a more easily machine parsable format\n";
|
||||||
|
|
||||||
static char reload_help[] =
|
static char reload_help[] =
|
||||||
"Usage: reload\n"
|
"Usage: reload\n"
|
||||||
@@ -286,20 +287,34 @@ static int handle_chanlist(int fd, int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
#define FORMAT_STRING "%15s (%-10s %-12s %-4d) %7s %-12s %-15s\n"
|
#define FORMAT_STRING "%15s (%-10s %-12s %-4d) %7s %-12s %-15s\n"
|
||||||
#define FORMAT_STRING2 "%15s (%-10s %-12s %-4s) %7s %-12s %-15s\n"
|
#define FORMAT_STRING2 "%15s (%-10s %-12s %-4s) %7s %-12s %-15s\n"
|
||||||
|
#define CONCISE_FORMAT_STRING "%s:%s:%s:%d:%s:%s:%s:%s:%s:%d\n"
|
||||||
|
|
||||||
struct ast_channel *c=NULL;
|
struct ast_channel *c=NULL;
|
||||||
int numchans = 0;
|
int numchans = 0;
|
||||||
if (argc != 2)
|
int concise = 0;
|
||||||
|
if (argc < 2 || argc > 3)
|
||||||
return RESULT_SHOWUSAGE;
|
return RESULT_SHOWUSAGE;
|
||||||
|
|
||||||
|
concise = (argc == 3 && (!strcasecmp(argv[2],"concise")));
|
||||||
c = ast_channel_walk_locked(NULL);
|
c = ast_channel_walk_locked(NULL);
|
||||||
ast_cli(fd, FORMAT_STRING2, "Channel", "Context", "Extension", "Pri", "State", "Appl.", "Data");
|
if(!concise)
|
||||||
|
ast_cli(fd, FORMAT_STRING2, "Channel", "Context", "Extension", "Pri", "State", "Appl.", "Data");
|
||||||
while(c) {
|
while(c) {
|
||||||
ast_cli(fd, FORMAT_STRING, c->name, c->context, c->exten, c->priority, ast_state2str(c->_state),
|
if(concise)
|
||||||
c->appl ? c->appl : "(None)", c->data ? ( !ast_strlen_zero(c->data) ? c->data : "(Empty)" ): "(None)");
|
ast_cli(fd, CONCISE_FORMAT_STRING, c->name, c->context, c->exten, c->priority, ast_state2str(c->_state),
|
||||||
|
c->appl ? c->appl : "(None)", c->data ? ( !ast_strlen_zero(c->data) ? c->data : "" ): "",
|
||||||
|
(c->callerid && !ast_strlen_zero(c->callerid)) ? c->callerid : "",
|
||||||
|
(c->accountcode && !ast_strlen_zero(c->accountcode)) ? c->accountcode : "",c->amaflags);
|
||||||
|
else
|
||||||
|
ast_cli(fd, FORMAT_STRING, c->name, c->context, c->exten, c->priority, ast_state2str(c->_state),
|
||||||
|
c->appl ? c->appl : "(None)", c->data ? ( !ast_strlen_zero(c->data) ? c->data : "(Empty)" ): "(None)");
|
||||||
|
|
||||||
numchans++;
|
numchans++;
|
||||||
ast_mutex_unlock(&c->lock);
|
ast_mutex_unlock(&c->lock);
|
||||||
c = ast_channel_walk_locked(c);
|
c = ast_channel_walk_locked(c);
|
||||||
}
|
}
|
||||||
ast_cli(fd, "%d active channel(s)\n", numchans);
|
if(!concise)
|
||||||
|
ast_cli(fd, "%d active channel(s)\n", numchans);
|
||||||
return RESULT_SUCCESS;
|
return RESULT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user