Limit the number of calls per extension per day!


Is it possible to limit the number of calls made by an extension?
I don’t want to limit the time, only the number of calls per extension per day.

I try (from trixbox forum), but not working in Asterisk 1.4

I change:

exten => _9.,n(dbwrite),DBput(ext/limit=${limitcall})
– to –
exten => _9.,n(dbwrite),Set(DB(ext/limit)=${limitcall})

but not working!!!

Any idea?


This code will allow you to assign an extension to be limited to X number of calls (you can customize) per day, and the value is reset at midnight.

In the code below, the system will allow calls to be dialed using 9+number up to 20 times. After the 20th time, the system will not allow the call through. A cron job will reset the counter back to 0 at midnight.


Open up /etc/asterisk/extensions_custom.conf

Goto the bottom of that file and copy in the following 19 lines of code:

exten => _9.,1,NoOp( ----- Limited Extension Context Activated ----- )
exten => _9.,n,Set(limitcall=${DB(ext/limit)})
exten => _9.,n,NoOp( ----- Call limit set to ${limitcall} in the database ----- ))
exten => _9.,n,GotoIf($["${limitcall}" > “20”]?hang)
exten => _9.,n,GotoIf($["${limitcall}" = “”]?resetvariable)
exten => _9.,n,Set(limitcall=${MATH(${limitcall}+1)})
exten => _9.,n(dbwrite),DBput(ext/limit=${limitcall})
exten => _9.,n,Macro(dialout-trunk,1,${EXTEN:1},)
exten => _9.,n,Macro(outisbusy,)
exten => _9.,n,Hangup()
exten => _9.,n(hang),NoOp( ----- Call limit of ${limitcall} has been reached. ------ )
exten => _9.,n,Hangup()
exten => _9.,n(resetvariable),NoOp( ----- Null value has been corrected ----- )
exten => _9.,n,Set(limitcall=1)
exten => _9.,n,Goto(dbwrite)
exten => s,1,Macro(hangupcall,)
exten => h,1,Macro(hangupcall,)

save those changes and exit.

in /etc/asterisk create a new file called limitcallreset
in that file put in the following:

asterisk -rx ‘database deltree ext’

save those changes and exit
now type
chmod 755 limitcallreset

now edit the file /etc/crontab
and at the bottom of that file put in the following:

1 0 * * * root ./etc/asterisk/./limitcallreset

save those changes.
now type
service crond restart

Now. go into FreePBX and click on the extension that you want to have this ‘limited’ call out assigned to.
Scroll down to the “CONTEXT” section and replace “from-internal” and put in “limitextension”

Submit those changes
click on the red bar.
Now, from that extension, make some calls and test!