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

Dnsmasq DHCP Lease Exhaustion and DNS NXDOMAIN Rate Sentinel

Audits dnsmasq edge gateway telemetry to detect DHCP pool address exhaustion and upstream DNS SERVFAIL queries before edge IoT devices disconnect.

Categories
CoreInfrastructure

Audits dnsmasq lightweight DNS forwarder and DHCP server instances across branch office gateways and edge computing clusters to detect address pool exhaustion and resolution failures.

How it works

  1. A schedule trigger executes the edge network audit workflow every 15 minutes.
  2. The Python task queries the dnsmasq Prometheus exporter endpoint (dnsmasq-exporter:9153).
  3. The script extracts active DHCP allocated lease counts, maximum pool limits, NXDOMAIN query spikes, and upstream SERVFAIL errors.
  4. An evaluation gate determines whether DHCP lease utilization percentages or DNS resolution failures breach operational tolerance bounds.
  5. When thresholds are breached, a high-priority Slack alert is dispatched to network engineering and edge SREs.
  6. When DHCP pools and DNS forwarders operate cleanly within safety limits, nominal telemetry is logged.
  7. A structured JSON audit manifest is emitted for network infrastructure compliance logs and edge capacity SLA archives.

Architecture diagram

graph TD
    Trigger[Schedule Trigger: 15m] --> ScanMetrics[Python Script: Scrape Dnsmasq Exporter Metrics]
    ScanMetrics --> EvalBreach{Lease Util >= Threshold OR SERVFAIL > 50?}
    EvalBreach -- Yes --> SlackAlert[Slack: High-Urgency NetOps Alert]
    EvalBreach -- No --> LogNominal[Log: Nominal Dnsmasq Gateway State]
    SlackAlert --> EmitManifest[Debug Return: Dnsmasq Audit Manifest]
    LogNominal --> EmitManifest

Architecture components

  • Trigger: Automated schedule polling at 15-minute intervals.
  • Script Task: Scrapes dnsmasq Prometheus exporter metrics using Docker container isolation.
  • Decision Gate: Evaluates whether DHCP lease pool allocation exceeds stability safety limits.
  • Notification Task: Dispatches structured Slack alerts with gateway identity and lease capacity metrics.
  • Audit Manifest: Emits JSON execution payloads containing edge network capacity and timestamps.

Key capabilities

  • Continuous surveillance of dnsmasq edge DHCP server address pool utilization.
  • Rapid detection of MAC address churn, rogue client storms, and IP lease table exhaustion.
  • Early warning before edge retail terminals, point-of-sale systems, or IoT nodes fail DHCP DISCOVER handshakes.
  • Zero external dependency execution via isolated containerized Python runners.

What you get

  • Preemptive alerting on edge network address starvation before field devices lose network connectivity.
  • Automated tracking of DNS forwarding error rates and upstream resolver reachability.
  • Real-time audit manifests capturing gateway capacity health for SOC 2 edge infrastructure compliance.
  • Configurable tolerance thresholds adaptable to regional branch offices and micro-datacenters.

Who it's for

  • Edge infrastructure engineers and Network Operations Center (NOC) teams managing distributed appliances.
  • Site Reliability Engineers (SREs) maintaining hybrid edge computing clusters and IoT gateways.
  • Retail systems administrators overseeing store branch office networking and local DNS caches.
  • Industrial IoT platform engineers monitoring automated factory floor DHCP assignment stability.

Why orchestrate this with Kestra

  • Deterministic Scheduling: Guarantees regular gateway health audits without fragile local crontab scripts.
  • 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

  • Guest Wi-Fi Address Starvation: Detects rapid DHCP pool exhaustion caused by transient visitor smartphone connections.
  • Upstream ISP DNS Failure: Alerts when upstream recursive DNS forwarders fail and generate widespread SERVFAIL responses.
  • Rogue MAC Spoofing Storm: Identifies malicious or buggy edge clients issuing thousands of unique DHCPDISCOVER requests.
  • Branch Office Lease Pruning: Verifies that expired lease recycling functions properly following office reopenings.

Inputs

Name Type Default Description
dnsmasq_metrics_url STRING http://dnsmasq-exporter.edge.svc.cluster.local:9153 Base HTTP URL exposing dnsmasq Prometheus metrics.
gateway_cluster_id STRING edge-branch-gw-us-central Target edge gateway or branch office appliance identifier.
max_lease_utilization_percent INT 85 Maximum allowable DHCP lease pool utilization percentage before alerting.
lookback_minutes INT 15 Lookback evaluation window in minutes for failure rates.
alert_on_dnsmasq_failures BOOL true Toggle Slack alert dispatch upon detecting lease exhaustion.

Expected outputs

  • {{ outputs.scan_dnsmasq_gateway_metrics.vars.dhcp_leases_allocated_count }}: Count of currently active DHCP leases.
  • {{ outputs.scan_dnsmasq_gateway_metrics.vars.dhcp_leases_max_count }}: Maximum configured pool lease capacity for the gateway.
  • {{ outputs.scan_dnsmasq_gateway_metrics.vars.dhcp_lease_utilization_pct }}: Percentage of allocated DHCP pool addresses in use.
  • {{ outputs.scan_dnsmasq_gateway_metrics.vars.dns_queries_servfail_count }}: Count of failed DNS queries returning SERVFAIL status.
  • {{ outputs.scan_dnsmasq_gateway_metrics.vars.is_alerting }}: Boolean flag indicating whether utilization thresholds were breached.
  • {{ outputs.emit_audit_manifest.value }}: Structured JSON audit manifest emitted for compliance archives.

Prerequisites

  • Dnsmasq daemon configured with dnsmasq-exporter exposing metrics on port 9153.
  • Exporter endpoint 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. Ensure dnsmasq daemon runs with lease file recording enabled (/var/lib/misc/dnsmasq.leases).
  2. Configure the SLACK_WEBHOOK_URL secret in your Kestra namespace settings.
  3. Specify your edge gateway identifier in gateway_cluster_id.
  4. Execute a manual test run via the Kestra UI to verify metric ingestion.
  5. Enable the periodic_dnsmasq_audit trigger to establish automated continuous surveillance.

Common pitfalls and troubleshooting

  • Lease File Access Permissions: Ensure dnsmasq-exporter has read access to the active lease file.
  • Lease Time Tuning: Excessively long lease times (e.g. 7 days) lead to artificial pool exhaustion in high-churn environments.
  • DNS Query Rate Limits: Verify dnsmasq.conf does not trigger dns-forward-max query drops under peak loads.
  • Upstream Forwarder Health: Ensure multiple fallback upstream nameservers (e.g. Quad9, Cloudflare) are configured.

How to extend

  • Automated Lease Table Purge: Chain an SSH command task to safely prune stale expired leases when pool utilization hits 95%.
  • Dynamic Subnet Expansion: Trigger an infrastructure automation flow to allocate a secondary /24 DHCP subnet on exhaustion.
  • PagerDuty Escalation: Escalate to on-call network engineers if SERVFAIL errors exceed 200 within a 15-minute window.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.