IBM Tivoli Software IBM Tivoli Software

[ Bottom of Page | Previous Page | Next Page | Contents | Index ]


Variables

Variables in rules are usually identified by a leading underscore (_), although they can also begin with an uppercase letter instead of an underscore. The recommended convention is to use the form with a leading underscore, as it makes rules easier to understand.

No declaration of variables is required. If a variable is not instantiated, it is instantiated with a value in the first call where it is used.

Note:
When writing rules, pay special attention to the use of variables. Using a variable that has not been instantiated with a value can cause the rule not to work as intended in certain circumstances. For example, in an event filter where the variable _no_value is not instantiated, the following attribute condition would always succeed and instantiate the variables _origin and _no_value to the value of the origin attribute:
where [origin:_origin equals _no_value]

Variables are stored in memory. When the event server shuts down, they are lost. To store variables so they can be reloaded when the event server restarts, write them to a file before the event server shuts down, and then read them back in after the event server is restarted. Prolog predicates such as read and write can be used in rules to perform these actions. See read and write for additional information.

If you do not want strings that begin with an uppercase letter to be interpreted as variables, you must delimit them with single quotation marks. For example, Level_1 would be interpreted as a variable, whereas 'Level_1' would be interpreted as a string.

To illustrate the importance of variable syntax, the following rules perform exactly the same function. If the intent of the second rule is to filter on TEC_Start events only, the TEC_Start class specification should be delimited with single quotation marks in the event filter.

rule: unquoted_single_class1: (

  event: _event of_class _class
  % The name of the event class is stored in variable
  % _class.

    where [
      msg: equals 'unquoted event filter 1'
    ],

  action: (
    set_event_message(_event,'msg changed to %s',
                      [_class])
  )
).


rule: unquoted_single_class2: (
  event: _event of_class TEC_Start
  % The name of the event class is stored in  variable
  % TEC_Start. To filter on event class TEC_Start only, 
  % specify 'TEC_Start' (within quotes)

    where [
      msg: equals 'unquoted class filter 2'
    ],

  action: (
    set_event_message(_event,'msg changed to %s',
                      ['TEC_Start'])
  )
).

[ Top of Page | Previous Page | Next Page | Contents | Index ]