This discussion has been locked. The information referenced herein may be inaccurate due to age, software updates, or external references.
You can no longer post new replies to this discussion. If you have a similar question you can start a new discussion in this forum.

Troubleshooting Alert Archiver Script

Hey all,

I'm stuck troubleshooting this PowerShell script. The purpose of the script is to backup alerts and store them in a folder as XML files. It is working flawlessly for the majority of alerts, however, there are 3 specific alerts that it is failing on. It goes as far as storing the alert XML file in the proper location but the file is empty. 

Any insight or assistance would be greatly appreciated!

Here is the error message and the 3 alerts that it's failing on. I've also included the full PowerShell script below:

Application Connection status is in Warning or Critical state

Exceeded AWS CloudWatch free polling limit

Exceeded Azure Cloud Monitor API free polling limit

Invoke-SwisVerb : ProvideFault failed, check fault information.
At C:\SW_Export\AlertArchiver.ps1:51 char:22
+ ... rtedAlert = Invoke-SwisVerb $swis Orion.AlertConfigurations Export $a ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Invoke-SwisVerb], FaultException`1
    + FullyQualifiedErrorId : SwisError,SwisPowerShell.InvokeSwisVerb

Import-Module pscx -Verbose

<#------------- FUNCTIONS -------------#>
Function Set-SwisConnection {
  Param(
      [Parameter(Mandatory=$true, HelpMessage = "What SolarWinds server are you connecting to (Hostname or IP)?" ) ] [string] $solarWindsServer,
      [Parameter(Mandatory=$true, HelpMessage = "Do you want to use the credentials from PowerShell [Trusted], or a new login [Explicit]?" ) ] [ ValidateSet( 'Trusted', 'Explicit' ) ] [ string ] $connectionType,
      [Parameter(HelpMessage = "Which credentials should we use for an explicit logon type" ) ] $creds
  )
  IF ( $connectionType -eq 'Trusted' ) {
    $swis = Connect-Swis -Trusted -Hostname $solarWindsServer
  } ELSEIF(!$creds) {
      $creds = Get-Credential -Message "Please provide a Domain or Local Login for SolarWinds"
      $swis = Connect-Swis -Credential $creds -Hostname $solarWindsServer
  } ELSE {
    $swis = Connect-Swis -Credential $creds -Hostname $solarWindsServer
  }
  RETURN $swis
}

<#------------- ACTUAL SCRIPT -------------#>

clear-host
$now = Get-Date -Format "yyyyMMdd_HHmm"
$script = $MyInvocation.MyCommand
try { $dir = Split-Path $script.path }
catch { }

$Logfile = "$dir\$($script.name)_$now.log"
Start-Transcript -Path $Logfile -Append -IncludeInvocationHeader | Out-Null

while(!$swistest) {
  $hostname = Read-Host -Prompt "what server should we connect to?"
  $connectionType = Read-Host -Prompt "Should we use the current powershell credentials [Trusted], or specify credentials [Explicit]?"
  $swis = Set-SwisConnection $hostname $connectionType
  $swistest = get-swisdata $swis "SELECT TOP 1 servername FROM Orion.Websites"
}

"Connected to $hostname Successfully using $connectiontype credentials"

# set up path to current user desktop
$UserPath = "C:\SW_Export\Alerts\"
if((test-path $userpath) -eq $false) {$newfolder = md -path $UserPath}

# get enabled alerts
$Alerts = Get-SwisData -SwisConnection $swis -Query "SELECT AlertID, Name ,REPLACE(REPLACE(Name,':',''), '/', '') as NewName FROM Orion.AlertConfigurations WHERE Enabled = 'true' order by NewName"

# export the alerts to xml
foreach ($Alert in $Alerts) {
    $ExportedAlert = Invoke-SwisVerb $swis Orion.AlertConfigurations Export $alert.AlertID
    " Exporting alert named: $($alert.NewName) to $UserPath"
    $ExportedAlert | Format-Xml | Out-File ($UserPath + "$($alert.NewName).xml")
}

"Finished"
Stop-Transcript

#Example of importing the alert back in
#$abc = ([xml](get-content -Path ($UserPath + "$($alert.Name).xml"))).return
#$result = Invoke-SwisVerb $swis Orion.AlertConfigurations Import $abc

  • Been a while since I wrote that, almost didn't recognize it.  

    I never ran into this myself because I disabled all OOTB alerts.  I created a copy of that alert, it had the same problem exporting.  So then I deleted the action and it worked.   Looks like there is something funky in that SQL message that the api export function doesn't like. 

  • It's a beautifully written script, thank you for writing and sharing it!

    I just did the same as you - Copied the alerts and deleted the actions. I re-ran the script and it worked perfect! Thank you!