13 Replies Latest reply on Feb 9, 2017 11:41 PM by tdanner

    "Proper" way to export/import Alert Configurations via SDK?

    mulder85gr

      Hello,

       

      I've been trying the new feature of exporting and importing alerts via the SDK in Powershell, with partial success.

       

      For example, the following bit works great:

      #Export Alert with ID = 119

      $ExportedAlert = Invoke-SwisVerb $swis Orion.AlertConfigurations Export 119

       

      #Import Alert from memory, using variable $ExportedAlert

      $AlertImportResult = Invoke-SwisVerb $swis Orion.AlertConfigurations Import $ExportedAlert

       

      The above works great and imports the memory, but what happens if I want to export an alert to a file and then import it on another Orion? What is the best way to save the contents of $ExportedAlert, and then retrieve them on the other Orion in a formatted way that can be imported?

       

      I have tried this:

      $AlertImportResult = Invoke-SwisVerb $swis Orion.AlertConfigurations Import 'PathToAlertFileXml'

       

      Which failes with error message: Alert import failed with error: Data at the root level is invalid. Line 1, position 1.

       

      or

       

      [xml]$TestImport = Get-Content 'PathToFile'

      $AlertImportResult = Invoke-SwisVerb $swis Orion.AlertConfigurations Import $TestImport

       

      Which failed with an actual powershell error.

       

      Has anyone mastered the proper way to export and import Alerts from files?

        • Re: "Proper" way to export/import Alert Configurations via SDK?
          tdanner

          What PowerShell error did you get?

           

          I think all you need to change is removing the [xml] piece from your last script. Like this:

           

          $TestImport = Get-Content 'PathToFile'

          $AlertImportResult = Invoke-SwisVerb $swis Orion.AlertConfigurations Import $TestImport

            • Re: "Proper" way to export/import Alert Configurations via SDK?
              mulder85gr

              Thanks tdanner. I have tried your suggestion but once again the $AlertImportResult.MigrationMessage.'#text' is: Alert import failed with error: Data at the root level is invalid. Line 1, position 1.

               

              The main problem as i see it is, is that the $ExportedAlert variable is of type

              PS C:\windows\system32> $ExportedAlert.GetType()

               

              IsPublic IsSerial Name                                     BaseType                                                                                                        

              -------- -------- ----                                     --------                                                                                                        

              True     False    XmlElement                               System.Xml.XmlLinkedNode 

               

              When we pipe the variable to a file say with this command: $ExportedAlert.InnerText | Out-File C:\SolarWinds_Installation\Alerts\Test.xml

               

              the file is identical to the contents of an actual exported alert from the GUI ( Alert Manager ---> Export Alert).

               

              However when we import the on a variable for importing the alert, the variable needs to be the same type as above with the correct formatting inside it, and that's what I can't seem to get right. So I Suppose the actual question is:

              How do we import the file on a properly formatted System.Xml.XmlLinkedNode variable?

                • Re: "Proper" way to export/import Alert Configurations via SDK?
                  tdanner

                  Almost there. Orion.AlertConfigurations.Import needs the xml dump of the alert as a string. The return value from Orion.AlertConfigurations.Export is the alert xml as a string, but it is wrapped in an XML element. As you discovered the ".InnerText" of this object is the string we need.

                   

                  # On system A

                  $ExportedAlert = Invoke-SwisVerb $swis Orion.AlertConfigurations Export 119

                  Set-Content Alert119.xml $ExportedAlert.InnerText

                   

                  # On system B

                  $AlertXml = Get-Content Alert119.xml

                  Invoke-SwisVerb $swis Orion.AlertConfigurations Import $AlertXml

                    • Re: "Proper" way to export/import Alert Configurations via SDK?
                      I LIKE EGGS

                      hay hay,

                       

                      gonna ask, can you only import alerts that are already imported? iv tried a few ways but when the alert is imported i can run the above and the alert imports but when the alert is removed and then i re try to import the alert with the verb it doesn't work, its like the import needs the alert to be imported first then you can import the alert on top,  i am trying to test the 'system b' really.. 

                       

                      Cheers

                      • Re: "Proper" way to export/import Alert Configurations via SDK?
                        mulder85gr

                        Hey tdanner,

                         

                        Thanks for working on it. I have tried your suggestion and now the error is different:

                         

                        $AlertImportResult.MigrationMessage.'#text'

                        Alert import failed with error: Unexpected end of file has occurred. The following elements are not closed: d2p1:PropertyValue, d2p1:ActionProperty, d2p1:ActionProperties, d

                        2p1:ActionDefinition, ResetActions, AlertDefinition. Line 1, position 2783.

                         

                        I think that the most important reason for failing, (even though the the string inside is identical), is the type of variable. Have a look a this:

                         

                        PS C:\windows\system32> $ExportedAlert.GetType()

                         

                        IsPublic IsSerial Name                                     BaseType                                                                                                        

                        -------- -------- ----                                     --------                                                                                                        

                        True     False    XmlElement                               System.Xml.XmlLinkedNode

                         

                         

                        PS C:\windows\system32> $AlertXml.GetType()

                         

                        IsPublic IsSerial Name                                     BaseType                                                                                                        

                        -------- -------- ----                                     --------                                                                                                        

                        True     True     Object[]                                 System.Array                                                                                                    

                         

                        I am confident that if we can find a way to import the contents of the file into a System.Xml.XmlLinkedNode variable, it should work. Maybe our friends over at StackOverflow could help us on that?