準備 |
|
AsteriskManagerAPIは、テキスト文字列をやりとりすることによって情報の伝達を行います。
AsteriskManagerAPIを利用するには、/etc/asterisk/manager.confを適宜変更する必要があります。
[general]
enabled = yes
port = 5038
bindaddr = 0.0.0.0
displayconnects = yes
debug=on
[astmgr]
secret = pass_astmgr
read = system,call,log,verbose,command,agent,user
write = system,call,log,verbose,command,agent,user
deny=0.0.0.0/0.0.0.0
permit=192.168.100.10/255.255.255.0
permit=127.0.0.1/255.255.255.0
port | AsteriskManagerAPIの受付ポート番号です |
permit | クライアントのIPを指定します |
[astmgr] | クライアントのユーザーIDを指定します |
secret | クライアントのパスワードを指定します |
|
サンプル |
|
AsteriskManagerAPIを利用して『sip show peers』を実行するプログラムを書いてみました。
ダウンロードはここ→
redHatLinuxES4で実行確認しました。
適当なフォルダにパッケージを解凍してください。
[root@asterisk1 asterisk_manager_api]# make
gcc -g -Wall -DLINUX_REDHAT -DFVERSION='"VER.1.20070324"' -I. -c program_main.c -o program_main.o
gcc -g -Wall -DLINUX_REDHAT -DFVERSION='"VER.1.20070324"' -I. -c sub_signal.c -o sub_signal.o
gcc -g -Wall -DLINUX_REDHAT -DFVERSION='"VER.1.20070324"' -I. -c sub_read_config.c -o sub_read_config.o
gcc -g -Wall -DLINUX_REDHAT -DFVERSION='"VER.1.20070324"' -I. -c sub_read_args.c -o sub_read_args.o
gcc -g -Wall -DLINUX_REDHAT -DFVERSION='"VER.1.20070324"' -I. -c sub_logput.c -o sub_logput.o
gcc -g -Wall -DLINUX_REDHAT -DFVERSION='"VER.1.20070324"' -I. -c sub_strdate.c -o sub_strdate.o
gcc -g -Wall -DLINUX_REDHAT -DFVERSION='"VER.1.20070324"' -I. -c sub_strip_enter.c -o sub_strip_enter.o
gcc -g -Wall -DLINUX_REDHAT -DFVERSION='"VER.1.20070324"' -I. -c sub_nettools.c -o sub_nettools.o
gcc -g program_main.o sub_signal.o sub_read_config.o sub_read_args.o sub_logput.o sub_strdate.o sub_strip_enter.o sub_nettools.o -o asterisk_srv -lm -lnsl -ldl
次に、設定ファイル(astmgr.cfg)を編集します。
dir_logdir | ログを出力する場所 |
ast_host | asteriskのIPアドレス |
ast_port | ManagerAPIのポート番号(5038) |
これで、実行できます。やってみましょう。
[root@asterisk1 asterisk_manager_api]# ./asterisk_srv -cfg astmgr.cfg
2007/03/24 12:14:31 [D] ( program_main.c:0045) NORMAL 9233 : ===== Asterisk Server Control (VER.1.20070324) Start ================
2007/03/24 12:14:31 [D] ( program_main.c:0046) NORMAL 9233 : Asterisk Host: 127.0.0.1
2007/03/24 12:14:31 [D] ( program_main.c:0047) NORMAL 9233 : Asterisk Port: 5038
2007/03/24 12:14:31 [D] ( program_main.c:0070) NORMAL 9233 : connected to asterisk (127.0.0.1,5038)
2007/03/24 12:14:31 [D] ( program_main.c:0105) NORMAL 9233 : SEND:(Action: Login Username: astmgr Secret: astmgr )
2007/03/24 12:14:31 [D] ( program_main.c:0197) NORMAL 9233 : Received: (Asterisk Call Manager/1.0 )
== Parsing '/etc/asterisk/manager.conf': Found
== Manager 'astmgr' logged on from 127.0.0.1
2007/03/24 12:14:31 [D] ( program_main.c:0197) NORMAL 9233 : Received: (Response: Success )
2007/03/24 12:14:31 [D] ( program_main.c:0197) NORMAL 9233 : Received: (Message: Authentication accepted )
2007/03/24 12:14:31 [D] ( program_main.c:0197) NORMAL 9233 : Received: ( )
2007/03/24 12:14:31 [D] ( program_main.c:0227) NORMAL 9233 : socket read complete
2007/03/24 12:14:31 [D] ( program_main.c:0131) NORMAL 9233 : SEND:(Action: Events Eventmask: On )
2007/03/24 12:14:31 [D] ( program_main.c:0150) NORMAL 9233 : SEND:(Action: Sippeers )
2007/03/24 12:14:31 [D] ( program_main.c:0197) NORMAL 9233 : Received: (Response: Success )
2007/03/24 12:14:31 [D] ( program_main.c:0197) NORMAL 9233 : Received: (Message: Peer status list will follow )
2007/03/24 12:14:31 [D] ( program_main.c:0197) NORMAL 9233 : Received: ( )
2007/03/24 12:14:31 [D] ( program_main.c:0227) NORMAL 9233 : socket read complete
2007/03/24 12:14:31 [D] ( program_main.c:0197) NORMAL 9233 : Received: (Event: PeerEntry )
2007/03/24 12:14:31 [D] ( program_main.c:0197) NORMAL 9233 : Received: (Channeltype: SIP )
2007/03/24 12:14:31 [D] ( program_main.c:0197) NORMAL 9233 : Received: (ObjectName: 5002 )
2007/03/24 12:14:31 [D] ( program_main.c:0197) NORMAL 9233 : Received: (ChanObjectType: peer )
2007/03/24 12:14:31 [D] ( program_main.c:0197) NORMAL 9233 : Received: (IPaddress: -none- )
2007/03/24 12:14:31 [D] ( program_main.c:0197) NORMAL 9233 : Received: (IPport: 0 )
2007/03/24 12:14:31 [D] ( program_main.c:0197) NORMAL 9233 : Received: (Dynamic: yes )
2007/03/24 12:14:31 [D] ( program_main.c:0197) NORMAL 9233 : Received: (Natsupport: yes )
2007/03/24 12:14:31 [D] ( program_main.c:0197) NORMAL 9233 : Received: (ACL: no )
2007/03/24 12:14:31 [D] ( program_main.c:0197) NORMAL 9233 : Received: (Status: UNKNOWN )
2007/03/24 12:14:31 [D] ( program_main.c:0197) NORMAL 9233 : Received: ( )
2007/03/24 12:14:31 [D] ( program_main.c:0227) NORMAL 9233 : socket read complete
2007/03/24 12:14:31 [D] ( program_main.c:0197) NORMAL 9233 : Received: (Event: PeerEntry )
2007/03/24 12:14:31 [D] ( program_main.c:0197) NORMAL 9233 : Received: (Channeltype: SIP )
2007/03/24 12:14:31 [D] ( program_main.c:0197) NORMAL 9233 : Received: (ObjectName: 5001 )
2007/03/24 12:14:31 [D] ( program_main.c:0197) NORMAL 9233 : Received: (ChanObjectType: peer )
2007/03/24 12:14:31 [D] ( program_main.c:0197) NORMAL 9233 : Received: (IPaddress: -none- )
2007/03/24 12:14:31 [D] ( program_main.c:0197) NORMAL 9233 : Received: (IPport: 0 )
2007/03/24 12:14:31 [D] ( program_main.c:0197) NORMAL 9233 : Received: (Dynamic: yes )
2007/03/24 12:14:31 [D] ( program_main.c:0197) NORMAL 9233 : Received: (Natsupport: yes )
2007/03/24 12:14:31 [D] ( program_main.c:0197) NORMAL 9233 : Received: (ACL: no )
2007/03/24 12:14:31 [D] ( program_main.c:0197) NORMAL 9233 : Received: (Status: UNKNOWN )
2007/03/24 12:14:31 [D] ( program_main.c:0197) NORMAL 9233 : Received: ( )
2007/03/24 12:14:31 [D] ( program_main.c:0227) NORMAL 9233 : socket read complete
2007/03/24 12:14:31 [D] ( program_main.c:0197) NORMAL 9233 : Received: (Event: PeerlistComplete )
2007/03/24 12:14:31 [D] ( program_main.c:0197) NORMAL 9233 : Received: (ListItems: 2 )
2007/03/24 12:14:31 [D] ( program_main.c:0197) NORMAL 9233 : Received: ( )
2007/03/24 12:14:31 [D] ( program_main.c:0227) NORMAL 9233 : socket read complete
== Manager 'astmgr' logged off from 127.0.0.1
|