Forum Discussion

Shack's avatar
Shack
Icon for Neophyte rankNeophyte
3 years ago

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

5 Replies

  • On 9/28/2021 at 10:06 AM, Shack said:

    I 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

     

    Thanks 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;

     

     

     

  • Anonymous's avatar
    Anonymous

    Do 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

  • I 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

  • I'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!

     

     
    datapoint0
    NaN
    param prefix is not invalid in format - (valid_prefixes=[.], method=namevalue, param=auto.vcenter)

    Raw Request/Response

     
    errOutput
     
    exitCode
    0
    output
    null
    responseTime
    25
    scriptOutput
    auto.vcenter.fullname=VMware vCenter Server 6.7.0 build-18831049
    auto.vcenter.build=18831049
    auto.vcenter.licenseproductname=VMware VirtualCenter Server
    auto.vcenter.os.type=linux-x64
    auto.vcenter.product.line=vpx
    auto.vcenter.version=6.7.0
    
  • Anonymous's avatar
    Anonymous

    If 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.