Once Nagios is installed, you will need to configure one host to monitor. We recommend also setting a service to be monitored.
To begin our trip through Nagios’s configuration, we are going to start with the main configuration file.
vanhelsing:/usr/local/nagios/etc# vim nagios.cfg-sample (If you did the samples install above)
A few items to confirm:
enable_notifications=1 date_format=us (Or your format of choice)
You will find each of these settings under their own header in the nagios.cfg file. Make sure you save it a nagios.cfg if you are editing the sample files. After that, we will want to add a host and a service. All IPs have been changed to protect the guilty and/or innocent.
vanhelsing:/usr/local/nagios/etc# vim hosts.cfg
Add the following to your hosts.cfg file, customized for whatever host you want to test with:
# SQLTest host definition define host{ use generic-host host_name sqltest register 1 alias SQL Test Server address 10.1.1.37 check_command check-host-alive max_check_attempts 10 notification_interval 120 notification_period 24x7 notification_options d,u,r }
An explanation of what this means:
use - Name of host template to use, you will have the generic-host template already. host_name - Host name (aka computer name for you Windows admins) register - Whether to register this host with Nagios (should always be a 1, unless you are building a template alias - display name on the Nagios alerts and notifications address - IP address of host check_command - check command to use on this host notification_period - time period to notify applicable contacts notification_options - when to send a notification on (d = down, u = unreachable, r = recovered) max_check_attempts - times to retry if the check does not return a host okay. notification_interval - time in minutes to wait until contact get an additional notice that the host is still down
Now for a service:
vanhelsing:/usr/local/nagios/etc# vim services.cfg
As before, customize for your test host.
# service def for MS SQL define service{ use generic-service host_name sqltest service_description MSSQL is_volatile 0 check_period 24x7 max_check_attempts 3 normal_check_interval 3 retry_check_interval 1 contact_groups nt-admins notification_interval 120 notification_period 24x7 notification_options w,u,c,r check_command check_nt!MSSQLServer }
For an explanation of options we have not seen before:
Service_description - Description of the Service being monitored; you can make it whatever you want Contact_groups - groups to contact if this service fails Check_command - check command to run to test this service
The check_nt command needs to be added to the checkcommands.cfg file. You’d add it now if you have to watch NT boxes; and you are following my examples. Also, don’t forget to download and install NSClient onto those NT based machines. The install is quick and simple.
Once you have these files modified, check your configuration. Before you run this command, you have to have the rest of the config files ready. We recommend moving most of the samples except for the following files: checkcommands.cfg, contact-groups.cfg and contacts.cfg. So, move the samples except those files and create blank ones with touch, e.g. as follows:
vanhelsing:/usr/local/nagios/bin# touch dependencies.cfg
At this point, you should have at least one host, one service. Now would be a good time to run the sanity check on your configuration files.
vanhelsing:/usr/local/nagios/bin# ./nagios -v ../etc/nagios.cfg Nagios 1.2 Copyright (c) 1999-2004 Ethan Galstad (nagios@nagios.org) Last Modified: 02-02-2004 License: GPL Reading configuration data... Running pre-flight check on configuration data... Checking services... Checked 8 services. Checking hosts... Checked 7 hosts. ? Checking time periods... Checked 4 time periods. Checking for circular paths between hosts... Checking for circular service execution dependencies... Checking global event handlers... Checking obsessive compulsive service processor command... Checking misc settings... Total Warnings: 3 Total Errors: 0 Things look okay - No serious problems were detected during the pre-flight check vanhelsing:/usr/local/nagios/bin#
If you come up with warnings, you are usually okay, but errors are bad. For example, if you get a “can’t parse file” error or something similar, go back and check your config files for misspellings, brackets, and the like.