4 Commits

Author SHA1 Message Date
a13d81e9c0 Merge branch 'release-1.1' 2021-12-03 10:53:35 +01:00
059c02e243 Merge branch 'dev' into release-1.1 2021-12-03 10:53:13 +01:00
a610f209d5 Merge branch 'release-1.1' 2021-12-02 14:08:54 +01:00
6e05a0b45c Merge branch 'release-1.0' 2021-11-29 15:55:27 +01:00
4 changed files with 22 additions and 45 deletions

View File

@@ -61,7 +61,7 @@ const AuthenticationType = {
OpenSystem_1: "OpenSystem_1",
OpenSystem_2: "OpenSystem_2",
Unknown: "Unknown",
};
}
class AuthenticationPacket extends Packet{
authenticationType;
}
@@ -81,7 +81,7 @@ const HandshakeStage = {
2: "2",
3: "3",
4: "4"
};
}
class HandshakePacket extends Packet{
handshakeStage;
}

View File

@@ -5,7 +5,6 @@ const logger = logFactory("main");
const { requireEnvVars } = require("./helper/env.js");
const { exit } = require("process");
const { exec } = require("./helper/exec.js");
const Os = require("os");
const { InfluxDB } = require("@influxdata/influxdb-client");
const InfluxChecks = require("./helper/influx-checks.js");
@@ -24,7 +23,6 @@ const env = process.env;
{
env.LOGLEVEL ??= "INFO";
env.WIFI_INTERFACE ??= "wlan0";
env.HOSTNAME ??= Os.hostname();
}
// Required vars
let errorMsg = requireEnvVars([
@@ -58,9 +56,6 @@ if(errorMsg){
exit(1);
});
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});
logger.info("Influx ok");
logger.info("Starting tcpdump..");
@@ -72,7 +67,7 @@ if(errorMsg){
let regexBlockStream = new RegexBlockStream(/^\d{2}:\d{2}:\d{2}.\d{6}.*(\n( {4,8}|\t\t?).*)+\n/gm);
let packetStreamFactory = new PacketStreamFactory();
let packetInfluxPointFactory = new PacketInfluxPointFactory();
let influxPointWriter = new InfluxPointWriter(influxWriteApi);
let influxPointWriter = new InfluxPointWriter(influxDb, env.INFLUX_ORG, env.INFLUX_BUCKET);
proc.stdout
.setEncoding("utf8")
.pipe(regexBlockStream)
@@ -82,22 +77,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 +112,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);

View File

@@ -1,6 +1,6 @@
const logger = require.main.require("./helper/logger.js")("InfluxPointWriter");
const { Writable } = require("stream");
const { WriteApi } = require("@influxdata/influxdb-client");
const {InfluxDB, Point, HttpError} = require("@influxdata/influxdb-client");
/**
* Get points and write them into influx
@@ -8,13 +8,16 @@ const { WriteApi } = require("@influxdata/influxdb-client");
class InfluxPointWriter extends Writable{
/**
*
* @param {WriteApi} writeApi WriteAPI from InfluxDB instance
* @param {InfluxDB} influxDb InfluxDb
* @param {string} org Organization to use
* @param {string} bucket Bucket to use
* @param {Partial<WriteOptions>} options Options for WriteApi
*/
constructor(writeApi){
constructor(influxDb, org, bucket, options){
super({
objectMode: true
});
this._api = writeApi;
this._api = influxDb.getWriteApi(org, bucket, "us", options);
}
_write(point, encoding, next){

View File

@@ -14,14 +14,14 @@ const TAG_LIST = [
/** Measurement-name and corresponding field-key */
const MEASUREMENT_MAP = new Map([
["rfmon_signal_dbm", "signal"],
["rfmon_payloadsize_bytes", "payloadSize"],
["rfmon_datarate_bytes", "dataRate"],
["rfmon_ssid_names", "ssid"],
["rfmon_authenticationtype_info", "authenticationType"],
["rfmon_associationsuccess_bools", "associationIsSuccessful"],
["rfmon_disassociationreason_info", "disassociationReason"],
["rfmon_handshakestage_info", "handshakeStage"],
["Signal", "signal"],
["PayloadSize", "payloadSize"],
["DataRate", "dataRate"],
["SSID", "ssid"],
["AuthenticationType", "authenticationType"],
["AssociationSuccess", "associationIsSuccessful"],
["DisassociationReason", "disassociationReason"],
["HandshakeStage", "handshakeStage"],
]);
@@ -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 */