2 Replies Latest reply on Aug 5, 2014 2:32 PM by dkeyser

    Adding of interfaces to a node. XML?

    dkeyser

      Hello everyone!

       

      I'm moving along in my scripting adventure with the SDK and PowerShell but I've hit a snag when it comes to handling the addition of interfaces. I'm looking at the example given after installing the SDK and it looks just like adding a node, awesome! But when I try to add an interface to a node I'm getting an error back stating that '

      A positional parameter cannot be found that accepts argument '.'.'

       

      I'm looking at the verbs and I'm seeing XML but the sample script does not show any need for XML. Has this changed?

       

      My code below:

      #Function to add Interfaces

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

      function AddInterface ($NewNodeID, $InterfaceInfo, $Pollers)

      {

      Write-Host "Entering AddInterface Function"

      $AllInterfacePollers = Get-SwisData $swis "Select Distinct PollerType from Orion.Pollers Where NetObjectType = 'I'"

       

       

       

       

          foreach ($Interface in $InterfaceInfo)

          {

          $InterfaceIndex = $Interface.Interfaceindex

          Write-Host "Interface index: $InterfaceIndex"

          $Caption = $Interface.InterfaceName

          Write-Host "Interface name: $Caption"

         

          $newIfaceProps = @{

              NodeID=$NewNodeID; # NodeID on which the interface is working on

              InterfaceName=$Caption; # description name of the interface to add

              InterfaceIndex=$InterfaceIndex;

              ObjectSubType="SNMP";

              Status=0;

              RediscoveryInterval=5;

              PollInterval=120;

              StatCollection=10;

                  }

         

          $newIfaceUri = New-SwisObject $swis -EntityType "Orion.NPM.Interfaces" -Properties $newIfaceProps.

          $ifaceProps = Get-SwisObject $swis -Uri $newIfaceUri

         

          $newIfaceUri

       

       

          ForEach ($PollerAdd in $Pollers){

          IF($AllInterfacePollers -contains $PollerAdd)

          {

          Write-Host "Found Poller $PollerAdd"

            $poller = @{

              PollerType="$PollerAdd";

              NetObject="I:"+$ifaceProps["InterfaceID"];

              NetObjectType="I";

              NetObjectID=$ifaceProps["InterfaceID"];

              }

          $pollerUri = New-SwisObject $swis -EntityType "Orion.Pollers" -Properties $poller

          $pollerUri

          }

          }

       

          }

      Write-Host "Exiting AddInterface function"

       

       

      }

        • Re: Adding of interfaces to a node. XML?
          dkeyser

          Also was playing with the XML way of things and I'm getting a funky error.

          "

          Invoke-SwisVerb : Type 'System.Management.Automation.PSObject' with data contract

          name 'PSObject:http://schemas.datacontract.org/2004/07/System.Management.Automat

          ion' is not expected. Add any types not known statically to the list of known typ

          es - for example, by using the KnownTypeAttribute attribute or by adding them to

          the list of known types passed to DataContractSerializer.

          At line:7 char:26

          + $output = Invoke-SwisVerb <<<<  $swis "Orion.NPM.Interfaces" "AddInterfacesOnNo

          de" $MyInterfaceArray

              + CategoryInfo          : NotSpecified: (:) [Invoke-SwisVerb], Serialization

             Exception

              + FullyQualifiedErrorId : System.Runtime.Serialization.SerializationExceptio

             n,SwisPowerShell.InvokeSwisVerb

          "

          Code I was playing with that produces this error:

          $TargetNodeID = $NewNodeID.GetValue(1)

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

          $InnerArray = $XMLInterfaceList.InnerXml

          $InnerArray = $XMLInterfaceList.DocumentElement

           

           

          $MyInterfaceArray = @($NewNodeID, $InnerArray, 'AddDevaultPollers')

           

           

          $output = Invoke-SwisVerb $swis "Orion.NPM.Interfaces" "AddInterfacesOnNode" $MyInterfaceArray

          • Re: Adding of interfaces to a node. XML?
            dkeyser

            Ok found the other example and now I've got a functioning add nodes function. Code below for those interested. Note - I'm pulling back an array for NewNodeID so I have to state which element I'm interested in. Your code may be different so YMMV.

             

            function AddInterface ($NewNodeID)

            {

            Write-Host "Entering AddInterface function"

             

            $TargetNodeID = $NewNodeID.GetValue(1)

            $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"

            }