Compare commits
6 Commits
7c5c37e9b5
...
v2.0.1
| Author | SHA1 | Date | |
|---|---|---|---|
| c3cd6393d4 | |||
| c97137f4a7 | |||
| a13d81e9c0 | |||
| 059c02e243 | |||
| a610f209d5 | |||
| 6e05a0b45c |
26
src/main.js
26
src/main.js
@@ -60,7 +60,7 @@ if(errorMsg){
|
||||
|
||||
logger.debug("Get WriteApi & set default-hostname to", `'${env.HOSTNAME}'`);
|
||||
const influxWriteApi = influxDb.getWriteApi(env.INFLUX_ORG, env.INFLUX_BUCKET, "us");
|
||||
//influxWriteApi.useDefaultTags({"hostname": env.HOSTNAME});
|
||||
influxWriteApi.useDefaultTags({"hostname": env.HOSTNAME});
|
||||
logger.info("Influx ok");
|
||||
|
||||
logger.info("Starting tcpdump..");
|
||||
@@ -82,22 +82,9 @@ if(errorMsg){
|
||||
|
||||
logger.debug("Attaching error-logger..");
|
||||
const loggerTcpdump = logFactory("tcpdump");
|
||||
let linkTypeId;
|
||||
proc.stderr.setEncoding("utf8").on("data", (data) => {
|
||||
if(!data.match(/^(tcpdump: )?listening on /i) || !data.match(/^\d+ packets captured/i)) { // Catch start-error
|
||||
loggerTcpdump.debug(data);
|
||||
|
||||
if(!linkTypeId && data.match(/^(tcpdump: )?listening on/i)){ // Grab first data containing listen-info if proper header was found
|
||||
const linkType = data.match(/((?<=link-type ))([a-z].*?) \(.*?\)(?=,)/i)[0];
|
||||
const linkTypeData = linkType.match(/(\S*) (.*)/i);
|
||||
const linkTypeId = linkTypeData[1];
|
||||
const linkTypeDetail = linkTypeData[2];
|
||||
|
||||
if(linkTypeId !== "IEEE802_11_RADIO"){
|
||||
logger.error(`Interface not in Monitor-mode! (Expected 'IEEE802_11_RADIO', but got '${linkTypeId}')`);
|
||||
shutdown(1, "SIGKILL");
|
||||
}
|
||||
}
|
||||
}
|
||||
else loggerTcpdump.error(data);
|
||||
});
|
||||
@@ -130,22 +117,17 @@ if(errorMsg){
|
||||
loggerTcpdump.debug(`tcpdump exited code: ${code}`);
|
||||
if (code) {
|
||||
loggerTcpdump.fatal(`tcpdump exited with non-zero code: ${code}`);
|
||||
if(!exitCode) exitCode = 1; // When exitCode is 0, set to 1
|
||||
exit(1);
|
||||
}
|
||||
logger.info("Shutdown");
|
||||
exit(exitCode);
|
||||
exit(0);
|
||||
});
|
||||
|
||||
// Handle stop-signals for graceful shutdown
|
||||
var exitCode = 0;
|
||||
function shutdownReq() {
|
||||
logger.info("Shutdown request received..");
|
||||
shutdown();
|
||||
}
|
||||
function shutdown(code, signal = "SIGTERM"){
|
||||
if(code) exitCode = code;
|
||||
logger.debug("Stopping subprocess tcpdump, then exiting myself..");
|
||||
proc.kill(signal); // Kill process, then upper event-handler will stop self
|
||||
proc.kill(); // Kill process (send SIGTERM), then upper event-handler will stop self
|
||||
}
|
||||
process.on("SIGTERM", shutdownReq);
|
||||
process.on("SIGINT", shutdownReq);
|
||||
|
||||
@@ -4,12 +4,12 @@ const {Point} = require("@influxdata/influxdb-client");
|
||||
|
||||
/** Keys to always use as tags */
|
||||
const TAG_LIST = [
|
||||
"srcMac",
|
||||
"dstMac",
|
||||
"srcmac",
|
||||
"dstmac",
|
||||
"bssid",
|
||||
"frequency",
|
||||
"flags",
|
||||
"packetType",
|
||||
"packettype",
|
||||
];
|
||||
|
||||
/** Measurement-name and corresponding field-key */
|
||||
@@ -66,10 +66,7 @@ function tagObjectRecursively(point, tag, field, suffix = ""){
|
||||
tagObjectRecursively(point, tag, value, `_${key}${suffix}`);
|
||||
});
|
||||
}
|
||||
else {
|
||||
const name = (tag+suffix).toLowerCase();
|
||||
point.tag(name, field);
|
||||
}
|
||||
else point.tag(tag+suffix, field);
|
||||
}
|
||||
|
||||
/** Mapping for type -> field-method */
|
||||
|
||||
Reference in New Issue
Block a user