zeek/doc
Johanna Amann db6f028003 Add config framework.
The configuration framework consists of three mostly distinct parts:

* option variables
* the config reader
* the script level framework

I will describe the three elements in the following.

Internally, this commit also performs a range of changes to the Input
manager; it marks a lot of functions as const and introduces a new
ValueToVal method (which could in theory replace the already existing
one - it is a bit more powerful).

This also changes SerialTypes to have a subtype for Values, just as
Fields already have it; I think it was mostly an oversight that this was
not introduced from the beginning. This should not necessitate any code
changes for people already using SerialTypes.

option variable
===============

The option keyword allows variables to be specified as run-tine options.
Such variables cannot be changed using normal assignments. Instead, they
can be changed using Option::set. It is possible to "subscribe" to
options and be notified when an option value changes.

Change handlers can also change values before they are applied; this
gives them the opportunity to reject changes. Priorities can be
specified if there are several handlers for one option.

Example script:

option testbool: bool = T;

function option_changed(ID: string, new_value: bool): bool
  {
  print fmt("Value of %s changed from %s to %s", ID, testbool, new_value);
  return new_value;
  }

event bro_init()
  {
  print "Old value", testbool;
  Option::set_change_handler("testbool", option_changed);
  Option::set("testbool", F);
  print "New value", testbool;
  }

config reader
=============

The config reader provides a way to read configuration files back into
Bro. Most importantly it automatically converts values to the correct
types. This is important because it is at least inconvenient (and
sometimes near impossible) to perform the necessary type conversions in
Bro scripts themselves. This is especially true for sets/vectors.

Configuration generally look like this:

[option name][tab/spaces][new variable value]

so, for example:

testaddr 2607:f8b0:4005:801::200e
testinterval 60
testtime 1507321987
test_set a	b	c	d	erdbeerschnitzel

The reader uses the option name to look up the type that variable has in
the Bro core and automatically converts the value to the correct type.

Example script use:

type Idx: record {
  option_name: string;
};

type Val: record {
  option_val: string;
};

global currconfig: table[string] of string = table();

event InputConfig::new_value(name: string, source: string, id: string, value: any)
  {
  print id, value;
  }

event bro_init()
  {
  Input::add_table([$reader=Input::READER_CONFIG, $source="../configfile", $name="configuration", $idx=Idx, $val=Val, $destination=currconfig, $want_record=F]);
  }

Script-level config framework
=============================

The script-level framework ties these two features together and makes
them a bit more convenient to use. Configuration files can simply be
specified by placing them into Config::config_files. The framework also
creates a config.log that shows all value changes that took place.

Usage example:

redef Config::config_files += {configfile};

export {
  option testbool : bool = F;
}

The file is now monitored for changes; when a change occurs the
respective option values are automatically updated and the value change
is written to config.log.
2017-11-29 13:46:59 -08:00
..
_static Minor Bro docs tweaks for correctness and readability 2017-10-23 15:21:28 -07:00
_templates Minor Bro docs tweaks for correctness and readability 2017-10-23 15:21:28 -07:00
broids Misc. documentation fixes. 2014-03-04 13:14:32 -06:00
cluster Update docs for the new logger node type 2016-06-30 15:45:36 -05:00
components Remove another reference to now removed bro-plugins. 2017-07-11 09:56:33 -07:00
configuration Update the quickstart guide for the deploy command 2016-11-09 14:35:12 -06:00
devel Fix some doc build warnings 2015-08-18 14:23:48 -05:00
ext Python 3 compatibility fixes for doc/ext/bro.py 2016-10-29 15:16:42 -05:00
frameworks Fix documentation build. 2017-07-07 14:35:38 -07:00
httpmonitor File API updates complete. 2015-04-20 10:46:48 -04:00
images Adapt more www niceties to broxygen (stylesheets, pygments); add more docs 2011-11-15 15:39:31 -06:00
install Update install instructions for Fedora 26 2017-08-01 15:54:26 -05:00
intro Fix broken links in the documentation 2013-09-11 16:32:02 -05:00
logs Baseline updates after hash function change. 2016-07-13 10:11:37 -07:00
mimestats Merge remote-tracking branch 'origin/topic/jsiwek/bit-1324' 2015-03-23 10:35:30 -07:00
quickstart Documentation updates for loading Bro scripts. 2017-04-17 12:09:18 -04:00
script-reference Add config framework. 2017-11-29 13:46:59 -08:00
scripting Fixing documentation piece. 2016-10-06 14:28:52 -07:00
.gitignore A set of script-reference polishing. 2012-01-09 18:04:34 -08:00
broxygen.conf.in Change Broxygen config file format. 2013-11-22 14:37:07 -06:00
CMakeLists.txt Replace libmagic w/ Bro signatures for file MIME type identification. 2014-03-04 11:12:06 -06:00
conf.py.in Update copyright year for sphinx. 2016-01-21 13:47:33 -08:00
index.rst Updating plugin documentation. 2014-10-07 15:14:39 -07:00
LICENSE Update documentation license 2016-10-06 11:35:31 -07:00
README Merge remote-tracking branch 'origin/fastpath' 2014-03-30 19:55:39 +02:00

Documentation
=============

This directory contains Bro documentation in reStructuredText format
(see http://docutils.sourceforge.net/rst.html).

It is the root of a Sphinx source tree and can be modified to add more
common/general documentation, style sheets, JavaScript, etc.  The Sphinx
config file is produced from ``conf.py.in``, and can be edited to change
various Sphinx options.

There is also a custom Sphinx domain implemented in ``ext/bro.py``
which adds some reST directives and roles that aid in generating useful
index entries and cross-references.  Other extensions can be added in
a similar fashion.

The ``make doc`` target in the top-level Makefile can be used to locally
render the reST files into HTML.  That target depends on:

* Python interpreter >= 2.5
* `Sphinx <http://sphinx-doc.org/>`_ >= 1.0.1
* Doxygen (required only for building the Broccoli API doc)

After completion, HTML documentation is symlinked in ``build/html``.

There's also a ``make docclean`` target which deletes any files
created during the documentation build process.

Notes for Writing Documentation
-------------------------------

* If you want to refer to a document that's part of the
  distribution, it currently needs to be copied or otherwise symlinked
  somewhere in to this Sphinx source tree. Then, it can be referenced
  in a toc tree or with the :doc: role.  Use the :download: role to
  refer to static files that will not undergo sphinx rendering.

* If you want to refer to a page on the Bro web site, use an HTTP URL.

Guidelines
----------

TODO.