WIP - refactoring.
This commit is contained in:
parent
504058ae7a
commit
2b95adcb23
|
@ -24,6 +24,7 @@ dependencies {
|
||||||
// Use the latest Groovy version for building this library
|
// Use the latest Groovy version for building this library
|
||||||
implementation 'org.codehaus.groovy:groovy-all:3.0.5'
|
implementation 'org.codehaus.groovy:groovy-all:3.0.5'
|
||||||
implementation 'com.squareup.okhttp3:okhttp:4.8.0'
|
implementation 'com.squareup.okhttp3:okhttp:4.8.0'
|
||||||
|
implementation 'org.influxdb:influxdb-java:2.19'
|
||||||
implementation 'org.slf4j:slf4j-api:1.7.+'
|
implementation 'org.slf4j:slf4j-api:1.7.+'
|
||||||
runtimeOnly 'ch.qos.logback:logback-classic:1.+'
|
runtimeOnly 'ch.qos.logback:logback-classic:1.+'
|
||||||
|
|
||||||
|
@ -31,7 +32,8 @@ dependencies {
|
||||||
testImplementation('org.spockframework:spock-core:2.0-M3-groovy-3.0')
|
testImplementation('org.spockframework:spock-core:2.0-M3-groovy-3.0')
|
||||||
testImplementation("org.slf4j:slf4j-simple:1.7.+")
|
testImplementation("org.slf4j:slf4j-simple:1.7.+")
|
||||||
testImplementation('com.squareup.okhttp3:mockwebserver:4.8.0')
|
testImplementation('com.squareup.okhttp3:mockwebserver:4.8.0')
|
||||||
|
//implementation platform('org.testcontainers:testcontainers-bom:1.14.3') //import bom
|
||||||
|
//testCompile "org.testcontainers:influxdb:1.14.3"
|
||||||
}
|
}
|
||||||
|
|
||||||
application {
|
application {
|
||||||
|
|
|
@ -8,8 +8,48 @@ import groovy.util.logging.Slf4j
|
||||||
@Slf4j
|
@Slf4j
|
||||||
class App {
|
class App {
|
||||||
|
|
||||||
|
App(String... args) {
|
||||||
|
|
||||||
|
println("App()")
|
||||||
|
|
||||||
|
Map<String,ManagedSystem> systems = new HashMap<String, ManagedSystem>()
|
||||||
|
Map<String, LogicalPartition> partitions = new HashMap<String, LogicalPartition>()
|
||||||
|
|
||||||
|
|
||||||
|
HmcClient hmc
|
||||||
|
try {
|
||||||
|
hmc = new HmcClient("https://10.32.64.39:12443", "hmci", "hmcihmci")
|
||||||
|
hmc.login()
|
||||||
|
|
||||||
|
hmc.getManagedSystems().each { systemKey, system ->
|
||||||
|
|
||||||
|
// Add to list of known systems
|
||||||
|
systems.putIfAbsent(systemKey, system)
|
||||||
|
|
||||||
|
// Get and process metrics for this system
|
||||||
|
String json = hmc.getPcmForManagedSystemWithId(system)
|
||||||
|
system.processPcmJson(json)
|
||||||
|
|
||||||
|
|
||||||
|
/*hmc.getLogicalPartitionsForManagedSystem(systemValue).each { lparKey, lpar ->
|
||||||
|
partitions.putIfAbsent(lparKey, lpar)
|
||||||
|
//hmc.get
|
||||||
|
}*/
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
hmc.logoff()
|
||||||
|
} catch(Exception e) {
|
||||||
|
log.error(e.message)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void main(String... args) {
|
static void main(String... args) {
|
||||||
|
|
||||||
|
|
||||||
def cli = new CliBuilder()
|
def cli = new CliBuilder()
|
||||||
cli.h(longOpt: 'help', 'display usage')
|
cli.h(longOpt: 'help', 'display usage')
|
||||||
cli.v(longOpt: 'version', 'display version')
|
cli.v(longOpt: 'version', 'display version')
|
||||||
|
@ -23,20 +63,10 @@ class App {
|
||||||
//println("TODO: Use configuration file: " + options.config)
|
//println("TODO: Use configuration file: " + options.config)
|
||||||
}
|
}
|
||||||
|
|
||||||
Hmc hmc
|
// TODO: Read configuration file or create new empty file,
|
||||||
try {
|
// pass the properties or configuration bean to App.
|
||||||
hmc = new Hmc("https://10.32.64.39:12443", "hmci", "hmcihmci")
|
|
||||||
hmc.login()
|
|
||||||
|
|
||||||
hmc.getManagedSystems()
|
|
||||||
hmc.getLogicalPartitions()
|
|
||||||
hmc.getProcessedMetrics()
|
|
||||||
|
|
||||||
hmc.logoff()
|
|
||||||
} catch(Exception e) {
|
|
||||||
log.error(e.message)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
new App(args)
|
||||||
|
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ import java.security.cert.CertificateException
|
||||||
import java.security.cert.X509Certificate;
|
import java.security.cert.X509Certificate;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
class Hmc {
|
class HmcClient {
|
||||||
|
|
||||||
private final MediaType MEDIA_TYPE_IBM_XML_LOGIN = MediaType.parse("application/vnd.ibm.powervm.web+xml; type=LogonRequest");
|
private final MediaType MEDIA_TYPE_IBM_XML_LOGIN = MediaType.parse("application/vnd.ibm.powervm.web+xml; type=LogonRequest");
|
||||||
|
|
||||||
|
@ -29,12 +29,12 @@ class Hmc {
|
||||||
private final String username
|
private final String username
|
||||||
private final String password
|
private final String password
|
||||||
|
|
||||||
protected Map<String,ManagedSystem> managedSystems = new HashMap<String, ManagedSystem>()
|
//protected Map<String,ManagedSystem> managedSystems = new HashMap<String, ManagedSystem>()
|
||||||
protected String authToken
|
protected String authToken
|
||||||
private final OkHttpClient client
|
private final OkHttpClient client
|
||||||
|
|
||||||
|
|
||||||
Hmc(String baseUrl, String username, String password) {
|
HmcClient(String baseUrl, String username, String password) {
|
||||||
this.baseUrl = baseUrl
|
this.baseUrl = baseUrl
|
||||||
this.username = username
|
this.username = username
|
||||||
this.password = password
|
this.password = password
|
||||||
|
@ -93,30 +93,31 @@ class Hmc {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void getManagedSystems() {
|
Map<String, ManagedSystem> getManagedSystems() {
|
||||||
|
|
||||||
log.debug("getManagedSystems()")
|
log.debug("getManagedSystems()")
|
||||||
|
|
||||||
URL url = new URL(String.format("%s/rest/api/uom/ManagedSystem", baseUrl))
|
URL url = new URL(String.format("%s/rest/api/uom/ManagedSystem", baseUrl))
|
||||||
Response response = getResponse(url)
|
Response response = getResponse(url)
|
||||||
String responseBody = response.body.string()
|
String responseBody = response.body.string()
|
||||||
|
Map<String,ManagedSystem> managedSystemsMap = new HashMap<String, ManagedSystem>()
|
||||||
|
|
||||||
def feed = new XmlSlurper().parseText(responseBody)
|
def feed = new XmlSlurper().parseText(responseBody)
|
||||||
feed?.entry?.each { entry ->
|
feed?.entry?.each { entry ->
|
||||||
//log.debug("Entry")
|
|
||||||
entry.content.each { content ->
|
entry.content.each { content ->
|
||||||
//log.debug("Content")
|
|
||||||
content.ManagedSystem.each { system ->
|
content.ManagedSystem.each { system ->
|
||||||
ManagedSystem managedSystem = new ManagedSystem(entry.id as String)
|
ManagedSystem managedSystem = new ManagedSystem(entry.id as String)
|
||||||
managedSystem.name = system.SystemName
|
managedSystem.name = system.SystemName
|
||||||
managedSystem.model = system.MachineTypeModelAndSerialNumber.Model
|
managedSystem.model = system.MachineTypeModelAndSerialNumber.Model
|
||||||
managedSystem.type = system.MachineTypeModelAndSerialNumber.MachineType
|
managedSystem.type = system.MachineTypeModelAndSerialNumber.MachineType
|
||||||
managedSystem.serialNumber = system.MachineTypeModelAndSerialNumber.SerialNumber
|
managedSystem.serialNumber = system.MachineTypeModelAndSerialNumber.SerialNumber
|
||||||
managedSystems.put(managedSystem.id, managedSystem)
|
managedSystemsMap.put(managedSystem.id, managedSystem)
|
||||||
log.debug("getManagedSystems() " + managedSystem.toString())
|
log.debug("getManagedSystems() " + managedSystem.toString())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return managedSystemsMap
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -128,7 +129,7 @@ class Hmc {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void getLogicalPartitionsForManagedSystem(ManagedSystem system) {
|
Map<String, LogicalPartition> getLogicalPartitionsForManagedSystem(ManagedSystem system) {
|
||||||
log.debug("getLogicalPartitionsForManagedSystem() - " + system.name)
|
log.debug("getLogicalPartitionsForManagedSystem() - " + system.name)
|
||||||
|
|
||||||
URL url = new URL(String.format("%s/rest/api/uom/ManagedSystem/%s/LogicalPartition", baseUrl, system.id))
|
URL url = new URL(String.format("%s/rest/api/uom/ManagedSystem/%s/LogicalPartition", baseUrl, system.id))
|
||||||
|
@ -136,6 +137,7 @@ class Hmc {
|
||||||
String responseBody = response.body.string()
|
String responseBody = response.body.string()
|
||||||
//log.debug(responseBody)
|
//log.debug(responseBody)
|
||||||
|
|
||||||
|
Map<String, LogicalPartition> partitionMap = new HashMap<String, LogicalPartition>() {}
|
||||||
def feed = new XmlSlurper().parseText(responseBody)
|
def feed = new XmlSlurper().parseText(responseBody)
|
||||||
feed?.entry?.each { entry ->
|
feed?.entry?.each { entry ->
|
||||||
//log.debug("Entry")
|
//log.debug("Entry")
|
||||||
|
@ -145,35 +147,35 @@ class Hmc {
|
||||||
LogicalPartition logicalPartition = new LogicalPartition(partition.PartitionUUID as String)
|
LogicalPartition logicalPartition = new LogicalPartition(partition.PartitionUUID as String)
|
||||||
logicalPartition.name = partition.PartitionName
|
logicalPartition.name = partition.PartitionName
|
||||||
logicalPartition.type = partition.PartitionType
|
logicalPartition.type = partition.PartitionType
|
||||||
system.partitions.put(logicalPartition.id, logicalPartition)
|
partitionMap.put(logicalPartition.id, logicalPartition)
|
||||||
log.debug("getLogicalPartitionsForManagedSystem() " + logicalPartition.toString())
|
log.debug("getLogicalPartitionsForManagedSystem() " + logicalPartition.toString())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return partitionMap
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void getProcessedMetrics() {
|
void getProcessedMetrics() {
|
||||||
managedSystems.each {
|
managedSystems.each {
|
||||||
getProcessedMetricsForManagedSystem(it.getValue())
|
getPcmForManagedSystemWithId(it.getValue())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void getProcessedMetricsForManagedSystem(ManagedSystem system) {
|
String getPcmForManagedSystemWithId(String systemId) {
|
||||||
log.debug("getProcessedMetricsForManagedSystem() " - system.name)
|
log.debug("getProcessedMetricsForManagedSystem() " - systemId)
|
||||||
URL url = new URL(String.format("%s/rest/api/pcm/ManagedSystem/%s/ProcessedMetrics?NoOfSamples=1", baseUrl, system.id))
|
URL url = new URL(String.format("%s/rest/api/pcm/ManagedSystem/%s/ProcessedMetrics?NoOfSamples=1", baseUrl, systemId))
|
||||||
Response response = getResponse(url)
|
Response response = getResponse(url)
|
||||||
String responseBody = response.body.string()
|
String responseBody = response.body.string()
|
||||||
//log.debug(responseBody)
|
|
||||||
|
|
||||||
def feed = new XmlSlurper().parseText(responseBody)
|
def feed = new XmlSlurper().parseText(responseBody)
|
||||||
feed?.entry?.each { entry ->
|
feed?.entry?.each { entry ->
|
||||||
String link = entry.link["@href"]
|
String link = entry.link["@href"]
|
||||||
//linksList.add(link)
|
|
||||||
switch (entry.category["@term"]) {
|
switch (entry.category["@term"]) {
|
||||||
case "ManagedSystem":
|
case "ManagedSystem":
|
||||||
processPcmJsonForManagedSystem(getPcmJsonForManagedSystem(link))
|
return getPcmJsonForManagedSystem(link)
|
||||||
break
|
break
|
||||||
case "LogicalPartition":
|
case "LogicalPartition":
|
||||||
//processPcmJsonForLogicalPartition(getPcmJsonForLogicalPartition(getProcessedMetricsForLogicalPartition(link)))
|
//processPcmJsonForLogicalPartition(getPcmJsonForLogicalPartition(getProcessedMetricsForLogicalPartition(link)))
|
||||||
|
@ -206,14 +208,15 @@ class Hmc {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
String getPcmJsonForManagedSystem(String jsonUrl) {
|
private String getPcmJsonForManagedSystem(String jsonUrl) {
|
||||||
log.debug("getPcmJsonForManagedSystem() - " + jsonUrl)
|
log.debug("getPcmJsonForManagedSystem() - " + jsonUrl)
|
||||||
URL url = new URL(jsonUrl)
|
URL url = new URL(jsonUrl)
|
||||||
Response response = getResponse(url)
|
Response response = getResponse(url)
|
||||||
return response.body.string()
|
return response.body.string()
|
||||||
}
|
}
|
||||||
|
|
||||||
String getPcmJsonForLogicalPartition(String jsonUrl) {
|
|
||||||
|
private String getPcmJsonForLogicalPartition(String jsonUrl) {
|
||||||
log.debug("getPcmJsonForLogicalPartition() - " + jsonUrl)
|
log.debug("getPcmJsonForLogicalPartition() - " + jsonUrl)
|
||||||
URL url = new URL(jsonUrl)
|
URL url = new URL(jsonUrl)
|
||||||
Response response = getResponse(url)
|
Response response = getResponse(url)
|
||||||
|
@ -221,16 +224,6 @@ class Hmc {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void processPcmJsonForManagedSystem(String json) {
|
|
||||||
log.debug("processPcmJsonForManagedSystem()")
|
|
||||||
def jsonObject = new JsonSlurper().parseText(json)
|
|
||||||
String systemUuid = jsonObject?.systemUtil?.utilInfo?.uuid as String
|
|
||||||
if(systemUuid && managedSystems.containsKey(systemUuid)) {
|
|
||||||
log.debug("processPcmJsonForManagedSystem() - Found UUID for ManagedSystem: " + systemUuid)
|
|
||||||
ManagedSystem system = managedSystems.get(systemUuid)
|
|
||||||
system.processMetrics(json)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void processPcmJsonForLogicalPartition(String json) {
|
void processPcmJsonForLogicalPartition(String json) {
|
||||||
log.debug("processPcmJsonForLogicalPartition()")
|
log.debug("processPcmJsonForLogicalPartition()")
|
5
src/main/groovy/biz/nellemann/hmci/InfluxClient.groovy
Normal file
5
src/main/groovy/biz/nellemann/hmci/InfluxClient.groovy
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
package biz.nellemann.hmci
|
||||||
|
|
||||||
|
class InfluxClient {
|
||||||
|
|
||||||
|
}
|
|
@ -26,7 +26,20 @@ class ManagedSystem {
|
||||||
return "[${id}] ${name} (${type}-${model} ${serialNumber})"
|
return "[${id}] ${name} (${type}-${model} ${serialNumber})"
|
||||||
}
|
}
|
||||||
|
|
||||||
void processMetrics(String json) {
|
|
||||||
|
|
||||||
|
|
||||||
|
void processPcmJson(String json) {
|
||||||
|
log.debug("processPcmJson()")
|
||||||
|
def jsonObject = new JsonSlurper().parseText(json)
|
||||||
|
String systemUuid = jsonObject?.systemUtil?.utilInfo?.uuid as String
|
||||||
|
if(systemUuid && this.id == systemUuid) {
|
||||||
|
log.debug("processPcmJson() - Found UUID for this ManagedSystem: " + systemUuid)
|
||||||
|
processMetrics(json)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void processMetrics(String json) {
|
||||||
//metrics = new JsonSlurper().parseText(json) as PcmData
|
//metrics = new JsonSlurper().parseText(json) as PcmData
|
||||||
def pcmMap = new JsonSlurper().parseText(json)
|
def pcmMap = new JsonSlurper().parseText(json)
|
||||||
metrics = new PcmData(pcmMap as Map)
|
metrics = new PcmData(pcmMap as Map)
|
||||||
|
|
|
@ -5,15 +5,15 @@ import okhttp3.mockwebserver.MockResponse
|
||||||
import okhttp3.mockwebserver.MockWebServer
|
import okhttp3.mockwebserver.MockWebServer
|
||||||
import spock.lang.Specification
|
import spock.lang.Specification
|
||||||
|
|
||||||
class HmcTest extends Specification {
|
class HmcClientTest extends Specification {
|
||||||
|
|
||||||
Hmc hmc
|
HmcClient hmc
|
||||||
MockWebServer mockServer = new MockWebServer();
|
MockWebServer mockServer = new MockWebServer();
|
||||||
|
|
||||||
|
|
||||||
def setup() {
|
def setup() {
|
||||||
mockServer.start();
|
mockServer.start();
|
||||||
hmc = new Hmc(mockServer.url("/").toString(), "testUser", "testPassword")
|
hmc = new HmcClient(mockServer.url("/").toString(), "testUser", "testPassword")
|
||||||
hmc.authToken = "blaBla"
|
hmc.authToken = "blaBla"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue