评分并提供意见反馈 :
华为采用机器翻译与人工审校相结合的方式将此文档翻译成不同语言,希望能帮助您更容易理解此文档的内容。 请注意:即使是最好的机器翻译,其准确度也不及专业翻译人员的水平。 华为对于翻译的准确性不承担任何责任,并建议您参考英文文档(已提供链接)。
配置自动检查设备健康状态示例(基于脚本维护助手)
通过配置脚本维护助手,可以自动检查设备的健康状态。
组网需求
如图6-2所示,远程服务器提供TFTP Server功能,DeviceA与TFTP Server之间路由可达。用户希望设备能够自动收集每天的健康状态信息,并将信息发送至TFTP Server以供分析,减少手工的维护工作量。
操作步骤
- 编辑Python脚本
# 编辑Python脚本,文件名为health.py。。
Python脚本中设置触发条件为定时器,并设置工作任务为执行命令行,收集设备的硬件状态、路由状态、接口链路状态等信息并将其发送至TFTP Server。Python脚本内容如下:# 定义触发条件的函数 def ops_condition(_ops): _ops.timer.cron("con1","0 1 * * * *") # 设置定时器事件 _ops.correlate("con1") # 定义工作任务的函数 def ops_execute(_ops): handle, err_desp = _ops.cli.open() # 打开命令行通道 _ops.cli.execute(handle,"display device > health.txt") # 执行命令行 _ops.cli.execute(handle,"display health >> health.txt") _ops.cli.execute(handle,"display ip routing-table >> health.txt") _ops.cli.execute(handle,"display lldp neighbor brief >> health.txt") _ops.cli.execute(handle,"tftp 10.2.1.1 put health.txt") ret = _ops.cli.close(handle) # 关闭命令行通道 return 0
- 上传Python脚本并安装
# DeviceA作为TFTP客户端从TFTP服务器下载脚本文件health.py(Python脚本存放在TFTP服务器上)。
<HUAWEI> system-view [~HUAWEI] sysname DeviceA [*HUAWEI] commit [~DeviceA] quit <DeviceA> tftp 10.2.1.1 get health.py Info: Transfer file in binary mode. Please wait for a while... / 635 bytes transferred Info: Downloaded the file successfully.
# 在DeviceA上安装Python脚本。
<DeviceA> ops install file health.py
- 配置脚本维护助手
<DeviceA> system-view [~DeviceA] ops [~DeviceA-ops] script-assistant python health.py [*DeviceA-ops] commit [~DeviceA-ops] return
- 检查配置结果
# 查看脚本维护助手配置。
<DeviceA> display ops assistant verbose name health.py Assistant information Name : health.py State : ready Type : script Default assistant : no Running statistics Running times : 0 Queue size/(free) : 10/(10) Skip for queue full : 0 Skip for delay : 0 Skip for suppression : 0 Skip for error : 0 Execute information Task abstract : health.py : ops_execute() Trigger control Occurs threshold : 1 Period (s) : 0 Delay (s) : 0 Suppress max : 0 Hits in period : 0 Condition information Correlate expression : con1 Condition tag : con1 Condition type : timer Subscribe result : success Occurs threshold : 0 Period (s) : 0 Hits in period : 0