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).


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.

  • Not the answer i hoped for, but thx. In my specific case I'll probably forgo intermediate config files and go all the way: Re-generate the config files from config management templates (saltstack) after each change. – Nils Toedtmann Nov 19 '15 at 9:51

You mentioned you're using Icinga. If you're on the latest Icinga2, the config format supports single-line definitions via semi-colons. I do this in my own setup in order to add new services when provisioning with ansible. e.g.

apply Service "freshness_etl_vendor_import_6am" to Host { import "etl-freshness-service" ; vars.dependens_on_job = "etl_vendor_import_6am" ; assign where "etl_host" in host.groups }

See here for further details in the docs. If you're on icinga2 and its not working for you, it could be there are some other formatting issues at play.

  • Another reason to upgrade from Icinga1 to Icinga2. It's on our roadmap ... Thx – Nils Toedtmann Nov 19 '15 at 9:52
  • I clarified the Icinga version we use (1.x) – Nils Toedtmann Nov 19 '15 at 10:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.