Using Workflows for Alert Actions

A workflow can be executed as an alert action. A workflow that is executed as an alert action is the selected Workflow for the Execute workflow Alert action (BUI), or is the value of the workflow property of the execute_workflow handler (CLI), as described in Adding Alert Actions.

To enable a workflow to be executed as an alert action, the workflow global variable must specify an alert: true member.

By default, workflows execute as the user that is executing the workflow. However, a workflow that is executed as an alert action executes by default as the user that created the workflow. To be able to be executed as an alert action, the workflow global variable of the workflow must specify a setid: true member.

Alert actions have a single object parameter that has the following members.

Table 9-8 Required Members for Alert Execution Context

Required Member Type Description

class

String

The class of the alert

code

String

The code of the alert

items

Object

An object describing the alert

timestamp

Date

Time of alert

The items member of the parameters object has the following members:

Table 9-9 Required Members for the items Member

Required Member Type Description

url

String

The URL of the web page describing the alert

action

String

The action that should be taken by the user in response to the alert

impact

String

The impact of the event that precipitated the alert

description

String

A human-readable string describing the alert

severity

String

The severity of the event that precipitated the alert

Example 9-11 Workflow Auditing Failure to Reboot

Workflows that execute as alert actions can use the audit function to generate audit log entries. For example, debugging information should be written to the audit log.

See the multiple uses of the audit function in the following example. This workflow:

  • Is executed in response to alert params.uuid, specifying this workflow to execute.

  • Reboots the system only if both controllers are in the clustered state.

  • Audits any failure to reboot.

var workflow = {
       name: 'Failover',
       description: 'Fail the node over to its clustered peer',
       alert: true,
       setid: true,
       execute: function (params) {
               var uuid = params.uuid;
               var clustered = 'AKCS_CLUSTERED';

               audit('attempting failover in response to alert ' + uuid);

               try {
                       run('configuration cluster');
               } catch (err) {
                       audit('could not get clustered state; aborting');
                       return;
               }

               if ((state = get('state')) != clustered) {
                       audit('state is ' + state + '; aborting');
                       return;
               }

               if ((state = get('peer_state')) != clustered) {
                       audit('peer state is ' + state + '; aborting');
                       return;
               }

               run('cd /');
               run('confirm maintenance system reboot');
       }
};