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

S2720, S5700, and S6720 V200R013C00

This document describes the configurations of Device Management, including device status query, hardware management, Stack, SVF, cloud-based management, PoE, monitoring interface, OPS, 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).
Example for Using the User-defined Environment Variable to Monitor Stack Status Change

Example for Using the User-defined Environment Variable to Monitor Stack Status Change

Networking Requirements

As shown in Figure 8-5, the user remotely manages the stack through a network. The user wants to detect the change in time and record logs when the specified member switch in the stack restarts.

Figure 8-5  Networking for monitoring stack status change

Configuration Roadmap

  1. Configure the IP address of VLANIF 10 on the master switch in a stack to the management IP address of the stack.

  2. Make a Python script slot_syslog.py to monitor whether member switches in the stack are restarted and record logs.

  3. Log in to the switch remotely, upload the Python script to the switch, and install the script.

  4. Configure a user-defined environment variable and specify the stack ID of the member switch to be monitored. Using the user-defined environment variable, the user can switch the member switch to be monitored without rewriting the Python script.

  5. Configure a Python script assistant.

Procedure

  1. Make a Python script.

    # Make a Python script slot_syslog.py to implement the following functions:
    • Subscribe to the event of stack status change, monitor whether member switches in the stack are restarted, and record logs when a member switch or card is restarted.

    • Specify the stack ID of the member switch.

  2. Upload and install the Python script.

    # Log in to the switch remotely and upload the Python script from the PC to the switch. For details about how to upload a file, see File Management in S2720, S5700, and S6720 V200R013C00 Configuration Guide - Basic Configuration.

    # Install the Python script on the switch.

    <Switch> ops install file slot_syslog.py

  3. Configure a user-defined environment variable.

    # Configure the user-defined environment variable slotid and specify the stack ID of the member switch to be monitored. You can switch the member switch without rewriting the Python script. For example, to monitor SwitchB, set slotid to 2. When the monitored member switch is changed to SwitchC, set slotid to 3. The following uses the slotid set to 2.

    <Switch> system-view
    [Switch] ops
    [Switch-ops] environment slotid 2

  4. Configure a Python script assistant.

    # Configure a Python script assistant and register the subscription event in the script slot_syslog.py. Wait for the event to be triggered.

    [Switch-ops] script-assistant python slot_syslog.py
    [Switch-ops] quit

  5. Verify the configuration.

    # Enable the log function. When the user-defined environment variable slotid is set to 2 and SwitchB is restarted, the switch generates logs.

    [Switch] info-center enable
    [Switch] quit
    <Switch> terminal monitor
    <Switch> terminal logging
    <Switch>
    Apr 08 2018 14:29:17+08:00 Switch %%01OPSA/6/SCRIPT_LOG: OPS: Slot 2 has been reset. (user="slot_syslog.py", session=864036019).

Configuration Files and Scripts

  • Configuration file of the switch

    #
    ops
     script-assistant python slot_syslog.py
     environment slotid 2
    #
    return
  • Example of the script slot_syslog.py

    # -*- coding: utf-8 -*-
    import ops         # Import the OPS module.
    import sys         # Import the sys module.
    import os          # Import the OS module.
    # Subscription processing function
    def ops_condition (ops):
    	# Obtain the value of the user-defined environment variable slotid.
    	slotid, errstr = ops.environment.get("slotid")
    	# Monitor the event of restarting the member switch in the specified slot.
    	slot = "slot " + slotid
    	value1, err_str1 = ops.device.subscribe("a12", slot, "RESET")
    	return 0
    # Work processing function
    def ops_execute (ops):
    	# Obtain the value of the user-defined environment variable slotid.
    	slotid, errstr = ops.environment.get("slotid")
    	slot = "slot " + slotid
    	logstring = "Slot %s has been reset." %slotid
    	# Generate the user log Slot x has been reset.
    	status, err_log = ops.syslog(logstring, "informational", "syslog")
Translation
Download
Updated: 2019-04-20

Document ID: EDOC1100065674

Views: 34099

Downloads: 287

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