Basic Nagios Core config

Basic Nagios Core config

This post describes the steps and principles involved in updating the default Nagios configuration to add a network host with a single service. It assumes a running Nagios system has already been setup as described here.

Nagios Core is configured by editing text files which reside in one of the following directories:

/usr/local/nagios/etc/
/usr/local/nagios/etc/objects/

To direct Nagios to monitor a single host with a single service simply add a config file for the host and give it a useful name. For example, I added my ISP’s router which has a web interface on HTTP. It’s a Virgin router so I called the config file vmrouter.cfg, creating it as follows:

sudo nano /usr/local/nagios/etc/objects/vmrouter.cfg

The above command creates the file and opens it in the nano editor. To add the host for monitoring simply add the following lines into the file, replacing the address with the correct IP (or hostname) address for your device:

define host {
        use                     generic-switch
        host_name               Virgin Router
        alias                   router
        address                 192.168.0.1
}

To close and save the file use the usual nano commands – Ctrl+X to close, “Y” to answer “yes” to overwriting the filename and <ENTER> to complete.

That creates a config file for the host itself but Nagios doesn’t know anything about the existence of it yet. To tell Nagios about it and prompt it to retrieve it’s details, edit the main Nagios config file:

sudo nano /usr/local/nagios/etc/nagios.cfg

and add a line to tell Nagios to read the new file. You can add the line anywhere but an ideal spot is just below the default files. Add the following line (with a comment to remind you later):

# added by me to monitor my VM router
cfg_file=/usr/local/nagios/etc/objects/vmrouter.cfg

so that the existing block looks like this:

# Definitions for monitoring the local (Linux) host
cfg_file=/usr/local/nagios/etc/objects/localhost.cfg

# added by me to monitor my VM router
cfg_file=/usr/local/nagios/etc/objects/vmrouter.cfg

Nagios needs to be restarted in order to reload the config files:

sudo systemctl restart nagios.service

If all goes well you’ll be returned to your command prompt without any output. If you receive any errors they’ll be displayed on the console and you’ll need to go back and check what you’ve edited.

Assuming all is working your Nagios dashboard should now show a new entry in the hosts area to show whether your router is up or down.

Adding a service for Nagios to monitor is achieved as follows:

sudo nano /usr/local/nagios/etc/objects/vmrouter.cfg

to edit the config file. Add the following to the existing text you created earlier:

define service {
        use                     local-service
        host_name               Virgin Router
        service_description     HTTP
        check_command           check_http
}

close and save as before (Ctrl+X, Y, <ENTER>). You don’t need to edit the nagios.cfg file as your changes are all contained within the host file that Nagios is already aware of. You do, however, need to force Nagios to re-read it by restarting:

sudo systemctl restart nagios.service

Again, if all goes well you should have an “HTTP” service listed in the services section of the Nagios dashboard.

Nagios can monitor various hosts and services, has some default checks built in and is capable of accessing other tools on the localhost machine to perform extended checks of devices and services on the network. The web has a heap of resources about these features and the default and template config files in the directories above are also good reading material.

Nagios can also alert by email and other methods when events occur. Another post sometime soon will detail how to set a basic notification system up.

3 Replies to “Basic Nagios Core config”

Leave a Reply

Your email address will not be published. Required fields are marked *