Hey guys, I've another question. I need csv accounting - I used linelog for this. Basically I have: linelog csv_acct_log { ... Accounting-Request { Start = "\"%m/%d/%Y\",\"%H:%G\",\"%{Acct-Status-Type}\",\"%{User-Name}\",\"%{Auth-Type}\",\"%{User-Name}\",\"%{NAS-IP-Address}\",\"%{NAS-Port}\",\"%{Service-Type}\",\"%{Framed-Protocol}\",\"%{Framed-IP-Address}\",\"%{Framed-IP-Netmask}\"..." ... } It works great - the only problem is that I want to use double quotes when there's attribute and don't use them when attribute is not present. In CSV file it should like this "07/14/2016","10:59:16","Interim","login@mycompany.com.pl",,,"some other value" The best solution would be to do it directly in linelog module - maybe using conditional syntax? I tried it but I haven't succeed yet. Otherwise I have to do it in unlang outside linelog. I tried something like that: %{%{Framed-Compression}:-%{control:empty}} but it doesn't allow me to introduce quoting. Any ideas? thanks, Chris
On Jul 14, 2016, at 6:46 AM, Adamczak Krzysztof <kradamcz@gmail.com> wrote:
It works great - the only problem is that I want to use double quotes when there's attribute and don't use them when attribute is not present.
You'll need to write code to do that. There isn't really any way to do it automatically in unlang. Or, live with empty double quotes, and post-process the CSV file to remove them: $ sed 's/,""/,/g;s/"",/,/g;' < foo.csv > bar.csv Alan DeKok.
Thanks Alan. I'd prefer to avoid postprocessing. I've came up with solution in ulang: if (!Framed-Compression) { update control { line == "%{Framed-Compression}" } } else { update control { line == ""%{Framed-Compression}"" } } if (!User-Name) { update control { line == "%{control:line},%{User-Name}" } } else { update control { line == "%{control:line},\%{control:empty}%{User-Name}" } } And then I can use line variable in linelog module :) But also I'd like to write a header to that csv file so I quess I'd end up in writing custom module in perl or C. thanks, Chris
OK. I've got another idea. Please tell me what do you think of it. I could use perl just to format attributes to desired form (escaping, double quoting, config file which define necessary attribute / ordering) and then pass generated line to linelog. The idea is to let the linelog handle file writes and keep my perl module as simple as it could be. Any thoughts?
On Fri, Jul 15, 2016 at 10:26:55AM +0200, Adamczak Krzysztof wrote:
OK. I've got another idea. Please tell me what do you think of it. I could use perl just to format attributes to desired form (escaping, double quoting, config file which define necessary attribute / ordering) and then pass generated line to linelog. The idea is to let the linelog handle file writes and keep my perl module as simple as it could be.
Any thoughts?
linelog is a heck of a lot faster than perl. If you want to do this in production, I'd definitely do some speed benchmarks first. Personally I'd either just write it out with linelog and then, like Alan said before, post-process if you really can't stand ',"",' in the files, or write a new xlat in rlm_expr to quote a non-null string and use that for all the attributes. Some variant on linelog specifically for generating CSV/TSV files might be worthwhile, but pretty much everyone's got along with linelog just fine so far, so it doesn't seem to be worth the time to write one. Matthew -- Matthew Newton, Ph.D. <mcn4@leicester.ac.uk> Systems Specialist, Infrastructure Services, I.T. Services, University of Leicester, Leicester LE1 7RH, United Kingdom For IT help contact helpdesk extn. 2253, <ithelp@le.ac.uk>
On 15 Jul 2016, at 05:40, Matthew Newton <mcn4@leicester.ac.uk> wrote:
On Fri, Jul 15, 2016 at 10:26:55AM +0200, Adamczak Krzysztof wrote:
OK. I've got another idea. Please tell me what do you think of it. I could use perl just to format attributes to desired form (escaping, double quoting, config file which define necessary attribute / ordering) and then pass generated line to linelog. The idea is to let the linelog handle file writes and keep my perl module as simple as it could be.
Any thoughts?
linelog is a heck of a lot faster than perl. If you want to do this in production, I'd definitely do some speed benchmarks first.
Personally I'd either just write it out with linelog and then, like Alan said before, post-process if you really can't stand ',"",' in the files, or write a new xlat in rlm_expr to quote a non-null string and use that for all the attributes.
Some variant on linelog specifically for generating CSV/TSV files might be worthwhile, but pretty much everyone's got along with linelog just fine so far, so it doesn't seem to be worth the time to write one.
In v3.1.x you can use attribute refs to write out a raw value. -Arran Arran Cudbard-Bell <a.cudbardb@freeradius.org> FreeRADIUS Development Team FD31 3077 42EC 7FCD 32FE 5EE2 56CF 27F9 30A8 CAA2
OK, guys. I appreciate feedback. For now I think I'll stick with: - linelog - logrotate (based on size / time with postrotate /usr/sbin/radmin -f /var/run/radiusd/radiusd.sock -e 'hup custom_acct_log') - postprocessing with sed (cleaning empty attributes / adding header to CSV) thanks again, Chris
participants (4)
-
Adamczak Krzysztof -
Alan DeKok -
Arran Cudbard-Bell -
Matthew Newton