Skip to content

Commit 4253d05

Browse files
authored
Merge pull request #13 from malvidin/line_contains_nul
Clearer Error Handling for Null
2 parents 5e7b7e0 + a629ed3 commit 4253d05

File tree

1 file changed

+25
-17
lines changed

1 file changed

+25
-17
lines changed

bin/decrypt.py

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
# coding=utf-8
33

44
from __future__ import absolute_import, division, print_function, unicode_literals
5+
6+
import csv
57
import os
68
import sys
79

@@ -19,23 +21,29 @@ class DecryptCommand(StreamingCommand):
1921
def stream(self, records):
2022
stmt = " ".join(self.fieldnames)
2123

22-
for record in records:
23-
try:
24-
decryptlib.g_record = record
25-
decryptlib.logger = self.logger
26-
exception_string = None
27-
28-
if self.field in record:
29-
result = record[self.field]
30-
31-
for fn, args in decryptlib.parsestmt(stmt):
32-
result = fn(result, args)
33-
34-
except Exception as e:
35-
exception_string = str(e)
36-
record[".decrypt_failure__"] = exception_string
37-
38-
yield record
24+
try:
25+
for record in records:
26+
try:
27+
decryptlib.g_record = record
28+
decryptlib.logger = self.logger
29+
exception_string = None
30+
31+
if self.field in record:
32+
result = record[self.field]
33+
34+
for fn, args in decryptlib.parsestmt(stmt):
35+
result = fn(result, args)
36+
37+
except Exception as e:
38+
exception_string = str(e)
39+
record[".decrypt_failure__"] = exception_string
40+
41+
yield record
42+
except csv.Error:
43+
raise csv.Error('Splunk record contained NUL. '
44+
'Use eval/replace or rex/sed beforehand to work around, '
45+
'or use the decrypt/escape function in the previous command.'
46+
' (fixed in Python 3.11)')
3947

4048

4149
dispatch(DecryptCommand, sys.argv, sys.stdin, sys.stdout, __name__)

0 commit comments

Comments
 (0)