ok
Direktori : /proc/self/root/lib/fm-agent/plugins/ |
Current File : //proc/self/root/lib/fm-agent/plugins/lm_sensors.py |
import agent_util import sys import os import platform from agent_util import float def build_sensor_dict(): cmd = """sensors -u""" ret, out = agent_util.execute_command(cmd) lines = out.splitlines() current_sensor_package = "" current_sensor = "" sensors_dict = {} for l in lines: l = l.lower() if not l or l == "" or "adapter" in l: continue if ":" in l: if not l or l == "" or "crit" in l or "max" in l: continue line = l.strip().split(":") if not line[1]: current_sensor = line[0].replace(" ", "_") else: sens_type = "temperature" if "fan" in current_sensor: sens_type = "fan_speed" textkey = "%s.%s.%s" % (current_sensor_package, current_sensor, line[0]) if sens_type not in sensors_dict: sensors_dict[sens_type] = {} sensors_dict[sens_type][textkey] = float(line[1]) else: current_sensor_package = l return sensors_dict class LMSensorsPlugin(agent_util.Plugin): textkey = "lm_sensors" label = "Hardware Sensors" @classmethod def get_metadata(self, config): status = agent_util.SUPPORTED msg = None if not agent_util.which("sensors", exc=False): self.log.info("lm_sensors binary not found") status = agent_util.UNSUPPORTED msg = "lm_sensors binary not found" return {} sensors = build_sensor_dict() self.log.debug("Found sensor data:\n%s" % sensors) data = {} if "temperature" in sensors.keys(): temp_options = sorted(sensors["temperature"].keys()) data["temperature"] = { "label": "Sensor temperature", "options": temp_options, "status": status, "error_message": msg, "unit": "Celsius", } if "fan_speed" in sensors.keys(): fan_options = sorted(sensors["fan_speed"].keys()) data["fan_speed"] = { "label": "Fan speed", "options": fan_options, "status": status, "error_message": msg, "unit": "RPM", } return data def check(self, textkey, option, config): sensors = build_sensor_dict() value = sensors.get(textkey, {}).get(option) if value == None: return None return float(value)