Limit outbound calls from extension

Good day,

I would like to know how I can limit outbound calls per (total) minutes or per currency total for an extension that when the extension exceeds i.e 100 minutes (per month) of outbound calls from extension the user can no longer make outbound calls.

There is nothing built into Asterisk to provide this. There are mechanisms that could be used to write such a thing - but that would be up to you, or you’d need to find something else that can be used with Asterisk to do so.

You can use a Pre-Dial Handler with the TIMEOUT function to limit the duration of a call:

https://wiki.asterisk.org/wiki/display/AST/Pre-Dial+Handlers

TIMEOUT function.

https://wiki.asterisk.org/wiki/display/AST/Asterisk+16+Function_TIMEOUT

a Hangup Handler could be used to update a database with how much time each call uses.

https://wiki.asterisk.org/wiki/display/AST/Hangup+Handlers

There is also the ‘L’ dial flag that can limit the length of a call in miliseconds.

https://wiki.asterisk.org/wiki/display/AST/Asterisk+16+Application_Dial

You actually mean a device or caller ID, not an extension.

The difficult part of this is that device or things with the same caller ID, can make more than one concurrent call, wheras you need to know the remaining budget at the start of the call.

Any suggestions for what can be used?

I do not want to limit the duration of a call. I want to block user from making calls once a limit for the month has been reached. Almost like pre-paid airtime for cell phones.

Apologies I come from a sip background.

I would then need this on the caller ID. Each user has their own caller ID for outbound calls.

That should be easy to do with dialplan before you call Dial.

I’d probably use either FUNC_ODBC or the native AstDB to store the user data depending on replication and performance needs. FUNC_ODBC would have more overhead.

Thank you for the help so far. Could you point me towards a guide on how to so that?

I am still new to asterisk.

It is pretty straightforward use of database access and the time limit features in Asterisk.

However, as I said, the time limit is set at the beginning of the call which means that either you have to ban concurrent calls from the same user, or they can go over budget on the last call of the billing period.

Incidentally RFC 3261 does not seem to use extension in the sense of a user agent anywhere. Mostly it is the sense of additions to the specification, and otherwise it is in the sense of additions to other things, e.g. time limits.

If they are able to go over budget on their last call that is fine. I can limit at .ie 180 or whatever their need would be.

Would you be able to point me int he direction to setup this in the database as I am still new to asterisk and DB. I am skilled in linux in general but not sql.

Worth to mention. This has been setup before and was working until a few months ago. But someone changed this or maybe there was a time specified for this rule to be in place that expired. But I cannot seem to find that anywhere. How and where in th DB can I check if this has been setup there? a2billing is installed but not configured. The a2billing db is empty.

When looking at the sql history entries I found this entry that was made.

Would this mean anything?

.mysql_history:SELECT sum(billsec) AS totalminute from cdr WHERE disposition = ‘ANSWERED’ AND dst like ‘0%’ and src=‘728’ and month( calldate )=‘NOVEMBER’ LIMIT 1
.mysql_history:SELECT sum(billsec) AS totalminute,8 from cdr WHERE disposition = ‘ANSWERED’ AND dst like ‘0%’ and src=‘728’ and month( calldate )=‘NOVEMBER’ LIMIT 1
.mysql_history:SELECT sum(billsec) AS totalminute,8 from cdr WHERE disposition = ‘ANSWERED’ AND dst like ‘0%’ and src=‘728’ and month( calldate )=‘11’ LIMIT 1
.mysql_history:SELECT sum(billsec) AS totalminute,8 from cdr WHERE disposition = ‘ANSWERED’ AND dst like ‘0%’ and src=‘728’ and month( calldate )=‘11’ LIMIT 1
.mysql_history:SELECT sum(billsec) AS totalminute,* from cdr WHERE disposition = ‘ANSWERED’ AND dst like ‘0%’ and src=‘728’ and month( calldate )=‘11’ LIMIT 1;
.mysql_history:SELECT sum(billsec) AS totalminute,* from cdr WHERE disposition = ‘ANSWERED’ AND dst like ‘0%’ and src=‘728’ and month( calldate )=‘11’ LIMIT 1
.mysql_history:SELECT *,sum(billsec) AS totalminute from cdr WHERE disposition = ‘ANSWERED’ AND dst like ‘0%’ and src=‘728’ and month( calldate )=‘11’ LIMIT 1;
.mysql_history:SELECT * from cdr WHERE disposition = ‘ANSWERED’ AND dst like ‘0%’ and src=‘728’ and month( calldate )=‘10’ LIMIT 1;
.mysql_history:SELECT *,sum(billsec) AS totalminute from cdr WHERE disposition = ‘ANSWERED’ AND dst like ‘0%’ and src=‘728’ and month( calldate )=‘10’ LIMIT 1;
.mysql_history:SELECT *,sum(billsec) AS totalminute from cdr WHERE disposition = ‘ANSWERED’ AND dst like ‘0%’ and src=‘728’ and month( calldate )=‘10’ LIMIT 1;
.mysql_history:SELECT sum(billsec) AS totalminute from cdr WHERE disposition = ‘ANSWERED’ AND dst like ‘0%’ and src=‘728’ and month(calldate) = 11 LIMIT 1;
.mysql_history:SELECT sum(billsec) AS totalminute from cdr WHERE disposition = ‘ANSWERED’ AND dst like ‘0%’ and src=‘728’ and month(calldate) = 11;
.mysql_history:SELECT * from cdr WHERE disposition = ‘ANSWERED’ AND dst like ‘0%’ and src=‘728’ and month(calldate) = 11;
.mysql_history:SELECT * from cdr WHERE disposition = ‘ANSWERED’ AND dst like ‘0%’ and src=‘728’ and year_month(calldate) = 2017-11;
.mysql_history:SELECT * from cdr WHERE disposition = ‘ANSWERED’ AND dst like ‘0%’ and src=‘728’ and year_month(calldate) = ‘2017-11’;
.mysql_history:SELECT * from cdr WHERE disposition = ‘ANSWERED’ AND dst like ‘0%’ and src=‘728’ and month(calldate) = 11 and year(calldate) = 2017;
.mysql_history:SELECT sum(billsec) from cdr WHERE disposition = ‘ANSWERED’ AND dst like ‘0%’ and src=‘728’ and month(calldate) = 11 and year(calldate) = 2017;
.mysql_history:SELECT sum(billsec) from cdr WHERE disposition = ‘ANSWERED’ AND dst like ‘0%’ and src=‘728’ and month(calldate) = 11 and year(calldate) = 2017 LIMIT 1;

728 would be the user that needs to be limited

They are queries about how many seconds the caller has made on level 0 (presumably external) calls in November 2017.

Thanks. I am hitting a brick wall. I know it has been setup but stopped working. This was most likely done in the DB. But where to look I don’t know.

I found that this was done with AGI script.

The script stopped working. Anyone have experience with AGI scripts for the issue?

It sounds like you should try and find an a2billing support resource.

1 Like

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