Best way to assign hosts to zones?

In a distributed monitoring scenario, what is the best way to create endpoints and zones? My current approach requires me to describe a host in two places: once in a host-specific config file and once in zones.conf.

From host1.conf:

object Host “host1” {
import “generic-host”

display_name = "Host 1"

// ...lots of config stuff

 * The following is what I'd like to do
zone_parent = "master"


From zones.conf:

for (server in [“host1”, “host2”, “host3”]) {
object Endpoint server + “.my.domain” use(server) {
log_duration = 0
object Zone server use(server) {
endpoints = [server + “.my.domain”]
parent = “master”

This approach works fine, but I have to mention host1 in two places, so when I add a new host I have to remember to update both. Instead, what I’d like to do is to add a host variable, something like “zone_parent” above, and then have zones.conf use that information to build the endpoint and zone.

I tried using apply, but it doesn’t allow applying endpoints or zones. The for loop above would work fine if the host list were in scope, but as has been pointed out more than once, get_objects doesn’t have the host list at the point where zones.conf is being parsed. For a similar reason, I can’t define a global array “all_hosts” that each host’s config file appends to: the parsing order of individual files isn’t controlled.

Is there a better solution that what I did above?

For our distributed monitoring we used setup-scripts which can be run and create the necessary config-files. This is more of a work around than an actual solution though, but it works fine.