syslog2cef 0.1.2__tar.gz → 0.1.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {syslog2cef-0.1.2/syslog2cef.egg-info → syslog2cef-0.1.4}/PKG-INFO +3 -1
- {syslog2cef-0.1.2 → syslog2cef-0.1.4}/pyproject.toml +4 -1
- {syslog2cef-0.1.2 → syslog2cef-0.1.4/syslog2cef.egg-info}/PKG-INFO +3 -1
- {syslog2cef-0.1.2 → syslog2cef-0.1.4}/syslog2cef.egg-info/SOURCES.txt +7 -1
- syslog2cef-0.1.4/syslog2cef.egg-info/requires.txt +6 -0
- {syslog2cef-0.1.2 → syslog2cef-0.1.4}/syslogcef/adaptive.py +28 -11
- {syslog2cef-0.1.2 → syslog2cef-0.1.4}/syslogcef/api.py +16 -5
- {syslog2cef-0.1.2 → syslog2cef-0.1.4}/syslogcef/cef.py +31 -7
- {syslog2cef-0.1.2 → syslog2cef-0.1.4}/syslogcef/cli.py +55 -15
- syslog2cef-0.1.4/syslogcef/net.py +309 -0
- {syslog2cef-0.1.2 → syslog2cef-0.1.4}/syslogcef/parsers.py +16 -3
- syslog2cef-0.1.4/syslogcef/validation.py +177 -0
- {syslog2cef-0.1.2 → syslog2cef-0.1.4}/tests/test_adaptive.py +54 -0
- syslog2cef-0.1.4/tests/test_net.py +269 -0
- syslog2cef-0.1.4/tests/test_validation.py +89 -0
- syslog2cef-0.1.2/syslog2cef.egg-info/requires.txt +0 -3
- {syslog2cef-0.1.2 → syslog2cef-0.1.4}/LICENSE +0 -0
- {syslog2cef-0.1.2 → syslog2cef-0.1.4}/README.md +0 -0
- {syslog2cef-0.1.2 → syslog2cef-0.1.4}/setup.cfg +0 -0
- {syslog2cef-0.1.2 → syslog2cef-0.1.4}/syslog2cef.egg-info/dependency_links.txt +0 -0
- {syslog2cef-0.1.2 → syslog2cef-0.1.4}/syslog2cef.egg-info/entry_points.txt +0 -0
- {syslog2cef-0.1.2 → syslog2cef-0.1.4}/syslog2cef.egg-info/top_level.txt +0 -0
- {syslog2cef-0.1.2 → syslog2cef-0.1.4}/syslogcef/__init__.py +0 -0
- {syslog2cef-0.1.2 → syslog2cef-0.1.4}/syslogcef/__main__.py +0 -0
- {syslog2cef-0.1.2 → syslog2cef-0.1.4}/syslogcef/mappings/__init__.py +0 -0
- {syslog2cef-0.1.2 → syslog2cef-0.1.4}/syslogcef/mappings/cisco_asa.json +0 -0
- {syslog2cef-0.1.2 → syslog2cef-0.1.4}/syslogcef/mappings/cisco_ios.json +0 -0
- {syslog2cef-0.1.2 → syslog2cef-0.1.4}/syslogcef/mappings/f5.json +0 -0
- {syslog2cef-0.1.2 → syslog2cef-0.1.4}/syslogcef/mappings/fortinet.json +0 -0
- {syslog2cef-0.1.2 → syslog2cef-0.1.4}/syslogcef/mappings/linux.json +0 -0
- {syslog2cef-0.1.2 → syslog2cef-0.1.4}/syslogcef/mappings/sophos.json +0 -0
- {syslog2cef-0.1.2 → syslog2cef-0.1.4}/syslogcef/mappings/vmware.json +0 -0
- {syslog2cef-0.1.2 → syslog2cef-0.1.4}/syslogcef/normalizer.py +0 -0
- {syslog2cef-0.1.2 → syslog2cef-0.1.4}/syslogcef/utils.py +0 -0
- {syslog2cef-0.1.2 → syslog2cef-0.1.4}/tests/test_cef.py +0 -0
- {syslog2cef-0.1.2 → syslog2cef-0.1.4}/tests/test_cli.py +0 -0
- {syslog2cef-0.1.2 → syslog2cef-0.1.4}/tests/test_normalizer.py +0 -0
- {syslog2cef-0.1.2 → syslog2cef-0.1.4}/tests/test_parsers.py +0 -0
- {syslog2cef-0.1.2 → syslog2cef-0.1.4}/tests/test_parsers_extra.py +0 -0
- {syslog2cef-0.1.2 → syslog2cef-0.1.4}/tests/test_pipeline.py +0 -0
- {syslog2cef-0.1.2 → syslog2cef-0.1.4}/tests/test_real_world.py +0 -0
- {syslog2cef-0.1.2 → syslog2cef-0.1.4}/tests/test_utils.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: syslog2cef
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.4
|
|
4
4
|
Summary: Convert RFC3164/RFC5424 syslog lines into ArcSight CEF
|
|
5
5
|
Author-email: Tamir Suliman <allamiro@gmail.com>
|
|
6
6
|
Project-URL: Homepage, https://github.com/allamiro/syslogcef
|
|
@@ -15,6 +15,8 @@ Description-Content-Type: text/markdown
|
|
|
15
15
|
License-File: LICENSE
|
|
16
16
|
Provides-Extra: test
|
|
17
17
|
Requires-Dist: pytest>=7; extra == "test"
|
|
18
|
+
Provides-Extra: kafka
|
|
19
|
+
Requires-Dist: kafka-python>=2.0; extra == "kafka"
|
|
18
20
|
Dynamic: license-file
|
|
19
21
|
|
|
20
22
|
<p align="center">
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "syslog2cef"
|
|
7
|
-
version = "0.1.
|
|
7
|
+
version = "0.1.4"
|
|
8
8
|
description = "Convert RFC3164/RFC5424 syslog lines into ArcSight CEF"
|
|
9
9
|
authors = [{name = "Tamir Suliman", email = "allamiro@gmail.com"}]
|
|
10
10
|
readme = "README.md"
|
|
@@ -26,6 +26,9 @@ Issues = "https://github.com/allamiro/syslogcef/issues"
|
|
|
26
26
|
test = [
|
|
27
27
|
"pytest>=7",
|
|
28
28
|
]
|
|
29
|
+
kafka = [
|
|
30
|
+
"kafka-python>=2.0",
|
|
31
|
+
]
|
|
29
32
|
|
|
30
33
|
[project.scripts]
|
|
31
34
|
syslogcef = "syslogcef.cli:main"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: syslog2cef
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.4
|
|
4
4
|
Summary: Convert RFC3164/RFC5424 syslog lines into ArcSight CEF
|
|
5
5
|
Author-email: Tamir Suliman <allamiro@gmail.com>
|
|
6
6
|
Project-URL: Homepage, https://github.com/allamiro/syslogcef
|
|
@@ -15,6 +15,8 @@ Description-Content-Type: text/markdown
|
|
|
15
15
|
License-File: LICENSE
|
|
16
16
|
Provides-Extra: test
|
|
17
17
|
Requires-Dist: pytest>=7; extra == "test"
|
|
18
|
+
Provides-Extra: kafka
|
|
19
|
+
Requires-Dist: kafka-python>=2.0; extra == "kafka"
|
|
18
20
|
Dynamic: license-file
|
|
19
21
|
|
|
20
22
|
<p align="center">
|
|
@@ -7,9 +7,11 @@ pyproject.toml
|
|
|
7
7
|
./syslogcef/api.py
|
|
8
8
|
./syslogcef/cef.py
|
|
9
9
|
./syslogcef/cli.py
|
|
10
|
+
./syslogcef/net.py
|
|
10
11
|
./syslogcef/normalizer.py
|
|
11
12
|
./syslogcef/parsers.py
|
|
12
13
|
./syslogcef/utils.py
|
|
14
|
+
./syslogcef/validation.py
|
|
13
15
|
./syslogcef/mappings/__init__.py
|
|
14
16
|
./syslogcef/mappings/cisco_asa.json
|
|
15
17
|
./syslogcef/mappings/cisco_ios.json
|
|
@@ -30,9 +32,11 @@ syslogcef/adaptive.py
|
|
|
30
32
|
syslogcef/api.py
|
|
31
33
|
syslogcef/cef.py
|
|
32
34
|
syslogcef/cli.py
|
|
35
|
+
syslogcef/net.py
|
|
33
36
|
syslogcef/normalizer.py
|
|
34
37
|
syslogcef/parsers.py
|
|
35
38
|
syslogcef/utils.py
|
|
39
|
+
syslogcef/validation.py
|
|
36
40
|
syslogcef/mappings/__init__.py
|
|
37
41
|
syslogcef/mappings/cisco_asa.json
|
|
38
42
|
syslogcef/mappings/cisco_ios.json
|
|
@@ -44,9 +48,11 @@ syslogcef/mappings/vmware.json
|
|
|
44
48
|
tests/test_adaptive.py
|
|
45
49
|
tests/test_cef.py
|
|
46
50
|
tests/test_cli.py
|
|
51
|
+
tests/test_net.py
|
|
47
52
|
tests/test_normalizer.py
|
|
48
53
|
tests/test_parsers.py
|
|
49
54
|
tests/test_parsers_extra.py
|
|
50
55
|
tests/test_pipeline.py
|
|
51
56
|
tests/test_real_world.py
|
|
52
|
-
tests/test_utils.py
|
|
57
|
+
tests/test_utils.py
|
|
58
|
+
tests/test_validation.py
|
|
@@ -31,9 +31,14 @@ def _epoch(match: "re.Match[str]", now: Optional[datetime]) -> datetime:
|
|
|
31
31
|
def _mon_day(match: "re.Match[str]", now: Optional[datetime]) -> datetime:
|
|
32
32
|
month = month_abbr_to_int(match.group("month"))
|
|
33
33
|
day = int(match.group("day"))
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
if match.groupdict().get("year"):
|
|
35
|
+
hour, minute, second = map(int, match.group("hms").split(":"))
|
|
36
|
+
return datetime(int(match.group("year")), month, day, hour, minute, second, tzinfo=timezone.utc)
|
|
37
|
+
# No year: use the same rollover inference as the dedicated parsers so a
|
|
38
|
+
# December event parsed in January lands in the previous year.
|
|
39
|
+
from .parsers import _infer_timestamp
|
|
40
|
+
|
|
41
|
+
return _infer_timestamp(month, day, match.group("hms"), now=now)
|
|
37
42
|
|
|
38
43
|
|
|
39
44
|
def _ymd_slash(match: "re.Match[str]", now: Optional[datetime]) -> datetime:
|
|
@@ -62,6 +67,16 @@ TIMESTAMP_LIB: Tuple[Tuple[str, str, Callable], ...] = (
|
|
|
62
67
|
HOST_RE = re.compile(r"^[A-Za-z0-9][A-Za-z0-9_.-]*$")
|
|
63
68
|
_SKIP_HOST_TOKENS = {"error", "warning", "info", "debug", "notice", "kernel"}
|
|
64
69
|
|
|
70
|
+
|
|
71
|
+
def _valid_host(candidate: Optional[str]) -> bool:
|
|
72
|
+
return bool(
|
|
73
|
+
candidate
|
|
74
|
+
and "=" not in candidate
|
|
75
|
+
and HOST_RE.match(candidate)
|
|
76
|
+
and candidate.lower() not in _SKIP_HOST_TOKENS
|
|
77
|
+
and not candidate.isdigit()
|
|
78
|
+
)
|
|
79
|
+
|
|
65
80
|
_CACHE: Dict[str, Tuple[Pattern[str], str, Callable]] = {}
|
|
66
81
|
_CACHE_MAX = 256
|
|
67
82
|
|
|
@@ -131,8 +146,15 @@ def adaptive_parse(line: str, *, now: Optional[datetime] = None):
|
|
|
131
146
|
ts = conv(pattern_ts_match(pattern, match), now)
|
|
132
147
|
except (ValueError, KeyError):
|
|
133
148
|
ts = None
|
|
134
|
-
|
|
135
|
-
|
|
149
|
+
gd = match.groupdict()
|
|
150
|
+
host = gd.get("adaptive_host")
|
|
151
|
+
msg = gd.get("adaptive_msg")
|
|
152
|
+
msg = line if msg is None else msg
|
|
153
|
+
# The shape signature reduces all words to the same class, so a
|
|
154
|
+
# cached host slot may capture a non-host token; revalidate.
|
|
155
|
+
if host is not None and not _valid_host(host.rstrip(":,")):
|
|
156
|
+
msg = f"{host} {msg}".strip()
|
|
157
|
+
host = None
|
|
136
158
|
return _build_event(raw, pri, ts, host, msg)
|
|
137
159
|
|
|
138
160
|
# Analysis pass: find the earliest timestamp in the line head.
|
|
@@ -157,12 +179,7 @@ def adaptive_parse(line: str, *, now: Optional[datetime] = None):
|
|
|
157
179
|
tokens = rest.split(None, 1)
|
|
158
180
|
if tokens:
|
|
159
181
|
candidate = tokens[0].rstrip(":,")
|
|
160
|
-
if (
|
|
161
|
-
"=" not in candidate
|
|
162
|
-
and HOST_RE.match(candidate)
|
|
163
|
-
and candidate.lower() not in _SKIP_HOST_TOKENS
|
|
164
|
-
and not candidate.isdigit()
|
|
165
|
-
):
|
|
182
|
+
if _valid_host(candidate):
|
|
166
183
|
host = candidate
|
|
167
184
|
msg = tokens[1] if len(tokens) > 1 else ""
|
|
168
185
|
|
|
@@ -74,14 +74,23 @@ def _load_mapping(mapping: Mapping[str, Any] | Path | str | None) -> Mapping[str
|
|
|
74
74
|
def to_cef(
|
|
75
75
|
event: NormalizedEvent,
|
|
76
76
|
mapping: Mapping[str, Any] | Path | str | None = None,
|
|
77
|
+
*,
|
|
78
|
+
validate: bool = False,
|
|
79
|
+
strict: bool = False,
|
|
77
80
|
) -> str:
|
|
78
|
-
"""Convert a normalized event into a CEF string.
|
|
81
|
+
"""Convert a normalized event into a CEF string.
|
|
82
|
+
|
|
83
|
+
With ``validate=True``, extension values are checked against the
|
|
84
|
+
ArcSight dictionary and violations logged as warnings; ``strict=True``
|
|
85
|
+
additionally raises :class:`syslogcef.validation.CEFValidationError`
|
|
86
|
+
on type or length violations.
|
|
87
|
+
"""
|
|
79
88
|
|
|
80
89
|
if mapping is None:
|
|
81
90
|
mapping_data = _guess_mapping(event)
|
|
82
91
|
else:
|
|
83
92
|
mapping_data = _load_mapping(mapping)
|
|
84
|
-
cef_event = build_cef(event, mapping_data)
|
|
93
|
+
cef_event = build_cef(event, mapping_data, validate=validate, strict=strict)
|
|
85
94
|
return cef_event.render()
|
|
86
95
|
|
|
87
96
|
|
|
@@ -91,13 +100,15 @@ def convert_line(
|
|
|
91
100
|
mode: Optional[str] = None,
|
|
92
101
|
mapping: Mapping[str, Any] | Path | str | None = None,
|
|
93
102
|
now: Optional[datetime] = None,
|
|
103
|
+
validate: bool = False,
|
|
104
|
+
strict: bool = False,
|
|
94
105
|
) -> str:
|
|
95
106
|
"""Full pipeline that parses, normalizes and converts a syslog line."""
|
|
96
107
|
|
|
97
108
|
parsed = parse_syslog(line, mode=mode, now=now)
|
|
98
109
|
normalized = normalize_event(parsed)
|
|
99
110
|
|
|
100
|
-
return to_cef(normalized, mapping)
|
|
111
|
+
return to_cef(normalized, mapping, validate=validate, strict=strict)
|
|
101
112
|
|
|
102
113
|
|
|
103
114
|
def _guess_mapping(event: NormalizedEvent) -> Mapping[str, Any]:
|
|
@@ -111,9 +122,9 @@ def _guess_mapping(event: NormalizedEvent) -> Mapping[str, Any]:
|
|
|
111
122
|
return CISCO_IOS
|
|
112
123
|
if "BIG-IP" in msg_upper or "F5" in app_upper:
|
|
113
124
|
return F5
|
|
114
|
-
if "
|
|
125
|
+
if "logid" in event.kv:
|
|
115
126
|
return FORTINET
|
|
116
|
-
if "log_id" in event.kv
|
|
127
|
+
if "log_id" in event.kv:
|
|
117
128
|
return SOPHOS
|
|
118
129
|
if "VMWARE" in msg_upper or "ESXI" in msg_upper or "VMWARE" in app_upper:
|
|
119
130
|
return VMWARE
|
|
@@ -56,7 +56,12 @@ class MappingResolver:
|
|
|
56
56
|
header = {}
|
|
57
57
|
for key in ["deviceVendor", "deviceProduct", "deviceVersion", "eventClassId", "name"]:
|
|
58
58
|
template = self.mapping.get(key, DEFAULT_MAPPING[key])
|
|
59
|
-
|
|
59
|
+
value = self._format(template, fields)
|
|
60
|
+
if not value:
|
|
61
|
+
# A template referencing missing fields must not leave an
|
|
62
|
+
# empty CEF header slot; fall back to the default template.
|
|
63
|
+
value = self._format(DEFAULT_MAPPING[key], fields)
|
|
64
|
+
header[key] = cef_escape_header(value)
|
|
60
65
|
severity = self._resolve_severity(fields)
|
|
61
66
|
header["severity"] = severity
|
|
62
67
|
return header
|
|
@@ -71,15 +76,18 @@ class MappingResolver:
|
|
|
71
76
|
return "3"
|
|
72
77
|
return severity_map.get(str(value), str(value))
|
|
73
78
|
|
|
74
|
-
def
|
|
75
|
-
|
|
79
|
+
def resolve_raw_extensions(self, fields: Mapping[str, Any]) -> Dict[str, str]:
|
|
80
|
+
raw = {}
|
|
76
81
|
merged = DEFAULT_MAPPING["extensions"].copy()
|
|
77
82
|
merged.update(self.mapping.get("extensions", {}))
|
|
78
83
|
for key, template in merged.items():
|
|
79
84
|
value = self._format(template, fields)
|
|
80
85
|
if value:
|
|
81
|
-
|
|
82
|
-
return
|
|
86
|
+
raw[key] = str(value)
|
|
87
|
+
return raw
|
|
88
|
+
|
|
89
|
+
def resolve_extensions(self, fields: Mapping[str, Any]) -> Dict[str, str]:
|
|
90
|
+
return {k: cef_escape(v) for k, v in self.resolve_raw_extensions(fields).items()}
|
|
83
91
|
|
|
84
92
|
def _format(self, template: str, fields: Mapping[str, Any]) -> str:
|
|
85
93
|
try:
|
|
@@ -92,11 +100,27 @@ class MappingResolver:
|
|
|
92
100
|
return ""
|
|
93
101
|
|
|
94
102
|
|
|
95
|
-
def build_cef(
|
|
103
|
+
def build_cef(
|
|
104
|
+
event: NormalizedEvent,
|
|
105
|
+
mapping: Mapping[str, Any],
|
|
106
|
+
*,
|
|
107
|
+
validate: bool = False,
|
|
108
|
+
strict: bool = False,
|
|
109
|
+
) -> CEFEvent:
|
|
96
110
|
resolver = MappingResolver(mapping)
|
|
97
111
|
fields = event.as_field_dict()
|
|
98
112
|
header = resolver.resolve_header(fields)
|
|
99
|
-
|
|
113
|
+
raw = resolver.resolve_raw_extensions(fields)
|
|
114
|
+
if validate or strict:
|
|
115
|
+
from .validation import CEFValidationError, validate_extensions
|
|
116
|
+
|
|
117
|
+
findings = validate_extensions(raw)
|
|
118
|
+
for finding in findings:
|
|
119
|
+
logger.warning("CEF validation: %s", finding)
|
|
120
|
+
fatal = [f for f in findings if f.fatal]
|
|
121
|
+
if strict and fatal:
|
|
122
|
+
raise CEFValidationError("; ".join(str(f) for f in fatal))
|
|
123
|
+
extensions = {k: cef_escape(v) for k, v in raw.items()}
|
|
100
124
|
return CEFEvent(header=header, extensions=extensions)
|
|
101
125
|
|
|
102
126
|
|
|
@@ -74,8 +74,8 @@ def follow_files(
|
|
|
74
74
|
handle.close()
|
|
75
75
|
|
|
76
76
|
|
|
77
|
-
def _convert_line_mp(line: str, mode: Optional[str], mapping: Optional[str]) -> str:
|
|
78
|
-
return convert_line(line, mode=mode, mapping=mapping)
|
|
77
|
+
def _convert_line_mp(line: str, mode: Optional[str], mapping: Optional[str], validate: bool = False, strict: bool = False) -> str:
|
|
78
|
+
return convert_line(line, mode=mode, mapping=mapping, validate=validate, strict=strict)
|
|
79
79
|
|
|
80
80
|
|
|
81
81
|
def process_lines(
|
|
@@ -85,16 +85,18 @@ def process_lines(
|
|
|
85
85
|
mapping: Optional[str],
|
|
86
86
|
use_multiprocessing: bool,
|
|
87
87
|
pool_size: Optional[int],
|
|
88
|
+
validate: bool = False,
|
|
89
|
+
strict: bool = False,
|
|
88
90
|
) -> Iterator[str]:
|
|
89
91
|
if use_multiprocessing:
|
|
90
92
|
size = pool_size or max(1, cpu_count() - 1)
|
|
91
93
|
with Pool(size) as pool:
|
|
92
|
-
worker = partial(_convert_line_mp, mode=mode, mapping=mapping)
|
|
94
|
+
worker = partial(_convert_line_mp, mode=mode, mapping=mapping, validate=validate, strict=strict)
|
|
93
95
|
for cef in pool.imap(worker, lines):
|
|
94
96
|
yield cef
|
|
95
97
|
else:
|
|
96
98
|
for line in lines:
|
|
97
|
-
yield convert_line(line, mode=mode, mapping=mapping)
|
|
99
|
+
yield convert_line(line, mode=mode, mapping=mapping, validate=validate, strict=strict)
|
|
98
100
|
|
|
99
101
|
|
|
100
102
|
def main(argv: Optional[list[str]] = None) -> int:
|
|
@@ -105,8 +107,13 @@ def main(argv: Optional[list[str]] = None) -> int:
|
|
|
105
107
|
parser.add_argument("--mode", choices=["rfc3164", "rfc5424", "rsyslog_json", "rsyslog_file", "journald_json", "journald_short", "journald_iso", "cisco_seq", "iso_syslog", "kv"], help="Parser mode override")
|
|
106
108
|
parser.add_argument("--mapping", type=str, help="Mapping JSON file")
|
|
107
109
|
parser.add_argument("--tail", action="store_true", help="Follow file like tail -f")
|
|
110
|
+
parser.add_argument("--listen", metavar="PROTO:PORT", help="Receive syslog over the network instead of reading files/stdin, e.g. udp:514, tcp:5514, or udp:10.0.0.5:514")
|
|
111
|
+
parser.add_argument("--send", metavar="URL", help="Forward CEF records to udp://HOST:PORT, tcp://HOST:PORT (newline-delimited, with reconnect), or kafka://BROKER:PORT/TOPIC (requires the kafka extra)")
|
|
112
|
+
parser.add_argument("--eps", type=float, help="Rate-limit --send to at most this many events per second")
|
|
108
113
|
parser.add_argument("--multiprocess", action="store_true", help="Process lines using a process pool")
|
|
109
114
|
parser.add_argument("--pool-size", type=int, help="Number of worker processes for --multiprocess")
|
|
115
|
+
parser.add_argument("--validate", action="store_true", help="Validate CEF extensions against the ArcSight dictionary; violations are logged as warnings")
|
|
116
|
+
parser.add_argument("--strict", action="store_true", help="Like --validate, but exit with an error on type/length violations")
|
|
110
117
|
parser.add_argument("--log-level", default="WARNING", help="Logging level")
|
|
111
118
|
|
|
112
119
|
args = parser.parse_args(argv)
|
|
@@ -115,20 +122,53 @@ def main(argv: Optional[list[str]] = None) -> int:
|
|
|
115
122
|
mapping = args.mapping
|
|
116
123
|
|
|
117
124
|
outputs: Iterator[str]
|
|
118
|
-
if args.
|
|
119
|
-
|
|
125
|
+
if args.listen:
|
|
126
|
+
from .net import listen_lines, parse_endpoint
|
|
127
|
+
|
|
128
|
+
try:
|
|
129
|
+
proto, host, port = parse_endpoint(args.listen)
|
|
130
|
+
except ValueError as exc:
|
|
131
|
+
parser.error(str(exc))
|
|
132
|
+
lines = listen_lines(proto, host, port)
|
|
133
|
+
outputs = process_lines(lines, mode=args.mode, mapping=mapping, use_multiprocessing=args.multiprocess, pool_size=args.pool_size, validate=args.validate or args.strict, strict=args.strict)
|
|
134
|
+
elif args.tail and args.paths:
|
|
135
|
+
outputs = process_lines(follow_files(args.paths), mode=args.mode, mapping=mapping, use_multiprocessing=args.multiprocess, pool_size=args.pool_size, validate=args.validate or args.strict, strict=args.strict)
|
|
120
136
|
else:
|
|
121
|
-
outputs = process_lines(iter_lines_from_sources(args.paths), mode=args.mode, mapping=mapping, use_multiprocessing=args.multiprocess, pool_size=args.pool_size)
|
|
137
|
+
outputs = process_lines(iter_lines_from_sources(args.paths), mode=args.mode, mapping=mapping, use_multiprocessing=args.multiprocess, pool_size=args.pool_size, validate=args.validate or args.strict, strict=args.strict)
|
|
122
138
|
|
|
123
|
-
|
|
124
|
-
|
|
139
|
+
sender = None
|
|
140
|
+
if args.send:
|
|
141
|
+
from .net import create_sender
|
|
142
|
+
|
|
143
|
+
try:
|
|
144
|
+
sender = create_sender(args.send, eps=args.eps)
|
|
145
|
+
except (ValueError, RuntimeError) as exc:
|
|
146
|
+
parser.error(str(exc))
|
|
147
|
+
|
|
148
|
+
from .validation import CEFValidationError
|
|
149
|
+
|
|
150
|
+
try:
|
|
151
|
+
if args.output:
|
|
152
|
+
with args.output.open("a" if args.append else "w", encoding="utf-8") as fp:
|
|
153
|
+
for cef in outputs:
|
|
154
|
+
fp.write(cef + "\n")
|
|
155
|
+
if args.tail or args.listen:
|
|
156
|
+
fp.flush()
|
|
157
|
+
if sender:
|
|
158
|
+
sender.send(cef)
|
|
159
|
+
elif sender:
|
|
125
160
|
for cef in outputs:
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
161
|
+
sender.send(cef)
|
|
162
|
+
else:
|
|
163
|
+
stream_flush = bool(args.tail or args.listen)
|
|
164
|
+
for cef in outputs:
|
|
165
|
+
print(cef, flush=stream_flush)
|
|
166
|
+
except CEFValidationError as exc:
|
|
167
|
+
print(f"syslogcef: strict validation failed: {exc}", file=sys.stderr)
|
|
168
|
+
return 1
|
|
169
|
+
finally:
|
|
170
|
+
if sender:
|
|
171
|
+
sender.close()
|
|
132
172
|
return 0
|
|
133
173
|
|
|
134
174
|
|