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 Providing a Warning Message According to User Input

Example for Providing a Warning Message According to User Input

Networking Requirements

As shown in Figure 8-4, the user remotely manages a switch through a network and wants to add a warning message before high-risk commands are executed. The command is only executed after the user confirms the operation, reducing the risk of accidental execution of the command.

Figure 8-4  Networking for providing a warning message according to user input

Configuration Roadmap

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

  2. Make a Python script riskwarning.py to display a warning message when a high-risk command needs to be executed.

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

  4. Configure a Python script assistant.

Procedure

  1. Make a Python script.

    # Make a Python script riskwarning.py to implement the following functions:
    • Register the command line event to trigger a warning message when a high-risk command needs to be executed.

    • Determine whether to execute the high-risk command based on the user input.

  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 riskwarning.py

  3. Configure a Python script assistant.

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

    <Switch> system-view
    [Switch] ops
    [Switch-ops] script-assistant python riskwarning.py
    [Switch-ops] quit

  4. Verify the configuration.

    # After the preceding configurations are complete, run the specified command to check whether the system will display a warning message. The command specified in the current script is arp learning multicast enable and is executed in the system view.

    [Switch] arp learning multicast enable
    The device may be attacked by ARP attack packets with multicast MAC addresses. Are you sure to continue?[Y/N]:

    If you enter N, the arp learning multicast enable command is not executed. If you enter the display current-configuration | include arp command in any view, the command output does not display the arp learning multicast enable command.

    If you enter Y, the arp learning multicast enable command is executed. If you enter the display current-configuration | include arp command in any view, the command output displays the arp learning multicast enable command.

    NOTE:

    To view the information displayed by print statements in OPS scripts, log in to the switch through the serial port.

Configuration Files and Scripts

  • Configuration file of the switch

    #
    ops
     script-assistant python riskwarning.py
    #
    return
  • Example of the script riskwarning.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):
    	# Match the high-risk command arp learning multicast enable.
    	value, err_str = ops.cli.subscribe("cli1", "arp learning multicast enable", enter=True, sync=True, sync_wait=60)
    	return 0
    # Work processing function
    def ops_execute (ops):
    	# Obtain the system environment variable _cli_vty, indicating the user channel.
    	key, value = ops.environment.get("_cli_vty")
    	# Display a warning message for the high-risk command on the terminal.
    	a, b = ops.terminal.write("The device may be attacked by ARP attack packets with multicast MAC addresses. Are you sure to continue?[Y/N]:", vty=key)
    	print a
    	print b
    	# Read the user input in the interaction between terminals.
    	a, b = ops.terminal.read(maxLen=200, timeout=30, vty=key)
    	# If Y or y is entered, the system continues to executing the high-risk command arp learning multicast enable.
    	if a == "Y" or a == "y":
    		return 1
    	# If other values are entered, the system will not execute the high-risk command.
    	else:
    		return 0
Translation
Download
Updated: 2019-04-20

Document ID: EDOC1100065674

Views: 34097

Downloads: 287

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