Installing Nagios on Solaris for network and server monitoring

Nagios, is a popular and free, open source network and server monitoring system that can benefit your IT infrastructure. nagios offers monitoring and alerting services for servers, switches, applications, and services.

This article will walk you through setting up a basic installation of Nagios on a Solaris 11 system.

Nagios installation prerequisites

You can successfully build Nagios Core using either the GNU compiler or Oracle Solaris Studio. In this article, we will be using the GNU C compiler to build the Nagios Core.

  1. Firstly, install the Apache Web Server and PHP Server:
    # pkg install pkg:/web/server/apache-22
    # pkg install pkg:/web/php-53
    # pkg install pkg:/web/server/apache-22/module/apache-php53
    # pkg install pkg:/library/gd
    Note: The Graphics Draw library (gd) is needed to use the nagios diagram feature)
  2. Install the GNU C compiler (gcc) if not installed on your system.
    # pkg install pkg:/developer/gcc-45
    There might be multiple version of gcc in your repository, use the pkg search -p gcc to examine which versions are available
  3. Create a nagios user and group
    # groupadd nagios
    # useradd -g nagios -c "nagios admin" nagios

Download, compile and install nagios

At the time of writing, the latest version of Nagiois is 4.0.2 available from the Nagious download page.

  1. Download and extract the archives into /usr/local/src (our your preferred download location)
    # mkdir -p /usr/local/src
    # cd /usr/local/src
    # tar -zxf nagious-4.0.2.tar.gz
    # mv nagious-4.0.2 nagios
  2. Configure and compile Nagios
    # cd nagios
    # ./configure --prefix=/usr/local/nagios
    
    Once the configuration process completes we need to modify a couple of files prior to compiling:
    1. Add the following line as line 28 of the ./worker/ping/worker-ping.c file:
      #include <pwd.h>
    2. Comment out the following line (line 144) in the ./include/config.h file:
      //#include <pwd.h>
    3. Change the following line (line 27) in the ./base/utils.c file from this:
      #include "../include/comments.h"
      To this:
      #include <pwd.h>
    4. Change the following line (line 29) in the ./cgi/Makefile file from this:
      CFLAGS=-Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCGI
      To this:
      CFLAGS=-Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCGI -I/usr/include/gd2
  3. Rub the following command to compile nagios:
    # gmake all
    cd ./base && make
    gmake[1]: Entering directory `/root/nagios/base'
    gcc -Wall -g -O2 -DHAVE_CONFIG_H -DNSCORE   -c -o broker.o broker.c
    gcc -Wall -g -O2 -DHAVE_CONFIG_H -DNSCORE   -c -o nebmods.o nebmods.c
    gcc -Wall -g -O2 -DHAVE_CONFIG_H -DNSCORE -c -o ../common/shared.o ../common/shared.c
    gcc -Wall -g -O2 -DHAVE_CONFIG_H -DNSCORE   -c -o checks.o checks.c
    gcc -Wall -g -O2 -DHAVE_CONFIG_H -DNSCORE   -c -o config.o config.c
    ...
  4. One compilation has completed, use the gmake install, gmake install-commandmode and gmake install-config:
    # gmake install
    # gmake install-commandmode
    # gmake install=config
  5. Now add the following lines to /usr/local/nagios/etc/cgi.cfg to get the correct authorisation for nagios:
    default_user_name=nagiosadmin
    authorized_for_system_information=nagiosadmin
    authorized_for_system_commands=nagiosadmin
    authorized_for_configuration_information=nagiosadmin
    authorized_for_all_hosts=nagiosadmin
    authorized_for_all_host_commands=nagiosadmin
    authorized_for_all_services=nagiosadmin
    authorized_for_all_service_commands=nagiosadmin

Building nagios plugins

After Nagios itself is compiled and installed, the next step is to repeat the process with the Nagios plug-ins, which enable enhanced system and service checks. At the time of writing plugins version 1.5 was available (visit Nagios plugins for the latest release)

  1. Download and uncompress:
    # cd /usr/local/src
    # wget https://www.nagios-plugins.org/download/nagios-plugins-1.5.tar.gz
    # tar -zxf nagios-plugins-1.5.tar.gz
    # cd nagios-plugins-1.5
  2. For plugins version 1.5, we need to modify the ./configure file and change line 18226 to the following:
    elif $PATH_TO_SWAP -l 2>/dev/null | egrep -i "^swapfile +dev + swaplo +blocks +free" >/dev/null
  3. Compile the nagios plugins:
    # ./configure --prefix=/usr/local/nagios
  4. Install the plugins:
    # gmake install

Configure Apache for Nagios

To configure Apache for use with Nagios, add the following code to your Apache config file. In this case the file is located in /etc/apache2/2.2/httpd.conf.

<IfModule alias_module>
    ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin"
    Alias /nagios /usr/local/nagios/share
</IfModule>
<Directory "/usr/local/nagios/sbin/">
    Options ExecCGI
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>
<Directory "/usr/local/nagios/share">
    Options None
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>

Create nagiosadmin user account

You'll need to create an Apache user account to be able to log into Nagios. The following command will create a user account called nagiosadmin and you will be prompted to provide a password for the account.

# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

Starting Apache Web Server and Nagios Server

Once Apache is configured for Nagios, simply enable and start the web server:

# svcadm enable apache2
# svcs apache2
STATE          STIME    FMRI
online         17:14:22 svc:/network/http:apache22

Enable and start the Nagios core services:

# svcadm restart manifest-import
# svcadm enable nagios

Nagios is now running, to confirm this you need to log into the Nagios Web interface. Point your browser to the ip address or FQDN of the Nagios core server, for example:

http://localhost/nagios
http://10.1.1.12/nagios

Configuring Nagios

Nagious has a number of configuration files located in:

/usr/local/nagios/etc
/usr/local/nagios/etc/objects

Whilst this article dealt with the compilation and installation of Nagios on the Solaris 11 OE, we do no cover the entire configuration; Review the Nagios online documentation which goes into detail on configuring Nagios.