Python自動(dòng)巡檢H3C交換機(jī)實(shí)現(xiàn)過程解析
1.通過netmiko模塊登錄交換機(jī),協(xié)議ssh,執(zhí)行收集信息命令,保存至txt文件
2.過濾txt文件中的內(nèi)容,保存到excel,使用xlwt模塊實(shí)現(xiàn)。
3.sendmai發(fā)送excel郵件。或者發(fā)送給釘釘機(jī)器人也可以
4.使用crond定時(shí)發(fā)送巡檢報(bào)表。
代碼如下
#!/usr/bin/python3 #H3c交換機(jī)import timefrom netmiko import ConnectHandlernow = 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()
以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. JavaScript實(shí)現(xiàn)簡單的彈窗效果2. Java commons-httpclient如果實(shí)現(xiàn)get及post請(qǐng)求3. javascript實(shí)現(xiàn)貪吃蛇小練習(xí)4. 我所理解的JavaScript中的this指向5. Vue 實(shí)現(xiàn)對(duì)quill-editor組件中的工具欄添加title6. PHP驗(yàn)證碼工具-Securimage7. PHP單件模式和命令鏈模式的基礎(chǔ)知識(shí)8. 一文帶你徹底理解Java序列化和反序列化9. PHP利用curl發(fā)送HTTP請(qǐng)求的實(shí)例代碼10. js實(shí)現(xiàn)碰撞檢測

網(wǎng)公網(wǎng)安備