{"id":176,"date":"2010-08-24T14:15:53","date_gmt":"2010-08-24T22:15:53","guid":{"rendered":"https:\/\/digitalcardboard.com\/blog\/?p=176"},"modified":"2012-04-19T06:34:29","modified_gmt":"2012-04-19T14:34:29","slug":"nagios-and-nconf-on-ubuntu-10-04-lucid-lynx","status":"publish","type":"post","link":"https:\/\/digitalcardboard.com\/blog\/2010\/08\/24\/nagios-and-nconf-on-ubuntu-10-04-lucid-lynx\/","title":{"rendered":"Nagios and NConf on Ubuntu 10.04 Lucid Lynx"},"content":{"rendered":"<p><span style=\"color: #800000;\"><strong><em>As of December 2011, NConf has released version 1.3.0 which changes the deployment methods for configs. Take a look at my <a title=\"Upgrading to NConf 1.3.0 on Ubuntu 11.10 Oneiric Ocelot\" href=\"https:\/\/digitalcardboard.com\/blog\/2012\/01\/29\/upgrading-to-nconf-1-3-0-on-ubuntu-11-10-oneiric-ocelot\/\"><span style=\"color: #800000;\">NConf 1.3.0 upgrade guide<\/span><\/a>!<\/em><\/strong><\/span><\/p>\n<p>Have you been wondering about how to get <a href=\"http:\/\/www.nagios.org\/\" target=\"_blank\">Nagios<\/a> and <a href=\"http:\/\/www.nconf.org\/\" target=\"_blank\">NConf<\/a> setup on your Ubuntu server? \u00a0Well, I took some notes the last time around, and here they are, for anyone that may find them useful. \u00a0Here we go!<\/p>\n<p><em>(disclaimer: don&#8217;t screw up your system.)<\/em><\/p>\n<h2>Prerequisites<\/h2>\n<p>If you didn&#8217;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:<\/p>\n<pre>sudo apt-get install apache2\r\nsudo apt-get install mysql-server mysql-client\r\nsudo apt-get install php5 libapache2-mod-php5<\/pre>\n<p>If you want <em>phpMyAdmin <\/em>(for web-based MySQL administration):<\/p>\n<pre>sudo apt-get install phpmyadmin<\/pre>\n<h2>Installing Nagios<\/h2>\n<p>Install Nagios with<\/p>\n<pre>sudo apt-get install nagios3<\/pre>\n<p>It should install all the necessary dependencies. Follow the prompts to get it configured and test it out by browsing to <em>http:\/\/&lt;yourserver&gt;\/nagios3<\/em><\/p>\n<p>If you would like to monitor Windows servers using <a href=\"http:\/\/nsclient.org\/\">NSClient++<\/a> (which I am doing), also install the NRPE plugin with<\/p>\n<pre>sudo apt-get install nagios-nrpe-plugin<\/pre>\n<p>I felt like I ought to backup the config files before I started messing with them, so I backed them up with<\/p>\n<pre>sudo cp -r \/etc\/nagios3 \/etc\/nagios3.backup<\/pre>\n<h2>Installing NConf<\/h2>\n<p><a href=\"http:\/\/www.nconf.org\/\" target=\"_blank\">NConf<\/a> provides a web-based frontend for configuring Nagios. \u00a0There&#8217;s no package in the Ubuntu repositories for it, but you can download it pretty easily. \u00a0Version 1.2.6 was the latest as of the time of this writing, so make sure you&#8217;re getting the latest version. \u00a0(Note: it looks like the link below gets cut off, so here&#8217;s a <a href=\"http:\/\/sourceforge.net\/projects\/nconf\/files\/\" target=\"_blank\">link to the NConf download page<\/a> where you can grab the latest source)<\/p>\n<pre>wget http:\/\/sourceforge.net\/projects\/nconf\/files\/nconf\/1.2.6-0\/nconf-1.2.6-0.tgz\/download<\/pre>\n<div id=\"_mcePaste\">Unpack it to your webroot:<\/div>\n<pre>sudo tar xzvf nconf-1.2.6-0.tgz -C \/var\/www<\/pre>\n<div>Change the owner of the folder and files you just extracted to the web user:<\/div>\n<div>\n<pre>sudo chown -R www-data:www-data \/var\/www\/nconf<\/pre>\n<\/div>\n<div>Now you&#8217;ll need to create a MySQL database to hold the <em>NConf<\/em> configuration data. \u00a0Using phpMyAdmin (<strong>sudo apt-get install phpmyadmin<\/strong> if you don&#8217;t have it) do the following:<\/div>\n<div>\n<ul>\n<li>Privileges -&gt; Add a new User<\/li>\n<li>User name: <em>nconf<\/em><\/li>\n<li>Host: <em>localhost<\/em><\/li>\n<li>Password: <em>(generate, and make a note of the generated password)<\/em><\/li>\n<li>Create database with the same name and grant all privileges<\/li>\n<li>Go<\/li>\n<li>Privileges -&gt; reload the privileges<\/li>\n<\/ul>\n<\/div>\n<p>Then browse to <em>http:\/\/&lt;yourserver&gt;\/nconf <\/em>and follow the prompts to finish initial configuration of <em>NConf<\/em>.<\/p>\n<p>When you get to the database configuration page, enter <strong>nconf<\/strong> 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 <strong>NAGIOS_BIN<\/strong> variable to <strong>\/usr\/sbin\/nagios3<\/strong> to reference the right location.<\/p>\n<p>Finally, remove the folders and files referenced at the end of the installation process:<\/p>\n<pre>sudo rm -r \/var\/www\/nconf\/INSTALL\r\nsudo rm \/var\/www\/nconf\/INSTALL.php\r\nsudo rm -r \/var\/www\/nconf\/UPDATE\r\nsudo rm \/var\/www\/nconf\/UPDATE.php<\/pre>\n<p>At this point, you should be able to login to <em>NConf<\/em>, although it won&#8217;t be doing anything of importance.<\/p>\n<h2>Configuring Nagios to use NConf<\/h2>\n<p>We&#8217;ll need to make some changes to one of the Nagios configuration files, so (using <strong>sudo<\/strong>) open up <em>\/etc\/nagios3\/nagios.cfg<\/em> in your favorite editor and delete or comment out all the lines that begin with <strong>cfg_dir=<\/strong> or <strong>cfg_file=<\/strong> and add the following lines:<\/p>\n<p><span style=\"font-family: Consolas, Monaco, 'Courier New', Courier, monospace; line-height: 18px; font-size: 12px; white-space: pre;\">cfg_dir=\/etc\/nagios3\/global<br \/>\n<\/span><span style=\"font-family: Consolas, Monaco, 'Courier New', Courier, monospace; line-height: 18px; font-size: 12px; white-space: pre;\">cfg_dir=\/etc\/nagios3\/Default_collector<\/span><\/p>\n<p>Back at the terminal, run the following command to create a folder for NConf to dump the configuration files it generates.<\/p>\n<pre>sudo mkdir \/etc\/nagios3\/import<\/pre>\n<h2>Configuring NConf to Deploy Nagios Configurations Automatically<\/h2>\n<p>Almost there. Using <strong>sudo<\/strong>, open up\u00a0<em>\/var\/www\/nconf\/ADD-ONS\/deploy_local.sh<\/em> and make the following changes to paths:<\/p>\n<pre>OUTPUT_DIR=\"\/var\/www\/nconf\/output\/\"\r\nNAGIOS_DIR=\"\/etc\/nagios3\/\"\r\n...\r\n\/etc\/init.d\/nagios3 reload<\/pre>\n<p><a href=\"https:\/\/digitalcardboard.com\/blog\/2010\/08\/24\/nagios-and-nconf-on-ubuntu-10-04-lucid-lynx\/#comment-13772\">GM<\/a>\u00a0and <a href=\"https:\/\/digitalcardboard.com\/blog\/2010\/08\/24\/nagios-and-nconf-on-ubuntu-10-04-lucid-lynx\/#comment-26047\">Allison<\/a>\u00a0pointed out in the comments that they had to set the execute bit on this file:<\/p>\n<pre>chmod +x \/var\/www\/nconf\/ADD-ONS\/deploy_local.sh<\/pre>\n<p>This script will deploy the generated configuration package and then reload the running instance of Nagios, but it&#8217;s easiest to use just installed in the root crontab.<\/p>\n<pre>sudo crontab -e<\/pre>\n<p>and adding the line<\/p>\n<pre>* * * * * \/var\/www\/nconf\/ADD-ONS\/deploy_local.sh<\/pre>\n<h2>Final Steps<\/h2>\n<p>After saving and closing the root crontab, log back into <em>NConf<\/em> and take a look around. \u00a0You&#8217;ll see some sample definitions and some predefined services for the localhost computer. \u00a0You may want to delete the <em>check_local_mrtgtraf<\/em> and <em>check_local_procs<\/em> services, as the first one doesn&#8217;t work without additional configuration and the second one is a sample definition, but you can make those changes at your leisure.<\/p>\n<p>Once you&#8217;re ready, click <strong>Generate Nagios config<\/strong>, and if all goes well, you&#8217;ll see something like the following:<\/p>\n<pre>[ Initializing NConf perl-API (library version 0.2, written by A. Gargiulo) ]\r\n[ Copyright (c) 2006-2009 Sunrise Communications AG, Zurich, Switzerland    ]\r\n\r\n[INFO]  Starting generate_config script\r\n[INFO]  Generating global config files\r\n[INFO]  Generating config for Nagios-collector 'Default Nagios'\r\n[INFO]  Ended generate_config script\r\n\r\nRunning syntax check:\r\n\r\n\t  Default_collector:\t Total Warnings: 0  Total Errors: 0\r\nChanges updated successfully.<\/pre>\n<p>Now log back into <em>Nagios<\/em> and click on <strong>Service Detail<\/strong>. \u00a0Within a minute or two, you should see the hosts and services change to reference the configuration as generated from <em>NConf<\/em>.<\/p>\n<p>If that works, then huzzah!<\/p>\n<p>Start making your configuration changes in <em>NConf<\/em> and enjoy not having the manipulate those <em>Nagios<\/em> conf files by hand anymore!<\/p>\n<h2>Troubleshooting, Tips and Caveats<\/h2>\n<p>Try running the <strong>deploy_local.sh<\/strong> script by hand (with <strong>sudo<\/strong>) if it doesn&#8217;t appear that <em>Nagios<\/em> is getting the configurations from NConf. You may be able to glean some information from the output of that script.<\/p>\n<p>New hosts not showing up in <em>Nagios<\/em> after being created in <em>NConf<\/em>? Make sure you&#8217;ve selected <strong>Default Nagios<\/strong> under <strong>&#8220;monitored by&#8221;<\/strong> when defining the host, or that host won&#8217;t get assigned properly.<\/p>\n<p>This setup process effectively disables all the command definitions provided by the package install of <em>Nagios<\/em>, which are stored under <em>\/etc\/nagios-plugins\/config<\/em>. \u00a0I looked through them and compared them to the ones provided by default with <em>NConf<\/em>, and I was fine with what <em>NConf<\/em> provided. \u00a0<em>NConf<\/em> provides a mechanism to import command definitions if you really find that you need them.<\/p>\n<p>I have no idea how this setup will hold up under an upgrade of the Nagios package. \u00a0We&#8217;ll see when the time comes, and if I remember, I&#8217;ll update these notes.<\/p>\n<p>If you have any trouble with the steps provided above, please comment and I&#8217;ll do what I can to assist.<\/p>\n<h2>More Information<\/h2>\n<p>Take a look at the following documentation from <em>NConf<\/em>:<\/p>\n<ul>\n<li><a href=\"http:\/\/www.nconf.org\/dokuwiki\/doku.php?id=nconf:help:documentation:quick-start_guide\" target=\"_blank\">Quick-start guide<\/a><\/li>\n<li><a href=\"http:\/\/www.nconf.org\/dokuwiki\/doku.php?id=nconf:help:documentation:installation\" target=\"_blank\">Installation guide<\/a><\/li>\n<li><a href=\"http:\/\/www.nconf.org\/dokuwiki\/doku.php?id=nconf:help:documentation:how_tos:configuration_deployment\" target=\"_blank\">Configuration deployment<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>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? \u00a0Well, I took some notes the last time around, and here they are, for [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[29],"tags":[23,32,30,31,79],"class_list":["post-176","post","type-post","status-publish","format-standard","hentry","category-system-administration","tag-linux","tag-monitoring","tag-nagios","tag-nconf","tag-ubuntu"],"_links":{"self":[{"href":"https:\/\/digitalcardboard.com\/blog\/wp-json\/wp\/v2\/posts\/176","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/digitalcardboard.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/digitalcardboard.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/digitalcardboard.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/digitalcardboard.com\/blog\/wp-json\/wp\/v2\/comments?post=176"}],"version-history":[{"count":5,"href":"https:\/\/digitalcardboard.com\/blog\/wp-json\/wp\/v2\/posts\/176\/revisions"}],"predecessor-version":[{"id":284,"href":"https:\/\/digitalcardboard.com\/blog\/wp-json\/wp\/v2\/posts\/176\/revisions\/284"}],"wp:attachment":[{"href":"https:\/\/digitalcardboard.com\/blog\/wp-json\/wp\/v2\/media?parent=176"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/digitalcardboard.com\/blog\/wp-json\/wp\/v2\/categories?post=176"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/digitalcardboard.com\/blog\/wp-json\/wp\/v2\/tags?post=176"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}