[RADIATOR] Accounting Hook ?

Heikki Vatiainen hvn at open.com.au
Thu Feb 17 17:15:27 UTC 2022


On 17.2.2022 17.13, Patrik Forsberg wrote:

> The extra data seem to be injected into the accounting package but the AcctLogFileName doesn’t pick it up but if I do a <AcctLog FILE> and reference it in the Handler it shows up in the accounting record!

I can confirm this. <AcctLog ...> clauses run the same time as <AuthLog 
..> clauses which is when a reply is sent.

> Guessing AcctLogFileName picks up its data before the hook gets to insert its data.
> (Tried it in PreProcessingHook as well with the same result)

I'd say changes done by PreProcessingHook should have been visible with 
output generated by AcctLogFileName.

Here's what I used for testing, first config:

<Handler>
    PreProcessingHook file:"%D/hook_compile-command-record.pl"
    AcctLogFileName %L/acctlog
    AccountingHandled
</Handler>


Then your hook slightly modified:

# Works as PreProcessingHook or PreAuthHook
use strict;
sub
{
     my $me = 'hook_compile-command-record.pl';

     # Often named as $p and $rp
     my ($request, $reply) = (${$_[0]}, ${$_[1]});
     my $command = '';

     $command = $request->get_attr('Juniper-Interactive-Command');
     main::log($main::LOG_DEBUG, "$me - command: $command", $request);

     $request->change_attr('Annex-CLI-Command', $command);

     my $tmp1 = $request->get_attr('Annex-CLI-Command');
     main::log($main::LOG_DEBUG, "$me - command: $tmp1", $request);

     $reply->change_attr('IPO-Command', $command);

     return;
}

It's not mandatory to pass the request object to logging, but it's helps 
when PacketTrace, LogTraceId and others are enabled. That is, it helps 
logger when selective logging is needed.

In acctlog I can see something like this:

	Juniper-Interactive-Command = "abc 123 xyz"
	Annex-CLI-Command = "abc 123 xyz"

and IPO-Command would be sent out if it were in the dictionary.

The packet dump that shows the incoming messages is done much earlier 
than the hook runs. If you'd want to dump the message from a hook too, 
use something like this:

     main::log($main::LOG_DEBUG, "$me - modified request:\n" . 
$request->dump(), $request);


Thanks,
Heikki

-- 
Heikki Vatiainen
OSC, makers of Radiator
Visit radiatorsoftware.com for Radiator AAA server software


More information about the radiator mailing list