WAS THIS PAGE HELPFUL? {html}<a href="mailto:training@gwos.com?subject=How to define a command">Leave Feedback</a>{html}\\
\\
h5. Overview
{anchor:CommandLine}
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]
h5. Steps
h6. 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
!bookshelf_01_how_to_define_a_command.jpg!
h6. 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 directiv{*}e 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.
{Note}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.{Note}
# 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.
{Note}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.{Note}
# 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
!bookshelf_02_how_to_define_a_command.jpg!
\\
h5. Overview
{anchor:CommandLine}
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]
h5. Steps
h6. 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
!bookshelf_01_how_to_define_a_command.jpg!
h6. 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 directiv{*}e 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.
{Note}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.{Note}
# 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.
{Note}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.{Note}
# 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
!bookshelf_02_how_to_define_a_command.jpg!