From: Terry Burton Date: Mon, 23 Mar 2020 16:58:43 +0000 (+0000) Subject: MS SQL: Simplify time handling using expansions X-Git-Tag: release_3_0_21~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=806e610f5446ae7d50aa95ed97def06e5e669da7;p=thirdparty%2Ffreeradius-server.git MS SQL: Simplify time handling using expansions --- diff --git a/raddb/mods-config/sql/main/mssql/queries.conf b/raddb/mods-config/sql/main/mssql/queries.conf index a25b0bf9519..ee21f740e5a 100644 --- a/raddb/mods-config/sql/main/mssql/queries.conf +++ b/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='%S', \ - AcctSessionTime=unix_timestamp('%S') - \ - unix_timestamp(AcctStartTime), \ + 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 <= '%S'" + AND AcctStartTime <= ${....event_timestamp}" } accounting-off { @@ -232,7 +251,7 @@ accounting { '%{NAS-IP-Address}', \ '%{%{NAS-Port-ID}:-%{NAS-Port}}', \ '%{NAS-Port-Type}', \ - '%S', \ + ${....event_timestamp}, \ '0', \ '%{Acct-Authentic}', \ '%{Connect-Info}', \ @@ -286,7 +305,7 @@ accounting { query = "\ UPDATE ${....acct_table1} \ SET \ - AcctStartTime = '%S', \ + AcctStartTime = ${....event_timestamp}, \ AcctStartDelay = '%{%{Acct-Delay-Time}:-0}', \ ConnectInfo_start = '%{Connect-Info}' \ WHERE AcctUniqueId = '%{Acct-Unique-Session-ID}' \ @@ -391,7 +410,7 @@ accounting { query = "\ UPDATE ${....acct_table2} \ SET \ - AcctStopTime = '%S', \ + 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}', \ @@ -437,7 +456,7 @@ accounting { '%{NAS-IP-Address}', \ '%{%{NAS-Port-ID}:-%{NAS-Port}}', \ '%{NAS-Port-Type}', \ - '%S', \ + ${....event_timestamp}, \ '%{Acct-Session-Time}', \ '%{Acct-Authentic}', \ '', \