Skip to content

Commit 7cc0797

Browse files
committed
changes for #3732
1 parent 56ac912 commit 7cc0797

1 file changed

Lines changed: 33 additions & 1 deletion

File tree

sp_Blitz.sql

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3740,6 +3740,14 @@ AS
37403740

37413741
IF @Debug IN (1, 2) RAISERROR('Running CheckId [%d].', 0, 1, 94) WITH NOWAIT;
37423742

3743+
;WITH las_job_run AS (
3744+
SELECT MAX(instance_id) AS instance_id,
3745+
job_id, COUNT_BIG(*) AS job_executions,
3746+
SUM(CASE WHEN run_status = 0 THEN 1 ELSE 0 END) AS failed_executions
3747+
FROM msdb.dbo.sysjobhistory
3748+
WHERE step_id = 0
3749+
GROUP BY job_id
3750+
)
37433751
INSERT INTO #BlitzResults
37443752
( CheckID ,
37453753
Priority ,
@@ -3754,8 +3762,32 @@ AS
37543762
'Agent Jobs Without Failure Emails' AS Finding ,
37553763
'https://www.brentozar.com/go/alerts' AS URL ,
37563764
'The job ' + [name]
3757-
+ ' has not been set up to notify an operator if it fails.' AS Details
3765+
+ ' has not been set up to notify an operator if it fails.'
3766+
+ CASE
3767+
WHEN jh.run_date IS NULL OR jh.run_time IS NULL OR jh.run_status IS NULL THEN ''
3768+
ELSE N' Executions: '+ CAST(ljr.job_executions AS VARCHAR(30))
3769+
+ CASE ljr.failed_executions
3770+
WHEN 0 THEN N''
3771+
ELSE N' ('+CAST(ljr.failed_executions AS NVARCHAR(10)) + N' failed)'
3772+
END
3773+
+ N' - last execution started on '
3774+
+ CAST(CONVERT(DATE,CAST(jh.run_date AS NVARCHAR(8)),113) AS NVARCHAR(10))
3775+
+ N', at '
3776+
+ STUFF(STUFF(RIGHT(N'000000' + CAST(jh.run_time AS varchar(6)),6),3,0,N':'),6,0,N':')
3777+
+ N', with status "'
3778+
+ CASE jh.run_status
3779+
WHEN 0 THEN N'Failed'
3780+
WHEN 1 THEN N'Succeeded'
3781+
WHEN 2 THEN N'Retry'
3782+
WHEN 3 THEN N'Canceled'
3783+
WHEN 4 THEN N'In Progress'
3784+
END +N'".'
3785+
END AS Details
37583786
FROM msdb.[dbo].[sysjobs] j
3787+
LEFT JOIN las_job_run ljr
3788+
ON ljr.job_id = j.job_id
3789+
LEFT JOIN msdb.[dbo].[sysjobhistory] jh
3790+
ON ljr.job_id = jh.job_id AND ljr.instance_id = jh.instance_id
37593791
WHERE j.enabled = 1
37603792
AND j.notify_email_operator_id = 0
37613793
AND j.notify_netsend_operator_id = 0

0 commit comments

Comments
 (0)