Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: enable/disable alert blackout via commandline #1199

Open
tvanzeleDelen opened this issue Jan 28, 2025 · 1 comment
Open

Comments

@tvanzeleDelen
Copy link

Hi,

Thanks for the alerting feature!

Would it be possible to enable/disable alert blackout periods via commandline, then we could integrate this in our pipelines for automated restores and patching.

Thanks

@DavidWiseman
Copy link
Collaborator

It seems like a good idea to include this as part of your automation. You could use dbatools to add and remove the blackout periods.

$ConnectionID ="INSTANCE_NAME_HERE"

$BlackoutPeriodID = New-DbaSqlParameter -ParameterName "BlackoutPeriodID" -SqlDbType Int -Direction Output
$params = @{
   BlackoutPeriodID = $BlackoutPeriodID
   StartDate = [DateTime]::UtcNow
   EndDate   = [DateTime]::UtcNow.AddHours(1) # 1hr duration
   ConnectionID=$ConnectionID
}
# Create blackout period
Invoke-DbaQuery -SqlInstance LOCALHOST -Database DBADashDB -Query "Alert.BlackoutPeriod_Add" -CommandType StoredProcedure -SqlParameters $params

# Do maintenance here
Start-Sleep -Seconds 30

# Remove blackout period

$BlackoutPeriodID = New-DbaSqlParameter -ParameterName "BlackoutPeriodID" -SqlDbType Int -Direction Input -Value $BlackoutPeriodID.Value

Invoke-DbaQuery -SqlInstance LOCALHOST -Database DBADashDB -Query "Alert.BlackoutPeriod_Del" -CommandType StoredProcedure -SqlParameters $BlackoutPeriodID

Hope this helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants