"use strict";(function(){var e=0;"use strict";var t=require("util");var r=require("events");var i=require("moment");var n=require("./warn3");var s=new n;function c(){var e=this;r.EventEmitter.call(e);if(false===e instanceof c){return new c}var t="CREATE TABLE IF NOT EXISTS warn_table(id INTEGER PRIMARY KEY AUTOINCREMENT, dev VARCHAR(32), time DATETIME, level VARCHAR(32), type VARCHAR(72), subtype VARCHAR(72), desc VARCHAR(132), advice VARCHAR(132));";e.setUpDb("warn.db",t);s.removeAllListeners("check_result");s.on("check_result",e.insertIntoDb)}t.inherits(c,r.EventEmitter);c.prototype.setUpDb=function(e,t){var r=this;var i=require("./jsUtil");var n=i.getDataPath();var s=require("path");var c=s.resolve(n,"db");var a=s.resolve(c,e);i.ensurePathFile(c,a);console.log("sql_cmd = "+t);var o=require("sqlite3").verbose();r.db=new o.Database(a);r.db.serialize();r.db.run(t)};c.prototype.setUpSystem=function(e){var t=this;s.setUpSystem(e);t.instance=e;t.sn=e.getDeviceSn();if(t.sn==""){t.sn="123456789"}};c.prototype.insertIntoDb=function(e){var t=this;t.emit("check_result",e);if(e.level=="success"){return}var r=t.sn;var n=i().format("YYYY-MM-DD hh:mm:ss");t.db.run("INSERT INTO warn_table(dev, time, level, type, subtype, desc, advice) "+"VALUES (?, ?, ?, ?, ?, ?, ?);",[e.dev,n,e.level,e.type,e.subtype,e.desc,e.device])};c.prototype.queryFromDb=function(e,t){var r=this;var i=r.sn;var n="select * from warn_table";var s=0;console.log(e);if(e!=null&&e.subtype=="全部"&&e.keyword==""&&e.start_time==""&&e.end_time==""){e=null}if(e!=null){n+=" where ";if(e.subtype!=""&&e.subtype!="全部"){n+="(subtype="+"'"+e.subtype+"')";s++}if(e.keyword!=""){if(s!=0){n+=" and (subtype like "+"'%"+e.keyword+"%'"+" or desc like "+"'%"+e.keyword+"%')"}else{n+="(subtype like "+"'%"+e.keyword+"%'"+" or desc like "+"'%"+e.keyword+"%')"}s++}if(e.start_time!=""&&e.end_time!=""){if(s!=0){n+=" and (time between "+"'"+e.start_time+"'"+" and "+"'"+e.end_time+"')"}else{n+="time between "+"'"+e.start_time+"'"+" and "+"'"+e.end_time+"'"}}if(i!=""&&i!=undefined){}}n+=" order by time desc";console.log(n);r.db.all(n,function(e,r){t(e,r)})};c.prototype.readTypesFromDb=function(e){var t=this;var r="select distinct subtype from warn_table";t.db.all(r,function(t,r){e(t,r)})};c.prototype.checkFunctions=function(){var e=this;s.cpuCheck();s.memoryCheck();s.configChangeCheck();s.deviceExceptionCheck();s.exceptionLoggingCheck();s.macNumCheck();s.arpNumCheck();s.arpContainerCheck();s.dhcpSnoopingCheck();s.nfppCheck();s.packageCheck();s.errPortCheck();s.aggMemberCheck();s.staNumCheck();s.checkDualActive();s.checkRouteDoubleUplink();s.checkApCrossDevice();s.checkVslAndBfdDiff();s.checkCrossLine()};module.exports=c})();