Nagios 4.x Install from Source on Ubuntu 12.04


This post is in the category: Guides

Posts here are mostly step-by-step guides on how to replicate something I have set up in the past. Read over my About page to see how I show commands/output and read the disclaimer.


I do not have Nagios 4.x on any production boxes yet, but I want to keep track on how this is working on Ubuntu 12.04. Apparently Nagios Core wasn’t well tested for Debian systems if at all. But in any case, it can be installed with a couple modifications.

This guide is going to be very similar to my guide on Nagios 3.x.

Update: Are you already on Ubuntu 14.04? Head on over here for the latest guide.

I will refer to this server with the hostname s10-nagios. Change at will, but adjust the commands accordingly.

Demo Video

Base OS Installation

Install Ubuntu Server 12.04. If you are provisioning a VM, a 24GB drive will be plenty.

Set a root password. Yeah, it’s best to use sudo for the one-off commands. But sometimes being root is just easier.

[user]$ sudo passwd root

Be sure we are on the latest updates:

[root]$ apt-get update
[root]$ apt-get dist-upgrade

Some basic reminders: Set account passwords, bash prompts, etc.

Nagios & Plugins Install

This guide is for Nagios 4.0.6. You may choose to use a different version, just make sure you adjust the commands that deal with version numbers accordingly.

Prepare the Nagios User & Group

[root]$ useradd -m -s /bin/bash nagios
[root]$ passwd nagios

Create the group needed for submitting commands from the web.

[root]$ groupadd nagcmd
[root]$ usermod -a -G nagcmd nagios
[root]$ usermod -a -G nagcmd www-data

Download / Extract Archives

[root]$ cd ~
[root]$ wget http://downloads.sourceforge.net/project/nagios/nagios-4.x/nagios-4.0.6/nagios-4.0.6.tar.gz 
[root]$ tar -xzvf nagios-4.0.6.tar.gz
[root]$ wget https://www.nagios-plugins.org/download/nagios-plugins-1.5.tar.gz
[root]$ tar -xzvf nagios-plugins-1.5.tar.gz

By the way, both of those tar command were without referencing the docs.

Compile and Install Nagios

Install some required packages.

[root]$ apt-get install libgd2-xpm-dev apache2 php5
[root]$ cd ~/nagios-4.0.6
[root]$ ./configure --with-command-group=nagcmd
[root]$ make all

After the compiling is complete, the following options are presented:

make install – This installs the main program, CGIs, and HTML files – make install-init – This installs the init script in /etc/init.d – make install-commandmode – This installs and configures permissions on the directory for holding the external command file – make install-config – This installs SAMPLE config files in /usr/local/nagios/etc You’ll have to modify these sample files before you can use Nagios. Read the HTML documentation for more info on doing this. Pay particular attention to the docs on object configuration files, as they determine what/how things get monitored! – make install-webconf – This installs the Apache config file for the Nagios web interface – make install-exfoliation – This installs the Exfoliation theme for the Nagios web interface – make install-classicui – This installs the classic theme for the Nagios web interface

I ran the following installations:

[root]$ make install
[root]$ make install-init
[root]$ make install-commandmode
[root]$ make install-config
[root]$ make install-webconf
Uh-oh. Did you notice the error message?

Check out the output from this last command:

[root]$ make install-webconf
/usr/bin/install -c -m 644 sample-config/httpd.conf /etc/httpd/conf.d/nagios.conf
/usr/bin/install: cannot create regular file ‘/etc/httpd/conf.d/nagios.conf’: No such file or directory
make: *** [install-webconf] Error 1

Silly Nagios installer, this is a Debian box! Let’s install this Apache2 config manually.

[root]$ /usr/bin/install -c -m 644 sample-config/httpd.conf /etc/apache2/conf.d/nagios.conf

Don’t attempt to start Nagios yet.

Compile and Install Nagios Plugins

We first need to install some prerequisites.

[root]$ apt-get install libnet-snmp-perl libperl5.14 libpq5 libradius1 libsensors4 libsnmp-base libsnmp15 libtalloc2 libtdb1 libwbclient0 samba-common samba-common-bin smbclient snmp whois libmysqlclient15-dev libssl-dev

Now install it

[root]$ cd ~/nagios-plugins-1.5
[root]$ ./configure --with-nagios-user=nagios --with-nagios-group=nagios
[root]$ make
[root]$ make install

NRPE Plugin Make & Install

Note the steps below carefully. DO NOT run “make install”. All we want to do is copy out the check_nrpe plugin, which is apparently not included in the original plugin pack.

[root]$ cd ~
[root]$ wget http://downloads.sourceforge.net/project/nagios/nrpe-2.x/nrpe-2.14/nrpe-2.14.tar.gz
[root]$ tar -xzvf nrpe-2.14.tar.gz
[root]$ cd nrpe-2.14
[root]$ ./configure --with-ssl=/usr/bin/openssl --with-ssl-lib=/usr/lib/x86_64-linux-gnu
[root]$ make

Instead of installing this whole package, we just want the plugin exec.

[root]$ cp src/check_nrpe /usr/local/nagios/libexec/

Configuration

Create the Apache login credentials.

[root]$ htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

Configure your Nagios services / hosts. For now, I recommend that you only setup a couple service checks for localhost while we build out the rest of the configuration.

BONUS TIP: Bash Alias

Create this bash alias to make it easier to run checks. For the rest of this guide, I will use the command nverify to run a check assuming that you created this alias.

[root]$ vim ~/.bash_aliases
alias nverify="/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg"

Don’t forget to log out and then back in to this box to see the new alias.

Check the configuration.

[root]$ nverify

Hold your breath & start the services.

[root]$ service apache2 restart
[root]$ service nagios start
Uh-oh. Did you notice the error message?

This is the part that doesn’t seem to be compatible with Debian systems. When I attempt to start the service, I see this:

[root]$ service nagios start
/etc/init.d/nagios: 20: .: Can't open /etc/rc.d/init.d/functions

There is an issue with the init script, and there is a thread that discusses this issue. I will use the fix posted by a member of the Nagios team. That post is located here.

[root]$ vim /etc/init.d/nagios

Delete the contents of the file, and paste in the code from the above mentioned post.

I also had to install daemon for this to work.

[root]$ apt-get install daemon

Now try to start the service again to see some more welcome output:

[root]$ service nagios start
 *  is not running
$Starting nagios:

Configure service to run at startup:

[root]$ ln -s /etc/init.d/nagios /etc/rc2.d/S20nagios

Checkpoint One

Let’s pause a moment to verify we have not made any mistakes.
  1. Reboot s10-nagios
  2. Verify that the service automatically started. Correct any startup config issues.
  3. Attempt to navigate to http://s10-nagios/nagios from a computer on the same LAN.
  4. Login using credentials previously specified.
Everything pass? Great – onward!

Nagiosgraph

Install some more prerequisites.

[root]$ apt-get install libcgi-pm-perl librrds-perl libgd-gd2-perl

Download and extract the files.

[root]$ cd ~
[root]$ wget http://downloads.sourceforge.net/project/nagiosgraph/nagiosgraph/1.4.4/nagiosgraph-1.4.4.tar.gz
[root]$ tar -xzvf nagiosgraph-1.4.4.tar.gz
[root]$ cd nagiosgraph-1.4.4

Verify that we have a working environment.

[root]$ ./install.pl --check-prereq

If everything looks good, continue with the install. I think it’s best to keep everything separate from the Nagios install to make upgrades easier.

[root]$ ./install.pl --layout standalone --prefix /usr/local/nagiosgraph

Most of the questions should be left at the default, except the last few. Questions that are not default are emphasized.

Destination directory (prefix)? [/usr/local/nagiosgraph]
Location of configuration files (etc-dir)? [/usr/local/nagiosgraph/etc]
Location of executables? [/usr/local/nagiosgraph/bin]
Location of CGI scripts? [/usr/local/nagiosgraph/cgi]
Location of documentation (doc-dir)? [/usr/local/nagiosgraph/doc]
Location of examples? [/usr/local/nagiosgraph/examples]
Location of CSS and JavaScript files? [/usr/local/nagiosgraph/share]
Location of utilities? [/usr/local/nagiosgraph/util]
Location of state files (var-dir)? [/usr/local/nagiosgraph/var]
Location of RRD files? [/usr/local/nagiosgraph/var/rrd]
Location of log files (log-dir)? [/usr/local/nagiosgraph/var]
Path of log file? [/usr/local/nagiosgraph/var/nagiosgraph.log]
Path of CGI log file? [/usr/local/nagiosgraph/var/nagiosgraph-cgi.log]
URL of CGI scripts? [/nagiosgraph/cgi-bin]
URL of CSS file? [/nagiosgraph/nagiosgraph.css]
URL of JavaScript file? [/nagiosgraph/nagiosgraph.js]
Path of Nagios performance data file? [/tmp/perfdata.log]
URL of Nagios CGI scripts? [/nagios/cgi-bin]
username or userid of Nagios user? [nagios]
username or userid of web server user? [www-data]
Modify the Nagios configuration? [n] y
Path of Nagios configuration file? [/usr/local/nagios/etc/nagios.cfg]
Path of Nagios commands file? /usr/local/nagios/etc/objects/commands.cfg
Modify the Apache configuration? [n] y

Restart some services.

[root]$ service apache2 restart
[root]$ service nagios restart

Graphs can now be accessed here: http://s10-nagios/nagiosgraph/cgi-bin/show.cgi

Template Hacks…err…Integration

The graphs can be integrated into the templates with a couple hacks. They are a bit cringeworthy, but they work.

To activate the pop-up graphs that we will include later, create this file.

[root]$ vim /usr/local/nagios/share/ssi/common-header.ssi
<script type="text/javascript" src="/nagiosgraph/nagiosgraph.js"></script>

To include icons for a specific service, you will need this line in your service definition:

action_url      /nagiosgraph/cgi-bin/show.cgi?host=$HOSTNAME$&service=$SERVICEDESC$&geom=1000x200' onMouseOver='showGraphPopup(this)' onMouseOut='hideGraphPopup()' rel='/nagiosgraph/cgi-bin/showgraph.cgi?host=$HOSTNAME$&service=$SERVICEDESC$

I also have a special graph saved for ping tests. I use this to show RTA and packet loss. We are going to utilize both actionurl and notesurl for this.

action_url              /nagiosgraph/cgi-bin/show.cgi?host=$HOSTNAME$&service=$SERVICEDESC$&db=pl,data&db=pl,warn&db=pl,crit&geom=1000x200' onMouseOver='showGraphPopup(this)' onMouseOut='hideGraphPopup()' rel='/nagiosgraph/cgi-bin/showgraph.cgi?host=$HOSTNAME$&service=$SERVICEDESC$&db=pl,data&db=pl,warn&db=pl,crit
notes_url               /nagiosgraph/cgi-bin/show.cgi?host=$HOSTNAME$&service=$SERVICEDESC$&db=rta,data&db=rta,warn&db=rta,crit&geom=1000x200' onMouseOver='showGraphPopup(this)' onMouseOut='hideGraphPopup()' rel='/nagiosgraph/cgi-bin/showgraph.cgi?host=$HOSTNAME$&service=$SERVICEDESC$&db=rta,data&db=rta,warn&db=rta,crit

Since we make use of the notes icon, lets give it the graph icon as well.

[root]$ mv /usr/local/nagios/share/images/notes.gif /usr/local/nagios/share/images/notes.bak.gif
[root]$ cp /usr/local/nagios/share/images/action.gif /usr/local/nagios/share/images/notes.gif

Go into your host configuration files and add the graph templates to your service definitions. Only add them to services that are returning performance data.

Here are some example services you can change in the default configuration files.

[root]$ vim /usr/local/nagios/etc/objects/localhost.cfg

Delete the service definition for Current Load and replace with this.

define service {
        use                     local-service
        host_name               localhost
        service_description     Current Load
        check_command           check_local_load!5.0,4.0,3.0!10.0,6.0,4.0
        action_url              /nagiosgraph/cgi-bin/show.cgi?host=$HOSTNAME$&service=$SERVICEDESC$&geom=1000x200' onMouseOver='showGraphPopup(this)' onMouseOut='hideGraphPopup()' rel='/nagiosgraph/cgi-bin/showgraph.cgi?host=$HOSTNAME$&service=$SERVICEDESC$
}

Delete the service definition for Ping and replace with this.

define service {
        use                     local-service
        host_name               localhost
        service_description     PING
        check_command           check_ping!100.0,20%!500.0,60%
        action_url              /nagiosgraph/cgi-bin/show.cgi?host=$HOSTNAME$&service=$SERVICEDESC$&db=pl,data&db=pl,warn&db=pl,crit&geom=1000x200' onMouseOver='showGraphPopup(this)' onMouseOut='hideGraphPopup()' rel='/nagiosgraph/cgi-bin/showgraph.cgi?host=$HOSTNAME$&service=$SERVICEDESC$&db=pl,data&db=pl,warn&db=pl,crit
        notes_url               /nagiosgraph/cgi-bin/show.cgi?host=$HOSTNAME$&service=$SERVICEDESC$&db=rta,data&db=rta,warn&db=rta,crit&geom=1000x200' onMouseOver='showGraphPopup(this)' onMouseOut='hideGraphPopup()' rel='/nagiosgraph/cgi-bin/showgraph.cgi?host=$HOSTNAME$&service=$SERVICEDESC$&db=rta,data&db=rta,warn&db=rta,crit
}

Check and restart Nagios.

[root]$ nverify
[root]$ service nagios restart

Now reload your Nagios homepage to see the graph icons.

Checkpoint Two

Let’s pause a moment to verify we have not made any mistakes.

You may have to let Nagios run for about 30 minutes to give the graphs a chance to collect some data.

  1. Navigate to http://s10-nagios/nagios from a computer on the same LAN.
  2. Login using credentials previously specified.
  3. View the services page, and note that ping and other services should have graph icons next to them.
  4. Mouseover the icons, confirm that graphs are popping up.
  5. Click on the icons, verify that you are being led to the page that shows graphs.
Everything pass? Great – onward!

Monitoring Nagios / MRTG

So you now have Nagios running to ensure all your servers and gadgets are running as expected. But…how do you know that Nagios is healthy? We should monitor that too! We are going to use MRTG to graph stats about how Nagios is running.

[root]$ apt-get install mrtg

Copy the default config file for Nagios stats.

[root]$ cp ~/nagios-4.0.6/sample-config/mrtg.cfg /usr/local/nagios/etc/
[root]$ mkdir /usr/local/nagios/share/stats

Configure the working directory.

[root]$ vim /usr/local/nagios/etc/mrtg.cfg

Add this to the top.

WorkDir: /usr/local/nagios/share/stats

Make the initial run.

[root]$ env LANG=C mrtg /usr/local/nagios/etc/mrtg.cfg

Configure the HTML page.

[root]$ indexmaker /usr/local/nagios/etc/mrtg.cfg --output=/usr/local/nagios/share/stats/index.html

Create a scheduled cron job to keep the status up to date.

[root]$ vim /etc/cron.d/nagiostats
*/5 * * * *  root  env LANG=C /usr/bin/mrtg /usr/local/nagios/etc/mrtg.cfg

Checkpoint Three

Let’s pause a moment to verify we have not made any mistakes.

You may have to let Nagios run for about 30 minutes to give the graphs a chance to collect some data.

  1. Navigate to http://s10-nag-01/nagios/stats/ from a computer on the same LAN.
  2. Verify that you see a bunch of pretty graphs.
Everything pass? Great – onward!

Nagios Template Tweaks

There are several additions / tweaks that are recommended for a more efficient experience.

Set the default page to the services detail page (may want to limit results or show a different page on a large installation)

[root]$ vim /usr/local/nagios/share/index.php

Find where $corewindow is defined, and change it to something more useful.

$corewindow="cgi-bin/status.cgi?host=all&limit=0";

Also lets add some links to the sidebar – specifically the graphs.

[root]$ vim /usr/local/nagios/share/side.php

Add this section wherever you see fit.

<div class="navsection">
<div class="navsectiontitle">External Tools</div>
<div class="navsectionlinks">
<ul class="navsectionlinks">
<li><a href="/nagios/stats" target="<?php echo $link_target;?>">Nagiostats</a></li>
<li><a href="/nagiosgraph/cgi-bin/show.cgi" target="<?php echo $link_target;?>">Nagiosgraph</a></li>
</ul>
</div>
</div>

Conclusion

You now have a working base Nagios install. Now you are off to build your service checks, find more plugins, and tweak your alerts. I can almost feel your anticipation!

This entry was posted in Guides and tagged , on by .

About Andrew Wells

I have been developing on the LAMP stack since about 2006. I run Ubuntu XFCE on my desktop and have a history of managing Ubuntu and CentOS servers. I code web applications mostly in PHP but have experience with other languages as well. When I'm not working, I can be found working in my home lab or out snowboarding, hiking, camping, or biking depending on the season.

65 thoughts on “Nagios 4.x Install from Source on Ubuntu 12.04

  1. Bill Spencer

    On the step called “To include icons for a specific service, you will need this line in your service definition: ”
    How and where do you do this?
    Sorry, I’m a complete ubuntu/linux noob.

    Reply
  2. Bill Spencer

    Which service definition? Can you give me an example of how you did it in your setup? For example…
    1. Open this with this
    2. Add this line here
    etc etc.
    Thanks…so far your notes are spot on.

    Reply
    1. Andrew Wells Post author

      Hi Bill – I updated the article with a couple example service definitions. See the section that starts with “Here are some example services you can change in the default configuration files.”

      Reply
  3. Bill Spencer

    Thanks Andrew that was a big help. I tried adding the action_url lines to Current Load, Current Users, and a few others and when I click on the graph, page loads but I have errors….for example, Current Load shows:
    Day, Week, Month, Year all show this in red….
    opening ‘/usr/local/nagiosgraph/var/rrd/localhost/Current%20Load___pl.rrd’: No such file or directory.

    Did I forget to add something from your instructions?
    I really appreciate all your help on this…if you lived in Central Florida, I’d be taking you to World of Beer!

    Reply
    1. Andrew Wells Post author

      That message means that the Round Robin Databases have not been created yet. That could be caused from a couple different reasons.

      – 1st reason can be simply time. The databases are not created until Nagios checks a service and saves the performance data. So once you install Nagiosgraph and restart Nagios, you need to wait for the service checks to run at least once for the graph to be initialized.
      – 2nd reason could be incorrect Nagios configuration. Take a peak at /usr/local/nagios/etc/nagios.cfg and /usr/local/nagios/etc/objects/commands.cfg to verify that the Nagiosgraph installer added lines to the end of those files.

      Reply
  4. Bill Spencer

    Lines are there, I’ll just wait and see what comes up…thanks a million Andrew.
    Do you have any other Nagios tutorials beyond this?

    Reply
    1. Andrew Wells Post author

      Ok, let’s try to follow the data through. First, confirm you have services passing performance data. From the Nagios services page, click on a service (like Ping or Current Load), and make sure there is data in the Performance Data Section.

      Next, check to see the file that sits between Nagios and Nagiosgraph.

      # watch "tail -n 30 /tmp/perfdata.log"

      What this command is doing is watching the contents of this file and automatically updating the screen. If you are only using the default config, there are not many checks happening. So you should only see a line or two appear, and then clear out over a few minutes. This file is a cache where the performance data is stored before being processed by Nagiosgraph.

      If this file doesn’t exist or is not ever showing any contents, check /usr/local/nagios/etc/nagios.cfg and verify Nagiosgraph updated the settings. You should see this at the end of the file:

      # begin nagiosgraph configuration
      # process nagios performance data using nagiosgraph
      process_performance_data=1
      service_perfdata_file=/tmp/perfdata.log
      service_perfdata_file_template=$LASTSERVICECHECK$||$HOSTNAME$||$SERVICEDESC$||$SERVICEOUTPUT$||$SERVICEPERFDATA$
      service_perfdata_file_mode=a
      service_perfdata_file_processing_interval=30
      service_perfdata_file_processing_command=process-service-perfdata-for-nagiosgraph
      # end nagiosgraph configuration
      

      If you are seeing the file size increase, and never clear out, service_perfdata_file_processing_command may not be functioning. Check /usr/local/nagios/etc/objects/commands.cfg and verify this is at the end of the file:

      # begin nagiosgraph configuration
      # command to process nagios performance data for nagiosgraph
      define command {
        command_name process-service-perfdata-for-nagiosgraph
        command_line /usr/local/nagiosgraph/bin/insert.pl
      }
      # end nagiosgraph configuration
      

      You can also try to run /usr/local/nagiosgraph/bin/insert.pl manually.

      Still not working? Check to see if the databases are being created:

      # ls -alh /usr/local/nagiosgraph/var/rrd

      You should see a directory for each host passing performance data.

      If you are still having trouble, please post the contents of /usr/local/nagios/etc/nagios.cfg and /usr/local/nagios/etc/objects/commands.cfg. Please paste those file into something like pastebin.com and post the links back here. Also, let me know if you have a different setup than what I used in this article, like a different version of Ubuntu.

      Let me know the results.

      Reply
  5. blitzkin

    hi andrew, thanks for this great tutorial.. i have a problem though with nagiosgraph:

    i get this error message when accessing showconfig.cgi
    cannot load ngshared.pm
    not found in any of these locations:
    /etc/nagiosgraph
    /etc/perl
    /usr/local/lib/perl/5.14.2
    /usr/local/share/perl/5.14.2
    /usr/lib/perl5
    /usr/share/perl5
    /usr/lib/perl/5.14
    /usr/share/perl/5.14
    /usr/local/lib/site_perl

    any help woule be much appreciated!

    Reply
    1. Andrew Wells Post author

      Something may not have installed correctly. Check out this command I ran on my test machine:

      [root]$ locate ngshared.pm
      /root/nagiosgraph-1.4.4/etc/ngshared.pm
      /usr/local/nagiosgraph/etc/ngshared.pm
      

      I see the mentioned file in the source folder and the installed location. See if you can find them there. If not, I would run the install.pl command again. Verify that you are specifying the --prefix.

      Reply
      1. blitzkin

        did the install with the prefix still the same error with ngshared.pm

        although ngshared.pm is located on both places where you mentioned it:

        /root/nagiosgraph-1.4.4/etc/ngshared.pm
        /usr/local/nagiosgraph/etc/ngshared.pm

        Thanks!

        Reply
        1. Andrew Wells Post author

          Ok, lets zoom out a little. Which OS are you attempting to install this on? And is this a fresh install?

          If you are getting server error pages, trigger that error again, and check the Apache log file for more details:

          [root]$ $ tail /var/log/apache2/error.log

          If that doesn’t turn up anything, view the file located at /usr/local/nagiosgraph/cgi/show.cgi, around line 11. See what directory is in the ‘use lib’ setting and make sure ngshared.pm is in that directory.

          Also as I’m writing this, I wonder if something like SELinux is getting in your way.

          Reply
          1. blitzkin

            Andrew i will try the steps again on a new install since i’m just setting it up as a vm.. will let you know of any update, i guess too many tutorials i read messed things up.. happy holidays man!

  6. mate

    hey, thanks for your great guide!
    just one little thing: “~/nagios-4.0.1/sample-config/mrtg.cfg” doesn’t exist but i think you mean “~/nagios-4.0.1/sample-config/mrtg.cfg.in”

    😉

    Reply
    1. Andrew Wells Post author

      The .in files are some sort of template. The config files are generated from this template after running this step:

      [root]$ cd ~/nagios-4.0.1
      [root]$ ./configure --with-command-group=nagcmd
      

      If I list that directory after that step, I see both files:

      [root]$ ls -alh ~/nagios/sample-config
      total 164K
      drwxrwxr-x  3 root root 4.0K Jan 11 21:03 .
      drwxrwxr-x 15 root root 4.0K Jan 11 21:03 ..
      -rw-------  1 root root  12K Jan 11 21:03 cgi.cfg
      -rw-rw-r--  1 root root  12K Aug 30 12:46 cgi.cfg.in
      -rw-rw-r--  1 root root   17 Aug 30 12:46 .gitignore
      -rw-------  1 root root 1010 Jan 11 21:03 httpd.conf
      -rw-rw-r--  1 root root  932 Aug 30 12:46 httpd.conf.in
      -rw-------  1 root root 7.0K Jan 11 21:03 mrtg.cfg
      -rw-rw-r--  1 root root 6.8K Aug 30 12:46 mrtg.cfg.in
      -rw-------  1 root root  44K Jan 11 21:03 nagios.cfg
      -rw-rw-r--  1 root root  44K Aug 30 12:46 nagios.cfg.in
      -rw-rw-r--  1 root root  983 Aug 30 12:46 README
      -rw-------  1 root root 1.4K Jan 11 21:03 resource.cfg
      -rw-rw-r--  1 root root 1.3K Aug 30 12:46 resource.cfg.in
      drwxrwxr-x  2 root root 4.0K Jan 11 21:03 template-object
      

      Look at the contents or both mrtg.cfg and mrtg.cfg.in. The files ending with .in shows variables like @localstatedir@, and the equivalent config file shows the value after the configure run.

      Reply
  7. Chris

    Thank you for the tutorial. It was very informative and thorough, it was also nice that you went further by doing some of your own tweaks. I have a request though, think you can do a tutorial for nconf\NRDP\NSClient++

    -thanks again

    Reply
  8. Chris

    I have been following other tutorials on line and yours is the best by far, THANKS!
    I have one issue and I’m hoping you can help me with. this error is coming up:
    check_mrtgtraf: Unable to open MRTG log file
    This is from the status information for monitoring port bandwidth.
    I am running an Ubuntu VM with nagios 4.02.
    I have read other threads about this issue and some are saying to install MRTG again but it is working fine.
    Anything that can explain this will help.
    Thanks

    Reply
      1. Chris

        I might as well put all the status errors on this post, I checked and the IP is correct, the snmp community string is also correct but I cant seem to get anything to come up.
        Does the model of the equipment I’m monitoring matter?

        Status for Port 1 Link Status – Unknown:
        # Monitor Port 1 status via SNMP
        define service{
        use generic-service ; Inherit values from a template
        host_name Core-Wh-SW
        service_description Port 1 Link Status
        check_command check_snmp!-C snmp_community -o ifOperStatus.1 -r 1 -m RFC1213-MIB
        }

        Status for Port 1 Bandwidth Usage – Unknown:
        # Monitor bandwidth via MRTG logs
        define service{
        use generic-service ; Inherit values from a template
        host_name Core-Wh-SW
        service_description Port 1 Bandwidth Usage
        check_command check_local_mrtgtraf!/var/lib/mrtg/192.168.200.2_1.log!AVG!1000000,1000000!5000000,5000000!10
        }
        Status for Uptime – Critical:
        # Monitor uptime via SNMP
        define service{
        use generic-service ; Inherit values from a template
        host_name Core-Wh-SW
        service_description Uptime
        check_command check_snmp!-C snmp_community -o sysUpTime.0
        action_url /nagiosgraph/cgi-bin/show.cgi?host=$HOSTNAME$&service=$SERVICEDESC$&geom=1000×200′ onMouseOver=’showGraphPopup(this)’ onMouseOut=’hideGraphPopup()’ rel=’/nagiosgraph/cgi-bin/showgraph.cgi?host=$HOSTNAME$&service=$SERVICEDESC$
        }

        Thanks for taking a look.

        Reply
        1. Chris

          I see the check_command is pointing to /var/lib/mrtg/192.168.200.2_1.log
          In this directory there is no 192.168.200.2_1.log?

          Reply
          1. Andrew Wells Post author

            Yup, first I would make sure that file path to the log file is correct.

            Then, see exactly what command is being ran for “check_local_mrtgtraf”. From the Nagios web interface, left side, click on “Configuration” at the bottom of the list. Select “Commands” and hit Continue. See what the shell command is for check_local_mrtgtraf and replicate that in an SSH session. You might be able to get some more insight as to the error output that way.

  9. Chris

    check_local_mrtgtraf = $USER1$/check_mrtgtraf -F $ARG1$ -a $ARG2$ -w $ARG3$ -c $ARG4$ -e $ARG5$

    I put in the command and received this error:
    bash: $/check_mrtgtraf: No such file or directory

    Reply
    1. Andrew Wells Post author

      $USER1$ points to the plugins directory. To see the path, refer to the file /usr/local/nagios/etc/resource.cfg where $USER1$ is defined. Most likely though, it points to /usr/local/nagios/libexec

      So the fill path to the executable is /usr/local/nagios/libexec/check_mrtgtraf but you have arguments. So based on your previous posts, it would look something like this:

      /usr/local/nagios/libexec/check_mrtgtraf -F /var/lib/mrtg/192.168.200.2_1.log -a AVG -w 1000000,1000000 -c 5000000,5000000 -e 10

      So run that command on your machine, and see if you still get the “file not found” message. If you do, tell me the output of this:

      tail /var/lib/mrtg/192.168.200.2_1.log

      Reply
      1. Chris

        This is the output of the commands:
        lab@ubuntu:/$ sudo /usr/local/nagios/libexec/check_mrtgtraf -F /var/lib/mrtg/192.168.200.2_1.log -a AVG -w 1000000,1000000 -c 5000000,5000000 -e 10
        check_mrtgtraf: Unable to open MRTG log file
        Usage check_mrtgtraf -F -a -w
        -c [-e expire_minutes]

        lab@ubuntu:/$ sudo tail /var/lib/mrtg/192.168.200.2_1.log tail: cannot open `/var/lib/mrtg/192.168.200.2_1.log’ for reading: No such file or directory

        Reply
        1. Andrew Wells Post author

          Yup, that log file you are referring to doesn’t exist. How did you get the path of that log file? If you followed a procedure publicly available, can you link to it?

          Reply
          1. Chris

            Are you asking about the procedure I used to install Nagios? I used your set up, which took me a lot farther than other sites.
            The path I got from the Nagios web interface, left side I clicked on “Configuration”. Selected “Commands” and hit Continue. I found the command here under check_local_mrtgtraf.

          2. Andrew Wells Post author

            I haven’t used this plugin before, but it seems that check_local_mrtgtraf scans existing log files. Something else has to put them there. MRTG in this article is configured to monitor the Nagios installation only, not switches. There has to be some other setup done by you to enable MRTG to query your switches. This article I found describes creating a configuration file using cfgmaker, and then adding that to the crontab to poll the switch and write that data to a log file. Is this what you are looking for?

  10. Chuck

    Great post thanks!
    I am also a bit green and am wondering how to move forward from here. We have a bunch of stores that connect to our main office over IPSEC. We want to mainly monitor the router for any downtime at each store. Eg Router A 10.10.1.1, Router B 10.10.2.1, Router C 10.10.3.1 etc.

    We just want to see if the connection goes down for any reason and then track history etc, so maybe a simple Ping? How do I add these to monitor.

    Thanks,

    Reply
      1. Chuck

        Perfect, thanks; everything is now up an running. I am trying to find a way to monitor both the Internal IP’s and External IP’s. Therefore showing if the IPSEC is going down or the Internet as a whole. Wondering if they can be monitored together or do I need to make separate files for the Internal to the External addresses.

        I came across this: http://exchange.nagios.org/directory/Plugins/Others/check_multiaddr/details. Great for monitoring Multiple Addresses, but only seems to check one at a time and doesnt really show you which one is down.

        Reply
  11. Abdul Wajid

    Newbie alert !
    [root]$ vim ~/.bash_aliases

    Cannot create an alias. Please elaborate the process to create the alis in Ubuntu Server 12.0.1.
    Thank YOu

    Reply
  12. Abdul Wajid

    I figured out the above reported problem but after configuring the nagiosgraph, when i access it through the webconsole i see below error.
    No data in rrd directory /usr/local/nagiosgraph/var/rrd

    Please help

    Regards
    Abdul Wajid

    Reply
    1. Andrew Wells Post author

      The graph data doesn’t build until the service checks run a couple times. If you still don’t see anything after 20 minutes, double check to make sure the install parameters were entered correctly for the Nagiosgraph installation. Refer to my demo video about 14 minutes in to see what I’m talking about.

      A good way to test that would be to take a peak at your Nagios configuration.

      [root]$ tail /usr/local/nagios/etc/nagios.cfg 
      # begin nagiosgraph configuration
      # process nagios performance data using nagiosgraph
      process_performance_data=1
      service_perfdata_file=/tmp/perfdata.log
      service_perfdata_file_template=$LASTSERVICECHECK$||$HOSTNAME$||$SERVICEDESC$||$SERVICEOUTPUT$||$SERVICEPERFDATA$
      service_perfdata_file_mode=a
      service_perfdata_file_processing_interval=30
      service_perfdata_file_processing_command=process-service-perfdata-for-nagiosgraph
      # end nagiosgraph configuration
      

      If you don’t see the nagiosgraph configuration at the end of that file, then something went wrong in the installation.

      Reply
        1. Andrew Wells Post author

          Make sure you created the file /usr/local/nagios/share/ssi/common-header.ssi with content mentioned in the article. Also make sure you have the appropriate action_url in the service definitions where you want the graph icons.

          Reply
  13. Abdul Wajid

    I have a problem while running below command to get the information through snmp. any idea how can i fix ?

    root@nagios:/usr/local/nagios/libexec# ./check_snmp -H 192.168.30.1 -C gpcc -o sysUpTimeInstance
    CRITICAL – Plugin timed out while executing system call

    Thank You

    Reply
    1. Andrew Wells Post author

      Are you seeing that timeout message in Nagios or when running the command directly on the command line?

      Nagios has a few settings that control how long certain commands (including checks) can run. These settings are located in /usr/local/nagios/etc/nagios.conf.

      This would be your area of interest:

      # TIMEOUT VALUES
      # These options control how much time Nagios will allow various
      # types of commands to execute before killing them off.  Options
      # are available for controlling maximum time allotted for
      # service checks, host checks, event handlers, notifications, the
      # ocsp command, and performance data commands.  All values are in
      # seconds.
      
      service_check_timeout=60
      host_check_timeout=30
      event_handler_timeout=30
      notification_timeout=30
      ocsp_timeout=5
      perfdata_timeout=5
      
      Reply
      1. Abdul Wajid

        I tried both the ways. From Nagios as well as from the CLI. Same error messag came up on the Web Console as well.

        Thanks

        Reply
        1. Andrew Wells Post author

          Interesting. So it sounds like it’s the actual plugin that’s timing out then and not the Nagios backend.

          I ran this to see the help information on the plugin you are using:

          [user]$ /usr/local/nagios/libexec/check_snmp -h

          I saw that there is a timeout value for this plugin:

           -t, --timeout=INTEGER
              Seconds before connection times out (default: 10)
          

          Try running the command again specifying a larger timeout value. I modified your earlier command, only adding -t 60 at the end:

          root@nagios:/usr/local/nagios/libexec# ./check_snmp -H 192.168.30.1 -C gpcc -o sysUpTimeInstance -t 60
          

          Remember that if we increase this timeout to be longer than the Nagios service check timeout, you may still need to change that as well.

          Reply
          1. Abdul Wajid

            Same error :

            root@ubuntu:/usr/local/nagios/libexec# ./check_snmp -H 192.168.30.1 -C gpcc -o sysUpTimeInstance -t 60
            CRITICAL – Plugin timed out while executing system call

            Thanks

  14. Abdul Wajid

    Hi,

    Same Error comes up. It takes round three to four minutes if i user -t switch with value 60. Another thing, if i put the wrong hostname then also it pops the same error message.

    Any Clue?

    Thanks

    Reply
    1. Andrew Wells Post author

      I would double-check that you have the SNMP settings correct. My best suggestion is to check the SNMP parameters and make sure that SNMP is correctly configured on the device you are querying (whatever is at 192.168.30.1).

      Try to remove some variables from the problem and test only the SNMP service on your network device. Instead of using Nagios (for now), try a simple SNMP browser instead, and once you are sure SNMP is working, try it with Nagios again.

      Reply
  15. Anilesh Thakur

    Hi,
    Recently I installed the nagios 4.0.5 core edition but i am unble to configure email notification, Plz explain in breif how to configure email notification in nagios4 on ununtu 12.04.

    Reply
  16. Tobias

    [root]$ /usr/bin/install -c -m 644 sample-config/httpd.conf /etc/apache2/conf.d/nagios.conf

    This looks wrong in your updated 4.0.6 installation (directory does not exist – just a typo) replace it with:

    [root]$ /usr/bin/install -c -m 644 sample-config/httpd.conf /etc/apache2/conf-available/nagios.conf

    Reply
    1. Andrew Wells Post author

      I believe that is an Ubuntu 12.04 / 14.04 difference. Apache was upgraded to 2.4.7 in Ubuntu 14.04, and that changed some things like the conf directories. I will rewrite this article for Ubuntu 14.04 soon.

      Reply
      1. Tobias

        Not sure. You install the file at /etc/apache2/conf.d but make a link from /etc/apache2/conf-available
        This does not match. But i admit I’m not an expert when it comes to Linux. However your guide helped me a lot to install it to 12.04. Now I#m on my way to get it running on 14.04.
        Thanks for your work 😉

        Reply
        1. Andrew Wells Post author

          Oops, you are correct! Thanks for the note. I was attempting to modify this article to be compatible with both Ubuntu 12.04 and 14.04 before I realized the major changes in Apache. I will update that section to /etc/apache2/conf.d. Thanks!

          Reply
  17. Gideon

    Hi Andrew, thank you so much for doing this step-by-step tutorial.

    I have a little problem where after i run the “make install-webconf” i get the error message, I proceed by using the solution you gave (/usr/bin/install -c -m 644 sample-config/httpd.conf /etc/apache2/conf.d/nagios.conf).

    But neither the “install” directory under /usr/bin/ or the “apache2/conf.d” under /etc/ exists.

    Ps. this is on a newly installed VM

    Reply
    1. Andrew Wells Post author

      What version of Ubuntu are you using? Ubuntu 14.04 has Apache2 config in /etc/apache2/conf-available. If that is the case, follow this article instead for Ubuntu 14.04.

      With regards to /usr/bin/install not being available, you may have to install the build-essential package.

      Reply
    2. Gideon

      I forgot to mention that its a 14.04 machine and i changed “…/apache2/conf.d…” to “…/apache2/conf-available…” in accordance to Tobias comment on the 14th of May.

      Reply
  18. amal

    good morning
    please I need your help : to install some prerequisites before installing nagios plugins
    I used this cmd ” apt-get install libnet-snmp-perl libperl5.14 libpq5 libradius1 libsensors4 libsnmp-base libsnmp15 libtalloc2 libtdb1 libwbclient0 samba-common samba-common-bin smbclient snmp whois libmysqlclient15-dev libssl-dev” the result was: ” E:unable to locate package libdb1
    E:unable to locate package libclient0
    E:unable ti locate package smbclients”

    Reply
  19. Johnas

    Hi Andrew!
    Excellent Tutorial! Everything is clear and well explained. I just wanted to add the fact the new Nagios 4.0.7 fixes the problem with install webconf and the error indicated is fixed so needless to replace the script. I had a question for you though. I need some help with a script to monitor game servers with metrics such as number of players and most importantly settting a threshold when a player wins a huge amount. You can get to me back through my email.
    Regards

    Reply
  20. Nour

    Hi there,

    i ám ruuning to some problems trying to get nagiosgraph working :

    root@kis13:/home/kis/nagiosgraph-1.5.2# ./install.pl –check-prereq
    checking required PERL modules
    Carp…1.29
    CGI…3.64
    Data::Dumper…2.145
    Digest::MD5…2.52
    File::Basename…2.84
    File::Find…1.23
    MIME::Base64…3.13
    POSIX…1.32
    RRDs…1.4007
    Time::HiRes…1.9725
    checking optional PERL modules
    GD…2.46
    Nagios::Config… ***FAIL***
    checking nagios installation
    found nagios exectuable at /usr/local/nagios/bin/nagios
    found nagios init script at /etc/init.d/nagios
    checking web server installation
    found apache executable at /usr/sbin/apache2
    found apache init script at /etc/init.d/apache2

    please your help .

    I tried to ingnore this message but then after the installation when running CPAN for the first time

    I get :

    Can’t call method “http” on unblessed reference at /usr/share/perl/5.18/CPAN/FirstTime.pm line 1868.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *