Nagios and NConf on Ubuntu
juli 23rd, 2011 by rroethof
Have you been wondering about how to get Nagios and NConf setup on your Ubuntu server?
Well, here is my ‘notepad’ from the last time around, and here they are, for anyone that may find them useful.
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
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:///nagios3
If you would like to monitor external servers using NRPE or NSClient++, 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.
(Note: Version 1.2.6 was the latest as of the time of this writing, so make sure you’re getting the latest version.)
mv download nconf-1.2.6-0.tgz
Unpack it to your webroot:
sudo tar xzvf nconf-1.2.6-0.tgz -C /var/www
sudo tar xzvf nconf-1.2.6-0.tgz -C /var/www
Change the owner of the folder and files you just extracted to the web user:
sudo chown -R www-data:www-data /var/www/nconf
Now you’ll need to create a MySQL database to hold the NConf configuration data:
mysql -u root -p
create database nconf;
grant all privileges on nconf.* to nconf@localhost identified by ‘somepassword’;
Then browse to http:///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/ »
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 party on!
Start making your configuration changes in NConf and enjoy not having the manipulate those Nagios conf files by hand anymore
viaNagios and NConf on Ubuntu.