Asterisk headcount monthly on registered extensions

Hi guys

Has anyone implemented a successful headcount script on FreePBX or Asterisk?
We need a monthly report on how many extensions was registered on FreePBX / Asterisk.

Please advise if anyone has any info on how to go about implementing something like this and store the values in a database somewhere.


A lot depends on how you want the information to be “vetted”. To start, what definition of “registered” are you looking for? Specific extensions, or phones? Do they need to have been in a call (originated or received) or just connected to the system? Do you want to know how many instruments were connected to that extension (by IP address, for example)? Are there other things you want to know about this connectivity?

The specificity of the what you are looking for will determine which logs and/or tables need to be referenced to get the information you are looking for.

Hi and thank you for your reply. I am looking to report on extensions registered on the system in the month with a seperate report for extensions that made calls for that month.

Thank you

Unless there’s a commercial module, the short answer is “not yet.”

Getting the registration information is simple enough - the would grep through the /var/log/asterisk/full log every day and put the “usual suspects” into a table somewhere. You might be able to get that info from the asteriskceldb database (since registering could be considered a Call Event).

The “call” information would come from the asteriskcdrdb database (or again asteriskceldb) and get the number of calls made and/or received from a specific extension.

The “full” log would be the hard way. If you can get what you are looking for the cdr or cel databases, it should be trivially simple.

So, this got me curious on how I would do this…
first question was “How do I know when an extensions connects?”
Well, that was solved with this:

 # cat /var/logs/asterisk/full | grep 'is now Reachable'

So… that got me the general idea… now to just break it down and get a list, sorted, and de-duplicated…

# cat /var/log/asterisk/full | grep 'is now Reachable' | grep -o -P "(?<=').*(?=')" | sort | uniq

Gives me a nice, pretty list of all the extensions that have logged on. Needless to say, you would need to filter for your date range…

So… final output… it’s not pretty… but it’s functional… by piping greps together…

#cat /var/log/asterisk/full | grep '2018-08' | grep 'is now Reachable' | grep -o -P "(?<=\').*(?=')" | sort | uniq

To break it down between the pipes…
Cat the full log, look for the year and month stamp… look for the words “is now reachable” in that… then strip out JUST the extension number, sort it, and then return just the unique values. All one line of code…

Mmm… one final note… if you want a COUNT of those extensions, in addition to the extensions, do this; the last number will be the count of extensions that registered.

# cat /var/log/asterisk/full | grep '2018-08' | grep 'is now Reachable' | grep -o -P "(?<=\').*(?=')" | sort | uniq | tee /dev/tty | wc -l

|tee /dev/tty |

does what ?

It’s kind of a cheat… without it, you would just get the count, and not the extensions.

Normally, tee would output to a file (in addition to the output of the command)… however, in this case, sending the tee to /dev/tty appends the wc -l to the output from the command. :smiley:

you might better using /dev/stdout or /dev/console , tty’s are kinda of different in an esoteric way

Well, I did test it on my box… ssh through Putty…

But I digress… does it do what the OP needed done? (well, the first part anyway… number of calls is a whole different aminal.) :smiley:

Thank you all for your comments.
I will not be able to use the full log as we have automated scripts that do logger rotate weekly and deletes old logs. I was thinking more along the lines of asterisk -rx ‘sip show peers’ | grep OK and using aux {print} to get the info. But what I need assistance with would be to store the info in mysql so that I can pull reports on the COUNT per month that was registered without any dups.

The idea is that if a phone was plugged in and it registered even for a minute it needs to ad that ext to a table with all the other extensions that was registered.
That way I can query the count each month to get the total exts that was registered.

I just need assistance to put my theory into something real and that will work.

Thanks again for everyone’s input thus far.

Hmmm… you asked for a script. I gave you a script.

Now you want it to write to sql…

Use inotify and run in the background fileter script

This is already present, in Dashboard. Registered extensions is one of the variables that’s archived for usage stats.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.