Thursday, August 7, 2014

Nagios Pi: Nagios File Structure


The version of Nagios in the Raspian repository is Nagios3.  It's not the latest, but it's the easiest to install and for small/home network monitoring it will do just fine.

Once you've installed Nagios, you'll be able to test the web interface and see that you're already monitoring the localhost (the RaspberryPi Nagios is running on).  To make it monitor other devices on the network, you'll have to do some configuration.

Nagios runs from configuration (.cfg) files and most of the customization of NagiosPi is accomplished by editing these files.

/etc/nagios3 is where most of these files reside.  Within this directory:

  • Apache2.conf = configuration for the Nagios HTML (Web) interface
  • Commands.cfg = links comand names to shell commands.
  • Htpasswd.users = hashed user passwords
  • Resource.cfg = where user macros are defined
  • Cgi.cfg = configuration for Nagios CGI scripts
  • Nagios.cfg = Main configuration file for the Nagios program

/etc/nagios3/conf.d is where the generic configuration files and templates reside and where I'll add new files.  You can certainly create these files outside of this directory but for simplicity sake, I'm going to add them here.

  • Contacts_nagios2.cfg = contacts to send alerts to
  • Generic-service_nagios2.cfg = template for creating a service
  • Services_nagios2.cfg = defines services to monitor on hosts
  • Extinfo_nagios2.cfg = extended host and service information
  • Hostgroups_nagios2.cfg = defines hostgroups to organize multiple hosts by type
  • Timeperiods_nagios2.cfg = customize timeperiods for checks and notifications here
  • Generic-host_nagios2.cfg = template for a generic host
  • Localhost_nagios2.cfg = configuration for the localhost and an excellent reference source for the additional hosts that you create.

 /etc/nagios3/stylesheets/ is where all of the cascading style sheet (CSS) files that define how the HTML interface looks are created.

Nagios Pi: Add more hosts


For this configuration of RaspberryPi I'm going to use a single file to hold information for all of the monitored hosts.  On a larger network you would find advantages to using a more complex structure for the couple dozen hosts we'll expect a RaspberryPi to monitor this will work well.
 
Start by creating  a new .cfg file in the /etc/nagios3/conf.d directory:

sudo nano hosts.cfg

 By the way, I'm also going to use the Nano text editor for simplicity sake and will not apologize for it.

The structure of the file is as follows:

define host {
 
     use     generic-host
Required Use generic-host as a template, this defines the most basic services. 
     host-name     host name
Required Supply the name of the host.  This is what the host will appear as in the Nagios UI.  If you supply the host-name but not an address, then Nagios will try to resolve this name against DNS.
     alias     description
Optional You can provide more description about the host here.
     address    xxx.xxx.xxx.xxx
Optional Defines the IP address this host is at.  Obviously, use only for devices that have fixed IP addresses.
}
 

A host with dynamic addressing would look like this:

define host {
        use      generic-host
        host_name       DIRECTV-H23-91652B1A
}

A host with fixed addressing would look like this:

define host {
        use     generic-host
        host_name       Main Floor AP
        address 192.168.2.15
        alias   Main Floor AP
}

Write out the file from Nano (control + O then control + x)

Check the Nagios config (or if you feel lucky....don't):

sudo nagios3 -v /etc/nagios3/nagios.cfg

Restart Nagios:

sudo service nagios3 restart

Go to the Nagios UI and check your hosts.

 

NagiosPi: Installing Nagios on Raspian

Log into your RaspberryPi

sudo apt-get install /y nagios3

Much selecting and unpacking follows, then setting up, then creating config files, then setting up.

at last, you'll be presented with a dialog asking you to create a password for the nagiosadmin user.  Choose, enter then confirm and you're on your way to...some more setting up.

Finally, you'll end up at a command prompt.  Not much reward for all that waiting.