那曲檬骨新材料有限公司

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

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

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

Python網(wǎng)絡(luò)設(shè)備巡檢(異常自動報警)

網(wǎng)絡(luò)技術(shù)干貨圈 ? 來源:網(wǎng)絡(luò)技術(shù)干貨圈 ? 2022-12-29 09:09 ? 次閱讀

思想

1、python抓取交換機信息
2、提取需要的檢查結(jié)果,并寫入excel表格
3、如果某一檢查結(jié)果超出閾值或不符合某一關(guān)鍵字,自動發(fā)送報警郵件
4、每十分鐘執(zhí)行一次python代碼

代碼

抓取交換機信息

importpexpect
importsys
importdatetime
importos

#today=datetime.date.today().strftime('%Y%m%d')
print(3)
ip='x.x.x.x'
passwd='xxxx'
txt='F5hexin.txt'
name=''
name1="----More----"
child=pexpect.spawn('telnet%s'%ip)
fout=open('/root/F5Core/Core/'+txt,'wb+')
child.logfile=fout
child.expect('login:')
child.sendline("admin")
child.expect('(?i)ssword:')
child.sendline("%s"%passwd)
child.expect("%s"%name)
child.sendline("displaypower")
child.expect("%s"%name)
child.sendline("displayversion")
foriinrange(20):
index=child.expect([name1,"%s"%name])
if(index==0):
child.send("")
else:
child.sendline("displayenvironment")
break
foriinrange(20):
index=child.expect([name1,"%s"%name])
if(index==0):
child.send("")
else:
child.sendline("displayfan")
break
foriinrange(10):
index=child.expect([name1,"%s"%name])
if(index==0):
child.send("")
else:
child.sendline("displaycpu-usage")
break
foriinrange(10):
index=child.expect([name1,"%s"%name])
if(index==0):
child.send("")
else:
child.sendline("displaymemory")
break
foriinrange(10):
index=child.expect([name1,"%s"%name])
if(index==0):
child.send("")
else:
child.sendline("displayinterfacebrief")
break
foriinrange(10):
index=child.expect([name1,"%s"%name])
if(index==0):
child.send("")
else:
child.sendline("dislogbuffer")
break
foriinrange(50):
index=child.expect([name1,"%s"%name])
if(index==0):
child.send("")
else:
child.sendline("displayiprouting-table")
break
foriinrange(50):
index=child.expect([name1,"%s"%name])
if(index==0):
child.send("")
else:
child.sendline("displayirflink")
break
foriinrange(3):
index=child.expect([name1,"%s"%name])
if(index==0):
child.send("")
else:
child.sendline("quit")
sys.exit()

代碼

匹配閾值,報警

#coding:utf-8
importpymssql
importxlwt
importdatetime
fromxlwtimport*
fromemail.mime.textimportMIMEText
fromemail.mime.multipartimportMIMEMultipart
importsmtplib
importdatetime
fromemailimportencoders
fromemail.mime.imageimportMIMEImage
fromemail.mime.baseimportMIMEBase
importre
importxlrd

file=open('/root/F5Core/Core/F5hexin.txt','r+')
listlist=file.readlines()
i=1
forlineinlistlist:#匹配檢查結(jié)果,超出閾值,把結(jié)果換成error。
if'displaypower'inline:
power11=listlist[i+6][8:15].strip()
ifpower11!='Normal':
power11='Error'
print(power11)
power12=listlist[i+8][8:15].strip()
ifpower12!='Normal':
power12='Error'
print(power11)
power13=listlist[i+10][8:15].strip()
ifpower13!='Normal':
power13='Error'
print(power11)
power14=listlist[i+12][8:15].strip()
ifpower14!='Normal':
power14='Error'
print(power11)
power21=listlist[i+28][8:15].strip()
ifpower21!='Normal':
power21='Error'
print(power11)
power22=listlist[i+30][8:15].strip()
ifpower22!='Normal':
power22='Error'
print(power11)
power23=listlist[i+32][8:15].strip()
ifpower23!='Normal':
power23='Error'
print(power23)
power24=listlist[i+34][8:15].strip()
ifpower24!='Normal':
power24='Error'
print(power24)
if'MPU(M)Chassis1Slot0:'inline:
time11=listlist[i+1][9:].strip()
print(time11)
if'LPUChassis1Slot2:'inline:
time12=listlist[i+1][9:].strip()
print(time12)
if'MPU(S)Chassis2Slot0:'inline:
time13=listlist[i+1][9:].strip()
print(time13)
if'LPUChassis2Slot2:'inline:
time14=listlist[i+1][9:].strip()
print(time14)
if'displayenvironment'inline:
environment11=listlist[i+10][26:29].strip()+''+listlist[i+12][26:29].strip()
environment12=listlist[i+14][26:29].strip()+''+listlist[i+16][26:29].strip()+''+listlist[i+18][26:29].strip()
environment13=listlist[i+46][26:29].strip()+''+listlist[i+51][26:29].strip()
environment14=listlist[i+53][26:29].strip()+''+listlist[i+55][26:29].strip()+''+listlist[i+57][26:29].strip()
ifint(listlist[i+10][26:29].strip())>70:
environment11='Error'
print(environment11)
ifint(listlist[i+12][26:29].strip())>70:
environment11='Error'
print(environment11)
ifint(listlist[i+14][26:29].strip())>70:
environment12='Error'
print(environment12)
ifint(listlist[i+16][26:29].strip())>70:
environment12='Error'
print(environment12)
ifint(listlist[i+18][26:29].strip())>70:
environment12='Error'
print(environment12)
ifint(listlist[i+46][26:29].strip())>70:
environment13='Error'
print(environment13)
ifint(listlist[i+51][26:29].strip())>70:
environment13='Error'
print(environment13)
ifint(listlist[i+53][26:29].strip())>70:
environment14='Error'
print(environment14)
ifint(listlist[i+55][26:29].strip())>70:
environment14='Error'
print(environment14)
ifint(listlist[i+57][26:29].strip())>70:
environment14='Error'
print(environment14)
if'displayfan'inline:
fana11=listlist[i+6][-8:].strip()
iffana11!='Normal':
fana11='Error'
print(fana11)
fana12=listlist[i+26][-8:].strip()
iffana12!='Normal':
fana12='Error'
print(fana12)
fana13=listlist[i+53][-8:].strip()
iffana13!='Normal':
fana13='Error'
print(fana13)
fana14=listlist[i+73][-8:].strip()
iffana14!='Normal':
fana14='Error'
print(fana14)
if'Chassis1Slot0CPU0CPUusage:'inline:
cpu11=listlist[i+5][6:10].strip()
ifint(re.sub('%','',cpu11))>30:
cpu11='Error'
print(cpu11)
if'Chassis1Slot2CPU0CPUusage:'inline:
cpu12=listlist[i+5][6:10].strip()
ifint(re.sub('%','',cpu12))>30:
cpu12='Error'
print(cpu12)
if'Chassis2Slot0CPU0CPUusage:'inline:
cpu13=listlist[i+5][6:10].strip()
ifint(re.sub('%','',cpu13))>30:
cpu13='Error'
print(cpu13)
if'Chassis2Slot2CPU0CPUusage:'inline:
cpu14=listlist[i+8][6:10].strip()
ifint(re.sub('%','',cpu14))>30:
cpu14='Error'
print(cpu14)
if'displaymemory'inline:
memory11=listlist[i+8][-6:].strip()
iffloat(re.sub('%','',memory11))530:
log11='Error'
print(log11)
if'Routes:'inline:
routingtable11=line[-5:].strip()
ifint(routingtable11)

自動執(zhí)行代碼

Linux crontab

5759153e-8708-11ed-bfe3-dac502259ad0.png

結(jié)果

1、正常巡檢結(jié)果

57696e2a-8708-11ed-bfe3-dac502259ad0.png

2、出現(xiàn)異常報警的巡檢結(jié)果

5792955c-8708-11ed-bfe3-dac502259ad0.png57ae711e-8708-11ed-bfe3-dac502259ad0.png

審核編輯:湯梓紅

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

    關(guān)注

    21

    文章

    2656

    瀏覽量

    100179
  • 網(wǎng)絡(luò)設(shè)備

    關(guān)注

    0

    文章

    318

    瀏覽量

    29765
  • python
    +關(guān)注

    關(guān)注

    56

    文章

    4807

    瀏覽量

    85037

原文標題:Python網(wǎng)絡(luò)設(shè)備巡檢(異常自動報警)

文章出處:【微信號:網(wǎng)絡(luò)技術(shù)干貨圈,微信公眾號:網(wǎng)絡(luò)技術(shù)干貨圈】歡迎添加關(guān)注!文章轉(zhuǎn)載請注明出處。

收藏 人收藏

    評論

    相關(guān)推薦

    外網(wǎng)訪問家里的網(wǎng)絡(luò)設(shè)備

    網(wǎng)絡(luò)設(shè)備
    學(xué)習(xí)電子知識
    發(fā)布于 :2023年07月17日 20:06:18

    網(wǎng)絡(luò)設(shè)備選擇技巧

    。為什么會這樣呢?使用過計算機的讀者都知道,當(dāng)CPU風(fēng)扇散熱不佳時計算機系統(tǒng)經(jīng)常會死機或自動重啟,網(wǎng)絡(luò)設(shè)備更是如此,高速運行的CPU與核心組件需要在一個合適的工作環(huán)境下運轉(zhuǎn),溫度太高會使它們損壞。設(shè)備散熱工作
    發(fā)表于 04-08 09:34

    變電站巡檢管理系統(tǒng)

    :電纜接頭接觸良好、觀察電纜接頭有無發(fā)熱放電現(xiàn)象)等,并輸入設(shè)備實際運行狀態(tài)及參數(shù),或選擇相應(yīng)分類(正常/異常,良好/發(fā)熱),提交即可。如設(shè)備超標、異常監(jiān)控中心會
    發(fā)表于 11-21 11:10

    HZD-HX型微機智能自動巡檢控制設(shè)備

    HZD-HX型微機智能自動巡檢控制設(shè)備技術(shù)參數(shù) 1、對于消防水泵來說,普遍存在一個問題:那就是在建筑物發(fā)生火災(zāi)時,有相當(dāng)多的消防泵在接到啟動信號后不能啟動,沒有水無法滅火,延誤了滅火時機,給國家財產(chǎn)
    發(fā)表于 05-26 14:06

    各類網(wǎng)絡(luò)設(shè)備

    ` 網(wǎng)絡(luò)設(shè)備,銳捷,艾泰,D-link,華為,H3C,思科,韓電,安普`
    發(fā)表于 11-29 11:15

    Linux常用網(wǎng)絡(luò)設(shè)備

    網(wǎng)絡(luò)設(shè)備是計算機體系結(jié)構(gòu)中必不可少的一部分,處理器如果想與外界通信,通常都會選擇網(wǎng)絡(luò)設(shè)備作為通信接口。眾所周知,在 OSI(Open Systems Interconnection,開放網(wǎng)際互連)中,網(wǎng)絡(luò)被劃分為七個層次,從下到
    發(fā)表于 07-25 07:37

    消防巡檢控制柜專用電氣元件:消防泵自動巡檢控制器

    消防智能數(shù)字巡檢裝置,又稱消防自動巡檢控制柜。巡檢為低頻巡檢巡檢時電機轉(zhuǎn)速為300轉(zhuǎn)/分,水系
    發(fā)表于 11-08 17:19

    網(wǎng)絡(luò)設(shè)備監(jiān)管系統(tǒng)的設(shè)計與實現(xiàn)

    網(wǎng)絡(luò)設(shè)備監(jiān)管是指對IP 網(wǎng)絡(luò)中的關(guān)鍵設(shè)備進行實時監(jiān)控和管理,使網(wǎng)絡(luò)管理員對網(wǎng)絡(luò)設(shè)備的使用情況有更為深入的了解。在研究分析
    發(fā)表于 06-23 13:33 ?24次下載

    家用網(wǎng)絡(luò)設(shè)備簡介

    家用網(wǎng)絡(luò)設(shè)備簡介 就在幾年前,家用網(wǎng)絡(luò)設(shè)備還相當(dāng)簡單。使用一根直連電纜、一部網(wǎng)絡(luò)集線器或以太網(wǎng)路由器,您可以將兩部或多部計算機連接在一起,共享外設(shè)、
    發(fā)表于 08-05 10:26 ?1073次閱讀

    基于正則表達式匹配的網(wǎng)絡(luò)設(shè)備自動管理系統(tǒng)_李林廣

    基于正則表達式匹配的網(wǎng)絡(luò)設(shè)備自動管理系統(tǒng)_李林廣
    發(fā)表于 03-16 08:50 ?0次下載

    Python寫SecureCRT批量登錄/巡檢網(wǎng)絡(luò)設(shè)備腳本

    因為有約200臺的網(wǎng)絡(luò)設(shè)備需要每天登錄巡檢、查看配置、保存配置、定期更改密碼(每周改一次),如果都手動去登錄、配置將是非常耗費時間和人力的,所以就有了整理出腳本的想法。查看了網(wǎng)上大多是VBS編寫的腳本,我對VBS不熟悉,剛好前段時間初步學(xué)習(xí)了
    的頭像 發(fā)表于 12-28 09:32 ?4704次閱讀

    如何使用Python通過SNMP監(jiān)控網(wǎng)絡(luò)設(shè)備

    前段時間,為了實現(xiàn)自動巡檢,我開發(fā)了自動巡檢工具,由于我的系統(tǒng)設(shè)備版本比較多,所以我是分別開發(fā)的客戶端程序,服務(wù)端使用dll文件與客戶端
    的頭像 發(fā)表于 01-09 10:38 ?1358次閱讀

    使用Python批量連接華為網(wǎng)絡(luò)設(shè)備

    隨著網(wǎng)絡(luò)規(guī)模的擴大和設(shè)備數(shù)量的增加,手動配置和管理每臺網(wǎng)絡(luò)設(shè)備變得越來越不現(xiàn)實。因此,自動化工具和腳本變得尤為重要。Python語言以其簡潔
    的頭像 發(fā)表于 08-12 17:48 ?543次閱讀

    Juniper設(shè)備常用的巡檢命令介紹

    網(wǎng)絡(luò)管理中,設(shè)備巡檢是確保網(wǎng)絡(luò)設(shè)備運行正常、性能最佳的重要環(huán)節(jié)。Juniper Networks設(shè)備廣泛應(yīng)用于各類
    的頭像 發(fā)表于 08-12 18:14 ?773次閱讀

    如何配置ptp網(wǎng)絡(luò)設(shè)備

    自動化等。 2. 硬件準備 2.1 選擇支持PTP的設(shè)備 確保你的網(wǎng)絡(luò)設(shè)備(如交換機、路由器、服務(wù)器等)支持PTP。這些設(shè)備通常有專門的硬件支持,如PTP Grandmaster(主時
    的頭像 發(fā)表于 12-29 09:36 ?295次閱讀
    圣淘沙百家乐游戏| 网页百家乐的玩法技巧和规则| 大发888游乐场| 娱乐城百家乐官网技巧| 百家乐是骗人的| 大发888手机版| 豪博百家乐官网现金网| 百家乐看点打法| 大发888游戏平台dafa888 gw| 百家乐官网真人游戏投注网| 百家乐投注限额| 乐透世界| 新濠百家乐官网娱乐城| 太阳城会员| 真人百家乐官网娱乐场| 网上百家乐是叫九五至尊么| 大众娱乐城| 百家乐官网手机壳| 大发888怎么代充| 线上百家乐官网| 百家乐平注法规则| 真人百家乐视频| 百家乐官网的必胜方法| 澳门百家乐哪家信誉最好| 巫溪县| 先锋百家乐的玩法技巧和规则 | 百家乐必胜| 海立方百家乐赢钱| 涂山国际娱乐城| 百家乐系统分析器| 调兵山市| 代理百家乐免费试玩| 百家乐官网起步多少| 百家乐遥控洗牌器| 澳门百家乐官网是骗人的| 百家乐的薇笑打法| 澳门百家乐官网真人斗地主| 戒掉百家乐的玩法技巧和规则| 百家乐官网视频游戏中心| 百家乐77s| 百家乐群详解包杀|