All Linux HowTo's

Nagios Part 3 | Nagios Services, Hosts and Groups

This is a multi-part series of Nagios articles all focused on configuring a complete Nagios monitored network. Find all related articles here.

Nagios monitors servers, switch and pretty much anything you like and each device must be defined in a file that Nagios looks at for guidance. That file is “/etc/nagios/servers/clients.cfg” according to the other Nagios articles on this blog. However, if it’s not in that location on your server, do a quick search and find it.

That file (that we’ll call the “clients” file) is very easy to understand but can get pretty long. The clients file does need some explanation and that’s the point of this article. Keep in mind that although i’m discussing the important parts, that file does allow plenty more than what we’ll cover.

We’re using SNMP over UDP (port 161), SNMP version “2c” and i recommend forcing “IPV4” which can be done by editing the “commands.cfg” file and replacing “check_ping” with “check_ping -4” – but that’s a topic for another time.

The example “clients” file below is the basis for the examples i provide below.

“hostgroup”. This section groups hosts together allow easy assignment of monitoring. For example, suppose you have two groups of servers; those that are monitored by SNMP and those that are monitored simply by “ping”. We would create two “hostgroup” sections where the first is for all devices monitored using SNMP and another section for those devices monitored simply for availability (ping). The “hostgroup” does NOT define any kind of monitoring at all – it simply groups devices together to make things easier later on.

TIP: Devices not mentioned in any “hostgroup” will still be monitored with pings.

“service”. This section defines what we want to monitor for. For example, suppose we want to monitor for CPU usage or RAM usage, we’d define one “service” for CPU and another for RAM. Actually, in the examples that follow, we include services for monitoring disk space too. We can monitor for anything that SNMP collects information for. This section does NOT specify which devices we’ll apply the service monitoring to.

“host”. This is where we define the devices that we monitor. We do NOT specify what services we want to monitor here.

How it all links together

  1. We define our devices in the “host” sections.
  2. We group the devices in the “hostgroup” section.
  3. We define the services to be monitored in the “service” section AND list the groups (the “hostgroup”) that the service monitoring applies to.

Example “services.cfg”:

Here’s the “services.cfg” file that our example is based on:

define hostgroup{
	hostgroup_name      snmp-servers
	alias               SNMP Hosts
	members             mail.example.com, www.example.com
}

define service{
        use                     generic-service
        hostgroup_name          snmp-servers
        service_description     CPU 5 Minute Load
        check_command           check_snmp!-C public -o 1.3.6.1.4.1.2021.10.1.3.2 -P 2c 
}
define service{
        use                     generic-service
        hostgroup_name          snmp-servers
        service_description     CPU Idel Time
        check_command           check_snmp!-C public -o 1.3.6.1.4.1.2021.11.11.0 -P 2c
}
define service{
        use                     generic-service
        hostgroup_name          snmp-servers
        service_description     Free RAM
        check_command           check_snmp!-C public -o 1.3.6.1.4.1.2021.4.11.0 -P 2c
}
define service{
        use                     generic-service
        hostgroup_name          snmp-servers
        service_description     Used Disk Space Percentage
        check_command           check_snmp!-C public -o 1.3.6.1.4.1.2021.9.1.9.1 -P 2c
}
define service{
        use                     generic-service
        hostgroup_name          snmp-servers
        service_description     Used Inodes Percentage
        check_command           check_snmp!-C public -o 1.3.6.1.4.1.2021.9.1.10.1 -P 2c
}

define host{
	use                             linux-server
	host_name                       mail.example.com
	alias                           mail.example.com
	address                         mail.example.com
	max_check_attempts              5
	check_period                    24x7
	notification_interval           30
	notification_period             24x7
}
define host{
	use                             linux-server
	host_name                       www.example.com
	alias                           www.example.com
	address                         www.example.com
	max_check_attempts              5
	check_period                    24x7
	notification_interval           30
	notification_period             24x7
}

Similar Posts:

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.