def _make_alerts_by_date(self, elements, date, *, width):
log.debug("Rendering alerts for %s..." % date)
+ # Style the table
+ style = reportlab.platypus.TableStyle((
+ # Make the grid slightly grey
+ ("GRID", (0, 0), (-1, -1), 0.25, reportlab.lib.colors.grey),
+
+ # Align all content to the top left corners of the cells
+ ("ALIGN", (0, 0), (-1, -1), "LEFT"),
+ ("ALIGN", (1, 0), (1, -1), "CENTER"),
+ ("ALIGN", (3, 0), (3, -1), "CENTER"),
+ ("VALIGN", (0, 0), (-1, -1), "TOP"),
+
+ # Chose a much smaller font size
+ ("FONTSIZE", (0, 0), (-1, -1), 8),
+
+ # Alternate the background colours of the rows
+ ("ROWBACKGROUNDS", (0, 1), (-1, -1), [
+ reportlab.lib.colors.white,
+ reportlab.lib.colors.lightgrey,
+ ]),
+ ))
+
# Fetch the alerts
c = self.db.execute("""
SELECT
# Start the table with the header
rows = [
- (_("Time"), _("Signature"), _("Protocol"), _("Source / Destination"))
+ ("", _("Time"), _("Signature"), _("Protocol"), _("Source / Destination"))
]
+ # Count the number of rows
+ i = 0
+
while True:
row = c.fetchone()
if row is None:
break
+ # Increment the row number
+ i += 1
+
# Parse the timestamp
t = datetime.datetime.strptime(row.timestamp, "%Y-%m-%d %H:%M:%S")
+ # Give some visual indication about the severity
+ # High Severity
+ if row.alert_severity == 1:
+ color = reportlab.lib.colors.crimson
+ # Medium Severity
+ elif row.alert_severity == 2:
+ color = reportlab.lib.colors.gold
+ # Low Severity
+ elif row.alert_severity == 3:
+ color = reportlab.lib.colors.dodgerblue
+ # Informational
+ elif row.alert_severity == 4:
+ color = reportlab.lib.colors.lightsteelblue
+ else:
+ color = None
+
+ # Set the severity colour
+ if color:
+ style.add("BACKGROUND", (0, i), (0, i), color)
+
# Append the row
rows.append((
+ # Severity
+ "",
+
# Time
t.strftime("%H:%M:%S"),
# Signature
reportlab.platypus.Paragraph(
- "%s %s<br />[%s:%s:%s] - %s" % (
- "*" * row.alert_severity,
+ "%s<br />[%s:%s:%s] - %s" % (
row.alert_signature,
row.alert_gid,
row.alert_signature_id,
table = reportlab.platypus.Table(rows,
# Set the widths of the rows
colWidths=(
- width * 0.1, width * 0.6, width * 0.1, width * 0.2,
+ width * 0.02, width * 0.08, width * 0.6, width * 0.1, width * 0.2,
),
# Repeat the header after a page break
)
# Style the table
- table.setStyle(
- reportlab.platypus.TableStyle((
- # Make the grid slightly grey
- ("GRID", (0, 0), (-1, -1), 0.25, reportlab.lib.colors.grey),
-
- # Align all content to the top left corners of the cells
- ("ALIGN", (0, 0), (-1, -1), "LEFT"),
- ("ALIGN", (0, 0), (0, -1), "CENTER"),
- ("ALIGN", (2, 0), (2, -1), "CENTER"),
- ("VALIGN", (0, 0), (-1, -1), "TOP"),
-
- # Chose a much smaller font size
- ("FONTSIZE", (0, 0), (-1, -1), 8),
-
- # Alternate the background colours of the rows
- ("ROWBACKGROUNDS", (0, 1), (-1, -1), [
- reportlab.lib.colors.white,
- reportlab.lib.colors.lightgrey,
- ]),
- )),
- )
+ table.setStyle(style)
# Append the table to the output
elements.append(table)