9 Replies Latest reply on Jan 19, 2017 11:42 AM by tdanner

    SWIS or JSON/REST API to bulk IMPORT xml web reports?

    szimmerm

      NPM 11.5.2, NCM 7.4 and SDK 1.10

       

      I have managed to take an xml export of a web based report and using perl, read the file (as one line)  and using regex to replace existing nodeID's, interfaceIDs in the <DataSources> section, Titles and names where applicable.  All other parts of the report are identical.

       

      The new xml file imports nicely via the "import" feature in web reports.

       

      However, I have about 300 of these individual report files.

       

      Does anyone know how to import these via scripting instead of through the web console?

       

      I tried to construct a JSON Invoke but I am pretty sure it didn't like the xml file.  the "definition" field in existing reports has different tag names and such.  Tried using one of those as a template... and it still failed.  I am certain the definition is incorrect.

       

      If anyone has done this successfully, please let me know.  I don't mind looping through each xml file via a script doing an invoke each time.

       

      I also don't mind doing this through swis either. 

       

      Also as a FEATURE REQUEST - being able to select multiple files when importing reports would make this much easier.

      thanks.

        • Re: SWIS or JSON/REST API to bulk IMPORT xml web reports?
          tdanner

          You can import a report with the CreateReport verb on the Orion.Report entity. It expects these parameters:

           

          1. name
          2. description
          3. limitationCategory
          4. category
          5. title
          6. subtitle
          7. definition - the report defintion in XML form
          8. isFavorite - not sure why this is declared as a string, since it must be "true" or "false"
          9. userName - this will be the owner of the report. You can leave it blank.

           

          Most of these parameters correspond to the values of the properties of Orion.Report, so you can see the corresponding values on existing reports by querying that entity.

            • Re: SWIS or JSON/REST API to bulk IMPORT xml web reports?
              I LIKE EGGS

              HI @Tdanner but what is the definition?

              i have done the below and copied a 'definition' from an exciting report but its not quite working have i got the syntax correct? 

               

              Invoke-SwisVerb $swis Orion.Report CreateReport @("Active Alerts older than 7 days","All alerts 'Active' older then 7 days",$null,"Compliance",$null,$null,"definition????",$null,$null)

               

               

              but its throwing an error.

               

              can you tell me the correct syntaxs for this?

              also can this be done to import alerts?

               

              thanks in advanced

                • Re: SWIS or JSON/REST API to bulk IMPORT xml web reports?
                  tdanner

                  Here's a sample script that reads a report, modifies it, and then imports it back.

                   

                  Update 2017-01-19: there were a number of problems with the script as I posted it. I'm removing it to avoid future confusion. I will follow up in this thread with a better script.

                  • Re: SWIS or JSON/REST API to bulk IMPORT xml web reports?
                    tdanner

                    Alert configurations are a bit simpler to import and export. I added documentation for this to the bottom of https://github.com/solarwinds/OrionSDK/wiki/Alerts .

                      • Re: SWIS or JSON/REST API to bulk IMPORT xml web reports?
                        I LIKE EGGS

                        Hi tdanner thank you for your help. just run into a slight problem. tried so many ways to export the XML file and re import it i have tried to out file export to xml then import from xml but cant get it tow work if did create with the query.

                          
                          
                        # Fetch an existing report definition  
                        $reportInfo = Get-SwisData $swis "SELECT top 1 Name, Category, Title, Type, SubTitle, Description, Definition, LimitationCategory, Owner 
                        FROM Orion.Report where name like '%All Disk Volumes%'" 
                        #| Export-Clixml c:\testing.xml 
                        
                        
                        
                        
                        #$importxml = Import-Clixml C:\testing.xml
                        $reportXml = [xml]$reportInfo.Definition  
                        
                        
                        
                        
                        #$reportxml = [xml]$importxml.Definition
                        
                        
                        
                        
                        # Prepare arguments for calling Orion.Report.CreateReport  
                        $name = $reportXml.Report.Name
                        $description = $reportXml.Report.Description
                        $limitationCategory = "custom" 
                        $category = "custom"  
                        $title = $reportXml.Report.Title  
                        $subtitle = $reportXml.Report.SubTitle
                        $definition = $reportXml.OuterXml
                        $isFavorite = "true"  
                        $username = "admin"
                        
                          
                        # Import the modified report  
                        Invoke-SwisVerb $swis Orion.Report CreateReport @($name, $description, $limitationCategory, $category, $title, $subtitle, $definition, $isFavorite, $username) 
                        
                        

                         

                        but im getting this:

                         

                        not sure if some formatting is out of place tired so many ways but brains going to mush

                         

                        hope you can provide some aid

                          • Re: SWIS or JSON/REST API to bulk IMPORT xml web reports?
                            I LIKE EGGS

                            i guess this would be the ideal scenario

                             

                            
                            # Connect to SWIS  
                            $swis = Connect-Swis -Hostname $orionServer -UserName $orionUsername -Password $orionPassword  
                              
                              
                            # Fetch an existing report definition  
                            $reportInfo = Get-SwisData $swis "SELECT top 1 Name, Category, Title, Type, SubTitle, Description, Definition, LimitationCategory, Owner 
                            FROM Orion.Report where name like '%All Disk Volumes%'" | Export-Clixml c:\testing.xml 
                            
                            
                            
                            
                            $importxml = Import-Clixml C:\testing.xml
                            #$reportXml = [xml]$reportInfo.Definition  
                            
                            
                            
                            
                            #$reportxml = [xml]$importxml.Definition
                            
                            
                            
                            
                            # Prepare arguments for calling Orion.Report.CreateReport  
                            $name = $importxml.Name
                            $description = $importxml.Description
                            $limitationCategory = $importxml.LimitationCategory
                            $category = $importxml.Category
                            $title = $importxml.Title
                            $subtitle = $importxml.SubTitle
                            $definition = $importxml.Definition
                            $isFavorite = "true"  
                            $username = "admin"
                            
                              
                            # Import the modified report  
                            Invoke-SwisVerb $swis Orion.Report CreateReport @($name, $description, $limitationCategory, $category, $title, $subtitle, $definition, $isFavorite, $username) 
                            
                        • Re: SWIS or JSON/REST API to bulk IMPORT xml web reports?
                          tdanner

                          Second try! One important note: Orion has two reporting systems. There's a legacy reporting system based on the old "Report Writer" desktop app and a newer, much more flexible reporting system that has a web-based editor. On the Reports page (Orion/Reports/ViewReports.aspx) there is a "Type" column that tells you which type a given report it.  The Orion.Report.CreateReport verb only works with the web-based reports.

                           

                          Try this one:

                           

                          # Parameters
                          $orionServer = "orionserver"
                          $orionUsername = "admin"
                          $orionPassword = ""
                          $oldReportName = "Agent Plugin Version"
                          
                          # Connect to SWIS
                          $swis = Connect-Swis -Hostname $orionServer -UserName $orionUsername -Password $orionPassword
                          
                          # Fetch an existing report definition
                          $reportInfo = Get-SwisData $swis "SELECT TOP 1 Name, Definition FROM Orion.Report WHERE Name=@name" @{name=$oldReportName}
                          $reportXml = [xml]$reportInfo.Definition
                          
                          # Modify our local copy of the existing report
                          $reportXml.Report.Name = "Modified $oldReportName"
                          
                          # Prepare arguments for calling Orion.Report.CreateReport
                          $name = $reportXml.Report.Name
                          $description = $reportXml.Report.Description
                          $limitationCategory = $reportXml.Report.LimitationCategory
                          $category = $reportXml.Report.Category
                          $title = $reportXml.Report.Name
                          $subtitle = ""
                          $definition = $reportXml.OuterXml
                          $isFavorite = "true"
                          $username = $orionUsername
                          
                          # Import the modified report
                          Invoke-SwisVerb $swis Orion.Report CreateReport @($name, $description, $limitationCategory, $category, $title, $subtitle, $definition, $isFavorite, $username)