[%
    FOREACH host IN hosts;
        SET host.fqdn = host.ip UNLESS host.fqdn.defined -%]
define host {
	host_name	[% host.fqdn %]
	alias		[% host.description or host.fqdn %]
	address		[% host.ip %]
	use		generic-host
[%      FOREACH attr IN host.nagiosconf -%]
	[% attr.key %]		[% attr.value %]
[%      END;
        IF host.parents.size -%]
	parents		[% host.parents.join(',') %]
[%      END -%]
}

[%  END;

    FOR hostgroup IN hostgroups;
        members = [];
        FOR member IN hostgroup.value.members;
            members.push(member.fqdn);
        END %]
define hostgroup {
	hostgroup_name	[% hostgroup.key %]
	alias		[% hostgroup.value.info or hostgroup.key %]
	members		[% members.sort.join(',') %]
}
[%   END -%]
