Showing posts with label SWQL. Show all posts
Showing posts with label SWQL. Show all posts

How to Bulk Enable Application Dependency Mapping on Agents in SolarWinds Orion Using PowerShell

SolarWinds Server & Application Monitor (SAM) has a feature called Application Dependency Mapping. This feature analyzes the connections on servers running the Orion agent to determine which processes and servers are talking to each other. It then takes those connections and creates application dependencies for them.

Identifying and enabling application dependency mappings programmatically in SolarWinds Orion can get a little funky. Below is a PowerShell script which finds any agents that do not have application dependency mappings enabled and enabled it on them. I also have this script posted on GitHub if you'd prefer to grab it from there. Sometime copying code from a web page can morph characters.

# Verify that the OrionSDK is installed and available.
# This is a required prerequisite for this script.
# It can be downloaded from https://github.com/solarwinds/OrionSDK
if (!(Get-Command Get-SwisData)) {
    if (!(Get-PSSnapin | Where-Object { $_.Name -eq "SwisSnapin" })) {
        Try {
            Add-PSSnapin "SwisSnapin"
        } Catch {
            if (Test-Path "C:\Program Files (x86)\SolarWinds\Orion SDK\SWQL Studio\SwisPowerShell.dll") {
                C:\Windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe "C:\Program Files (x86)\SolarWinds\Orion SDK\SWQL Studio\SwisPowerShell.dll" | Out-Null
                C:\Windows\Microsoft.NET\Framework64\v4.0.30319\InstallUtil.exe "C:\Program Files (x86)\SolarWinds\Orion SDK\SWQL Studio\SwisPowerShell.dll" | Out-Null
            } else {
                Write-Host "This script requires the OrionSDK to be installed." -ForegroundColor Red
                Write-Host "https://github.com/solarwinds/OrionSDK" -ForegroundColor Red
            }
        }
    }
}

# Checking to see if we already have stored credentials.
# If not, we'll prompt for credentials and securely
# store them with Export-CLIXML.
$ApiCredPath = $env:Userprofile + '\ApiCreds'
if (!(Test-Path -Path $ApiCredPath)) {
    $ApiCred = Get-Credential -Message "Please enter your credentials for SolarWinds Orion"
    if ($ApiCred) {
        Export-Clixml -Path $ApiCredPath -InputObject $ApiCred
    }
}
$SwCredential = Import-Clixml -Path $ApiCredPath -Verbose

# Checking to see if we have a cached an Orion server.
# If not, we'll prompt for hostname or IP address of the
# primary Orion server and cache it to the Orion environment variable.
if (!$Env:Orion) {
    $OrionServer = Read-Host "Enter the hostname or IP of your primary Orion server."
    if ($OrionServer) {
        New-Item -Path Env:\Orion -Value $OrionServer
    }
}
$Swis = Connect-Swis -Hostname $env:Orion -Credential $SwCredential

# Get agent nodes that don't yet have application dependencies enabled
$NodesQuery = @"
    SELECT NodeID, ObjectSubType, IPAddress, Caption, n.CustomProperties.Environment, n.Inventory.NodeID AS [InventoryNodeID]
    FROM Orion.Nodes n
    WHERE n.ObjectSubType='Agent' AND 
        n.Inventory.NodeID IS NULL AND 
"@

$Nodes = Get-SwisData -SwisConnection $Swis -Query $NodesQuery


# Loop through each of the nodes and enable application dependencies
foreach ($Node in $Nodes) {
    Invoke-SwisVerb -SwisConnection $Swis -EntityName Orion.ADM.NodeInventory -Verb Enable -Arguments @( ,@( $($Node.NodeID) ) )
}

Enable-ApplicationDependencyPolling.ps1

Custom SWQL Query to Identify the Top 10 SolarWinds Orion Nodes by Their Number of NPM Elements

Below is a SWQL query which can be used to determine which nodes in your SolarWinds Orion environment have the most elements. What is an element? In NPM, every node, volume and interface counts as an element. Which leads to, why is this important? For one, SolarWinds Network Performance Monitor (NPM) is typically licensed by the number of elements, unless you are one of the newer nodes based licensing options. If you have a large environment, this also comes in helpful when trying to balance the load across your polling engines. Typically, a polling engine is limited to ~12,000 elements before your polling frequencies start to automatically slow down (unless you're stacking polling engine licenses and have the computer resources to support it).

SELECT TOP 10 i.Interfaces + v.Volumes + 1 AS [Elements]
    , n.Caption AS [Node]
    , n.NodeID
    , n.IP_Address AS [IP]
    , n.Vendor
    , n.MachineType
FROM Orion.Nodes n
INNER JOIN (SELECT COUNT(InterfaceID) AS [Interfaces], NodeID FROM Orion.NPM.Interfaces GROUP BY NodeID) AS i ON i.NodeID=n.NodeID
INNER JOIN (SELECT COUNT(VolumeID) AS [Volumes], NodeID FROM Orion.Volumes GROUP BY NodeID) AS v ON v.NodeID=n.NodeID
GROUP BY n.NodeID
    , n.Caption
    , n.IP_Address
    , n.Vendor
    , n.MachineType
    , i.Interfaces
    , v.Volumes
ORDER BY [Elements] DESC

If you're unfamiliar with SWQL and how to run it, I'll list a few ways below.

  1. You can go to https://<OrionURL>/orion/Admin/swis.aspx in your environment, past the code in the box, and execute it. You'll have to replace "https://<OrionUrl>" with the URL for your environment, of course.
  2. If you have the OrionSDK installed, you can run it in SWQL Studio.
  3. If you have the OrionSDK installed, you can run the query with the "Get-SwisData" PowerShell cmdlet.
  4. You can use the query above as a data source for a report or custom dashboard widget.

Custom SWQL Query to Identify the Top 10 SolarWinds Orion Nodes by Their Number of Enabled SAM Components

Since SolarWinds Server & Application Monitor (SAM) went to node based licensing, it isn't super easy to determine which nodes have the most SAM components assigned to them. Below is a SWQL query which can be used to display the top 10 nodes with the most enabled SAM components in your environment.

SELECT TOP 10 Count(c.ComponentID) AS [Components]
    , c.Application.Node.NodeID
     , c.Application.Node.Caption AS [Node]
     , c.Application.Node.IP_Address AS [IP]
     , c.Application.Node.Vendor
     , c.Application.Node.MachineType
FROM Orion.APM.Component c
WHERE c.Disabled = 'False'
GROUP BY c.Application.Node.NodeID
    , c.Application.Node.Caption
    , c.Application.Node.IP_Address
    , c.Application.Node.Vendor
    , c.Application.Node.MachineType
ORDER BY [Components] DESC

If you're unfamiliar with SWQL and how to run it, I'll list a few ways below.
  1. You can go to https://<OrionURL>/orion/Admin/swis.aspx in your environment, past the code in the box, and execute it. You'll have to replace "https://<OrionUrl>" with the URL for your environment, of course.
  2. If you have the OrionSDK installed, you can run it in SWQL Studio.
  3. If you have the OrionSDK installed, you can run the query with the "Get-SwisData" PowerShell cmdlet.
  4. You can use the query above as a data source for a report or custom dashboard widget.

Prelude

I have been working with SolarWinds products for many years now. I've done everything from professional services across the SolarWinds portfolio of products to systems engineering and administration jobs. I've even earned five SolarWinds SCP certifications. Over the years, I've learned a lot of tips and tricks, as well as developed an extensive archive of PowerShell scripts, pollers, SWQL and SQL queries, etc. As I have time, I'll be cleaning up my code, posting the details here, and building out a related GitHub repository. Bookmark the site, subscribe to the RSS feed, etc... there's a lot of good things coming down the pipe!

Feel free to follow me on GitHubThwack and/or LinkedIn

Issue Where SolarWinds Orion Agents Show As Connected But They Are Not Updating Statistics (RESOLVED)

This issue can easily slip by unnoticed. All of that status indicators still show green, so everything is good, right? Not so! Statistics an...