|
|
|
@ -139,7 +139,7 @@ class Parser { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const parse_logs = async (file_name) => { |
|
|
|
|
const parse_logs = async (file_name, errors) => { |
|
|
|
|
const read_stream = fs.createReadStream(file_name); |
|
|
|
|
|
|
|
|
|
const rl = readline.createInterface({ |
|
|
|
@ -179,6 +179,8 @@ const parse_logs = async (file_name) => { |
|
|
|
|
|
|
|
|
|
by_ip[data.ip] = ip_chain; |
|
|
|
|
} catch(error) { |
|
|
|
|
if(errors) console.error(error); |
|
|
|
|
|
|
|
|
|
stats.errors += 1; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -242,6 +244,7 @@ const output_results = (min, chains_sorted) => { |
|
|
|
|
program |
|
|
|
|
.option("--no-set", "Use a Set instead of a list for chains.") |
|
|
|
|
.option("--min <Number>", "The lowest count to print. Stop at this.", 1) |
|
|
|
|
.option("--errors", "Show the erorrs so you can fix them.", false) |
|
|
|
|
.requiredOption("--input <String>", "Input file.") |
|
|
|
|
.description("Processes different web server logs to determine request chain frequency.") |
|
|
|
|
.version(0.1); |
|
|
|
@ -252,6 +255,6 @@ OPTS.min = parseInt(OPTS.min); |
|
|
|
|
|
|
|
|
|
assert(!isNaN(OPTS.min), `min must be a number, you have ${OPTS.min}`); |
|
|
|
|
|
|
|
|
|
const [by_ip, stats] = await parse_logs(OPTS.input); |
|
|
|
|
const [by_ip, stats] = await parse_logs(OPTS.input, OPTS.errors); |
|
|
|
|
const chains_sorted = sort_request_chains(by_ip, OPTS.set); |
|
|
|
|
output_results(OPTS.min, chains_sorted); |
|
|
|
|