Making Broker Optional in Script

Hello,

I have a Zeek script that I would like to add optional Broker functionality to. I don’t want it to be a requirement, so I’m adding run-time redef options that can be toggled to enable/disable it.

Something like:

This is the exact script I’m trying to load Broker with at run-time: https://raw.githubusercontent.com/cybera/zeek-sniffpass/broker/scripts/main.bro

When I run the default script without Broker, everything runs fine since the default is disabled (const broker_enable = F &redef;).

However, when I try to override this on Zeek 3.0.0 with Broker 1.2.3 in my local.zeek file:

@if is only evaluated once when scripts are parsed. If you are changing broker_enable you have to do it before your script is loaded.

Also, instead of

@if( /^3\./ in bro_version() )

you can just do

@ifdef(zeek_init)