Nagios 4.1 Monitoring System on Ubuntu 14.04 with Qpage

We use Nagios for monitoring servers and equipment, we also use a paging software called Qpage. While I found there were plenty of walkthroughs on how Nagios is supposed to work there were few explaining how Qpage works into Nagios. If you are setting up multiple Nagios servers then you probably want to setup a master server with nConf.

I will not be explaining every little command, such as cd or tar, if you are following this tutorial you should already know the basics and a bit more.

For this tutorial I am using Ubuntu Server 14.04.2 which can be downloaded from ubuntu.com

Files required for this: (There may be newer version but this is what I am using currently)

nagios-4.1.0rc1.tar.gz

nagios-plugins-2.0.3.tar.gz

nrpe-2.15.tar.gz

qpage-3.3.tar.gz

When I do a fresh installation I typically only install the OpenSSH server during installation then I install the rest of the packages after I have the system fully up to date. SO Step Zero would be install your server OS and do all your updates.

Step one is to install the needed packages to the server

#> apt-get install apache2 libapache2-mod-php5 build-essential libgd2-xpm-dev libssl-dev sendmail heirloom-mailx wget apache2-utils curl apt-file libnet-snmp-perl libpq5 libradius1 libsensors4 libsnmp-base libtdb1 libwbclient0 samba-common samba-common-bin smbclient snmp whois mrtg libmysqlclient15-dev libcgi-pm-perl librrds-perl libgd-gd2-perl checkinstall unzip libtalloc2 daemon

Step two we are going to create the users and groups

#> groupadd -g 3000 nagios

#> groupadd -g 3001 nagcmd

#> useradd -u 3000 -g nagios -G nagcmd -d /usr/local/nagios -c ‘Nagios Admin’ nagios

#> adduser www-data nagcmd

Step 3 create a src directory to work from and download the files needed

mkdir -p /usr/local/src/nagios4

cd /usr/local/src/nagios4

Put your downloaded files in the above directory ( not required but if you are following along with the tutorial you may get lost if you don’t )

Step 4 extract all the files that you downloaded for installation

#> tar -xf nagios-4.1.0rc1.tar.gz

#> tar -xf nagios-plugins-2.0.3.tar.gz

#> tar -xf qpage-3.3.tar.Z

#> tar -xf nrpe-2.15.tar.gz

Step 5 is actually several steps, we will just call this Install Nagios

#> cd nagios-4.1.0rc1

#> mkdir -p /usr/local/nagios/share/{stylesheets,images}

#> ./configure –prefix=/usr/local/nagios –with-nagios-user=nagios –with-nagios-group=nagios –with-command-user=nagios –with-command-group=nagcmd

#> make all

#> checkinstall

( You will be performing several checkinstall each one you will enter 10 press enter, type libc6, perl and hit enter then hit enter again. This is setting the dependencies for the package. )

#> 10 <enter>

#> libc6, perl <enter>

#> <enter>

#> checkinstall –pkgname=nagios-init make install-init

#> 10 <enter>

#> libc6, perl <enter>

#> <enter>

#> checkinstall –pkgname=nagios-config make install-config

#> 10 <enter>

#> libc6, perl <enter>

#> <enter>

#> checkinstall –pkgname=nagios-commandmode make install-commandmode

#> 10 <enter>

#> libc6, perl <enter>

#> <enter>

#> checkinstall –pkgname=nagios-webconf make install-webconf

#> 10 <enter>

#> libc6, perl <enter>

#> <enter>

#> /usr/bin/install -c -m 644 sample-config/httpd.conf /etc/apache2/conf-available/nagios.conf

#> ln -s /etc/apache2/conf-available/nagios.conf /etc/apache2/conf-enabled/nagios.conf

#> checkinstall –install=no –pkgname=nagios-exfoliation make install-exfoliation

#> 10 <enter>

#> libc6, perl <enter>

#> <enter>

Step 6 install Nagios Plugins

#> cd /usr/local/src/nagios4/nagios-plugins-2.0.3

#> ./configure –with-nagios-user=nagios –with-nagios-group=nagios –with-openssl=/usr/bin/openssl –enable-perl-modules –enable-libtap

#> make

#> checkinstall

#> 10 <enter>

#> libc6, perl <enter>

#> <enter>

Step 7 Install NRPE ( this allows for remote plugin execution )

#> cd /usr/local/src/nagios4/nrpe-2.15

#> ./configure –with-ssl=/usr/bin/openssl –with-ssl-lib=/usr/lib/x86_64-linux-gnu

#> make all

#> checkinstall

#> 10 <enter>

#> libc6, perl <enter>

#> <enter>

Step 8 Create the Nagios startup script

#> vi /etc/init/nagios.conf

# nagios – monitoriong system

description     “nagios monitoring system”

start on virtual-filesystems

stop on runlevel [06]

respawn

respawn limit 5 30

limit nofile 65550 65550

chdir /usr/local/nagios/

setuid nagios

setgid nagios

console log

script

        exec bin/nagios etc/nagios.cfg

end script

:wq

#> mv /etc/init.d/nagios /var/backups/nagios.init

Step 9 Create the Nagios admin login to view the interface

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

#> chown nagios:nagcmd /usr/local/nagios/etc/htpasswd.users

Step 10 Setup SSL and Apache –  if you have a cert use it here otherwise generate a self signed cert as below

#> mkdir /etc/apache2/ssl

#> cd /etc/apache2/ssl

#> a2enmod ssl

#> openssl req -x509 -nodes -days 365 -newkey rsa:4096 -out nagios.pem -keyout nagios.key

#> mkdir -p /var/www/nagios4/

#> chown www-data:www-data /var/www/nagios4

#> ln -s /usr/local/src/nagios4/nagios-4.0.8/contrib/exfoliation/images/favicon.ico /var/www/favicon.ico

#> vi /etc/apache2/sites-available/nagios.conf

<VirtualHost *:80>

        ServerName <YOUR SERVER>

        Redirect / https://<YOUR SERVER>/

</VirtualHost>

<VirtualHost *:443>

    ServerAdmin <YOUR EMAIL>

    ServerName <YOUR SERVER>

    DocumentRoot /var/www/nagios4

    <Directory />

        Options +FollowSymLinks

        AllowOverride None

    </Directory>

    <Directory /var/www/nagios4>

        Options -Indexes +FollowSymLinks +MultiViews

        AllowOverride All

        Require all granted

    </Directory>

     SSLEngine On

     SSLCertificateFile /etc/apache2/ssl/nagios.pem

     SSLCertificateKeyFile /etc/apache2/ssl/nagios.key

</VirtualHost>

:wq

#> a2enmod cgi

#> a2dissite 000-default

#> a2ensite nagios.conf

#> service apache2 restart

#> ln -s /usr/local/nagios/etc/ /etc/nagios4

Step 11 Setup the Nagios config directory 

This is a good way to organize your configuration files, you do not have to follow this structure just be sure to edit your nagios.conf file and point the config files to the proper directories and files however you organize them. With an nConf setup you end up not using this structure anyhow.

#> mkdir /etc/nagios4/conf.d

#> vi /etc/nagios4/nagios.cfg

cfg_dir=/etc/nagios4/conf.d/

:wq

#> mkdir -p /etc/nagios4/conf.d/{hosts,services,timeperiods,templates,hostgroups,servicegroups,contacts}

#> service nagios restart

Step 12 Setup Qpage

#> cd /usr/local/src/nagios4/qpage-3.3/

#> ./configure

#> make

#> cp qpage /usr/local/bin/

#> cd /etc/init.d/

#> vi qpage

#!/bin/sh

#

# Startup for QuickPage

#

# chkconfig: 345 99 99

# description: Listen and dispatch ACPI events from the kernel

# processname: qpage

PATH=/bin:/usr/bin:/usr/local/bin

case “$1” in

        start)

                echo “Starting QuickPage daemon” > /dev/console 2>&1

                qpage -C /etc/qpage.cf -q10 > /dev/console 2>&1 &

                ;;

        stop)

                pid=`ps -e | grep qpage | awk ‘{print $1}’`

                if [ ! -z “$pid” ]; then

                        echo “Stopping QuickPage daemon” > /dev/console 2>&1

                        kill $pid > /dev/null 2>&1

                fi

                ;;

        *)

                echo “Usage: /etc/init.d/qpage { start | stop }”

                ;;

esac

exit 0

:wq

#> chmod 755 qpage

#> mkdir /var/spool/qpage

#> chmod 755 /var/spool/qpage

#> chown daemon:root /var/spool/qpage

#> mkdir /var/qpage

#> chmod 755 /var/qpage

#> chown daemon:root /var/qpage

#> vi /etc/group

Add root and daemon to the dialout group so it can use the modem

:wq

Here is an example qpage setup, we send pages to a relay that then sends them to text messages on our phones via AT&T you may or may not be able to use that setup. At minimum if you want to use a pager setup you will want pagers that can accept text.

#> vi /etc/qpage.cf

administrator=<YOUR EMAIL ADDRESS>

queuedir=/var/spool/qpage

lockdir=/var/qpage

identtimeout=5

modem=microcomm

#NOTE this is YOUR modem I used a USB US Robotics modem that the system assigned TTYACM0

        device=/dev/ttyACM0 

        initcmd=at&f0

        dialcmd=atdt

# AT&T Text to number service

service=attwireless

   device=microcomm

        baudrate=9600

        parity=even

        allowpid=yes

        maxtries=6

        phone=18882983562

        maxmsgsize=2048

# Verizon Text to number service

service=verizon

        device=microcomm

        baudrate=2400

        parity=even

        allowpid=yes

        maxtries=6

        phone=18668230501

        maxmsgsize=2048

#

# Pager list:

#

pager=pager1

        text=pager1

        pagerid=5555555555

        service=attwireless

pager=pager2

        text=pager2

        pagerid=5555555555

        service=attwireless

:wq

#> /etc/init.d/qpage start

Test qpage with one of the pagers

#> qpage -d pager1

testing

.

You can double check /var/log/syslog to make sure it sent the page.

This entry was posted in Linux How-To. Bookmark the permalink.

Leave a Reply

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