English 中文(简体)
Nagios - Commands
  • 时间:2024-12-22

Nagios - Commands


Previous Page Next Page  

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_pne command_pne
}

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

Command pne − 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_pne /usr/pb/nagios/plugins/check_ssh ‘$HOSTADDRESS$’
}

This command will execute the plugin − /usr/pbl/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
}

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 apve or not and many more.

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 flexibipty in performing the checks. This is how you need to define a command with parameter −

define command {
   command_name check-host-apve-pmits
   command_pne $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-apve-pmits!1000.0,70%!5000.0,100%
}

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

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

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

Advertisements