SteveBamford
Neophyte
2 days agoexception:groovy.lang.MissingMethodException: No signature of method:
Working on my NetScan script for our Arista AP's still and when trying to execute a http [DELETE] I get the above error when following the Delete documentation here which suggests I can just call the URL and header.
Currently this is just using the collector debug !groovy command
If I then try with blank payload I get a different error: exception:java.lang.NullPointerException
First Error with no payload in call:
exception:groovy.lang.MissingMethodException: No signature of method: com.santaba.agent.groovyapi.http.Client.delete() is applicable for argument types: (java.lang.String, java.util.LinkedHashMap) values: [https://awm14001-c4.srv.wifi.arista.com/wifi/api/session, [Content-Type:application/json, ...]]
Possible solutions: delete(java.lang.String, java.lang.String, java.util.Map), release(), release(), close(), every(), get(java.lang.String)
java.lang.RuntimeException: groovy.lang.MissingMethodException: No signature of method: com.santaba.agent.groovyapi.http.Client.delete() is applicable for argument types: (java.lang.String, java.util.LinkedHashMap) values: [https://awm14001-c4.srv.wifi.arista.com/wifi/api/session, [Content-Type:application/json, ...]]
Possible solutions: delete(java.lang.String, java.lang.String, java.util.Map), release(), release(), close(), every(), get(java.lang.String)
at com.logicmonitor.groovy.objects.BaseWrapper.invoke(BaseWrapper.java:124)
at com.logicmonitor.groovy.objects.lang.ScriptWrapper.run(ScriptWrapper.java:31)
at com.santaba.agent.groovy.executor.GroovyScriptShell.execute(GroovyScriptShell.java:71)
at com.santaba.agent.util.GroovyScriptExecutor.execute(GroovyScriptExecutor.java:148)
at com.santaba.agent.debugger.GroovyTask._executeInAgent(GroovyTask.java:210)
at com.santaba.agent.debugger.GroovyTask._handle(GroovyTask.java:189)
at com.santaba.agent.debugger.DebugTask.run(DebugTask.java:176)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: groovy.lang.MissingMethodException: No signature of method: com.santaba.agent.groovyapi.http.Client.delete() is applicable for argument types: (java.lang.String, java.util.LinkedHashMap) values: [https://awm14001-c4.srv.wifi.arista.com/wifi/api/session, [Content-Type:application/json, ...]]
Possible solutions: delete(java.lang.String, java.lang.String, java.util.Map), release(), release(), close(), every(), get(java.lang.String)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:71)
at org.codehaus.groovy.runtime.callsite.PojoMetaClassSite.call(PojoMetaClassSite.java:48)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:136)
at Script85.run(Script85.groovy:76)
at jdk.internal.reflect.GeneratedMethodAccessor68.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at com.logicmonitor.groovy.objects.BaseWrapper.invoke(BaseWrapper.java:118)
... 9 more
Second Error with Blank Payload:
exception:java.lang.NullPointerException
java.lang.RuntimeException: java.lang.NullPointerException
at com.logicmonitor.groovy.objects.BaseWrapper.invoke(BaseWrapper.java:124)
at com.logicmonitor.groovy.objects.lang.ScriptWrapper.run(ScriptWrapper.java:31)
at com.santaba.agent.groovy.executor.GroovyScriptShell.execute(GroovyScriptShell.java:71)
at com.santaba.agent.util.GroovyScriptExecutor.execute(GroovyScriptExecutor.java:148)
at com.santaba.agent.debugger.GroovyTask._executeInAgent(GroovyTask.java:210)
at com.santaba.agent.debugger.GroovyTask._handle(GroovyTask.java:189)
at com.santaba.agent.debugger.DebugTask.run(DebugTask.java:176)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: java.lang.NullPointerException
at com.santaba.agent.groovyapi.http.Client._processResponse(Client.java:580)
at com.santaba.agent.groovyapi.http.Client.request(Client.java:429)
at com.santaba.agent.groovyapi.http.Client.delete(Client.java:409)
at com.santaba.agent.groovyapi.http.Client$delete$4.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:144)
at Script91.run(Script91.groovy:76)
at jdk.internal.reflect.GeneratedMethodAccessor68.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at com.logicmonitor.groovy.objects.BaseWrapper.invoke(BaseWrapper.java:118)
... 9 more
The Code:
/*******************************************************************************
* Arista WIFI Integration with CUE for discovery of the AP's
******************************************************************************/
import com.santaba.agent.groovyapi.http.*
import com.santaba.agent.groovy.utils.GroovyScriptHelper as GSH
import com.logicmonitor.mod.Snippets
import com.santaba.agent.AgentVersion
import java.text.DecimalFormat
import groovy.json.JsonOutput
import groovy.json.JsonSlurper
// To run in debug mode, set to true
Boolean debug = false
// To enable logging, set to true
Boolean log = false
// Set props object based on whether or not we are running inside a netscan or debug console
def props
try {
hostProps.get("system.hostname")
props = hostProps
debug = true // set debug to true so that we can ensure we do not print sensitive properties
}
catch (MissingPropertyException) {
props = netscanProps
}
//String key = props.get("AristaWIFI.api.key")
//String token = props.get("AristaWIFI.api.token")
//String clientId = props.get("AristaWIFI.api.clientId")
String key = [REMOVED]
String token = [REMOVED]
String clientId = "logicmonitor"
//if (!key) {
// throw new Exception("Must provide AristaWIFI.api.key to run this script. Verify necessary credentials have been provided in Netscan properties.")
//}
//if (!token) {
// throw new Exception("Must provide AristaWIFI.api.token credentials to run this script. Verify necessary credentials have been provided in Netscan properties.")
//}
//if (!clientId) {
// throw new Exception("Must provide AristaWIFI.api.clientId credentials to run this script. Verify necessary credentials have been provided in Netscan properties.")
//}
//def logCacheContext = "${org}::arista-wifi-cloud"
//Boolean skipDeviceDedupe = props.get("skip.device.dedupe", "false").toBoolean()
//String hostnameSource = props.get("hostname.source", "")?.toLowerCase()?.trim()
Integer collectorVersion = AgentVersion.AGENT_VERSION.toInteger()
// Bail out early if we don't have the correct minimum collector version to ensure netscan runs properly
if (collectorVersion < 32400) {
def formattedVer = new DecimalFormat("00.000").format(collectorVersion / 1000)
throw new Exception("Upgrade collector running netscan to 32.400 or higher to run full featured enhanced netscan. Currently running version ${formattedVer}.")
}
externalHost= "awm14001-c4.srv.wifi.arista.com";
httpClient = HTTP.open(externalHost,443);
httpClient.setHTTPProxy('proxy.iggroup.local',8080);
// Log in to arista
loginurl = "https://awm14001-c4.srv.wifi.arista.com/wifi/api/session"
payloadstring = '{"type":"apiKeycredentials","keyId":"'+key+'","keyValue":"'+token+'","timeout":3600,"clientIdentifier": "'+clientId+'"}';
def payload = payloadstring;
println payload;
def loginResponse = httpClient.post(loginurl,payload,["Content-Type":"application/json"]);
if ( !(httpClient.getStatusCode() =~ /20/) )
{
// Error has occured
println "Authentication Failure";
println httpClient.getStatusCode();
println loginResponse;
return(1);
}
String RawCookie = httpClient.getHeader("Set-Cookie")
//Have Kept but as yet not needed will remove if not needed..
String httpResponseBody = httpClient.getResponseBody()
//Retrieve the Cookie to use from the header.
AristaCookie = RawCookie.split(';')[0]
println httpClient.getStatusCode()
String cookieString = '"'+AristaCookie+'"'
def logoutheaders = ["Content-Type":"application/json","Cookie":cookieString]
//println logoutheaders
def logoutResponse = httpClient.delete(loginurl,logoutheaders) <- With No payload
def logoutResponse = httpClient.delete(loginurl,'{}'logoutheaders) <- With blank payload I have just tried "" as the payload as well.
logoutResult = httpClient.getStatusCode()
if ( !(httpClient.getStatusCode() =~ /20/) )
{
//Error has occured
println "Logout Failure";
println httpClient.getStatusCode();
println loginResponse;
return(1);
}
println AristaCookie;
println httpResponseBody;
println logoutResponse;
def LMDebugPrint(message) {
if (debug) {
println(message.toString())
}
}
The Same URL and the same header with no payload works if I work in python obviously appreciate they are different languages, just confirming that the formatting is correct.