Host address from DNS SRV record

Is it possible to write a host definition such that the IP address for the host (and thus where the service checks go) is determined by a DNS SRV lookup?

I’m asking because I have a service that runs on two different servers, but the ‘primary’ server is determined by DNS SRV, and I only want to be running the service check on the server that is currently the primary.

Hello @thehunmonkgroup,
I hope you are well. Instead of using the IP for the address attribute in the host object you can use the dns record as the address attribute.

Regards
Alex

@aclark6996 unfortunately that does not work with DNS SRV records:

Could not resolve hostname _sip._udp.voice.al-staging.com: No address associated with hostname

I believe SRV records need special treatment because they return multiple hostnames with mulitple priorities/weights. So unless Icinga2 has some special syntax for declaring an address attribute is using an SRV record, I don’t think this is going to work.

So far, best I’ve come up with is:

  1. Make out of band DNS SRV query
  2. Parse results
  3. Programmatically update /etc/hosts with the correct final IP of the server in question
  4. Use the /etc/hosts entry as the DNS name in the address attribute of the Host object

Ugly, but at least workable!