Shell
getdata.groovy
url = "http://10.0.2.74:9000/api/resources?resource=ESB:com.boco.esb.analysismgr.service.impl&metrics=classes"
addr = url.toURL()
conn= addr.openConnection()
status = conn.getResponseCode()
reader = new BufferedReader(new InputStreamReader(conn.getInputStream()))
datastr = reader.readLine()
import groovy.json.JsonSlurper
slurper = new JsonSlurper()
data = slurper.parseText(datastr)
msr = data[0].msr.frmt_val[0]
Run Shell Script
-
start shell: "groovysh"
-
load script file: ". getdata.groovy";
-
all variables in script file can be used in shell; evaluate variable value by its name directly;
-
reload file: "purge all" then ". getdata.groovy";
Script
getdata_scpt.groovy
def url = "http://10.0.2.74:9000/api/resources?resource=ESB:com.boco.esb.analysismgr.service.impl&metrics=classes"
def addr = url.toURL()
def conn= addr.openConnection()
def status = conn.getResponseCode()
def reader = new BufferedReader(new InputStreamReader(conn.getInputStream()))
println reader.readLine()
run script
groovy getdata_scpt.groovy