Simple network inspection tool
Open source address:
GitHub: https://github.com/liuyuanchengweb/simple_network_inspection_tool
Gitee: https://gitee.com/useryc/simple_network_inspection_tool
generalize
This application implements a scalable network device information collection tool developed for delivery engineers who do not have corresponding network management equipment during delivery, or who do not have network management equipment for small and medium-sized network operation and maintenance and need to collect information in batches from switch equipment.
As this project is an open source project, everyone is welcome to pay more attention to it. Those who are capable can work together to maintain the project and fix bugs, and become a contributor in the open source community.
Function
Download import template
This function is mainly used to generate an excel file for the devices that need to be added in batches to fill in the corresponding information.
Batch import templates
This function mainly implements the import of the filled excel into the database, which is used to operate the equipment
Add new device
This function is mainly used to add a single device conveniently and quickly
test connection
It is mainly used to test whether the port of the device is connected normally
Start inspection
It is mainly used to start the device connection, execute the function in the plug-in template, and form an excel document according to the content returned by the function in the plug-in template after execution.
Backup configuration files
Mainly used to collect device configuration files, which are stored in txt format by default.
Query interface
Find a display among multiple devices
Editing interface
Mainly used to modify device information
Delete interface
Delete a device from the database
Application Notes
Tool architecture
The tool uses FastAPI as the back-end framework, and the front-end uses VUE3 to develop a completely separated front-end and back-end project.
device driver
The device type drivers are all netmiko drivers. The device type must be filled in with the device in the netmiko driver list. There is verification on the backend. When entering the device, the device type field and protocol field will be verified, which are enumeration types.
scalability
For the collected information that needs to be defined, functions can be written according to certain specifications, and the expansion of relevant information can be completed by returning the content.
For example, this Huawei template
Fixed writing method ------> Import the DataHandle class decorator, and import BaseConnection in netmiko as a type annotation, which can be convenient during writing. Functions that need to perform inspections are added to the all method. Backup configuration file functions need to be written in a fixed way. Function name.
After the import is complete, instantiate the DataHandle class decorator. Currently, the DataHandle class decorator implements two method decorators.
Backup_config is used as a decorator for saving txt configuration files. It needs to fix the return data and file name. Return data, file name -> data is used as the content written to the file, and the file name is used as the saved file name.
data is a decorator that collects information and saves it to excel. When developing a template function, you only need to use this decorator and return two fixed values, data and table. Data is the excel table data and table is the column. name
import re
from API.decorator import DataHandle
from netmiko import BaseConnection
data = DataHandle()
# 例如这个,在启动设备巡检时会自动执行__all__列表中的函数
__all__ = ['huawei_name', 'huawei_version', 'huawei_cpu']
# 备份配置文件的函数需要写固定函数名
# 以下例子,调用backup_config装饰器,函数名固定为backup_config(conn):
# 备份配置文件函数需要固定名称和固定参数。
@data.backup_config
def backup_config(conn: BaseConnection):
output = conn.send_command(command_string='display current-configuration')
file_names = re.search(r'sysname\s(.*)', output).group(1)
file_name = f'{
file_names}.txt'
data = output
return data, file_name
# 常规采集数据写法,调用data装饰器,函数固定参数conn,固定返回两个值,其余自由编写
@data.data
def huawei_cpu(conn: BaseConnection):
table = 'CPU'
output = conn.send_command(command_string='display cpu-usage')
data = re.search(r'CPU Usage\s+:\s([0-9]{1,3}%)', output).group(1)
return data, table
application deployment
environment
Python 3.10 or higher
Deploy a test virtual machine to Windows 10
Deployment command
# 查看自己环境的python版本
C:\Users\ycll>python -v
# 3.10以上
# 更新pip
C:\Users\ycll>python.exe -m pip install --upgrade pip
# 安装pipx
C:\Users\ycll>python -m pip install --user pipx -i https://pypi.tuna.tsinghua.edu.cn/simple
# pipx刷新到系统变量中
C:\Users\ycll>python -m pipx ensurepath
# 确认pipx安装是否正常
C:\Users\ycll>pipx --version
1.1.0
# 安装poetry会稍微有点慢
C:\Users\ycll>pipx install poetry -i https://pypi.tuna.tsinghua.edu.cn/simple
# 安装好确认安装正常
C:\Users\ycll>poetry -V
Poetry (version 1.4.0)
# 进入项目目录
C:\Users\ycll>cd C:\Users\ycll\Desktop\simple_network_inspection_tool_v0.2.0
# 安装依赖
C:\Users\ycll\Desktop\simple_network_inspection_tool_v0.2.0>poetry install
# 运行项目
poetry run run.py
Monitor port 18888 by default
After running, access 127.0.0.1:18888 as the front-end page
The interface document address is 127.0.0.1:18888/docs
Can be accessed locally or remotely
grateful
Front-end roommate
NetDevOps fellow travelers: Mr. Wang Yin, Mr. Jiujing, Diandi Technology, Mr. Zhu Jiasheng
And Netmiko open source project, FastAPI, and related open source projects
Open source license
Open source license follows the MIT Open Source Agreement