Skip to content

Commit

Permalink
Merge pull request #2491 from e3rd/enh-smtp_batch-hardening
Browse files Browse the repository at this point in the history
ENH: smtp_batch invalid row hardening
  • Loading branch information
sebix committed Apr 9, 2024
2 parents 188f091 + 6e6c03b commit d4ea2ad
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
4 changes: 2 additions & 2 deletions docs/user/bots.md
Original file line number Diff line number Diff line change
Expand Up @@ -4969,7 +4969,7 @@ Note: The field "raw" gets base64 decoded if possible. Bytes `\n` and `\r` are r

Launch it like this:
```
</usr/local/bin executable> <bot-id> cli [--tester tester's email]
</usr/local/bin executable> <bot-id> --cli [--tester tester's email]
```
Example:
```bash
Expand All @@ -4993,7 +4993,7 @@ You can schedule the batch sending easily with a cron script, I.E. put this into

```
# Send the e-mails every day at 6 AM
0 6 * * * /usr/local/bin/intelmq.bots.outputs.smtp_batch.output smtp-batch-output-cz cli --ignore-older-than-days 4 --send > /tmp/intelmq-send.log
0 6 * * * /usr/local/bin/intelmq.bots.outputs.smtp_batch.output smtp-batch-output-cz cli --ignore-older-than-days 4 --send &> /tmp/intelmq-send.log
```

**Module:** `intelmq.bots.outputs.smtp_batch.output`
Expand Down
13 changes: 7 additions & 6 deletions intelmq/bots/outputs/smtp_batch/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,7 @@ def prepare_mails(self):
print("... failed ...", flush=True)
continue
else:
# visible both warning and print
print(f"Warning: {mail_record} timeout, too big to read from redis", flush=True)
self.logger.warning(f"Warning: {mail_record} timeout, too big to read from redis")
self.logger.warning("Warning: timeout, too big to read from redis: %r", mail_record)
self.timeout.append(mail_record)
continue

Expand All @@ -253,8 +251,11 @@ def prepare_mails(self):
fieldnames = set()
rows_output = []
for row in lines:
if threshold and row["time.observation"][:19] < threshold.isoformat()[:19]:
continue
try:
if threshold and row["time.observation"][:19] < threshold.isoformat()[:19]:
continue
except KeyError:
self.logger.warning("Warning: row skipped due to time.observation error: %r", mail_record)
fieldnames = fieldnames | set(row.keys())
keys = set(self.allowed_fieldnames).intersection(row)
ordered_keys = []
Expand Down Expand Up @@ -290,7 +291,7 @@ def prepare_mails(self):
try:
zf.writestr(filename + ".csv", output.getvalue())
except Exception:
self.logger.error(f"Cannot zip mail {mail_record}")
self.logger.error("Error: Cannot zip mail: %r", mail_record)
continue

if email_to in self.alternative_mail:
Expand Down

0 comments on commit d4ea2ad

Please sign in to comment.