<Discovery ID="Microsoft.SystemCenter.ServiceReporting.2012.ServiceReporting.DiscoveryRule" Target="SQLLibrary!Microsoft.SQLServer.DBEngine" Enabled="true" ConfirmDelivery="false" Remotable="true" Priority="Normal" Comment="This discovery discovers instances of the ServiceReporting service as instances of the ServiceReporting class.">
<Category>Discovery</Category>
<DiscoveryTypes>
<DiscoveryClass TypeID="Microsoft.SystemCenter.ServiceReporting.2012.ServiceReportingService">
<Property TypeID="SRLibraryMP!Microsoft.SystemCenter.ServiceReporting.ServiceReportingService" PropertyID="ScheduleInterval"/>
<Property TypeID="SRLibraryMP!Microsoft.SystemCenter.ServiceReporting.ServiceReportingService" PropertyID="JobName"/>
<Property TypeID="SRLibraryMP!Microsoft.SystemCenter.ServiceReporting.ServiceReportingService" PropertyID="ConnectionString"/>
</DiscoveryClass>
</DiscoveryTypes>
<DataSource ID="DS" TypeID="Windows!Microsoft.Windows.TimedPowerShell.DiscoveryProvider" RunAs="SQLLibrary!Microsoft.SQLServer.SQLDiscoveryAccount" Comment="The data source for this discovery is a query to the Service Reporting database that confirms the presence of the Service Reporting feature.">
<IntervalSeconds>14400</IntervalSeconds>
<SyncTime/>
<ScriptName>ServiceReporting Discover Rule TimedPowerShell Discovery Provider Script</ScriptName>
<ScriptBody><Script>
param
(
$ConnectionString,
$CommandText
)
# Get known properties for the discovered instance
$oAPI.LogScriptEvent("ServiceReportingDiscovery.ps1", 100, 0, "Start Service Reporting service job discovery in $ConnectionString.")
try
{
$ErrorActionPreference = "Stop"
-- Job schedule
SELECT @JobId = j.job_id,
@ScheduleInterval = CASE
WHEN s.freq_type = 4 AND s.freq_interval = 1 AND s.freq_subday_type = 1 THEN 24 * 60 -- every 1 day, at specified time
WHEN s.freq_type = 4 AND s.freq_interval = 1 AND s.freq_subday_type = 2 THEN s.freq_subday_interval / 60 -- every 1 day, every n seconds
WHEN s.freq_type = 4 AND s.freq_interval = 1 AND s.freq_subday_type = 4 THEN s.freq_subday_interval -- every 1 day, every n minutes
WHEN s.freq_type = 4 AND s.freq_interval = 1 AND s.freq_subday_type = 8 THEN s.freq_subday_interval * 60 -- every 1 day, every n hours
ELSE 24 * 60 -- all others to be set as 1 day
END
FROM msdb.dbo.sysjobs j
JOIN msdb.dbo.sysjobschedules js
ON j.job_id = js.job_id
JOIN msdb.dbo.sysschedules s
ON s.schedule_id = js.schedule_id
WHERE j.name = @JobName
-- Output results
SELECT @JobName AS [Job Name],
@JobId AS [JobId],
ISNULL(@ScheduleInterval, 0) AS [Schedule Interval (Minutes)]
WHERE @JobId IS NOT NULL
</Value>
</Parameter>
</Parameters>
<TimeoutSeconds>300</TimeoutSeconds>
</DataSource>
</Discovery>