Nagios 简明教程

Nagios - Commands

命令定义定义了一个命令。命令包括服务检查、服务通知、服务事件处理程序、主机检查、主机通知和主机事件处理程序。Nagios 的命令定义在 commands.cfg 文件中定义。

A command definition defines a command. Commands include service checks, service notifications, service event handlers, host checks, host notifications, and host event handlers. Command definitions for Nagios are defined in commands.cfg file.

以下是在命令定义格式 −

The following is the format for defining of a Command −

define command {
   command_name command_name
   command_line command_line
}

Command name − 此指令用于标识命令。联系方式、主机和服务的定义通过命令名称引用。

Command name − This directive is used to identify the command. The definitions of contact, host, and service is referenced by command name.

Command line − 此指令用于定义 Nagios 在将命令用于服务或主机检查、通知或事件处理程序时执行的操作。

Command line − This directive is used to define what is executed by Nagios when the command is used for service or host checks, notifications, or event handlers.

Example

define command{
   command_name check_ssh
   command_line /usr/lib/nagios/plugins/check_ssh ‘$HOSTADDRESS$’
}

此命令将执行插件 − /usr/libl/nagios/plugins/check_ssh 带有 1 个参数 : '$HOSTADDRESS$'

This command will execute the plugin − /usr/libl/nagios/plugins/check_ssh with 1 parameter : '$HOSTADDRESS$'

使用此检查命令的非常简短的主机定义可能类似于此处所示内容 −

A very short host definition that would use this check command could be similar to the one shown here −

define host{
   host_name host_tutorial
   address 10.0.0.1
   check_command check_ssh
}

命令定义告知如何执行主机/服务检查。如果发现任何问题,它还定义如何生成通知并处理任何事件。有几个命令来执行检查,例如检查 SSH 是否正常工作的命令、检查数据库是否启动并正在运行的命令、检查主机是否处于活动状态的命令等等。

The command definitions tell how to perform host/service checks. The also define how to generate notifications if any issue is identified and to handle any event. There are several commands to perform the checks, such as commands to check if SSH is working properly or not, command to check that database is up and running, command to check if a host is alive or not and many more.

有一些命令告诉用户基础设施中存在哪些问题。您可以在 Nagios 中创建自己的自定义命令或使用任何第三方命令,它们与 Nagios 插件项目类似,它们之间没有区别。

There are commands which tell users what issues are present in the infrastructure. You can create your own custom commands or use any third-party command in Nagios, and they are treated similar to Nagios plugins project, there is no distinction between them.

您还可以在命令中传递参数,这在执行检查方面提供了更大的灵活性。以下是如何定义带参数的命令 −

You can also pass arguments in the command, this give more flexibility in performing the checks. This is how you need to define a command with parameter −

define command {
   command_name check-host-alive-limits
   command_line $USER5$/check_ping -H $HOSTADDRESS$ -w $ARG1$ -c $ARG2$ -p 5
}

上述命令的主机定义 −

The host definition for the above command −

define host {
   host_name system2
   address 10.0.15.1
   check_command check-host-alive-limits!1000.0,70%!5000.0,100%
}

您可以通过将外部命令添加到 Nagios 周期性处理的命令文件中,在 Nagios 中运行外部命令。

You can run external commands in Nagios by adding them to commands file which is processed by Nagios daemon periodically.

通过外部命令,您可以在 Nagios 运行时完成很多检查。您可以暂时禁用一些检查,或强制一些检查立即运行,暂时禁用通知等。以下是必须写在命令文件中的 Nagios 中外部命令的语法 −

With External commands you can achieve lot many checks while Nagios is running. You can temporarily disable few checks, or force some checks to run immediately, disable notifications temporarily etc. The following is the syntax of external commands in Nagios that must be written in command file −

[time] command_id;command_arguments

您还可以在此处 https://assets.nagios.com/downloads/nagioscore/docs/externalcmds/ 查看可在 Nagios 中使用的所有外部命令的列表 −

You can also check out the list of all external commands that can be used in Nagios here − https://assets.nagios.com/downloads/nagioscore/docs/externalcmds/