Claim your Biolink Click Here
0 like 0 dislike
3.8k 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?
in Education & Reference by | 3.8k 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

 

by (4.7k points)
selected by
0 0

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
asked Jul 7, 2014 in Education & Reference by Bhoomika (-30 points) | 27.4k views
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
asked Mar 30, 2014 in Computers & Internet by Yogi (460 points) | 426 views
0 like 0 dislike
0 answers
0 like 0 dislike
2 answers
asked Jun 19, 2014 in Education & Reference by Bhoomika (-30 points) | 224 views
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
asked Aug 12, 2013 in Education & Reference by stephen | 3.3k views
0 like 0 dislike
1 answer
0 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

1,310 questions
1,471 answers
569 comments
4,809 users