diff --git a/DBExtractor/DBExtractor.config.json b/DBExtractor/DBExtractor.config.json new file mode 100644 index 0000000..aa20bce --- /dev/null +++ b/DBExtractor/DBExtractor.config.json @@ -0,0 +1,14 @@ +{ + "dbDriver":"mssql", "dbDriverComment":"either mssql (user/password) or mssql/msnodesqlv8 (trustedConnection)", + "processingType": "casrpslog", + "sourceTag": "CCERpsLog", + "serverURI": "http://localhost:2222", + "pollIntervalIdle": 10000, + "sqlConfig": { + "user": "casdbuser", + "password": "4KcLao2016!", + "server": "ustww2063\\CCE", + "database": "CAS110", + "port": 1433 + } +} \ No newline at end of file diff --git a/casRpsLogExtractor/casRpsLogExtractor.config.json.example b/DBExtractor/DBExtractor.config.json.example similarity index 75% rename from casRpsLogExtractor/casRpsLogExtractor.config.json.example rename to DBExtractor/DBExtractor.config.json.example index acd4ee8..82c2038 100644 --- a/casRpsLogExtractor/casRpsLogExtractor.config.json.example +++ b/DBExtractor/DBExtractor.config.json.example @@ -1,4 +1,6 @@ { + "dbDriver":"mssql", "dbDriverComment":"either mssql (user/password) or mssql/msnodesqlv8 (trustedConnection)", + "processingType": "casrpslog", "sourceTag": "CCERpsLog", "serverURI": "http://localhost:2222", "pollIntervalIdle": 10000, diff --git a/casRpsLogExtractor/casRpsLogExtractor.js b/DBExtractor/DBExtractor.js similarity index 78% rename from casRpsLogExtractor/casRpsLogExtractor.js rename to DBExtractor/DBExtractor.js index 0449846..b83d1eb 100644 --- a/casRpsLogExtractor/casRpsLogExtractor.js +++ b/DBExtractor/DBExtractor.js @@ -1,7 +1,8 @@ -const sql = require("mssql/msnodesqlv8"); -//const sql = require("mssql"); -const request = require("request-promise"); const fs = require("fs"); +const config = JSON.parse(fs.readFileSync("DBExtractor.config.json", "utf8")); + +const sql = require(config.dbDriver); +const request = require("request-promise"); const winston = require("winston"); const logger = winston.createLogger({ @@ -14,12 +15,12 @@ const logger = winston.createLogger({ ), transports: [ new winston.transports.Console(), - new winston.transports.File({ filename: './log/casRpsLogExtractorError.log', level: 'error' }), + new winston.transports.File({ filename: './log/DBExtractorError.log', level: 'error' }), new winston.transports.File({ filename: './log/Combined.log' }) ] }); -console.log(`casRpsLogExtractor Copyright (C) 2019 j.tretter@gmail.com +console.log(`DBExtractor Copyright (C) 2019 j.tretter@gmail.com This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -34,12 +35,10 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see .`); -logger.log("info", `casRpsLogExtractor v0.1 Starting`); +logger.log("info", `DBExtractor v0.1 Starting`); -const config = JSON.parse(fs.readFileSync("casRpsLogExtractor.config.json", "utf8")); logger.log("debug", "Config" + JSON.stringify(config)) -const processingType = "casrpslog"; const maxResultsPerMessage=100; let maxPKey = ""; let maxPKeyUnsent = ""; @@ -49,13 +48,13 @@ let theInterval; try { - lastOutMaxPKey = maxPKey = fs.readFileSync("casRpsLogExtractor.maxPKey.dat", "utf8"); + lastOutMaxPKey = maxPKey = fs.readFileSync("DBExtractor.maxPKey.dat", "utf8"); logger.log("debug", "MaxPKey Loaded: " + maxPKey); } catch (ex) { if (ex.errno === -4058) { logger.log("info", "MaxPKey-File not existing. Will be created."); } else { - logger.log("error", "opening casRpsLogExtractor.maxPKey.dat :" + ex); + logger.log("error", "opening DBExtractor.maxPKey.dat :" + ex); } } @@ -73,7 +72,7 @@ sql.connect(config.sqlConfig, err => { runNextPoll(); sqlRequest.on('row', row => { - outData = { sourceTag: config.sourceTag, processingType: processingType, data: row }; + outData = { sourceTag: config.sourceTag, processingType: config.processingType, data: row }; process.stdout.write("#"); request.json = true; @@ -92,7 +91,7 @@ sql.connect(config.sqlConfig, err => { request({ method: 'POST', uri: config.serverURI, body: JSON.stringify(allRows), json: true }).then(_ => { // count up the maxPKey only when the request was successful... maxPKey=maxPKeyUnsent; - fs.writeFileSync("casRpsLogExtractor.maxPKey.dat", maxPKey); + fs.writeFileSync("DBExtractor.maxPKey.dat", maxPKey); }).catch(err=>{ logger.log("error","Sending Request to Service: " + err) }).finally(_=>{ diff --git a/DBExtractor/DBExtractor.maxPKey.dat b/DBExtractor/DBExtractor.maxPKey.dat new file mode 100644 index 0000000..df706b3 --- /dev/null +++ b/DBExtractor/DBExtractor.maxPKey.dat @@ -0,0 +1 @@ +0010000000a87kj9 \ No newline at end of file diff --git a/RuleEngine.js b/RuleEngine.js index c376ff7..67c4ed1 100644 --- a/RuleEngine.js +++ b/RuleEngine.js @@ -107,26 +107,39 @@ exports.RuleEngine = class RuleEngine { logger.log("debug", "Logic FLAT start - whiteFilterRule: " + JSON.stringify(theWhiteFilterRule)); let isKnownComp = false; let retVal = false; + + let dataValue; + let ruleValue; + let sDataType = theWhiteFilterRule.dataType || "string"; + + if (sDataType ==="number") { + dataValue = Number(inputData[theWhiteFilterRule.Field]); + ruleValue = Number(theWhiteFilterRule.Value); + } else { + dataValue = inputData[theWhiteFilterRule.Field]; + ruleValue = theWhiteFilterRule.Value; + } + try { if (theWhiteFilterRule.Comp === "===") { - isKnownComp = true; - if (inputData[theWhiteFilterRule.Field] === theWhiteFilterRule.Value) {retVal = true;} + isKnownComp = true; + if (dataValue === ruleValue) {retVal = true;} } else if (theWhiteFilterRule.Comp === "<") { - isKnownComp = true; - if (inputData[theWhiteFilterRule.Field] < theWhiteFilterRule.Value) {retVal = true;} + isKnownComp = true; + if (dataValue < ruleValue) {retVal = true;} } else if (theWhiteFilterRule.Comp === ">") { isKnownComp = true; - if (inputData[theWhiteFilterRule.Field] > theWhiteFilterRule.Value) {retVal = true;} + if (dataValue > ruleValue) {retVal = true;} } else if (theWhiteFilterRule.Comp === "<=") { isKnownComp = true; - if (inputData[theWhiteFilterRule.Field] <= theWhiteFilterRule.Value) {retVal = true;} + if (dataValue <= ruleValue) {retVal = true;} } else if (theWhiteFilterRule.Comp === ">=") { isKnownComp = true; - if (inputData[theWhiteFilterRule.Field] >= theWhiteFilterRule.Value) {retVal = true;} + if (dataValue >= ruleValue) {retVal = true;} } else if (theWhiteFilterRule.Comp === "~") { isKnownComp = true; - logger.log("debug", "RegexFilter: " + theWhiteFilterRule.Value + " || " + ""+inputData[theWhiteFilterRule.Field].replace(/\r/g, "\\r").replace(/\n/g, "\\n")); - retVal = this.reTest(theWhiteFilterRule.Value, inputData[theWhiteFilterRule.Field]); + logger.log("debug", "RegexFilter: " + ruleValue + " || " + ""+dataValue.replace(/\r/g, "\\r").replace(/\n/g, "\\n")); + retVal = this.reTest(ruleValue, dataValue); } } catch (ex) { logger.log("error", "LogicFlat-Error " + ex + " WhiteFilterRule: " + JSON.stringify(theWhiteFilterRule) + " InputData " + JSON.stringify(inputData)); diff --git a/diskUsageMonitor/diskUsageMonitor.js b/diskUsageMonitor/diskUsageMonitor.js index ef786a0..3ef56bd 100644 --- a/diskUsageMonitor/diskUsageMonitor.js +++ b/diskUsageMonitor/diskUsageMonitor.js @@ -45,20 +45,15 @@ function cb(){ theMessage.processingType=processingType; theMessage.sourceTag=config.sourceTag; theMessage.timestamp=new Date(); - theDiskLimit.isWarn=false; disk.check(theDiskLimit.path, function(err, info) { if (err) { logger.log("error","Error reading disk Information " + err); theDiskLimit.error = err; - theDiskLimit.isWarn = true; } else { let availGB=info.available/1024/1024; let totalGB=info.total/1024/1024; theDiskLimit.availGB=availGB; theDiskLimit.totalGB=totalGB; - if (availGB<=theDiskLimit.minFree) { - theDiskLimit.isWarn=true; - } } theMessage.data=theDiskLimit; logger.log("debug","Sending Message: " + JSON.stringify(theMessage)); diff --git a/log/.issues.log.un~ b/log/.issues.log.un~ index 726008c..9487648 100644 Binary files a/log/.issues.log.un~ and b/log/.issues.log.un~ differ diff --git a/rules/diskusage.rule.json b/rules/diskusage.rule.json index 57e9aef..f50257c 100644 --- a/rules/diskusage.rule.json +++ b/rules/diskusage.rule.json @@ -1,5 +1,5 @@ { "diskusage": { "rules":[ - { "Logic":"-", "Field":"isWarn", "Comp":"!==", "Value":true} + { "Logic":"-", "dataType":"number", "Field":"availGB", "Comp":">", "Value":100} ]} } \ No newline at end of file