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

Example for Providing a Warning Message According to User Input

Networking Requirements

As shown in Figure 6-4, the user manages a switch through a remote 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 6-4  Networking for providing a warning message according to user input

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 riskwarning.py to display a warning message when a high-risk command needs to be executed.

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

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

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

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

    #
    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 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: 2018-09-03

Document ID: EDOC1100038289

Views: 39166

Downloads: 15

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