Limit monthly calls by context

Home » Asterisk Users » Limit monthly calls by context
Asterisk Users 6 Comments

Hello group,

I have this situation:

I have several contexts with a few extensions each one. I need to give every context a limited quantity of minutes they can use. All the extensions in the context will share the same “bag” of minutes. Meaning ext 101 use 1900 mins, ext 102 60 mins and ext 40 mins.
The limit must be monthly.

I guess some “billing” solution can do the trick, but I think it’s too much for that little. I don’t need any other feature.

I was thinking something like checking the CDR before make the call, I know it may permit some “extra” minutes to be used, but it really doesn’t need to be that exact. A couple of extra minutes won’t hurt.

Ideas, suggestions ?

Hans Goossen
Investigación & Desarrollo
Planet S.A.
http://www.pla.net.py

6 thoughts on - Limit monthly calls by context

  • Hello Hans,

    i would create a macro which calls an agi. The agi searches the CDR
    table (mine is in sql) and calculates if the call can go through. Then
    i’d call this macro from every extension in the dial plan just before
    the dial cmd.

    It depends on the number of simultaneous calls from within the same
    context. The agi can return a number of seconds (calculated from sql)
    which the dial cmd can use as an absolute limit and after that amount of
    seconds it can hang up the call (see S or L flags).

  • I’d say try a2billing- thats abit of an overkill for just this
    functionality but you’ll get lot or options to play with there.

  • You can do this with a global variable and a dedicated context.

    [mailto:asterisk-users-bounces@lists.digium.com] On Behalf Of Sammy Govind
    Sent: Wednesday, November 16, 2011 12:25 PM

    I’d say try a2billing- thats abit of an overkill for just this functionality
    but you’ll get lot or options to play with there.

    Hello Hans,

    I guess some “billing” solution can do the trick, but I think it’s too much
    for that little. I don’t need any other feature.

    i would create a macro which calls an agi. The agi searches the CDR table
    (mine is in sql) and calculates if the call can go through. Then i’d call
    this macro from every extension in the dial plan just before the dial cmd.

    I was thinking something like checking the CDR before make the call, I know
    it may permit some “extra” minutes to be used, but it really doesn’t need to
    be that exact. A couple of extra minutes won’t hurt.

    It depends on the number of simultaneous calls from within the same context.
    The agi can return a number of seconds (calculated from sql) which the dial
    cmd can use as an absolute limit and after that amount of seconds it can
    hang up the call (see S or L flags).

  • Set a global variable or several in the beginning of the dialplan with the
    monthly allowance for each context. In the “h” extension of each time-limited
    context, subtract the duration of the call just made from the global. In each
    extension which is time-limited, replace Dial() with a call to a macro which
    either actually executes the Dial() if there is any time remaining (and uses
    that as an absolute timeout value), otherwise plays a message.

    If you need the remaining allowances to persist across reboots / dialplan
    reloads, you’ll have to have an AGI write them to a file which you can #include
    in the [globals] section of the dialplan. A cron job can then be used to
    reset the allowances at the beginning of each month, by copying a “pristine”
    file over it.

    Note it’s still possible to go over with this method, because the remaining
    time is only recalculated at hangup, but you said it didn’t have to be exact.

  • If you store the Global in DB and read it back from DB, it can persist
    across reboots and reloads.