Created
December 22, 2024 08:31
-
-
Save NiceRath/cf417d23c5bb944a02fde1ad2a5b2acf to your computer and use it in GitHub Desktop.
How to Monitor MSSQL Agent-Jobs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note: Zabbix covers this in their template: https://www.zabbix.com/integrations/mssql