John Duprey

Members
  • Content Count

    1
  • Joined

  • Last visited

Community Reputation

0 Neutral

About John Duprey

  • Rank
    Community Member
  1. 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;