cancel
Showing results for 
Search instead for 
Did you mean: 
Create Post

Enable Hardware Health via PowerShell

Working with nickzourdos​ today on an issue he found where he needed to enable hardware health polling on ~80 devices that were pre-existing in NPM.

It should be noted that all devices are the same make/model. This is important.

Step 1: Research

Hardware Health · solarwinds/OrionSDK Wiki · GitHub

It seems we need the NetObjectID and the PollingMethod for this

Step 2: A little more research

Query SWIS via the SWQL Studio to get a sample of the PollingMethod used on an existing device

You can grab the SWQL Studio Here: Releases · solarwinds/OrionSDK · GitHub

Query:

SELECT PollingMethod, ParentObjectType, ParentObjectID FROM Orion.HardwareHealth.HardwareInfoBase WHERE ParentObjectType = 'N' AND ParentObjectID =<NodeID of Sample Node>

Step 3: Execute the below script in PowerShell, supplying the Hostname, Login to SolarWinds, PollingMethod, and Search Criteria for your nodes (Nick is a solid admin and has a very nice standard naming convention!)

#region Top of Script

#requires -version 2
<#
.SYNOPSIS
    Enables Hardware Health Pollers for Nick's Nodes

.DESCRIPTION
    https://github.com/solarwinds/OrionSDK/wiki/Hardware-Health

.NOTES
    Version:        1.0
    Author:         Zack Mutchler
    Creation Date:  July 12, 2018
    Purpose/Change: Initial Script development. 
#>

#endregion

#####-----------------------------------------------------------------------------------------#####

#region Functions

# Create a function to connect to the SolarWinds Information Service (SWIS)
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
    )

    # Import the SolarWinds PowerShell Module
    Import-Module SwisPowerShell

    # Connect to SWIS
    IF ( $ConnectionType -eq 'Trusted'  ) {

        $swis = Connect-Swis -Trusted -Hostname $SolarWindsServer
   
    }

    ELSE {
   
        $creds = Get-Credential -Message "Please provide a Domain or Local Login for SolarWinds"

        $swis = Connect-Swis -Credential $creds -Hostname $SolarWindsServer

    }

RETURN $swis

}

#endregion Functions

#####-----------------------------------------------------------------------------------------#####

#region Variables

# Connect to SWIS
$hostname = Read-Host -Prompt "Hostname or IP Address of your SolarWinds server"
$swis = Set-SwisConnection -SolarWindsServer $hostname -ConnectionType Explicit

# Build the wildcard search for the Node Names
$captions = Read-Host -Prompt "Partial Name for the Hosts you want to target (Wildcard will be added in the script, do not use it here)"
$queryParam = "%" + $captions + "%"

# Supply the Polling Method to be applied to all target nodes
$pollingMethod = Read-Host "What is the polling method (integer) to be used?"

# Query all of the target nodes to build list of NodeIDs and Captions
$nodeQuery = "SELECT NodeID, Caption FROM Orion.Nodes WHERE Caption LIKE @caption"
$nodes = Get-SwisData -SwisConnection $swis -Query $nodeQuery -Parameters @{ caption = $queryParam }

#endregion Variables

#####-----------------------------------------------------------------------------------------#####

#region Execution

# Iterate through the Nodes and enable hardware health
Foreach( $n in $nodes ) {

    # Setup the ID and Name variables
    $netObjectID = "N:" + $n.NodeID
    $nodeName = $n.Caption

    # Set the hardware pollers for the nodes
    Try{
   
        $results = Invoke-SwisVerb -SwisConnection $swis -EntityName Orion.HardwareHealth.HardwareInfoBase -Verb EnableHardwareHealth -Arguments @( $netObjectID, $pollingMethod )

        Write-Host "Hardware Health Enabled for: $( $nodeName )" -ForegroundColor Green

    }

    Catch{

        $ErrorMessage = $_.Exception.Message
        Write-Host "The error message was $( $ErrorMessage )" -ForegroundColor Yellow

    }

}

#endregion Execution

Note: If you get an error that you're missing the Module, run this in PowerShell:

Install-Module -Name SwisPowerShell

ref: PowerShell Gallery | SwisPowerShell 2.3.0.108

Comments

This applies to any type of device type?

Sort of. You can run this for any device type that is supported by Hardware Health polling. However the script is designed to be run against a single PollingMethod at a time. (Gathered from Step 2)

So, if you have 4 Cisco devices that all use polling method 9, and 2 f5s that all use polling method 12; you would run the script 2 times (one for each polling method and target nodes).

There's good information in the GitHub wiki posted in Step 1. But, there's not a solid map that I know of that can mark every single model to each polling method, so full automation wasn't the goal here.

That being said, it would be simple enough to setup some static mapping in the script by including the MachineType in the $nodeQuery variable and then using that data to evaluate against...

Something like this in theory:

If( $machineType -like '*Cisco*' ) { apply Cisco polling method }

If ( $machineType -like '*f5*' ) { apply f5 polling method }

etc...

Without having the full map of everything, this method would be limited based on the machine types you currently have and mapping existing nodes to polling methods.

Based on the relative rarity of needing this script, we decided it would be easier just to run it as needed, versus setting it up to run on a schedule filled with every possibility of polling method:machine type combinations.

Just checking out there if anyone has built one like this but with the 'DisableHardwareHealth' verb and focus not only on Node or machine type but node and sensor name?

Thanks Zack,

If anyone else is interested here is a SQL query that will disable based off the sensor name:

update [dbo].[HWH_HardwareItem] set IsDisabled = 0 where UniqueName = 'sensorname' and HardwareInfoID in (select ID from HWH_HardwareInfo where netobjecttype = 'N' and netobjectID in (select nodeid

from nodesdata where caption like '%nodename%'))

Version history
Revision #:
1 of 1
Last update:
‎07-12-2018 11:28 AM
Updated by: