标签:localtime oca dmi strftime imp send str h3c import
1.通过netmiko模块登录交换机,协议ssh,执行收集信息命令,保存至txt文件#!/usr/bin/python3
#H3c交换机
import time
from netmiko import ConnectHandler
now = time.strftime("%Y%m%d",time.localtime(time.time()))
log_time = time.strftime("%Y-%m-%d %H:%M:%S",time.localtime())
ip_list = [
[‘sw-001‘,‘192.168.1.1‘],
[‘sw-002‘,‘192.168.1.2‘],
]
SW = {
‘device_type‘:‘hp_comware‘,
‘username‘:‘admin‘,
‘ip‘:‘‘,
‘password‘:"$password"
}
for ip_item in ip_list:
SW[‘ip‘] = ip_item[1]
connect = ConnectHandler(**SW)
print(log_time + ‘Successfully connected to ‘ + ip_item[0])
output = connect.send_command(‘system view‘)
iproute = connect.send_command("display ip routing-table")
version = connect.send_command(‘dis version‘)
fan = connect.send_command(‘display fan‘)
cpu = connect.send_command(‘display cpu-usage‘)
mem = connect.send_command(‘display memory‘)
env = connect.send_command(‘display environment‘)
fo = open(‘xusj‘,‘w‘)
fo.write(iproute)
fo.write(fan)
fo.write(cpu)
fo.write(mem)
fo.write(env)
fo.close()
标签:localtime oca dmi strftime imp send str h3c import
原文地址:https://blog.51cto.com/xushaojie/2486217