Jump to content

Asterisk: How to insert debugging into your dialplan with Verbose

0
  chco's Photo
Posted May 15 2011 05:47 PM

The excerpt below from Asterisk Cookbook shows you how to insert debugging into your dialplan that can be enabled on a global, per-device, or per-channel basis..
Use something like this chanlog GoSub() routine:

[chanlog]
exten => s,1,GotoIf($[${DB_EXISTS(ChanLog/all)} = 0]?checkchan1)
    same => n,GotoIf($[${ARG1} <= ${DB(ChanLog/all)}]?log)
    same => n(checkchan1),Set(KEY=ChanLog/channel/${CHANNEL})
    same => n,GotoIf($[${DB_EXISTS(${KEY})} = 0]?checkchan2)
    same => n,GotoIf($[${ARG1} <= ${DB(${KEY})}]?log)
    same => n(checkchan2),Set(KEY=ChanLog/channel/${CUT(CHANNEL,-,1)})
    same => n,GotoIf($[${DB_EXISTS(${KEY})} = 0]?return)
    same => n,GotoIf($[${ARG1} <= ${DB(${KEY})}]?log)
    same => n(return),Return() ; Return without logging
    same => n(log),Verbose(0,${ARG2})
    same => n,Return()


The chanlog GoSub() routine takes two arguments:


ARG1

A numeric log level



ARG2

The log message


Channel logging using this routine will be sent to the Asterisk console at verbose level 0, meaning that they will show up when you want them to, regardless of the current core set verbose setting. This routine uses a different method, values in AstDB, to control what messages show up. See Table 1-1 for the AstDB entries read in by the chanlog routine. If the log level argument is less than or equal to one of these matched entries in the AstDB, then the message will be logged.

Table 1-1. chanlog AstDB entries

FamilyKeyDescription
ChanLog/allThis setting is applied to all channels.
ChanLog/channels/<device>The chanlog routine will also look for an entry that matches the part of the channel name that comes before the -. For example, if the channel name is SIP/myphone-00112233, the routine will look for a key of channels/SIP/myphone.
ChanLog/channels/<full_channel>The chanlog routine also checks for a match against the full channel name.


Once this routine has been added to your dialplan, you can start adding log statements to any extensions on your system. As an example, here is a typical company main menu that now has chanlog messages for each step:

exten => 6000,1,GoSub(chanlog,s,1(1,[${CHANNEL}] Entered main menu))
    same => n,Background(main-menu)
    same => n,WaitExten(5)

exten => 1,1,GoSub(chanlog,s,1(1,[${CHANNEL}] Pressed 1 for Sales))
    same => n,Goto(sales,s,1)

exten => 2,1,GoSub(chanlog,s,1(1,[${CHANNEL}] Pressed 2 for Technical Support))
    same => n,Goto(tech_support,s,1)

exten => 3,1,GoSub(chanlog,s,1(1,[${CHANNEL}] Pressed 3 for Customer Service))
    same => n,Goto(customer_service,s,1)

exten => 4,1,GoSub(chanlog,s,1(1,[${CHANNEL}] Pressed 4 for Training))
    same => n,Goto(training,s,1)

exten => 5,1,GoSub(chanlog,s,1(1,[${CHANNEL}] Pressed 5 for Directory))
    same => n,Directory()

exten => 0,1,GoSub(chanlog,s,1(1,[${CHANNEL}] Pressed 0 for Operator))
    same => n,Goto(operator,s,1)

exten => i,1,GoSub(chanlog,s,1(1,[$CHANNEL}] invalid "${INVALID_EXTEN}"))
    same => n,Goto(6000,1)

exten => t,1,GoSub(chanlog,s,1(1,[${CHANNEL}] Timed out waiting for digit))
    same => n,Goto(6000,1)


To see the output, we will first disable all other verbose messages from Asterisk and then turn on chanlog messages for all channels:

*CLI> core set verbose 0
*CLI> database put ChanLog all 1


Now when someone calls into the main menu, he will see messages like this at the Asterisk console:

[SIP/000411223344-000000b8] Entered main menu
[SIP/000411223344-000000b8] Pressed 4 for Training


For more information about other types of logging and monitoring of Asterisk systems, see Chapter 24, “System Monitoring and Logging,” of Asterisk: The Definitive Guide (O’Reilly).

Asterisk Cookbook

Learn more about this topic from Asterisk Cookbook.

Asterisk has a wealth of features to help you customize your PBX to fill very specific business needs. This short cookbook offers recipes for tackling dialplan fundamentals, making and controlling calls, and monitoring channels in your PBX environment. Each recipe includes a simple code solution you can put to work immediately, along with a detailed discussion that offers insight into why and how the recipe works.

See what you'll learn


Tags:
0 Subscribe


0 Replies