[%
    kunden = {};
    tab = "\t";

    FOREACH standort IN standorte;
        UNLESS loop.first %]

[%      END -%]
# Standort [% standort.user -%]
[%      IF standort.name.defined %] ([% standort.name %])
[%      END;

        FOREACH host IN standort.hosts %]
[%
            SET host.fqdn = host.ip UNLESS host.fqdn.defined;

            kunde = host.kunde.name or standort.kunde.name or standort.kunde;
            SET kunden.$kunde = [] UNLESS kunden.exists(kunde);
            kunden.$kunde.push(host.fqdn);

            SET host.nagiosconf.alias = host.description or host.fqdn
              UNLESS host.nagiosconf.exists('alias');
            SET host.nagiosconf.contact_groups = "${host.kunde.name}-bf"
              UNLESS host.nagiosconf.exists('contact_groups');
            SET host.nagiosconf.use = 'generic-host'
              UNLESS host.nagiosconf.exists('use');
-%]
define host {
	host_name	[% host.fqdn %]
	address		[% host.ip %]
[%
            FOREACH attr IN host.nagiosconf;
                tabs = ( 31 - attr.key.length ) / 8;
                SET tabs = 1 IF tabs < 1;
-%]
	[% attr.key; tab.repeat(tabs); attr.value %]
[%          END;
            IF host.parents.size -%]
	parents		[% host.parents.join(',') %]
[%          END -%]
}
[%          FOR interface IN host.interfaces %]
define service {
	service_description	[% interface.fqdn or interface.ip %]
	use			generic-service
	host_name		[% host.fqdn %]
	check_command		check_ip_[% IF interface.flag.neg_monitoring %]anti[% END %]ping
	contact_groups		[% host.nagiosconf.contact_groups %]
}
[%
            END;
        END;
    END;

    FOREACH kunde IN kunden;
        IF loop.first; %]

# Hostgroups:
[%      END %]
define hostgroup {
	hostgroup_name	[% kunde.key %]
	alias		[% kunde.key %]
	members		[% kunde.value.join(',') %]
}
[%  END -%]
