John Duprey

vCenter ESXi Hardware Sensors

Recommended Posts

This DataSource is the vCenter equivalent of VMware_ESXi_HardwareSensors one.

The new DataSource is called VMware_vCenter_HostHardwareSensors ( lmLocator CDGEFM ), it targets system.virtualization =~ "VMware ESX vcenter" and provides hardware sensor instances that are titled host name - sensor name grouped by type.

Discovery Script

import com.santaba.agent.groovyapi.esx.ESX
import com.vmware.vim25.mo.*
import java.security.MessageDigest

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

// We are confident we can parse names for these devices
def deviceSensorTypes = ["fan",
						 "storage",
						 "power",
						 "chassis",
						 "voltage",
						 "battery",
						 "processors",
						 "watchdog",
						 "cable/interconnect",
						 "memory",
						 "slot/connector",
						 "system",
						 "boot",
						 "logging",
						 "management subsystem health",
						 "temperature",
						 "other",
						 "platform alert",
						 "chip set"];

def svc = new ESX();
svc.open(addr, user, pass, 10 * 1000);  // timeout in 10 seconds

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

// Get ESX hosts
HostSystem[] esxHosts = new InventoryNavigator(rootFolder).searchManagedEntities("HostSystem")

esxHosts.each { esx ->

    // Find and iterate over host sensors
    def numericSensors = esx?.runtime?.healthSystemRuntime?.systemHealthInfo?.numericSensorInfo;

    numericSensors.each()
    {
    	sensor ->
    
    	if(sensor.sensorType != "Software Components")
    	{
		    def name = sensor.name;

		    // Check the name for a device format. Strip alert status from the name
		    // Example: "[Device] Processor 0 CPU1 UPI Link 0: Config Error - Deassert"

    		if(deviceSensorTypes.contains(sensor.sensorType.toLowerCase()))
    		{
    			// Remove status suffix
    			name = name.split(" -").first();    

			    // Clean up the [device] prefix that shows up some times.
			    if (name.startsWith("[Device]"))
			    {
	    			name = name.replace("[Device]", "");
    			}
		    }

		    name = esx.name + ' - ' + name.trim().capitalize();
		    def wildvalue = MessageDigest.getInstance("MD5").digest(name.bytes).encodeHex().toString();

		    def properties = [:];
		    properties["sensor_type"] = sensor.sensorType.capitalize();
		    properties["host"] = esx.name;

		    // Generate a unit string
		    if(sensor.baseUnits) properties["sensor_units"] = sensor.baseUnits;
		    if(sensor.baseUnits && sensor.rateUnits) properties["sensor_units"] = "${sensor.baseUnits}/${sensor.rateUnits}"
		
		    println "${wildvalue}##${name}######${properties.collectEntries{ k, v -> ["auto.${k}=${v}"]}.keySet().join('&');}"
	    }
    }
}
return 0;

Collection Script

import com.santaba.agent.groovyapi.esx.ESX
import com.vmware.vim25.mo.*
import java.security.MessageDigest

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

// We are confident we can parse names for these devices
def deviceSensorTypes = ["fan",
						 "storage",
						 "power",
						 "chassis",
						 "voltage",
						 "battery",
						 "processors",
						 "watchdog",
						 "cable/interconnect",
						 "memory",
						 "slot/connector",
						 "system",
						 "boot",
						 "logging",
						 "management subsystem health",
						 "temperature",
						 "other",
						 "platform alert",
						 "chip set"];

def sensorStateMap = ["green"	:1,
					  "yellow"	:2,
					  "red"		:3];

def svc = new ESX();
svc.open(addr, user, pass, 10 * 1000);  // timeout in 10 seconds

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

// Get ESX hosts
HostSystem[] esxHosts = new InventoryNavigator(rootFolder).searchManagedEntities("HostSystem")

esxHosts.each { esx ->
// Find and iterate over host sensors
    def numericSensors = esx?.runtime?.healthSystemRuntime?.systemHealthInfo?.numericSensorInfo;

    numericSensors.each()
    {
    	sensor ->

	    if(sensor.sensorType != "Software Components")
	    {   
    		def name = sensor.name;

		    // Check the name for a device format. Strip alert status from the name
		    // Example: "[Device] Processor 0 CPU1 UPI Link 0: Config Error - Deassert"

		    if(deviceSensorTypes.contains(sensor.sensorType.toLowerCase()))
		    {
    			// Remove status suffix
			    name = name.split(" -").first();

			    // Clean up the [device] prefix that shows up some times.
			    if (name.startsWith("[Device]"))
			    {
    				name = name.replace("[Device]", "");
			    }
		    }

		    name = esx.name + ' - ' + name.trim().capitalize();
		    def wildvalue = MessageDigest.getInstance("MD5").digest(name.bytes).encodeHex().toString();

		    println "${wildvalue}.state=${sensorStateMap.get(sensor.healthState.key, 0)}";
		    println "${wildvalue}.reading=${sensor.currentReading}";
		    println "${wildvalue}.modifier=${sensor.unitModifier}";
	    }
    }
}
return 0;

 

Share this post


Link to post
Share on other sites

I'm new to the exchange side of things and wasn't aware there was a security review process. I'll ping andrey and see if he can clarify. Is there a particular need to have it in the exchange? You could just export the xml and host it on github or something for others to get it there. Or are you looking for a "blessing" from LM?

Share this post


Link to post
Share on other sites

I guess it more about having it vetted before being released to the general public. Also I don't really have access to the XML, OP does. He just posted the scripts. I have no way to see what data points or settings are being used. Hence the request to vet the submission and approve so we can pull it into our environments. 

Share this post


Link to post
Share on other sites

Thank you much Stuart. I'm not sure what the official approval process is and who's responsible for that. I just saw that Andrey has been really responsive to these sort of submissions. 

Share this post


Link to post
Share on other sites

I heard back from him over lunch. Apparently there used to be something akin to a queue system where these things would get processed. However, in case you are unaware, there is a significant rewrite in the works for the exchange (really awesome stuff making it more like an app store) and when that rewrite started, that workflow was one of the first things that got broken. 

So in the meantime, the official word on how to make sure this is getting attention is to hit up the LM support team. They can internally slack the datasources channel where it will get the attention it needs.

For this one, i've already put that in motion as of a few minutes ago.  Stay tuned...

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.