ps/Modules/Alkami.PowerShell.Services/Public/Test-NagTriggers.ps1
2023-05-30 22:51:22 -07:00

43 lines
1.3 KiB
PowerShell

function Test-NagTriggers {
<#
.SYNOPSIS
Tests that the dbo.nag_triggers db contains valid triggers for the masterdatabase configuring the machine.config master connection string for a pod
#>
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()
$query = New-Object System.Data.SqlClient.SqlCommand("SELECT count(*) FROM [dbo].[NAG_TRIGGERS] where TRIGGER_STATE = 'WAITING'", $conn)
$numberofWaitingTriggers = $query.ExecuteScalar()
if ($numberofWaitingTriggers -eq 0 ) {
throw "No Triggers present for Nag, Check if Nag is running"
}
Write-Host "Found $numberofWaitingTriggers Triggers in the waiting state."
}
catch {
Write-Warning "An exception occurred while trying to Check Nag Triggers"
Write-Warning $error[0] | Format-List -Force
return $null
}
finally {
if ($conn.State -ne [System.Data.ConnectionState]::Closed) {
$conn.Close()
}
$conn = $null
}
}