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
I am wondering what is does the XML look like that AddInterfaceToNode looks like or is expecting....or if you spot something else wrong please let me know!
Thanks!