Is it possible to automate a Disconnect-Request based on exceeded Monthly-Usage?

Alan DeKok aland at deployingradius.com
Fri Sep 13 15:06:10 CEST 2019



> On Sep 12, 2019, at 3:09 PM, Houman <houmie at gmail.com> wrote:
> 
> Hi Alan,
> 
> Great news, It almost works now.
> 
> The issue I get is now the conditional here:
> 
> preacct {
>        preprocess
>        if (Monthly-Usage > 300000000000) {

  And where does "Monthly-Usage" come from?

  Not from the Accounting-Request packet.

> (5)   preacct {
> (5)     [preprocess] = ok
> (5)     if (Monthly-Usage > 300000000000) {
> (5)     ERROR: Failed retrieving values required to evaluate condition

  Yup.

> Now I wonder why the attribute is not seen?

  Because it doesn't exist.

> I have set it like this:
> 
> echo 'ATTRIBUTE Monthly-Usage 3001 integer64' >>
> /etc/freeradius/3.0/dictionary
> 
> update request {
>           Monthly-Usage = "%{sql:SELECT
> COALESCE((SUM(`acctoutputoctets`)), 0) FROM radacct WHERE
> `username`='"'"'%{User-Name}'"'"' AND Month(acctupdatetime)=(Month(NOW()))
> AND Year(acctupdatetime)=Year(NOW())}"
> }

  And where is that set?

> When updating the request, the Monthly-Usage attribute should be already
> set, so how comes it doesn't recognise the variable within preacct?

  If it WAS already set, then the debug output would show it being set.

  Odds are that your'e setting it when the Access-Request is received.  The server does *not* magically track attributes across multiple packets.  That's what a database is for.

  Or, you're setting it in the "accounting' section, which (according to the debug output) runs AFTER the "preacct" section.

  If you want to set Monthly-Usage, the you need to *actually set it* ::

preacct {
       preprocess

     update request {
          Monthly-Usage = "%{sql:SELECT
COALESCE((SUM(`acctoutputoctets`)), 0) FROM radacct WHERE
`username`='"'"'%{User-Name}'"'"' AND Month(acctupdatetime)=(Month(NOW()))
AND Year(acctupdatetime)=Year(NOW())}"
    }

       if (Monthly-Usage > 300000000000) {
           update disconnect {
                       &User-Name = "%{User-Name}"
           }
...

  Then it will work.

  Alan DeKok.




More information about the Freeradius-Users mailing list