Nagios configuration syntax: Multiple directives per line

configurationicinganagios

A large volatile part of my Nagios 3 (Icinga 1, actually) config looks like this:

...
define host{
    host_name   bla0037
    use         template-bla
}

define host{
    host_name   bla0042
    use         template-bla
}
...

Scripted management would be much easier if I could bundle up host definitions into single lines, like this:

...
define host{ host_name bla0037;  use template-bla }
define host{ host_name bla0042;  use template-bla }
...

But I haven't found out yet how. (e.g. semicolon makes the rest of a line a comment). Ideas?

(Generating lots of little host-bla0XYZ.cfg files would also help automation, but I'd rather not clutter the conf dirs).

Best Answer

No, you cannot do this. The config file parser reads one line at a time and expects a single directive per line. You would have to heavily modify the parser in xodtemplate.c to do this.

The only special exceptions in the parser are ; or # (comments) and \ (split a long line into multiple lines).

The only way I can think of to do what you want would be to use some different delimited as a stand-in for \n in your management system output, and then post-process (e.g., sed -e) these files on the Nagios/Icinga end into config files.

For example, you could then modify the init script to run your post-process job before every reload/HUP. This would be an ugly hack, but it could work.

Related Topic