As of December 2011, NConf has released version 1.3.0 which changes the deployment methods for configs. Take a look at my NConf 1.3.0 upgrade guide!
Have you been wondering about how to get Nagios and NConf setup on your Ubuntu server? Well, I took some notes the last time around, and here they are, for anyone that may find them useful. Here we go!
(disclaimer: don’t screw up your system.)
If you didn’t check the box to configure your box as a LAMP (Linux, Apache, MySQL, PHP) server when you first setup your box, do that first with:
sudo apt-get install apache2 sudo apt-get install mysql-server mysql-client sudo apt-get install php5 libapache2-mod-php5
If you want phpMyAdmin (for web-based MySQL administration):
sudo apt-get install phpmyadmin
Install Nagios with
sudo apt-get install nagios3
It should install all the necessary dependencies. Follow the prompts to get it configured and test it out by browsing to http://<yourserver>/nagios3
If you would like to monitor Windows servers using NSClient++ (which I am doing), also install the NRPE plugin with
sudo apt-get install nagios-nrpe-plugin
I felt like I ought to backup the config files before I started messing with them, so I backed them up with
sudo cp -r /etc/nagios3 /etc/nagios3.backup
NConf provides a web-based frontend for configuring Nagios. There’s no package in the Ubuntu repositories for it, but you can download it pretty easily. Version 1.2.6 was the latest as of the time of this writing, so make sure you’re getting the latest version. (Note: it looks like the link below gets cut off, so here’s a link to the NConf download page where you can grab the latest source)
sudo tar xzvf nconf-1.2.6-0.tgz -C /var/www
sudo chown -R www-data:www-data /var/www/nconf
- Privileges -> Add a new User
- User name: nconf
- Host: localhost
- Password: (generate, and make a note of the generated password)
- Create database with the same name and grant all privileges
- Privileges -> reload the privileges
Then browse to http://<yourserver>/nconf and follow the prompts to finish initial configuration of NConf.
When you get to the database configuration page, enter nconf for the username and the database name, and use the generated password you should have made a note of earlier. For most everything else, accept the defaults, but change the NAGIOS_BIN variable to /usr/sbin/nagios3 to reference the right location.
Finally, remove the folders and files referenced at the end of the installation process:
sudo rm -r /var/www/nconf/INSTALL sudo rm /var/www/nconf/INSTALL.php sudo rm -r /var/www/nconf/UPDATE sudo rm /var/www/nconf/UPDATE.php
At this point, you should be able to login to NConf, although it won’t be doing anything of importance.
Configuring Nagios to use NConf
We’ll need to make some changes to one of the Nagios configuration files, so (using sudo) open up /etc/nagios3/nagios.cfg in your favorite editor and delete or comment out all the lines that begin with cfg_dir= or cfg_file= and add the following lines:
Back at the terminal, run the following command to create a folder for NConf to dump the configuration files it generates.
sudo mkdir /etc/nagios3/import
Configuring NConf to Deploy Nagios Configurations Automatically
Almost there. Using sudo, open up /var/www/nconf/ADD-ONS/deploy_local.sh and make the following changes to paths:
OUTPUT_DIR="/var/www/nconf/output/" NAGIOS_DIR="/etc/nagios3/" ... /etc/init.d/nagios3 reload
chmod +x /var/www/nconf/ADD-ONS/deploy_local.sh
This script will deploy the generated configuration package and then reload the running instance of Nagios, but it’s easiest to use just installed in the root crontab.
sudo crontab -e
and adding the line
* * * * * /var/www/nconf/ADD-ONS/deploy_local.sh
After saving and closing the root crontab, log back into NConf and take a look around. You’ll see some sample definitions and some predefined services for the localhost computer. You may want to delete the check_local_mrtgtraf and check_local_procs services, as the first one doesn’t work without additional configuration and the second one is a sample definition, but you can make those changes at your leisure.
Once you’re ready, click Generate Nagios config, and if all goes well, you’ll see something like the following:
[ Initializing NConf perl-API (library version 0.2, written by A. Gargiulo) ] [ Copyright (c) 2006-2009 Sunrise Communications AG, Zurich, Switzerland ] [INFO] Starting generate_config script [INFO] Generating global config files [INFO] Generating config for Nagios-collector 'Default Nagios' [INFO] Ended generate_config script Running syntax check: Default_collector: Total Warnings: 0 Total Errors: 0 Changes updated successfully.
Now log back into Nagios and click on Service Detail. Within a minute or two, you should see the hosts and services change to reference the configuration as generated from NConf.
If that works, then huzzah!
Start making your configuration changes in NConf and enjoy not having the manipulate those Nagios conf files by hand anymore!
Troubleshooting, Tips and Caveats
Try running the deploy_local.sh script by hand (with sudo) if it doesn’t appear that Nagios is getting the configurations from NConf. You may be able to glean some information from the output of that script.
New hosts not showing up in Nagios after being created in NConf? Make sure you’ve selected Default Nagios under “monitored by” when defining the host, or that host won’t get assigned properly.
This setup process effectively disables all the command definitions provided by the package install of Nagios, which are stored under /etc/nagios-plugins/config. I looked through them and compared them to the ones provided by default with NConf, and I was fine with what NConf provided. NConf provides a mechanism to import command definitions if you really find that you need them.
I have no idea how this setup will hold up under an upgrade of the Nagios package. We’ll see when the time comes, and if I remember, I’ll update these notes.
If you have any trouble with the steps provided above, please comment and I’ll do what I can to assist.
Take a look at the following documentation from NConf: