Does Asterisk contain extension details in a MySQL DB like the call details?


(Chasemixon) #1

Many years ago I wrote a simple VBS Script that pulled the call details for a group of extensions for integrating into a reporting program. I would like to expand on that to create my config files for my phones, but I wasn’t sure if the extension details are in the mysql db or if they are just in the conf files. Thanks in advance!


(Joshua C. Colp) #2

Are you referring to FreePBX? Asterisk and FreePBX are two separate things, and Asterisk itself can be configured to be used in different ways.


(Chasemixon) #3

I know they are two different things, but I’m not sure which one is the correct one… LOL but whatever the extension configs are stored in? I guess what I’m trying to ask is does either have a DB in mysql that I could query and get the extension details from… like Select * from extension table where ID = myext and write a config file?
like something like this?
!sip user name: 2411
!sip auth name: 2411
!sip password: secretpassword
!sip registration period: 60


(Joshua C. Colp) #4

FreePBX does, Asterisk doesn’t unless configured to use that mechanism or if it is configured by a GUI that stores such information in a database (as is the case for FreePBX). I do not know where FreePBX stores such information.


(Chasemixon) #5

I’m not 100% but I did find the SIP table in the DB asterisk seem to have what I need to get started anyway… I could be wrong but it looks good at first glance…


(Chasemixon) #6

in the asterisk gui it has an asterisk info page where I can see all kinds of good info, do you know if that is stored anywhere, I went through all the tables in asterisk and didn’t see it.


(Jared Busch) #7

This is the FreePBX community, not the Asterisk community. Unless Sangoma is planning to merge them, then you need to be thinking more about FreePBX than Asterisk.

Every single user fillable field in the FreePBX GUI is stored in the MySQL/MariaDB database.


(Jared Busch) #8

You need to be more specific in what you want.

You can start with devices


(Chasemixon) #9

sorry should have put that in there, I’m looking for the IP addresses of the devices or MAC address actually…


(Jared Busch) #10

Those do not exist in FreePBX.

If you have the EndPoint Manager commercial module, and use it for all provisioning, you will find the MAC addresses there.


(Chasemixon) #11

:blush: I was kinda trying to build my own… lol but that’s ok, at least I can get the config files built, I’ll just have to find the mac address of phone and copy and paste the config into that file.


(Jared Busch) #12

You always have to know the MAC address of the phone in order to create a provisioning file. The phones use their mac address as part of the file name they request. There is no way to shortcut that. You cannot simply pull them out of no where.


(Chasemixon) #13

yea, that’s true, I wasn’t thinking about that… :roll_eyes:


(TheJames) #14
ip neighbor | awk '{print $1 ", " $5}'

prints

192.168.X.XX, AA:BB:CC:DD:EE:FF
192.168.X.XX, 11:22:33:44:55:66

tl;dr the arp table has all the mac addresses your server knows about on your network. You can parse the data with your language of choice and associate mac -> phone by IP.


(Lorne Gaetz) #15

This is not true. Most GUI field values are written to MySQL, but many are only written to AstDB and a small number of values are parsed from and written directly to conf files.


(Chasemixon) #16

Thanks! I had thought about that, but with my network connected via VPN’s I’m not sure how I could integrate that into my script to create config files. A+ for effort… :smile:


(Chasemixon) #17

is AstDB accessible? I didn’t see that one listed when I did Show Databases;


#18

It is an sqlite3 database at

/var/lib/asterisk/astdb.sqlite3

you can install sqlite3(client) if you want to get to it from bash, BUT, writing or even reading to it from it bash while asterisk is running can set up a nasty lock condition that is very hard to fix as asterisk access to it it is thread safe but NOT multiuser safe, I suggest you use the asterisk cli “database (tab until happy)” process, from bash . .

rasterisk -x 'database show' (del , deltree, get, put, query, show, showkey)


(Chasemixon) #19

thanks to all who helped! I have it working, and it does what I need it to do, create the cfg files for each extension, we only use one type of phone here. If anyone would like I created a github page for the project… Thanks Lorne! you’re awesome… :slight_smile:


(Lorne Gaetz) #20

If you have something to share, upload it to Github, include licensing details and link it here.