Nagios automatic configuration using NConf
Today i worked on a simple configuration of Nagios but it is very long and tricky. In Nagios Core site library i’ve found several projects that help SysAdmin to configure the monitored sytems in a simple manner. One of these is NConf, a web based configurator.
Here a description of the first configuration.
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 ofNConf.
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 withcfg_dir= or cfg_file= and add the following lines:
Note: look at the paths because NConf deploy automatically to these paths the configuration files.
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
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
sudo crontab -e
* * * * * /var/www/nconf/ADD-ONS/deploy_local.sh
[ 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.
Troubleshooting, Tips and Caveats
For Path problems you can get these errors:When I am trying to verify the nagios with “nagios -v /etc/nagios/nagios.cfg” command
I got following problem.
Total Warnings: 0
Total Errors: 3
Error: There are no services defined!
Checked 0 services.
Error: There are no hosts defined!
Checked 0 hosts.
Error: There are no contacts defined!
Checked 0 contacts.
Simple control that the deployed files are in the correct place.