Configure Nagios Service Groups To Monitor Live Websites

Nagios Service Groups

In this article, I am going to demonstrate "Nagios Service Groups" which is the most important feature of Nagios monitoring.

Before I start the steps to configure service groups. I am hoping that you have done with installation and configuration part of Nagios server.
If you are not aware of the Nagios or related services then go through the previous articles on Nagios.

Read:  Nagios Monitoring Server installation and Configuration

Read: Monitor Remote or Client Host using Nagios and NRPE Service

Service Groups :

Service groups are basically used to group one or more services together so we will able to check services at one place.
Service groups are a very useful Nagios feature and easy to configure.

Syntax :

define servicegroup
{
servicegroup_name WebSites
alias Live Web Sites
members websites_check,www.test.org,websites_check,www.testexample.com
}

Required Directives:

servicegroup_name: This directive used to define the name of Service Group.
alias: This directive helps you to easily identify a particular service group.
members: This is defined a list of services with the host in this group. Make sure Host & services should be separated by commas.

Now we are using Service group to group live website URL. we will go to monitor all our live websites HTTP 200 status. It will give us a report for the uptime and downtime of live websites.

To check live websites HTTP status, we need below plugin to download on Nagios server.

Check_website plugin :

This plugin is meant to verify that the index page is being served properly. Many plugins may check to see if port 80 is responding for a domain or if the site comes up without realizing if it is erroring out due to a DB tie-in, etc. This creates a file in /tmp that has the actual content output from the index. If it is not responding correctly or with an error, it will provide a critical error.

Let’s start the configuration of check_website plugin and Service group on Nagios.

Step 1: Download Check_website plugin

Download the check_website plugin with a below-provided link. Save this plugin under the “/usr/local/nagios/libexec”. Basically, all the plugins reside under the same directory or path.

Download plugin :

$ cd /usr/local/nagios/libexec
$ wget http://www.techthings.org/monitor-memcache-service-with-nagios/check_website.zip
$ unzip check_website.zip

Change permission of plugin,

$ chown nagios.nagioscmd check_website
$ chmod +x check_website

Step 2: Create websitecheck.cfg file

To monitor live website URL you need to first create a configuration file and define the host in that file.
This file is not present on the server. You need to manually create websitecheck.cfg file and add the definitions to monitor the website.
Go to the “/usr/local/nagios/etc/objects” & create file "websitecheck.cfg" .

$ cd /usr/local/nagios/etc/objects/
$ vim websitecheck.cfg

#Add the below lines to define Host.
define host{
use linux-server
host_name websites_check
alias websites_check
address 127.0.0.1
}

#Add Service to check the website.

define service{
use local-service
host_name websites_check
service_description www.techthings.org
check_command check_website!www.test.org
}

define service{
use local-service
host_name websites_check
service_description www.nagios.com
check_command check_website!www.testexample.com
}

Step 3: Create Servicegroup.cfg file

This file basically helps to define multiple services in single file as a group. Servicegroup.cfg file also resides under the “/usr/local/nagios/etc/objects/”. This is the main configuration file to define groups.

$ cd /usr/local/nagios/etc/objects/
$ vim servicegroup.cfg

#Add Servicegroups

define servicegroup{
servicegroup_name WebSites
alias Live Web Sites
members websites_check,www.test.org,websites_check,www.testexample.com
}

Step 4: Add command in commands.cfg

As you can see above we have used the check_website command in websitecheck.cfg file. This command we need to define the command.cfg file. Without adding command you will not able to fetch or check website URL status.
open "commands.cfg" file and add check_website command,

$ cd /usr/local/nagios/etc/objects/
$ vim commands.cfg

#Add Check_website command
define command{
command_name check_website
command_line $USER1$/check_http -H $ARG1$ -e "HTTP/1.1 200" -t 60
}

Step 5: Set Permissions

Once the all above file has created. Give necessary permissions to those files so it will work without any issues.

$ chown -R  nagios.nagioscmd /usr/local/nagios/etc/objects
$ chmod 664 websitechecks.cfg servicegroup.cfg commands.cfg

Step 6: Check & Restart Nagios service

Before restarting Nagios server make sure you have check or test configuration file with below command. Once below command run without errors and warnings then restart the Nagios service.

$ /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

Restart Service,

$ /etc/init.d/nagios restart

Step 7: Open Nagios Web Interface

Now go to the browser and open Nagios web interface. In right-hand navigation pane click on “Service Groups → website_check”.

Service Groups

These are the 7 simple steps to configure service groups on Nagios server. If you’re facing any difficulties while configuring Service Groups. Please do comment your queries or problem via the comment section, till then stay tuned to techthings.org for more such valuable articles.

I recommended before implementing this article go through below articles which give you more understanding about Nagios Monitoring.

Related Posts :

Leave a Reply

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