loading scripts only if file exists

Hi all,

is there a way to @load a script in bro only if the file exists?

My scenario is that I'd like to be able to include configuration data from, e.g., /etc/bro-config.bro. But this script might not exist in all scenarios. Loading it via @load gives an error if the file doesn't exist.

I've tried to use @prefixes to conditionally load scripts, but couldn't figure out exactly where bro would be searching for those scripts.

If there an equivalent for something like "if [-f /etc/bro-config.bro] " ?

Best regards,

Dirk

Hi Dirk,

This just came up last month :slight_smile:

http://mailman.icsi.berkeley.edu/pipermail/bro/2015-November/009312.html

And clarified:

http://mailman.icsi.berkeley.edu/pipermail/bro/2015-December/009324.html

Grant

I've tried to use @prefixes to conditionally load scripts, but couldn't
figure out exactly where bro would be searching for those scripts.

I think that prefixes are probably exactly what you’re looking for. If you add a prefix and then create a file by the right name it will only load it when it finds the file. This is a little tricky with the current setup unfortunately, I didn’t get this setup quite the way I wanted to a number of years ago.

If you write a file named “local.local.bro” to your site/ directory, that script will automatically load if it’s found.

If there an equivalent for something like "if [-f /etc/bro-config.bro] " ?


Not really.

  .Seth

Hi Seth,

  1. Is “local.local.bro”a hard-coded name that will always work, even without extending @prefixes?
  2. If I extend @prefixes inside a plugin script, which directory would be searched? E.g., if I extend prefixes in the following file:

/opt/bro/lib/bro/plugins/Demo_demo/scripts/Demo/demo/bla.bro
@prefixes = myprefix

while my bro plugin search path is: /opt/bro/lib/bro/plugins

If I understand the documentation correctly, this would search for files named

myprefix.Demo_demo.scripts.Demo.demo.bla.bro

Is that correct?

Thanks a lot!

Dirk