Spider my Orion Pages with PowerShell & SWQL

A few days ago, I spoke before a small group of people about what I’d been doing with the Orion SDK.  I mentioned that I had created a Spider-Orion script that I use to navigate to every page in my install.  When I mentioned this script several people asked where it was published.  The short answer – here.

Now most of my Orion SDK scripts are “one-shots.”  These are quick blips that are used once (saved) and then forgotten.  This is one such script.  I wrote it, but never formalized it (good commenting, converting it to a function, writing better error trapping, etc.), which I try to do with most scripts that I publish.  I was encouraged by this class that I spoke to that making it formalized was far less important than making it available.

I felt rather sheepish, but decided that they are right.  So here’s my script.  It’s commented out fairly well, but if you have any questions, please feel free to ask.  I don’t mind responding to comments.

# Spider-Orion.ps1
###########################################################################################################
# Purpose: Spider SolarWinds Orion Site


if ( -not ( Get-Command -Name Connect-Swis -ErrorAction SilentlyContinue ) )
{
    # Requires that Orion SDK be installed
    Add-PSSnapin -Name SwisSnapin -ErrorAction Stop
}

$Hostname = "localhost" # Hostname (or IP) of the SolarWinds Server
$Username = "guest"
$Password = "orion"
$SecPass  = ConvertTo-SecureString -String $Password -AsPlainText -Force
$Creds    = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $Username, $SecPass

# Connect to the SolarWinds Information Service (SWIS)
$Swis     = Connect-Swis -Hostname $Hostname -Credential $Creds

# Query the server for all Managed Entities (nodes, interfaces, volumes, applications, etc.) and their "parent" (Ancestor) objects.
$SWQL     = "SELECT DetailsURL, AncestorDetailsUrls FROM System.ManagedEntity"


Write-Host "Getting Managed Entities"
$ManagedEntities  = Get-SwisData -SwisConnection $Swis -Query $SWQL
Write-Host "Found $( $ManagedEntities.Count ) entities"


$Swis.Close()
Remove-Variable -Name Swis -ErrorAction SilentlyContinue


# Get all entity lists
Write-Host "Collapsing DetailsUrl"
$LinkList  = $ManagedEntities.DetailsUrl

# add any ancestors
Write-Host "Collapsing AncestorDetailsUrls"
$LinkList += $ManagedEntities.AncestorDetailsUrls

# make the list unique (no duplicates)
Write-Host "Removing Duplicates"
$UniqueURLs = $LinkList | Select-Object -Unique

Write-Host "$( $UniqueURLs.Count ) Unique URLs"

# create empty report
$Report = @()

# counters
$i = 0; $iCount = $UniqueUrls.Count
ForEach ( $Url in $UniqueURLs )
{
    Write-Progress -Activity "Crawling $hostname" -CurrentOperation "Getting $Url" -Status "Link $( $i + 1) of $iCount" -PercentComplete ( ( $i / $iCount ) * 100 )
    # if the URL already contains a ?, 
    if ( $Url -like "*?*" )
    {
        # then we just need to append the parameters
        $FullUrl = "http://$( $hostname )$( $Url )&AccountID=$( $Username )&Password=$( $Password )"
    }
    else
    {
        # otherwise we need to put in the parameterization
        $FullUrl = "http://$( $hostname )$( $Url )?AccountID=$( $Username )&Password=$( $Password )"
    }
    # Make a call to the web page
    Write-Host "Making Web Call to $FullUrl"
    $Results = Invoke-WebRequest -Uri $FullUrl
    
    # Create a reporting item and capture some relevant information
    $ReportItem = New-Object -TypeName PSObject -Property @{ Server = $Hostname; Url = $Url; FullUrl = $FullUrl; PageTitle = $Results.ParsedHtml.title; Status = $Results.StatusDescription; }
    # add it to the report
    $Report += $ReportItem

    # increment the counter
    $i++
}
Write-Progress -Activity "Crawling $hostname" -Completed
# return the report
$Report

 

1 thought on “Spider my Orion Pages with PowerShell & SWQL”

  1. Nice, I can see using this to potentially capture hubble stats in order to identify slow views or page errors/optimization data.

    Reply

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.