info@techdevops.com | 437-991-3573 | Data Engineering Services
TechDevOps.com
Resources Tools
Experts in Microsoft SQL Server on Windows, Linux, Containers | Clusters, Always On, FCI | Migrations, Cloud, Performance



View SQL Job Last Status in Microsoft System Center
by BF (Principal Consultant; Architecture; Engineering)
2019-05-03







--View SQL Jobs Last Status in System Center


Declare @SQLServer varchar(250) = ''
Declare @SQLJobName varchar(250) = ''
SELECT
bme.Path,
bme.DisplayName as 'Entity Display Name',
mv.DisplayName AS 'Monitor Display Name',
Case s.HealthState When 1 Then 'Success' When 2 Then 'Failed' Else '?' End As 'Health State',
DateAdd(HH, -4, s.LastModified) AS 'State Last Modified',
mv.AlertOnState,
mv.AlertPriority,
mv.AlertSeverity,
mv.AlertAutoResolve,
mv.Name AS 'Monitor Name',
bme.FullName AS 'Target'
FROM [OperationsManager].[dbo].[State] s
JOIN BaseManagedEntity bme ON s.BaseManagedEntityId = bme.BaseManagedEntityId
JOIN MonitorView mv ON mv.Id = s.MonitorId
WHERE bme.[Path] Like '%MSSQLSERVER%' and mv.DisplayName = 'Last Run Status'
and (@SQLServer = '' or [Path] Like '%' + @SQLServer + '%')
and (@SQLJobName = '' or bme.DisplayName = @SQLJobName)
Order By
--bme.Path ASC,
--bme.DisplayName ASC
s.LastModified Desc