Skip to content

Commit bcfe5c3

Browse files
add zeek preprocessing
1 parent 15e3582 commit bcfe5c3

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

tasks/preprocessing/zeek.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
from abc import ABC
2+
from typing import Optional
3+
4+
from netunicorn.base import Task, TaskDispatcher, Result, Node, Architecture
5+
from netunicorn.library.tasks.tasks_utils import subprocess_run
6+
7+
8+
class _ZeekDebian12(Task, ABC):
9+
"""
10+
Only for Debian 12 (bookworm)
11+
"""
12+
13+
requirements = [
14+
"apt-get install -y curl",
15+
"echo 'deb http://download.opensuse.org/repositories/security:/zeek/Debian_12/ /' | sudo tee /etc/apt/sources.list.d/security:zeek.list",
16+
"curl -fsSL https://download.opensuse.org/repositories/security:zeek/Debian_12/Release.key | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/security_zeek.gpg > /dev/null",
17+
"sudo apt-get update",
18+
"sudo apt-get install -y zeek-6.0",
19+
]
20+
21+
22+
class ZeekPCAPAnalysisLinuxImplementation(Task):
23+
def __init__(
24+
self, pcap_filename: str, flags: Optional[list[str]] = None, *args, **kwargs
25+
):
26+
self.flags = flags or []
27+
self.pcap_filename = pcap_filename
28+
super().__init__(*args, **kwargs)
29+
30+
def run(self) -> Result:
31+
return subprocess_run(
32+
["/opt/zeek/bin/zeek"] + self.flags + ["-r", self.pcap_filename]
33+
)
34+
35+
36+
class ZeekPCAPAnalysis(TaskDispatcher):
37+
def __init__(
38+
self, pcap_filename: str, flags: Optional[list[str]] = None, *args, **kwargs
39+
):
40+
self.linux_debian_implementation = ZeekPCAPAnalysisLinuxImplementation(
41+
pcap_filename=pcap_filename, flags=flags
42+
)
43+
super().__init__(*args, **kwargs)
44+
45+
def dispatch(self, node: Node) -> Task:
46+
if node.architecture in {Architecture.LINUX_AMD64, Architecture.LINUX_ARM64}:
47+
return self.linux_debian_implementation
48+
else:
49+
raise NotImplementedError(
50+
f"Architecture {node.architecture} is not supported for ZeekPCAPAnalysis"
51+
)

0 commit comments

Comments
 (0)