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

filtering out interfaces before adding via AddInterfacesOnNode

Jump to solution

I seem to remember there being a post on how to handle the xml objects that you get back from running a DiscoverInterfacesOnNode verb against a node. I'm unable to locate this information and I'd like to add in some logic to filter out the interfaces we would not like to import into the system. Any help or direction would be fantastic!

Tags (1)
0 Kudos
1 Solution

It's in the PowerShell\NPM.DiscoverAndAddInterfacesOnNode.ps1 sample script installed with the SDK. It looks like this:

# Connect to SWIS

$hostname = "localhost"

$username = "admin"

$password = New-Object System.Security.SecureString

$cred = New-Object -typename System.Management.Automation.PSCredential -argumentlist $username, $password

$swis = Connect-Swis -host $hostname -cred $cred

# The node ID to discovery interfaces on

$nodeId = 1

# Discover interfaces on the node

$discovered = Invoke-SwisVerb $swis Orion.NPM.Interfaces DiscoverInterfacesOnNode $nodeId

if ($discovered.Result -ne "Succeed") {

  Write-Host "Interface discovery failed."

}

else {

  # Filter the resulting list to include only ifType 6 (fast ethernet)

  $discovered.DiscoveredInterfaces.DiscoveredLiteInterface |? {$_.ifType -ne 6} |% { $discovered.DiscoveredInterfaces.RemoveChild($_) | Out-Null }

  # Add the remaining interfaces

  Invoke-SwisVerb $swis Orion.NPM.Interfaces AddInterfacesOnNode @($nodeId, $discovered.DiscoveredInterfaces, "AddDefaultPollers") | Out-Null

}

View solution in original post

9 Replies
Level 11

Hi dkeyser,

I use C# and maybe this topic helps you. Add Interfaces On Node

0 Kudos

I saw this every time I searched for the example I'm remembering but I'm not able to understand what you're doing since I don't program in C#. Thank you for the help though, I do appreciate it!

0 Kudos

What language/runtime are you working in?

0 Kudos

I'm currently working in PowerShell 4.0. I'm getting the XML returned with all the interfaces detectable and I'm looking to remove the ones that don't meet our criteria.

I know I saw somewhere an example of someone doing just that but I can't find the bookmark for it. That'll teach me to not just copy the example code for later!

0 Kudos

It's in the PowerShell\NPM.DiscoverAndAddInterfacesOnNode.ps1 sample script installed with the SDK. It looks like this:

# Connect to SWIS

$hostname = "localhost"

$username = "admin"

$password = New-Object System.Security.SecureString

$cred = New-Object -typename System.Management.Automation.PSCredential -argumentlist $username, $password

$swis = Connect-Swis -host $hostname -cred $cred

# The node ID to discovery interfaces on

$nodeId = 1

# Discover interfaces on the node

$discovered = Invoke-SwisVerb $swis Orion.NPM.Interfaces DiscoverInterfacesOnNode $nodeId

if ($discovered.Result -ne "Succeed") {

  Write-Host "Interface discovery failed."

}

else {

  # Filter the resulting list to include only ifType 6 (fast ethernet)

  $discovered.DiscoveredInterfaces.DiscoveredLiteInterface |? {$_.ifType -ne 6} |% { $discovered.DiscoveredInterfaces.RemoveChild($_) | Out-Null }

  # Add the remaining interfaces

  Invoke-SwisVerb $swis Orion.NPM.Interfaces AddInterfacesOnNode @($nodeId, $discovered.DiscoveredInterfaces, "AddDefaultPollers") | Out-Null

}

View solution in original post

I've hit another interesting snag in this project. When constructing my array to pass to the AddInterfacesOnNodes my discovered interfaces variable gets wiped out. Prior to adding this to the array it's fine. In the example you're creating and passing the array in one step, I'm just taking two so I don't see much of a different in this.

I constructed my array like so: $MyInterfaceArray = @($TargetNodeID, $XMLInterfaceList.DiscoveredInterfaces, 'AddDefaultPollers')

Before adding to the array I get this from $XMLInterfaceList:

Id               : 1
xmlns            : http://schemas.datacontract.org/2004/07/SolarWinds.InformationService.Contract
d1p1             : http://schemas.solarwinds.com/2008/NPM
i                : http://www.w3.org/2001/XMLSchema-instance
z                : http://schemas.microsoft.com/2003/10/Serialization/

DiscoveredInterfaces : DiscoveredInterfaces

Result          

: Succeed

After I add my variable to the array this is what the array holds:

[DBG]: PS C:\Users\Administrator\desktop>> $MyInterfaceArray

5

AddDefaultPollers

Any ideas why I can't put my results into an array any longer only after having filtered out the unwanted interfaces?

0 Kudos

Without seeing more of your code it is hard to know what is going on. Could you post a larger chunk?

0 Kudos

Something must have been stuck in memory. I shut down for the day and when I came back and tried it everything worked. Thank you for all your help. I've posted my function below. I'm passing 3 bits of information via the $NewNodeID variable so that's the reason I'm using the GetValue(2).

#Function to add Interfaces

##############################################################

function AddInterface ($NewNodeID)

{

Write-Host "Entering AddInterface function"

$TargetNodeID = $NewNodeID.GetValue(2)

$XMLInterfaceList = Invoke-SwisVerb $swis "Orion.NPM.Interfaces" "DiscoverInterfacesOnNode" $TargetNodeID

$MyInterfaceArray = @($TargetNodeID, $XMLInterfaceList.DiscoveredInterfaces, 'AddDefaultPollers')

Invoke-SwisVerb $swis "Orion.NPM.Interfaces" "AddInterfacesOnNode" $MyInterfaceArray | Out-Null

Write-Host "Exiting AddInterface function"

}

0 Kudos

For some reason that example is no longer in the specifed directory. I have a feeling a certain feline friend helped me lose that one...

Thank you for pointing me in the right direction! That seems pretty straight forward to follow.

0 Kudos