Sync MySQL table with "sip show peers"

7 posts / 0 new
Last post
black187
black187's picture
Sync MySQL table with "sip show peers"

Hello,

Anybody has an idea, how to sync "sip show peers" with a table in MYSQL.

I already have a script made to write from result of "sip show peers" to MYSQL table (peer, IP address...).

But how can I know if an admin deletes peer from FreePBX. How can I get this information to update the MySQL table, that the peer is deleted?

Right now I use "Truncate table..." (delete the table) before I make an "insert into...". But it is not a good solution. Instead of "Truncate" I would like to check if there is any changes in peers ...

p_lindheimer
p_lindheimer's picture
what are you actually trying

what are you actually trying to do with the mysql table?

black187
black187's picture
I have a table, which is

I have a table, which is populated with Asterisk peers (I use command sip show peers, and extract the peers to put it in the table). This script is run every 10 minutes.

The problem I have -> when I delete an extension in FreePBX, I don't know how to check it - to see if it was deleted. Therefore I have the deleted extension still in my table.

Is it possible to compare the array which I get from "sip show peers" to the table, and see if there is any differences?

I probably shouldn't put this question here - it would be more appropriate to ask this question to some PHP forum...

SkykingOH
SkykingOH's picture
The question was asked, what

The question was asked, what are you doing with the data?

The purpose was to suggest a better way to accomplish what you are doing.

Could you please briefly explain your application for the data?

Scott Holtzman, CTO
Micro Advantage, Inc.

  • Hosted Open Source FreePBX
  • Hosted PBXTended
  • On Net connections for Time Warner and other Major Carriers
  • Asterisk FreePBX Consulting

    http://www.microadv.com

black187
black187's picture
Monitoring system. Right now

Monitoring system. Right now it will be made as an external app, but when all is done it will be FreePBX module.

I check all SIP users on the system (extension number, IP, port which is registered on, useragent, registration status) via parsing of "sip show peers" and "sip show peer XXX". And check their availability every 2 minutes (or some other time frame) via ping and via checking if the registration port is open (I did a similar system for Aastra SIP phones).

The main core of the app is made (colecting the data and writing it to Mysql table), now I'm stuck at syncing the SIP users - if a SIP user is deleted from FreePBX, how can I delete it from my Mysql table?

One solution would be, that when i check my extension (one by one) from my MySQL table, and the compare them to "sip show peers", or "sip show peer XXX" and delete the one which is not there. But I don't think this is a good solution for a system with a lot of extensions (too many queries...). It has to be more optimal way to do it.

SkykingOH
SkykingOH's picture
Have you looked at the

Have you looked at the structure of the Asterisk database in FreePBX? You should just pull the trunks from their.

Look at the 3rd party trunk utilization module (see how they populate the trunk drop box) for a coding example.

Scott Holtzman, CTO
Micro Advantage, Inc.

  • Hosted Open Source FreePBX
  • Hosted PBXTended
  • On Net connections for Time Warner and other Major Carriers
  • Asterisk FreePBX Consulting

    http://www.microadv.com

black187
black187's picture
Hmm, I have looked and it

Hmm, I have looked and it should work - but the system will be designed (at first) to also work without FreePBX - just Asterisk.

And thanks for the advice - third party trunks... I will look at it..