Skip to content

Instantly share code, notes, and snippets.

@originalhat
Created June 1, 2012 22:25
Show Gist options
  • Save originalhat/2855482 to your computer and use it in GitHub Desktop.
Save originalhat/2855482 to your computer and use it in GitHub Desktop.
Installing Nagios on OSX (10.6.8)

Nagios Install - OSX (10.6.8)

Overview

Installing Nagios on linux is well documented and relativly straightforward. Installing Nagios on OSX however, can be a bit different, and in my case presented a number of unique issues that I hope this guide might address.

If you run into an odd error messages, check the Troubleshooting section below, it might have the answer you're looking for!

Requirements / Dependencies

General Dependencies

Nagios requires a few things to work properly, here's what I needed to get things running:

  • Apache
  • PHP
  • Upgrading Xcode to 3.2.6+

Framework Dependencies

I used MacPorts for this:

$ sudo port install zlib

$ sudo port install libpng

$ sudo port install jpeg

$ sudo port install gd2

I ran into a few problems here, see the Troubleshooting section for more information.

Installing Nagios

You may run into some brew dependency issues, but here's the command for installing Nagios:

$ sudo brew install nagios

I ran into some issues at this point that required me upgrade a variety of things, all of which were pretty straightforward and Googleable.

Assuming things went well, you can check to see if Nagios is installed with:

$ nagios

Nagios Core 3.4.1
Copyright (c) 2009-2011 Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last Modified: 05-11-2012
License: GPL

Website: http://www.nagios.org
Usage: nagios [options] <main_config_file>

Options:

-v, --verify-config          Verify all configuration data
-s, --test-scheduling        Shows projected/recommended check scheduling and other
                           diagnostic info based on the current configuration files.
-x, --dont-verify-paths      Don't check for circular object paths - USE WITH CAUTION!
-p, --precache-objects       Precache object configuration - use with -v or -s options
-u, --use-precached-objects  Use precached object config file
-d, --daemon                 Starts Nagios in daemon mode, instead of as a foreground process

Visit the Nagios website at http://www.nagios.org/ for bug fixes, new
releases, online documentation, FAQs, information on subscribing to
the mailing lists, and commercial support options for Nagios.

Now on to configuration settings and debugging rogue issues.

Configurations

Nagios Configurations

There are two primary Nagios configuration files that I needed to modify to get Nagios running. Knowing the location of these files, expecially the nagios.cfg file is critical to running Nagios.

  • nagios.cfg
  • cgi.cfg

Another important Nagios file is the nagios.conf file, not to be confused with nagios.cfg. This .conf file is a good place to get your general Apache configuration settings.

This file was located in the /usr/local/Cellar/nagios/3.4.1/ folder on my machine and the important contents are as follows:

ScriptAlias /nagios/cgi-bin "/usr/local/Cellar/nagios/3.4.1/cgi-bin"

<Directory "/usr/local/Cellar/nagios/3.4.1/cgi-bin">
#  SSLRequireSSL
   Options ExecCGI	
   AllowOverride None
   Order allow,deny
   Allow from all
#  Order deny,allow
#  Deny from all
#  Allow from 127.0.0.1
   AuthName "Nagios Access"
   AuthType Basic
   AuthUserFile /usr/local/etc/nagios/htpasswd.users
   Require valid-user
</Directory>

Alias /nagios "/usr/local/Cellar/nagios/3.4.1/share/nagios/htdocs"

<Directory "/usr/local/Cellar/nagios/3.4.1/share/nagios/htdocs">
#  SSLRequireSSL
   Options None
   AllowOverride None
   Order allow,deny
   Allow from all
#  Order deny,allow
#  Deny from all
#  Allow from 127.0.0.1
   AuthName "Nagios Access"
   AuthType Basic
   AuthUserFile /usr/local/etc/nagios/htpasswd.users
   Require valid-user
</Directory>

These settings need to be transplated into the Apache config files, which just happens to be our next step.

Apache Configurations

For Nagios to work with Apache (and be accessable via localhost) we need modify the Apache configurations file.

First we need to find out where our httpd.conf is located:

$ whereis httpd
  /usr/sbin/httpd

$ /usr/sbin/httpd -V
  Server version: Apache/2.2.21 (Unix)
  Server built:   Dec  5 2011 20:56:38
  Server's Module Magic Number: 20051115:30
  Server loaded:  APR 1.3.8, APR-Util 1.3.9
  Compiled using: APR 1.3.8, APR-Util 1.3.9
  Architecture:   64-bit
  Server MPM:     Prefork
    threaded:     no
      forked:     yes (variable process count)
  Server compiled with....
   -D APACHE_MPM_DIR="server/mpm/prefork"
   -D APR_HAS_SENDFILE
   -D APR_HAS_MMAP
   -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
   -D APR_USE_FLOCK_SERIALIZE
   -D APR_USE_PTHREAD_SERIALIZE
   -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
   -D APR_HAS_OTHER_CHILD
   -D AP_HAVE_RELIABLE_PIPED_LOGS
   -D DYNAMIC_MODULE_LIMIT=128
   -D HTTPD_ROOT="/usr"
   -D SUEXEC_BIN="/usr/bin/suexec"
   -D DEFAULT_PIDLOG="/private/var/run/httpd.pid"
   -D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
   -D DEFAULT_LOCKFILE="/private/var/run/accept.lock"
   -D DEFAULT_ERRORLOG="logs/error_log"
   -D AP_TYPES_CONFIG_FILE="/private/etc/apache2/mime.types"
   -D SERVER_CONFIG_FILE="private/etc/apache2/httpd.conf"

The last line indicates that our httpd.conf file is located in the /private/etc/apache2 directory.

Once you have httpd.conf file open, transplant the Nagios settings from above.

Next, restart the Apache server:

$ sudo apachectl restart

With our basic configurations set, we're just about ready to fire up Nagios.

Running Nagios

First we need to check that our Nagios configurations file isn't filled with any nasty errors:

$ sudo nagios -v /usr/local/etc/nagios/nagios.cfg 

If all goes well you should see something similar to this:

Nagios Core 3.4.1
Copyright (c) 2009-2011 Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last Modified: 05-11-2012
License: GPL

Website: http://www.nagios.org
Reading configuration data...
   Read main config file okay...
Processing object config file '/usr/local/etc/nagios/objects/commands.cfg'...
Processing object config file '/usr/local/etc/nagios/objects/contacts.cfg'...
Processing object config file '/usr/local/etc/nagios/objects/timeperiods.cfg'...
Processing object config file '/usr/local/etc/nagios/objects/templates.cfg'...
Processing object config file '/usr/local/etc/nagios/objects/localhost.cfg'...
   Read object config files okay...

Running pre-flight check on configuration data...

Checking services...
	 Checked 8 services.
Checking hosts...
    Checked 1 hosts.
Checking host groups...
    Checked 1 host groups.
Checking service groups...
    Checked 0 service groups.
Checking contacts...
    Checked 1 contacts.
Checking contact groups...
    Checked 1 contact groups.
Checking service escalations...
    Checked 0 service escalations.
Checking service dependencies...
    Checked 0 service dependencies.
Checking host escalations...
    Checked 0 host escalations.
Checking host dependencies...
    Checked 0 host dependencies.
Checking commands...
    Checked 24 commands.
Checking time periods...
    Checked 5 time periods.
Checking for circular paths between hosts...
Checking for circular host and service dependencies...
Checking global event handlers...
Checking obsessive compulsive processor commands...
Checking misc settings...

Total Warnings: 0
Total Errors:   0

Things look okay - No serious problems were detected during the pre-flight check

If this looks good, we can go ahead and start the Nagios daemon:

$ /usr/local/Cellar/nagios/3.4.1/bin/nagios -d /usr/local/etc/nagios/nagios.cfg 

We can then verify that the Nagios core is running:

$ ps -aux |grep nagios
  lroot     8356   0.4  0.0  2435120    540 s000  R+    3:38PM   0:00.00 grep nagios
  root      3418   0.0  0.0  2463604    640   ??  Ss    1:09PM   0:03.58 /usr/local/Cellar/nagios/3.4.1/bin/nagios -d /usr/local/etc/nagios/nagios.cfg

If you don't see Nagios running, check the **Troubleshooting section below.

Conclusion

You shoud be able to check your results by navigating to http://localhost/nagios.

You may need to login, depending on how you configured the Nagios .cnf files.

That about wraps up the Nagios / OSX. If you have any other problems, check the Troubleshooting below for solutions to some of the larger issues I encountered along the way.

Troubleshooting

Dependencies' Dependencies Outdated

If you're lucky like me, you'll get some error messages while installing the component frameworks. Most of the problems can be fixed by simply updating the dependencies' dependencies with:

$ sudo port upgrade outdated

Brew Symlink Error

While installing Nagios I had some issues with my Symlinks. It was likely the result of my failed intial stabs at getting things running.

Either way, here's the solution if you have some problems.

$ sudo brew link jpeg

This caused a new problem. The solution was congealed through a "man's answer" approach, which involved destroying the following files:

bin/cjpeg
bin/djpeg
bin/jpegtran
bin/rdjpgcom
bin/wrjpgcom
include/jconfig.h
include/jerror.h
include/jmorecfg.h
include/jpeglib.h
lib/libjpeg.8.dylib
lib/libjpeg.a
share/man/man1/cjpeg.1
share/man/man1/djpeg.1
share/man/man1/jpegtran.1
share/man/man1/rdjpgcom.1
share/man/man1/wrjpgcom.1

Once I "took out the trash," I re-ran the brew symlink command again and kept moving.

Nagios Doesn't Start / Not Running

Check the log.

In my case I was receiving the following error:

Error: Could not create external command file '/usr/local/var/lib/nagios/rw/nagios.cmd' as named pipe: (2) -> No such file or directory.  If this file already exists and you are sure that another copy of Nagios is not running, you should delete this file.

For whatever reason the rw directory was never created when installing Nagios. The fix was as simple as adding the folder to the /usr/local/var/lib/nagios/ directory.

Can't See Services

Check the cgi.cfg for approprate usage settings. You may need to change the authorized users settings or create a user for Apache to autheticate with Nagios.

@gmyou
Copy link

gmyou commented Nov 28, 2013

Thank you for your help.

"Check the cgi.cfg for approprate usage settings. You may need to change the authorized users settings or create a user for Apache to autheticate with Nagios."

Is it 'htpasswd'?

@colemanfoley
Copy link

Thank you, this has been very helpful. I've used this to set up Nagios 3.5.1 on OS X 10.9.1, and it mostly worked. One difference I found: the nagios.conf file was at usr/local/Cellar/nagios/3.5.1/share/nagios.conf.

In order to view the localhost/nagios page, I had to enable(?) PHP by uncommenting this line in httpd.conf:
LoadModule php5_module libexec/apache2/libphp5.so

@songgane-zz
Copy link

Thank you for your help.

@demoV
Copy link

demoV commented Mar 3, 2017

I successfully able to install it.
But UI showing nagios core is not running.
can you help me on this./

@westofpluto
Copy link

"Once you have httpd.conf file open, transplant the Nagios settings from above."

Can you please be more specific?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment