Need assistance with writing a powershell script to stop the AG Lag Alert on a cluster during a specific time frame. It happens daily at the same time so i would like to have redgate not alert on it for a 3 hour window.
Comments
2 comments
-
Here's a concise PowerShell script to disable the AG Lag Alert during a 3-hour window:
powershellCopy code
$startTime = "14:00" # 2:00 PM $endTime = "17:00" # 5:00 PM $currentTime = Get-Date -Format "HH:mm" $alertName = "AG_Lag_Alert" if ($currentTime -ge $startTime -and $currentTime -lt $endTime) { Write-Host "Disabling AG Lag Alert" Stop-SqlAgentJob -JobName $alertName # Adjust based on your alert system } else { Write-Host "Alert remains active" }
Adjust
Stop-SqlAgentJob
or alert handling based on your setup. -
Here’s a PowerShell script to stop AG Lag Alert on a cluster during a specific time frame using Redgate SQL Monitor:
powershellCopy code
# Set parameters $AGName = "YourAvailabilityGroupName" $ClusterName = "YourClusterName" $StartTime = "09:00" # Start time for the 3-hour window (e.g., 09:00) $EndTime = "12:00" # End time for the 3-hour window (e.g., 12:00) # Connect to SQL Monitor $SqlMonitor = Connect-SqlMonitor # Get the AG lag alert $Alert = Get-SqlMonitorAlert -Monitor $SqlMonitor -Name "AG Lag Alert" # Disable alert during the time frame Disable-SqlMonitorAlert -Alert $Alert -Cluster $ClusterName -StartTime $StartTime -EndTime $EndTime Write-Output "AG Lag Alert disabled for the $StartTime to $EndTime window."
This script connects to Redgate SQL Monitor, retrieves the AG Lag Alert, and disables it for the specified 3-hour window. Adjust
$AGName
,$ClusterName
,$StartTime
, and$EndTime
to match your cluster configuration.
Add comment
Please sign in to leave a comment.