Monday, June 8, 2020

Asterisk AMI & AstDB (initial steps + Python connect)

First time AMI setup

vi /etc/asterisk/manager.conf minimal configuration required:
[general]
enabled = yes ;AMI
webenabled = no ;AJAM
httptimeout=120
port = 5038
bindaddr = 0.0.0.0
tlsenable=no
[admin]
secret=My$ecr3t
read=all
write=all

Test over telnet:

Wait till connected:
telnet 127.0.0.1 5038

Send below commands:
Action: Login
Username: admin
Secret: My$ecr3t
Events: off

"Enter" twice to get:
Response: Success
Message: Authentication accepted

To logoff:
Action: logoff

AstDB

To view needed permissions:
CLI> manager show commands

To write into astdb:
Action: DBPut
Family: TEST
Key: WhatEverYouWant

DBDel and DBGet are working in the same manner as DBPut above.

Python to AstDB connect

import sqlite3 # it's standard library

Learn name of the table and its structure:
connector = sqlite3.connect("/var/lib/asterisk/astdb.sqlite3")
cursor = connector.cursor()
cursor.execute("select sql from sqlite_master where type = 'table'")
print(cursor.fetchall())

cursor.close()
con.close()

No comments:

Post a Comment