Now that we have some keys in Consul, we want to get that into a Nagios configuration file using Consul-Template. Consul-Template requires only two files which are used to create a third.

hosts.hcl – template configuration
hosts.ctmpl – template
hosts.cfg – output

I’m using Ubuntu 16.04 and here’s where I put the files;

/etc/consul-template.d/configs/hosts.hcl
/etc/consul-template.d/templates/hosts.ctmpl
/etc/nagios3/conf.d/hosts.cfg

File Contents

/etc/consul-template.d/config/hosts.hcl

template {
  source = "/etc/consul-template.d/templates/hosts.ctmpl"
  destination = "/etc/nagios3/conf.d/hosts.cfg"
}

/etc/consul-template.d/templates/hosts.ctmpl

Tagged on: