]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Cassandra queries.conf: Simplify using expansions
authorTerry Burton <tez@terryburton.co.uk>
Fri, 16 Aug 2019 11:09:24 +0000 (12:09 +0100)
committerAlan DeKok <aland@freeradius.org>
Fri, 23 Aug 2019 17:29:05 +0000 (13:29 -0400)
raddb/mods-config/sql/main/cassandra/queries.conf

index 1fd278c70e7e74b1399a2fc7475bcbd26bdaa262..a575e44d5287e4dd6e963ac7bdb84663ff6cda54 100644 (file)
 #
 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 = "%{expr:${event_timestamp_epoch} * 1000}"
+
 #######################################################################
 # Default profile
 #######################################################################
@@ -139,7 +158,7 @@ accounting {
                accounting-on {
                        query = "\
                                INSERT INTO radnasreboot (nasipaddress, timestamp) \
-                               VALUES ('%{NAS-IP-Address}', %{expr:%{%{integer:Event-Timestamp}:-%l}} * 1000});"
+                               VALUES ('%{NAS-IP-Address}', ${....event_timestamp});"
                }
 
                accounting-off {
@@ -183,8 +202,8 @@ accounting {
                                        '%{NAS-IP-Address}', \
                                        '%{%{NAS-Port-Id}:-%{NAS-Port}}', \
                                        '%{NAS-Port-Type}', \
-                                       %{expr:%{%{integer:Event-Timestamp}:-%l} * 1000}, \
-                                       %{expr:%{%{integer:Event-Timestamp}:-%l} * 1000}, \
+                                       ${....event_timestamp}, \
+                                       ${....event_timestamp}, \
                                        null, \
                                        '%{Acct-Authentic}', \
                                        '%{Connect-Info}', \
@@ -210,7 +229,7 @@ accounting {
                                        acctstarttime \
                                ) VALUES ( \
                                        '%{Acct-Unique-Session-Id}', \
-                                       %{expr:(%{%{integer:Event-Timestamp}:-%l} - &Acct-Session-Time) * 1000} \
+                                       %{expr:(${....event_timestamp_epoch} - &Acct-Session-Time) * 1000} \
                                ) IF NOT EXISTS; \
                                INSERT INTO ${....acct_table1} ( \
                                        acctuniqueid, \
@@ -243,7 +262,7 @@ accounting {
                                        '%{NAS-IP-Address}', \
                                        '%{%{NAS-Port-Id}:-%{NAS-Port}}', \
                                        '%{NAS-Port-Type}', \
-                                       %{expr:%{%{integer:Event-Timestamp}:-%l} * 1000}, \
+                                       ${....event_timestamp}, \
                                        null, \
                                        '%{Acct-Authentic}', \
                                        '%{Connect-Info}', \
@@ -270,7 +289,7 @@ accounting {
                                        acctstarttime \
                                ) VALUES ( \
                                        '%{Acct-Unique-Session-Id}', \
-                                       %{expr:(%{%{integer:Event-Timestamp}:-%l} - &Acct-Session-Time) * 1000} \
+                                       %{expr:(${....event_timestamp_epoch} - &Acct-Session-Time) * 1000} \
                                ) IF NOT EXISTS; \
                                INSERT INTO ${....acct_table1} ( \
                                        acctuniqueid, \
@@ -304,8 +323,8 @@ accounting {
                                        '%{NAS-IP-Address}', \
                                        '%{%{NAS-Port-Id}:-%{NAS-Port}}', \
                                        '%{NAS-Port-Type}', \
-                                       %{expr:%{%{integer:Event-Timestamp}:-%l} * 1000}, \
-                                       %{expr:%{%{integer:Event-Timestamp}:-%l} * 1000}, \
+                                       ${....event_timestamp}, \
+                                       ${....event_timestamp}, \
                                        '%{Acct-Authentic}', \
                                        '%{Connect-Info}', \
                                        %{expr:(&Acct-Input-Gigawords << 32) | &Acct-Input-Octets}, \