function Test-RadiumMetaData { <# .SYNOPSIS Tests that dbo.JobMetaData contains some work, and that the number of failed jobs is less than 5% of the total number of jobs #> param( ) $masterConnectionString = Get-MasterConnectionString try { $conn = New-Object System.Data.SqlClient.SqlConnection $conStrBuilder = New-Object System.Data.SqlClient.SqlConnectionStringBuilder($masterConnectionString) $conn.ConnectionString = $conStrBuilder.ToString() $conn.Open() $command = New-Object System.Data.SqlClient.SqlCommand("select Status, Count(status) as count from dbo.JobMetadata where RunDateTimeUtc > DateADD(mi, -30, GETUTCDATE()) group by status", $conn) $adapter = New-Object System.Data.sqlclient.sqlDataAdapter $command $dataset = New-Object System.Data.DataSet $adapter.Fill($dataSet) | Out-Null $failedJobs = 0 $totalJobs = 0 $successfullJobs = 0 $dataset.Tables[0].Rows | ForEach-Object { if ($_.Status -eq 4) { $failedJobs += $_.Count } if ($_.Status -eq 2) { $successfullJobs += $_.Count } $totalJobs += $_.Count } if (($successfullJobs -eq 0) -and ($totalJobs -gt 0)) { throw "No jobs have been successful in last 10 minutes, even though $totalJobs have ran" } if (($totalJobs -gt 0) -and (($failedJobs / $totalJobs) -gt .005)) { throw "the number of failed jobs exceeded 5% $failedJobs occurred out of $totalJobs" } Write-Host "There are $totalJobs total jobs $failedJobs failed jobs, and $successfullJobs successful jobs in the last 10 minutes " } catch { $warning = "An exception occurred while trying to Check Radium Triggers" Write-Warning $warning Write-Warning $error[0] | Format-List -Force throw $warning } finally { if ($conn.State -ne [System.Data.ConnectionState]::Closed) { $conn.Close() } $conn = $null } }