FreePBX System Status

Hello Friends,
So i would like to know how FREEpbx get the system status in the main page. Especialy the FreePBX Statistics, who that know that x trunk id are registred ? Its get info from the database asterisk ? or from a file ?

Advance thanx,

From the Asterisk manager interface.

You can also get the data from the Asterisk SNMP MIB OID’s

Thanx for your reply SkykingOH but i would like to know how it work, because i’ve created a web interface to create in a simpliest way the trunk, and at the last i would like to make a scripts that check if the trunk is registred.

I just told you the two interface methods. Using SNMP, the standard for metric collection or the AMI (Asterisk Manager Interface).

Take a look at the Asterisk documentation, AMI is a simple socket connection.

As far as SNMP many web interfaces are available including PHP libraries.

Here is the path to the MIB’s you can at least walk them and see what data is available.

/usr/src/asterisk/doc/asterisk-mib.txt /usr/share/snmp/mibs/ASTERISK-MIB.txt
/usr/src/asterisk/doc/digium-mib.txt /usr/share/snmp/mibs/DIGIUM-MIB.txt

Thanx, we don’t have installed SNMP, so i will search with the AMI method

At last, i’ve found that the AMI method open a file, and make an array, but i can’t find the name of the file, do someone know that ?

advance thanx,

I don’t understand either of your comments. SNMP is not something you have or don’t have. The net is replete with free managers and plug ins.

Second AMI is socket based, it doesn’t use files and the output is ascii not an array.

Sorry for my bad english, i’m from france…

I search those files but they don’t exist, and so my boss say that we don’t have snmp…
/usr/src/asterisk/doc/asterisk-mib.txt /usr/share/snmp/mibs/ASTERISK-MIB.txt
/usr/src/asterisk/doc/digium-mib.txt /usr/share/snmp/mibs/DIGIUM-MIB.txt

I’m trying to know how the System status, especialy the trunks register work, with AMI…

Just an idia, can i make a “sip show registry” with cli in php ?

You can do the show registry via the AMI.

It also sends an event on registration.

Have you read any documentation on AMI?

Some links:

Yes i’ve read some documentation, about asterisk, AMI …

I’ve write a few lines, but it says me " Asterisk Call Manager/1.1 Response: Error Message: Authentication failed "

The lines was :
$errno = “”;
$errstr = “”;
$timeout = 10;

$socket = fsockopen(“192.XXX.XX.XX”,“5038”, $errno, $errstr, $timeout);
fputs($socket, “Action: login\r\n”);
fputs($socket, “Username: admin\r\n”);
fputs($socket, “Secret: XXXXX\r\n”);
fputs($socket, “Action: Command\r\n”);
fputs($socket, “Command: sip show registry\r\n\r\n”);

while (!feof($socket)) {
$wrets .= fread($socket, 4096);

echo $wrets;

I checked the file manager.conf, the admin text lines are there, but i can’t connect to the socket …don’t understand why, i check the secret and the username … maybe my script is wrong but i don’t see anyting wrong …

here is my manager.conf file :

secret = XXXXX
read = system,call,log,verbose,command,agent,user,config,command,dtmf,reporting,cdr,dialplan,originate
write = system,call,log,verbose,command,agent,user,config,command,dtmf,reporting,cdr,dialplan,originate

Are you running this program on the FreePBX server? If you are not then you will need to modify the permit= to allow the system you are running the program on to have access.

What language are you writing this in?

yes i’m running this program on the FreePBX server, yes the permit is permit= …

i’m using php …

now it show me just "Asterisk Call Manager/1.1"
it don’t show me the response for “sip show registry” …

Did you reload manager after adding administration user. You can debug from asterisk click.

Yes, i’ve forgot to reload manager…now the problem is that my script take arround 1min to show me the page, with the lines "Asterisk Call Manager/1.1"
The connection is ok, but it won’t show me the registry …

my script is :
$errno = “”;
$errstr = “”;
$timeout = “1”;

$socket = fsockopen(“192.XXX.XX.XX”,“5038”, $errno, $errstr, $timeout);
fputs($socket, “Action: Login\r\n”);
fputs($socket, “Username: admin\r\n”);
fputs($socket, “Secret: XXXXXX\r\n”);
fputs($socket, “Action: Command\r\n”);
fputs($socket, “Command: sip show registry\r\n”);

while (!feof($socket)) {
$wrets .= fread($socket, 4096);

echo $wrets;

You are opening your socket to but your permit only allows permit= Try opening the socket on

I’ve tried this, but still same time execution and same display …

I am running your script on my system and get no output. I did an amportal restart and got output. I am wondering if the while loop is not seeing the EOF for the socket.

When talking to the Asterisk AMI the last command sent to it needs to be terminated with two end of lines. Or you can read that as “an empty line” signals the AMI to process the request.

Pretty complete documentation including links to example code (with more complete error checking) at

If you are running this script on a freepbx 2.10+ server then this little script below is actually the easiest method.

<?php if ([email protected]_once(getenv('FREEPBX_CONF') ? getenv('FREEPBX_CONF') : '/etc/freepbx.conf')) { include_once('/etc/asterisk/freepbx.conf'); } if($astman->connected()) { $out = $astman->Command('sip show registry'); echo $out['data']; } else { echo "not asterisk manager connection"; } ?>

Thanx tm1000, and thanx all