Beispiel #1
0
def check_feature(chip, feature):
    sfs = list(sensors.SubFeatureIterator(chip, feature)) # get a list of all subfeatures

    label = sensors.get_label(chip, feature)

    skipname = len(feature.name)+1 # skip common prefix

    # vals is a list of value min and max
    vals = [sensors.get_value(chip, sf.number) for sf in sfs]

    if feature.type == sensors.feature.INTRUSION:
        # short path for INTRUSION to demonstrate type usage
        status = "alarm" if int(vals[0]) == 1 else "normal"
        print("\t"+label+"\t"+status)

    names = [sf.name[skipname:].decode("utf-8") for sf in sfs]
    data = list(zip(names, vals))

    str_data = ", ".join([e[0]+": "+str(e[1]) for e in data])

    if vals[2] > value_max[label]:
        print("\tCheck "+src[label]+"\tFAILED! "+str(vals[2])+" > "+str(value_max[label])+")")
        return False

    if vals[1] < value_min[label]:
        print("\tCheck "+src[label]+"\tFAILED! "+str(vals[1])+" < "+str(value_min[label])+")")
        return False

    print("\tCheck "+src[label]+"\t"+"\t("+str(vals[0])+") ....OK")
    return True
Beispiel #2
0
def process_temp():
    print("-" * 50)
    sensors.init()
    critical = False
    try:
        for chip in sensors.ChipIterator():
            for feature in sensors.FeatureIterator(chip):
                subs = list(sensors.SubFeatureIterator(chip, feature))
                critical = None
                current = None
                for sub in subs:
                    value = sensors.get_value(chip, sub.number)
                    if sub.name.endswith(b"input"):
                        current = value
                    if sub.name.endswith(b"crit"):
                        critical_value = value
                name = sensors.get_label(chip, feature)
                print("Current temp for {}: {} / {}".format(name, current,
                                                            critical_value))
                if current >= critical_value:
                    critical = True
        if critical:
            play_critical()
    finally:
        sensors.cleanup()
def print_feature(chip, feature):
    sfs = list(sensors.SubFeatureIterator(chip, feature)) # get a list of all subfeatures

    label = sensors.get_label(chip, feature)

    skipname = len(feature.name)+1 # skip common prefix
    vals = [sensors.get_value(chip, sf.number) for sf in sfs]

    if feature.type == sensors.feature.INTRUSION:
        # short path for INTRUSION to demonstrate type usage
        status = "alarm" if int(vals[0]) == 1 else "normal"
        print("\t"+label+"\t"+status)
        return

    names = [sf.name[skipname:].decode("utf-8") for sf in sfs]
    data = list(zip(names, vals))

    str_data = ", ".join([e[0]+": "+str(e[1]) for e in data])
    print("\t"+label+"\t"+str_data)
Beispiel #4
0
def print_feature(chip, feature):
    sfs = list(sensors.SubFeatureIterator(chip, feature))  # get a list of all subfeatures

    label = sensors.get_label(chip, feature)

    skip_name = len(feature.name) + 1  # skip common prefix
    values = [sensors.get_value(chip, sf.number) for sf in sfs]

    if feature.type == sensors.Feature.INTRUSION:
        # short path for INTRUSION to demonstrate type usage
        status = "alarm" if int(values[0]) == 1 else "normal"
        print("\t" + label + "\t" + status)
        return

    names = [sf.name[skip_name:].decode("utf-8") for sf in sfs]
    data = list(zip(names, values))

    str_data = ", ".join([e[0] + ": " + str(e[1]) for e in data])
    print("\t" + label + "\t" + str_data)
Beispiel #5
0
def coretemp():
    rv = {}
    for chip in sensors.ChipIterator():
        chipname = sensors.chip_snprintf_name(chip)
        if "temp" not in chipname:
            continue

        chipdata = {}
        for feature in sensors.FeatureIterator(chip):
            label = sensors.get_label(chip, feature)

            sfs = list(sensors.SubFeatureIterator(chip, feature)) # get a list of all subfeatures
            vals = [sensors.get_value(chip, sf.number) for sf in sfs]
            names = [sf.name[len(feature.name)+1:].decode("utf-8") for sf in sfs]

            data = dict(zip(names, vals))
            # We use the label instead of the name because the name is typically unhelpful.
            chipdata[sanitizeName(label)] = data["input"]
        
        rv[chipname] = chipdata
    
    return rv