Installing Nagios on FreeBSD 9.1 - Adding monitoring for hosts
In my previous post, I went through a basic Nagios installation on FreeBSD 9.1, but didn't go into adding new hosts.
We'll look into this here.
This tutorial assumes you configured Nagios from ports as in my previous post.
1. Modify the Nagios configuration (slightly!)
Let's first create a new subdirectory to drop in the new host configs.
cd /usr/local/etc/nagios
mkdir host-configurations
Now edit the main Nagios configuration to tell Nagios to look into that directory:
1. Edit the file /usr/local/etc/nagios/nagios.cfg with your favorite editor
2. Find the section:
# OBJECT CONFIGURATION FILE(S)
Note: The location of the line doesn't really matter, but why not keep things tidy?
3. Inside that section add the following:
cfg_dir=/usr/local/etc/nagios/host-configurations
2. Add a new host configuration
In my network I have another FreeBSD server with IP address 192.168.2.16. That server runs a custom Ruby (Sinatra) application on port 80. I'd like to make sure it's always up and running and since we're on it add a simple ping and SSH check.
So let's create a new file - it can be named anything as long as it has the .cfg extension, for this example I'm going to name it web-server.cfg. Therefore the full path is going to be:
/usr/local/etc/nagios/host-configurations/web-server.cfg
I'm going to add in it the following:
#
# HOST DEFINITION
#
# Define a host for the local machine
define host{
use freebsd-server ; Name of host template to use
; This host definition will inherit all variables that are defined
; in (or inherited by) the freebsd-server host template definition.
host_name web-server
alias My awesome web server
address 192.168.2.16
}
#
# SERVICE DEFINITIONS
#
# Define a service to "ping" the local machine
define service{
use local-service ; Name of service template to use
host_name web-server
service_description PING
check_command check_ping!100.0,20%!500.0,60%
}
# Define a service to check SSH on the local machine.
# Disable notifications for this service by default, as not all users may have SSH enabled.
define service{
use local-service ; Name of service template to use
host_name web-server
service_description SSH
check_command check_ssh
notifications_enabled 0
}
# Define a service to check HTTP on the local machine.
# Disable notifications for this service by default, as not all users may have HTTP enabled.
define service{
use local-service ; Name of service template to use
host_name web-server
service_description HTTP
check_command check_http
notifications_enabled 0
}
Then to make the configuration take effect don't forget to restart nagios:
/usr/local/etc/rc.d/nagios restart
3. Check the results in the web interface
Check the results in the web interface - open it up in your browser and click on 'Hosts' on the left. You should be seeing something like this:
If you use the search bar in the left to search for 'web-server' you'll get the status of the services: