pmacct icon indicating copy to clipboard operation
pmacct copied to clipboard

Abort if asked to output in JSON without JSON support having been compiled-in

Open msune opened this issue 5 months ago • 2 comments

nfacctd with the following configuration:

daemonize: false

!Flowlogs
nfacctd_ip: 0.0.0.0
nfacctd_port: 2055

!print plugin
plugins: print
print_output: json
print_refresh_time: 1
aggregate: src_host, dst_host, src_port, dst_port, proto
print_output_file: logs/simple_collect_output.json

doesn't abort:

WARN: [nfacctd.conf] print_output set to json but will produce no output (missing --enable-jansson).
INFO ( default/core ): NetFlow Accounting Daemon, nfacctd 1.7.10-git (20250801-3 (faf8bea7))
INFO ( default/core ):  '--disable-silent-rules' '--enable-l2' '--enable-traffic-bins' '--enable-bgp-bins' '--enable-bmp-bins' '--enable-st-bins'
INFO ( default/core ): Reading configuration file '/home/marc/personal/pmacct/test/nfacctd_nfv9_accounting/nfacctd.conf'.
INFO ( default/core ): waiting for NetFlow/IPFIX data on interface=all ip=0.0.0.0 port=2055/udp
INFO ( default_print/print ): cache entries=16411 base cache memory=56322552 bytes

I guess this issue is common to all daemons and possibly other plugins too.

msune avatar Aug 02 '25 21:08 msune

Hi Marc,

It is strange you don't get anything, you should get a warning about the condition in the log, see here: https://github.com/pmacct/pmacct/blob/2b77abcbbbd1110b90b8847b6ba58da6299fc42b/src/cfg_handlers.c#L3205

Surely the behavior could be changed to an error / abort, that would be the low hanging fruit.

Not sure whether we want to take it the extra mile and define a registry of requirements to run the daemon, probably 1:1 mapped to the --enable features of the configure script; then flag requirements in the registry while parsing the config and then check them out in a function -- overall cleaner. It's a bit of work, not rocket science, probably one for the boring times (ie. we can re-title this issue and mark it as enhancement).

Thoughts?

Paolo

paololucente avatar Aug 05 '25 21:08 paololucente

It is strange you don't get anything, you should get a warning about the condition in the log, see here:

You are right. I seem to have missed the very first line of the log when I looked into it.

personal/pmacct/test$ cat nfacctd_nfv9_accounting/outputs/nfacctd.stderr 
WARN: [nfacctd.conf] print_output set to json but will produce no output (missing --enable-jansson).

Editing the title. We can tag as enhancement.

Not sure whether we want to take it the extra mile and define a registry of requirements to run the daemon, probably 1:1 mapped to the --enable features of the configure script; then flag requirements in the registry while parsing the config and then check them out in a function -- overall cleaner. It's a bit of work, not rocket science, probably one for the boring times (ie. we can re-title this issue and mark it as enhancement).

I think this would make sense. It can be as simple as a bitmap or a struct with booleans (since we don't care about efficiency for this one time check), and the plugins / features can check whether the requirements are there.

The nice thing of a bitmap, though is that we can have s/t like:

bool pmacct_check_compiledin_features(uint64_t required_features);

and invoke like

if(!pmacct_check_compiledin_features(LIB_1 | FEAT_2 /*etc*/))
   abort();

Instead of having to pass a ptr to a struct. Not a big deal either way.

msune avatar Aug 06 '25 21:08 msune