This project is designed to analyze AWS VPC Flow Logs. It parses flow log data and maps each log entry to a tag based on a provided lookup table. The program processes log files and generates statistical output about the analyzed logs.
flow-log-analysis/
├── cmd/
│ └── flow-log-analysis/
│ └── flow-log-analysis.go
├── internal/
│ ├── parser/
│ │ └── parser.go
│ └── output/
│ └── output.go
├── data/
│ ├── lookup.csv
│ └── flowlog.txt
├── go.mod
└── README.md
This project uses only Go standard libraries:
bufio: For efficient file readingencoding/csv: For CSV file operationsflag: For command-line flag parsingfmt: For formatted I/Oos: For file system operationspath/filepath: For file path manipulationssort: For sorting slicesstrconv: For string conversionsstrings: For string operations
- Each flow log entry should have 14 fields, which is the default log format. Entries with fewer fields will be skipped.
- Only Version 2 log entries will be parsed. The program checks the first field of each log entry to ensure it's "2".
- The lookup table is a CSV file with columns: dstport, protocol, and tag.
- Visit the official Go download page.
- Download the installer for your operating system.
- Follow the installation instructions for your OS.
- Verify the installation by opening a terminal and running:
go version
- Clone this repository:
git clone https://github.com/yourusername/flow-log-analysis.git
cd flow-log-analysis
- Build the program:
go build -o flow-analyzer ./cmd/flow-log-analysis
- Run the program:
./flow-analyzer -lookup ./data/lookup.txt -log ./data/flowlog.txt -output .
The program generates two CSV files in the specified output directory:
tag_counts.txt: Contains the count of each tag found in the log file.port_protocol_counts.txt: Contains the count of each unique port/protocol combination.
The following tests and validations were performed:
- Log entry with fewer than 14 fields:
- Added a log entry with only 13 fields.
- Result: The parsing on the entry was skipped
- Log entry with version 3 instead of version 2:
- Added a log entry starting with "3" instead of "2".
- Result: The entry was skipped, and a warning was logged.
- Empty log file:
- Tested with an empty log file.
- Result: The program completed successfully with empty output files.
- Case sensitivity:
- Tested with mixed case in log entries and lookup table.
- Result: Matching was performed case-insensitively as required.