Compare commits

..

No commits in common. "39350932a48f791e1bd6443d19924eb9417053ca" and "57cf6fb0a7ae8b106278d843821339502a8a1645" have entirely different histories.

4 changed files with 21 additions and 23 deletions

View File

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

View File

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

View File

@ -1,6 +1,6 @@
const logger = require.main.require("./helper/logger.js")("InfluxPointWriter"); const logger = require.main.require("./helper/logger.js")("InfluxPointWriter");
const { Writable } = require("stream"); 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 * Get points and write them into influx
@ -8,13 +8,16 @@ const { WriteApi } = require("@influxdata/influxdb-client");
class InfluxPointWriter extends Writable{ 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({ super({
objectMode: true objectMode: true
}); });
this._api = writeApi; this._api = influxDb.getWriteApi(org, bucket, "us", options);
} }
_write(point, encoding, next){ _write(point, encoding, next){

View File

@ -4,24 +4,24 @@ const {Point} = require("@influxdata/influxdb-client");
/** Keys to always use as tags */ /** Keys to always use as tags */
const TAG_LIST = [ const TAG_LIST = [
"srcmac", "srcMac",
"dstmac", "dstMac",
"bssid", "bssid",
"frequency", "frequency",
"flags", "flags",
"packettype", "packetType",
]; ];
/** Measurement-name and corresponding field-key */ /** Measurement-name and corresponding field-key */
const MEASUREMENT_MAP = new Map([ const MEASUREMENT_MAP = new Map([
["rfmon_signal_dbm", "signal"], ["Signal", "signal"],
["rfmon_payloadsize_bytes", "payloadSize"], ["PayloadSize", "payloadSize"],
["rfmon_datarate_bytes", "dataRate"], ["DataRate", "dataRate"],
["rfmon_ssid_names", "ssid"], ["SSID", "ssid"],
["rfmon_authenticationtype_info", "authenticationType"], ["AuthenticationType", "authenticationType"],
["rfmon_associationsuccess_bools", "associationIsSuccessful"], ["AssociationSuccess", "associationIsSuccessful"],
["rfmon_disassociationreason_info", "disassociationReason"], ["DisassociationReason", "disassociationReason"],
["rfmon_handshakestage_info", "handshakeStage"], ["HandshakeStage", "handshakeStage"],
]); ]);