Allow for printing the errors when you need to fix the parsing.

master
Zed A. Shaw 2 years ago
parent 7d22b1894f
commit cf527da326
  1. 7
      02-filter-a-log-file/chains_parser.js
  2. 14
      02-filter-a-log-file/package-lock.json
  3. 1
      02-filter-a-log-file/package.json

@ -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);

@ -10,6 +10,7 @@
"license": "BSD",
"dependencies": {
"ava": "^4.3.1",
"commander": "^9.4.0",
"date-fns": "^2.29.1",
"ua-parser-js": "^1.0.2"
}
@ -454,6 +455,14 @@
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA=="
},
"node_modules/commander": {
"version": "9.4.0",
"resolved": "https://registry.npmjs.org/commander/-/commander-9.4.0.tgz",
"integrity": "sha512-sRPT+umqkz90UA8M1yqYfnHlZA7fF6nSphDtxeywPZ49ysjxDQybzk13CL+mXekDRG92skbcqCLVovuCusNmFw==",
"engines": {
"node": "^12.20.0 || >=14"
}
},
"node_modules/common-path-prefix": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/common-path-prefix/-/common-path-prefix-3.0.0.tgz",
@ -2139,6 +2148,11 @@
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA=="
},
"commander": {
"version": "9.4.0",
"resolved": "https://registry.npmjs.org/commander/-/commander-9.4.0.tgz",
"integrity": "sha512-sRPT+umqkz90UA8M1yqYfnHlZA7fF6nSphDtxeywPZ49ysjxDQybzk13CL+mXekDRG92skbcqCLVovuCusNmFw=="
},
"common-path-prefix": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/common-path-prefix/-/common-path-prefix-3.0.0.tgz",

@ -11,6 +11,7 @@
"license": "BSD",
"dependencies": {
"ava": "^4.3.1",
"commander": "^9.4.0",
"date-fns": "^2.29.1",
"ua-parser-js": "^1.0.2"
}

Loading…
Cancel
Save