0 like 0 dislike
2,200 views
I am new to asterisk and I want to show active calls on a PHP page and I am using asterisk 11, can anyone tell me the way how it works?
asked Jul 29, 2013 in Education & Reference by Joseph | 2,200 views
    

1 Answer

0 like 0 dislike
Best answer

1. Query asterisk CLI with active_channels.sh script:

#! /bin/sh

stamp=`date "+%Y/%m/%d %H:%M:%S"`
calls=`/usr/sbin/asterisk -rx 'show channels' | grep "active call"`
channels=`/usr/sbin/asterisk -rx 'show channels' | grep "active channel"`
sip_total=`/usr/sbin/asterisk -rx 'sip show users' | wc -l`
sip_online=`/usr/sbin/asterisk -rx 'sip show peers' | grep OK | wc -l`

echo "$calls" > /var/www/html/services/active_channels.php
echo "$channels" >> /var/www/html/services/active_channels.php
echo "$sip_total" >> /var/www/html/services/active_channels.php
echo "$sip_online" >> /var/www/html/services/active_channels.php
echo "$stamp" >> /var/www/html/services/active_channels.php

sed -i 's/active calls//g' /var/www/html/services/active_channels.php
sed -i 's/active channels//g' /var/www/html/services/active_channels.php

 

The output data will be saved to active_channels.php file.


2. Run the script every minute (crontab -e)
* * * * * /...absolute path to your script.../active_channels.sh

 

answered Jul 30, 2013 by Marc (2,430 points)
selected Jul 30, 2013 by Marc

3. Process the output file in index.php

<?php

echo "<head>";
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"progress_bar.css\">";
echo "<meta http-equiv=\"Refresh\" content=\"45\">";
echo "</head>";
echo "<body>";

$filename = "active_channels.php";
$fp = @fopen($filename, "r");
if ($fp) { $array = explode("\n", fread($fp, filesize($filename))); }

$calls = $array[0];
$channels = $array[1];
$sip_total = $array[2];
$sip_online = $array[3];
$stamp = $array[4];

// progress bar maximum
$max_channels = 40;
///////////////////////

$bar_calls = ($calls * 200) / $max_channels;
$bar_channels = ($channels * 200) / $max_channels;
$bar_sip = ($sip_online * 200) / $sip_total;

if ($bar_calls >= 155) { $bar_calls_colour = "bar_yellow.gif"; }<br style="margin: 0px; padding: 0px; color: rgb(46, 139, 87); font-family: Monaco, 'Andale Mono', 'Courier New', Courier, mono; line-height: 1

Related questions

0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
asked Mar 30, 2014 in Computers & Internet by Yogi (180 points) | 66 views
0 like 0 dislike
0 answers
0 like 0 dislike
2 answers
asked Jun 19, 2014 in Education & Reference by Bhoomika (50 points) | 35 views
0 like 0 dislike
1 answer
asked Sep 12, 2013 in Education & Reference by Sidh | 1,030 views
0 like 0 dislike
1 answer
asked Aug 12, 2013 in Education & Reference by stephen | 2,668 views
0 like 0 dislike
1 answer
1 like 0 dislike
1 answer

Where your donation goes
Technology: We will utilize your donation for development, server maintenance and bandwidth management, etc for our site.

Employee and Projects: We have only 15 employees. They are involved in a wide sort of project works. Your valuable donation will definitely boost their work efficiency.

How can I earn points?
Awarded a Best Answer 10 points
Answer questions 10 points
Asking Question -20 points

Mathe Forum Schule und Studenten
1,179 questions
1,319 answers
277 comments
1,638 users