[asterisk-users] Limit monthly calls by context
A J Stiles
asterisk_list at earthshod.co.uk
Wed Nov 16 13:12:56 CST 2011
On Wednesday 16 November 2011, Hans Goossen wrote:
> 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 ?
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.
--
AJS
Answers come *after* questions.
More information about the asterisk-users
mailing list