Installing Icinga Monitoring Tool on Ubuntu

In this tutorial, we will install an open source monitoring system ICINGA, on ubuntu 14.04. Firstly we will configure some basic configuration to monitor network and services of host resources via the web interface.
We would be needing one server and no. of clients that we want to monitor. Here we are using Icinga version 1.x. Icinga Monitoring tool is completely plug-in based

With this guide we will end up with

On Remote Host:

Installing require packages on server

#> apt-get install apache2 build-essential libgd2-xpm-dev
#> apt-get install libjpeg62 libjpeg62-dev libpng12 libpng12-dev
#> apt-get install snmp libsnmp5-dev
#> apt-get install openssl openssl-devel
#> apt-get install libssl-*
#> apt-get install libjpeg-devel libpng libpng-devel
#> apt-get install libjpeg-turbo
  • Create account information:Become the root user.
     $> su -l

    Create a new icinga user account and give it a password:

     #> /usr/sbin/useradd nagios
     #> passwd nagios

    Make a new directory to keep all downloads underneath

    #cd Downloads

    Install nagios plugin

    #wget http://nagios-plugins.org/download/nagios-plugins-2.0.3.tar.gz
    #tar -xvzf nagios-plugins-2.0.3.tar.gz 
    #cd nagios-plugins-2.0.3/
    #./configure
    #make
    #make install

    The permission on the plugin directory  and the plugins will need to be fixed at this point, so run the following commands.

    #chown nagios.nagios /usr/local/nagios
    #chown -R nagios.nagios /usr/local/nagios/libexec

    Install xinetd

    #apt-get install xinetd

    Download, compile and install NRPE daemon

    #wget http://sourceforge.net/projects/nagios/files/nrpe-2.x/nrpe-2.15/nrpe-2.15.tar.gz -O nrpe.tgz
    #tar -xzvf nrpe.tgz
    #cd nrpe
    #./configure --with-ssl=/usr/bin/openssl --with-ssl-lib=/usr/lib/x86_64-linux-gnu --enable-ssl
    #make all -w
    #make install-plugin
    #make install-daemon
    #make install-daemon-config
    #vim /usr/local/nagios/etc/nrpe 
    allowed_hosts = 127.0.0.1 <server ip> 
    #vim /etc/xinetd.d/nrpe
    only_from = 127.0.0.1 <server ip> 
    #vim /etc/services
    nrpe    5666/tcp

    Open Firewall

    #iptables -I INPUT -p tcp -m tcp --dport 5666 -j ACCEPT 
    #sudo iptables -v -n -x -L

On Server Side:

Installing require packages on server

#> apt-get install apache2 build-essential libgd2-xpm-dev
#> apt-get install libjpeg62 libjpeg62-dev libpng12 libpng12-dev
#> apt-get install snmp libsnmp5-dev
#> apt-get install openssl openssl-devel
#> apt-get install libssl-*
#> apt-get install libjpeg-devel libpng libpng-devel
#> apt-get install libjpeg-turbo

Become the root user.

 $> su -l

We will need to install Postfix for mail services, I suggest you go to though this guide to set up a mail server https://www.digitalocean.com/community/tutorials/how-to-install-and-setup-postfix-on-ubuntu-14-04

Create a new icinga user account and give it a password:

 #> /usr/sbin/useradd -m icinga 
 #> passwd icinga

On some distributions you’ll need to add the group in a single step:

 #> /usr/sbin/groupadd icinga

For sending commands from the classic web interface to Icinga, you’ll need to create a new group icinga-cmd. Add the webuser and the Icinga user to this group:

 #> /usr/sbin/groupadd icinga-cmd
 #> /usr/sbin/usermod -a -G icinga-cmd icinga
 #> /usr/sbin/usermod -a -G icinga-cmd www-data

(or www, wwwrun, apache, depending on the distribution)

Change to your local source directory i.e. /usr/src

 #> cd /usr/src

Get the current source from the Icinga Website.

Don’t forget to download the Monitoring Plugins.

or you can directly install by adding its ppa.

# add-apt-repository ppa:formorer/icinga
# apt-get update
# apt-get install icinga icinga-doc icinga-idoutils mysql-server libdbd-mysql mysql-client
or
# apt-get install icinga icinga-doc icinga-idoutils postgresql libdbd-pgsql postgresql-client

Now you will be presented with a series of prompts regarding your Icinga installation. Here is a list of the prompts, and how you should answer them:

  • MySQL Configuration: Enter a new MySQL root user password
  • PostFix Configuration: Select “Internet Site”
  • PostFix Configuration: Enter your Fully Qualified Domain Name (example.com, for example)
  • Configuring icinga-cgi: Enter “icingaadmin” user’s password (login to access Icinga).
  • Configuring icinga-common: Enter “No” to enabling external commands
  • Configuring icinga-idoutils: Enter “Yes” to configuring database for icinga-idoutils with dbconfig-common
  • Configuring icinga-idoutils: Select “mysql” as the database type
  • Configuring icinga-idoutils: Enter MySQL root password (that you just assigned above)
  • Configuring icinga-idoutils: Enter a new icinga-idoutils database user password

Plugins

# apt-get install nagios-plugins

Download monitoring plugins, compile and install them.

#wget https://www.monitoring-plugins.org/download/monitoring-plugins-2.1.1.tar.gz
#tar xvzf monitoring-plugins-2.1.1.tar.gz
#cd monitoring-plugins-2.1.1/
#./configure --prefix=/usr/local/icinga --with-cgiurl=/icinga/cgi-bin --with-nagios-user=icinga --with-nagios-group=icinga
#make
#make install
#setenforce 0

Once you have defined the necessary contexts you have to apply the settings:

#chcon -R /usr/local/icinga/sbin
#chcon -R /usr/local/icinga/share
#chcon -R /usr/local/icinga/var/rw
#update-rc.d icinga defaults

Enable ido2db Daemon

# vim /etc/default/icinga
IDO2DB=yes
# service ido2db start

In order to check the enabled status on ido2db startup, use

# sh -x /etc/init.d/ido2db start | grep IDO2DB

Enable idomod module

Check whether this has already been done in /etc/icinga/modules/idoutils.cfg. If not, copy the sample config over and restart Icinga to load the module. (Tip – if icinga.cfg does not contain cfg_dir=/etc/icinga/modules the config won’t be included!).

# cp /usr/share/doc/icinga-idoutils/examples/idoutils.cfg-sample /etc/icinga/modules/idoutils.cfg
# service icinga restart

Check your icinga log and/or syslog to verify that Icinga with idomod has been started, as well as idomod has successfully connected to ido2db.

Enable external commands

If you were not asked during package install, do it manually.

# vim /etc/icinga/icinga.cfg
check_external_commands=1
 
# service icinga stop
# dpkg-statoverride --update --add nagios www-data 2710 /var/lib/icinga/rw
# dpkg-statoverride --update --add nagios nagios 751 /var/lib/icinga
# service icinga start 
# update-rc.d icinga defaults

Classic UI Authentication

The authorization is stored within  /etc/icinga/htpasswd.users – new users can be added with the following command

# htpasswd /etc/icinga/htpasswd.users <username>

start icinga

#/etc/init.d/icinga start

Make sure your system’s firewall rules are configured to allow access to the web server if you want to access the Icinga classic interface remotely.

#iptables -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT

Accessing the Icinga User Interface

Go to http://yourhost/icinga, and log in using the icingaadmin login that you set up during the Icinga installation.

You should see that Icinga is monitoring one host, localhost (your Icinga server), and seven services, like this:

Icinga Initial Overview

The top row shows that the single monitored host is “Up”, and the bottom row shows that there are seven “OK” monitored services.

If the status of localhost is “Down”, you might need to change the permissions of your ping command. Run the following command to allow the nagios user to use the ping command:

sudo chmod u+s `which ping`

Let’s add more hosts and services to be monitored!

Congratulation! you are done with installation of Icinga on your server system. But you are not done yet. There is still more to go 🙂

Now on Monitoring Host (Server) we have to do following tasks:

  • Install check_nrpe plugin
  • Create Nagios command defination for using the check_nrpe plugin
  • Create Nagios host and service definitions for monitoring the remote host
Installing NRPE addon:

Design Overview:

Screenshot from 2015-01-06 19:22:15

We can configure NRPE plugin on remote host using two ways:

  • Download and compile tarball of nrpe plugin
  • Install it from available packages

I have mentioned both the ways, go with one you like the most.

WAY 1:

make a Downloads directory anywhere in file system so that we can keep all downloads at same place. Suppose I have made a directory at /Downloads

#> cd Downloads

Instead of installing NRPE from scratch you may want to use a package which might be available for your OS.

If you are planning to install from source then please use the official release tarball using something like

#> wget http://sourceforge.net/projects/nagios/files/nrpe-2.x/nrpe-2.15/nrpe-2.15.tar.gz -O nrpe.tgz
#> tar xzf nrpe.tgz
#> cd nrpe
#> ./configure --with-ssl=/usr/bin/openssl --with-ssl-lib=/usr/lib/x86_64-linux-gnu --enable-ssl
#>  make all
#> make install-plugin

Test communication with the NRPE daemon

Make sure that the nrpe_check plugin can communicate with NRPE daemon on the remote host

#/usr/local/nagios/libexec/check_nrpe -H <remote host address>

 you should get back a string that will tell you what version of NRPE is installed on remote host

 Create a command defination

#vim /etc/icinga/commands.cfg

add the following definition to file

 

 define command{
        command_name check_nrpe
        command_line    $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
        }

now navigate to

#cd /etc/icinga/objects/
#cp localhost_icinga.cfg ./yourhost.cfg

localhost_icinga.cfg contains the definition to get status of services running on our localhost. We can use same configuration and modify them to get services status of our remote host.

#vim yourhost.cfg

replace host_name with your remote host name(any name), and address with IP address of the remote host which you want to monitor. And then define all services related to that hostname.

# 

define host{
        use                     generic-host            ; Name of host template to use
        host_name               remotehost
        alias                   icinga-2
        address                 <remote host IP address>
        }

# Define a service to check the disk space of the root partition
# on the local machine.  Warning if < 20% free, critical if
# < 10% free space on partition.

define service{
        use                             generic-service 
        host_name                       remotehost
        service_description             Disk Space
        check_command                   check_all_disks!20%!10%
        }



# Define a service to check the number of currently logged in
# users on the local machine.  Warning if > 20 users, critical
# if > 50 users.

define service{
        use                             generic-service 
        host_name                       remotehost
        service_description             Current Users
        check_command                   check_users!20!50
        }


# Define a service to check the number of currently running procs
# on the local machine.  Warning if > 250 processes, critical if
# > 400 processes.

define service{
        use                             generic-service 
        host_name                       remotehost
        service_description             Total Processes
                check_command                   check_procs!250!400
        }



# Define a service to check the load on the local machine. 
define service{
        use                             generic-service 
        host_name                       remotehost
        service_description             Current Load
                check_command                   check_load!5.0!4.0!3.0!10.0!6.0!4.0
        }

copy all code inside it and paste same code at the end of same file, here the code you have copied is giving you details of your localhost and now we will modify it to give us information regarding our remote machine.

Restart your xinetd and icinga service

#service xinetd restart
#service icinga restart

WAY 2

We will be using NRPE as our agent to gather remote host data for Icinga.

Installing NRPE on a Remote Host:

#sudo apt install nagios-plugins nagios-nrpe-serve

and modify it with same aforementioned procedure.

===========================================================================================

References:

https://wiki.icinga.org/display/howtos/Setting+up+Icinga+with+IDOUtils+on+Ubuntu

http://nagios.sourceforge.net/docs/nrpe/NRPE.pdf

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s