ESX Host Services?
I'm looking for a way to monitor ESX Host Services. Right now I have a script that I believed to be working but after spot checking a few hosts it seems to not be totally accurate. Or, I just don't fully understand the backend on a host as far as the services go vs the data I am collecting.
My datasource is reporting services to be Running on hosts that clearly state certain services to be Stopped.
Active Discovery
import com.santaba.agent.groovyapi.esx.ESX
import com.vmware.vim25.mo.InventoryNavigator
def hostname = hostProps.get("system.hostname")
def user = hostProps.get("esx.user")
def pass = hostProps.get("esx.pass")
def custom_url = hostProps.get("esx.url")
def display_name = hostProps.get("system.displayname")
// Connect to the ESX service
def url = custom_url ?: "https://${hostname}/sdk"
def svc = new ESX()
svc.open(url, user, pass, 10 * 1000) // Timeout in 10 seconds
// Get the service instance and root folder
def si = svc.getServiceInstance()
def rootFolder = si.getRootFolder()
// Search for managed entities of type 'HostSystem'
def hosts = new InventoryNavigator(rootFolder).searchManagedEntities("HostSystem")
// Iterate over each host system
hosts.each { host ->
// Get the services for the current host
def services = host.getConfig().getService()
// Iterate over each service
services.each { service ->
// Get the label and key of each service
def labels = service?.service?.label
def keys = service?.service?.key
def running = service?.service?.running ? "Running" : "Stopped"
// If label is an array, print each element on its own line
if (labels instanceof List) {
labels.eachWithIndex { singleLabel, index ->
println "${keys[index]}##${keys[index]}##${singleLabel}"
}
} else {
// If label is not an array, print it normally
//println "Service Label: ${labels}, Key: ${keys}, Status: ${running}"
}
}
}
// Close the ESX service connection
svc.close()
Data Collection