Script icon
Docker icon
If icon
SlackIncomingWebhook icon
Log icon
Return icon
Schedule icon

Keepalived VRRP State Transition Flapping Sentinel

Monitors Keepalived VRRP daemon transitions to prevent virtual IP flapping, split-brain dual-master states, and gateway drops.

Categories
CloudInfrastructure

Audits Keepalived VRRP telemetry across high-availability load balancer and firewall pairs to detect virtual IP state flapping and split-brain election storms.

How it works

  1. A schedule trigger executes the VRRP audit workflow every 15 minutes.
  2. The Python task queries the Keepalived Prometheus exporter endpoint (keepalived-exporter:9650).
  3. The script extracts cumulative state transition counts, multicast advert errors, and active master/backup state.
  4. An evaluation gate determines whether transition frequency or advert packet errors breach stability limits.
  5. When thresholds are breached, a high-priority Slack alert is dispatched to network engineering teams.
  6. When VRRP state remains stable in master or backup mode, nominal status is logged.
  7. A structured JSON audit manifest is emitted for high-availability compliance logs and gateway telemetry archives.

Architecture diagram

graph TD
    Trigger[Schedule Trigger: 15m] --> ScanMetrics[Python Script: Scrape Keepalived VRRP Metrics]
    ScanMetrics --> EvalBreach{Transitions >= Threshold OR Advert Errors > 2?}
    EvalBreach -- Yes --> SlackAlert[Slack: High-Urgency NetOps Incident]
    EvalBreach -- No --> LogNominal[Log: Nominal VRRP Quorum State]
    SlackAlert --> EmitManifest[Debug Return: VRRP Audit Manifest]
    LogNominal --> EmitManifest

Architecture components

  • Trigger: Automated schedule polling at 15-minute intervals.
  • Script Task: Scrapes Keepalived VRRP exporter metrics using Docker isolation.
  • Decision Gate: Evaluates whether VRRP state transition counts exceed operational stability limits.
  • Notification Task: Dispatches structured Slack alerts with instance identifier and transition counts.
  • Audit Manifest: Emits JSON execution payloads containing current state and timestamps.

Key capabilities

  • Continuous surveillance of Keepalived VRRP virtual router election state.
  • Rapid detection of split-brain dual-master scenarios causing ARP cache poisoning.
  • Isolation of multicast advertisement packet drops across physical network switches.
  • Zero external dependency execution via isolated containerized Python runners.

What you get

  • Preemptive alerting on load balancer virtual IP instability and link flapping.
  • Automated detection of multicast network dropouts between active-passive firewall nodes.
  • Real-time audit manifests capturing gateway transition history for compliance audits.
  • Configurable tolerance thresholds adaptable to active-passive and active-active setups.

Who it's for

  • Network engineers maintaining HAProxy and NGINX high-availability virtual IP clusters.
  • Datacenter SREs overseeing bare-metal gateway routers and Linux firewall pairs.
  • Cloud infrastructure teams operating private cloud Kubernetes ingress controllers.
  • DevOps engineers diagnosing intermittent TCP connection reset spikes on VIPs.

Why orchestrate this with Kestra

  • Deterministic Scheduling: Guarantees regular health polling without fragile local host cron jobs.
  • Containerized Runners: Runs Python tasks inside isolated Docker containers without host library dependencies.
  • Condition Branching: Flowable If tasks route alerts and nominal logging cleanly without spaghetti code.
  • Enterprise Secret Safety: Securely injects Slack webhook credentials without plain-text exposure.

Use cases

  • Switch VLAN IGMP Snooping Failure: Detects dropped VRRP multicast packets causing nodes to enter dual-master mode.
  • HAProxy Node Health Flap: Alerts when upstream health check script flapping triggers continuous VRRP demotions.
  • Gratuitous ARP Stall: Identifies transition storms where client switches fail to update MAC address tables.
  • Dual-Master Conflict: Prevents IP collision outages on primary customer-facing ingress endpoints.

Inputs

Name Type Default Description
keepalived_metrics_url STRING http://keepalived-exporter.networking.svc.cluster.local:9650 Base HTTP URL exposing Keepalived Prometheus metrics.
vrrp_instance_id STRING VI_LOAD_BALANCER_EXTERNAL Target VRRP instance name under active surveillance.
max_state_transitions_threshold INT 3 Maximum allowable VRRP state transitions before alerting.
lookback_minutes INT 15 Lookback evaluation window in minutes for transition rate.
alert_on_vrrp_flapping BOOL true Toggle Slack alert dispatch upon detecting VRRP flapping.

Expected outputs

  • {{ outputs.scan_keepalived_vrrp_metrics.vars.state_transitions_count }}: Cumulative number of VRRP state transitions.
  • {{ outputs.scan_keepalived_vrrp_metrics.vars.advert_errors_count }}: Count of advertisement packet reception errors.
  • {{ outputs.scan_keepalived_vrrp_metrics.vars.current_vrrp_state }}: Current VRRP operational state (MASTER or BACKUP).
  • {{ outputs.scan_keepalived_vrrp_metrics.vars.is_master }}: Boolean flag indicating if current node holds master role.
  • {{ outputs.scan_keepalived_vrrp_metrics.vars.is_alerting }}: Boolean flag indicating whether flapping thresholds were breached.
  • {{ outputs.emit_audit_manifest.value }}: Structured JSON audit manifest emitted for compliance archives.

Prerequisites

  • Keepalived daemon running with keepalived_exporter or JSON metrics socket enabled.
  • Keepalived exporter port 9650 reachable from the Kestra worker execution environment.
  • Docker daemon running on the Kestra host to execute containerized Python tasks.

Secrets

  • SLACK_WEBHOOK_URL: Incoming webhook URL for the target NetOps Slack alerting channel.

Quick start

  1. Verify that keepalived_exporter is scraping VRRP status and listening on port 9650.
  2. Configure the SLACK_WEBHOOK_URL secret in your Kestra namespace settings.
  3. Specify your target VRRP instance name in vrrp_instance_id.
  4. Execute a manual test run via the Kestra UI to verify metric ingestion.
  5. Enable the periodic_keepalived_audit trigger to establish automated continuous surveillance.

Common pitfalls and troubleshooting

  • VRRP Protocol 112 Blocking: Firewalls dropping IP protocol 112 cause both nodes to assume MASTER state.
  • Virtual Router ID Collision: VRID collisions with other clusters on the same Layer 2 domain trigger advert errors.
  • Authentication Mismatch: Ensure auth_type PASS passwords match exactly across master and backup nodes.
  • Unicast Peer Misconfiguration: If multicast is blocked in cloud environments, verify unicast peer IP lists.

How to extend

  • Automated ARP Flush Sub-Flow: Trigger an automated arping broadcast task upon detecting failover to clear switch caches.
  • HAProxy Process Restart: Chain a remediation flow to restart unhealthy upstream services when failover is triggered.
  • PagerDuty Escalation: Escalate to on-call network engineers when multiple VRRP instances flap simultaneously.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.