Connection Logging has almost always been possible in one form or another.
A recent post made me revisit this.
I had a elaborate logging scheme I built for my servers that was not going to work under asl3.
So, because of that recent post I went back to the basics that have always been there and tested them with asl3.
If you are currently using conpgm or discpgm, you may need to find a method to insert them in your existing scripts.(likely at the very beginning of them)
But here it is in a nutshell basic format for you to alter for your own use.
I created 2 shell scripts conlog.sh and dislog.sh
(I place my scripts in /etc/astersk/myscripts)
Here are the function lines in rpt.conf
connpgm = /etc/asterisk/myscripts/conlog.sh ;
discpgm = /etc/asterisk/myscripts/dislog.sh ;
So you will need to insert this for each node you want logging. And, if needed, you can change the log file name for different nodes. But I find it better to only use one file. None of my nodes have high level of connections. One file is easy to sort/find and manage.
Here is conlog.sh
#!/bin/bash
echo $1 connected $2 on $(date +"%T") - $(date +"%m-%d-%Y") >> /var/www/html/nodelogs/conlog.txt
And dislog.sh
#!/bin/bash
echo $1 disconnected $2 on $(date +"%T") - $(date +"%m-%d-%Y") >> /var/www/html/nodelogs/conlog.txt`.
To explain how this works a bit, the two built-in app_rpt functions conpgm and discpgm pass 2 parameters to the script. The first is the node it is seated from ($1) and the second is the external node ($2) that is connecting or disconnecting.
Now in my simple example use,
both shell scripts write to the same file for easy understanding.
I personally use the web/html directory for stuff like this so I can access it from my smartphone when needed. An extra for you ? You need Apache or equivalent installed for that.
So, for this to work, your shell scripts need to be owned by asterisk and have the rights to execute.
see also
The log file output may also need rights for you to view it depending on your chosen method.
The output of the file will look like this…
48234 connected 29284 on 05:19:56 - 01-01-2025
48234 disconnected 29284 on 05:21:17 - 01-01-2025
You will have to alter this to fit your own need or use, but I would make it work as is (if possible) before you start changing anything.
That is as simple example as I can make on short time.
Most problems you might run into are typo’s and file permissions/rights.
Hope that get some wheels turning for you to understand more of how to make your own stuff. Enjoy !