In this article we will cover the complete addition of Windows and Linux Hosts to an existing Icinga2 instance. If you do not still have an Icinga2 server running, you can follow our existing installation guide.

Server side prerequisites

The following steps must be executed only once on the server. This will create certificates for the server and enable his server role.

[root@HOSTNAME] ~ # icinga2 node wizard
Welcome to the Icinga 2 Setup Wizard!

We will guide you through all required configuration details.

Please specify if this is a satellite/client setup ('n' installs a master setup) [Y/n]: n

Starting the Master setup routine...

Please specify the common name (CN) [HOSTNAME.DOMAIN]:
Reconfiguring Icinga...
Checking for existing certificates for common name 'HOSTNAME.DOMAIN'...
Certificate '/var/lib/icinga2/certs//HOSTNAME.DOMAIN.crt' for CN 'HOSTNAME.DOMAIN' already existing. Skipping certificate generation.
Generating master configuration for Icinga 2.
'api' feature already enabled.

Master zone name [master]:

Default global zones: global-templates director-global
Do you want to specify additional global zones? [y/N]: N
Please specify the API bind host/port (optional):
Bind Host []:
Bind Port []:

Do you want to disable the inclusion of the conf.d directory [Y/n]: n

Then, make a backup of the previous services and hosts configuration files. We will create our own.

[root@HOSTNAME] ~ # cd /etc/icinga2
[root@HOSTNAME] icinga2 # mv conf.d/hosts.conf conf.d/hosts.conf.old
[root@HOSTNAME] icinga2 # mv conf.d/services.conf conf.d/services.conf.old
[root@HOSTNAME] icinga2 # mkdir -p /etc/icinga2/zones.d/master

Now, we can create a brand new services.conf with some basic checks (disk/ssh/load/procs/ping/swap/users).

cat << EOF > /etc/icinga2/zones.d/master/services.conf
        apply Service "ping4" {
        check_command = "ping4"
        assign where host.address
}

apply Service "disk" {
        check_command = "disk"
        command_endpoint = host.vars.client_endpoint
        assign where host.vars.client_endpoint
}

apply Service "ssh" {
        check_command = "ssh"
        assign where (host.address || host.address6) && host.vars.os == "Linux"
}

apply Service "load" {
      check_command = "load"
      command_endpoint = host.vars.client_endpoint
      assign where (host.address || host.address6) && host.vars.os == "Linux"
}

apply Service "procs" {
      check_command = "procs"
      command_endpoint = host.vars.client_endpoint
      assign where host.vars.client_endpoint
}

apply Service "swap" {
      check_command = "swap"
      command_endpoint = host.vars.client_endpoint
      assign where host.vars.client_endpoint
}

apply Service "users" {
      check_command = "users"
      command_endpoint = host.vars.client_endpoint
      assign where host.vars.client_endpoint
}
EOF

Client addition

From this step, you should execute all the steps for each host that need to be monitored.

Server side

Generate a ticket for the target host that will be added to the monitoring.

icinga2 pki ticket --cn 'NODENAME.DOMAIN'

From here, you have two choices:

If you choose to use my script you can directly jump to the next section “Client side”. If not, following these instructions.

Begin with the declaration of the Host object, here a Linux host.

vim /etc/icinga2/zones.d/master/hosts.conf

object Host "CLIENT" {
  check_command = "hostalive"
  address = "CLIENT"
  vars.client_endpoint = name 
  vars.os = "Linux"
  vars.notification["mail"] = {
    groups = [ "icingaadmins" ]
  }
}

Then populate the zones.conf file, where all the Endpoint and Zones are defined. Here is the complete file, but for a host addition, you will only have to add “object Endpoint & object Zone” related to the NODENAME you want to add.

vim /etc/icinga2/zones.conf

object Endpoint "SERVER.DOMAIN" {
        host = "SERVER.DOMAIN"
        port = "5665"
}

object Zone "master" {
        endpoints = [ "SERVER.DOMAIN" ]
}

object Endpoint "NODENAME.DOMAIN" {
}

object Zone "NODENAME.DOMAIN" {
        endpoints = [ "NODENAME.DOMAIN" ]
        parent = "master"
}

object Zone "global-templates" {
        global = true
}

object Zone "director-global" {
        global = true
}

Finish by reloading the icinga2 services to take in charge modifications.

systemctl restart icinga2

Client side (Linux)

Depending of you Linux OS, follow the according procedure.

# Debian 9

wget -O - https://packages.icinga.com/icinga.key | apt-key add -
echo "deb http://packages.icinga.com/debian icinga-$(lsb_release -sc) main" | tee /etc/apt/sources.list.d/icinga2.list
echo "deb-src http://packages.icinga.com/debian icinga-$(lsb_release -sc) main" | tee -a /etc/apt/sources.list.d/icinga2.list
apt-get update
apt-get install -y icinga2 vim-icinga2 vim-addon-manager
vim-addon-manager -w install icinga2
apt-get install -y monitoring-plugins
# CentOS 5

yum install -y epel-release; rpm --import http://packages.icinga.com/icinga.key;curl -o /etc/yum.repos.d/ICINGA-release.repo http://packages.icinga.com/epel/ICINGA-release.repo;yum makecache; yum install -y icinga2 nagios-plugins-all;chkconfig icinga2 on;/etc/init.d/icinga2 start
# CentOS 6

yum install -y epel-release
yum install -y https://packages.icinga.com/epel/icinga-rpm-release-6-latest.noarch.rpm
yum install -y icinga2
chkconfig icinga2 on
service icinga2 start
yum install -y nagios-plugins-all
# CentOS 7

yum install -y epel-release
rpm --import https://packages.icinga.com/icinga.key
yum -y install https://packages.icinga.com/epel/icinga-rpm-release-7-latest.noarch.rpm
yum install icinga2 -y
systemctl enable icinga2
systemctl start icinga2
yum install -y nagios-plugins-all

You can now launch the icinga2 wizard to configure the Node. So on the client execute.

icinga2 node wizard

(default option are not specified)
# icinga2 node wizard
...
Please specify if this is a satellite/client setup ('n' installs a master setup) [Y/n]: Y
...
Please specify the common name (CN) [HOSTNAME.DOMAIN]: HOSTNAME
...
Master/Satellite Common Name (CN from your master/satellite node): SERVER.DOMAIN
Do you want to establish a connection to the parent node from this node? [Y/n]: Y
Please specify the master/satellite connection information:
Master/Satellite endpoint host (IP address or FQDN): SERVER.DOMAIN
...
Add more master/satellite endpoints? [y/N]: N
...
Is this information correct? [y/N]: y

Please specify the request ticket generated on your Icinga 2 master (optional).
 (Hint: # icinga2 pki ticket --cn 'HOSTNAME'): 
xxxxxxxxxxxxxxxxxxxxxx (Report here the code obtained from the srv)
...
Accept config from parent node? [y/N]: y
Accept commands from parent node? [y/N]: y
...
systemctl restart icinga2

Client side (Windows)

For Windows, simply download the binary and execute it as administrator. Let all options by default and select “Run Icinga 2 setup wizard” at the end of the process.

Here is the configuration you should select on the Setup Wizard:

Do not forget to reload/restart the icinga2 service on the server.

You should now view your new host on the icingaweb2 web interface.