The OPS allows a maintenance assistant to subscribe to an event. When the event occurs, the assistant is triggered.
opsObj.event.subscribe(tag, feature, event, condition[4], occurs=1, period=30)
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. |
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.