Question

Datasource to get Uptime of VMWare vCenter Appliance

  • 22 March 2023
  • 1 reply
  • 56 views

Badge

I cannot find a DataSource to build off to grab the uptime of our vCenter appliances.

I am able to get ESXi hosts uptimes with:

import com.vmware.vim25.mo.*;
import com.santaba.agent.groovyapi.esx.ESX;

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 rootFolder = svc.getServiceInstance().getRootFolder();

def hosts = new InventoryNavigator(rootFolder).searchManagedEntities("HostSystem");

hosts.each
{
esx ->
def uptimeinSeconds = esx.summary.quickStats;
println "UpTimeInSeconds=${uptimeinSeconds.uptime}";
}

return 0;

but cannot seem to adapt this for vCenter Appliances.

 

Any help would be appreciated!


1 reply

Userlevel 5
Badge +10

It looks like the API might be https://developer.vmware.com/apis/vsphere-automation/latest/appliance/api/appliance/system/uptime/get/ , but I did not test. You might want to base it on one of the existing VMware_VCSA_* DataSources as I don’t think the ESX groovy module support vcsa api calls.

Reply