18video性欧美19sex,欧美高清videosddfsexhd,性少妇videosexfreexxx片中国,激情五月激情综合五月看花,亚洲人成网77777色在线播放

0
  • 聊天消息
  • 系統(tǒng)消息
  • 評論與回復(fù)
登錄后你可以
  • 下載海量資料
  • 學(xué)習(xí)在線課程
  • 觀看技術(shù)視頻
  • 寫文章/發(fā)帖/加入社區(qū)
會員中心
創(chuàng)作中心

完善資料讓更多小伙伴認(rèn)識你,還能領(lǐng)取20積分哦,立即完善>

3天內(nèi)不再提示

Netmiko+excle定時(shí)檢測接口狀態(tài)

jf_yLA7iRus ? 來源:知乎楓嵐 ? 作者:知乎楓嵐 ? 2022-10-19 09:15 ? 次閱讀
加入交流群
微信小助手二維碼

掃碼添加小助手

加入工程師交流群

一、前言:在本人看著群里的大佬紛紛分享自己的文章和一些運(yùn)維思路,深知只有用出來,寫出來,分享出來,跟大家一起交流,這個程序和學(xué)習(xí)到的新知識才算真正掌握了。在這里非常感謝王印王老師@弈心、朱嘉盛老師@朱嘉盛以及群里的各位大佬不遺余力地分享著自己的文章。針對python的學(xué)習(xí)主要源于他們的專欄。

二、實(shí)驗(yàn)背景:

前一段時(shí)間,機(jī)房剛剛建完,但是弱電做的網(wǎng)線不太行,出現(xiàn)兩次網(wǎng)線問題,這不是要了命了么。領(lǐng)導(dǎo)說,想辦法如果交換機(jī)網(wǎng)線出問題了你得能知道。我想說,咱們用個運(yùn)維平臺不行嗎,我又想我們今年手里的服務(wù)器資源只剩下4核,6G了。
行,那就寫個腳本吧。本次實(shí)驗(yàn)以H3C設(shè)備為基礎(chǔ)。

就是說寫一個只要接口狀態(tài)發(fā)生變化就能有郵件通知你,而且還有excle作為佐證。

我認(rèn)為本次實(shí)驗(yàn)僅僅適用于十幾二十臺小環(huán)境的網(wǎng)絡(luò)。(而且有點(diǎn)錢上個平臺不比嘛強(qiáng))

三、需求分析

首先首次使用腳本之后,excle里工作表收集的都是當(dāng)前所有設(shè)備的UP的接口。

81f94692-4f45-11ed-a3b6-dac502259ad0.jpg

工作簿底下的工作表的是所有設(shè)備,以命名+IP的形式存在。

822ed49c-4f45-11ed-a3b6-dac502259ad0.jpg

工作簿底下是所有的設(shè)備

然后如果有一個接口的狀態(tài)出現(xiàn)了變化,只要有變化,Link這一列對應(yīng)的狀態(tài)就會變色,還會發(fā)郵件以工作簿為附件。

824087fa-4f45-11ed-a3b6-dac502259ad0.jpg

82770eec-4f45-11ed-a3b6-dac502259ad0.jpg

如果你是就想人為規(guī)劃斷開這個接口,不是鏈路的損壞,那么在下次執(zhí)行這個腳本的時(shí)候,不是UP接口就不存在了。

82a1a1e8-4f45-11ed-a3b6-dac502259ad0.jpg

如果這個接口從ADM狀態(tài)又回復(fù)為UP,那么也會發(fā)郵件,并且攜帶工作簿為附件。

82affcb6-4f45-11ed-a3b6-dac502259ad0.jpg

81f94692-4f45-11ed-a3b6-dac502259ad0.jpg

最后設(shè)置成1分鐘執(zhí)行一次,放在服務(wù)器里。

每次執(zhí)行程序只會維護(hù)第一次執(zhí)行程序輸出的這一張表,所以不用擔(dān)心文件太多。

三、代碼分析

3.1完整代碼

先上完整代碼,然后再進(jìn)行分析。

#coding=gbk
importre
importsmtplib
importthreading
importtime
fromemail.mime.applicationimportMIMEApplication
fromemail.mime.multipartimportMIMEMultipart
fromemail.mime.textimportMIMEText
frompprintimportpprint
fromqueueimportQueue

fromnetmikoimportConnectHandler
fromopenpyxl.reader.excelimportload_workbook
fromopenpyxl.workbookimportWorkbook
fromopenpyxl.stylesimportPatternFill,Border,Side,Font

threads=[]#用于多線程
ip_list=open('ip_file.txt')#IP地址先行放入文件中
dims={}#用于對工作表中自動設(shè)置最大行寬
content=""#用于輸出在郵箱中的內(nèi)容
defssh_seesion(ip,ouput,):
globalcontent,sheet
#這幾個列表是寫入工作表的先行條件,也就是工作表的每一列,先把想寫入工作表的每一列的內(nèi)容寫入列表,然后再遍歷列表把內(nèi)容寫入工作表
interface_list=[]
link_list=[]
speed_list=[]
description_list=[]

connection_info={'device_type':'hp_comware',
'ip':ip,
'username':'xxxxx',
'password':'xxxxxx'}

withConnectHandler(**connection_info)asconn:
output=conn.send_command("displayinterfacebrief",use_textfsm=True)
sysname=conn.send_command('displaycurrent-configuration|includesysname')
name=re.search(r's+S+s+(S+)',sysname).groups()[0]
#pprint(output)

try:
sheet=wb[name+'_'+ip]#調(diào)用自己的那一張表
#先給逼刪了
column_B=sheet['B']
foriincolumn_B:
#print(i.value)
ifi.valuenotin('Link','UP'):
num=re.search('d+',i.coordinate).group()#找到需要刪的那一行
print(num)
sheet.delete_rows(int(num))
except:
pass

#取出接口up的
foriinoutput:
ifi.get('link')=='UP':
interface_list.append(i.get('interface'))
link_list.append(i.get('link'))
speed_list.append(i.get('speed'))
description_list.append(i.get('description'))
#判斷這次interface跟上次也就是表格里的有沒有區(qū)別以是否是UP的為前提不是UP的或者多了UP的或者少了UP的只要變化就要被記錄


ifstr(name+'_'+ip)inwb.sheetnames:#如果這個表存在就讓里原本有的接口進(jìn)入列表
sheet_pre=wb[name+'_'+ip]
column_A=sheet_pre['A']#取出以前的表的第一列
sheet_pre_A1=[i.valueforiincolumn_A]
sheet_pre_A1.remove('Interfaces')#遍歷第一列的時(shí)候會有抬頭也就是Interfaces'需要把這個去掉
#print(sheet_pre_A1)#sheet_pre_A1里是上一次表格里有的接口列表
#print(interface_list)#interface_list里是這一次想放入表格里的UP的接口的列表
#取出兩個列表的差集,這個差集是現(xiàn)在UP的和表里的差集
sheet_dif=list(set(sheet_pre_A1)^(set(interface_list)))#把兩個表中變化的接口放入sheet_dif這個列表里
print(sheet_dif)#至此有變化的且不是UP的接口就進(jìn)入列表了
iflen(sheet_dif)!=0:#如果這個列表里有數(shù)據(jù)就發(fā)郵箱
content=content+f"{name}{str(sheet_dif)}接口發(fā)生了變化
'"#配合發(fā)郵件的

foriinoutput:#為了把差集的接口情況寫入列表
forpinsheet_dif:
ifp==i.get('interface')andi.get('link')!='UP':#找到這個不是UP的接口各種情況還寫進(jìn)去
interface_list.append(i.get('interface'))
link_list.append(i.get('link'))
speed_list.append(i.get('speed'))
description_list.append(i.get('description'))
content=content+i.get('interface')+'接口由UP變成了'+i.get('link')+'
'
elifp==i.get('interface')andi.get('link')=='UP':
content=content+i.get('interface')+'接口UP了'+'
'


font=Font(name="微軟雅黑",bold=True)#字體加粗
yellowFill=PatternFill(start_color='FFFF00',end_color='FFFF00',fill_type='solid')#黃色
thin_border=Border(left=Side(style='thin'),right=Side(style='thin'),top=Side(style='thin'),
bottom=Side(style='thin'))#有邊框
SpringGreen=PatternFill(start_color='3CB371',end_color='3CB371',fill_type='solid')#黃色

ifstr(name+'_'+ip)inwb.sheetnames:#如果表格存在直接往里寫
row_numbers=list(range(2,len(output)+2))#只能從第二行開始
forinterface,rowinzip(interface_list,row_numbers):
sheet.cell(row=row,column=1,value=interface)
forlink,rowinzip(link_list,row_numbers):
sheet.cell(row=row,column=2,value=link)
forspeed,rowinzip(speed_list,row_numbers):
sheet.cell(row=row,column=3,value=speed)
fordescription,rowinzip(description_list,row_numbers):
sheet.cell(row=row,column=4,value=description)

#往里寫完之后查看B1這列然后找到不是UP的給賦值綠色
column_B=sheet['B']
foriincolumn_B:
#print(i.value)
ifi.valuenotin('Link','UP'):
print(i.coordinate)#查找到接口有問題的坐標(biāo)
sheet[i.coordinate].fill=SpringGreen


else:#如果表格不存在則創(chuàng)建表格
sheet=wb.create_sheet(name+'_'+ip)#這里的sheet相當(dāng)于JT-6-1F-DAS-1這個表格
columns=['A1','B1','C1','D1']
cells=['Interfaces','Link','Speed','Description']
fori,pinzip(columns,cells):
#放入表格中
sheet[i]=p
sheet[i].fill=yellowFill
sheet[i].font=font

row_numbers=list(range(2,len(output)+2))#只能從第二行開始
forinterface,rowinzip(interface_list,row_numbers):
sheet.cell(row=row,column=1,value=interface)
forlink,rowinzip(link_list,row_numbers):
sheet.cell(row=row,column=2,value=link)
forspeed,rowinzip(speed_list,row_numbers):
sheet.cell(row=row,column=3,value=speed)
fordescription,rowinzip(description_list,row_numbers):
sheet.cell(row=row,column=4,value=description)


forrowinsheet.rows:
#print(row)
forcellinrow:
#print(cell.value)
cell.border=thin_border
ifcell.value:
dims[cell.column_letter]=max((dims.get(cell.column_letter,0),len(str(cell.value))))

forcol,valueindims.items():
sheet.column_dimensions[col].width=value+3


defsend_email(sender,receicer,password,content):
#這份代碼比較標(biāo)準(zhǔn)了,可以直接用了

#發(fā)件人郵箱
sender=sender
#收件人郵箱
receiver=receicer
#抄送人郵箱
#acc='xxxxxxxx@qq.com'
#郵件主題
subject='服務(wù)器運(yùn)行情況'

#郵箱密碼(授權(quán)碼)
password=password

#郵件設(shè)置
msg=MIMEMultipart()
msg['Subject']=subject#主題
msg['to']=receiver#接收者
#msg['acc']=acc#抄送者
msg['from']="信息化員工"#發(fā)件人

#郵件正文
content=content

#添加郵件正文:
msg.attach(MIMEText(content,'plain','utf-8'))#content是正文內(nèi)容,plain即格式為正文,utf-8是編碼格式

#添加附件
#注意這里的文件路徑是斜杠
file_name=r'E:python	est	est功能腳本接口up_down	est_openpyxl.xlsx'
file_name_list=file_name.split('\')[-1]#獲得文件的名字
xlsxpart=MIMEApplication(open(file_name,'rb').read())
xlsxpart.add_header('Content-Disposition','attachment',filename=file_name_list)
#服務(wù)端向客戶端游覽器發(fā)送文件時(shí),如果是瀏覽器支持的文件類型,一般會默認(rèn)使用瀏覽器打開,比如txt、jpg等,會直接在瀏覽器中顯示,如果需要提示用戶保存,就要利用Content-Disposition進(jìn)行一下處理,關(guān)鍵在于一定要加上attachment
msg.attach(xlsxpart)

#設(shè)置郵箱服務(wù)器地址以及端口
smtp_server="smtp.qq.com"
smtp=smtplib.SMTP(smtp_server,25)#'smtp.qq.com'是QQ郵箱發(fā)郵件的服務(wù)器,用新浪郵箱就是'smtp.sina.com',就是smtp加上你們郵箱賬號@符號后面的內(nèi)容。端口默認(rèn)是25。
#smtp.set_debuglevel(1)#顯示出交互信息

#登陸郵箱
smtp.login(sender,password)

#發(fā)送郵件
smtp.sendmail(sender,receiver.split(','),msg.as_string())
#receiver.split(',')+acc.split(',')是['xxxxxxxx@qq.com','xxxxxxxx@qq.com']

#斷開服務(wù)器鏈接
smtp.quit()

print(f"程序于{time.strftime('%X')}執(zhí)行開始
")
#記錄開始時(shí)間
start_time=time.time()

#注意邏輯關(guān)系先創(chuàng)建工作簿再進(jìn)入多線程最后保存工作簿
try:#如果存在這個表格就直接打開,如果部存在就創(chuàng)建
wb=load_workbook('test_openpyxl.xlsx')
ws=wb.active
except:#創(chuàng)建表格如果存在就不創(chuàng)建
wb=Workbook()
wb.remove(wb['Sheet'])
ws=wb.active

foripsinip_list.readlines():
t=threading.Thread(target=ssh_seesion,args=(ips.strip(),Queue()))
t.start()
threads.append(t)


foriinthreads:
i.join()
#加入檢查功能


iflen(content)!=0:
print(content)
send_email("xxxx@qq.com","xxxx@qq.com","jveyorpbogllijhj",content)


end_time=time.time()-start_time

wb.save('test_openpyxl.xlsx')#保存工作表
print(f'總共耗時(shí){round(end_time,2)}秒')
print(f"程序于{time.strftime('%X')}執(zhí)行結(jié)束
")
TestFSM模板
ValueInterface(S+)
ValueLink(UP|DOWN|ADM|Stby)
ValueSpeed(.*G|auto)
ValueDescription(S+|s+)

Start
^s*${Interface}s+${Link}s+${Speed}((a)|s*)+s+S+s+S+s+S+s+${Description}->Record

3.2分析

特別詳細(xì)的分析寫在了代碼的注釋中。這里只是對思路的分析。

首先就是登錄設(shè)備,然后調(diào)用TestFSM模板做解析,再取出設(shè)備的名字。use_textfsm=True的用法參照朱嘉盛:《網(wǎng)絡(luò)工程師的Python之路》(nornir實(shí)驗(yàn)10,聯(lián)動Textfsm,ntc-template,華為)

defssh_seesion(ip,ouput,):
globalcontent,sheet
#這幾個列表是寫入工作表的先行條件,也就是工作表的每一列,先把想寫入工作表的每一列的內(nèi)容寫入列表,然后再遍歷列表把內(nèi)容寫入工作表
interface_list=[]
link_list=[]
speed_list=[]
description_list=[]

connection_info={'device_type':'hp_comware',
'ip':ip,
'username':'xxxxxx',
'password':'123'}

withConnectHandler(**connection_info)asconn:
output=conn.send_command("displayinterfacebrief",use_textfsm=True)
sysname=conn.send_command('displaycurrent-configuration|includesysname')
name=re.search(r's+S+s+(S+)',sysname).groups()[0]
#pprint(output)

首先明確這個腳本是一分鐘執(zhí)行一次,然后是在工作簿中找到此次登錄的設(shè)備的工作表,然后對其進(jìn)行刪除操作,刪除工作表中存在的不是UP的接口的那一行,因?yàn)檫@個工作簿的目的是存接口為UP的接口的信息,那么之前存在不是UP的接口的內(nèi)個工作簿呢?通過郵箱發(fā)出來了。因?yàn)槿绻谝淮螆?zhí)行這個程序,那么肯定不存在這個表,所以用個try……except。

i.coordinate用來獲取一個格子的坐標(biāo)的。比如輸出結(jié)果就是B11這樣。

try:
sheet=wb[name+'_'+ip]#調(diào)用自己的那一張表
#先給逼刪了
column_B=sheet['B']
foriincolumn_B:
#print(i.value)
ifi.valuenotin('Link','UP'):
num=re.search('d+',i.coordinate).group()#找到需要刪的那一行
print(num)
sheet.delete_rows(int(num))
except:
passtry:
sheet=wb[name+'_'+ip]#調(diào)用自己的那一張表
#先給逼刪了
column_B=sheet['B']
foriincolumn_B:
#print(i.value)
ifi.valuenotin('Link','UP'):
num=re.search('d+',i.coordinate).group()#找到需要刪的那一行
print(num)
sheet.delete_rows(int(num))
except:
pass
defssh_seesion(ip,ouput,):
globalcontent,sheet
#這幾個列表是寫入工作表的先行條件,也就是工作表的每一列,先把想寫入工作表的每一列的內(nèi)容寫入列表,然后再遍歷列表把內(nèi)容寫入工作表
interface_list=[]
link_list=[]
speed_list=[]
description_list=[]

connection_info={'device_type':'hp_comware',
'ip':ip,
'username':'xxxxxx',
'password':'123'}

withConnectHandler(**connection_info)asconn:
output=conn.send_command("displayinterfacebrief",use_textfsm=True)
sysname=conn.send_command('displaycurrent-configuration|includesysname')
name=re.search(r's+S+s+(S+)',sysname).groups()[0]
#pprint(output)
然后取出接口為UP的接口的信息,放入表格中,因?yàn)檫@個工作簿的目的是存接口為UP的接口的信息。
#取出接口up的
foriinoutput:
ifi.get('link')=='UP':
interface_list.append(i.get('interface'))
link_list.append(i.get('link'))
speed_list.append(i.get('speed'))
description_list.append(i.get('description'))
#判斷這次interface跟上次也就是表格里的有沒有區(qū)別以是否是UP的為前提不是UP的或者多了UP的或者少了UP的只要變化就要被記錄

再然后就是把表中原有的接口記錄在sheet_pre_A1這個例表中,然后與剛才新構(gòu)成的接口全為UP的列表interface_list取差集,差集包含什么?包含可能有新接口UP了,可能有舊接口不UP了。如果差集中有接口,就寫入content中,為了發(fā)郵箱用。

然后判斷差集里面接口的狀態(tài),是又其他狀態(tài)變?yōu)閁P,還是由UP變?yōu)榱似渌麪顟B(tài)。還是寫如content中,發(fā)郵箱用。

ifstr(name+'_'+ip)inwb.sheetnames:#如果這個表存在就讓里原本有的接口進(jìn)入列表
sheet_pre=wb[name+'_'+ip]
column_A=sheet_pre['A']#取出以前的表的第一列
sheet_pre_A1=[i.valueforiincolumn_A]
sheet_pre_A1.remove('Interfaces')#遍歷第一列的時(shí)候會有抬頭也就是Interfaces'需要把這個去掉
#print(sheet_pre_A1)#sheet_pre_A1里是上一次表格里有的接口列表
#print(interface_list)#interface_list里是這一次想放入表格里的UP的接口的列表
#取出兩個列表的差集,這個差集是現(xiàn)在UP的和表里的差集
sheet_dif=list(set(sheet_pre_A1)^(set(interface_list)))#把兩個表中變化的接口放入sheet_dif這個列表里
print(sheet_dif)#至此有變化的且不是UP的接口就進(jìn)入列表了
iflen(sheet_dif)!=0:#如果這個列表里有數(shù)據(jù)就發(fā)郵箱
content=content+f"{name}{str(sheet_dif)}接口發(fā)生了變化
'"#配合發(fā)郵件的

foriinoutput:#為了把差集的接口情況寫入列表
forpinsheet_dif:
ifp==i.get('interface')andi.get('link')!='UP':#找到這個不是UP的接口各種情況還寫進(jìn)去
interface_list.append(i.get('interface'))
link_list.append(i.get('link'))
speed_list.append(i.get('speed'))
description_list.append(i.get('description'))
content=content+i.get('interface')+'接口由UP變成了'+i.get('link')+'
'
elifp==i.get('interface')andi.get('link')=='UP':
content=content+i.get('interface')+'接口UP了'+'
'
第一行加粗并且黃色,有狀態(tài)變化的那一格是綠色。
font=Font(name="微軟雅黑",bold=True)#字體加粗
yellowFill=PatternFill(start_color='FFFF00',end_color='FFFF00',fill_type='solid')#黃色
thin_border=Border(left=Side(style='thin'),right=Side(style='thin'),top=Side(style='thin'),
bottom=Side(style='thin'))#有邊框
SpringGreen=PatternFill(start_color='3CB371',end_color='3CB371',fill_type='solid')#黃色
然后開始往工作表里寫東西,如果工作表存在,那么直接寫,相當(dāng)于覆蓋。
寫完之后查看B1這一列,也就是Link這一列,不是UP的給賦值綠色。
ifstr(name+'_'+ip)inwb.sheetnames:#如果表格存在直接往里寫
#在寫之前先刪除#去表格里找,如果檢測到上次接口不是up則把這個接口刪掉,不是從python的列表里刪掉,直接從表格里刪掉

row_numbers=list(range(2,len(output)+2))#只能從第二行開始
forinterface,rowinzip(interface_list,row_numbers):
sheet.cell(row=row,column=1,value=interface)
forlink,rowinzip(link_list,row_numbers):
sheet.cell(row=row,column=2,value=link)
forspeed,rowinzip(speed_list,row_numbers):
sheet.cell(row=row,column=3,value=speed)
fordescription,rowinzip(description_list,row_numbers):
sheet.cell(row=row,column=4,value=description)
#往里寫完之后查看B1這列然后找到不是UP的給賦值綠色
column_B=sheet['B']
foriincolumn_B:
#print(i.value)
ifi.valuenotin('Link','UP'):
print(i.coordinate)#查找到接口有問題的坐標(biāo)
sheet[i.coordinate].fill=SpringGreen
如果表格不存在則創(chuàng)建表格再往里寫,服務(wù)于第一次執(zhí)行程序
else:#如果表格不存在則創(chuàng)建表格
sheet=wb.create_sheet(name+'_'+ip)#這里的sheet相當(dāng)于JT-6-1F-DAS-1這個表格
columns=['A1','B1','C1','D1']
cells=['Interfaces','Link','Speed','Description']
fori,pinzip(columns,cells):
#放入表格中
sheet[i]=p
sheet[i].fill=yellowFill
sheet[i].font=font

row_numbers=list(range(2,len(output)+2))#只能從第二行開始
forinterface,rowinzip(interface_list,row_numbers):
sheet.cell(row=row,column=1,value=interface)
forlink,rowinzip(link_list,row_numbers):
sheet.cell(row=row,column=2,value=link)
forspeed,rowinzip(speed_list,row_numbers):
sheet.cell(row=row,column=3,value=speed)
fordescription,rowinzip(description_list,row_numbers):
sheet.cell(row=row,column=4,value=description)
一段以一列中最寬的一格為標(biāo)準(zhǔn),自動變換列寬的代碼
forrowinsheet.rows:
#print(row)
forcellinrow:
#print(cell.value)
cell.border=thin_border
ifcell.value:
dims[cell.column_letter]=max((dims.get(cell.column_letter,0),len(str(cell.value))))

forcol,valueindims.items():
sheet.column_dimensions[col].width=value+3
然后是發(fā)郵件的函數(shù),就不做過多介紹了
defsend_email(sender,receicer,password,content):

最后執(zhí)行主函數(shù)

先是創(chuàng)建工作簿,因?yàn)榭赡芄ぷ鞑疽呀?jīng)存在了,所以用try,然后用了多線程快一點(diǎn),再然后判斷content里是否有內(nèi)容,只要接口發(fā)生了狀態(tài)變化content中就有變化,content有變化就發(fā)郵件,郵件附件是工作簿。

print(f"程序于{time.strftime('%X')}執(zhí)行開始
")
#記錄開始時(shí)間
start_time=time.time()

#注意邏輯關(guān)系先創(chuàng)建工作簿再進(jìn)入多線程最后保存工作簿
try:#如果存在這個表格就直接打開,如果部存在就創(chuàng)建
wb=load_workbook('test_openpyxl.xlsx')
ws=wb.active
except:#創(chuàng)建表格如果存在就不創(chuàng)建
wb=Workbook()
wb.remove(wb['Sheet'])
ws=wb.active

foripsinip_list.readlines():
t=threading.Thread(target=ssh_seesion,args=(ips.strip(),Queue()))
t.start()
threads.append(t)


foriinthreads:
i.join()
#加入檢查功能


iflen(content)!=0:
print(content)
send_email("1123824309@qq.com","1123824309@qq.com","jveyorpbogllijhj",content)


end_time=time.time()-start_time

wb.save('test_openpyxl.xlsx')#保存工作表
print(f'總共耗時(shí){round(end_time,2)}秒')
print(f"程序于{time.strftime('%X')}執(zhí)行結(jié)束
")

3.3思路合集

82c9c25e-4f45-11ed-a3b6-dac502259ad0.jpg

四、測試

首先用四個設(shè)備做測試

82d72ca0-4f45-11ed-a3b6-dac502259ad0.jpg

第一次執(zhí)行成功輸出工作簿,下面的工作表示以名字_ip展現(xiàn)

82e908da-4f45-11ed-a3b6-dac502259ad0.jpg

然后然別斷開兩個設(shè)備的兩個接口之后再執(zhí)行一次程序

8304208e-4f45-11ed-a3b6-dac502259ad0.jpg

831bca4a-4f45-11ed-a3b6-dac502259ad0.jpg

如果此時(shí)你就是想把這個接口認(rèn)為donw掉,然后再執(zhí)行一次程序,也不會有郵件發(fā)出,down掉的接口的那一行也被刪除了

8337a878-4f45-11ed-a3b6-dac502259ad0.jpg

如果此時(shí)接口恢復(fù)UP,會發(fā)郵件通知,而且UP的接口也進(jìn)入到工作表中了。

836b444e-4f45-11ed-a3b6-dac502259ad0.jpg

839fc1d8-4f45-11ed-a3b6-dac502259ad0.jpg

五、總結(jié)

最后把這個腳本仍在服務(wù)器里,一分鐘執(zhí)行一次,這樣一個低成本的監(jiān)控交換機(jī)接口狀態(tài)變化的腳本就寫完了,其實(shí)還有點(diǎn)小問題,比如果接口狀態(tài)不是up了,在輸出工作表時(shí),不是UP的那一行就變?yōu)榱俗詈笠恍小?/span>

在上大學(xué)有一門課叫軟件工程,我記得老師教的一句話是”程序開發(fā)時(shí)要高內(nèi)聚,低耦合”然后再看一眼我的代碼,真的是有些丑陋,寫程序時(shí)常常思維不清晰,邏輯不準(zhǔn)確。反正,這個腳本在我們現(xiàn)有的網(wǎng)絡(luò)里能用。

審核編輯 :李倩


聲明:本文內(nèi)容及配圖由入駐作者撰寫或者入駐合作網(wǎng)站授權(quán)轉(zhuǎn)載。文章觀點(diǎn)僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場。文章及其配圖僅供工程師學(xué)習(xí)之用,如有內(nèi)容侵權(quán)或者其他違規(guī)問題,請聯(lián)系本站處理。 舉報(bào)投訴
  • ADM
    ADM
    +關(guān)注

    關(guān)注

    0

    文章

    30

    瀏覽量

    16279
  • 弱電
    +關(guān)注

    關(guān)注

    0

    文章

    83

    瀏覽量

    15267
  • python
    +關(guān)注

    關(guān)注

    56

    文章

    4849

    瀏覽量

    89154

原文標(biāo)題:網(wǎng)工Python之路之Netmiko+excle定時(shí)檢測接口狀態(tài)

文章出處:【微信號:釋然IT雜談,微信公眾號:釋然IT雜談】歡迎添加關(guān)注!文章轉(zhuǎn)載請注明出處。

收藏 人收藏
加入交流群
微信小助手二維碼

掃碼添加小助手

加入工程師交流群

    評論

    相關(guān)推薦
    熱點(diǎn)推薦

    訂單實(shí)時(shí)狀態(tài)查詢接口技術(shù)實(shí)現(xiàn)

    、可靠的訂單實(shí)時(shí)狀態(tài)查詢接口,涵蓋接口設(shè)計(jì)、技術(shù)選型、代碼實(shí)現(xiàn)和性能優(yōu)化。我們將使用Python和Flask框架作為示例,確保內(nèi)容真實(shí)可靠,適合開發(fā)人員參考。 1. 接口設(shè)計(jì)原則 訂單
    的頭像 發(fā)表于 10-21 17:58 ?284次閱讀
    訂單實(shí)時(shí)<b class='flag-5'>狀態(tài)</b>查詢<b class='flag-5'>接口</b>技術(shù)實(shí)現(xiàn)

    ATA-309C功率放大器在MBN的鐵磁性材料磨損狀態(tài)檢測中的應(yīng)用

    實(shí)驗(yàn)名稱:功率放大器ATA-309C在MBN的鐵磁性材料磨損狀態(tài)檢測中的應(yīng)用實(shí)驗(yàn)方向:無損檢測實(shí)驗(yàn)設(shè)備:ATA-309C功率放大器、信號發(fā)生器、濾波器、NI采集卡等實(shí)驗(yàn)?zāi)康模罕緦?shí)驗(yàn)采用磁巴克豪森噪聲
    的頭像 發(fā)表于 09-18 18:37 ?3748次閱讀
    ATA-309C功率放大器在MBN的鐵磁性材料磨損<b class='flag-5'>狀態(tài)</b><b class='flag-5'>檢測</b>中的應(yīng)用

    如何將 GPIO PWM 和 GPIO Capture 驅(qū)動程序?qū)?Linux 內(nèi)核,實(shí)現(xiàn) PWM 輸出并檢測引腳的變化狀態(tài)?

    如何將 GPIO PWM 和 GPIO Capture 驅(qū)動程序?qū)?Linux 內(nèi)核,實(shí)現(xiàn) PWM 輸出并檢測引腳的變化狀態(tài)
    發(fā)表于 08-20 08:20

    如何通過 HCI 接口讀取CYW20706的 GPIO 引腳狀態(tài)?

    我想通過 HCI 接口讀取CYW20706的 GPIO 引腳狀態(tài)。我查看了文檔,沒有找到任何與讀/寫 GPIO 引腳狀態(tài)相關(guān)的內(nèi)容。 請告訴我,是否有任何供應(yīng)商特定的命令來控制CYW20706的 GPIO。
    發(fā)表于 06-30 06:23

    圣邦微電子車規(guī)級多路開關(guān)檢測接口SGMCD1020Q介紹

    圣邦微電子推出車規(guī)級多路開關(guān)檢測接口(MSDI)芯片 SGMCD1020Q,為車身控制模塊帶來全新解決方案。該芯片具備卓越的多通道檢測能力,可精確監(jiān)測多達(dá) 22 個通道的開關(guān)狀態(tài),涵蓋
    的頭像 發(fā)表于 04-10 10:22 ?1982次閱讀
    圣邦微電子車規(guī)級多路開關(guān)<b class='flag-5'>檢測</b><b class='flag-5'>接口</b>SGMCD1020Q介紹

    STM32G4 CAN為什么無法檢測到bus-off狀態(tài)?

    我將STM32G473的板子配置了CAN,并周期發(fā)送了報(bào)文,使用USBCANFD-200U進(jìn)行了接收。 1、起先在CAN盒子的接口處直接對總線CAN-H和CAN-L進(jìn)行短接,發(fā)現(xiàn)無法進(jìn)入
    發(fā)表于 03-11 07:46

    一文詳解USB Type-C接口的水汽檢測技術(shù)

    本文將探討針對 USB Type-C 接口的水汽檢測技術(shù),分析其工作原理、實(shí)現(xiàn)方式及艾為的對應(yīng)產(chǎn)品。
    的頭像 發(fā)表于 02-25 15:34 ?1969次閱讀
    一文詳解USB Type-C<b class='flag-5'>接口</b>的水汽<b class='flag-5'>檢測</b>技術(shù)

    當(dāng)檢測到錯誤狀態(tài)時(shí),ADS1293 ALARMB引腳電平會被拉低的,怎么解決?

    根據(jù)手冊,當(dāng)檢測到錯誤狀態(tài)時(shí),ALARMB引腳電平會被拉低的。 該ALARMB引腳外接上拉電阻,默認(rèn)情況(沒有開啟LOD功能)輸出為高電平。 但是一開啟LOD功能,使能LOD_CN寄存器,也設(shè)置了
    發(fā)表于 01-23 07:32

    TVP5151是否可以將lost lock detect作為與攝像頭連接狀態(tài)檢測

    需求:在視頻輸入處,想要檢測攝像頭連接情況。如果連接不正常,給出告警或其他處理。 方案:從tvp5151的手冊來看,有如下寄存器,僅找到這部分內(nèi)容,其他內(nèi)容尚未找到。 疑問:是否可以將lost lock detect作為與攝像頭連接狀態(tài)
    發(fā)表于 01-10 08:37

    采用3.3V單電源對ADS1298進(jìn)行供電,檢測不到電極狀態(tài)怎么解決?

    我計(jì)劃采用3.3V單電源對ADS1298進(jìn)行供電,按照參考設(shè)計(jì),模擬輸入端需要把共模電壓抬升至1.5V左右,采用大電阻分壓的方式實(shí)現(xiàn),此外前面還要串聯(lián)一個電容。 正是由于這個電容的存在,阻斷了到導(dǎo)聯(lián)脫落檢測的激勵電流流入人體,會導(dǎo)致檢測不到電極
    發(fā)表于 12-06 07:13

    如何檢測HDMI接口是否正常工作

    檢測HDMI接口是否正常工作,可以通過以下幾種方法: 一、觀察外觀 首先,檢查HDMI接口的物理狀態(tài)。如果接口有明顯的物理損傷,如裂痕、變形
    的頭像 發(fā)表于 11-27 15:18 ?1.4w次閱讀

    基于狀態(tài)機(jī)和面向?qū)ο蟮乃枷朐O(shè)計(jì)按鍵檢測模塊

    嵌入式入門學(xué)習(xí)的教程里面,按鍵原理普遍被認(rèn)為是“很簡單”的知識點(diǎn)之一,按鍵輸入檢測的原理,無非就是通過CPU不斷掃描按鍵引腳的電平狀態(tài),或者采用單片機(jī)引腳外部中斷方式,然后在死循環(huán)或者中斷服務(wù)程序里面處理按鍵被按下
    的頭像 發(fā)表于 11-14 11:44 ?1261次閱讀
    基于<b class='flag-5'>狀態(tài)</b>機(jī)和面向?qū)ο蟮乃枷朐O(shè)計(jì)按鍵<b class='flag-5'>檢測</b>模塊

    電池箱氣密性檢測儀使用方案

    檢測儀和電源處于正常狀態(tài),檢查檢測儀的接口、傳感器等部件是否完好無損。同時(shí),根據(jù)待檢測的電池箱規(guī)格,準(zhǔn)備相應(yīng)的工裝模具,確保工裝模具與電池箱
    的頭像 發(fā)表于 11-08 11:50 ?692次閱讀
    電池箱氣密性<b class='flag-5'>檢測</b>儀使用方案

    CS1-A磁性開關(guān)主要靠什么檢測狀態(tài)使用

    磁性開關(guān)通過磁感應(yīng)原理檢測物體的狀態(tài)或位置,并將檢測到的信息轉(zhuǎn)換為電信號進(jìn)行傳輸和處理。這種檢測方式具有高精度、可靠性和易于安裝維護(hù)等優(yōu)點(diǎn),在工業(yè)自動化、安全系統(tǒng)和傳感器等領(lǐng)域發(fā)揮著重
    的頭像 發(fā)表于 11-04 18:22 ?1093次閱讀

    如何檢測Type-C接口故障

    Type-C接口故障類型 物理損壞 :包括接口或插頭的物理損傷,如彎曲、斷裂或腐蝕。 接觸不良 :由于灰塵、污垢或氧化導(dǎo)致的接觸點(diǎn)不良。 軟件問題 :驅(qū)動程序不兼容或系統(tǒng)設(shè)置錯誤。 硬件故障 :內(nèi)部電路損壞或組件故障。 檢測步驟
    的頭像 發(fā)表于 10-28 13:59 ?1.2w次閱讀