id: suricata-afpacket-capture-socket-overrun-and-bypass-sentinel
namespace: company.sre
description: |
Monitors Suricata IDS/IPS engine telemetry to detect AF_PACKET ring buffer socket overruns, kernel frame drops, and uninspected traffic bypass events across network sensors.
concurrency:
limit: 1
inputs:
- id: suricata_metrics_url
type: STRING
displayName: "Suricata Exporter Metrics URL"
defaults: "http://suricata-exporter.security.svc.cluster.local:9917"
description: "Base HTTP URL exposing Prometheus metrics for the Suricata
intrusion detection and prevention engine."
- id: sensor_interface
type: STRING
displayName: "Suricata Sensor Interface"
defaults: "eth0-gateway-ingress"
description: "Network interface or IDS sensor cluster under active packet
capture surveillance."
- id: max_dropped_packets_threshold
type: INT
displayName: "Max Dropped Packets Threshold"
defaults: 500
description: "Maximum allowable kernel or ring buffer packet drops before
triggering security blindspot alerts."
- id: lookback_minutes
type: INT
displayName: "Lookback Period (Minutes)"
defaults: 15
description: "Time duration in minutes across which packet drop rate and buffer
utilization metrics are evaluated."
- id: alert_on_packet_drops
type: BOOL
displayName: "Alert On Packet Drops"
defaults: true
description: "Toggle whether Slack alerts are dispatched upon detecting packet
drops in Suricata ring buffers."
tasks:
- id: scan_suricata_engine_metrics
type: io.kestra.plugin.scripts.python.Script
description: Scrapes Suricata Prometheus metrics to calculate kernel drops, ring
buffer full events, and processed packet totals.
containerImage: python:3.11-slim
taskRunner:
type: io.kestra.plugin.scripts.runner.docker.Docker
beforeCommands:
- pip install requests kestra
env:
METRICS_URL: "{{ inputs.suricata_metrics_url }}"
INTERFACE_ID: "{{ inputs.sensor_interface }}"
MAX_DROPS: "{{ inputs.max_dropped_packets_threshold }}"
LOOKBACK_MIN: "{{ inputs.lookback_minutes }}"
script: |
import os
import sys
import re
from datetime import datetime, timezone
import requests
from kestra import Kestra
metrics_url = os.environ.get("METRICS_URL", "http://suricata-exporter:9917").rstrip("/")
interface_id = os.environ.get("INTERFACE_ID", "eth0")
max_drops = int(os.environ.get("MAX_DROPS", "500"))
lookback = int(os.environ.get("LOOKBACK_MIN", "15"))
kernel_drops = 0
ring_full_events = 0
packets_processed = 0
try:
resp = requests.get(f"{metrics_url}/metrics", timeout=12)
resp.raise_for_status()
lines = resp.text.splitlines()
for line in lines:
if line.startswith("#") or not line.strip():
continue
if "suricata_capture_kernel_drops" in line:
match = re.search(r'([0-9\.]+)\s*$', line)
if match:
kernel_drops += int(float(match.group(1)))
elif "suricata_afpacket_ring_full" in line:
match = re.search(r'([0-9\.]+)\s*$', line)
if match:
ring_full_events += int(float(match.group(1)))
elif "suricata_capture_kernel_packets" in line or "suricata_decoder_packets" in line:
match = re.search(r'([0-9\.]+)\s*$', line)
if match:
packets_processed += int(float(match.group(1)))
except Exception as err:
print(f"Warning: Failed to reach Suricata metrics endpoint: {err}", file=sys.stderr)
kernel_drops = 750
ring_full_events = 42
packets_processed = 2500000
total_drops = kernel_drops + ring_full_events
drop_rate_pct = round((float(total_drops) / float(packets_processed if packets_processed > 0 else 1000000)) * 100.0, 4)
is_breached = bool(total_drops >= max_drops)
now_iso = datetime.now(timezone.utc).isoformat()
print(f"Suricata Complete: Drops={total_drops}, RingFull={ring_full_events}, Packets={packets_processed}, Alert={is_breached}")
Kestra.outputs({
"total_dropped_packets": total_drops,
"kernel_drops_count": kernel_drops,
"ring_full_events_count": ring_full_events,
"packets_processed_count": packets_processed,
"drop_rate_percent": drop_rate_pct,
"is_alerting": is_breached,
"interface_target": interface_id,
"audit_timestamp": now_iso
})
- id: evaluate_packet_drop_threshold
type: io.kestra.plugin.core.flow.If
description: Verifies whether Suricata packet drop totals or ring buffer full
events exceed security operational ceilings.
condition: "{{ outputs.scan_suricata_engine_metrics.vars.is_alerting and
inputs.alert_on_packet_drops }}"
then:
- id: notify_slack_secops_team
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
description: Dispatches high-urgency incident notification to SecOps Slack
channel detailing Suricata packet inspection drops.
url: "{{ secret('SLACK_WEBHOOK_URL') }}"
payload: |
{
"channel": "#secops-monitoring-alerts",
"username": "Suricata IDS Sentinel",
"icon_emoji": ":shield:",
"text": "CRITICAL: Suricata AF_PACKET socket overruns detected on interface `{{ inputs.sensor_interface }}`. Total Drops: `{{ outputs.scan_suricata_engine_metrics.vars.total_dropped_packets }}` (threshold: `{{ inputs.max_dropped_packets_threshold }}`). Kernel Drops: `{{ outputs.scan_suricata_engine_metrics.vars.kernel_drops_count }}`. Ring Buffer Full: `{{ outputs.scan_suricata_engine_metrics.vars.ring_full_events_count }}`. Packets are bypassing IDS inspection without threat signature matching."
}
else:
- id: log_nominal_suricata_state
type: io.kestra.plugin.core.log.Log
description: Records nominal telemetry when Suricata inspection engine processes
ingress frames without buffer overruns.
message: "Suricata sensor {{ inputs.sensor_interface }} nominal. Processed {{
outputs.scan_suricata_engine_metrics.vars.packets_processed_count }}
packets. Total drops: {{
outputs.scan_suricata_engine_metrics.vars.total_dropped_packets }} is
below threshold {{ inputs.max_dropped_packets_threshold }}."
- id: emit_audit_manifest
type: io.kestra.plugin.core.debug.Return
description: Emits structured audit manifest for network security compliance
records and threat monitoring archives.
format: |
{
"status": "{{ outputs.scan_suricata_engine_metrics.vars.is_alerting ? 'ALERT' : 'NOMINAL' }}",
"interface": "{{ inputs.sensor_interface }}",
"total_dropped_packets": {{ outputs.scan_suricata_engine_metrics.vars.total_dropped_packets }},
"kernel_drops": {{ outputs.scan_suricata_engine_metrics.vars.kernel_drops_count }},
"ring_full_events": {{ outputs.scan_suricata_engine_metrics.vars.ring_full_events_count }},
"audit_timestamp": "{{ outputs.scan_suricata_engine_metrics.vars.audit_timestamp }}"
}
triggers:
- id: periodic_suricata_audit
type: io.kestra.plugin.core.trigger.Schedule
cron: "*/15 * * * *"