split an accounting attribute in two and write two new attributes to MySQL

xaled at web.de xaled at web.de
Wed Feb 16 22:38:37 UTC 2022


Thanks Alan,

apreciate your help!

Greetings,
Xaled

-----Original Message-----
From: Freeradius-Users
<freeradius-users-bounces+xaled=web.de at lists.freeradius.org> On Behalf Of
Alan DeKok
Sent: Wednesday, February 16, 2022 4:21 PM
To: FreeRadius users mailing list <freeradius-users at lists.freeradius.org>
Subject: Re: split an accounting attribute in two and write two new
attributes to MySQL

On Feb 14, 2022, at 3:49 PM, xaled at web.de wrote:
> I want to split the Acct-Session-Id attribute from account stop
> request at the "/" sign and write the two resulting parts in to two
> separate columns in a MySQL DB.

  The best way to do this is via a regular expression:

	if (Acct-Session-Id =~ /^(...)/(...)/) {
		update request {
			Split-Session-ID += "%{1}"
			Split-Session-ID += "%{2}"
		}

  You'll have to use a real regular expression, of course But it should
work.

> My limited understanding of the way to approach it is have something
> like a local variable defined that would take the results of the
> explode operations and then use this new variable to write the splited
> content in two columns in a MySQL DB.

  The "explode" operation won't create two attributes, though.  It will
assign the results only to one attribute.

> From your comment I seem to get that there is no concept of something
> like local variables in FreeRADIUS that can be freely defined and operated
upon.
> I would need to have attributes defined within the dictionary that
> would act as the variables that I need.

  Yes.

> Given the explanation would it be the right way to proceed?
> * Defining a new attribute in raddb/dictionary that would hold the
> results of the splitting.

  Yes.

> * Add update request section to preacct:

  No.  Just use a regular expression.

> * in MySQL driver-specific configuration use:
>
> '%{Split-Session-ID[1]}', \
> '%{Split-Session-ID[2]}', \

  That should work.

  Alan DeKok.

-
List info/subscribe/unsubscribe? See
http://www.freeradius.org/list/users.html



More information about the Freeradius-Users mailing list