Nagios Learning Note Three: Configuring Nagios

Source: Internet
Author: User
Tags time and date

1. Nagios's master configuration file

Nagios's main configuration file is Nagios.cfg, whose syntax is very concise, usually # begins with the behavior Comment line, and the parameter is formatted as <parameter>=<value>;, some parameters can be repeated. The commonly used parameters are described below:

Log_file: Set the Nagios log file;

The Cfg_file:nagios object defines the relevant file, which can be reused multiple times to specify multiple files;

Cfg_dir: Sets the directory where the relevant files for the Nagios object definition are located, and all files in this directory are files defined as objects; This parameter can be reused multiple times to specify multiple directories;

Resource_file: Sets the relevant files for the Nagios-attached macro definition;

Status_file: Sets the files that Nagios stores the current status information for all hosts and services;

Status_update_interval: Sets the update frequency of state information in the file specified by Status_file;

Service_check_timeout: Set timeout for service detection, default is 60 seconds;

Host_check_timeout: Set timeout for host detection, default is 30 seconds;

Notification_timeout: Sets the time-out for notification message sending attempt, default is 30 seconds;

2, resource_file and macro definitions

In the master configuration file, the parameter resource_file is used to define the storage file for all user variables (that is, "macros"), which is used to store additional information that can be accessed in the object definition, such as access to a service's password, etc., so this information is usually sensitive data that is generally not allowed to be accessed through the Web interface. You can define up to 32 macros in this file, which are $user1$, $USER 2$ ... $USER 32, and these macros are typically referenced in the check command. Typically, $user1$ is used to refer to the path information in the directory where the Nagios plugin is located, so it is generally not recommended to modify its value.

Nagios defines a number of macros in advance, and their values usually depend on their context. As follows:

HOSTNAME: The host name used to refer to the specified host for the HOST_NAME, and the hostname of each host is unique;

Hostaddress: The value that is used to refer to the address directive in the host object, which can usually be an IP address or host name;

Hostdisplayname: The value used to refer to the alias instruction in the host object to describe the current host, the display name of the host;

Hoststate: The current state of a host, one of the three up,down,unreachable;

Hostgroupnames: Used to refer to the names of all the host groups to which the hosts belong, separated by commas between host groups;

Lasthostcheck: Used to refer to the time and date of the last detection of a host, the UNIX timestamp format;

Listhoststate: Used to refer to the state of the previous detection of a host, up,down or unreachable one of the three;

SERVICEDESC: The value used to refer to the desccription instruction in the corresponding service object;

ServiceState: Used to refer to the current state of a service, one of Ok,warning,unkown or critical;

Servicegroupnames: A comma-separated list of service group names used to refer to all service groups to which a service belongs;

CONTACTNAME: The value used to refer to the contact_name instruction in a contact object;

Contactalias: The value used to refer to the alias instruction in a contact object;

Contactemail: The value used to refer to an email instruction in a contact object;

Contactgroupnames: Used to refer to the name of all contact groups that a contact belongs to, separated by commas between the contact group names;

Nagios 3 also supports custom macros, but it is unique in its definition and usage. An administrator can use extra instructions in the definition of a type object and be able to use a specially formatted macro in the command to reference the value of this instruction. The reference method differs depending on the object type, as follows:

$_host<variable>$– refers to the value of the instruction defined in the host object;

$_service<variable>$– refers to the value of the instruction defined in the service object;

$_contact<variable>$– refers to the value of the instruction defined in the contact object;

A simple example is as follows:

If a host is defined as:

Define Host

{

HOST_NAME Somemachine

Address 10.0.0.1

_mac 12:34:56:78:90:ab

Check_command Check-host-by-mac

}

The corresponding detection command can be defined as:

Define Command

{

Command_name Check-host-by-mac

Command_line $USER 1$/check_hostmac-h $HOSTADDRESS $-M $_hostmac$

}

3. Define host Objects

"Host" refers to the machine being monitored, but the physical host can also be a virtual device. The definition of a host object should contain at least one simple name, an alias, an IP address, and a detection command to use. In addition, many times, the definition should also include monitoring window, contact and related issues to be notified, the frequency of detection, the way to retry the detection, the frequency of sending notifications and so on. For specific instructions and instructions, please refer to the official documentation: Http://nagios.sourceforge.net/docs/3_0/objectdefinitions.html#host.

Example of a host definition:

Define Host

{

HOST_NAME WebServer1

Hostgroups webservers

Alias Www.magedu.com

Address 172.16.100.11

Check_command check-host-alive

Check_interval 5

Retry_interval 1

Max_check_attempts 5

Check_period 24x7

Contact_groups Linux-admins

Notification_interval 30

Notification_period 24x7

Notification_options D,u,r

}

The notification_options is used to specify which notifications should be sent when the host is in a state. Its various states and their representations are as follows:

D--down

U--unreachable

R--up (Host recovery)

F--flapping

s--commissioning Downtime start or end

Hosts can be grouped into groups, which are host groups. Each host group object typically contains a globally unique simple name, a description name, and members belonging to this group. In addition, members of a host group can also be other host groups. The main group definition example is as follows:

Define HostGroup

{

Hostgroup_name webservers

Alias Linux Web servers

Members WebServer1

}

4. Define the service object

A "service" is a feature or resource object provided by a host, such as an HTTP service, storage space resource, or CPU load. The service is attached to the host, and each service is identified by a service name that requires uniqueness on a particular host. Each service object also typically defines a detection command and how to make a problem notification.

Define Service

{

HOST_NAME WebServer1

Service_description www

Check_command check_http

Check_interval 10

Check_period 24x7

Retry_interval 3

Max_check_attempts 3

Notification_interval 30

Notification_period 24x7

Notification_options W,c,u,r

Contact_groups Linux-admins

}

The notification_options is used to specify which notifications should be sent when the service is in a state. Its various states and their representations are as follows:

W--warning

U--unknown

C--critical

R--ok (recovery)

F--flapping

s--commissioning Downtime start or end

Unlike host objects, sometimes multiple hosts may provide the same services, such as multiple servers providing the Web at the same time. Therefore, when you define a service object, it host_name multiple hosts that can be separated by commas.

Services can be grouped into groups, which are service groups. Each service group object typically contains a globally unique simple name, a description name, and members belonging to the group. In addition, a service group member is typically a service on a host that uses the format of

Define Servicegroup

{

Servicegroup_name webservices

Alias all services related to Web

Members Webserver1,www,webserver2,www

}

5. Defining Command objects

Commands are used to describe how to perform state detection on a host or service. The definition of a service object consists of two directives: first name (command_name) and command Line (command_line); the name is used to identify this command object, and the command line is the one that is actually executed when the detection is performed.

When a command object is used to detect other objects, it usually requires additional parameters to identify a particular object to detect, at which point the Command object needs to be command_name[!arg1][!arg2][...] The syntax format for the reference. Therefore, in the definition of the Command object, the command-line directive usually uses the macro $arg1$, $ARG 2$ ..., corresponding to receive [!arg1][!arg2][...] The arguments that are passed.

As defined by the following command object:

Define Command

{

Command_name Check_local_swap

Command_line $USER 1$/check_swap-w $ARG 1$-C $ARG 2$

}

The following service uses the Command object defined above to detect the service object:

Define Service

{

HOST_NAME localhost

Service_description Swap Usage

Check_command check_local_swap!20!10

}

6. Define the time period object

A period is used to define a date and time span that an action can or cannot perform, such as a daily 8:00-18:00 within a weekday, which can be repeated in several different operations. The definition of a period object contains a globally unique name identifier and one or more time spans. For example:

Define TimePeriod

{

Timeperiod_name workinghours

Alias working Hours, from Monday to Friday

Monday 09:00-17:00

Tuesday 09:00-17:00

Wednesday 09:00-17:00

Thursday 09:00-17:00

Friday 09:00-17:00

}

Where there are many ways to specify the time format:

Calendar time: The format is YYYY-MM-DD, such as 2012-04-21;

Date: as April 21;

One day of the month: 21, 21st per month;

Number of weeks of the month: for example, Saturday 1, the first month of Saturday;

Day of the week: such as Monday, Tuesday and so on;

7. Define Contact objects

The contact object is used to define the owner of a host device or to accept a notification when a problem occurs. The definition of a contact object contains a globally unique identity name, a description name, and one or more e-mail addresses. In addition, it should typically include notification commands that are used when a corresponding host or service fails. For example:

Define Contact

{

Contact_Name mageedu

Alias Mage Education

email [email protected]

Host_notification_period workinghours

Service_notification_period workinghours

Host_notification_options D,u,r

Service_notification_options W,u,c,r

Host_notification_commands Host-notify-by-email

Service_notification_commands Notify-by-email

}

Contacts can also be grouped into groups, that is, contact groups. A contact group object contains a globally unique identity name, a description name and a contact member (members) or a person contact Group (contactgroup_members) that belongs to this contact set. For example:

Define Contactgroup

{

Contactgroup_name Linux-admins

Alias Linux Administrators

Members magedu, mageedu

}

In the definition of a host or service object, you can specify either a contact or a contact group. Of course, a host's problem contact can also be different from the one on which the service runs.

8. Template and Object inheritance

Nagios implements template-based object inheritance through a powerful inheritance engine. This means that you can define the common properties of an object of a type to be organized into an object template and inherit the definition of its related properties directly from this template when defining an object in its type. The method of defining an object template is simple, and usually requires only the Register directive and its value to be set to 0 when defining a type object. The name of the object template is typically defined using the name Directive, which differs from the directives used by a particular type of object. When defining objects of this type, only the use directive is used and its value is set to the name of the corresponding template. For example:

Define Host

{

Name Generic-server

Check_command check-host-alive

Check_interval 5

Retry_interval 1

Max_check_attempts 5

Check_period 24x7

Notification_interval 30

Notification_period 24x7

Notification_options D,u,r

Register 0

}

Define Host

{

Use Generic-server

Name WebServer1

Alias Web Server 01

Address 172.16.100.11

Contact_groups Linux-admins

}

When an object is defined to inherit more than one template at the same time, you only need to specify multiple template names separated by commas for the use directive. At the same time, Nagios supports multi-level inheritance of templates.

9. Dependency relationship

To describe the dependencies between Nagios objects, there are two terms used here: Master (the host or service being relied upon) and dependent (the Nagios object that relies on master in the dependency relationship). Nagios can define dependencies between objects, define its parent object for an object, or even specify the time period in which this dependency takes effect. Here is an example of a dependency definition:

Define Hostdependency

{

Dependent_host_name Backuphost

HOST_NAME Vpnserver1

Dependency_period maintenancewindows

}

Where host_name is used to define the master host, Dependent_host_name defines the dependent host. In the definition of dependencies, it is common to use Execution_failure_criteria to define what state the master host is, and no longer detects the host that relies on this master, notification_failure_ Criteria is used to define what state the master is in and does not send dependent related host issue notifications to the contact person.

The definition of inter-service dependencies is similar to the dependencies between hosts, such as:

Define Servicedependency

{

HOST_NAME MySQLServer

Service_description MySQL

Dependent_hostgroup_name apacheservers

Dependent_service_description WebService

Execution_failure_criteria C,u

Notification_failure_criteria c,u,w

}

Nagios Learning Note Three: Configuring Nagios

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.