-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathMigrateAlerts.ps1
More file actions
35 lines (30 loc) · 1.59 KB
/
MigrateAlerts.ps1
File metadata and controls
35 lines (30 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<#------------- CONNECT TO SWIS -------------#>
#define old host, credentials, and sql connection string
$hostnameold = 'oldserver'
#$userold = "user"
#$passwordold = "pass"
# create a connection to the SolarWinds API
#$swissource = connect-swis -host $hostnameold -username $userold -password $passwordold -ignoresslerrors
$swissource = Connect-Swis -Hostname $hostnameold -Trusted
#define new host, credentials, no sql string is necessary
$hostnamenew = 'newserver'
#$usernew = "user"
#$passwordnew = "pass"
# create a connection to the SolarWinds API
#$swisdest = connect-swis -host $hostnamenew -username $usernew -password $passwordnew -ignoresslerrors
$swisdest = Connect-Swis -Hostname $hostnamenew -Trusted
<#------------- ACTUAL SCRIPT -------------#>
# get Alert IDs for enabled alerts
$AlertIDs = Get-SwisData -SwisConnection $swissource -Query "SELECT AlertID FROM Orion.AlertConfigurations WHERE Enabled = 'true' and name not like '%syslog%'"
# migrate the alerts
foreach ($AlertID in $AlertIDs) {
$AlertName = Get-SwisData -SwisConnection $swissource -Query "SELECT Name FROM Orion.AlertConfigurations WHERE AlertID = $AlertID"
$Existing = Get-SwisData -SwisConnection $swisdest "select name from orion.alertconfigurations where name = '$AlertName'"
if ($existing.count -eq 0) {
write-output "Migrating alert named: $AlertName"
$ExportedAlert = Invoke-SwisVerb $swissource Orion.AlertConfigurations Export $AlertID
Invoke-SwisVerb $swisdest Orion.AlertConfigurations Import $ExportedAlert
} else {
"Alert named: $AlertName already exists, skipping"
}
}