Forum Discussion

StLaurie's avatar
2 years ago

Datasource to get Uptime of VMWare vCenter Appliance

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.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();, user, pass, 10 * 1000); // Timeout in 10 seconds

def rootFolder = svc.getServiceInstance().getRootFolder();

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

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!