基于SNMP在网络监控中的应用1_OLT设备的监控
生活随笔
收集整理的這篇文章主要介紹了
基于SNMP在网络监控中的应用1_OLT设备的监控
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
? ? ?SNMP 是應(yīng)用在 IP 網(wǎng)絡(luò)管理網(wǎng)絡(luò)節(jié)點(diǎn)(服務(wù)器、OLT、路由器、交換機(jī)等)的一種標(biāo)準(zhǔn)協(xié)議,屬于應(yīng)用層協(xié)議,通過 SNMP 可以獲得設(shè)備的主要運(yùn)行參數(shù)信息,幫助管理員解決出現(xiàn)的問題,我用到的開發(fā)工具包括C#、JavaScript、Echarts等。
? ? 本次介紹如何監(jiān)控OLT設(shè)備的主要工作參數(shù)指標(biāo),包括上行口狀態(tài)、板卡cpu利用率、內(nèi)存利用率和溫度等,其他需要監(jiān)控的指標(biāo)自己可以摸索。
OLT設(shè)備的oid信息由于保密的需要做了隱藏 public string zxAnOltsysName = "1.3.6.1.2.1.1.5.0"; //C320設(shè)備名稱 public string zxAnOltsysDescr = "1.3.6.1.2.1.1.1.0"; //C320設(shè)備描述 public string zxAnOltGei1Status = "1.3.6.1.2.1.2.2.*"; //C320上行口 public string zxAnCardOperStatus = "1.3.6.1.4.1.3902.*";//塊卡狀態(tài) public string zxAnCardCpuLoad = "1.3.6.1.4.1.3902.*";//板卡cpu利用率 public string zxAnCardMemUsage = "1.3.6.1.4.1.3902.*";//內(nèi)存利用率 public string zxAnOltTemperature = "1.3.6.1.4.1.3902.*"; //溫度 public string zxAnOltOnuAddress = "1.3.6.1.4.1.3902.*"; //帶的ONUmac根據(jù)oid調(diào)用getOIDValue()函數(shù)獲得對應(yīng)的參數(shù)值。
public Dictionary<string, string> getOIDValue(string host, string singleoid, string mcmtsCommunity){Dictionary<string, string> dic = new Dictionary<string, string>();try{OctetString community = new OctetString(mcmtsCommunity);AgentParameters param = new AgentParameters(community);param.Version = SnmpVersion.Ver2;IpAddress agent = new IpAddress(host);UdpTarget target = new UdpTarget((IPAddress)agent, 161, 1000, 1);Pdu pdu = new Pdu(PduType.Get);if (!singleoid.Contains("SNMP No-Such-Instance")){pdu.VbList.Add(singleoid);SnmpV2Packet result = (SnmpV2Packet)target.Request(pdu, param);// If result is null then agent didn't reply or we couldn't parse the reply. if (result != null){// ErrorStatus other then 0 is an error returned by // the Agent - see SnmpConstants for error definitions if (result.Pdu.ErrorStatus == 0){for (int i = 0; i < result.Pdu.VbList.Count; i++){dic.Add(result.Pdu.VbList[i].Oid.ToString(), result.Pdu.VbList[i].Value.ToString());}}}target.Close();}else{dic = null;}}catch (Exception e){dic = null;}return dic;} public Dictionary<string, string> getWalkValueV2(string host, string irootOid, string mcmtsCommunity){Dictionary<string, string> dic = new Dictionary<string, string>();try{OctetString community = new OctetString(mcmtsCommunity);AgentParameters param = new AgentParameters(community);param.Version = SnmpVersion.Ver2;IpAddress agent = new IpAddress(host);UdpTarget target = new UdpTarget((IPAddress)agent, 161, 1000, 1);// Define Oid that is the root of the MIB// tree you wish to retrieveOid rootOid = new Oid(irootOid); // ifDescrOid lastOid = (Oid)rootOid.Clone();Pdu pdu = new Pdu(PduType.GetBulk);pdu.NonRepeaters = 0;pdu.MaxRepetitions = 5;while (lastOid != null){if (pdu.RequestId != 0){pdu.RequestId += 1;}// Clear Oids from the Pdu class.pdu.VbList.Clear();// Initialize request PDU with the last retrieved Oidpdu.VbList.Add(lastOid);// Make SNMP requestSnmpV2Packet result = (SnmpV2Packet)target.Request(pdu, param);// You should catch exceptions in the Request if using in real application.// If result is null then agent didn't reply or we couldn't parse the reply.if (result != null){// ErrorStatus other then 0 is an error returned by // the Agent - see SnmpConstants for error definitionsif (result.Pdu.ErrorStatus != 0){// agent reported an error with the requestConsole.WriteLine("Error in SNMP reply. Error {0} index {1}",result.Pdu.ErrorStatus,result.Pdu.ErrorIndex);lastOid = null;break;}else{// Walk through returned variable bindingsforeach (Vb v in result.Pdu.VbList){// Check that retrieved Oid is "child" of the root OIDif (rootOid.IsRootOf(v.Oid)){//Console.WriteLine("{0} ({1}): {2}",v.Oid.ToString(),SnmpConstants.GetTypeName(v.Value.Type),v.Value.ToString());dic.Add(v.Oid.ToString(), v.Value.ToString());if (v.Value.Type == SnmpConstants.SMI_ENDOFMIBVIEW)lastOid = null;elselastOid = v.Oid;}else{// we have reached the end of the requested// MIB tree. Set lastOid to null and exit looplastOid = null;}}}}else{Console.WriteLine("No response received from SNMP agent.");}}target.Close();}catch (Exception e){dic = null;}return dic;}把獲得的參數(shù)值利用頁面進(jìn)行展示,如果發(fā)現(xiàn)指標(biāo)異常,通過微信平臺進(jìn)行相應(yīng)的報警,讓維修人員盡快處理(由于時間關(guān)系,下一步在寫相關(guān)的內(nèi)容)
?
效果圖
?
總結(jié)
以上是生活随笔為你收集整理的基于SNMP在网络监控中的应用1_OLT设备的监控的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: DSG和传统变速器有什么区别
- 下一篇: wangEditor 5.0自定义上传图