Designing and Managing Behavior Models - Using Trap Masks - Writing a Trigger Function -
Defining a Trap Mask      Examples of Trigger Functions

Writing a Trigger Function

If a mask cannot completely describe the type of trap it is looking for by specifying the contents of the trap's Generic trap, Enterprise, and Specific trap fields, it must contain a trigger function. This function, which you write using Perl, can include additional conditions that the trap must meet, and it can fire different triggers as appropriate.

Most trigger functions are very similar in structure. They follow this pattern:


   if (condition1) {
FireTrigger(arguments);
}
elsif (condition2) {
FireTrigger(arguments);
}
else {
FireTrigger(arguments);
}

The conditions, which can be arbitrarily complex, generally test the contents of a trap's variable bindings. However, they can test other information as well; for example, a condition can determine whether a trap came from a particular node. The FireTrigger() function fires a trigger, whose name, subobject, and node you can control.

To assist you in writing trigger functions, NerveCenter provides:

For further information about these predefined functions and variables and the pop-up help menu, see the following sections:

Also, see the section Examples of Trigger Functions. This section presents several sample trigger functions that show a number of the functions and variables being used in context.

Functions for Use in Trigger Functions

NerveCenter provides a number of functions (actually Perl subroutines) that facilitate the writing of trigger functions. The list below indicates what types of functions are available and where you can find detailed information about each function:

Variable-Binding Functions

Before looking at the variable-binding functions, let's make sure that we're using the same terminology.

When a trap arrives, NerveCenter looks at the trap's variable bindings and, for each variable binding, it sees an object and a value.

Variable Binding

trapMasksa5

In this case, the object is the OID encoding of the object type (sysDescr) plus an instance, and the value is a string that describes the system.

When NerveCenter sees this variable binding, it stores the following information. The portion of the OID that corresponds to the system group is stored as the binding's base object, and the instance (0) is stored as the binding's instance. When concatenated, the base object and the instance form what NerveCenter calls a subobject.

Base Objects, Instances, and Subobjects

trapMasksa9

The variable sysDescr is stored as the binding's attribute.

Attributes

trapMasks10

Finally, the value "Windows Workstation" is stored as the binding's value.

The variable-binding functions give you access to a binding's subobject, attribute, and value. There's also a function that returns the number of variable bindings in a trap or trigger.

Each of the variable-binding functions is explained below:

VbAttribute()

Syntax: VbAttribute(index)

Description: Returns the attribute from the variable binding with an index of index. The first variable binding has an index of 0.

VbNum()

Syntax: VbNum()

Description: Returns the number of variable bindings in the trap's variable-binding list.

VbObject()

Syntax: VbObject(index)

Description: Returns the subobject from the variable binding with an index of index. The first variable binding has an index of 0.

VbValue()

Syntax: VbValue(index)

Description: Returns the value from the variable binding with an index of index. The first variable binding has an index of 0.

Variables for Use in Trigger Functions

NerveCenter defines several variables for use in trap mask trigger functions. For the most part, these variables contains the values of the fields in a trap's Protocol Data Unit (PDU), with the exception of the variable bindings.

The complete list of variables that you can use in a trap mask trigger function is shown in tVariables Used in Trigger Functions:

Variables Used in Trigger Functions

Variable Description

$NodeName

The name of the node that was the source of the trap

$TrapPduAgentAddress

The IP address of the SNMP agent that sent the trap

$TrapPduCommunity

The community name included in the SNMP message

$TrapPduEnterprise

An OID representing the object that generated the trap

$TrapPduGenericNumber

The generic trap type

$TrapPduSpecificNumber

A specific trap code

$TrapPduTime

The time, in hundredths of a second, between the last initialization of the network entity and the generation of the trap



Defining a Trap Mask Examples of Trigger Functions
29 July 2003