WAS THIS PAGE HELPFUL? Leave Feedback
Overview
A Command line, which defines a command, is referenced in contact, host, and service definitions among other places. Commands that can be defined include service checks, service notifications, service event handlers, host checks, host notifications, and host event handlers. By default, Configuration uses commands.cfg to store check command definitions.
Command definitions can contain macros, but you must make sure that you include only those macros that are valid for the circumstances when the command will be used. Immediately prior to the execution of a command, Nagios will replace all macros in the command with their corresponding values. This allows you to define a few generic commands to handle all your needs. For additional information on the use of macros see: http://nagios.sourceforge.net/docs/1_0/macros.html
Steps
Select Resource
- Select Commands from the Configuration page and select New.
- In the Select Resource screen, check the resource macro to configure. This is used to specify an optional resource file that can contain $USERn$ macro definitions. $USERn$ macros are useful for storing usernames, passwords, and items commonly used in command definitions (like directory paths). User macros can be defined in one or more resource files. Nagios supports up to thirty-two user macros ($USER1$ through $USER32$).
- After selecting the resource macro, the screen will change and the selected macro's options will appear at the top of the screen. Select a Plugin to associate with the resource macro from the drop-down list. The selected plugin will check local or remote resources or services of some type. This is incorporated into the command line. And, select Next to continue.
Figure: Select Resource
New Command
- In the Command Wizard screen, enter a name for the command.
- Next, specify a command type: Check = service/host check commands, handlers; Notify = notification commands; Other = other commands (i.e. performance data collectors).
- The Command line directive is used to define what is actually executed by Nagios when the command is used for service or host checks, notifications, or event handlers. This field can be edited and before the command line is executed, all valid macros are replaced with their respective values. See the Nagios documentation on macros for determining when you can use different macros.
The command line is not surrounded in quotes. Also, if you want to pass a dollar sign ($) on the command line, you have to escape it with another dollar sign. - The Test area within the Command Wizard screen enables you to test the command line for a host with arguments. When you click the Test button this parses through the command definition, performs the macro substitutions, inserts the hostname from the host box, puts the resulting command into a shell command line and executes, returning the results of the execution in the box to the right. Specifically, the Test fields are used as follows when you click the Test button;
- Host - To specify the name of an existing host within Monarch. Used to substitute corresponding values for $HOSTNAME$, $HOSTALIAS$, and $HOSTADDRESS$ macro references in the command.
- Arguments - Specifies the command-argument values, separated by ! characters (exclamation points). These will be used to substitute corresponding values for $ARG1$, $ARG2$, and similar macro references in the command.
- Service description - To specify the name of a host service within Monarch. This will be used to substitute a value for $SERVICEDESC$ macro references in the command.
This help information is also available by selecting the question mark help buttons next to each field. The help button at the bottom of the screen provides direct access to this help page.
- Select Add to add the new command. Cancel will exit the command wizard without saving. You will be prompted that the command has been saved. Select Continue.
Figure: New Command Wizard