3 Replies Latest reply on Nov 23, 2014 9:27 PM by tdanner

    Using Swis v3 getting error using AddInterfaceToNode

    gbass

      Using a groovy application we can successfully use the verb AddInterfaceToNode if we discover the interface on the node first but if we come back later to add we can an error: Here is how we are building the call:

       

      import javax.xml.parsers.DocumentBuilderFactory

      import org.apache.axis.AxisProperties;

      import org.apache.axis.client.Stub;

      import org.apache.axis.message.MessageElement;

      import org.apache.axis.message.RPCParam;

      import org.datacontract.schemas._2004._07.System_Xml.ArrayOfXmlElementXmlElement;

      import com.solarwinds.swis.InformationServiceLocator;

      import com.solarwinds.swis.MapNamespaceContext

      import com.solarwinds.swis.PropertyBag

      import org.w3c.dom.Element;

      import org.w3c.dom.Node;

      import org.w3c.dom.NodeList;

      import com.solarwinds.schemas._2007._08.informationservice.InformationService;

      import com.solarwinds.schemas._2007._08.informationservice.InformationServiceFaultContract;

      import com.solarwinds.schemas._2007._08.informationservice.InvokeResponseInvokeResult;

      import com.solarwinds.swis.SwisUtil;

      import groovy.xml.XmlUtil

      import groovy.util.slurpersupport.GPathResult

       

      def swis

      def host = 'x.x.x.x'

      def username = 'xxxx'

      def password = 'xxxxx'

      def NodeID = 455

       

       

       

      def buildParameter (MessageElement value)

      {

          def parameters = new ArrayOfXmlElementXmlElement();

        def messageElements = new MessageElement[1];

        messageElements[0] = value;

        parameters.set_any(messageElements);

        return parameters;

      }

       

      def parameterWrapper = new ArrayOfXmlElementXmlElement[9]

      parameterWrapper[0] = buildParameter("NodeID",455

      parameterWrapper[1] = buildParameter("InterfaceName","Ethernet0/0/0")

      parameterWrapper[2] = buildParameter("IfName","E0/0/0")

      parameterWrapper[3] = buildParameter("InterfaceIndex",4498)

      parameterWrapper[4] = buildParameter("ObjectSubType","SNMP")

      parameterWrapper[5] = buildParameter("Status",0)

      parameterWrapper[6] = buildParameter("RediscoveryInterval",5)

      parameterWrapper[7] = buildParameter("PollInterval",120)

      parameterWrapper[8] = buildParameter("StatCollection",10)

       

       

      def globalWrapper = new ArrayOfXmlElementXmlElement[3];

      globalWrapper[0] = buildParameter(new RPCParam("NodeID",NodeID)

      globalWrapper[1] = parameterWrapper

      globalWrapper[2] = buildParameter(new RPCParam("PollerType", "AddDefaultPollers"))

       

       

       

       

      def login = false;

      def result = ""

       

       

      //test loop

      parameterWrapper.each{ k,v ->

          result += "Key: $k :: Value: $v\n"

      }

       

       

       

       

      def xs = new XmlSlurper(false, true)

      AxisProperties.setProperty("axis.socketSecureFactory","org.apache.axis.components.net.SunFakeTrustSocketFactory")

       

       

      if (host && username && password && NodeID)

      {

          try

        {

        // Log into SWIS.

        swis = SwisUtil.getSwisClient(host, username, password, true)

        login = true

        

        invokeResult = swis.invoke("Orion.NPM.Interfaces", "AddInterfacesOnNode", globalWrapper )

        resultXml = invokeResult.get_any()[0].toString()

        def newInterfaces = xs.parseText(resultXml.toString())

       

        // abort if we failed to add interfaces to the node.

        if (newInterfaces.Result.text() == "Succeed")

        {

        result += "\nAdded ${PayLoad} interfaces to node."

        addedInterfaces = true

        }

        else

        {

        result += "\nFAIL - could not add interfaces to node."

        throw new Exception("Failed to add interfaces to node.")

        }

       

        }

        catch (InformationServiceFaultContract fault)

        {

        result += "\nFAIL - ${fault.getMessage1()}";

        fault.getStackTrace().each

        { trace ->

        result += "\n\t${trace}";

        }

        }

        catch (Exception e)

        {

        result += "\nFAIL - ${e.getMessage()}";

        e.getStackTrace().each

        { trace ->

        result += "\n\t${trace}";

        }

        }

      }

      else

      {

        result += "\nFAIL - parameters not received."

      }

       

       

      return result

       

      And get the following error:

       

      org.codehaus.groovy.runtime.InvokerInvocationException: groovy.lang.MissingMethodException: No signature of method: Groovy_Solarwinds_SWIS_Add_EMSREPORTS_INTERFACE.buildParameter() is applicable for argument types: (java.lang.String, java.lang.Integer) values: [NodeID, 455]

      Possible solutions: buildParameter(org.apache.axis.message.MessageElement)

      at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:97)

      at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)

      at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1056)

      at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:884)

      at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:704)

      at groovy.lang.GroovyObjectSupport.invokeMethod(GroovyObjectSupport.java:44)

      at groovy.lang.Script.invokeMethod(Script.java:78)

      at com.resolve.util.GroovyScript.execute(GroovyScript.java:78)

      at com.resolve.util.ThreadGroovy.run(ThreadGroovy.java:95)

      at java.lang.Thread.run(Thread.java:662)

      Caused by: groovy.lang.MissingMethodException: No signature of method: Groovy_Solarwinds_SWIS_Add_EMSREPORTS_INTERFACE.buildParameter() is applicable for argument types: (java.lang.String, java.lang.Integer) values: [NodeID, 455]

      Possible solutions: buildParameter(org.apache.axis.message.MessageElement)

      at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:54)

      at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:78)

      at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:44)

      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:141)

      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:153)

      at Groovy_Solarwinds_SWIS_Add_EMSREPORTS_INTERFACE.run(Groovy_Solarwinds_SWIS_Add_EMSREPORTS_INTERFACE.groovy:73)

      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

      at java.lang.reflect.Method.invoke(Method.java:597)

      at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)

      ... 9 more

       

      So does anyone know what the XML and Properties are that the verb AddInterfaceToNode should look like or have an example using java on how to add an interface without using the DiscoverInterface verb first?

       

      Thanks!

        • Re: Using Swis v3 getting error using AddInterfaceToNode
          tdanner

          AddInterfacesOnNode is really intended to be called using the (possibly filtered) output of DiscoverInterfacesOnNode. But if you get the XML right, it should work fine when you build the "DiscoveredInterfaces" XML from scratch. If you have a working script using AddInterfacesOnNode, I recommend you dump the XML from that and compare it to what your groovy script generates.

           

          Just looking at the error and the rest of the code, it appears that the problem is with this line:

           

          parameterWrapper[0] = buildParameter("NodeID",455

           

          Maybe that should be this?

           

          parameterWrapper[0] = buildParameter(new RPCParam("NodeID",455))

           

          I don't really know what an "RPCParam" is in this case, but in other places in this code you are passing a string and an int to it. buildParameter is a local function that only accepts MessageElements.

            • Re: Using Swis v3 getting error using AddInterfaceToNode
              scottfraley

              Speaking of AddInterfaceToNode... (or, AddInterfacesOnNode in this case;)

               

              Does the body / payload for AddInterfacesOnNode look like this [when doing a REST call]?

              { 256, [
              {
                      "ifIndex": 83886080,
                      "Caption": "mgmt0 · MGMT:descriptionText",
                      "ifType": 6,
                      "ifSubType": 0,
                      "InterfaceID": 0,
                      "Manageable": true,
                      "ifSpeed": 0
                  },{
                      "ifIndex": 335544419,
                      "Caption": "loopback99 · Failover mechanism",
                      "ifType": 24,
                      "ifSubType": 0,
                      "InterfaceID": 0,
                      "Manageable": true,
                      "ifSpeed": 0
                  },{
                      "ifIndex": 369098752,
                      "Caption": "port-channel1 · descriptionText",
                      "ifType": 53,
                      "ifSubType": 0,
                      "InterfaceID": 0,
                      "Manageable": true,
                      "ifSpeed": 0
                  }
              ],
              "AddDefaultPollers" // is there somewhere I can see what other string values might go here?
              }

              Where 256 == NodeID

               

              Also, that [array] is output of DiscoverInterfacesOnNode.

               

               

              Thanks,

              Scott

                • Re: Using Swis v3 getting error using AddInterfaceToNode
                  tdanner

                  Close. The body for AddInterfacesOnNode should look like this:

                   

                  [ 256, [

                  {

                          "ifIndex": 83886080,

                          "Caption": "mgmt0 · MGMT:descriptionText",

                          "ifType": 6,

                          "ifSubType": 0,

                          "InterfaceID": 0,

                          "Manageable": true,

                          "ifSpeed": 0

                      },{

                          "ifIndex": 335544419,

                          "Caption": "loopback99 · Failover mechanism",

                          "ifType": 24,

                          "ifSubType": 0,

                          "InterfaceID": 0,

                          "Manageable": true,

                          "ifSpeed": 0

                      },{

                          "ifIndex": 369098752,

                          "Caption": "port-channel1 · descriptionText",

                          "ifType": 53,

                          "ifSubType": 0,

                          "InterfaceID": 0,

                          "Manageable": true,

                          "ifSpeed": 0

                      }

                  ],

                  "AddDefaultPollers"

                  ]

                   

                  All I did was change the outer delimiter from { } to [ ] since you always send a json array to any Invoke call.

                   

                  There are two options for the third parameter: "AddDefaultPollers" and "AddNoPollers". If you send "AddNoPollers" then no statistics will be collected - you would have to know which pollers to add and add them using a bunch of Create calls for Orion.Pollers. I would recommend sticking with AddDefaultPollers. If there is something you don't want collected (maybe you don't care about interface errors for some reason), you could always just pass AddDefaultPollers and then Delete any Orion.Pollers entries you don't want.