This page last changed on Jan 11, 2010 by marty.

Available only in HQ Enterprise

Define a Script Action for an Alert*

A script action allows you to access and use HQ 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 http://support.hyperic.net/display/DOC/User-defined+Control+Actions

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

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_RESOURCE_NAME The name of the resource for which the alert fired. localhost.hyperic.com
HYPERIC_ALERT_NAME The name of the alert that fired. High Load
HYPERIC_ALERT_DESCRIPTION The description of the alert that fired. 
This alert will fire when the load rises
HYPERIC_ALERT_PRIORITY The priority of the alert that fired, 1 for High, 2 for Medium, 3 for Low. 2
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_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_ALERT_ALERT_TIME The time at which the  alert fired, in milliseconds from epoch. 1219167000000
HYPERIC_RECOVERY_ALERT A boolean that indicates if the alert is a recovery alert. false
HYPERIC_PLATFORM_NAME The platform on which this 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.

ScriptTab.png (image/png)
ScriptEntry.png (image/png)
Document generated by Confluence on Apr 20, 2010 15:01