Skip to content

Commit 3a1f55e

Browse files
committed
docs: enhance README files with detailed automation and data pipeline documentation
1 parent 092a62b commit 3a1f55e

13 files changed

Lines changed: 329 additions & 38 deletions

File tree

CHANGELOG.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,33 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [2.5] - 2025-10-18
9+
10+
### Added
11+
12+
- Automated file upload functionality with scheduling options
13+
- AWS S3 bucket region auto-detection
14+
- Enhanced configuration scripts with S3 discovery and validation
15+
- Improved status checking with AWS integration
16+
- Time interval filtering for CSV processing
17+
- Schedule type validation for log selections
18+
19+
### Changed
20+
21+
- Enhanced CSV processing logic with better error handling
22+
- Improved AWS_PROFILE handling across automation scripts
23+
- Streamlined user prompts and interaction flow
24+
- Updated configuration scripts for better error handling
25+
- Unified lolcat piping logic in install and main scripts
26+
- Improved temp file cleanup in test upload functions
27+
28+
### Fixed
29+
30+
- CSV processing error handling and output
31+
- Schedule type validation for non-castle log selections
32+
- Config loading with sudo-aware implementation
33+
- POSIX compliance in status scripts
34+
835
## [2.0] - 2025-01-28
936

1037
### Added

README.md

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,23 @@ chmod +x install.sh
4646

4747
## ⚙️ Automation
4848

49-
This project includes a powerful automation module for scheduling the entire log processing pipeline. It can be installed as a systemd service to run automatically, even when no user is logged in.
49+
Automation lives in scripts/data/automation and is fully documented there. It installs a systemd service/timer to run the collection → processing → filtering → upload/queue pipeline, with offline queueing and a guided configuration.
5050

51-
**[For full details, see the Automation Module Documentation](./scripts/data/automation/README.md)**
51+
See the complete guide: scripts/data/automation/README.md
52+
53+
---
54+
55+
## 📚 Documentation map
56+
57+
- scripts/data/README.md — Data pipeline overview and flow
58+
- scripts/data/collection/README.md — How logs are collected (v4/v5), outputs
59+
- scripts/data/process/README.md — Processing flow and CSV schemas
60+
- scripts/data/process/processors/README.md — Processor internals (log.py, logv2.py, castle.py)
61+
- scripts/data/upload/README.md — Manual upload flow and CSV month filtering
62+
- scripts/data/automation/README.md — Automation with systemd (install, configure, run, troubleshoot)
63+
- scripts/system/README.md — System operations (networking, modem, Wi‑Fi, Raspberry Pi config)
64+
- scripts/troubleshoot/README.md — Diagnostic tools (Kolibri, OC4D, storage, Wi‑Fi)
65+
- scripts/update/README.md — Update helpers (OS and tool)
66+
- scripts/vpn/README.md — VPN connect/disconnect/status
67+
- config/README.md — automation.conf settings, ownership, permissions
68+
- 00_DATA/README.md — Data directory layout and naming

config/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Config
2+
3+
- automation.conf — Generated by automation configure script. Controls server version, device location label, S3 bucket/prefix, schedule, and interval.
4+
5+
Ownership & permissions
6+
7+
- File is owned by the service user (typically pi) and chmod 600
8+
- The automation runner reads this file at runtime; use the Configure menu to edit it safely
9+
10+
Keys
11+
12+
- SERVER_VERSION (v1/v2), PYTHON_SCRIPT (oc4d/cape_coast_d)
13+
- DEVICE_LOCATION (label for folder and file naming)
14+
- S3_BUCKET (s3://bucket) and S3_SUBFOLDER (optional; files go under subfolder/RACHEL/)
15+
- SCHEDULE_TYPE and RUN_INTERVAL

scripts/data/README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Data Pipeline
2+
3+
Menus and scripts for collecting, processing, uploading, and automating analytics on CDN server logs.
4+
5+
Submodules
6+
7+
- collection — gathers logs from v4 (Apache) and v5 (OC4D)
8+
- process — parses logs into CSV summaries via processors
9+
- upload — manual month filtering and S3 upload
10+
- automation — unattended runs with systemd
11+
12+
End‑to‑end flow
13+
14+
1. Collect: copies logs into 00_DATA/LOCATION_logs_YYYY_MM_DD and decompresses .gz
15+
2. Process: writes 00_DATA/00_PROCESSED/RUN/summary.csv using the right processor
16+
3. Finalize + Upload: either manual (upload/) or scheduled (automation/runner.sh)
17+
18+
Data contracts
19+
20+
- Input logs (v4): text lines in Apache combined format (access.log\*)
21+
- Input logs (v5): JSON per line with a message field that embeds HTTP request data
22+
- Output CSV (summary.csv) columns (vary by processor) include at least:
23+
- IP Address, Access Date, Module Viewed, Status Code, Data Saved (GB), Device Used, Browser Used
24+
- Some processors (e.g., castle.py) also include Access Time and Location Viewed
25+
26+
Where to start
27+
28+
- Use ./scripts/data/main.sh to drive the whole flow, or jump into each submodule
29+
30+
See also: scripts/data/automation/README.md for unattended scheduling.

scripts/data/automation/README.md

Lines changed: 83 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,101 @@
1-
# Log Processor Automation Module
1+
# Automation (Log Processor)
22

3-
## 1. Overview
3+
This module installs and runs the end‑to‑end data pipeline on a schedule: collect logs → process to CSV → time‑window filter → upload to S3 (or queue if offline).
44

5-
This module automates the entire log processing pipeline, from data collection to uploading. It is designed to run as a reliable, unattended background service on a Linux server.
6-
The core of the automation is built using **systemd**, Linux's native service manager. This was chosen over other methods like `cron` because it offers superior logging via the system journal, better service dependency management, and more flexible timer configurations.
5+
Why systemd? It provides reliable scheduling (timer units), dependency handling, robust logging via journalctl, and runs without an interactive session.
76

8-
---
7+
Key features
98

10-
## 2. Key Features ✨
9+
- Scheduled runs via systemd timer (daily/weekly/monthly/custom; hourly for Castle logs)
10+
- Offline‑first: queues uploads in 00_DATA/00_UPLOAD_QUEUE and flushes next time online
11+
- Guided configuration with AWS bucket discovery and a live test upload
12+
- Status dashboard covering timer, queue, connectivity, and AWS identity
13+
- Dual logging to journalctl and /var/log/v5_log_processor/automation.log
1114

12-
- **Scheduled Execution**: Automatically runs the data pipeline on a configurable schedule using a dedicated `systemd` timer.
13-
- **Intelligent Offline Queueing**: If the internet is unavailable, processed files are automatically placed in an `00_DATA/00_UPLOAD_QUEUE` directory. The system flushes this queue by uploading all pending files the next time it runs with an active internet connection.
14-
- **Advanced Interactive Menu**: A user-friendly menu (enhanced with `whiptail` if available) for installing, checking status, and configuring the automation.
15-
- **Dynamic & Validated Configuration**: The configuration script dynamically discovers available S3 buckets and subfolders. Before saving, it performs a **live upload test** to validate that the chosen settings and AWS credentials are correct.
16-
- **Comprehensive Status Dashboard**: The status script provides a full health check, including timer status, queue contents, network connectivity, and AWS identity verification.
17-
- **Dual Logging**: All output is simultaneously logged to both the systemd journal (viewable with `journalctl`) and a persistent file at `/var/log/v5_log_processor/automation.log` for robust troubleshooting.
18-
- **Automatic AWS Region Detection**: The upload scripts automatically detect the correct AWS region for the target S3 bucket, eliminating the need for manual configuration.
15+
Prerequisites
1916

20-
---
17+
- Linux with systemd, bash, Python 3
18+
- AWS CLI installed and configured for the service user (typically pi)
19+
- Python dependencies for processors (see requirements.txt)
2120

22-
## 3. How It Works ⚙️
21+
Components
2322

24-
The automation follows a clear, multi-stage workflow triggered by a system timer.
23+
- main.sh — Menu entrypoint for Install, Status, Configure
24+
- install.sh — Creates service/timer and the wrapper at /usr/local/bin/run_v5_log_processor.sh
25+
- configure.sh — Writes config/automation.conf; discovers buckets/subfolders; validates with live test upload; sets schedule
26+
- runner.sh — Orchestrates the pipeline (collect → process → filter → upload/queue) and auto‑detects S3 bucket region
27+
- status.sh — Health/status report: timer/service, queue contents, connectivity, AWS identity, last logs
28+
- flush_queue.sh — Uploads any queued CSVs using per‑bucket region detection
29+
- filter_time_based.py — Builds final CSVs for hourly/daily/weekly; automation calls process_csv.py for monthly
30+
- /usr/local/bin/run_v5_log_processor.sh — Wrapper used by systemd to run runner.sh and tee output to both log and journal
2531

26-
1. **Timer Triggers**: At the scheduled time, the `v5-log-processor.timer` unit tells `systemd` to start the service. The schedule is managed via a robust override file in `/etc/systemd/system/v5-log-processor.timer.d/`.
27-
2. **Service Runs**: The `v5-log-processor.service` unit executes the main wrapper script located at `/usr/local/bin/run_v5_log_processor.sh`.
28-
3. **Pipeline Initiated**: The wrapper script is responsible for setting up the environment. It navigates to the project directory and executes the main pipeline script, `scripts/data/automation/runner.sh`. It also uses the `tee` command to pipe all output to both the journal and the log file.
29-
4. **Configuration Loaded**: The `runner.sh` script sources its settings from `config/automation.conf`, loading the correct Server Version, S3 Bucket, etc.
30-
5. **The Data Workflow (executed by `runner.sh`)**:
31-
- **Collect**: The script collects raw server logs based on the `SERVER_VERSION` setting.
32-
- **Process**: The collected logs are cleaned and transformed into a `summary.csv` by the appropriate Python processor (`log.py`, `logv2.py`, or `castle.py`), which is selected based on the `SERVER_VERSION` and `PYTHON_SCRIPT` variables.
33-
- **Filter & Finalize**: The `summary.csv` is further processed by `process_csv.py` to generate the final, month-specific CSV file.
34-
- **Upload or Queue**: The script checks for internet connectivity.
35-
- If **online**, it first runs the `flush_queue.sh` logic to upload any previously queued files, then uploads the newly generated file.
36-
- If **offline**, it copies the new file to the `00_DATA/00_UPLOAD_QUEUE` directory to be uploaded later.
32+
Configuration (config/automation.conf)
3733

38-
---
34+
Written by configure.sh and kept inside the repo so the automation can run from the project directory.
3935

40-
## 4. Usage and Management
36+
- SERVER_VERSION: v1 (Server v4/Apache) or v2 (Server v5/OC4D)
37+
- PYTHON_SCRIPT: oc4d or cape_coast_d (only v2)
38+
- DEVICE_LOCATION: short label used in folder names and output filenames
39+
- S3_BUCKET: s3://bucket‑name
40+
- S3_SUBFOLDER: optional prefix under the bucket; files go to subfolder/RACHEL/
41+
- SCHEDULE_TYPE: hourly (castle only), daily, weekly, monthly, or custom
42+
- RUN_INTERVAL: for custom schedules (seconds, >= 300)
4143

42-
To manage the automation, navigate to the project root and run the menu script.
44+
Data flow
4345

44-
```bash
45-
./main.sh
46+
1. Collect
4647

48+
- v1/v4: copies /var/log/apache2 access.log\* into 00_DATA/LOCATION_logs_YYYY_MM_DD
49+
- v2/v5: copies /var/log/oc4d oc4d-_.log, capecoastcastle-_.log, and \*.gz (excludes exceptions)
50+
- Gzip files are decompressed
4751

48-
---
52+
1. Process
4953

50-
## ⚙️ Automation
54+
- Chooses processor based on SERVER_VERSION and PYTHON_SCRIPT:
55+
- v1/v4 → scripts/data/process/processors/log.py
56+
- v2/v5 (oc4d) → scripts/data/process/processors/logv2.py
57+
- v2/v5 (cape_coast_d) → scripts/data/process/processors/castle.py
58+
- Produces 00_DATA/00_PROCESSED/RUN_FOLDER/summary.csv
5159

52-
This project includes a powerful automation module for scheduling the entire log processing pipeline. It can be installed as a systemd service to run automatically, even when no user is logged in.
60+
1. Filter to final CSV
5361

54-
**[For full details, see the Automation Module Documentation](./scripts/data/automation/README.md)**
62+
- hourly/daily/weekly → filter_time_based.py selects the last completed window and writes a device‑named CSV in the same folder; it prints the filename to stdout
63+
- monthly → scripts/data/upload/process_csv.py runs in filename mode to create LOCATION_MM_YYYY.csv and prints the filename
64+
65+
1. Upload or queue
66+
67+
- Connectivity check: if online, first flush queued files, then upload the new one using per‑bucket region detection; if offline, copy the new file to 00_DATA/00_UPLOAD_QUEUE
68+
69+
Scheduling
70+
71+
- Timer unit: v5-log-processor.timer
72+
- Service unit: v5-log-processor.service
73+
- Schedule is applied via override at /etc/systemd/system/v5-log-processor.timer.d/override.conf
74+
- Modes:
75+
- hourly (only when PYTHON_SCRIPT=cape_coast_d)
76+
- daily, weekly, monthly
77+
- custom interval via OnUnitActiveSec=RUN_INTERVAL
78+
- Timers are Persistent=true, so missed runs trigger shortly after boot
79+
80+
Where things live
81+
82+
- Config: config/automation.conf (chmod 600, owned by the service user)
83+
- Raw runs: 00_DATA/<DEVICE_LOCATION>\_logs_YYYY_MM_DD/
84+
- Processed: 00_DATA/00_PROCESSED/<DEVICE_LOCATION>\_logs_YYYY_MM_DD/
85+
- Queue: 00_DATA/00_UPLOAD_QUEUE/
86+
- Logs: /var/log/v5_log_processor/automation.log and journalctl -u v5-log-processor.service
87+
88+
Commands
89+
90+
- Install: sudo ./scripts/data/automation/install.sh
91+
- Configure: sudo ./scripts/data/automation/configure.sh
92+
- Status: ./scripts/data/automation/status.sh
93+
- Manual run (wrapper): sudo /usr/local/bin/run_v5_log_processor.sh
94+
95+
Troubleshooting
96+
97+
- Use ./scripts/data/automation/status.sh to quickly see timer state, next/last run, queue, connectivity, and AWS identity
98+
- If uploads fail, runner auto‑detects bucket region but credentials/policies can still block PUT; run Configure and use the live test or aws sts get-caller-identity
99+
- “No new entries matched the time period” means summary.csv existed but didn’t contain rows in the last completed window
100+
- If config can’t be read, ensure config/automation.conf exists and is readable; Configure will recreate it with correct ownership and perms
101+
- To disable, sudo systemctl stop v5-log-processor.timer && sudo systemctl disable v5-log-processor.timer

scripts/data/collection/README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Collection
2+
3+
Collect server logs from:
4+
5+
- v4 (Apache) at /var/log/apache2 (access.log\*)
6+
- v5 (OC4D) at /var/log/oc4d (oc4d-_.log, capecoastcastle-_.log, *.gz; excludes *exceptions\*)
7+
8+
Outputs
9+
10+
- Creates a run folder in 00_DATA named LOCATION_logs_YYYY_MM_DD and copies relevant files there
11+
- Decompresses any .gz files in-place
12+
- Skips exception logs (e.g., oc4d-exceptions-\*.log) to avoid noise
13+
14+
Usage
15+
16+
- Run the menu: ./scripts/data/collection/main.sh
17+
- To collect directly: ./scripts/data/collection/all.sh
18+
19+
Inner workings
20+
21+
- The script prompts for server type (v4 or v5) and device location (used in the folder name)
22+
- v4 copies files matching access.log\* from /var/log/apache2
23+
- v5 copies:
24+
- oc4d-_.log (excluding oc4d-exceptions-_.log)
25+
- capecoastcastle-_.log (excluding capecoastcastle-exceptions-_.log)
26+
- any \*.gz files
27+
- After copying, .gz files are decompressed so processors can read plain text
28+
- The resulting folder is moved into 00_DATA for the processing stage

scripts/data/process/README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Processing
2+
3+
Turn collected logs into CSV summaries.
4+
5+
Processors
6+
7+
- v1/v4 → scripts/data/process/processors/log.py
8+
- v2/v5 (oc4d) → scripts/data/process/processors/logv2.py
9+
- v2/v5 (cape_coast_d) → scripts/data/process/processors/castle.py
10+
11+
Outputs
12+
13+
- summary.csv written to 00_DATA/00_PROCESSED/RUN_FOLDER/
14+
- Individual per-file CSVs are also generated alongside summary.csv
15+
16+
CSV schemas
17+
18+
- v4/log.py: columns = [IP Address, Access Date, Module Viewed, Status Code, Data Saved (GB), Device Used, Browser Used]
19+
- v5/logv2.py: columns = [IP Address, Access Date, Module Viewed, Status Code, Data Saved (GB), Device Used, Browser Used]
20+
- v5/castle.py: columns = [IP Address, Access Date, Access Time, Module Viewed, Location Viewed, Status Code, Data Saved (GB), Device Used, Browser Used]
21+
22+
Notes & edge cases
23+
24+
- logv2.py expects each line to be JSON with a message field containing a combined-log-like string
25+
- castle.py parses a more structured message; it logs regex and timestamp errors into error_log.txt in the processed folder and normalizes IPv6 ::ffff: prefix
26+
- All processors normalize sizes to gigabytes and parse user agents to OS family and browser family
27+
28+
Usage
29+
30+
- Menu: ./scripts/data/process/main.sh
31+
- Direct: ./scripts/data/process/logs.sh
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Processors
2+
3+
Python scripts that parse logs and build summary.csv.
4+
5+
- log.py — Apache (Server v4) access logs
6+
- logv2.py — OC4D (Server v5) logs
7+
- castle.py — Cape Coast Castle variant of v5 logs
8+
9+
Implementation notes
10+
11+
- Ensure required Python packages in requirements.txt are installed
12+
- Regexes in the processors must match the actual log format; prefer named groups to avoid index drift
13+
- Inputs: v4 expects Apache combined lines; v5 expects JSON lines with a message
14+
- Outputs: per-file CSVs and a run-level summary.csv (headers vary per processor; see parent README)
15+
- Error handling: castle.py writes JSON/regex/timestamp issues to error_log.txt; logv2.py prints skipped lines
16+
- Performance: processors stream line-by-line; summary.csv is combined from per-file CSVs to keep memory steady

scripts/data/upload/README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Upload
2+
3+
Manual upload tools and helpers.
4+
5+
Main pieces
6+
7+
- upload.sh — pick a processed run and send the final CSV to S3
8+
- process_csv.py — filter summary.csv for a month and produce LOCATION_MM_YYYY.csv (also used by automation in filename mode)
9+
- s3_bucket.sh — helper to pick/validate buckets (if present)
10+
11+
Usage
12+
13+
- Menu: ./scripts/data/upload/main.sh
14+
- Direct: ./scripts/data/upload/upload.sh
15+
16+
Inner workings
17+
18+
- upload.sh lists processed run folders (matching _log_) under 00_DATA/00_PROCESSED and prompts for selection
19+
- It makes a working copy of summary.csv (summary_copy.csv) and invokes process_csv.py with:
20+
- folder path, device location (prompted), month (prompted, normalized to 2 digits), and input filename
21+
- in manual mode, process_csv.py prints the year; the final file is LOCATION_MM_YYYY.csv
22+
- The script then prompts for an S3 subfolder and uploads to s3://rachel-upload-test/subfolder/RACHEL/LOCATION_MM_YYYY.csv
23+
24+
Error modes
25+
26+
- Missing summary.csv: script exits and returns to menu
27+
- Empty filtered dataset: process_csv.py prints nothing; no upload is attempted
28+
- AWS CLI errors: surfaced to the terminal; verify credentials/region

scripts/system/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# System
2+
3+
Utilities for system configuration and maintenance.
4+
5+
- networking.sh and networking/ — IP, interfaces, diagnostics
6+
- modem.sh — USB modem connect
7+
- wifi-name.sh / wifi-password.sh — manage Wi‑Fi AP settings
8+
- raspi-config.sh — run Raspberry Pi config
9+
- reboot.sh / shutdown.sh — power controls
10+
11+
Inner workings
12+
13+
- Networking tasks use ip and ifconfig where available; the networking/ folder may include helpers for routes and status
14+
- Wi‑Fi name/password scripts edit hostapd configuration (files/hostapd_secure.conf)
15+
- Commands are run with care; some actions may require sudo depending on the environment

0 commit comments

Comments
 (0)