Lots of re-structuring and handling of different data types
This commit is contained in:
14
DBExtractor/DBExtractor.config.json
Normal file
14
DBExtractor/DBExtractor.config.json
Normal file
@@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,6 @@
|
|||||||
{
|
{
|
||||||
|
"dbDriver":"mssql", "dbDriverComment":"either mssql (user/password) or mssql/msnodesqlv8 (trustedConnection)",
|
||||||
|
"processingType": "casrpslog",
|
||||||
"sourceTag": "CCERpsLog",
|
"sourceTag": "CCERpsLog",
|
||||||
"serverURI": "http://localhost:2222",
|
"serverURI": "http://localhost:2222",
|
||||||
"pollIntervalIdle": 10000,
|
"pollIntervalIdle": 10000,
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
const sql = require("mssql/msnodesqlv8");
|
|
||||||
//const sql = require("mssql");
|
|
||||||
const request = require("request-promise");
|
|
||||||
const fs = require("fs");
|
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 winston = require("winston");
|
||||||
|
|
||||||
const logger = winston.createLogger({
|
const logger = winston.createLogger({
|
||||||
@@ -14,12 +15,12 @@ const logger = winston.createLogger({
|
|||||||
),
|
),
|
||||||
transports: [
|
transports: [
|
||||||
new winston.transports.Console(),
|
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' })
|
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
|
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
|
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
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.`);
|
along with this program. If not, see <https://www.gnu.org/licenses/>.`);
|
||||||
|
|
||||||
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))
|
logger.log("debug", "Config" + JSON.stringify(config))
|
||||||
const processingType = "casrpslog";
|
|
||||||
const maxResultsPerMessage=100;
|
const maxResultsPerMessage=100;
|
||||||
let maxPKey = "";
|
let maxPKey = "";
|
||||||
let maxPKeyUnsent = "";
|
let maxPKeyUnsent = "";
|
||||||
@@ -49,13 +48,13 @@ let theInterval;
|
|||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
lastOutMaxPKey = maxPKey = fs.readFileSync("casRpsLogExtractor.maxPKey.dat", "utf8");
|
lastOutMaxPKey = maxPKey = fs.readFileSync("DBExtractor.maxPKey.dat", "utf8");
|
||||||
logger.log("debug", "MaxPKey Loaded: " + maxPKey);
|
logger.log("debug", "MaxPKey Loaded: " + maxPKey);
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
if (ex.errno === -4058) {
|
if (ex.errno === -4058) {
|
||||||
logger.log("info", "MaxPKey-File not existing. Will be created.");
|
logger.log("info", "MaxPKey-File not existing. Will be created.");
|
||||||
} else {
|
} 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();
|
runNextPoll();
|
||||||
|
|
||||||
sqlRequest.on('row', row => {
|
sqlRequest.on('row', row => {
|
||||||
outData = { sourceTag: config.sourceTag, processingType: processingType, data: row };
|
outData = { sourceTag: config.sourceTag, processingType: config.processingType, data: row };
|
||||||
process.stdout.write("#");
|
process.stdout.write("#");
|
||||||
request.json = true;
|
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(_ => {
|
request({ method: 'POST', uri: config.serverURI, body: JSON.stringify(allRows), json: true }).then(_ => {
|
||||||
// count up the maxPKey only when the request was successful...
|
// count up the maxPKey only when the request was successful...
|
||||||
maxPKey=maxPKeyUnsent;
|
maxPKey=maxPKeyUnsent;
|
||||||
fs.writeFileSync("casRpsLogExtractor.maxPKey.dat", maxPKey);
|
fs.writeFileSync("DBExtractor.maxPKey.dat", maxPKey);
|
||||||
}).catch(err=>{
|
}).catch(err=>{
|
||||||
logger.log("error","Sending Request to Service: " + err)
|
logger.log("error","Sending Request to Service: " + err)
|
||||||
}).finally(_=>{
|
}).finally(_=>{
|
||||||
1
DBExtractor/DBExtractor.maxPKey.dat
Normal file
1
DBExtractor/DBExtractor.maxPKey.dat
Normal file
@@ -0,0 +1 @@
|
|||||||
|
0010000000a87kj9
|
||||||
@@ -107,26 +107,39 @@ exports.RuleEngine = class RuleEngine {
|
|||||||
logger.log("debug", "Logic FLAT start - whiteFilterRule: " + JSON.stringify(theWhiteFilterRule));
|
logger.log("debug", "Logic FLAT start - whiteFilterRule: " + JSON.stringify(theWhiteFilterRule));
|
||||||
let isKnownComp = false;
|
let isKnownComp = false;
|
||||||
let retVal = 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 {
|
try {
|
||||||
if (theWhiteFilterRule.Comp === "===") {
|
if (theWhiteFilterRule.Comp === "===") {
|
||||||
isKnownComp = true;
|
isKnownComp = true;
|
||||||
if (inputData[theWhiteFilterRule.Field] === theWhiteFilterRule.Value) {retVal = true;}
|
if (dataValue === ruleValue) {retVal = true;}
|
||||||
} else if (theWhiteFilterRule.Comp === "<") {
|
} else if (theWhiteFilterRule.Comp === "<") {
|
||||||
isKnownComp = true;
|
isKnownComp = true;
|
||||||
if (inputData[theWhiteFilterRule.Field] < theWhiteFilterRule.Value) {retVal = true;}
|
if (dataValue < ruleValue) {retVal = true;}
|
||||||
} else if (theWhiteFilterRule.Comp === ">") {
|
} else if (theWhiteFilterRule.Comp === ">") {
|
||||||
isKnownComp = true;
|
isKnownComp = true;
|
||||||
if (inputData[theWhiteFilterRule.Field] > theWhiteFilterRule.Value) {retVal = true;}
|
if (dataValue > ruleValue) {retVal = true;}
|
||||||
} else if (theWhiteFilterRule.Comp === "<=") {
|
} else if (theWhiteFilterRule.Comp === "<=") {
|
||||||
isKnownComp = true;
|
isKnownComp = true;
|
||||||
if (inputData[theWhiteFilterRule.Field] <= theWhiteFilterRule.Value) {retVal = true;}
|
if (dataValue <= ruleValue) {retVal = true;}
|
||||||
} else if (theWhiteFilterRule.Comp === ">=") {
|
} else if (theWhiteFilterRule.Comp === ">=") {
|
||||||
isKnownComp = true;
|
isKnownComp = true;
|
||||||
if (inputData[theWhiteFilterRule.Field] >= theWhiteFilterRule.Value) {retVal = true;}
|
if (dataValue >= ruleValue) {retVal = true;}
|
||||||
} else if (theWhiteFilterRule.Comp === "~") {
|
} else if (theWhiteFilterRule.Comp === "~") {
|
||||||
isKnownComp = true;
|
isKnownComp = true;
|
||||||
logger.log("debug", "RegexFilter: " + theWhiteFilterRule.Value + " || " + ""+inputData[theWhiteFilterRule.Field].replace(/\r/g, "\\r").replace(/\n/g, "\\n"));
|
logger.log("debug", "RegexFilter: " + ruleValue + " || " + ""+dataValue.replace(/\r/g, "\\r").replace(/\n/g, "\\n"));
|
||||||
retVal = this.reTest(theWhiteFilterRule.Value, inputData[theWhiteFilterRule.Field]);
|
retVal = this.reTest(ruleValue, dataValue);
|
||||||
}
|
}
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
logger.log("error", "LogicFlat-Error " + ex + " WhiteFilterRule: " + JSON.stringify(theWhiteFilterRule) + " InputData " + JSON.stringify(inputData));
|
logger.log("error", "LogicFlat-Error " + ex + " WhiteFilterRule: " + JSON.stringify(theWhiteFilterRule) + " InputData " + JSON.stringify(inputData));
|
||||||
|
|||||||
@@ -45,20 +45,15 @@ function cb(){
|
|||||||
theMessage.processingType=processingType;
|
theMessage.processingType=processingType;
|
||||||
theMessage.sourceTag=config.sourceTag;
|
theMessage.sourceTag=config.sourceTag;
|
||||||
theMessage.timestamp=new Date();
|
theMessage.timestamp=new Date();
|
||||||
theDiskLimit.isWarn=false;
|
|
||||||
disk.check(theDiskLimit.path, function(err, info) {
|
disk.check(theDiskLimit.path, function(err, info) {
|
||||||
if (err) {
|
if (err) {
|
||||||
logger.log("error","Error reading disk Information " + err);
|
logger.log("error","Error reading disk Information " + err);
|
||||||
theDiskLimit.error = err;
|
theDiskLimit.error = err;
|
||||||
theDiskLimit.isWarn = true;
|
|
||||||
} else {
|
} else {
|
||||||
let availGB=info.available/1024/1024;
|
let availGB=info.available/1024/1024;
|
||||||
let totalGB=info.total/1024/1024;
|
let totalGB=info.total/1024/1024;
|
||||||
theDiskLimit.availGB=availGB;
|
theDiskLimit.availGB=availGB;
|
||||||
theDiskLimit.totalGB=totalGB;
|
theDiskLimit.totalGB=totalGB;
|
||||||
if (availGB<=theDiskLimit.minFree) {
|
|
||||||
theDiskLimit.isWarn=true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
theMessage.data=theDiskLimit;
|
theMessage.data=theDiskLimit;
|
||||||
logger.log("debug","Sending Message: " + JSON.stringify(theMessage));
|
logger.log("debug","Sending Message: " + JSON.stringify(theMessage));
|
||||||
|
|||||||
Binary file not shown.
@@ -1,5 +1,5 @@
|
|||||||
{ "diskusage":
|
{ "diskusage":
|
||||||
{ "rules":[
|
{ "rules":[
|
||||||
{ "Logic":"-", "Field":"isWarn", "Comp":"!==", "Value":true}
|
{ "Logic":"-", "dataType":"number", "Field":"availGB", "Comp":">", "Value":100}
|
||||||
]}
|
]}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user