Network equipment information acquisition method and device and electronic equipment

By obtaining the device identification of the network device and determining the target data rule template based on the setting mapping rules, the problem of long adaptation cycle and complicated operation in the existing methods is solved, and rapid adaptation and efficient operation and maintenance are achieved, reducing labor costs.

CN119545151APending Publication Date: 2025-02-28SHENHUA HOLLYSYS INFORMATION TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411509358.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-28
Publication Date
2025-02-28

AI Technical Summary

Technical Problem

The existing methods have too long adaptation cycles, cumbersome operations, high labor costs and low operation and maintenance efficiency when collecting network equipment information.

Method used

By acquiring the device identification of the network device, determining the target data rule template associated with the device identification based on the setting mapping rules, and then collecting the device information of the network device based on the template. The method includes parsing the target data rule template, logging in to a network device, sending information acquisition commands, and receiving and extracting command execution results to obtain device information.

Benefits of technology

It realizes the rapid completion of network equipment adaptation, avoids the need to increase or modify code, improves operation and maintenance efficiency, reduces labor costs, and the data rule template is not related to the switch manufacturer, type, and model, greatly improving convenience and flexibility.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119545151A_ABST
    Figure CN119545151A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a network equipment information acquisition method and device and electronic equipment, and belongs to the technical field of computers. The method comprises the following steps: acquiring an equipment identifier of network equipment; determining a target data rule template associated with the device identifier based on a set mapping rule; the set mapping rule comprises data rule templates associated with different device identifiers; the target data rule template comprises a data acquisition rule of the network equipment corresponding to the equipment identifier; and collecting equipment information of the network equipment based on the target data rule template. According to the embodiment of the invention, the information acquisition of the network equipment (such as the switch) is realized based on the data rule template, the adaptation of the network equipment can be quickly completed, the process of acquiring the information acquisition of the switch is realized in a mode of avoiding adding or modifying codes, the operation and maintenance efficiency is improved, and the labor cost is reduced. And the data rule template in the embodiment of the invention is irrelevant to the manufacturer, the type and the model of the switch, so that the convenience and the flexibility are greatly improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a network device information collection method, a network device information collection device, an electronic device, a machine-readable storage medium and a computer program product. Background Art

[0002] For network access related products, it is usually necessary to add management to network devices and obtain device information from network devices (such as switches) to achieve terminal discovery, control, online management and other functions. However, with the diversity of switch manufacturers, types, and models (up to hundreds of types), the interfaces of various switches are not standardized. Therefore, in the network environment of different user sides, the process of obtaining switch information through SSH and TELNET usually requires specifying the switch manufacturer and model, and developing code adaptation according to the output format.

[0003] Due to the wide variety of corresponding switches, the executed commands and interfaces are not unified. Due to different switch manufacturers or types in different projects, it is necessary to add or modify the code one by one to adapt and implement the information collection process, and it is necessary to repeatedly package and upgrade and debug at the project site. The adaptation cycle is too long, the operation is cumbersome, the labor cost is high, and the operation and maintenance efficiency is low. Summary of the invention

[0004] The purpose of the embodiments of the present invention is to provide a network device information collection method, a network device information collection device, an electronic device, a machine-readable storage medium and a computer program product, so as to solve the defects of the existing methods in network device information collection, such as long adaptation period, cumbersome operation, high labor cost and low operation and maintenance efficiency.

[0005] In order to achieve the above object, an embodiment of the present invention provides a network device information collection method, including: Get the device ID of the network device; Determine the target data rule template associated with the device identification based on the set mapping rule; the set mapping rule includes data rule templates associated with different device identifications; the target data rule template includes a data acquisition rule for the network device corresponding to the device identification; The device information of the network device is collected based on the target data rule template.

[0006] Optionally, the collecting device information of the network device based on the target data rule template includes: Parsing the target data rule template and logging into the network device; Sending an information acquisition command to the network device based on the target data rule template; Receiving a command execution result of executing the information acquisition command sent by the network device; Extracting information from the command execution result based on the set data extraction command to obtain device information of the network device; The data acquisition rule includes the information acquisition command and the setting data extraction command.

[0007] Optionally, the data acquisition rule is constructed based on a regular expression.

[0008] Optionally, extracting information from the command execution result based on the set data extraction command to obtain device information of the network device includes: When the command execution result is in the form of a string, the command execution result is extracted based on a set regular expression to obtain the device information of the network device; when the command execution result is in the form of a data list with blank values, the command execution result is extracted based on the column header method to obtain the device information of the network device; and when the command execution result is in the form of a data list without blank values, the command execution result is extracted based on the column index method to obtain at least one of the device information of the network device.

[0009] Optionally, the device information of the network device includes at least one of a port table, a MAC address table, and an ARP table of a switch.

[0010] On the other hand, an embodiment of the present invention further provides a network device information collection device, including: An acquisition module, used to acquire a device identification of a network device; A determination module, configured to determine a target data rule template associated with the device identification based on a set mapping rule; the set mapping rule includes data rule templates associated with different device identifications; the target data rule template includes a data acquisition rule for a network device corresponding to the device identification; A collection module is used to collect device information of the network device based on the target data rule template.

[0011] Optionally, the collecting device information of the network device based on the target data rule template includes: Parsing the target data rule template and logging into the network device; Sending an information acquisition command to the network device based on the target data rule template; Receiving a command execution result of executing the information acquisition command sent by the network device; Extracting information from the command execution result based on the set data extraction command to obtain device information of the network device; The data acquisition rule includes the information acquisition command and the setting data extraction command.

[0012] Optionally, the data acquisition rule is constructed based on a regular expression.

[0013] Optionally, extracting information from the command execution result based on the set data extraction command to obtain device information of the network device includes: When the command execution result is in the form of a string, the command execution result is extracted based on a set regular expression to obtain the device information of the network device; when the command execution result is in the form of a data list with blank values, the command execution result is extracted based on the column header method to obtain the device information of the network device; and when the command execution result is in the form of a data list without blank values, the command execution result is extracted based on the column index method to obtain at least one of the device information of the network device.

[0014] Optionally, the device information of the network device includes at least one of a port table, a MAC address table, and an ARP table of a switch.

[0015] On the other hand, an embodiment of the present invention further provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the above-mentioned network device information collection method when executing the program.

[0016] On the other hand, an embodiment of the present invention further provides a machine-readable storage medium having a computer program stored thereon, and the computer program implements the above-mentioned network device information collection method when executed by a processor.

[0017] On the other hand, an embodiment of the present invention further provides a computer program product, including a computer program, and when the computer program is executed by a processor, the above-mentioned network device information collection method is implemented.

[0018] Through the above technical solution, the embodiment of the present invention determines the target data rule template associated with the device identifier based on the set mapping rule, and then collects the device information of the network device based on the target data rule template. The embodiment of the present invention realizes the information collection of network devices (such as switches) based on the data rule template, which can quickly complete the adaptation of network devices, and avoid the process of obtaining switch information collection by adding or modifying code, thereby improving operation and maintenance efficiency and reducing labor costs. In addition, the data rule template of the embodiment of the present invention is independent of the switch manufacturer, type, and model, which greatly improves convenience and flexibility.

[0019] Other features and advantages of the embodiments of the present invention will be described in detail in the subsequent detailed description. BRIEF DESCRIPTION OF THE DRAWINGS

[0020] The accompanying drawings are used to provide a further understanding of the embodiments of the present invention and constitute a part of the specification. Together with the following specific implementations, they are used to explain the embodiments of the present invention, but do not constitute a limitation on the embodiments of the present invention. In the accompanying drawings: Figure 1 This is one of the flow charts of the network device information collection method provided by the present invention; Figure 2 is a schematic diagram of a data rule template provided by the present invention; Figure 3 This is the second flow chart of the network device information collection method provided by the present invention; Figure 4 It is one of the schematic diagrams of the switch port information returned by the switch provided by the present invention; Figure 5 This is the second schematic diagram of the switch port information returned by the switch provided by the present invention; Figure 6 It is a schematic diagram of a MAC address table returned by the switch provided by the present invention; Figure 7 This is the third flow chart of the network device information collection method provided by the present invention; Figure 8 It is a structural schematic diagram of the network equipment information collection device provided by the present invention; Fig. 9 It is a structural schematic diagram of the electronic device provided by the present invention. DETAILED DESCRIPTION

[0021] The specific implementation of the embodiment of the present invention is described in detail below in conjunction with the accompanying drawings. It should be understood that the specific implementation described here is only used to illustrate and explain the embodiment of the present invention, and is not used to limit the embodiment of the present invention.

[0022] The following describes the technical terms "switch", "port", "SSH", "TELNET", "MAC address table", "ARP" and "JSON" that appear in the present invention.

[0023] switch A switch is a network device that is mainly used for forwarding electrical (optical) signals. It can provide an exclusive electrical signal path for any two network nodes connected to the switch. Switches play a vital role in computer networks. Whether in enterprise networks, campus networks or home networks, switches are indispensable equipment for building a stable and efficient communication environment.

[0024] Port (also called interface) A switch port is an interface in a network device used to connect network devices and transmit data. These ports have different types and functions to meet various network needs. In a logical sense, ports can be divided into several types, including: Access port: belongs to only one VLAN and is used to connect terminal devices such as computers.

[0025] Trunk port: allows multiple VLANs to pass through, is used as the interface between switches, and supports the reception and transmission of multiple VLAN messages.

[0026] Hybrid port: allows multiple VLANs to pass through, is used as an interface for switches or computers, and supports the reception and transmission of multiple VLAN messages.

[0027] SSH SSH is the abbreviation of Secure Shell, which was developed by the Network Working Group of IETF. SSH is a security protocol based on the application layer. SSH is a more reliable protocol designed to provide security for remote login sessions and other network services.

[0028] TELNET TELNET is a remote login protocol, a network protocol based on TCP / IP protocol, used to establish remote connections between computers.

[0029] MAC address table The MAC address table of a switch, also known as a forwarding table, is an important data structure used by the switch to forward frames. It records the correspondence between MAC addresses and ports, as well as information such as the VLAN to which the port belongs.

[0030] ARP The ARP protocol, or Address Resolution Protocol, is a network layer protocol that runs on each network node and is responsible for completing the mapping of the host IP address to the MAC address. It maintains the ARP table and caches the mapping relationship between the host's IP address (network address) and MAC address (physical address).

[0031] JSON JSON (JavaScript Object Notation) is an open standard, lightweight file format and data exchange format that is easy to read and write. Its concise and clear hierarchical structure can effectively improve network transmission efficiency.

[0032] There are several problems in the existing network device information collection method: 1. The software system function needs to periodically collect switch information. Therefore, due to different switch manufacturers or types in different projects, it is necessary to add or modify codes one by one to adapt and implement the information collection process, which results in high personnel investment costs; 2. The more types of switches that are compatible with the software system, the more types of management there are, and the code will be too redundant and bloated, so the cost of code maintenance is high.

[0033] 3. The collection process matches different collection processing programs according to the manufacturer and type. If the switches of the same manufacturer and the same type have inconsistent versions, sometimes there will be differences in the information collection process. Currently, there is a strong correlation and poor compatibility.

[0034] In view of this, the purpose of the embodiments of the present invention is to provide a network device information collection method, a network device information collection device, an electronic device, a machine-readable storage medium and a computer program product, so as to solve the defects of the existing methods in network device information collection, such as long adaptation cycle, cumbersome operation, high labor cost and low operation and maintenance efficiency.

[0035] Method Embodiment Please refer to Figure 1 , an embodiment of the present invention provides a network device information collection method, comprising: Step 100: Obtain a device identification of a network device.

[0036] The electronic device obtains a device identification of a network device. The network device may be a router, a switch, etc. The network device in the embodiment of the present invention is described by taking a switch as an example. The device identification may be various identifications that uniquely characterize the switch. For example, the device identification may be an IP address of the switch, a device ID, etc. In the embodiment of the present invention, the device identification may be an IP address of the switch.

[0037] Step 200: Determine a target data rule template associated with the device identification based on a set mapping rule.

[0038] Wherein, the set mapping rule includes data rule templates associated with different device identifiers. For example, in the embodiment of the present invention, the technician can set up the interface in the electronic device in advance to determine the data rule templates corresponding to the IP addresses of different switches. For example, the IP address 0.0.0.1 of switch 1 corresponds to data rule template 1, and the IP address 0.0.0.2 of switch 2 corresponds to data rule template 2. The embodiment of the present invention determines the target data rule template associated with the device identifier based on the set mapping rule. The target data rule template includes a data acquisition rule for the network device corresponding to the device identifier. The device information of the network device acquired by the data acquisition rule includes at least one of the port table, MAC address table and ARP table of the switch. In one embodiment, the device information of the network device acquired by the data acquisition rule includes the port table, MAC address table and ARP table of the switch. The port table needs to collect the switch port name, port description, port VLAN, port type, port attributes, etc.; the MAC table needs to collect the switch port name, port VLAN, MAC address; the ARP table is generally general information, mainly IP address information and MAC address information.

[0039] In one embodiment, when the device information of the network device acquired by the data acquisition rule includes the port table, MAC address table and ARP table of the switch, the data rule template can be defined in JSON format, and the rule description is mainly based on three nodes: int_table (port information), mac_table (MAC address forwarding table), arp_table (ARP information). In one embodiment, the data rule template is as follows Figure 2 As shown. Figure 2 For the description of the port table node rules, see Table 1.

[0040] Table 1

[0041] Among them, Figure 2 For a description of the MAC address table node rules, see Table 2.

[0042] Table 2

[0043] Among them, Figure 2 For the description of the ARP table node rules, see Table 3.

[0044] Table 3

[0045] Step 300: Collect device information of the network device based on the target data rule template.

[0046] The electronic device collects the device information of the network device based on the target data rule template. In one embodiment, the specific processing process is to log in to the switch through the data collection service according to the pre-defined target data rule template, send commands to obtain information (port table, MAC table, ARP table) one by one, match the data rules according to the command execution results, and extract the values ​​of the corresponding nodes, thereby completing the entire information collection process. The data collection service is a parsing engine service based on the data rule template of the switch. Its main functions are to log in to the switch, issue commands and receive the returned result information, and to match and extract data based on the returned information, and to realize the information acquisition process according to the defined rules.

[0047] The embodiment of the present invention determines the target data rule template associated with the device identifier based on the set mapping rule, and then collects the device information of the network device based on the target data rule template. The embodiment of the present invention realizes the information collection of network devices (such as switches) based on the data rule template, which can quickly complete the adaptation of network devices and avoid the process of obtaining switch information collection by adding or modifying codes, thereby improving operation and maintenance efficiency and reducing labor costs. In addition, the data rule template of the embodiment of the present invention is independent of the switch manufacturer, type, and model, which greatly improves convenience and flexibility.

[0048] In other aspects of the embodiments of the present invention, step 300, collecting device information of the network device based on the target data rule template, includes: Step 310: parse the target data rule template and log in to the network device.

[0049] Step 320: Send an information acquisition command to the network device based on the target data rule template.

[0050] Step 330: Receive a command execution result of executing the information acquisition command sent by the network device.

[0051] Step 340: extract information from the command execution result based on the set data extraction command to obtain device information of the network device.

[0052] Please refer to Figure 3, the electronic device performs the step of parsing the target data rule template when acquiring the target data rule template. When the electronic device has a parsing error, the switch information acquisition is terminated; when the parsing is correct, the step of logging into the switch is performed. The data acquisition rule in the target data rule template includes the information acquisition command and the setting data extraction command. The electronic device sends the information acquisition command in the data acquisition rule to the switch, that is, the electronic device sends the information acquisition command to the switch, and the switch performs switch information acquisition based on the information acquisition command and returns the switch information to the electronic device. The switch information may include at least one of a port table, a MAC table, and an ARP table. In one embodiment, the switch information includes a port table, a MAC table, and an ARP table. The electronic device parses the switch information to obtain the port table, the MAC table, and the ARP table. The electronic device then extracts information from the command execution result based on the setting data extraction command to obtain the port table, the MAC table, and the ARP table of the switch. Subsequently, the port table, the MAC table, and the ARP table of the switch are written into a data storage device.

[0053] The data acquisition rules of the target data rule template in the embodiment of the present invention include the information acquisition command and the setting data extraction command. The target data rule template in the embodiment of the present invention can support multiple command configurations. For example Figure 2 The "cmds" of "int_table" includes multiple commands, the "cmds" of "mac_table" includes multiple commands, and the "cmds" of "arp_table" includes multiple commands. For example, the port information acquisition process usually requires multiple commands (usually 2) to obtain the complete information of a switch port, so the acquisition process will send command information in sequence according to the content defined by the current port rule, associate them through the port name, and summarize the execution results of multiple commands into a complete information and write it into the data storage.

[0054] In addition, the data acquisition rules of the embodiment of the present invention are constructed based on regular expressions. The data rule template of the embodiment of the present invention is suitable for obtaining the port table, MAC address table, and ARP table information of the switch, and the data rule template is defined in JSON format. Each rule in the data rule template can support regular expression parsing data, which is simple and clear, flexible in configuration, and supports extensibility. Other information can be obtained according to needs, as long as the implementation can support this custom field information parsing, so as to meet more functional needs of the software system.

[0055] In other aspects of the embodiment of the present invention, step 340, extracting information from the command execution result based on the setting data extraction command to obtain device information of the network device, includes: When the command execution result is in the form of a string, the command execution result is extracted based on a set regular expression to obtain the device information of the network device; when the command execution result is in the form of a data list with blank values, the command execution result is extracted based on the column header method to obtain the device information of the network device; and when the command execution result is in the form of a data list without blank values, the command execution result is extracted based on the column index method to obtain at least one of the device information of the network device.

[0056] The data extraction process of the embodiment of the present invention can support matching of character strings in a regular manner, and can also obtain the value of the column according to the display format of the data list, thereby realizing the entire information collection process.

[0057] For example, see Figure 4 , when the returned data is in the form of a string of data. The string data has an obvious start mark or end mark (such as the acquisition of switch port information, the start mark is interface and the end mark is !). For this data format, "cmd_type" can be configured as "by_str" (see Figure 2 The rule configuration of show running-config in the data rule template). That is, by setting a regular expression to extract the command execution result, the switch port information of the network device is obtained. For example, in one embodiment, the following regular expression can be used to realize the collection of switch port information: \b(?:GigabitEthernet|FastEthernet)([0-9]\ / [0-9]+)\b.

[0058] Among them, \b: indicates a word boundary, ensuring that we match the complete port name and not part of other text. (?:GigabitEthernet|FastEthernet): is a non-capturing group used to match GigabitEthernet or FastEthernet strings. ([0-9]\ / [0-9]+): is a capturing group used to match the port number. Here it is assumed that the port number consists of two numbers separated by a slash ( / ). The first number may be one or more digits, but the second number is at least one digit. \b: again indicates a word boundary.

[0059] For another example, please refer to Figure 5 , when the returned data is in the form of a data list with blank values, this method uses the column header field (such as Figure 5The header fields are Port, Name, Status, Vlan, Duplex, Speed, and Type. The start and end positions are calculated, and the actual data and the list headers are aligned to avoid data confusion caused by empty strings during the line-by-line reading process (such as Figure 5 The value corresponding to Name is an empty string). This data format can configure "cmd_type" to "by_list_title" (see Figure 2 The rule configuration of show int status in the data rule template). That is, the command execution result is extracted by column heading to obtain the port information of the switch.

[0060] For another example, see Figure 6 , when the returned data is in the form of a data list without blank values, this method corresponds to the case where the target value does not have a blank value. The target value can be directly extracted according to the column index method. This data format can configure "cmd_type" to "by_list_index" (see Figure 2 The rule configuration of show mac address-table in the data rule template). That is, the command execution result is extracted by column index to obtain the MAC address table information of the switch.

[0061] Therefore, the embodiment of the present invention can parse the value returned by the switch in paragraph string or list mode (by column title, by column index), which is highly flexible.

[0062] In summary, please refer to Figure 7In the embodiment of the present invention, the technician configures and sets mapping rules in the interface of the electronic device in advance, obtains data rule templates associated with different device identifiers and writes them into the data storage device for data storage. After the storage is successful, the target data rule template associated with the device identifier of the switch is determined from the data storage device based on the set mapping rules. When the target data rule template is obtained, the electronic device performs the step of parsing the target data rule template. When the electronic device has a parsing error, the switch information collection ends; when the parsing is correct, the step of logging into the switch is performed. The data acquisition rule in the target data rule template includes the information acquisition command and the set data extraction command. The electronic device sends the information acquisition command in the data acquisition rule to the switch, that is, the electronic device sends the information acquisition command to the switch, and the switch performs switch information acquisition based on the information acquisition command and returns the switch information to the electronic device. In one embodiment, the switch information includes a port table, a MAC table and an ARP table. The electronic device parses the switch information to obtain the port table, the MAC table and the ARP table. The electronic device then extracts information from the command execution result based on the set data extraction command to obtain the port table, the MAC table and the ARP table of the switch. Subsequently, the port table, the MAC table and the ARP table of the switch are written into the data storage device. Finally, the switch's port table, MAC table and ARP table are read from the data storage device for interface display.

[0063] The data rule templates of the embodiment of the present invention are described below through several example templates.

[0064] Template 1: { "int_table": { "cmds": [ { "cmd": "display current-configuration", "cmd_end": "]", "cmd_type": "by_str", "reg_port": "interface (.+)", "reg_vlan": "port access vlan (.+)", "reg_trunk": "port link-type (.+)|port (.+) permit vlan|port (.+)vlan", "reg_trunkflag": "trunk" }, { "cmd": "display interface brief", "cmd_end": "]", "cmd_type": "by_list_index", "reg_port": "1", "reg_up": "2", "reg_desc": "7" } }, "mac_table": { "cmds": { "cmd": "display mac-address", "cmd_end": "]", "cmd_type": "by_list_index", "reg_mac": "1", "reg_vlan": "2", "reg_port": "4" } }, "arp_table": { "cmds": { "cmd": "display arp", "cmd_end": "]", "cmd_type": "by_list_index", "reg_ip": "1", "reg_mac": "2" } } } Template 2: { "int_table": { "cmds": { "cmd": "show running-config", "cmd_end": "#", ​​​"cmd_type": "by_str", "reg_port": "interface (.+)", "reg_portvalid": "Fa.+ / |Gi.+ / ", "reg_desc": "description (.+)", "reg_vlan": "switchport access vlan (.+)", "reg_trunk": "switchport mode (.+)", "reg_trunkflag": "trunk", "reg_nextnode": "!|end" }, { "cmd": "show int status", "cmd_end": "#", "cmd_type": "by_list_title", "reg_port": "Port", "reg_portvalid": "Fa.+ / |Gi.+ / ", "reg_up": "Status", "reg_upflag": "connected" } ] }, "mac_table": { "cmds": [ { "cmd": "show mac address-table", "cmd_end": "#", "cmd_type": "by_list_index", "reg_mac": "2", "reg_vlan": "1", "reg_port": "4" } ] }, "arp_table": { "cmds": { "cmd": "show arp", "cmd_end": "#", "cmd_type": "by_list_index", "reg_ip": "2", "reg_mac": "4" } } } Template 3: { "int_table": { "cmds": { "cmd": "display current-configuration", "cmd_end": "]", "cmd_type": "by_str", "reg_port": "interface (.+)", "reg_vlan": "port access vlan (.+)", "reg_trunk": "port link-type (.+)|port (.+) permit vlan|port (.+)vlan", "reg_trunkflag": "trunk" }, { "cmd": "display interface brief", "cmd_end": "]", "cmd_type": "by_list_index", "reg_port": "1", "reg_up": "2", "reg_desc": "7" } }, "mac_table": { "cmds": { ​​"cmd": "display mac-address", "cmd_end": "]", "cmd_type": "by_list_index", "reg_mac": "1", "reg_vlan": "2", "reg_port": "4" } ] }, "arp_table": { "cmds": [ { "cmd": "display arp", "cmd_end": "]", "cmd_type": "by_list_index", "reg_ip": "1", "reg_mac": "2" } ] } } The embodiment of the present invention can realize switch information collection based on a universal data rule template. Under the same rule parsing engine, there is no need to add or modify code. It only needs to redefine the configuration data rule template in the electronic device interface and associate it with the switch through the device identifier (IP address, etc.), so as to quickly complete the adaptation collection of switch information. If there is a difference from the expected result, the result output can be reviewed by adjusting the data rule template. The operation is simple, convenient and flexible.

[0065] In other words, the main technical idea of ​​the embodiment of the present invention is to achieve the purpose of obtaining switch information by defining a data rule template based on switch information collection and implementing a matching parsing engine (i.e., data collection service) therewith, thereby reducing the adaptation cost and maintenance cost of R&D in the process of participation. The commands and return results corresponding to different switches for obtaining information may be different. The adaptation process can be quickly completed by referring to the data rule template for modification or minor adjustments. This idea or method can be extended to other information acquisition (except port table, MAC address table, ARP table), and can also be applied to other network devices (such as routers), so as to meet more functional requirements of the software system.

[0066] Device Embodiment Please refer to Figure 8On the other hand, an embodiment of the present invention further provides a network device information collection device, comprising: The acquisition module 801 is used to acquire the device identification of the network device; Determination module 802, used to determine the target data rule template associated with the device identification based on the set mapping rule; the set mapping rule includes data rule templates associated with different device identifications; the target data rule template includes a data acquisition rule for the network device corresponding to the device identification; The collection module 803 is used to collect the device information of the network device based on the target data rule template.

[0067] The embodiment of the present invention determines the target data rule template associated with the device identifier based on the set mapping rule, and then collects the device information of the network device based on the target data rule template. The embodiment of the present invention realizes the information collection of network devices (such as switches) based on the data rule template, which can quickly complete the adaptation of network devices and avoid the process of obtaining switch information collection by adding or modifying codes, thereby improving operation and maintenance efficiency and reducing labor costs. In addition, the data rule template of the embodiment of the present invention is independent of the switch manufacturer, type, and model, which greatly improves convenience and flexibility.

[0068] Optionally, the collecting device information of the network device based on the target data rule template includes: Parsing the target data rule template and logging into the network device; Sending an information acquisition command to the network device based on the target data rule template; Receiving a command execution result of executing the information acquisition command sent by the network device; Extracting information from the command execution result based on the set data extraction command to obtain device information of the network device; The data acquisition rule includes the information acquisition command and the setting data extraction command.

[0069] Optionally, the data acquisition rule is constructed based on a regular expression.

[0070] Optionally, extracting information from the command execution result based on the set data extraction command to obtain device information of the network device includes: When the command execution result is in the form of a string, the command execution result is extracted based on a set regular expression to obtain the device information of the network device; when the command execution result is in the form of a data list with blank values, the command execution result is extracted based on the column header method to obtain the device information of the network device; and when the command execution result is in the form of a data list without blank values, the command execution result is extracted based on the column index method to obtain at least one of the device information of the network device.

[0071] Optionally, the device information of the network device includes at least one of a port table, a MAC address table, and an ARP table of a switch.

[0072] The network device information collection device includes a processor and a memory. The acquisition module 801, the determination module 802 and the collection module 803 are all stored in the memory as program units. The processor executes the program units stored in the memory to implement corresponding functions.

[0073] The processor includes a kernel, which calls the corresponding program unit from the memory. There can be one or more kernels.

[0074] The memory may include non-permanent memory in a computer-readable medium, random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM, and the memory includes at least one memory chip.

[0075] Fig. 9 An example of a physical structure diagram of an electronic device is shown in FIG. Fig. 9 As shown, the electronic device may include: a processor 910, a communication interface 920, a memory 930 and a communication bus 940, wherein the processor 910, the communication interface 920 and the memory 930 communicate with each other through the communication bus 940. The processor 910 may call the logic instructions in the memory 930 to execute the network device information collection method, which includes: obtaining the device identification of the network device; determining the target data rule template associated with the device identification based on the set mapping rule; the set mapping rule includes data rule templates associated with different device identifications; the target data rule template includes the data acquisition rule of the network device corresponding to the device identification; and collecting the device information of the network device based on the target data rule template.

[0076] In addition, the logic instructions in the above-mentioned memory 930 can be implemented in the form of a software functional unit and can be stored in a computer-readable storage medium when it is sold or used as an independent product. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk and other media that can store program codes.

[0077] On the other hand, the present invention also provides a computer program product, which includes a computer program. The computer program can be stored on a machine-readable storage medium. When the computer program is executed by a processor, the computer can execute a network device information collection method, which includes: obtaining a device identification of the network device; determining a target data rule template associated with the device identification based on a set mapping rule; the set mapping rule includes a data rule template associated with different device identifications; the target data rule template includes a data acquisition rule for the network device corresponding to the device identification; and collecting the device information of the network device based on the target data rule template.

[0078] On the other hand, the present invention also provides a machine-readable storage medium having a computer program stored thereon, which, when executed by a processor, is implemented to perform a network device information collection method, the method comprising: obtaining a device identification of the network device; determining a target data rule template associated with the device identification based on a set mapping rule; the set mapping rule includes data rule templates associated with different device identifications; the target data rule template includes a data acquisition rule for the network device corresponding to the device identification; and collecting the device information of the network device based on the target data rule template.

[0079] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.

[0080] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.

[0081] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. A method for collecting network device information, characterized in that: include: Get the device ID of the network device; Determine a target data rule template associated with the device identification based on a set mapping rule; The set mapping rule includes data rule templates associated with different device identifiers; the target data rule template includes data acquisition rules for network devices corresponding to the device identifiers; The device information of the network device is collected based on the target data rule template.

2. The network device information collection method according to claim 1, characterized in that: The collecting the device information of the network device based on the target data rule template includes: Parsing the target data rule template and logging into the network device; Sending an information acquisition command to the network device based on the target data rule template; Receiving a command execution result of executing the information acquisition command sent by the network device; Extracting information from the command execution result based on the set data extraction command to obtain device information of the network device; The data acquisition rule includes the information acquisition command and the setting data extraction command.

3. The network device information collection method according to claim 1 or 2, characterized in that: The data acquisition rules are constructed based on regular expressions.

4. The network device information collection method according to claim 2, characterized in that: The extracting information from the command execution result based on the set data extraction command to obtain the device information of the network device includes: When the command execution result is in the form of a string, the command execution result is extracted based on a set regular expression to obtain the device information of the network device; when the command execution result is in the form of a data list with blank values, the command execution result is extracted based on the column header method to obtain the device information of the network device; and when the command execution result is in the form of a data list without blank values, the command execution result is extracted based on the column index method to obtain at least one of the device information of the network device.

5. The network device information collection method according to claim 4, characterized in that: The device information of the network device includes at least one of a port table, a MAC address table, and an ARP table of a switch.

6. A network equipment information collection device, characterized in that: include: An acquisition module, used to acquire a device identification of a network device; A determination module, configured to determine a target data rule template associated with the device identification based on a set mapping rule; The set mapping rule includes data rule templates associated with different device identifiers; the target data rule template includes data acquisition rules for network devices corresponding to the device identifiers; A collection module is used to collect device information of the network device based on the target data rule template.

7. The network equipment information collection device according to claim 6, characterized in that: The collecting the device information of the network device based on the target data rule template includes: Parsing the target data rule template and logging into the network device; Sending an information acquisition command to the network device based on the target data rule template; Receiving a command execution result of executing the information acquisition command sent by the network device; Extracting information from the command execution result based on the set data extraction command to obtain device information of the network device; The data acquisition rule includes the information acquisition command and the setting data extraction command.

8. The network equipment information collection device according to claim 6 or 7, characterized in that: The data acquisition rules are constructed based on regular expressions.

9. The network equipment information collection device according to claim 7, characterized in that: The extracting information from the command execution result based on the set data extraction command to obtain the device information of the network device includes: When the command execution result is in the form of a string, the command execution result is extracted based on a set regular expression to obtain the device information of the network device; when the command execution result is in the form of a data list with blank values, the command execution result is extracted based on the column header method to obtain the device information of the network device; and when the command execution result is in the form of a data list without blank values, the command execution result is extracted based on the column index method to obtain at least one of the device information of the network device.

10. The network equipment information collection device according to claim 9, characterized in that: The device information of the network device includes at least one of a port table, a MAC address table, and an ARP table of a switch.

11. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the program, the network device information collection method described in any one of claims 1 to 5 is implemented.

12. A machine-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the network device information collection method according to any one of claims 1 to 5 is implemented.

13. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the network device information collection method according to any one of claims 1 to 5 is implemented.