Capture vCenter Versions
I need to be able to report on vCenter versions. Today that is only captured when SNMP is configured on the vCenter Appliance. I need another way to populate this for all of the VC's in my environment as many of them are not configured with SNMP just esx.user and .pass.
Anyone out there with a groovy script that would do this? I'm stuck reading the output using the first link below. I would like to just read the value from one of the properties on the page and set it as a property on my device.
This page displays the info nicely in xml - https://${host}/mob/?moid=ServiceInstance&doPath=content%2eabout
This one also does too via the API - https://vcenter.fqdn/rest/appliance/system/version
Shack
Posted 4 years ago·Last reply 4 years ago
5 comments
FrankG
·4 years agoThanks for this. Trying to find the exact Service Instance context via VMware documentation was unfruitful and I don't have direct access to the SDK endpoints at the moment. I was about to try to regain access to a lab vCenter to get this information and I stumbled upon this. I owe you a beer @Shack.
In the interest of keeping the sharing vibe strong, here's a similar property source that I made for iDRAC BIOS and Firmware versioning. If it helps anyone else, my job is done. If not, no worries.
---
Dell iDRAC BIOS - AppliesTo - system.sysoid =~ "1.3.6.1.4.1.674.10892.5" || hasCategory("DellDRACDetail")
/*********** Frank G - LM Community ******************/
import com.santaba.agent.groovyapi.snmp.Snmp;
def hostname = hostProps.get("system.hostname");
// gather all properties necessary.
def props = hostProps.toProperties()
def timeout = 5000; // Timeout in milliseconds
def system_WalkAsMap = Snmp.walkAsMap(hostname, ".1.3.6.1.4.1.674.10892.5.4.300.50", props, timeout); // This is the systemBIOStable for iDRAC
if (system_WalkAsMap) {
println "auto.drac.bios.version=" + system_WalkAsMap['1.8.1.1'] // 1.8.1.1 = BIOS version name
println "auto.drac.bios.version.date=" + system_WalkAsMap['1.7.1.1'] // 1.7.1.1 = BIOS version date
}
// Successful script execution, return 0;
return 0;
----
Dell iDRAC Firmware (similar/same appliesTo as above)
/*********** Frank G - LM Community ******************/
import com.santaba.agent.groovyapi.snmp.Snmp;
def hostname = hostProps.get("system.hostname");
// gather all properties necessary.
def props = hostProps.toProperties()
def timeout = 5000; // Timeout in milliseconds
def system_WalkAsMap = Snmp.walkAsMap(hostname, ".1.3.6.1.4.1.674.10892.5.4.300.60", props, timeout); // This is the firmwaretable for iDRAC
if (system_WalkAsMap) {
println "auto.drac.firmware.version.1=" + system_WalkAsMap['1.11.1.1'] // 1.11.1.1 = firmware version name
println "auto.drac.firmware.version.2=" + system_WalkAsMap['1.11.1.2'] // 1.11.1.2 = firmware version name (2, if applicable)
println "auto.drac.version=" + system_WalkAsMap['1.8.1.1'] // 1.8.1.1 = iDRAC version
}
// Successful script execution, return 0;
return 0;
LM User
·4 years agoIf you are trying to capture non-numeric data, you should build this as a propertysource. If you've got it as a DataSource, non-numerical data will result in "NaN" errors.
If you are trying to set these attributes as properties, you need to build it as a propertysource.
clinton_buss
·4 years agoI'm totally new to datapoints in LM, so hopefully I'm just missing simple. When I add the groovy script above to a new datasource, I get results via "poll now" but they are only in the "Raw Request/Response" section as "Script Output" while "Output" remains a null value. I'm using "content the script writes to the standard output" and a Key value of "auto.vcenter" - Thanks for any insight!
Raw Request/Response
Shack
OP4 years agoI figured this out and went a different route. Here is what I'm using. Works perfectly on all VC's in our environment, both windows and appliance.
import com.santaba.agent.groovyapi.esx.ESX
import com.vmware.vim25.mo.*
def host = hostProps.get("system.hostname")
def user = hostProps.get("esx.user")
def pass = hostProps.get("esx.pass")
def addr = hostProps.get("esx.url") ?: "https://${host}/sdk"
def svc = new ESX()
svc.open(addr, user, pass, 10 * 1000) // timeout in 10 seconds
def si = svc.getServiceInstance()
def rootFolder = si.getRootFolder()
// Get resource
HostSystem esxHost = new InventoryNavigator(rootFolder).searchManagedEntities("HostSystem").first()
println "auto.vcenter.fullname=${si.aboutInfo.fullName}"
println "auto.vcenter.build=${si.aboutInfo.build}"
println "auto.vcenter.licenseproductname=${si.aboutInfo.licenseProductName}"
println "auto.vcenter.os.type=${si.aboutInfo.osType}"
println "auto.vcenter.product.line=${si.aboutInfo.productLineId}"
println "auto.vcenter.version=${si.aboutInfo.version}"
return 0
LM User
·4 years agoDo you already have a script started?
You might check here and here for examples of how to fetch web pages in Groovy. From there, since you're fetching XML, it shouldn't be too hard to parse XML. I like this tutorial.