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

S9300, S9300E, and S9300X V200R012C00

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).
Example for Using the User-defined Environment Variable to Monitor Card Status Change

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

Networking Requirements

As shown in Figure 6-5, the user manages the switch through a remote network. The user wants to detect the change in time and record logs when the card in the specified slot restarts.

Figure 6-5  Networking for monitoring card status change

Configuration Roadmap

The configuration roadmap is as follows:
  1. Configure the IP address of the interface as the management IP address of the switch.

  2. Make a Python script slot_syslog.py to monitor whether the card is restarted and record logs.

  3. Log in to the switch remotely using the IP address 10.2.1.1/24, upload the Python script to the switch, and install the script.

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

  5. Configure a Python script assistant.

Procedure

  1. Configure the IP address of the interface as the management IP address of the switch.

    # Configure a VLAN and add the interface to the VLAN.

    <Quidway> system-view
    [Quidway] sysname Switch
    [Switch] vlan batch 10
    [Switch] interface gigabitethernet 1/0/1
    [Switch-GigabitEthernet1/0/1] port link-type trunk
    [Switch-GigabitEthernet1/0/1] port trunk allow-pass vlan 10
    [Switch-GigabitEthernet1/0/1] quit

    # Configure the IP address of the interface.

    [Switch] interface vlanif 10
    [Switch-Vlanif10] ip address 10.2.1.1 24
    [Switch-Vlanif10] quit
    [Switch] quit

  2. Make a Python script.

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

    • Specify the slot ID of the card.

  3. Upload and install the Python script.

    # Log in to the switch remotely using the IP address 10.2.1.1/24 and upload the Python script from the PC to the switch. For details about how to upload a file, see File Management in S9300, S9300E, and S9300X V200R012C00 Configuration Guide - Basic Configuration.

    # Install the Python script on the switch.

    <Switch> ops install file slot_syslog.py

  4. Configure a user-defined environment variable.

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

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

  5. 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

  6. Verify the configuration.

    # Enable the log function. When the user-defined environment variable slotid is set to 2 and the card in slot 2 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

    #
    sysname Switch
    #
    vlan batch 10
    #
    interface Vlanif10
     ip address 10.2.1.1 255.255.255.0
    #
    interface GigabitEthernet1/0/1
     port link-type trunk
     port trunk allow-pass vlan 10
    #
    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 card 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: 2018-09-03

Document ID: EDOC1100038289

Views: 38353

Downloads: 15

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