Exemplo n.º 1
0
    def checkslot(self, ret):
        u"""get slot present status"""
        slots_conf = MONITOR_DEV_STATUS.get("slots", None)
        slotpresent = MONITOR_DEV_STATUS_DECODE.get("slotpresent", None)

        if slots_conf is None or slotpresent is None:
            return False
        for item_slot in slots_conf:
            totalerr = 0
            try:
                ret_t = {}
                ret_t["id"] = item_slot.get("name")
                ret_t["status"] = ""
                gettype = item_slot.get("gettype")
                presentbit = item_slot.get("presentbit")
                if gettype == "io":
                    io_addr = item_slot.get("io_addr")
                    val = io_rd(io_addr)
                    if val is not None:
                        retval = val
                    else:
                        totalerr -= 1
                        logger.error(
                            " %s  %s" %
                            (item_slot.get("name"), "lpc read failed"), )
                else:
                    bus = item_slot.get("bus")
                    loc = item_slot.get("loc")
                    offset = item_slot.get("offset")
                    ind, val = rgi2cget(bus, loc, offset)
                    if ind == True:
                        retval = val
                    else:
                        totalerr -= 1
                        logger.error(
                            " %s  %s" %
                            (item_slot.get("name"), "i2c read failed"), )
                if totalerr < 0:
                    ret_t["status"] = "NOT OK"
                    ret.append(ret_t)
                    continue
                val_t = (int(retval, 16) & (1 << presentbit)) >> presentbit
                logger.debug(
                    DEBUG_COMMON,
                    "%s present:%s" %
                    (item_slot.get("name"), slotpresent.get(val_t)),
                )
                if val_t != slotpresent.get("okval"):
                    ret_t["status"] = "ABSENT"
                else:
                    ret_t["status"] = "PRESENT"
            except Exception as e:
                ret_t["status"] = "NOT OK"
                totalerr -= 1
                logger.error("checkslot error")
                logger.error(str(e))
            ret.append(ret_t)
        return True
Exemplo n.º 2
0
 def setled(self, item, color):
     if item.get("type", "i2c") == "sysfs":
         rgsysset(item["cmdstr"], item.get(color))
     else:
         mask = item.get("mask", 0xFF)
         ind, val = rgi2cget(item["bus"], item["devno"], item["addr"])
         if ind == True:
             setval = (int(val, 16) & ~mask) | item.get(color)
             rgi2cset(item["bus"], item["devno"], item["addr"], setval)
         else:
             logger.error("led %s" % "i2c read failed")
Exemplo n.º 3
0
    def checkfan(self, ret):
        u"""get fan status present and roll"""
        fans_conf = MONITOR_DEV_STATUS.get("fans", None)
        fanpresent = MONITOR_DEV_STATUS_DECODE.get("fanpresent", None)
        fanroll = MONITOR_DEV_STATUS_DECODE.get("fanroll", None)

        if fans_conf is None or fanpresent is None or fanroll is None:
            logger.error("checkfan: config error")
            return False
        for item_fan in fans_conf:
            totalerr = 0
            try:
                ret_t = {}
                ret_t["id"] = item_fan.get("name")
                ret_t["status"] = ""
                presentstatus = item_fan.get("presentstatus")
                presentbus = presentstatus.get("bus")
                presentloc = presentstatus.get("loc")
                presentaddr = presentstatus.get("offset")
                presentbit = presentstatus.get("bit")
                ind, val = rgi2cget(presentbus, presentloc, presentaddr)
                if ind == True:
                    val_t = (int(val, 16) & (1 << presentbit)) >> presentbit
                    logger.debug(
                        DEBUG_COMMON,
                        "checkfan:%s present status:%s" %
                        (item_fan.get("name"), fanpresent.get(val_t)),
                    )
                    if val_t != fanpresent.get("okval"):
                        ret_t["status"] = "ABSENT"
                        ret.append(ret_t)
                        continue
                else:
                    logger.error(
                        "checkfan: %s get present status error." %
                        item_fan.get("name"), )
                motors = item_fan.get("rollstatus")
                for motor in motors:
                    statusbus = motor.get("bus", None)
                    statusloc = motor.get("loc", None)
                    statusaddr = motor.get("offset", None)
                    statusbit = motor.get("bit", None)
                    ind, val = rgi2cget(statusbus, statusloc, statusaddr)
                    if ind == True:
                        val_t = (int(val, 16) & (1 << statusbit)) >> statusbit
                        logger.debug(
                            DEBUG_COMMON,
                            "checkfan:%s roll status:%s" %
                            (motor.get("name"), fanroll.get(val_t)),
                        )
                        if val_t != fanroll.get("okval"):
                            totalerr -= 1
                    else:
                        totalerr -= 1
                        logger.error("checkfan: %s " % item_fan.get("name"))
                        logger.error("get %s status error." % motor["name"])
            except Exception as e:
                totalerr -= 1
                logger.error("checkfan error")
                logger.error(str(e))
            if totalerr < 0:
                ret_t["status"] = "NOT OK"
            else:
                ret_t["status"] = "OK"
            ret.append(ret_t)
        return True
Exemplo n.º 4
0
    def checkpsu(self, ret):
        u"""get  psu status present, output and warning"""
        psus_conf = MONITOR_DEV_STATUS.get("psus", None)
        psupresent = MONITOR_DEV_STATUS_DECODE.get("psupresent", None)
        psuoutput = MONITOR_DEV_STATUS_DECODE.get("psuoutput", None)
        psualert = MONITOR_DEV_STATUS_DECODE.get("psualert", None)

        if psus_conf is None or psupresent is None or psuoutput is None:
            logger.error("checkpsu: config error")
            return False
        for item_psu in psus_conf:
            totalerr = 0
            try:
                ret_t = {}
                ret_t["id"] = item_psu.get("name")
                ret_t["status"] = ""
                gettype = item_psu.get("gettype")
                presentbit = item_psu.get("presentbit")
                statusbit = item_psu.get("statusbit")
                alertbit = item_psu.get("alertbit")
                if gettype == "io":
                    io_addr = item_psu.get("io_addr")
                    val = io_rd(io_addr)
                    if val is not None:
                        retval = val
                    else:
                        totalerr -= 1
                        logger.error(
                            " %s  %s" %
                            (item_psu.get("name"), "lpc read failed"), )
                else:
                    bus = item_psu.get("bus")
                    loc = item_psu.get("loc")
                    offset = item_psu.get("offset")
                    ind, val = rgi2cget(bus, loc, offset)
                    if ind == True:
                        retval = val
                    else:
                        totalerr -= 1
                        logger.error(
                            " %s  %s" %
                            (item_psu.get("name"), "i2c read failed"), )
                if totalerr < 0:
                    ret_t["status"] = "NOT OK"
                    ret.append(ret_t)
                    continue
                val_t = (int(retval, 16) & (1 << presentbit)) >> presentbit
                val_status = (int(retval, 16) & (1 << statusbit)) >> statusbit
                val_alert = (int(retval, 16) & (1 << alertbit)) >> alertbit
                logger.debug(
                    DEBUG_COMMON,
                    "%s present:%s output:%s alert:%s" % (
                        item_psu.get("name"),
                        psupresent.get(val_t),
                        psuoutput.get(val_status),
                        psualert.get(val_alert),
                    ),
                )
                if (val_t != psupresent.get("okval")
                        or val_status != psuoutput.get("okval")
                        or val_alert != psualert.get("okval")):
                    totalerr -= 1
            except Exception as e:
                totalerr -= 1
                logger.error("checkpsu error")
                logger.error(str(e))
            if totalerr < 0:
                ret_t["status"] = "NOT OK"
            else:
                ret_t["status"] = "OK"
            ret.append(ret_t)
        return True