debug_utilities: Add ast_logescalator

The escalator works by creating a set of startup commands in cli.conf
that set up logger channels and issue the debug commands for the
subsystems specified.  If asterisk is running when it is executed,
the same commands will be issued to the running instance.  The original
cli.conf is saved before any changes are made and can be restored by
executing '$prog --reset'.

The log output will be stored in...
$astlogdir/message.$uniqueid
$astlogdir/debug.$uniqueid
$astlogdir/dtmf.$uniqueid
$astlogdir/fax.$uniqueid
$astlogdir/security.$uniqueid
$astlogdir/pjsip_history.$uniqueid
$astlogdir/sip_history.$uniqueid

Some minor tweaks were made to chan_sip, and res_pjsip_history
so their history output could be send to a log channel as packets
are captured.

A minor tweak was also made to manager so events are output to verbose
when "manager set debug on" is issued.

Change-Id: I799f8e5013b86dc5282961b27383d134bf09e543
This commit is contained in:
George Joseph
2017-01-25 05:50:43 -07:00
parent 3eabae43c4
commit ef4deb8ecd
4 changed files with 479 additions and 29 deletions

View File

@@ -157,6 +157,9 @@ struct expression_token {
char field[];
};
/*! \brief Log level for history output */
static int log_level = -1;
/*!
* \brief Operator callback for determining equality
*/
@@ -644,6 +647,41 @@ static struct pjsip_history_entry *pjsip_history_entry_alloc(pjsip_msg *msg)
return entry;
}
/*! \brief Format single line history entry */
static void sprint_list_entry(struct pjsip_history_entry *entry, char *line, int len)
{
char addr[64];
if (entry->transmitted) {
pj_sockaddr_print(&entry->dst, addr, sizeof(addr), 3);
} else {
pj_sockaddr_print(&entry->src, addr, sizeof(addr), 3);
}
if (entry->msg->type == PJSIP_REQUEST_MSG) {
char uri[128];
pjsip_uri_print(PJSIP_URI_IN_REQ_URI, entry->msg->line.req.uri, uri, sizeof(uri));
snprintf(line, len, "%-5.5d %-10.10ld %-5.5s %-24.24s %.*s %s SIP/2.0",
entry->number,
entry->timestamp.tv_sec,
entry->transmitted ? "* ==>" : "* <==",
addr,
(int)pj_strlen(&entry->msg->line.req.method.name),
pj_strbuf(&entry->msg->line.req.method.name),
uri);
} else {
snprintf(line, len, "%-5.5d %-10.10ld %-5.5s %-24.24s SIP/2.0 %u %.*s",
entry->number,
entry->timestamp.tv_sec,
entry->transmitted ? "* ==>" : "* <==",
addr,
entry->msg->line.status.code,
(int)pj_strlen(&entry->msg->line.status.reason),
pj_strbuf(&entry->msg->line.status.reason));
}
}
/*! \brief PJSIP callback when a SIP message is transmitted */
static pj_status_t history_on_tx_msg(pjsip_tx_data *tdata)
{
@@ -665,6 +703,13 @@ static pj_status_t history_on_tx_msg(pjsip_tx_data *tdata)
AST_VECTOR_APPEND(&vector_history, entry);
ast_mutex_unlock(&history_lock);
if (log_level != -1) {
char line[256];
sprint_list_entry(entry, line, sizeof(line));
ast_log_dynamic_level(log_level, "%s\n", line);
}
return PJ_SUCCESS;
}
@@ -698,6 +743,13 @@ static pj_bool_t history_on_rx_msg(pjsip_rx_data *rdata)
AST_VECTOR_APPEND(&vector_history, entry);
ast_mutex_unlock(&history_lock);
if (log_level != -1) {
char line[256];
sprint_list_entry(entry, line, sizeof(line));
ast_log_dynamic_level(log_level, "%s\n", line);
}
return PJ_FALSE;
}
@@ -1118,38 +1170,12 @@ static void display_entry_list(struct ast_cli_args *a, struct vector_history_t *
for (i = 0; i < AST_VECTOR_SIZE(vec); i++) {
struct pjsip_history_entry *entry;
char addr[64];
char line[256];
entry = AST_VECTOR_GET(vec, i);
sprint_list_entry(entry, line, sizeof(line));
if (entry->transmitted) {
pj_sockaddr_print(&entry->dst, addr, sizeof(addr), 3);
} else {
pj_sockaddr_print(&entry->src, addr, sizeof(addr), 3);
}
if (entry->msg->type == PJSIP_REQUEST_MSG) {
char uri[128];
pjsip_uri_print(PJSIP_URI_IN_REQ_URI, entry->msg->line.req.uri, uri, sizeof(uri));
snprintf(line, sizeof(line), "%.*s %s SIP/2.0",
(int)pj_strlen(&entry->msg->line.req.method.name),
pj_strbuf(&entry->msg->line.req.method.name),
uri);
} else {
snprintf(line, sizeof(line), "SIP/2.0 %u %.*s",
entry->msg->line.status.code,
(int)pj_strlen(&entry->msg->line.status.reason),
pj_strbuf(&entry->msg->line.status.reason));
}
ast_cli(a->fd, "%-5.5d %-10.10ld %-5.5s %-24.24s %s\n",
entry->number,
entry->timestamp.tv_sec,
entry->transmitted ? "* ==>" : "* <==",
addr,
line);
ast_cli(a->fd, "%s\n", line);
}
}
@@ -1319,6 +1345,11 @@ static int load_module(void)
{
CHECK_PJSIP_MODULE_LOADED();
log_level = ast_logger_register_level("PJSIP_HISTORY");
if (log_level < 0) {
ast_log(LOG_WARNING, "Unable to register history log level\n");
}
pj_caching_pool_init(&cachingpool, &pj_pool_factory_default_policy, 0);
AST_VECTOR_INIT(&vector_history, HISTORY_INITIAL_SIZE);
@@ -1339,6 +1370,10 @@ static int unload_module(void)
pj_caching_pool_destroy(&cachingpool);
if (log_level != -1) {
ast_logger_unregister_level("PJSIP_HISTORY");
}
return 0;
}