Skip to content
Permalink
Browse files

MSSQL queries.conf: Simplify using expansions

  • Loading branch information
terryburton authored and alandekok committed Aug 16, 2019
1 parent cdbaab1 commit fa3f304fb720d7cfb9d24739746c3dfd78bd2f2a
Showing with 26 additions and 7 deletions.
  1. +26 −7 raddb/mods-config/sql/main/mssql/queries.conf
@@ -26,6 +26,25 @@
#
sql_user_name = "%{User-Name}"

#######################################################################
# Query config: Event-Timestamp
#######################################################################
# event_timestamp_epoch is the basis for the time inserted into
# accounting records. Typically this will be the Event-Timestamp of the
# accounting request, which is usually provided by a NAS.
#
# Uncomment the next line, if you want the timestamp to be based on the
# request reception time recorded by this server, for example if you
# distrust the provided Event-Timestamp.
#event_timestamp_epoch = "%l"

event_timestamp_epoch = "%{%{integer:Event-Timestamp}:-%l}"

# event_timestamp is the SQL snippet for converting an epoch timestamp
# to an SQL date.

event_timestamp = "DATEADD(SS, ${event_timestamp_epoch}, '19700101')"

#######################################################################
# Authorization Queries
#######################################################################
@@ -107,14 +126,14 @@ accounting {
query = "\
UPDATE ${....acct_table1} \
SET \
AcctStopTime=DATEADD(SS, %{%{integer:Event-Timestamp}:-%l}, '19700101'), \
AcctSessionTime=%{%{integer:Event-Timestamp}:-%l} - \
AcctStopTime=${....event_timestamp}, \
AcctSessionTime=${....event_timestamp_epoch} - \
DATEDIFF(SS, '1970-01-01', AcctStartTime), \
AcctTerminateCause='%{%{Acct-Terminate-Cause}:-NAS-Reboot}', \
AcctStopDelay = %{%{Acct-Delay-Time}:-0} \
WHERE AcctStopTime = 0 \
AND NASIPAddress = '%{NAS-IP-Address}' \
AND AcctStartTime <= DATEADD(SS, %{%{integer:Event-Timestamp}:-%l}, '19700101')"
AND AcctStartTime <= ${....event_timestamp}"
}

accounting-off {
@@ -159,7 +178,7 @@ accounting {
'%{NAS-IP-Address}', \
'%{%{NAS-Port-ID}:-%{NAS-Port}}', \
'%{NAS-Port-Type}', \
DATEADD(SS, %{%{integer:Event-Timestamp}:-%l}, '19700101'), \
${....event_timestamp}, \
'0', \
'%{Acct-Authentic}', \
'%{Connect-Info}', \
@@ -183,7 +202,7 @@ accounting {
query = "\
UPDATE ${....acct_table1} \
SET \
AcctStartTime = DATEADD(SS, %{%{integer:Event-Timestamp}:-%l}, '19700101'), \
AcctStartTime = ${....event_timestamp}, \
AcctStartDelay = '%{%{Acct-Delay-Time}:-0}', \
ConnectInfo_start = '%{Connect-Info}' \
WHERE AcctUniqueId = '%{Acct-Unique-Session-ID}' \
@@ -257,7 +276,7 @@ accounting {
query = "\
UPDATE ${....acct_table2} \
SET \
AcctStopTime = DATEADD(SS, %{%{integer:Event-Timestamp}:-%l}, '19700101'), \
AcctStopTime = ${....event_timestamp}, \
AcctSessionTime = '%{Acct-Session-Time}', \
AcctInputOctets = convert(bigint, '%{%{Acct-Input-Gigawords}:-0}' * POWER(2.0, 32)) | '%{%{Acct-Input-Octets}:-0}', \
AcctOutputOctets = convert(bigint, '%{%{Acct-Output-Gigawords}:-0}' * POWER(2.0, 32)) | '%{%{Acct-Output-Octets}:-0}', \
@@ -303,7 +322,7 @@ accounting {
'%{NAS-IP-Address}', \
'%{%{NAS-Port-ID}:-%{NAS-Port}}', \
'%{NAS-Port-Type}', \
DATEADD(SS, %{%{integer:Event-Timestamp}:-%l}, '19700101'), \
${....event_timestamp}, \
'%{Acct-Session-Time}', \
'%{Acct-Authentic}', \
'', \

0 comments on commit fa3f304

Please sign in to comment.
You can’t perform that action at this time.