Add centralized constants module and .env configuration support
This commit is contained in:
1 parent
94be1da199
commit
eea5ef6885
14 files changed
+334
-126
No files matched your search
+13
-13
@@ -13,16 +13,17 @@ import re
|
||||
from collections import Counter
|
||||
|
||||
from .analyzer import Analyzer
|
||||
from .constants import (
|
||||
DEFAULT_ERROR_RATIO,
|
||||
DEFAULT_MIN_ERRORS,
|
||||
NPM_LOG_PATH,
|
||||
NPM_REPORT_DIR,
|
||||
)
|
||||
from .files import write_csv
|
||||
from .flags import flag_scanners
|
||||
from .models import Request
|
||||
from .utils import arg_parser
|
||||
|
||||
|
||||
DEFAULT_LOG_PATH = os.environ.get("NPM_LOG_PATH", r"Y:\npm\logs")
|
||||
DEFAULT_REPORT_DIR = os.path.join(
|
||||
os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "reports", "npm")
|
||||
|
||||
# [02/Aug/2026:05:01:31 +0200] - 401 401 - GET https host "/path"
|
||||
# [Client IP] [Length N] [Gzip X] [Sent-to IP] "UA" "Referer"
|
||||
LINE_RE = re.compile(
|
||||
@@ -83,8 +84,8 @@ class NpmAnalyzer(Analyzer):
|
||||
("ua", lambda r: r.ua),
|
||||
)
|
||||
|
||||
def __init__(self, *args, min_errors: int = 5,
|
||||
error_ratio: float = 0.5, **kwargs):
|
||||
def __init__(self, *args, min_errors: int = DEFAULT_MIN_ERRORS,
|
||||
error_ratio: float = DEFAULT_ERROR_RATIO, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.min_errors = min_errors
|
||||
self.min_ratio = error_ratio
|
||||
@@ -145,11 +146,11 @@ class NpmAnalyzer(Analyzer):
|
||||
def main() -> None:
|
||||
parser = arg_parser(
|
||||
"analyze NPM proxy logs, flag scanner IPs, export MikroTik rules",
|
||||
DEFAULT_LOG_PATH, DEFAULT_REPORT_DIR)
|
||||
parser.add_argument("--min-errors", type=int, default=5,
|
||||
help="minimum error responses to flag (default: 5)")
|
||||
parser.add_argument("--error-ratio", type=float, default=0.5,
|
||||
help="minimum error ratio to flag (default: 0.5)")
|
||||
NPM_LOG_PATH, NPM_REPORT_DIR)
|
||||
parser.add_argument("--min-errors", type=int, default=DEFAULT_MIN_ERRORS,
|
||||
help=f"minimum error responses to flag (default: {DEFAULT_MIN_ERRORS})")
|
||||
parser.add_argument("--error-ratio", type=float, default=DEFAULT_ERROR_RATIO,
|
||||
help=f"minimum error ratio to flag (default: {DEFAULT_ERROR_RATIO})")
|
||||
args = parser.parse_args()
|
||||
|
||||
NpmAnalyzer(
|
||||
@@ -157,7 +158,6 @@ def main() -> None:
|
||||
report_dir=args.report_dir,
|
||||
top=args.top,
|
||||
quiet=args.quiet,
|
||||
write_rsc=not args.no_rsc,
|
||||
min_errors=args.min_errors,
|
||||
error_ratio=args.error_ratio,
|
||||
).run()
|
||||
|
||||
Reference in new issue
Block a user