Subscribe to Events

Function Description

The OPS allows a maintenance assistant to subscribe to an event. When the event occurs, the assistant is triggered.

Command Prototype

opsObj.event.subscribe(tag, feature, event, condition[4], occurs=1, period=30)

Parameter Description

Table 1 describes parameters supported by event subscription APIs.
Table 1 Parameters supported by event subscription APIs

Method

Description

opsObj

Specifies an OPS object. It is obtained through ops.ops() instantiation.

tag

Specifies a condition ID. The value is a string of 1 to 8 case-sensitive characters. It starts with a letter and can contain letters, digits, and underscores (_). The value can be None Working conditions with a tag and without a tag are mutually exclusive. If the two conditions are used, the condition that is successfully configured first takes effect. In addition, the tag cannot be set to and, or, or andnot.

feature

Specifies a feature name, which is a well-known character string, such as ospf.

event

Specifies an event name, which is a well-known character string, such as VFM_FLHSYNC_FAIL.

condition[4]

Specifies a condition array. The value can be None. The array contains a maximum of four members. For example:

conditions = []

con1 = {'name':'ifIndex', 'op':'eq', 'value':'100'}

conditions.append(con1)

con2 = {'name':' vpnInstance', 'op':'eq', 'value': 'abc'}

conditions.append(con2)

The relationship between multiple conditions is AND.

occurs

Specifies the number of occurrence times within a statistical period.

period

Specifies a subscription period.

Description of Return Values

  • First return value: The value 0 indicates a success, and the value 1 indicates a failure.
  • Second return value: This value describes success or failure reasons, expressed in a character string.

Example

test.py

import ops

def ops_condition(_ops):
   _ops.event.subscribe("evt1","configuration", "CFG_FILE_CHANGE", [])
   _ops.correlate("evt1")

def ops_execute(_ops):
   handle, err_desp  = _ops.cli.open()
   _ops.cli.execute(handle,"display device > ops_test.log")
   ret = _ops.cli.close(handle) 
   return 0

After the script is executed, when the assistant detects CFG_FILE_CHANGE and input display device to redirect the output to the ops_test.log file, the script is triggered.

Copyright © Huawei Technologies Co., Ltd.
Copyright © Huawei Technologies Co., Ltd.
< Previous topic Next topic >