Skip to main content
nagiosUbuntu

Nagios Defining a new host

By October 22, 2013August 13th, 2017No Comments

In this tutorial we look a the method in Nagios defining a new host. So buckle up and get ready to enjoy the ride. So far we have just completed the installation and the server will monitor itself. To monitor other hosts we start be defining a host within the nagios.cfg configuration. Once we have the host defined we can look at adding them to groups and associating services with these hosts so we can monitor the HTTP server, database server or what ever we need. So lets start by looking  at the configuration directory. Can you remember where we said it was? …. Yes you are correct /etc/nagios3

/etc/nagios3

This is the configuration directory for Nagios on Ubuntu 12.04.  The main configuration file is nagios.cfg found in this directory. To make adding new entries easier though the main nagios.cfg file includes other directories. We can view this with the command

grep cfg_dir /etc/nagios3/nagios.cfg

The directive cfg_dir includes the complete directory, cfg_file just a single file.

We can see from the output of grep the the /etc/nagios3/conf.d directory is included and we will a new file to this directory. The name of the file does not matter but I will add it for a host called store so naming it store.cfg makes sense.

define host {
  host_name store.tup.local
  alias store
  address 192.168.0.8
  max_check_attempts 3
  check_period 24x7
  check_command check-host-alive
  contacts root
  notification_interval 60
  notification_period 24x7
}

The host definition is within the braces and of course this is just an extension on the nagios.cfg , so we could define more than one host or other settings in this file. Later we will add services to monitor on this host.

We are checking that the host is alive throughout the 24 hour period 7 days a week. The check is a ping and 3 failed pings will raise a host down alert. The configuration is still quite basic but it is enough to get us started on monitoring with Nagios Core.

Once we have saved the file we can run the pre-flight checks, so we do not try to restart Nagios without having verified the entries we have added.

sudo nagios3 -v /etc/nagios3/nagios.cfg | less

Once we are happy with the config we can restart the monitoring server

sudo /etc/init.d/nagios3 restart

Then connect with a browser and check all is happy.