As a result of this thread a few weeks ago, I was reminded once again that
- I don’t have much in the way of practical knowledge of how the Asterisk AMI works and
- There is no simple resource to monitor a FreePBX phone dev state in real time
Since I’ve occasionally needed something like this, and since I was cooped up in quarantine and on vacation simultaneously, I set out to remedy those two problems. The result is this script:
In it’s present form, nobody would call it elegant. As my goal was largely to learn more about the AMI, it doesn’t do much. When you run it, every time an extension hint changes it echos to the console:
exten: 5002 status: 1 statustext: InUse
exten: 5002 status: 0 statustext: Idle
exten: 5002 status: 1 statustext: InUse
exten: 5004 status: 8 statustext: Ringing
exten: 5004 status: 1 statustext: InUse
exten: 5002 status: 0 statustext: Idle
exten: 5004 status: 0 statustext: Idle
I have a vague sense that PHP is not the best language for this purpose, but I didn’t need to saddle myself with learning a new language as well as the AMI. And as the saying goes, “If your only tool is a hammer …”
Anyone who wants to give it a try is welcome to do so by:
cd /tmp
wget https://gist.githubusercontent.com/lgaetz/64ad83952a2a629204222e48fc01bb51/raw/dc6216ec068c3a704dc4c2ec0bf51a74581a8eb2/lgaetz-hinterland.php
chmod +x lgaetz-hinterland.php
./lgaetz-hinterland.php
Make some calls and watch the console. Comments, corrections, etc. cheerfully received.