You can configure an alarm to run a script or a command when the alarm is triggered.
Use the alarm environment variables to define complex scripts and attach them to multiple alarms or inventory objects. For example, you can write a script that enters the following trouble ticket information into an external system when an alarm is triggered:
n Alarm name
n Object on which the alarm was triggered n Event that triggered the alarm
n Alarm trigger values
When you write the script, include the following environment variables in the script:
n VMWARE_ALARM_NAME
n VMWARE_ALARM_TARGET_NAME
n VMWARE_ALARM_EVENTDESCRIPTION
n VMWARE_ALARM_ALARMVALUE
You can attach the script to any alarm on any object without changing the script.
Prerequisites
Required Privilege: Alarms.Create Alarm or Alarm.Modify Alarm Procedure
1 In the Actions tab of the Alarm Settings dialog box, click Add to add an action.
2 In the Actions column, select Run a command from the drop-down menu.
3 In the Configuration column, type script or command information:
For this type of command... Enter this...
EXE executable files Full pathname of the command. For example, to run the cmd.exe command in the C:\tools directory, type:
c:\tools\cmd.exe.
BAT batch file Full pathname of the command as an argument to the
c:\windows\system32\cmd.exe command. For example, to run the cmd.bat command in the C:\tools directory, type:
c:\windows\system32\cmd.exe /c c:\tools\cmd.bat.
NOTE The command and its parameters must be formatted into one string.
If your script does not make use of the alarm environment variables, include any necessary parameters in the configuration field. For example:
c:\tools\cmd.exe AlarmName targetName
c:\windows\system32\cmd.exe /c c:\tools\cmd.bat alarmName targetName
4 (Optional) Configure alarm transitions and frequency. See “Specify Which Actions to Perform When Triggered,” on page 129.
What to do next
Click OK to save the alarm definition and exit the dialog box, or navigate to a different tab to make further changes.
Alarm Environment Variables for Scripts
To simplify script configuration for alarm actions, VMware provides environment variables for VMware alarms. Use the variables to define more complex scripts and attach them to multiple alarms or inventory objects so that the alarm action occurs when the alarm triggers.
Table 5-4. Alarm Environment Variables
Variable Name Variable Description Supported Alarm Type
VMWARE_ALARM_NAME The name of the triggered alarm. Condition, State, Event
VMWARE_ALARM_ID The MOID of the triggered alarm. Condition, State, Event
VMWARE_ALARM_TARGET_NAME The name of the entity on which
the alarm triggered. Condition, State, Event
VMWARE_ALARM_TARGET_ID The MOID of the entity on which
the alarm triggered. Condition, State, Event VMWARE_ALARM_OLDSTATUS The old status of the alarm. Condition, State, Event VMWARE_ALARM_NEWSTATUS The new status of the alarm. Condition, State, Event VMWARE_ALARM_TRIGGERINGSUMMARY A multiline summary of the alarm. Condition, State, Event VMWARE_ALARM_DECLARINGSUMMARY A single-line declaration of the
alarm expression. Condition, State, Event VMWARE_ALARM_ALARMVALUE The value that triggered the alarm. Condition, State VMWARE_ALARM_EVENTDESCRIPTION A description of the alarm status
change event. Condition, State
VMWARE_ALARM_EVENTDESCRIPTION A description of the event that
triggered the alarm. Event
Table 5-4. Alarm Environment Variables (Continued)
Variable Name Variable Description Supported Alarm Type
VMWARE_ALARM_EVENT_DATACENTER The name of the datacenter in
which the event occurred. Event VMWARE_ALARM_EVENT_COMPUTERESOURCE The name of the cluster or resource
pool in which the event occurred. Event
VMWARE_ALARM_EVENT_HOST The name of the host on which the
event occurred. Event
VMWARE_ALARM_EVENT_VM The name of the virtual machine on
which the event occurred. Event VMWARE_ALARM_EVENT_NETWORK The name of the network on which
the event occurred. Event
VMWARE_ALARM_EVENT_DATASTORE The name of the datastore on
which the event occurred. Event
VMWARE_ALARM_EVENT_DVS The name of the vSphere
Distributed Switch on which the event occurred.
Event
Alarm Command-Line Parameters
VMware provides command-line parameters that function as a substitute for the default alarm environment variables. You can use these parameters when running a script as an alarm action for a condition, state, or event alarm.
The command-line parameters enable you to pass alarm information without having to change an alarm script.
For example, you can use these parameters when you have an external program for which you do not have the source. You can pass in the necessary data by using the substitution parameters, which take precedence over the environment variables. You pass the parameters through the Configuration dialog box in the alarm definition wizard or on a command line.
Table 5-5. Command-Line Parameters for Alarm Action Scripts
Variable Description
{eventDescription} The text of the alarmStatusChange event. The {eventDescription} variable is supported only for Condition and State alarms.
{targetName} The name of the entity on which the alarm is triggered.
{alarmName} The name of the alarm that is triggered.
{triggeringSummary} A summary of the alarm trigger values.
{declaringSummary} A summary of the alarm declaration values.
{oldStatus} The alarm status before the alarm is triggered.
{newStatus} The alarm status after the alarm is triggered.
{target} The inventory object on which the alarm is set.