Skip to content

Instantly share code, notes, and snippets.

@NiceRath
Created December 22, 2024 08:31
Show Gist options
  • Save NiceRath/cf417d23c5bb944a02fde1ad2a5b2acf to your computer and use it in GitHub Desktop.
Save NiceRath/cf417d23c5bb944a02fde1ad2a5b2acf to your computer and use it in GitHub Desktop.
How to Monitor MSSQL Agent-Jobs
# discover all existing agent-jobs
SELECT name, step_name, jobs.job_id FROM msdb.dbo.sysjobsteps job_steps INNER JOIN msdb.dbo.sysjobs jobs ON jobs.job_id = job_steps.job_id
# get status for each job
SELECT subsystem, database_name, command, last_run_outcome, last_run_duration, last_run_date, last_run_time FROM msdb.dbo.sysjobsteps WHERE step_name = '{#STEP_NAME}' AND job_id = '{#JOB_ID}'
# check the status and trigger if not ok
## json query: $..last_run_outcome.first()
## error if last_run_outcome=0
@NiceRath
Copy link
Author

Note: Zabbix covers this in their template: https://www.zabbix.com/integrations/mssql

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment