Defining object dependencies in Nagios

It is a very common scenario that computers, or the applications they offer, depend on other objects to function properly. A typical example is that a web based application will depend on a database server. Another is a host behind a private network that depends on an OpenVPN service to work. As a system administrator, your job is to know these relations—if you plan to reinstall a database cluster, you need to let people know there will be downtime for almost all applications. Nagios should also be aware of such relations.

In such cases, it is very useful for system monitoring software to consider these dependencies. When analyzing which hosts and services are not working properly, it is good to analyze such dependencies and discard things that are not working because of other failures. This way, it will be easier for you to focus on the real problems. Therefore, it allows you to get to the root cause of any malfunction much faster.

Nagios allows you to define how hosts and services depend on each other. This allows for very flexible configurations and checks. Nagios provides very flexible mechanisms for checking hosts and services—it will take all dependencies into account. This means that if a service relies on another one to function properly, Nagios will perform checks to make sure that all dependent services are working properly. In case a dependent service is not working properly, Nagios may or may not perform checks and may or may not send out any notifications, depending on how the dependency is defined. This is logical, because the service will probably not work properly if a dependent object is not working.

Nagios also offers the ability to specify parents for hosts. This is, in a way, similar to dependencies, as both specify that one object depends on another object. The main difference is that parents are used to define the infrastructure hierarchy. Parent definitions are also used by Nagios to skip checks for hosts that will obviously be down. Dependencies, on the other hand, can be used to suppress notifications about the problems that are occurring due to dependent services being down, but they do not necessarily cause Nagios to skip checking a particular host or service. Another difference is that parents can only be specified for hosts, whereas dependencies can be set up between hosts and services.

Dependencies also offer more flexibility in terms of how they are configured. It is possible to specify which states of the dependent host or service will cause Nagios to stop sending out notifications. You can also tell Nagios when it should skip performing checks based on the status of the dependent object.

To aid in describing how objects depend on each other, Nagios documentation uses two terms—master and dependent objects. When defining dependency, a master object is the object that needs to be working correctly in order for the other object to function. Similarly, the dependent object is the one that needs another object in order to work. This terminology will be used throughout this section, to avoid confusion.

Creating host dependencies

Let’s start with host dependency definitions. These are objects that have several attributes, and each dependency can actually describe one or more dependencies, for example, it is possible to tell Nagios that 20 machines rely on a particular host in a single dependency definition.

Here is an example of a dependency specifying that during maintenance, a Windows backup storage server in another branch depends upon a VPN server:

  define hostdependency 
  { 
    dependent_host_name            backupstorage-branch2 
    host_name                      vpnserver-branch1 
    dependency_period              maintenancewindows 
  } 

The following table describes all of the available directives for defining a host dependency. Items in bold are required when specifying a dependency:

Option

Description

dependent_host_name

Defines hostnames that are dependent on the master hosts, separated by commas

dependent_hostgroup_name

Defines the host group names whose members are dependent on the master hosts, separated by commas

host_name

Defines the master hosts, separated by commas

hostgroup_name

Defines the host groups whose members are to be the master hosts, separated by commas

inherits_parent

Defines whether a dependency should inherit dependencies of the master hosts

execution_failure_criteria

Specifies which master host states should prevent Nagios from checking the dependent hosts, separated by commas; it can be one or more of the following:

n – none, checks should always be executed

p – pending state (no check has yet been done)

o – host UP state

d – host DOWN state

u – host UNREACHABLE state

notification_failure_criteria

Specifies which master host states should be prevented from generating notifications about the dependent host’s status changes, separated by commas; it can be one or more of the following:

n – none, notification should always take place

p – pending state (no check has yet been done)

o – host UP state

d – host DOWN state

u – host UNREACHABLE state

dependency_period

Specifies the time periods during which the dependency will be valid; if not specified, the dependency is always valid

The question is where to store such dependency files. As for service definitions, it is recommended that you store dependencies specific to a particular host in the file containing the definition of the dependent host. For the previous example, we would put it in the hosts/backupstorage-branch2.cfg file.

When defining a dependency that will describe a relationship between more than one master or dependent host, it’s best to put these into a generic file for dependencies—for example, we can put it in hosts/dependencies.cfg. Another good option is to put the dependency definitions that only affect a single master host in the master host’s definition.

If you are defining a dependency that covers more than one master or dependent host, it is best to use host groups to manage the list of hosts that should be included in the dependency’s definition. This can be one or more host group names, and very often, these groups will also be the same as for the service definitions.

Creating service dependencies

Service dependencies work in a similar way to host dependencies. For hosts, you need to specify one or more master hosts and one or more dependent hosts; for services, you need to define a master service and a dependent service.

Service dependencies can be defined only for a single service, but on multiple hosts. For example, you can tell Nagios that IMAP services on the emailservers host group depend on the LDAP service on the ldapserver host.

Here is an example of how to define such a service dependency:

  define servicedependency 
  { 
    host_name                      ldapserver 
    service_description            LDAP 
    dependent_hostgroup_name       emailservers 
    dependent_service_description  IMAP 
    execution_failure_criteria     c,u 
    notification_failure_criteria  c,u,w 
  } 

The following table describes all available directives for defining a service dependency. Items in bold are required when specifying a dependency:

Option

Description

dependent_host_name

Defines the hostnames whose services should be taken into account for this dependency, separated by commas

dependent_hostgroup_name

Defines the host group names whose members’ services should be taken into account for this dependency, separated by commas

dependent_service_description

Defines the service that should be the dependent service for all the specified dependent hosts

host_name

Defines the master hosts whose services should be taken into account by this dependency, separated by commas

hostgroup_name

Defines the master host groups whose members’ services should be taken into account by this dependency, separated by commas

service_description

Defines the service that should be the master service for all the provided master hosts

inherits_parent

Specifies whether this dependency should inherit the dependencies of the master hosts

execution_failure_criteria

Specifies which master service states should prevent Nagios from checking the dependent services, separated by commas; it can be one or more of the following:

n – none, checks should always be executed

p – pending state (no check has yet been done)

o – service OK state

w – service WARNING state

c – service CRITICAL state

u – service UNKNOWN state

notification_failure_criteria

Specifies which master service states should be prevented from generating notifications for the dependent service status changes, separated by commas; it can be one or more of the following:

n – none, checks should always be executed

p – pending state (no check has yet been done)

o – service OK state

w – service WARNING state

c – service CRITICAL state

u – service UNKNOWN state

dependency_period

Specifies the time periods during which the dependency will be valid; if not specified, the dependency is always valid

As is the case for host dependencies, there is a question of where to store the service dependency definitions. A good answer to this is to store dependencies in the same files that the dependent service definitions are kept in. If you are following the previous suggestions regarding how to keep services in the file structure, then for a service bound to a single host, both service and the related dependencies should be kept in the same file as the host definition itself. If a service is used by more than one host, it is kept in a separate file. In this case, dependencies related to that service should also be kept in the same file as the service.

Related Articles

How to add swap space on Ubuntu 21.04 Operating System

How to add swap space on Ubuntu 21.04 Operating System

The swap space is a unique space on the disk that is used by the system when Physical RAM is full. When a Linux machine runout the RAM it use swap space to move inactive pages from RAM. Swap space can be created into Linux system in two ways, one we can create a...

read more

Lorem ipsum dolor sit amet consectetur

0 Comments

Submit a Comment

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

seven − 1 =