Reorganise SQL files
[freeradius.git] / raddb / sql / counter / postgresql / queries.conf
1 # -*- text -*-
2 ##
3 ## counter.conf -- PostgreSQL queries for rlm_sqlcounter
4 ##
5 ##      $Id$
6
7 #  Rather than maintaining seperate (GDBM) databases of
8 #  accounting info for each counter, this module uses the data
9 #  stored in the raddacct table by the sql modules. This
10 #  module NEVER does any database INSERTs or UPDATEs.  It is
11 #  totally dependent on the SQL module to process Accounting
12 #  packets.
13 #
14 #  The 'sql-module-instance' parameter holds the instance of the sql
15 #  module to use when querying the SQL database. Normally it
16 #  is just "sql".  If you define more and one SQL module
17 #  instance (usually for failover situations), you can
18 #  specify which module has access to the Accounting Data
19 #  (radacct table).
20 #
21 #  The 'reset' parameter defines when the counters are all
22 #  reset to zero.  It can be hourly, daily, weekly, monthly or
23 #  never.  It can also be user defined. It should be of the
24 #  form:
25 #       num[hdwm] where:
26 #       h: hours, d: days, w: weeks, m: months
27 #       If the letter is ommited days will be assumed. In example:
28 #       reset = 10h (reset every 10 hours)
29 #       reset = 12  (reset every 12 days)
30 #
31 #  The 'key' parameter specifies the unique identifier for the
32 #  counter records (usually 'User-Name').
33 #
34 #  The 'query' parameter specifies the SQL query used to get
35 #  the current Counter value from the database. There are 3
36 #  parameters that can be used in the query:
37 #               %b      unix time value of beginning of reset period
38 #               %e      unix time value of end of reset period
39 #
40 #  The 'check-name' parameter is the name of the 'check'
41 #  attribute to use to access the counter in the 'users' file
42 #  or SQL radcheck or radcheckgroup tables.
43 #
44 #  DEFAULT  Max-Daily-Session > 3600, Auth-Type = Reject
45 #      Reply-Message = "You've used up more than one hour today"
46 #
47 sqlcounter dailycounter {
48         sql-module-instance = sql
49         
50         counter-name = Daily-Session-Time
51         check-name = Max-Daily-Session
52         reply-name = Session-Timeout
53         key = User-Name
54         reset = daily
55
56         # This query properly handles calls that span from the
57         # previous reset period into the current period but
58         # involves more work for the SQL server than those
59         # below
60         query = "SELECT SUM(AcctSessionTime - \
61                 GREATER((%b - AcctStartTime::ABSTIME::INT4), 0)) \
62                 FROM radacct WHERE UserName='%{${key}}' AND \
63                 AcctStartTime::ABSTIME::INT4 + AcctSessionTime > '%b'"
64
65         # This query ignores calls that started in a previous
66         # reset period and continue into into this one. But it
67         # is a little easier on the SQL server
68 #       query = "SELECT SUM(AcctSessionTime) FROM radacct WHERE \
69 #                UserName='%{${key}}' AND AND AcctStartTime::ABSTIME::INT4 > '%b'"
70
71         # This query is the same as above, but demonstrates an
72         # additional counter parameter '%e' which is the
73         # timestamp for the end of the period
74 #       query = "SELECT SUM(AcctSessionTime) FROM radacct \
75 #                WHERE UserName='%{${key}}' AND AcctStartTime::ABSTIME::INT4 \
76 #                BETWEEN '%b' AND '%e'"
77 }
78
79 sqlcounter monthlycounter {
80         sql-module-instance = sql
81         
82         counter-name = Monthly-Session-Time
83         check-name = Max-Monthly-Session
84         reply-name = Session-Timeout
85         key = User-Name
86         reset = monthly
87
88         # This query properly handles calls that span from the
89         # previous reset period into the current period but
90         # involves more work for the SQL server than those
91         # below
92         query = "SELECT SUM(AcctSessionTime - \
93                 GREATER((%b - AcctStartTime::ABSTIME::INT4), 0)) \
94                 FROM radacct WHERE UserName='%{${key}}' AND \
95                 AcctStartTime::ABSTIME::INT4 + AcctSessionTime > '%b'"
96
97
98         # This query ignores calls that started in a previous
99         # reset period and continue into into this one. But it
100         # is a little easier on the SQL server
101 #       query = "SELECT SUM(AcctSessionTime) FROM radacct WHERE \
102 #                UserName='%{${key}}' AND AND AcctStartTime::ABSTIME::INT4 > '%b'"
103
104         # This query is the same as above, but demonstrates an
105         # additional counter parameter '%e' which is the
106         # timestamp for the end of the period
107 #       query = "SELECT SUM(AcctSessionTime) FROM radacct \
108 #                WHERE UserName='%{${key}}' AND AcctStartTime::ABSTIME::INT4 \
109 #                BETWEEN '%b' AND '%e'"
110 }
111
112 sqlcounter noresetcounter {
113         sql-module-instance = sql
114         
115         counter-name = Max-All-Session-Time
116         check-name = Max-All-Session
117         key = User-Name
118         reset = never
119
120         query = "SELECT SUM(AcctSessionTime) FROM radacct WHERE UserName='%{${key}}'"
121 }