"use strict";(function(){var e=0;"use strict";var t=require("util");var s=require("events");var r=require("./deviceIntfDb");function i(e){s.EventEmitter.call(this);if(false===this instanceof i){return new i}this.preIntfFlows=[];this.intfDbInstance=new r(e);this.preIntfFlowsInDb=[];this.previousTime=new Date}t.inherits(i,s.EventEmitter);i.prototype.getDeviceIntfInfo=function(t,s,r){var i=this;var n="show int";var a=function o(e){};var p=new Date;var c=parseInt((p-i.previousTime)/1e3);if(c==0){c=100}var f=function v(t){var n="====";var f=[];var l=[];var o=[];var d="";var h="";var u=0;var y=0;var I=0;var B=0;var w=0;var m=[];var F=[];if(e==1){var b=require("fs");var t=b.readFileSync("me.txt");v(t.toString())}var D=t.split(/\r?\n/gi);var N=false;for(var M=0;M<D.length;M++){if(D[M].search(n)!==-1){d={deviceName:s,seriaNo:r,intfName:"",intfClass:"physical",descs:"",status:"up",adminStatus:"up",bandwidth:0,sendBytes:0,rcvBytes:0,drops:0,errors:0,crcs:0,negoSpeed:"unknown",ip:"no ip address",ipv6:"no ip address"};h={deviceName:s,seriaNo:r,intfName:"",status:"up",bandwidth:0,sendBytes:0,rcvBytes:0,interval:30};h.interval=c;d.intfName=D[M].split("= ")[1].split(" =")[0].trim();h.intfName=d.intfName;if(h.intfName.search("Ethernet")!==-1){d.intfClass="physical"}else{N=true}u=0;y=0;I=0;B=0;w=0}if(D[M].search("line protocol")!==-1){if(D[M].search("UP")!==-1){d.status="up";h.status="up"}else{d.status="down";h.status="down"}}if(D[M].search("BW")!==-1){d.bandwidth=D[M].split("BW")[1].trim().split(" ")[0];h.bandwidth=d.bandwidth}if(D[M].search("administratively down")!==-1){d.adminStatus="down"}if(D[M].search("description")!==-1){d.descs=D[M].split(":")[1].trim().replace('"',"").replace('"',"")}if(D[M].search("oper speed is")!==-1){d.negoSpeed=D[M].split("oper speed is")[1].trim()}if(D[M].search("packets input")!==-1){d.rcvBytes=D[M].split(",")[1].split("bytes")[0].trim();u=D[M].split(",")[3].split("dropped")[0].trim()}if(D[M].search("input errors")!==-1){y=D[M].split(",")[0].split("input errors")[0].trim();I=D[M].split(",")[1].split("CRC")[0].trim()}if(D[M].search("Interface address")!==-1){d.ip=D[M].split(":")[1].trim()}if(D[M].search("packets output")!==-1){d.sendBytes=D[M].split(",")[1].split("bytes")[0].trim();B=D[M].split(",")[3].split("dropped")[0].trim()}if(D[M].search("output errors")!==-1){w=D[M].split(",")[0].split("output errors")[0].trim()}if(D[M].search("interface resets")!==-1){if(N==true){continue;N=false}var g=Math.ceil(u)+Math.ceil(B);var S=Math.ceil(I);var q=Math.ceil(y)+Math.ceil(w);var E=0;var k=0;var C=0;var x=false;for(var T=0;T<i.preIntfFlows.length;T++){if(i.preIntfFlows[T].intfName==d.intfName){x=true;if(i.preIntfFlows[T].sendBytes<=Math.ceil(d.sendBytes)){h.sendBytes=Math.ceil(d.sendBytes)-i.preIntfFlows[T].sendBytes;h.rcvBytes=Math.ceil(d.rcvBytes)-i.preIntfFlows[T].rcvBytes;E=g-i.preIntfFlows[T].drops;k=S-i.preIntfFlows[T].crcs;C=q-i.preIntfFlows[T].errors}else{h.sendBytes=Math.ceil(d.sendBytes);h.rcvBytes=Math.ceil(d.rcvBytes);E=g;k=S;C=q}i.preIntfFlows[T].sendBytes=Math.ceil(d.sendBytes);i.preIntfFlows[T].rcvBytes=Math.ceil(d.rcvBytes);i.preIntfFlows[T].drops=g;i.preIntfFlows[T].crcs=S;i.preIntfFlows[T].errors=q;break}}if(x==false){var U={intfName:d.intfName,sendBytes:Math.ceil(d.sendBytes),rcvBytes:Math.ceil(d.rcvBytes),drops:g,crcs:S,errors:q};i.preIntfFlows.push(U);h.sendBytes=0;h.rcvBytes=0}var W=false;for(var A=0;A<i.preIntfFlowsInDb.length;A++){if(i.preIntfFlowsInDb[A].intfName==d.intfName){W=true;d.sendBytes=h.sendBytes+i.preIntfFlowsInDb[A].sendBytes;d.rcvBytes=h.rcvBytes+i.preIntfFlowsInDb[A].rcvBytes;d.drops=E+i.preIntfFlowsInDb[A].drops;d.crcs=k+i.preIntfFlowsInDb[A].crcs;d.errors=C+i.preIntfFlowsInDb[A].errors}}if(W==false){d.sendBytes=h.sendBytes;d.rcvBytes=h.rcvBytes;d.drops=E;d.crcs=k;d.errors=C}m.push(d);F.push(h);i.previousTime=p}}i.intfDbInstance.insertAndUpdateIntfBatch(m,a);i.intfDbInstance.insertIntoIntfFlowBatch(F,a)};var l=function d(e,s){if(e==null){i.preIntfFlowsInDb=s}t.exec(n,f)};this.intfDbInstance.queryIntfInfoBySn(r,l)};module.exports=i})();