Installing Nagios with MacPorts

A few quick notes on steps I took when installing Nagios from MacPorts. Most of this is given to you during the install, but there are a few missing steps that I’ve added here.I didn’t end up using it, after the installation, but I’ve got a few notes from what little usage I did after the install.

  1. Do the install:
    sudo port install nagios
    
  2. Edit /opt/local/apache2/conf/httpd.conf and add the following before any existing ScriptAlias directives:
    #
    # Nagios stuff
     
    ScriptAlias /nagios/cgi-bin/ "/opt/local/sbin/nagios/"
    <directory "/opt/local/sbin/nagios">
     AllowOverride None
        Options ExecCGI
        Order allow,deny
        Allow from all
        AuthName "Nagios Access"
        AuthType Basic
        AuthUserFile /opt/local/etc/nagios/htpasswd.users
        require valid-user
    </directory>
     
    Alias /nagios "/opt/local/share/nagios"
    <directory "/opt/local/share/nagios">
        Options None
        AllowOverride AuthConfig
        Order allow,deny
        Allow from all
    </directory>
     
    # End Nagios stuff
    #

    # # Nagios stuff ScriptAlias /nagios/cgi-bin/ "/opt/local/sbin/nagios/" &lt;directory "/opt/local/sbin/nagios"> AllowOverride None Options ExecCGI Order allow,deny Allow from all AuthName "Nagios Access" AuthType Basic AuthUserFile /opt/local/etc/nagios/htpasswd.users require valid-user &lt;/directory> Alias /nagios "/opt/local/share/nagios" <directory "/opt/local/share/nagios"> Options None AllowOverride AuthConfig Order allow,deny Allow from all </directory> # End Nagios stuff #

  3. Back up the default config files, just in case:
    cd /opt/local/etc/nagios
    sudo mkdir sample
    sudo cp *.cfg-sample sample/
    cd objects
    sudo mkdir sample
    sudo cp *.cfg-sample sample/
    
  4. Rename the default config files:
    cd /opt/local/etc/nagios
    sudo -s
    for i in *cfg-sample; do mv $i `echo $i | sed -e s/cfg-sample/cfg/`; done;
    cd objects
    for i in *cfg-sample; do mv $i `echo $i | sed -e s/cfg-sample/cfg/`; done; exit
    
  5. Create an Apache password file for the ‘nagiosadmin’ user:
    sudo /opt/local/apache2/bin/htpasswd -c /opt/local/etc/nagios/htpasswd.users nagiosadmin
    
  6. Create a couple of directories that are needed:
    sudo mkdir -p /opt/local/var/nagios/spool/checkresults
    sudo chown -R nagios:nagios /opt/local/var/nagios/spool
    
  7. Add the www user to the nagios group so that Apache has write access to certain files, especially /opt/local/var/nagios/rw/nagios.cmd:
    sudo dscl . -append /Groups/nagios GroupMembership www
    sudo dscl . -append /Groups/nagios GroupMembership _www
    
  8. Test the config to make sure everything’s okay:
    sudo nagios -v /opt/local/etc/nagios/nagios.cfg
    
  9. Restart Apache and start the Nagios daemon:
    sudo /opt/local/apache2/bin/apachectl -k restart
    sudo /opt/local/var/nagios/nagios.init start
    
  10. If you want it to run at startup, enable the startup item:
    sudo launchctl load -w /Library/LaunchDaemons/org.macports.nagios.plist
    

Usage Notes

The documentation is of course geared toward a Linux install; directory names are different in a MacPorts install.

  • /usr/local/nagios/libexec/ is /opt/local/libexec/nagios/
  • /usr/local/nagios/etc/ is /opt/local/etc/nagios/
  • The startup script /etc/rc.d/init.d/nagios is at /opt/local/var/nagios/nagios.init
  • The binary location /usr/local/nagios/bin/nagios is /opt/local/bin/nagios

8 Replies to “Installing Nagios with MacPorts”

    1. Pretty much anything I’d guess. It’s not a terribly complicated piece of software! “sudo port install nagios” is the easiest way to find out.

  1. I’m very appreciative someone is assuming the entire groundwork is laid by MacPorts to get this going, thanks a lot for this.
    Not to be anal or anything, I still don’t have this working yet in Snow Leopard or Leo(second fresh setup with 403 access denied errors) but it’s only been a short while I’ve been trying.
    For the sake of completeness, it seems a bit out of order that the nagios-specific ScriptAlias comes before the Alias additions to the file, is that required?
    It is obvious that a MacPorts-installed Apache2 is being installed as well, but that’s not mentioned.
    Also, step 4 assumes the working directory is /opt/local/etc/nagios, so you may want to throw in a “cd ..” at the beginning of that step.
    Please understand I just want to verify I’m doing the steps correctly before I tinker with users and chown(wasn’t there supposed to be a nagioscmd group as well?)

    1. I’ve fixed the mistake in step 4, thanks for that. I didn’t get very far with this, Nagios seems more painful to configure than any piece of software should ever be. For a network that’s constantly adding and updating devices, it’s not very useful.
      I can say I got the thing running successfully with these steps, but that’s about as far as I got with it.

  2. Awesome post. Thanks! A few minor comments…

    1. In step 6, -P must be lowercase:
    sudo mkdir -p /opt/local/var/nagios/spool/checkresults

    2. In step 5, sudo is repeated twice, and for those using the default apache install, htpasswd binary is located in the default path:
    sudo sudo /opt/local/apache2/bin/htpasswd -c /opt/local/etc/nagios/htpasswd.users nagiosadmin

    would then be:
    sudo htpasswd -c /opt/local/etc/nagios/htpasswd.users nagiosadmin

Comments are closed.