Skip to content

Commit f898492

Browse files
committed
process container - introduce docker/podman container wrapper for processing pcaps to csvs
1 parent 3717722 commit f898492

File tree

4 files changed

+129
-0
lines changed

4 files changed

+129
-0
lines changed

docker/Dockerfile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM rockylinux:9
2+
3+
RUN dnf install -y dnf-plugins-core && \
4+
dnf copr -y enable @CESNET/NEMEA && \
5+
dnf install -y epel-release && \
6+
dnf install -y ipfixprobe nemea && \
7+
dnf clean all
8+
9+
RUN mkdir -p /output
10+
WORKDIR /output
11+
ENTRYPOINT ["/bin/bash", "-c"]
12+
13+
VOLUME ["/output"]

docker/README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# ipfixprobe Docker wrapper
2+
3+
This repository contains a Docker container that processes network traffic from a pcap file using `ipfixprobe`. It accepts a pcap file and a processing script, runs it inside the container, and outputs the results in CSV format.
4+
5+
## Requirements
6+
* Docker or Podman
7+
* bash
8+
* which, mktemp
9+
10+
## Usage
11+
This container performs the following tasks:
12+
1. Copies a pcap file and processing script into the container.
13+
2. Runs the ipfixprobe tool to export flows.
14+
3. Logs the results in CSV format.
15+
16+
### Build
17+
18+
The script builds the image automatically, but be sure that Dockerfile is in the same directory.
19+
20+
To build the manually image, navigate to the directory containing the Dockerfile and run:
21+
22+
```bash
23+
docker build -t docker_ipfixprobe .
24+
```
25+
26+
### Run
27+
To run, use
28+
29+
```bash
30+
bash ./ipfixprobe_wrapper.sh <process_script.sh> <input_file.pcap> <output_file.csv>
31+
```
32+
33+
To process a file `../pcaps/mixed.pcap` using a processing script `process_script.sh` and output the results to `output.csv`, use the following wrapper script:
34+
35+
```bash
36+
bash ./ipfixprobe_wrapper.sh ./process_script.sh ../pcaps/mixed.pcap ./output.csv
37+
```
38+
39+
* `process_script.sh` Script for processing the pcap file inside the container.
40+
* `input_file.pcap` Path to the input pcap file
41+
* `output_file.csv` Path to the output CSV file
42+
43+
### Volumes
44+
45+
The container uses `/output` as a volume to share files between your host system temporary dir (with `mktemp`) and the container.

docker/ipfixprobe_wrapper.sh

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/bin/bash
2+
IMAGE_NAME="docker_ipfixprobe"
3+
4+
# Run the ipfixprobe on the input pcap file with defined script, and save the output CSV file to the output path.
5+
PROCESS_SCRIPT_PATH=$1
6+
INPUT_FILE_PATH=$2
7+
OUTPUT_CSV_PATH=$3
8+
9+
if [ -z "$PROCESS_SCRIPT_PATH" ] || [ -z "$INPUT_FILE_PATH" ] || [ -z "$OUTPUT_CSV_PATH" ] ; then
10+
echo "Usage: $0 <process_script> <input_file_path> <output_csv_path>"
11+
exit 1
12+
fi
13+
14+
CONT_BIN="$(which podman 2>/dev/null)"
15+
if [ -z "$CONT_BIN" ]; then
16+
CONT_BIN="$(which docker 2>/dev/null)"
17+
fi
18+
if [ -z "$CONT_BIN" ]; then
19+
echo "Missing podman or docker."
20+
exit 2
21+
fi
22+
23+
# Check if the Docker image exists
24+
if ! $CONT_BIN image inspect "$IMAGE_NAME" >/dev/null 2>&1; then
25+
echo "Docker image '$IMAGE_NAME' not found. Attempting to build it..."
26+
27+
# Determine the script directory
28+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
29+
DOCKERFILE_PATH="$SCRIPT_DIR/Dockerfile"
30+
31+
if [ ! -f "$DOCKERFILE_PATH" ]; then
32+
echo "Dockerfile not found at $DOCKERFILE_PATH"
33+
exit 3
34+
fi
35+
36+
# Build the Docker image
37+
echo "Building Docker image '$IMAGE_NAME'..."
38+
$CONT_BIN build -t "$IMAGE_NAME" -f "$DOCKERFILE_PATH" "$SCRIPT_DIR"
39+
40+
if [ $? -ne 0 ]; then
41+
echo "Failed to build Docker image."
42+
exit 4
43+
fi
44+
fi
45+
46+
47+
INPUT_FILE=$(basename "$INPUT_FILE_PATH")
48+
PROCESS_SCRIPT=$(basename "$PROCESS_SCRIPT_PATH")
49+
TMP_FOLDER="$(mktemp -d)"
50+
51+
cp "$INPUT_FILE_PATH" "$TMP_FOLDER/$INPUT_FILE"
52+
cp "$PROCESS_SCRIPT_PATH" "$TMP_FOLDER/$PROCESS_SCRIPT"
53+
chmod +x "$TMP_FOLDER/$PROCESS_SCRIPT"
54+
55+
"$CONT_BIN" run --privileged --rm -v $TMP_FOLDER:/output "$IMAGE_NAME" "/output/$PROCESS_SCRIPT \"$INPUT_FILE\""
56+
[ -f "$TMP_FOLDER/$INPUT_FILE.csv" ] && cp "$TMP_FOLDER/$INPUT_FILE.csv" "$OUTPUT_CSV_PATH" || echo "No output CSV file found."
57+
58+
# Clean up
59+
rm "$TMP_FOLDER/$INPUT_FILE"
60+
rm "$TMP_FOLDER/$PROCESS_SCRIPT"
61+
[ -f "$TMP_FOLDER/$INPUT_FILE.csv" ] && rm "$TMP_FOLDER/$INPUT_FILE.csv"
62+
rm -rf "$TMP_FOLDER"

docker/process_script.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
3+
FILE=$1 # input file
4+
cd /output # workdir
5+
6+
7+
ipfixprobe -i "pcap;file=$FILE" -p "pstats" -p "nettisa" -o "unirec;i=f:$FILE.trapcap:timeout=WAIT;p=(pstats,nettisa)"
8+
/usr/bin/nemea/logger -t -i "f:$FILE.trapcap" -w "$FILE.csv"
9+
rm $FILE.trapcap

0 commit comments

Comments
 (0)