Forum Discussion
7 years ago
Alright, disregard that old code, whoooo, that's a lot harder to do than what you pointed me at @Michael Rodrigues, i can't believe I missed that in the support documentation.
Anyways, got it working this way. Thanks!
import com.santaba.agent.groovyapi.http.*;
import groovy.json.JsonSlurper;
def hostName = hostProps.get("system.hostname");
def user = hostProps.get("viptela.user");
def pass = hostProps.get("viptela.pass");
slurper = new JsonSlurper()
// instantiate an http client object for the target system
httpClient = HTTP.open(hostName, 443);
// use an authentication API call to initiate a session
// specify the url to which we want to post
url = "https://"+hostName+"/j_security_check";
def payload = 'j_username=' + user + '&j_password=' + pass;
// do the post
def postResponse = httpClient.post(url, payload,["Content-Type":"application/x-www-form-urlencoded"]);
// does the response indicate a successful authentication?
if ( !(httpClient.getStatusCode() =~ /200/) )
{
// no -- report an error, and return a non-zero exit code
println "authentication failure";
return(1);
}
// we are now authenticated. Subsequent GETs with the httpClient will pass in the session cookie
url="https://"+hostName+"/dataservice/alarms/count";
def getResponse=httpClient.get(url);
// print some data
//println httpClient.getResponseBody();
arrayLines = slurper.parseText(httpClient.getResponseBody());
println "count:" + arrayLines.data.count[0];
println "cleared_count:" + arrayLines.data.cleared_count[0];
Related Content
- 5 months ago
- 10 months ago
- 2 years ago
- 9 months ago