How To Roll-over / Move / Rotate An Asterisk Master.csv Call Detail Record (CDR) File Every 15 Minutes

Home » Asterisk Users » How To Roll-over / Move / Rotate An Asterisk Master.csv Call Detail Record (CDR) File Every 15 Minutes
Asterisk Users 14 Comments

If you are trying to provide CDR files to a billing service, such as WebCDR.com, you need to provide files containing your latest call data every 15 minutes or so. I wrote a script and a cron job that will create a new CDR file every 15 minutes with the latest CDR records, without interrupting call flow. You do not need to make any changes to your Asterisk configuration to use these scripts.

There are two files that you need to install on your Asterisk server:

asterisk-cdr-rollover.sh

14 thoughts on - How To Roll-over / Move / Rotate An Asterisk Master.csv Call Detail Record (CDR) File Every 15 Minutes

  • IIRC log rotate only rolls the files in /var/log/asterisk, not
    /var/log/asterisk/cdr-csv

    —–Original Message—

  • I have a huge logrotate config file and I use Webmin to manage it all.

    Actually, Webmin is a good all-around system management tool, in my opinion.

  • man logrotate.conf #?

    Just list the files you want to rotate in /etc/logrotate.d/asterisk
    (or whereever).

  • I was confusing the linux function logrotate with the asterisk function
    “logger rotate”.

    —–Original Message—

  • Paul:

    Four reasons not to use logrotate:

    1. logrotate does not provide log rotation every 15 minutes.

    2. logrotate will not create unique file names unless you use a date format in the name (file names with a .nnn extension get reused over time), but since logrotate only supports YYYYMMDD, not hours, minutes, or seconds, once again you’re limited to daily roll-overs.
    (asterisk-cdr-rollover generates file names using the format cdr-YYYYMMDDHHMISS.csv.)

    3. My customers need to be able to feed CDR files into a telecom billing, monitoring, fraud-detecting system I work on called WebCDR.com, which works best if it gets a new CDR file every fifteen minutes.

    4. If there are no calls after 15 minutes, with asterisk-cdr-rollover I
    get a zero byte file, which can trigger a “no calls” alarm, alerting me that something is wrong with the Asterisk switch. (The switch setup I’m working will always have some calls within a 15 minute block if everything is working correctly, although people with less-busy switches can always configure a larger alarm window to suit their situations.) If you’re running a high-traffic switch, this can be a life-saver.

    If you want a copy, go to https://github.com/earlruby/asterisk-cdr-rollover and click the ZIP
    button to download the script and cron job. It’s free.

    — Earl

  • apt-get install logtail

    logtail2 – print log file lines that have not been read

    Every 15 minutes use it to get the new lines from the CSV file. Rotate it when needed with logrotate.

  • Sure it does, you can invoke it using crontab, like you do for your script.

    Not so, logroate actually supports strftime %s, so you get the number of seconds since the Epoch. Easily converted into any datetime format you wish.

    postrotate/endscript should work for this.

    No native support, but you could invoke logic using postrotate/endscript from above.

    Understood. If it works for you that is great, I was mostly trying to understand why you choose to rewrite logrotate 🙂

  • What’s the logrotate dateformat string that generates YYYYMMDDHHMISS?
    According to the man page, it doesn’t support that, but you say that it’s “easily converted into any datetime format you want”, and that’s the datetime format I want. Is the man page out of date?