From 4423aa4c18b9d8246b04ef20cab478980f78f546 Mon Sep 17 00:00:00 2001 From: catttam Date: Tue, 10 Sep 2024 15:59:26 +0200 Subject: [PATCH] Changed parser methods --- extract_goaccess_metrics.sh | 7 +++++-- goaccess_metric_parser.py | 17 +++++++++-------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/extract_goaccess_metrics.sh b/extract_goaccess_metrics.sh index fc2971a..65b59d0 100755 --- a/extract_goaccess_metrics.sh +++ b/extract_goaccess_metrics.sh @@ -23,7 +23,10 @@ metrics(){ LOG_FILE=$1 filename=`basename "$LOG_FILE"` geo_err=$( { goaccess "${LOG_FILE}" --log-format="${LOG_FORMAT}" -o "${OUTPUTS_PATH}/${filename}_full.json" --json-pretty-print; } 2>&1 ) - python3 goaccess_metric_parser.py -f "${OUTPUTS_PATH}/${filename}_full.json" -g 0 + if [[ $filename == "latest"* ]]; then + python3 goaccess_metric_parser.py -f "${OUTPUTS_PATH}/${filename}_full.json" -g 0 + else + python3 goaccess_metric_parser.py -f "${OUTPUTS_PATH}/${filename}_full.json" -g 0 -u status_codes=('200' '204' '404' '500') init="t" @@ -70,7 +73,7 @@ done for logfile in "$LOCAL_LOGS_DIR/$log/controller/"*; do if [[ $logfile == *".log"* ]]; then - if [[ $logfile == *".log"]]; then + if [[ $logfile == *".log" ]]; then cat $logfile | grep -a 'oscar-oscar' | grep -a '/job\|/run' | tee -a $LATEST_LOGS >/dev/null metrics $LATEST_LOGS else diff --git a/goaccess_metric_parser.py b/goaccess_metric_parser.py index 997b116..aee02ba 100644 --- a/goaccess_metric_parser.py +++ b/goaccess_metric_parser.py @@ -39,9 +39,9 @@ > Countries reached > Output format: {continent, country, total_visits, unique_visits, start_date, end_date} """ -def parse_geolocation_info(): +def parse_geolocation_info(write_type): - with open(f'{OUTPUT_PATH}/geolocation_metrics.csv', 'w', newline='') as gfile: + with open(f'{OUTPUT_PATH}/geolocation_metrics.csv', write_type, newline='') as gfile: writer = csv.writer(gfile) fields = ["continent", "country", "total_visits", "unique_visits", "start_metric_date", "end_metric_date"] writer.writerow(fields) @@ -111,13 +111,14 @@ def parse_requests_info(status_code, write_type): sfile.close() +wr="w" +if args.use_existing: + wr="a" + if args.general: - parse_geolocation_info() -elif args.partial: - if args.use_existing: - parse_requests_info(args.status_code, "a") - else: - parse_requests_info(args.status_code, "w") + parse_geolocation_info(wr) +if args.partial: + parse_requests_info(args.status_code, wr)