Schedule icon
Script icon
Process icon
Loop icon
If icon
SlackIncomingWebhook icon
Log icon

Windows Service Restart Storm and Recovery Action Audit

Audit Windows System log for services that terminate unexpectedly in bursts, score restart storms, check recovery actions, and alert Slack.

Categories
Infrastructure

Windows services that crash at three in the morning and restart themselves four times before anyone notices are one of the most under-monitored failure modes on a server fleet. The System event log already knows about every one of them - Service Control Manager writes event 7031 and 7034 each time a service terminates, and event 7000 each time one fails to start - but nobody reads that log until a user complains. This blueprint turns those records into a scored daily audit: it collects the termination events over a configurable window, groups them per service, flags any service that crossed the storm threshold, resolves every culprit to its real service name, checks whether a recovery action is actually configured, and posts a single Slack alert only when a storm is confirmed.

How it works

  1. The daily trigger (io.kestra.plugin.core.trigger.Schedule) runs the audit every morning at 06:00 so overnight storms are on the desk at shift start. Manual runs accept windowHours, stormThreshold and includeUnexpectedShutdowns as inputs.
  2. The collect_and_score task (io.kestra.plugin.scripts.powershell.Script on the Process task runner so it reads the host's own event log) pulls System events 7031, 7034, 7000 and optionally 6008 with Get-WinEvent, parses the service name out of each message, maps display names to service names through Win32_Service, groups terminations per service, and scores every service that reached the threshold. For each storm service it also runs sc.exe qfailure and records whether a recovery command line is configured. The full event list is written to service_events.json as an output file and the verdict is emitted as task variables.
  3. The per_service_recovery_audit task (io.kestra.plugin.core.flow.Loop) walks the storm services one at a time, re-reads each service's current state, start mode and recovery configuration, and logs a one-line audit trail per service that survives in the execution history.
  4. The alert_if_storm task (io.kestra.plugin.core.flow.If) branches on the scored verdict: a confirmed storm posts one Slack message with the machine, the storm count, the worst offender and the services missing recovery actions; a clean window writes a single all-clear log line instead.
  5. The errors handler posts a Slack notice with allowFailure: true, so a broken collector or an unreadable event log escalates instead of failing silently.

What you get

  • A daily, scored verdict per machine: STORM or CLEAR, with the event total, the worst offending service and the services that lack recovery actions.
  • A service_events.json artifact attached to every execution with the full event list, ready for trend analysis or compliance evidence.
  • One Slack alert per storm instead of one alert per crash, with the recovery-action gap called out so the fix is obvious.
  • A per-service recovery audit trail in the execution history that shows state and start mode at the time of the run.

Who it's for

  • Windows fleet operators who suspect services are crash-looping overnight but have no alerting on the System log.
  • Site reliability teams standardising restart-storm thresholds across branch, edge or virtualisation hosts.
  • Administrators proving to a vendor that a service is terminating repeatedly and has no recovery action configured.

Why orchestrate this with Kestra

Get-WinEvent and sc.exe are one-liners on a single box, but a fleet needs the collection, the threshold scoring, the recovery-action audit and the escalation to live in one place with a schedule, inputs, an execution history and a guaranteed error path. Kestra gives the audit a schedule and typed inputs, keeps every run's JSON artifact and per-service audit trail, and puts the Slack escalation behind a conditional so quiet nights stay quiet. Running it as a flow also means the same definition can be pointed at many machines through a Loop over a CMDB list instead of a scheduled task on each host.

Prerequisites

  • A Windows Kestra worker with the Process task runner available, since the audit must read the host's own System log and the default Docker runner cannot see it.
  • PowerShell 5.1 or pwsh and read access to the System event log, plus permission to run sc.exe.
  • A Slack incoming webhook stored as the SLACK_WEBHOOK_URL secret.
  • The service-name parser reads English Service Control Manager messages; on non-English Windows adjust the two regex patterns in collect_and_score to the local message format.

Secrets

  • SLACK_WEBHOOK_URL: Slack incoming webhook used by the storm alert and by the on-error handler.

Quick start

  1. Add the SLACK_WEBHOOK_URL secret to the namespace and deploy the flow on a Windows worker.
  2. Run it manually with the default 24 hour window and threshold of 3; inspect service_events.json and the emitted verdict in the outputs tab.
  3. Lower stormThreshold to 1 once to see the Slack alert path fire end to end.
  4. Leave the schedule at 06:00 or align it with your shift handover, then extend the collect_and_score script to fan out over a host list with a Loop.

How to extend

  • Fan the audit out over a fleet by wrapping the collector in io.kestra.plugin.core.flow.Loop over a host list and passing -ComputerName to Get-WinEvent over WinRM.
  • Add event 6037, 6009 or provider-specific crash events to the id list to widen the failure picture.
  • Enrich the Slack alert with the dump file path by parsing the matching Windows Error Reporting event and attaching it to the execution.
  • Persist service_events.json to S3 or a database for multi-week trend lines on the same service.
  • Escalate a repeated storm to ServiceNow or Jira with the existing plugin tasks instead of Slack.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.