How to monitor managed OS by hostname, not by IP address

Hello, I’m a new comer of icinga2. Here I want to monitor managed OS by their hostnames, not by IP address. I add Ansible block in my “/etc/icinga2/conf.d/custom-cfg” with each segment like below shows. As you can see, there is a parameter “address”. here I need to replace it with a parameter like hostname or something, so I can input variable value by Ansible block. Thanks.

BEGIN ANSIBLE MANAGED BLOCK for Management k8s

object Host “k8s” {

display_name = “k8s”

#import “hhq-host”

import “RedHat-ssh-agent”

address = “10.245.77.2”

vars.os = “Linux”

vars.notification[“mail”] = {

/* The UserGroup icingaadmins is defined in users.conf. */

groups = [ “icingaadmins” ] }

}

END ANSIBLE MANAGED BLOCK for Management k8s

You can simply put the hostname/FQDN in the address variable instead of the IP address.
(If the check plugin used and the host executing the check can handle the lookup)

2 Likes