Set Up Alert Action Script

Available only in vFabric Hyperic

Define a Script Action for an Alert

A script action allows you to access and use Hyperic environment variables that contain information about a fired alert. You can use the data in any fashion you wish, for instance in a web service call to external management system.

To use the script action feature, write a script that implements the action or logic you wish to perform with the alert-related environment variables. When you configure the alert, specify the script to be executed when the alert fires. The script is server-side only, meaning it must be accessible and executable by the same user running the HQ Server process.

Agent-side Scripts

If you wish to execute agent-side scripts, see Configure a Custom Control Action.

Script actions can be defined for resource alerts and resource type alerts. In this version of Hyperic, escalation schemes do not support script actions.

Script actions are synchronous

Script actions execute one at a time. Until a script action completes, additional alerts will not fire on the resource.

Script actions and memory

Script actions are forked by the the Hyperic Server's Java process. Most operating systems duplicate the Java process's memory before executing the new process; exact behavior varies by operating system. If the operating system does not provide for over-committing memory, script execution requires an amount of free memory equal to the amount of memory that the Hyperic Server's Java process consumes — otherwise, the script action will not run.

Environment Variables for Fired Alert Data

The environment variables for fired alert data are prefixed with the string "HYPERIC_". The table below describes the variables.

Variable

Description

Example Output

HYPERIC_ALERT_ALERT_TIME

The time at which the  alert fired, in milliseconds from epoch.

1219167000000

HYPERIC_ALERT_CONDITION

The condition that caused the alert to fire. Note:  This environment variable is supported only on Unix-based platforms. The value contains the Java \n character, which causes errors under Windows. In Windows environments, use the HYPERIC_ALERT_SUMMARY variable, which provides the same information without the \n character.

If Load Average 5 Minutes > 1.0 (actual value = 1.4)

HYPERIC_ALERT_DESCRIPTION

The description of the alert that fired. 

This alert will fire when the load rises

HYPERIC_ALERT_ID

The internal Hyperic ID for the alert that fired.

Note: The HYPERIC_ALERT_ID for an alert is not committed to the Hyperic database until all alert actions are complete. Therefore, an alert action script (whether it uses SQL or HQApi) cannot query or update the Hyperic database using the alert's HYPERIC_ALERT_ID, because that value will not yet exist in the Hyperic database.

 

HYPERIC_ALERT_NAME

The name of the alert that fired.

High Load

HYPERIC_ALERT_PRIORITY

The priority of the alert that fired, 1 for High, 2 for Medium, 3 for Low.

2

HYPERIC_ALERT_SUMMARY

A condensed data string that contains the relevant alert and resource names and values which triggered the alert.

Mac OS X DOWN The-Idea-Men Availability (0.0%)

HYPERIC_FIXED_ALERT_ID

This variable was added in Hyperic 4.5.1.2.

Valid for recovery alerts only. Supplies the internal Hyperic ID for the primary alert to which the recovery alert is assigned.

 

HYPERIC_FIXED_ALERT_NAME

This variable was added in Hyperic 4.5.1.2.

Valid for recovery alerts only. Supplies the name of the primary alert to which the recovery alert is assigned.

High Load

HYPERIC_PLATFORM_NAME

The platform on which this alert fired.

localhost.hyperic.com

HYPERIC_RECOVERY_ALERT

A boolean that indicates if the alert is a recovery alert.

false

HYPERIC_RESOURCE_ID

The internal ID for the resource for which the alert fired.

 

HYPERIC_RESOURCE_NAME

The name of the resource for which the alert fired.

localhost.hyperic.com

Example Script

The following script is an example of using the alert variables. The example script simply writes the time that the script executed and the variables to a log file; it is not a representative use case. The purpose of script actions is to enable more complex alert actions, and actions that meet the unique needs of your environment.

alert.pl
#!/usr/bin/perl
my $logfile = "/tmp/output.txt";
my $date = localtime();
open LOGFILE, ">$logfile" or die "Cannot open log file for writing";
print LOGFILE "# Running script at $date", "\n";
foreach $key (sort keys(%ENV)) {
if ($key =~ m/^HYPERIC/) {
my $msg = "$key = $ENV{$key}";
print LOGFILE $msg, "\n";
}
}
close LOGFILE;

Assign the Script Action to an Alert

To assign a script action to an alert definition:

  1. Select the alert definition.

  2. Click the Script tab in the Alert Definition page.

  3. Enter the full path to script and click Set.