Guide · Databases
Monitor a SQL Server Agent job
Agent operator notifications tell you when a job step raises an error. They stay silent if the Agent service is stopped, the box never comes back after a reboot, or the job is simply skipped. A check-in step closes that gap: no ping, no assumption the job ran.
1. Create a check
Create a check in Mortemain matching the job's schedule and an appropriate grace window, then copy its ping URL.
https://ping.mortemain.com/your-check-uuid
2. Add a check-in step to the job
Open the job's Steps page and add a new step after the last real step. Set its type to PowerShell and give it this command:
Invoke-RestMethod "https://ping.mortemain.com/your-check-uuid" -TimeoutSec 10
No module to install: Invoke-RestMethod ships with the PowerShell that Agent already uses for step type "PowerShell". If you'd rather stick to an Operating system (CmdExec) step, curl.exe ships with Windows Server 2019 and later:
curl.exe -fsS --max-time 10 "https://ping.mortemain.com/your-check-uuid" -o NUL
3. Alert immediately on failure
By default, when any step fails Agent's on-failure action is Quit the job reporting failure, so your success step at the end never runs and Mortemain would only notice once the whole grace window has expired. To get paged the moment the job breaks, add one more dedicated step and re-point every real step at it.
Add a final step, e.g. Ping Fail (PowerShell):
Invoke-RestMethod "https://ping.mortemain.com/your-check-uuid/fail" -TimeoutSec 10
Then, on every real step's Advanced page, change On failure action from the default to Go to step: Ping Fail. The job still ends up reporting failure once Ping Fail quits, but not before Mortemain has been told.
This works the same whether the job was launched by its schedule, an alert, or an ad hoc sp_start_job call: Agent runs the steps identically either way, no special handling needed for how the job was triggered.
4. Optional: track run duration
Add a first step, Ping Start (PowerShell), before any real work, so Mortemain can time the run:
Invoke-RestMethod "https://ping.mortemain.com/your-check-uuid/start" -TimeoutSec 10
With a /start ping in place, Mortemain reports actual run duration alongside up/down status, useful for spotting a job that still finishes, just slower each week.
Test it
Right-click the job and Start Job at Step. The check should flip to up within a few seconds of the last step running. Then temporarily break a step (rename a table it queries, say) and rerun the job: the down alert should land immediately instead of waiting for the schedule's grace window to expire, confirming Ping Fail is wired to every step.