@@ -6,6 +6,8 @@ import { program } from "commander"
6
6
import { prepareResponse , compileHost , pushAlert } from "./utils"
7
7
import ndjson from "ndjson"
8
8
import { Mutex , MutexInterface } from "async-mutex"
9
+ import dotenv from "dotenv"
10
+
9
11
10
12
var server : net . Server
11
13
var connections : Record < number , net . Socket > = { }
@@ -86,15 +88,24 @@ function main() {
86
88
. name ( "AWS-Suricata Ingestor" )
87
89
. description ( "Basic CLI app to ingest data from suricata on AWS" )
88
90
program
89
- . requiredOption ( "-u, --url <url>" , "URL for the webhook destination" )
90
- . requiredOption ( "-k, --key <api_key>" , "API Key for the webhook destination" )
91
91
. 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" )
92
95
program . parse ( process . argv )
93
96
let options = program . opts ( )
94
- if ( new URL ( options . url ) ) {
97
+ SOCKETFILE = options . socket
98
+ if ( options . url && new URL ( options . url ) ) {
95
99
url = options . url
96
100
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" )
98
109
}
99
110
100
111
console . info ( "Socket: %s \n Process: %s" , SOCKETFILE , process . pid )
0 commit comments