Skip to content
Permalink
Browse files

PostgreSQL queries.conf: Simplify using expansions

  • Loading branch information
terryburton authored and alandekok committed Aug 16, 2019
1 parent 8f07320 commit 556711f5e908d84ccc5b62b80fc4186df938d73f
Showing with 42 additions and 23 deletions.
  1. +42 −23 raddb/mods-config/sql/main/postgresql/queries.conf
@@ -27,6 +27,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 = "TO_TIMESTAMP($event_timestamp_epoch)"

#######################################################################
# Default profile
#######################################################################
@@ -211,13 +230,13 @@ accounting {
query = "\
UPDATE ${....acct_table1} \
SET \
AcctStopTime = TO_TIMESTAMP(%{%{integer:Event-Timestamp}:-%l}), \
AcctUpdateTime = TO_TIMESTAMP(%{%{integer:Event-Timestamp}:-%l}), \
AcctSessionTime = (%{%{integer:Event-Timestamp}:-%l} - EXTRACT(EPOCH FROM(AcctStartTime))), \
AcctStopTime = ${....event_timestamp}, \
AcctUpdateTime = ${....event_timestamp}, \
AcctSessionTime = (${....event_timestamp_epoch} - EXTRACT(EPOCH FROM(AcctStartTime))), \
AcctTerminateCause = '%{%{Acct-Terminate-Cause}:-NAS-Reboot}' \
WHERE AcctStopTime IS NULL \
AND NASIPAddress= '%{%{NAS-IPv6-Address}:-%{NAS-IP-Address}}' \
AND AcctStartTime <= TO_TIMESTAMP(%{%{integer:Event-Timestamp}:-%l})"
AND AcctStartTime <= ${....event_timestamp}"
}

accounting-off {
@@ -236,8 +255,8 @@ accounting {
'%{%{NAS-IPv6-Address}:-%{NAS-IP-Address}}', \
NULLIF('%{%{NAS-Port-ID}:-%{NAS-Port}}', ''), \
'%{NAS-Port-Type}', \
TO_TIMESTAMP(%{%{integer:Event-Timestamp}:-%l}), \
TO_TIMESTAMP(%{%{integer:Event-Timestamp}:-%l}), \
${....event_timestamp}, \
${....event_timestamp}, \
NULL, \
0, \
'%{Acct-Authentic}', \
@@ -258,8 +277,8 @@ accounting {
ON CONFLICT (AcctUniqueId) \
DO UPDATE \
SET \
AcctStartTime = TO_TIMESTAMP(%{%{integer:Event-Timestamp}:-%l}), \
AcctUpdateTime = TO_TIMESTAMP(%{%{integer:Event-Timestamp}:-%l}), \
AcctStartTime = ${....event_timestamp}, \
AcctUpdateTime = ${....event_timestamp}, \
ConnectInfo_start = '%{Connect-Info}' \
WHERE ${....acct_table1}.AcctUniqueId = '%{Acct-Unique-Session-Id}' \
AND ${....acct_table1}.AcctStopTime IS NULL"
@@ -268,8 +287,8 @@ accounting {
query = "\
UPDATE ${....acct_table1} \
SET \
AcctStartTime = TO_TIMESTAMP(%{%{integer:Event-Timestamp}:-%l}), \
AcctUpdateTime = TO_TIMESTAMP(%{%{integer:Event-Timestamp}:-%l}), \
AcctStartTime = ${....event_timestamp}, \
AcctUpdateTime = ${....event_timestamp}, \
ConnectInfo_start = '%{Connect-Info}' \
WHERE AcctUniqueId = '%{Acct-Unique-Session-Id}'"
}
@@ -284,8 +303,8 @@ accounting {
FramedInterfaceId = NULLIF('%{Framed-Interface-Id}', ''), \
DelegatedIPv6Prefix = NULLIF('%{Delegated-IPv6-Prefix}', '')::inet, \
AcctSessionTime = %{%{Acct-Session-Time}:-NULL}, \
AcctInterval = (%{%{integer:Event-Timestamp}:-%l} - EXTRACT(EPOCH FROM (COALESCE(AcctUpdateTime, AcctStartTime)))), \
AcctUpdateTime = TO_TIMESTAMP(%{%{integer:Event-Timestamp}:-%l}), \
AcctInterval = (${....event_timestamp_epoch} - EXTRACT(EPOCH FROM (COALESCE(AcctUpdateTime, AcctStartTime)))), \
AcctUpdateTime = ${....event_timestamp}, \
AcctInputOctets = (('%{%{Acct-Input-Gigawords}:-0}'::bigint << 32) + \
'%{%{Acct-Input-Octets}:-0}'::bigint), \
AcctOutputOctets = (('%{%{Acct-Output-Gigawords}:-0}'::bigint << 32) + \
@@ -304,8 +323,8 @@ accounting {
'%{%{NAS-IPv6-Address}:-%{NAS-IP-Address}}', \
NULLIF('%{%{NAS-Port-ID}:-%{NAS-Port}}', ''), \
'%{NAS-Port-Type}', \
TO_TIMESTAMP(%{%{integer:Event-Timestamp}:-%l}), \
TO_TIMESTAMP(%{%{integer:Event-Timestamp}:-%l}), \
${....event_timestamp}, \
${....event_timestamp}, \
NULL, \
%{%{Acct-Session-Time}:-NULL}, \
'%{Acct-Authentic}', \
@@ -333,10 +352,10 @@ accounting {
query = "\
UPDATE ${....acct_table2} \
SET \
AcctStopTime = TO_TIMESTAMP(%{%{integer:Event-Timestamp}:-%l}), \
AcctUpdateTime = TO_TIMESTAMP(%{%{integer:Event-Timestamp}:-%l}), \
AcctStopTime = ${....event_timestamp}, \
AcctUpdateTime = ${....event_timestamp}, \
AcctSessionTime = COALESCE(%{%{Acct-Session-Time}:-NULL}, \
(%{%{integer:Event-Timestamp}:-%l} - EXTRACT(EPOCH FROM(AcctStartTime)))), \
(${....event_timestamp_epoch} - EXTRACT(EPOCH FROM(AcctStartTime)))), \
AcctInputOctets = (('%{%{Acct-Input-Gigawords}:-0}'::bigint << 32) + \
'%{%{Acct-Input-Octets}:-0}'::bigint), \
AcctOutputOctets = (('%{%{Acct-Output-Gigawords}:-0}'::bigint << 32) + \
@@ -362,9 +381,9 @@ accounting {
'%{%{NAS-IPv6-Address}:-%{NAS-IP-Address}}', \
NULLIF('%{%{NAS-Port-ID}:-%{NAS-Port}}', ''), \
'%{NAS-Port-Type}', \
TO_TIMESTAMP(%{%{integer:Event-Timestamp}:-%l} - %{%{Acct-Session-Time}:-0}), \
TO_TIMESTAMP(%{%{integer:Event-Timestamp}:-%l}), \
TO_TIMESTAMP(%{%{integer:Event-Timestamp}:-%l}), \
TO_TIMESTAMP(${....event_timestamp_epoch} - %{%{Acct-Session-Time}:-0}), \
${....event_timestamp}, \
${....event_timestamp}, \
NULLIF('%{Acct-Session-Time}', '')::bigint, \
'%{Acct-Authentic}', \
'%{Connect-Info}', \
@@ -390,10 +409,10 @@ accounting {
query = "\
UPDATE ${....acct_table2} \
SET \
AcctStopTime = TO_TIMESTAMP(%{%{integer:Event-Timestamp}:-%l}), \
AcctUpdateTime = TO_TIMESTAMP(%{%{integer:Event-Timestamp}:-%l}), \
AcctStopTime = ${....event_timestamp}, \
AcctUpdateTime = ${....event_timestamp}, \
AcctSessionTime = COALESCE(%{%{Acct-Session-Time}:-NULL}, \
(%{%{integer:Event-Timestamp}:-%l} - EXTRACT(EPOCH FROM(AcctStartTime)))), \
(${....event_timestamp_epoch} - EXTRACT(EPOCH FROM(AcctStartTime)))), \
AcctInputOctets = (('%{%{Acct-Input-Gigawords}:-0}'::bigint << 32) + \
'%{%{Acct-Input-Octets}:-0}'::bigint), \
AcctOutputOctets = (('%{%{Acct-Output-Gigawords}:-0}'::bigint << 32) + \

0 comments on commit 556711f

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