The OPS allows a maintenance assistant to subscribe to alarms. When an alarm is generated, the maintenance assistant is triggered.
opsObj.alarm.subscribe(tag, feature, event, condition[4]=None, alarm_state=start, 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. |
alarm_state |
Whether an alarm is generated or cleared. The value can be start or end. |
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. alarm.subscribe("alm1", "bgp", "bgpBackwardTransition", condition, alarm_state='start') _ops.correlate("alm1") 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, an alarm is triggered when bgpBackwardTransition is detected.