This post is more than 5 years old
3 Posts
0
144831
April 10th, 2013 12:00
Alarming on powered-on vCPUs at Cluster Level
I am trying to set up a Rule that set an Alarm when powered-on vCPUs in a cluster exceed a certain level. The following function works just fine when I am creating a Dashboard, but when I try to port it into a Rule, I am unable to get values out of the VM metrics. The "state" variable is assigned Null.
cluster = args['cluster'];
esxHosts = cluster.get("esxServers");
Integer vCPUCount = 0;
for (esxHost in esxHosts) {
VMs = esxHost.get("virtualMachines");
for (VM in VMs) {
state = VM.get("vmState/current/value");
if (state == 'poweredOn') {
vCPUs = VM.get("cpus/cores/current/average");
vCPUCount += vCPUs;
}
}
}
return vCPUCount;
I would appreciate any help you can provide!


john_s_main
132 Posts
1
April 10th, 2013 13:00
in a rule, I generally do something like this:
ds = server.DataService
cluster = scope;
esxHosts = cluster.get("esxServers");
Integer vCPUCount = 0;
for (esxHost in esxHosts) {
VMs = esxHost.get("virtualMachines");
for (VM in VMs) {
state = ds.retrieveLatestValue(VM,'vmState').getValue()
if (state == 'poweredOn') {
vCPUs = ds.retrieveLatestValue(VM.cpus,'cores').getValue().getAvg()
vCPUCount += vCPUs;
}
}
}
return vCPUCount;
wbdeford
3 Posts
0
April 10th, 2013 14:00
Thanks, John!!