Skip to content

Commit 81c8312

Browse files
(feature) Pull variables from env file for ingestor (metlo-labs#57)
1 parent f6e3aa7 commit 81c8312

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

ingestors/suricata/index.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import { program } from "commander"
66
import { prepareResponse, compileHost, pushAlert } from "./utils"
77
import ndjson from "ndjson"
88
import { Mutex, MutexInterface } from "async-mutex"
9+
import dotenv from "dotenv"
10+
911

1012
var server: net.Server
1113
var connections: Record<number, net.Socket> = {}
@@ -86,15 +88,24 @@ function main() {
8688
.name("AWS-Suricata Ingestor")
8789
.description("Basic CLI app to ingest data from suricata on AWS")
8890
program
89-
.requiredOption("-u, --url <url>", "URL for the webhook destination")
90-
.requiredOption("-k, --key <api_key>", "API Key for the webhook destination")
9191
.requiredOption("-s, --socket <socket_path>", "Socket file path")
92+
.option("-e, --env <path>", "Env file path")
93+
.option("-u, --url <url>", "URL for the webhook destination")
94+
.option("-k, --key <api_key>", "API Key for the webhook destination")
9295
program.parse(process.argv)
9396
let options = program.opts()
94-
if (new URL(options.url)) {
97+
SOCKETFILE = options.socket
98+
if (options.url && new URL(options.url)) {
9599
url = options.url
96100
api_key = options.key
97-
SOCKETFILE = options.socket
101+
} else if (options.env) {
102+
dotenv.config({ path: options.env })
103+
if (process.env.METLO_ADDR && process.env.METLO_KEY) {
104+
url = process.env.METLO_ADDR + "/api/v1/log-request/single"
105+
api_key = process.env.METLO_KEY
106+
}
107+
} else {
108+
throw new Error("Neither url/key or env params defined. Must choose either of options")
98109
}
99110

100111
console.info("Socket: %s \n Process: %s", SOCKETFILE, process.pid)

ingestors/suricata/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"async-mutex": "^0.4.0",
1010
"axios": "^0.27.2",
1111
"commander": "^9.4.0",
12+
"dotenv": "^16.0.3",
1213
"ndjson": "^2.0.0",
1314
"ts-node": "^10.9.1",
1415
"tsc": "^2.0.4",

ingestors/suricata/yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ diff@^4.0.1:
114114
resolved "https://registry.yarnpkg.com/diff/-/diff-4.0.2.tgz#60f3aecb89d5fae520c11aa19efc2bb982aade7d"
115115
integrity sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==
116116

117+
dotenv@^16.0.3:
118+
version "16.0.3"
119+
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.0.3.tgz#115aec42bac5053db3c456db30cc243a5a836a07"
120+
integrity sha512-7GO6HghkA5fYG9TYnNxi14/7K9f5occMlp3zXAuSxn7CKCxt9xbNWG7yF8hTCSUchlfWSe3uLmlPfigevRItzQ==
121+
117122
follow-redirects@^1.14.9:
118123
version "1.15.1"
119124
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.1.tgz#0ca6a452306c9b276e4d3127483e29575e207ad5"

0 commit comments

Comments
 (0)