17.5. The Asterisk CLIAsterisk's CLI is where you, the administrator, control and monitor the Asterisk PBX. The Asterisk CLI provides you with real-time information about voice channels, extensions, contexts, and more. Using the CLI, you can start and stop the Asterisk server, as described earlier in the chapter. You can do status queries about the voice channels, place and hang up calls, and add or remove extensions and contexts. If the Asterisk server is already running, you can launch the Asterisk CLI by starting another instance of Asterisk in client mode: # asterisk -r The first command you should probably learn is help , which displays a list of valid commands or, when used as follows , gives command-specific assistance: pbx*CLI> help show channels Notice the pbx*CLI> prompt. This prompt will vary depending on the Unix hostname of your machinein this case, it's pbx . 17.5.1. Inspecting ChannelsThere are several types of voice channels in Asterisk. There can be analog FXO (foreign exchange office) channels, such as those facilitated by a POTS telephone company line and an X100P card. There can also be voice channels provided by H.323, SIP, IAX, SCCP, and MGCP (all different VoIP signaling protocols), as well as by FXS (foreign exchange station) devices like QuickNet's Phone Jack interface card and PRI interfaces, too. You can use the Asterisk CLI to inspect each type of channel, but the details provided are different for each:
Each of these commands provides a list of channel numbers that can correspond to a numeric reference in the channel name , as described earlier (example: Zap/1 ). Take a look at a zap show channels command: pbx*CLI> zap show channels Chan. Num. Extension Context Language MusicOnH 1 incoming default The command output shows that there is a single Zaptel channel available for use by the Asterisk PBX. In our experimental server, this logical channel represents the physical X100P interface with a telco line connected to it. The command output tells that the context for calls on this channel is incoming because the start extension in extensions.conf is established within that context. This channel is referred do in the dial-plan as Zap/1 . You can dig deeper using the CLI, to the configuration of a specific channel, by running the zap show channel <channel#> command, like this: pbx*CLI> zap show channel 1 Channel: 1 File Descriptor: 17 Span: 1 Extension: Context: incoming Caller ID string: Destroy: 0 Signalling Type: FXS Kewlstart Owner: <None> Real: <None> Callwait: <None> Threeway: <None> Confno: -1 Propagated Conference: -1 Real in conference: 0 DSP: no Relax DTMF: yes Dialing/CallwaitCAS: 0/0 Default law: ulaw Fax Handled: no Pulse phone: no Echo Cancellation: 128 taps, currently OFF Actual Confinfo: Num/0, Mode/0x0000 There are many channel-specific settings, most of which are user -definable. You can see from this list that, even within the scope of a single Zaptel channel, Asterisk is extremely flexible. In our test server, this channel is an FXO channelthat is, a channel that connects to the telephone company. In order to interact correctly with the phone company's switch, the X100P (or other compatible) interface has to use FXS signaling, so that, to the phone company, it appears to be a regular telephone answering the line and not a newfangled Asterisk server (FXO/FXS signaling was introduced in Chapter 4). Other types of channels (SIP, H.323, etc.) have their own channel-specific settings. 17.5.2. Inspecting the Dial-PlanThe show dialplan CLI command can be used two ways: showing the entire system-wide dial-plan, or only showing a specific context or extension. Here's the output for a small, but complete, dial-plan: pbx*CLI> show dialplan [ Context 'default' created by 'pbx_config' ] '3101' => 1. Dial(SIP/3101@10.1.1.101) [pbx_config] 2. Voicemail(u4101) [pbx_config] '3102' => 1. Dial(SIP/3102@10.1.1.102) [pbx_config] 2. Voicemail(u4101) [pbx_config] '3103' => 1. Dial(SIP/3103@10.1.1.103) [pbx_config] 2. Voicemail(u4101) [pbx_config] '8500' => 1. VoiceMailMain( ) [pbx_config] '_9NXXXXXX' => 1. Dial(${PSTN}/{EXTEN:1}) [pbx_config] 2. Congestion( ) [pbx_config] Ignore pattern => '9' [pbx_config] [ Context 'incoming' created by 'pbx_config' ] 's' => 1. Answer( ) [pbx_config] 2. Dial(SIP/3103@10.1.1.10330) [pbx_config] 3. Voicemail(u4101) [pbx_config] 4. Hangup( ) [pbx_config] In the default context, several extensions are configured to ring calls on specific SIP telephones with static IP addresses and an extension pattern that matches outbound calls. The 8500 extension is one that allows private users of the Asterisk system to access the voice mail management greeting. There's also an incoming context that attempts to ring a certain phone with the s extension and then transfers the call on the current channel to a voice mailbox if nobody answers the phone. To get a specific extension's dial-plan only, run the show dialplan CLI command with an argument of extension@context : pbx*CLI> s how dialplan 3102@default [ Context 'default' created by 'pbx_config' ] '3102' => 1. Dial(SIP/3102@10.1.1.102) [pbx_config] 2. Voicemail(u4101) [pbx_config] In this case, only the extension definition for 3102 in the default context is shown. 17.5.3. Administering the Dial-Plan Using the CLIEarlier, we covered the primary configuration file for the dial-plan: extensions.conf . You can also alter the dial-plan using CLI commands. The difference between using the CLI and using the configuration file is this: CLI dial-plan changes, such as additions and removals of extensions, occur immediately, whereas changes to extensions.conf require a restart of Asterisk (or at least a config-reload), which introduces downtime. Consider the following CLI command: pbx*CLI> add extension 120,1,Dial(SIP/110@oreilly.com:5060) into local The command add extension is followed by the same definition string you would see in an exten directive in extensions.conf that is, the extension number, priority, and application command for the extension. The final part, into local , tells Asterisk which context to add the extension intoin this case, local . The CLI can also be used to drop extensions, using the remove extension command, and to re-create the extensions.conf file based on the current "live" dial-plan, using the save dialplan command. If you prefer to use the configuration file to maintain your dial-plan, you can avoid total Asterisk restarts by issuing a reload extensions command, which re-reads the extensions.conf file and affects the dial-plan accordingly . That said, using the CLI may be the preferred method for programming the dial-plan, because it gives you immediate feedback in case of syntax errors or other common mistakes. In order to save changes made at the CLI, your extensions.conf must contain the writeprotect=no setting in its general section, and you must issue a save dialplan command at the CLI. This will cause the current dial-plan configuration to overwrite anything in your extensions.conf file (including comments). 17.5.4. CLI Command Reference17.5.4.1 Administrator commands
17.5.4.2 Process control commands
17.5.4.3 AGI commands
17.5.4.4 Database commands
17.5.4.5 IAX v2 commands
17.5.4.6 IAX v1 commands
17.5.4.7 Crypto commands
17.5.4.8 H.323 commandsH.323 media channels are supported by Asterisk but does not compile by default. Installation instructions for H.323 support are found in /usr/src/asterisk/channels/h323/README . Asterisk cannot act as an H.323 gatekeeper, only as a gateway. A fully H.323 VoIP network would also need an H.323 gatekeeper, such as the excellent GnuGK, which is covered in Chapter 7.
17.5.4.9 SIP commandsSIP support is built in to Asterisk via the chan_sip module, which comes with it. Asterisk can act as a SIP proxy, a SIP registrar, and a SIP client. Named SIP call routes, which are created in /etc/asterisk/sip.conf , are called SIP peers, and their destinations can be SIP phones or other SIP servers. (Refer to "SIP Channels," earlier in this chapter.)
17.5.4.10 MGCP channel commandsThe Media Gateway Control Protocol is supported by Asterisk out of the box. The MGCP module is included in the standard distribution. MGCP channels are configured in /etc/asterisk/mgcp.conf .
17.5.4.11 SCCP channel commandsSCCP (Skinny Client Control Protocol) is a leg-only signaling protocol for VoIP endpoints. It is supported most prominently by all Cisco IP phones, among others. The chan_skinny Asterisk module provides SCCP compatibility.
17.5.4.12 CAPI channel commandsCAPI channels are used to support BRI channels with Asterisk. The CAPI module can be obtained from http://www.junghanns.net/asterisk.
17.5.4.13 Zaptel channel commandsZaptel interface hardware for POTS, FXO/FXS, T1, and E1 links is manufactured by Digium, and it is supported natively by Asterisk using the chan_zap module, which is loaded by default when you install it.
|