No relevant resource is found in the selected language.

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Read our privacy policy>Search

Reminder

To have a better experience, please upgrade your IE browser.

upgrade

Configuration Guide - Device Management

S7700 and S9700 V200R013C00

This document describes the configurations of Device Management, including device status query, hardware management, CSS, SVF, PoE, OPS, OIDS, energy-saving management, information center, fault management, NTP, synchronous ethernet, PTP.
Rate and give feedback:
Huawei uses machine translation combined with human proofreading to translate this document to different languages in order to help you better understand the content of this document. Note: Even the most advanced machine translation cannot match the quality of professional translators. Huawei shall not bear any responsibility for translation accuracy and it is recommended that you refer to the English document (a link for which has been provided).
Making a Python Script for Association Between OIDS and OPS

Making a Python Script for Association Between OIDS and OPS

Context

After an OIDS event is generated through the OIDS monitoring function or OIDS filter, you can use the OPS APIs (including OIDS event subscription, writing back event execution result to OIDS, and obtaining environment variable) supported by association between OIDS and OPS to make Python scripts for developing functions.

Procedure

  1. Create a text and modify its file name extension to .py as a Python script.
  2. Edit the script according to the Python script format.

    # -*- coding: utf-8 -*-     # Declare that this Python script file uses utf-8 as source code encoding.
    
    # Fixed statement for importing the OPS module. You can use OPS APIs supported by the device in the script only after the OPS module is imported. For details, see OPS API List.
    import ops
    # Fixed statement for importing the sys module. The sys module is responsible for interaction between programs and the built-in Python interpreter of the device and provides a series of functions and variables. After the sys module is imported, you can use these functions and variables. For details about functions and variables, see official Python documents.
    import sys
    # Fixed statement for importing the OS module. The OS module is responsible for interaction between programs and the operating system and provides interfaces for accessing the bottom layer of the operating system. After the OS module is imported, you can use these interfaces. For details about these interfaces, see official Python documents.
    import os
    
    # Fixed statement for defining the subscription processing function ops_condition. This function is invoked when the script assistant is configured and is used to subscribe to events. It is scheduled and executed by the built-in framework script _frame.py of the device.
    # The input parameter of the function ops_condition is the OPS object created in _frame.py. You can perform data access under this object.
    def ops_condition(ops):
    	# The current phase is the subscription phase. You need to use OIDS Event Subscription.
    	# Use the ops.oids.subscribe API to subscribe to an event identified by tempHigh. It indicates that the specified action in the execution phase is triggered when the sensor temperature is too high. You can modify the timer as required.
    	# If the input parameter value is a character string, you need to enclose the string in double quotation marks.
    	# The ret and desp are user-defined script variables, indicating the first and second return values of the ops.oids.subscribe API, respectively. Typically, return values can be displayed using the print statement in the debugging phase. This helps you view debugging information and locate faults.
    	# For OPS APIs, you can determine whether return values are required based on actual requirements. If return values are required, the number of return values must be specified based on the OPS API prototype. The meaning of return values varies depending on the OPS API. For details, see the corresponding OPS API.
    	# If the first return value of the ops.oids.subscribe API is a digit, 0 indicates that the API is successfully executed and 1 indicates that the API fails to be executed. The second return value is returned only when the first return value is 1. If the second value is a character string, the cause of the execution failure is described.
    	ret, desp = _ops.oids.subscribe("tempHigh", 'TEMP', 'Temperature High')
    	# Specify the return value of a function. The return value of a function can be used as the processing result.
    	# The return value of a function is used as the output of the function and can be assigned to other variables as the input of other functions.
    	# The return value of the function ops_condition is 0, indicating that this function is successfully executed.
    	return 0
    
    # Fixed statement for defining the execution processing function ops_execute. This function is invoked when the script event is executed and is used to execute the action. It is scheduled and executed by the built-in framework script _frame.py of the device.
    # The input parameter of the function ops_execute is the OPS object created in _frame.py. You can perform data access under this object.
    def ops_execute(ops):
    	# The current phase is the execution phase. You need to use the OPS APIs obtaining environment variable and writing back event execution result to OIDS supported by association between OIDS and OPS and applicable to the execution phase. The following uses writing back event execution result to OIDS as an example.
    	# Use the ops.oids.result API to write back the result to OIDS.
    	# The ret and errDesp are user-defined script variables, indicating the first and second return values of the ops.oids.result API, respectively. Typically, return values can be displayed using the print statement in the debugging phase. This helps you view debugging information and locate faults.
    	# For OPS APIs, you can determine whether return values are required based on actual requirements. If return values are required, the number of return values must be specified based on the OPS API prototype. The meaning of return values varies depending on the OPS API. For details, see the corresponding OPS API.
    	# If the first return value of the ops.oids.result API is a digit, 0 indicates that the API is successfully executed and 1 indicates that the API fails to be executed. The second return value is returned only when the first return value is 1. If the second value is a character string, the cause of the execution failure is described.
    	ret, errDesp = _ops.oids.result(False, "The temperature of the device is too high!")
    	# Specify the return value of a function. The return value of a function can be used as the processing result.
    	# The return value of a function is used as the output of the function and can be assigned to other variables as the input of other functions.
    	# The return value of the function ops.oids.result is 0, indicating that this function is successfully executed.
    	return 0
    • A Python script involves three parts: importing the Python module, ops_condition(ops) subscription function, and ops_execute(ops) execution function.

    • No matter whether OPS APIs used in a Python script are successfully executed, corresponding logs are recorded on the device. For details about corresponding logs, see OPSA in S7700 and S9700 V200R013C00 Log Reference.

  3. Save the Python script.
Translation
Download
Updated: 2019-04-20

Document ID: EDOC1100065738

Views: 39881

Downloads: 37

Average rating:
This Document Applies to these Products
Related Documents
Related Version
Share
Previous Next