Maybe this could be useful to somebody else.
We have a large number of branch units (about 100), each one with its own proprietary PBX that send its CDR/SMDR to a centralized collector. The layout of each CDR stream collected is, once configured, automatically handled.
The transmission method is really simple: The remote PBX opens a socket connection to the collector on some fixed TCP port and send the CDR as it is being generated, one line at a time. The collector accepts connections from previously configured IP addresses only and, since the collector as well as all PBX’s are on a private network, there is no need for additional security measures.
We are now in a process of replacing those proprietary PBX by Asterisk appliances (home built under NanoBSD), and this is how we integrated the basic CDR generated by Asterisk into our legacy centralized collector.
This little script goes into /usr/local/bin/send-cdr.sh :
#!/bin/sh
DESTINATION="192.168.x.y" # the IP address or hostname of the collector
DSTPORT="12345" # the TCP port where the collector expect to receive CDR
A1="/var/log/asterisk/cdr-csv/Master.csv"
A2="/var/log/asterisk/cdr-csv/CDR.csv"
A3="/var/log/asterisk/cdr-csv/backup-cdr.csv"
if [ -s $A2 ]; then
if ping -q -c3 $DESTINATION >/dev/null; then
if nc -N $DESTINATION DSTPORT < $A2; then
mv $A2 $A3
if [ -s $A1 ]; then
mv $A1 $A2
fi
fi
fi
else
if [ -s $A1 ]; then
mv $A1 $A2
fi
fi
(make executable with chmod +x send-cdr.sh)
This line was entered into the command crontab -e :
*/1 * * * * /usr/local/bin/send-cdr.sh
(check the manual page of this command if you are not familiar with it)
- The send-cdr.sh script will be executed every minute.
- On every iteration the local CDR file is sent to the remote collector and kept just until the next iteration.
- When the collector is not reachable or refuses the connection, the script waits for the next iteration to retry.