mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-20 20:44:20 +00:00
Add core show channels count CLI command. (issue #8932 reported by mr_mehul_shah)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@52525 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
1
CHANGES
1
CHANGES
@@ -67,6 +67,7 @@ Changes since Asterisk 1.4-beta was branched:
|
|||||||
* Added the srvlookup option to iax.conf
|
* Added the srvlookup option to iax.conf
|
||||||
* Added 'E' and 'V' commands to ExternalIVR.
|
* Added 'E' and 'V' commands to ExternalIVR.
|
||||||
* Added 'DBDel' and 'DBDelTree' manager commands.
|
* Added 'DBDel' and 'DBDelTree' manager commands.
|
||||||
|
* Added 'core show channels count' CLI command.
|
||||||
|
|
||||||
SIP changes
|
SIP changes
|
||||||
-----------
|
-----------
|
||||||
|
97
main/cli.c
97
main/cli.c
@@ -458,19 +458,20 @@ static char *handle_chanlist(struct ast_cli_entry *e, int cmd, struct ast_cli_ar
|
|||||||
#define VERBOSE_FORMAT_STRING2 "%-20.20s %-20.20s %-16.16s %-4.4s %-7.7s %-12.12s %-25.25s %-15.15s %8.8s %-11.11s %-20.20s\n"
|
#define VERBOSE_FORMAT_STRING2 "%-20.20s %-20.20s %-16.16s %-4.4s %-7.7s %-12.12s %-25.25s %-15.15s %8.8s %-11.11s %-20.20s\n"
|
||||||
|
|
||||||
struct ast_channel *c = NULL;
|
struct ast_channel *c = NULL;
|
||||||
int numchans = 0, concise = 0, verbose = 0;
|
int numchans = 0, concise = 0, verbose = 0, count = 0;
|
||||||
int fd, argc;
|
int fd, argc;
|
||||||
char **argv;
|
char **argv;
|
||||||
|
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
case CLI_INIT:
|
case CLI_INIT:
|
||||||
e->command = "core show channels [concise|verbose]";
|
e->command = "core show channels [concise|verbose|count]";
|
||||||
e->usage =
|
e->usage =
|
||||||
"Usage: core show channels [concise|verbose]\n"
|
"Usage: core show channels [concise|verbose|count]\n"
|
||||||
" Lists currently defined channels and some information about them. If\n"
|
" Lists currently defined channels and some information about them. If\n"
|
||||||
" 'concise' is specified, the format is abridged and in a more easily\n"
|
" 'concise' is specified, the format is abridged and in a more easily\n"
|
||||||
" machine parsable format. If 'verbose' is specified, the output includes\n"
|
" machine parsable format. If 'verbose' is specified, the output includes\n"
|
||||||
" more and longer fields.\n";
|
" more and longer fields. If 'count' is specified only the channel and call\n"
|
||||||
|
" count is output.\n";
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
case CLI_GENERATE:
|
case CLI_GENERATE:
|
||||||
@@ -485,58 +486,64 @@ static char *handle_chanlist(struct ast_cli_entry *e, int cmd, struct ast_cli_ar
|
|||||||
concise = 1;
|
concise = 1;
|
||||||
else if (!strcasecmp(argv[e->args-1],"verbose"))
|
else if (!strcasecmp(argv[e->args-1],"verbose"))
|
||||||
verbose = 1;
|
verbose = 1;
|
||||||
|
else if (!strcasecmp(argv[e->args-1],"count"))
|
||||||
|
count = 1;
|
||||||
else
|
else
|
||||||
return CLI_SHOWUSAGE;
|
return CLI_SHOWUSAGE;
|
||||||
} else if (a->argc != e->args - 1)
|
} else if (a->argc != e->args - 1)
|
||||||
return CLI_SHOWUSAGE;
|
return CLI_SHOWUSAGE;
|
||||||
|
|
||||||
if (!concise && !verbose)
|
if (!count) {
|
||||||
ast_cli(fd, FORMAT_STRING2, "Channel", "Location", "State", "Application(Data)");
|
if (!concise && !verbose)
|
||||||
else if (verbose)
|
ast_cli(fd, FORMAT_STRING2, "Channel", "Location", "State", "Application(Data)");
|
||||||
ast_cli(fd, VERBOSE_FORMAT_STRING2, "Channel", "Context", "Extension", "Priority", "State", "Application", "Data",
|
else if (verbose)
|
||||||
"CallerID", "Duration", "Accountcode", "BridgedTo");
|
ast_cli(fd, VERBOSE_FORMAT_STRING2, "Channel", "Context", "Extension", "Priority", "State", "Application", "Data",
|
||||||
|
"CallerID", "Duration", "Accountcode", "BridgedTo");
|
||||||
|
}
|
||||||
|
|
||||||
while ((c = ast_channel_walk_locked(c)) != NULL) {
|
while ((c = ast_channel_walk_locked(c)) != NULL) {
|
||||||
struct ast_channel *bc = ast_bridged_channel(c);
|
struct ast_channel *bc = ast_bridged_channel(c);
|
||||||
char durbuf[10] = "-";
|
char durbuf[10] = "-";
|
||||||
|
|
||||||
if ((concise || verbose) && c->cdr && !ast_tvzero(c->cdr->start)) {
|
if (!count) {
|
||||||
int duration = (int)(ast_tvdiff_ms(ast_tvnow(), c->cdr->start) / 1000);
|
if ((concise || verbose) && c->cdr && !ast_tvzero(c->cdr->start)) {
|
||||||
if (verbose) {
|
int duration = (int)(ast_tvdiff_ms(ast_tvnow(), c->cdr->start) / 1000);
|
||||||
int durh = duration / 3600;
|
if (verbose) {
|
||||||
int durm = (duration % 3600) / 60;
|
int durh = duration / 3600;
|
||||||
int durs = duration % 60;
|
int durm = (duration % 3600) / 60;
|
||||||
snprintf(durbuf, sizeof(durbuf), "%02d:%02d:%02d", durh, durm, durs);
|
int durs = duration % 60;
|
||||||
|
snprintf(durbuf, sizeof(durbuf), "%02d:%02d:%02d", durh, durm, durs);
|
||||||
|
} else {
|
||||||
|
snprintf(durbuf, sizeof(durbuf), "%d", duration);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (concise) {
|
||||||
|
ast_cli(fd, CONCISE_FORMAT_STRING, c->name, c->context, c->exten, c->priority, ast_state2str(c->_state),
|
||||||
|
c->appl ? c->appl : "(None)",
|
||||||
|
S_OR(c->data, ""), /* XXX different from verbose ? */
|
||||||
|
S_OR(c->cid.cid_num, ""),
|
||||||
|
S_OR(c->accountcode, ""),
|
||||||
|
c->amaflags,
|
||||||
|
durbuf,
|
||||||
|
bc ? bc->name : "(None)");
|
||||||
|
} else if (verbose) {
|
||||||
|
ast_cli(fd, VERBOSE_FORMAT_STRING, c->name, c->context, c->exten, c->priority, ast_state2str(c->_state),
|
||||||
|
c->appl ? c->appl : "(None)",
|
||||||
|
c->data ? S_OR(c->data, "(Empty)" ): "(None)",
|
||||||
|
S_OR(c->cid.cid_num, ""),
|
||||||
|
durbuf,
|
||||||
|
S_OR(c->accountcode, ""),
|
||||||
|
bc ? bc->name : "(None)");
|
||||||
} else {
|
} else {
|
||||||
snprintf(durbuf, sizeof(durbuf), "%d", duration);
|
char locbuf[40] = "(None)";
|
||||||
}
|
char appdata[40] = "(None)";
|
||||||
}
|
|
||||||
if (concise) {
|
if (!ast_strlen_zero(c->context) && !ast_strlen_zero(c->exten))
|
||||||
ast_cli(fd, CONCISE_FORMAT_STRING, c->name, c->context, c->exten, c->priority, ast_state2str(c->_state),
|
snprintf(locbuf, sizeof(locbuf), "%s@%s:%d", c->exten, c->context, c->priority);
|
||||||
c->appl ? c->appl : "(None)",
|
if (c->appl)
|
||||||
S_OR(c->data, ""), /* XXX different from verbose ? */
|
snprintf(appdata, sizeof(appdata), "%s(%s)", c->appl, S_OR(c->data, ""));
|
||||||
S_OR(c->cid.cid_num, ""),
|
ast_cli(fd, FORMAT_STRING, c->name, locbuf, ast_state2str(c->_state), appdata);
|
||||||
S_OR(c->accountcode, ""),
|
}
|
||||||
c->amaflags,
|
|
||||||
durbuf,
|
|
||||||
bc ? bc->name : "(None)");
|
|
||||||
} else if (verbose) {
|
|
||||||
ast_cli(fd, VERBOSE_FORMAT_STRING, c->name, c->context, c->exten, c->priority, ast_state2str(c->_state),
|
|
||||||
c->appl ? c->appl : "(None)",
|
|
||||||
c->data ? S_OR(c->data, "(Empty)" ): "(None)",
|
|
||||||
S_OR(c->cid.cid_num, ""),
|
|
||||||
durbuf,
|
|
||||||
S_OR(c->accountcode, ""),
|
|
||||||
bc ? bc->name : "(None)");
|
|
||||||
} else {
|
|
||||||
char locbuf[40] = "(None)";
|
|
||||||
char appdata[40] = "(None)";
|
|
||||||
|
|
||||||
if (!ast_strlen_zero(c->context) && !ast_strlen_zero(c->exten))
|
|
||||||
snprintf(locbuf, sizeof(locbuf), "%s@%s:%d", c->exten, c->context, c->priority);
|
|
||||||
if (c->appl)
|
|
||||||
snprintf(appdata, sizeof(appdata), "%s(%s)", c->appl, S_OR(c->data, ""));
|
|
||||||
ast_cli(fd, FORMAT_STRING, c->name, locbuf, ast_state2str(c->_state), appdata);
|
|
||||||
}
|
}
|
||||||
numchans++;
|
numchans++;
|
||||||
ast_channel_unlock(c);
|
ast_channel_unlock(c);
|
||||||
|
Reference in New Issue
Block a user