How To Add Remote Linux Machines into Icinga 2 Server
Setup Master with Clients
On the master node, create a new configuration directory using the following command.
mkdir -p /etc/icinga2/zones.d/master
We will now define the client nodes and apply service checks using the command endpoint execution method on them.
centos.itzgeek.local:
vi /etc/icinga2/zones.d/master/centos.itzgeek.local.conf
Add the following in the above file.
// Endpoints & Zones object Endpoint "centos.itzgeek.local" { } object Zone "centos.itzgeek.local" { endpoints = [ "centos.itzgeek.local" ] parent = "master" } // Host Objects object Host "centos.itzgeek.local" { check_command = "hostalive" address = "192.168.1.20" vars.client_endpoint = name //follows the convention that host name == endpoint name // Custom Optional check - START vars.local_disks["/app Filesystem"] = { disk_partitions = "/app" } vars.local_http_vhosts["http"] = { http_uri = "/" } vars.local_tcp_port["tcp"] ={ tcp_port = "23" service_name = "Telnet Check" port_number = "Port 23" } // Custom Optional Check - END }
Ubuntu.itzgeek.local:
vi /etc/icinga2/zones.d/master/ubuntu.itzgeek.local.conf
Simple monitoring check for Ubuntu.
// Endpoints & Zones object Endpoint "ubuntu.itzgeek.local" { } object Zone "ubuntu.itzgeek.local" { endpoints = [ "ubuntu.itzgeek.local" ] parent = "master" } // Host Objects object Host "ubuntu.itzgeek.local" { check_command = "hostalive" address = "192.168.1.30" vars.client_endpoint = name //follows the convention that host name == endpoint name }
Since we have disabled inclusion of the conf.d
directory during the setup icinga2 node wizard
, we have to add services using command endpoint checks.
vi /etc/icinga2/zones.d/master/services.conf
Add the following basic services and few custom services.
// Ping Check apply Service "Ping" { check_command = "ping4" assign where host.address // check is executed on the master node } // System Load apply Service "System Load" { check_command = "load" command_endpoint = host.vars.client_endpoint // Check executed on client node assign where host.vars.client_endpoint } // System Process Count apply Service "Process" { check_command = "procs" command_endpoint = host.vars.client_endpoint assign where host.vars.client_endpoint } // Logged in User Count apply Service "Users" { check_command = "users" command_endpoint = host.vars.client_endpoint assign where host.vars.client_endpoint } // Disk Usage Check apply Service "Disk" { check_command = "disk" command_endpoint = host.vars.client_endpoint assign where host.vars.client_endpoint } // Disk Usage Check for Specific Partition apply Service for (disk => config in host.vars.local_disks) { check_command = "disk" vars += config command_endpoint = host.vars.client_endpoint assign where host.vars.client_endpoint } // System Swap Check apply Service "SWAP" { check_command = "swap" command_endpoint = host.vars.client_endpoint assign where host.vars.client_endpoint } // SSH Service Check apply Service "SSH Service" { check_command = "ssh" command_endpoint = host.vars.client_endpoint assign where host.vars.client_endpoint } // FTP Service Check apply Service "FTP Service" { check_command = "ftp" command_endpoint = host.vars.client_endpoint assign where host.vars.client_endpoint } // Icinga 2 Service Check apply Service "Icinga2 Service" { check_command = "icinga" command_endpoint = host.vars.client_endpoint assign where host.vars.client_endpoint } // Apache VirtualHost Check apply Service for (http_vhost => config in host.vars.local_http_vhosts) { check_command = "http" vars += config command_endpoint = host.vars.client_endpoint assign where host.vars.client_endpoint } // TCP Port Check apply Service for (tcp_port => config in host.vars.local_tcp_port) { check_command = "tcp" vars += config display_name = + vars.service_name + " - " + vars.port_number command_endpoint = host.vars.client_endpoint assign where host.vars.client_endpoint }
You can read more about service monitoring here.
Validate the configuration.
icinga2 daemon -C
Restart Icinga 2 on the master node.
### For Systemd Systems ### systemctl restart icinga2 ### For SysVinit Systems ### service icinga2 restart
Monitor Remote Linux Machines with Icinga 2
Now, you should be able to see both machines in Icinga Web 2 dashboard.
Dashboard >> Overview >> Hosts.

Click on the client machine to get the details of a particular node.

You can click on Services tab to see the status of checked services.
centos.itzgeek.local:

ubuntu.itzgeek.local:

Hope this article series helped you to setup Icinga 2 on your environment.
That’s All.