サンプルコード
@Grab(group='org.apache.httpcomponents', module='httpclient', version='4.3.5') import org.apache.http.client.methods.* import org.apache.http.impl.client.* import org.apache.http.message.* import org.apache.http.auth.* import groovy.json.* def host = "192.168.1.240" // replace this def port = 7180 def user = "admin" def password = "admin" def httpclient = new DefaultHttpClient() httpclient.getCredentialsProvider().setCredentials( new AuthScope(host, port), new UsernamePasswordCredentials(user, password) ) def method = new HttpGet("http://${host}:${port}/api/v7/hosts") def response = httpclient.execute(method) println response.getStatusLine().getStatusCode() def json = new JsonSlurper().parseText(response.getEntity().getContent().text) for(item in json.items){ println "hostname:${item.hostname}" println "IP Address:${item.ipAddress}" println "Rack ID:${item.rackId}" }参考情報
/hosts - Cloudera Manager API v7
0 件のコメント:
コメントを投稿