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.)
Prerequisites
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
Installing Nagios
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
Installing NConf
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)
wget http://sourceforge.net/projects/nconf/files/nconf/1.2.6-0/nconf-1.2.6-0.tgz/download
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
- Go
- 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:
cfg_dir=/etc/nagios3/global
cfg_dir=/etc/nagios3/Default_collector
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
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
Final Steps
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.
More Information
Take a look at the following documentation from NConf:
37 Comments
When I generate the config file for Nagios, I see no errors and everthing looks fine. However, I never see the changes in Nagios. Any suggestions?
Sounds like NConf may not be deploying the config properly to Nagios (if at all). Did you configure the deploy_local.sh script?
I pretty much have everything working.. except for ..
when I add
cfg_dir=/usr/local/nagios/global
cfg_dir=/usr/local/nagios/Default_collector
nagios borks and won’t startup..
any ideas?
It’s possible that it might be a permissions issue. Does /var/log/nagios3/nagios.log reveal anything of value when it fails to start?
Nevermind.. sorted it.. I had left some of the other directives in that file uncommented…
thanks…
Hey Jason, thanks for the post. Can I suggest a couple of additions?
# Install mysql (I didn’t have this on a fresh Lucid box)
sudo aptitude install mysql-server
sudo aptitude install libapache2-mod-auth-mysql phpmyadmin
It seems like you also have to comment out cfg_file in addition to cfg_dir in nagios.cfg. This blocked me from a proper config loading with the deploy script.
Also, in the deploy script, might want to note that you need to be careful with slashes and the ’3′ for nagios3.. I missed a slash in the import which caused a few issues as well.
Thanks again for the post!
Ah, I had installed the LAMP stuff when I setup the server, but good point. I’ll make a note of that.
Thanks for mentioning to comment out cfg_file, I spent the last two hours going through every file related to Nagios to get it to start/update properly. I came back here to re-read, and your comment got me up and running right away.
Not sure where I have gone wrong but on the /etc/init.d/nagios3 reload I get a failure
***> One or more problems was encountered while running the pre-flight check…
Check your configuration file(s) to ensure that they contain valid
directives and data defintions. If you are upgrading from a previous
version of Nagios, you should be aware that some variables/definitions
may have been removed or modified in this version. Make sure to read
the HTML documentation regarding the config files, as well as the
‘Whats New’ section to find out what has changed.
* errors in config!
[fail]
ANy help would me appriaciated, PS I had to create the global and Default_collector manually
im also getting a /var/www/nconf/ADD-ONS/deploy_local.sh: Permission denied
Ive eddited this using winscp so not if ive done somthing wrong there any help would be great
Thanks
Might be a permissions issue. Is anything being generated in the /etc/nagios3/global and Default_collector folders? They should be owned by www-data:www-data with 755 perms on both folders.
Also, can you run the deploy_local.sh script by hand (using sudo)?
Fantastic I had the permission correct on the folder ADD-ONS but checking deploy_local.sh that was set to 644 changed that and another file in the same folder to 755 and it worked
Thanks for your help
Error accessing or executing Nagios / Icinga binary ‘usr/sbin/nagios3′.
Cannot run the mandatory syntax check.
This error I got at the end, after trying to add a host, hope someone can help me?
Can you run the /usr/sbin/nagios3 binary manually from the terminal?
Error accessing or executing Nagios / Icinga binary ‘etc/nagios3?.
Cannot run the mandatory syntax check.
I also got this error at the end.. Any suggestions?
Regards
Double check the path to nagios. You should be able to execute it manually by running
/usr/sbin/nagios3from the terminal.If you need to edit the path, you can change it in the configs at
/var/www/nconf/config/nconf.phpAwesome thanks!!
I’ve run thru twice, reverting back to a VM snapshot between times and I get the same error:
Nagios Core 3.2.0
Copyright (c) 2009 Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last Modified: 08-12-2009
License: GPL
Website: http://www.nagios.org
Reading configuration data…
Read main config file okay…
Processing object config file ‘/var/www/nconf/temp/global/host_templates.cfg’…
Processing object config file ‘/var/www/nconf/temp/global/timeperiods.cfg’…
Processing object config file ‘/var/www/nconf/temp/global/contacts.cfg’…
Processing object config file ‘/var/www/nconf/temp/global/service_templates.cfg’…
Processing object config file ‘/var/www/nconf/temp/global/misccommands.cfg’…
Processing object config file ‘/var/www/nconf/temp/global/contactgroups.cfg’…
Processing object config file ‘/var/www/nconf/temp/global/checkcommands.cfg’…
Processing object config file ‘/var/www/nconf/temp/Default_collector/hosts.cfg’…
Processing object config file ‘/var/www/nconf/temp/Default_collector/hostgroups.cfg’…
Processing object config file ‘/var/www/nconf/temp/Default_collector/extended_host_info.cfg’…
Processing object config file ‘/var/www/nconf/temp/Default_collector/services.cfg’…
Processing object config file ‘/var/www/nconf/temp/Default_collector/servicegroups.cfg’…
Processing object config file ‘/var/www/nconf/temp/Default_collector/extended_service_info.cfg’…
Error: Service description, host name, or check command is NULL
Error: Could not register service (config file ‘/var/www/nconf/temp/Default_collector/services.cfg’, starting on line 58)
Error processing object config files!
***> The name of the main configuration file looks suspicious…
Make sure you are specifying the name of the MAIN configuration file on
the command line and not the name of another configuration file. The
main configuration file is typically ‘/usr/local/nagios/etc/nagios.cfg’
***> One or more problems was encountered while processing the config files…
Check your configuration file(s) to ensure that they contain valid
directives and data defintions. If you are upgrading from a previous
version of Nagios, you should be aware that some variables/definitions
may have been removed or modified in this version. Make sure to read
the HTML documentation regarding the config files, as well as the
‘Whats New’ section to find out what has changed.
Where is it getting services.cfg from and why is puking on line 58??
Looks like you’re deploying your configs to /var/www/nconf/temp/ rather than /etc/nagios3/ so it’s possible it could be a permissions issue.
Also, check through your services definitions from within NConf. It’s possible you’ve got a faulty service being generated from NConf, so Nagios throws it back.
Figured it out earlier today, deleting the check_local_procs and check_mgttraf broke it. Skipped that step and it worked fine.
I have succesfully deploy nconf and nagios3. But nconf still can not automatically extract output to /etc/nagios3. I already give access to user www-data to /etc/nagios3. But nconf still cannot write the output. So i manually extract file NagiosConfig.tgz into dir /etc/nagios3, restarting nagios and all item now appear in map
Did you create the import folder in /etc/nagios3/ ?
I got the nagios3 and nconf to work but when i try to do a deploy files dont get deploy automatically, it doesn’t extract the files in import
I tried to manually extract the files but i get this error.
Processing object config file ‘/etc/nagios3/global/checkcommands.cfg’…
Processing object config file ‘/etc/nagios3/global/timeperiods.cfg’…
Processing object config file ‘/etc/nagios3/global/host_templates.cfg’…
Processing object config file ‘/etc/nagios3/global/commands.cfg’…
Warning: Duplicate definition found for command ‘process-host-perfdata’ (config file ‘/etc/nagios3/global/commands.cfg’, starting on line 16)
Error: Could not add object property in file ‘/etc/nagios3/global/commands.cfg’ on line 17.
Error processing object config files!
***> One or more problems was encountered while processing the config files…
Check your configuration file(s) to ensure that they contain valid
directives and data defintions. If you are upgrading from a previous
version of Nagios, you should be aware that some variables/definitions
may have been removed or modified in this version. Make sure to read
the HTML documentation regarding the config files, as well as the
‘Whats New’ section to find out what has changed.
* errors in config!
This was the content of the File “global/commands.cfg”
cat global/commands.cfg
#define command {
# command_name notify-host-by-email
# command_line /usr/bin/printf “%b” “***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n” | /bin/mail -s “** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **” $CONTACTEMAIL$
#}
#define command {
# command_name notify-service-by-email
# command_line /usr/bin/printf “%b” “***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$” | /bin/mail -s “** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **” $CONTACTEMAIL$
#}
define command {
command_name check-host-alive
command_line $USER1$/check_ping -H $HOSTADDRESS$ -w 3000.0,80% -c 5000.0,100% -p 5
}
define command {
command_name process-host-perfdata
command_line /usr/bin/printf “%b” “$LASTHOSTCHECK$\t$HOSTNAME$\t$HOSTSTATE$\t$HOSTATTEMPT$\t$HOSTSTATETYPE$\t$HOSTEXECUTIONTIME$\t$HOSTOUTPUT$\t$HOSTPERFDATA$\n” >> /var/nagios/host-perfdata.out
}
define command {
command_name process-service-perfdata
command_line /usr/bin/printf “%b” “$LASTSERVICECHECK$\t$HOSTNAME$\t$SERVICEDESC$\t$SERVICESTATE$\t$SERVICEATTEMPT$\t$SERVICESTATETYPE$\t$SERVICEEXECUTIONTIME$\t$SERVICELATENCY$\t$SERVICEOUTPUT$\t$SERVICEPERFDATA$\n” >> /var/nagios/service-perfdata.out
}
define command {
command_name service_is_stale
command_line /usr/lib/nagios/plugins/eventhandlers/stale_service.sh
}
Can anyone tell me what i am doing wrong.. here ..
If you’re getting duplicate definition errors, make sure you’ve commented out or removed all the
cfg_dir=lines in the nagios.cfg file. It seems like Nagios is still trying to reference one of the standard config files.Hey This is fixed there were Duplicate entries in 2 different files..
I’m running ubuntu server natty, nagios3 , nconf.
Just thought I would add what I had to do to for my install to work.
More than likely its because I had not read the above properly but i’ll post anyway!
cfg_dir=/etc/nagios3/global
cfg_dir=/etc/nagios3/Default_collector
I had to create these folders.
I also had to chmod +x /var/www/nconf/ADD-ONS/deploy_local.sh
Then I ran var/www/nconf/ADD-ONS/deploy_local.sh by using sudo ./deploy_local.sh from the directory
Then I ran sudo /etc/init.d/nagios3 restart
Thanks to this guide it pointed me in the right direction and I thank you!
do you know if there is a way to incorporate this into NConf “Generate Nagios config” action
edit: The method in the above post is how I have to do it, however I do not know why and wish there was a fix I could use
Take a look at the section Configuring NConf to Deploy Nagios Configurations Automatically. Once NConf generates the deploy file, the cron job should pick it up and put it in the right place, if it all works.
Se alguem tiver com esse erro:
Error accessing or executing Nagios / Icinga binary ‘/var/www/html/nconf/bin/nagios’. Cannot run the mandatory syntax check.
No meu caso o NConf não estava encontrando os binarios do nagios.
rode o comando:
cp /usr/local/nagios/bin/* /var/www/html/nconf/bin/nagios
flow
When I add any host in Nconf, m not able to view it in Nagios frontend.
Can you verify that Nconf is generating a config file and that Nagios is picking it up?
Thank you a lot!! It works! ) But i had to correct configs slightly ^)
Followed your guide exactly but what I add via NConf is not being updated to Nagios. I checked the directories and everything, files are being generated. Perhaps I missed something with removing the cfg lines in nagios.cfg?
Disregard the previous comment, I commented out the logfile in nagios.cfg…
Gogo retard move!
Glad that it’s working for you!
Thanks for a nice tutorial, however i believe a few steps are missing..I followed all the steps by nagios didnt started at the end with error
——
***> One or more problems was encountered while running the pre-flight check…
Check your configuration file(s) to ensure that they contain valid
directives and data defintions. If you are upgrading from a previous
version of Nagios, you should be aware that some variables/definitions
may have been removed or modified in this version. Make sure to read
the HTML documentation regarding the config files, as well as the
‘Whats New’ section to find out what has changed.
errors in config! … failed!
failed!
——————
Then I figured that “generate nagios config” need to run from nconf, which generate a .tgz file in output directory which give a gloabl and default_collector folder when we extract it, and those 2 need to be copied in /etc/nagios3
I did and everything went well…
I thought to mention my experience and my findings..
Thanks for a nice tutorial again, all credit goes to you my friend
2 Trackbacks
[...] Using (and embellishing upon) instructions for Installing Nagios and Nconf on Ubuntu 10.04 http://digitalcardboard.com/blog/2010/08/24/nagios-and-nconf-on-ubuntu-10-04-lucid-lynx/ [...]
[...] been over a year since I originally installed and configured Nagios and NConf 1.2.6 on my Lucid Lynx server. In the meantime, I’ve upgraded the hardware and moved to Ubuntu 11.10 Oneiric Ocelot, mostly [...]