ASL3 Connection Logging EXAMPLE HERE

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 !

1 Like

You can also get this data into /var/log/asterisk/messages.log by editing /etc/asterisk/logger.conf and changing the line

messages.log => notice,warning,error,dtmf

to

messages.log => notice,warning,error,verbose,dtmf

and restarting asterisk.The verbose argument can also take an integer e.g. verbose(3) to fine tune…

You can get this data into the asterisk CLI console by using the command

logger set level VERBOSE on

and

logger show channels

to see what’s being logged by level.

1 Like

Mike,

Great info for logging…

For those of us which use Supermon, I would interested to know if you considered using its connection logger. In my rpt.conf for connpgm and discpgm, I use /usr/local/sbin/supermon/smlogger 1 or 0

If you have used this logger, was there a reason why you chose to use a script instead.

I don’t use supermon. I do still use allmon2 so others can see what connection structures are. And I have wrote my own management interface that does not require loading more software to have to many monkeys turning wrenches in the same barrel…LOL
Personal preference only. Not suggesting against it in any way.

But as I always say, with asterisk, there is always more than one way to do a task, not that some are not difficult.

Even the script above is much different than what I wrote for myself. But it does write to a file I view on the web for a quick look.
I tend to only post the principle for others to follow for their own use as I’m not supporting it something more complex that less people will use. Taylor it for yourself. This was totally uncomplicated and some will likely make some notable improvements and perhaps start using the conpgm discpgm for other useful things since it has been explained and demonstrated a bit better…

As always, one size does not fit all. There is a strong force folks try to give to write something specifically for their needs.(not understanding time constraints) And I would rather encourage others to write something useful. Even if it is not for everyone. At least post the principle.

I have to re-rwrite many of my old toys for ASL3 so, I may post more.
But my systems are heavy on phone and remote control stuff. Not all ham radio.
A bunch of changes with asterisk broke a good many of them when the upgrade happened., just from a change in syntax. (most of my servers still use v1.01)
Takes time to sort through them all and I am trying to retire and taking as much money before hand as they offer me to keep me around LOL.
Just a little reflection as we charge into a new year. Life still gets in the way of the fun stuff.