Configuring Nagios for monitoring of basic services

The Nagios documentation says:

""Nagios is quite powerful and flexible, but it can take a lot of work to get it configured just the way you’d like. Once you become familiar with how it works and what it can  do for you, you’ll never want to be without it.
""
The saying was true for me as I struggled a lot initially while configuring nagios . After configuring once to monitor the localhost , I tried again and it was straight forward for me  . I was able to configure it without much issues and thought of documenting it. Initially we will see how to configure nagios to monitor services on localhost , and later  we will see how to monitor services on different hosts .

The following steps are need to be followed while configuring Nagios to monitor services on localhost.

1. Download nagios and nagios-plugin from the nagios repository
         http://www.nagios.org/download/
   If you want to get it through commandline , then you can download it using

      wget http://sourceforge.net/projects/nagios/files/nagios-3.x/nagios-3.2.1/nagios-3.2.1.tar.gz/download
     wget http://sourceforge.net/projects/nagiosplug/files/nagiosplug/1.4.14/nagios-plugins-1.4.14.tar.gz/download


2. Create a nagios User who will manage the Nagios interface . You have to execute the commands as
    root or with sudo privileges.
         sudo /usr/sbin/useradd -m nagios
         passwd nagios


3. Create a new nagcmd group for allowing external commands to be submitted through the web
    interface.Add both the nagios user and the apache user to the group.
        sudo /usr/sbin/groupadd nagcmd
        sudo /usr/sbin/usermod -a -G nagcmd nagios
        sudo /usr/sbin/usermod -a -G nagcmd apache


4. It's time now to install nagios . Let's do it . Couple of steps are there .

       tar zxvf nagios-3.2.1.tar.gz
       cd nagios-3.2.1/
      ./configure --with-command-group=nagcmd

       make all 
       sudo make install
       sudo make install-init
       sudo make install-config
       sudo make install-commandmode


5. After installing nagios , we need to do some basic level configuration . Sample configuration files   are copied to /usr/local/nagios/etc directory. These sample files should work fine for getting started with Nagios. We need to edit the /usr/local/nagios/etc/objects/contacts.cfg config file and change the email address  to the address we want to receive alerts . In our case , it is nagios@localhost.

6. After installing and configuring nagios , we need to configure the web interface through which we will monitor and manage the services.

      1. Install the Nagios web config file in the Apache conf.d directory.
              sudo make install-webconf
      2. Create a nagiosadmin account for logging into the Nagios web interface.
              sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
      3. Restart Apache to make the new settings take effect.
             sudo service httpd restart 

 For those who donot have patience , they can now restart the nagios service and can fire up the  interface  to view the nagios interface . The following commands can be used for this. 
       
      1. sudo /etc/init.d/nagios restart
     2. Open the following link using browser.
                    http://localhost/nagios/                 

If you see message like this "(Return code of 127 is out of bounds - plugin may be missing)" on the right panel , that means your configuration is correct as of now . The above message indicates that the nagios plugins are missing and we will install the plugins in the next step.  

7. Nagios provides provides many usefull plugins to get us started monitoring all the basics. We also need to get the plugins installed to monitor the bacic services . Some of the plugins include checks like host check , local disk usage check , HTTP check , Current Load on the system etc. Let's now get the plugin installed.
              tar zxvf nagios-plugins-1.4.14.tar.gz
              cd nagios-plugins-1.4.14/
             ./configure --with-nagios-user=nagios --with-nagios-group=nagios
              make ; sudo make install

 
8. Now since we have the core nagios and nagios plugins installed , now lets's put our nagios configuration into action . We will start the nagios service and start monitoring services on localhost.

         1.Verify whether the nagios configuration file is fine before starting the nagios service.
                       sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
         2.Start the nagios service
                       sudo service nagios start
                       sudo chkconfig --add nagios
                       sudo chkconfig nagios on

         3.Login to the web interface and click on "Services" on the left hand side panel and start
             monitoring your services. Phew!, we are done.Very much straight forward if done carefully.
                        http://localhost/nagios/
            It will ask for the username and password which you provided at Step 6 and start monitoring your services .

Comments

Popular posts from this blog

PSSH : Parallel SSH to execute commands on a number of hosts

How to add check_http as a service in Nagios Monitoring using NRPE

Configuring Nagios to monitor services using NRPE