Quantcast
Channel: THWACK: Discussion List - All Communities
Viewing all articles
Browse latest Browse all 16365

How to Request : Bulk Addition of nodes

$
0
0

I have three groups of 50 servers that I would like to add to the SAM module. Each server within a group is identical to the next. Is there a 'copy node' function someplace that I could use to copy over the snmp,custom properties, application monitors and resources?

 

I attempted to write a powershell function to complete this, however both the volumes and the interfaces are not being assigned on the 'copied' node.

 

Here is my code :

 

Function Get-OrionConnection

{

 

 

  # Connect to SWIS

  $hostname = $server

  $cred = New-Object -typename System.Management.Automation.PSCredential

  $swis = Connect-Swis -host $hostname

  Return $swis

}

 

 

Function Copy-OrionNode

{

  <#

  .NOTES

  Name: Copy-OrionNode

  Version History:

  1.0 - 12/8/2015 - Initial Release.

  .SYNOPSIS

  Copies an existing node in Orion

  .DESCRIPTION

  SolarWinds Orion is a Plexus monitoring application, this script eases the creation of

  node (things to be monitored) objects within the system. This is really aimed for 'bulk'

  additions.

  .PARAMETER SourceNode

  Designates the name of the server to be copied.

  .PARAMETER TargetNode

  Designates the name of the server to be created.

  Returns nothing

  #>

  [CmdletBinding()]

  Param

  (

  [Parameter(Mandatory=$True,Position=0)]

  [String]$SourceComputerName,

  [Parameter(Mandatory=$True,Position=0)]

  [String]$TargetComputerName

  )

  Begin

  {

  if( !($swConnection) )

  {

  $swConnection = Get-PLXSOrionConnection

  }

  #Attempt to resolve the dns name, if not availabe, throw error.

  try{$IPAddress = [System.Net.Dns]::GetHostAddresses($TargetComputerName)}

  catch

  {

  Write-error "Unable to resolve DNS Name"

  break

  }#catch

  }

  Process

  {

  #Find the node and if it exists.

  $sourceData = Get-SwisData $swConnection "SELECT Uri FROM Orion.Nodes where sysname like $SourceComputerName'"

  #Get the exact properties of the node so we can paste them.

  $sourceNode = Get-SwisObject $swConnection $sourceData

 

 

  # Make an in-memory copy of the node

  Write-host ("Copying " + $sourceNode.Caption + "(" + $sourceNode.IPAddress + ") to " + $TargetComputerName + "(" + $IPAddress + ")" )

            Write-Verbose ("Getting Node properties ")

  $targetNodeProps = @{

     IPAddress=[string]$IPAddress;

     EngineID=$sourceNode.EngineID;

     ObjectSubType=$sourceNode.ObjectSubType;

     SNMPVersion=$sourceNode.SNMPVersion;

     EntityType =$sourceNode.EntityType

     Caption = $TargetComputerName

     DynamicIP =$sourceNode.DynamicIP

     PollInterval =$sourceNode.PollInterval

     RediscoveryInterval =$sourceNode.RediscoveryInterval

     StatCollection =$sourceNode.StatCollection

     Community =$sourceNode.Community

     }

       

        # Create the node on the target system

        Write-Verbose ("Creating Node : " + $TargetComputerName)

  $targetUri = New-SwisObject $swConnection -EntityType "Orion.Nodes" -Properties $targetNodeProps

  $targetNode = Get-SwisObject $swConnection $targetUri

        Write-Verbose "Node Created "

 

 

        <##############################################################>

        Write-Verbose ("Setting Custom Properties : " + $TargetComputerName)

        #Find the node and if it exists.

  $sourceData = $sourceData + '/CustomProperties'

  #Get the exact properties of the node so we can paste them.

  $sourceNodeCustom = Get-SwisObject $swConnection $sourceData

        $targetNodeCustomAttributes = @{

  BusinessService=$sourceNodeCustom.BusinessService

  CustomAttribute1=$sourceNodeCustom.CustomAttribute1

  CustomAttribute2=$sourceNodeCustom.CustomAttribute2

  Environment=$sourceNodeCustom.Environment

  }

        $targetCustomURI = $targetURI + '/CustomProperties'

        $targetNodeCustomURI = Set-SwisObject -SwisConnection $swConnection -Uri $targetCustomURI -Properties $targetNodeCustomAttributes

        Write-Verbose "Custom Properties set successfully "

        <##############################################################>

        Write-Verbose "Getting Poller Properties"

        $pollerTypes = Get-SwisData $swConnection "SELECT PollerType FROM Orion.Pollers WHERE NetObject=@netobject" @{netobject='N:'+$sourceNode.NodeID}

        foreach ($pollerType in $pollerTypes) {

        $poller = @{

           PollerType = "$pollerType";

           NetObject = "N:"+$targetNode.NodeID;

            }#@

        Write-Verbose "Adding poller $pollerType"

        New-SwisObject $swConnection -EntityType "Orion.Pollers" -Properties $poller | Out-Null

        }#foreach

       

        <##############################################################>

        Write-Verbose ("Getting Interface properties")

        #Find the node and if it exists.

  $sourceInterfaceData = Get-SwisData $swConnection "SELECT URI FROM Orion.NPM.Interfaces where NodeID=@node"@{node=$sourceNode.NodeID}

  #Get the exact properties of the node so we can paste them.

  $sourceInterfaces = Get-SwisObject $swConnection $sourceInterfaceData

        $targetifaceProps = @{

     #NodeID=$newNodeURI.NodeID; # NodeID on which the interface is working on

     InterfaceName=$sourceInterfaces.InterfaceName; 

     InterfaceIndex=$sourceInterfaces.InterfaceIndex;

     ObjectSubType=$sourceInterfaces.ObjectSubType;

     Status=$sourceInterfaces.Status;

     }

       

        Write-Host @targetifaceProps

 

 

        New-SwisObject $swConnection -EntityType "Orion.NPM.Interfaces" -Properties $targetifaceProps | Out-Null

        <##############################################################>

 

 

        Write-Verbose "Getting volume properties"

        $sourceVolumesData = Get-SwisData $swConnection "SELECT Nodes.Volumes.Uri FROM Orion.Nodes WHERE NodeID=@node" @{node=$sourceNode.NodeID}

        foreach ($sourceVolumeData in $sourceVolumesData)

        {

            $sourceVolProps += Get-SwisObject $swConnection $sourceVolumeData

            Write-Host "  Copying" $sourceNode.Caption "/" $sourceVolProps.Caption

        }

        $targetVolProps = @{}

        $volumePropsToCopy |% { $targetVolProps[$_] = $sourceVolProps[$_] }

        $targetVolProps["NodeID"] = $targetNode.NodeID

 

 

        # Create the copy

        $targetVolUri = New-SwisObject $swConnection -EntityType "Orion.Volumes" -Properties $targetVolProps

        $targetVol = Get-SwisObject $swConnection $targetVolUri

       

        <##############################################################

       

        # Copy the pollers for the new Volume

        $volPollerTypes = Get-SwisData $swConnection "SELECT PollerType FROM Orion.Pollers WHERE NetObject=@netobject" @{netobject='V:'+$sourceVolProps.VolumeID}

        foreach ($volPollerType in $volPollerTypes) {

            $volPoller = @{

                PollerType = "$volPollerType";

                NetObject = "V:"+$newVol.VolumeID;

            }

            Write-Host "      Adding poller $volPollerType"

            New-SwisObject $swConnection -EntityType "Orion.Pollers" -Properties $volPoller | Out-Null

        }#>

  }#Process

  End{}

}

 

 

if( !($swConnection) )

{

$swConnection = Get-OrionConnection

}


Viewing all articles
Browse latest Browse all 16365

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>