示例#1
0
def getVoltages(pOut_):
    sender = []
    json = []

    for block in pOut_:
        if 'Adapter: PCI adapter' in block:  # we dont need GPU voltages
            continue

        voltagesRe = re.findall(r'(.+):\n(?:\s+)?in(\d+)_input:\s+(\d+\.\d+)',
                                block, re.I)
        if voltagesRe:
            for name, num, val in voltagesRe:

                for regexp, key, jsn in VOLTAGE_REGEXPS_KEYS_AND_JSONS:
                    if re.search(regexp, name, re.I):
                        sender.append('"%s" mini.brd.vlt[%s] "%s"' %
                                      (HOST, key, removeQuotes(val)))
                        json.append({jsn: key})

                sender.append('"%s" mini.brd.vlt[%s] "%s"' %
                              (HOST, num, removeQuotes(val))
                              )  # static items for graph, could be duplicate

            break  # as safe as possible

    return sender, json
def findValues(p):
    sender = []

    for key, regexp in keysandRegexp:
        reVal = re.search(regexp, p, re.I | re.M)

        if reVal:
            val = reVal.group(1).strip()
            val = removeQuotes(val)

            if key == 'hw.bios.BiosCharacteristics':
                val = val.replace('{', '').replace('}', '')
                valTemp = ''

                charList = val.split(',')
                for i in charList:
                    for j in biosCharacteristics:
                        if i == j[0]:
                            valTemp = '%s %s%s' % (valTemp, j[1], r'\n')

                val = valTemp

            if key == 'hw.bios.SoftwareElementState':
                for i in softwareElementState:
                    if i[0] == val:
                        val = i[1]

            if key == 'hw.bios.TargetOperatingSystem':
                for i in targetOS:
                    if i[0] == val:
                        val = i[1]

            sender.append('"%s" %s "%s"' % (host, key, val))

    return sender
def getCpusData(pOut_):

    sender = []
    json = []

    # determine available CPUs
    cpusRe = re.findall(r'\+\-\s+(.+)\s+\(\/[\w-]+cpu\/(\d+)\)', pOut_, re.I)
    cpus = set(cpusRe)
    #print(cpusRe)

    allTemps = []
    for name, id in cpus:
        # Processor model
        sender.append('"%s" mini.cpu.info[cpu%s,ID] "%s"' %
                      (HOST, id, removeQuotes(name.strip())))
        json.append({'{#CPU}': id})

        gotTjmax = getTjmax(pOut_, id, name)
        if gotTjmax:
            sender.append('"%s" mini.cpu.info[cpu%s,TjMax] "%s"' %
                          (HOST, id, gotTjmax))

        # All core temperatures for given CPU
        coreTempsRe = re.findall(
            r'Core.+:\s+(\d+).+\(\/[\w-]+cpu\/%s\/temperature\/(\d+)\)' % id,
            pOut_, re.I)
        if coreTempsRe:
            sender.append('"%s" mini.cpu.info[cpu%s,CPUstatus] "PROCESSED"' %
                          (HOST, id))
            cpuTemps = []
            for coretemp, coreid in coreTempsRe:
                cpuTemps.append(int(coretemp))
                allTemps.append(int(coretemp))
                sender.append('"%s" mini.cpu.temp[cpu%s,core%s] "%s"' %
                              (HOST, id, coreid, coretemp))
                json.append({'{#CPUC}': id, '{#CORE}': coreid})

            sender.append('"%s" mini.cpu.temp[cpu%s,MAX] "%s"' %
                          (HOST, id, str(max(cpuTemps))))

        elif isCpuWithoutSensor(name):
            sender.append('"%s" mini.cpu.info[cpu%s,CPUstatus] "NO_SENSOR"' %
                          (HOST, id))
        else:
            sender.append('"%s" mini.cpu.info[cpu%s,CPUstatus] "NO_TEMP"' %
                          (HOST, id))

    if cpus:
        if allTemps:
            error = None
            sender.append('"%s" mini.cpu.temp[MAX] "%s"' %
                          (HOST, str(max(allTemps))))
        else:
            error = 'NOCPUTEMPS'
    else:
        error = 'NOCPUS'

    return sender, json, error
示例#4
0
def getCpuData(pOut_):
    '''Note: certain cores can pose as different blocks making them separate cpus in zabbix.'''
    sender = []
    json = []

    cpuBlocks = -1  # first cpu will be '0'
    allTemps = []
    for block in pOut_:
        regexp = chooseCpuRegexp(block)

        coreTempsRe = re.findall(regexp, block, re.I | re.M)

        if (coreTempsRe and regexp):

            cpuBlocks += 1  # you need to be creative to parse lmsensors

            json.append({'{#CPU}': cpuBlocks})
            sender.append(
                '"%s" mini.cpu.info[cpu%s,ID] "%s"' %
                (HOST, cpuBlocks, removeQuotes(block.splitlines()[0])))

            tempCrit = re.search(r'_crit:\s+(\d+)\.\d+', block, re.I)
            if tempCrit:
                tjMax = tempCrit.group(1)
            else:
                tjMax = FALLBACK_TJMAX

            sender.append('"%s" mini.cpu.info[cpu%s,TjMax] "%s"' %
                          (HOST, cpuBlocks, tjMax))

            cpuTemps = []
            previousCore = None
            for num, val in coreTempsRe:
                if previousCore == num:
                    continue  # some cores have same number - ignore them
                previousCore = num

                cpuTemps.append(int(val))
                allTemps.append(int(val))
                sender.append('"%s" mini.cpu.temp[cpu%s,core%s] "%s"' %
                              (HOST, cpuBlocks, num, val))
                json.append({'{#CPUC}': cpuBlocks, '{#CORE}': num})

            sender.append('"%s" mini.cpu.temp[cpu%s,MAX] "%s"' %
                          (HOST, cpuBlocks, max(cpuTemps)))

    if cpuBlocks != -1:
        if allTemps:
            error = None
            sender.append('"%s" mini.cpu.temp[MAX] "%s"' %
                          (HOST, max(allTemps)))
        else:
            error = 'NOCPUTEMPS'
    else:
        error = 'NOCPUS'

    return sender, json, error
def getBoardInfo(pOut_):

    sender = []

    for regexp, key in BOARD_REGEXPS_AND_KEYS:
        reMatch = re.search(regexp, pOut_, re.I | re.M)
        if reMatch:
            sender.append('"%s" %s "%s"' %
                          (HOST, key, removeQuotes(reMatch.group(1).strip())))

    return sender
def getOHMRversion(pOut_):

    OHMRver = re.search(r'^Version:\s+(.+)$', pOut_, re.I | re.M)
    if OHMRver:
        version = OHMRver.group(1).strip()
    else:
        version = None

    sender = [
        '"%s" mini.info[OHMRversion] "%s"' % (HOST, removeQuotes(version))
    ]

    return sender
def getVoltages(pOut_):

    sender = []
    json = []

    voltagesRe = re.findall(
        r'\+\-\s+(.+)\s+:\s+(\d+\.\d+|\d+)\s+.+\(\/lpc\/[\w-]+\/voltage\/(\d+)\)',
        pOut_, re.I)
    for name, val, id in voltagesRe:
        name = name.strip()

        for regexp, key, jsn in VOLTAGE_REGEXPS_KEYS_AND_JSONS:
            if re.search(regexp, name, re.I):
                sender.append('"%s" mini.brd.vlt[%s] "%s"' %
                              (HOST, key, removeQuotes(val)))
                json.append({jsn: key})

        sender.append(
            '"%s" mini.brd.vlt[%s] "%s"' %
            (HOST, id,
             removeQuotes(val)))  # static items for graph, could be duplicate

    return sender, json
def findValuesInWMI(ID_, block_):
    sender = []
    
    if isIgnoredService(block_):
        return sender

    for key, regexp in keysAndRegexps:

        reVal = re.search(regexp, block_, re.I | re.M)
        
        
        if reVal:
            
            val = reVal.group(1).strip()
            val = removeQuotes(val)

            sender.append('"%s" %s[%s] "%s"' % (host, key, ID_, val))

    return sender
def findValues(slotNum, bank):
    sender = []

    for key, regexp in keysAndRegexps:
        reVal = re.search(regexp, bank, re.M | re.I)

        if reVal:
            val = reVal.group(1).strip()
            val = removeQuotes(val)

            # Additional check if acquired ID have an explanation
            for subKey, idValSubList in subKeysAndParameters:
                if key == subKey:
                    for id, actualVal in idValSubList:
                        if id == val:
                            val = actualVal

            sender.append('"%s" %s[slot%s] "%s"' % (host, key, slotNum, val))

    return sender
def findValues(cpuNum, cpu_out):
    sender = []
    
    for key, regexp in keysandRegexp:
        reVal = re.search(regexp, cpu_out, re.I | re.M)
        
        if reVal:
        
            val = reVal.group(1).strip()
            val = removeQuotes(val)

            for p_key, parameter in keysandParameters:
                if key == p_key:
                    for i in parameter:
                        if i[0] == val:
                            val = i[1]

            sender.append('"%s" %s[cpu%s] "%s"' %(host, key, cpuNum, val))

    return sender
示例#11
0
def getGpuData(pOut_):

    sender = []
    json = []

    gpuBlocks = -1
    allTemps = []
    for i in pOut_:
        temp = re.search(
            r'(nouveau.+|nvidia.+)\n.+\n.+\n(?:\s+)?temp\d+_input:\s+(\d+)', i,
            re.I)
        if temp:
            gpuid = temp.group(1)
            val = temp.group(2)

            gpuBlocks += 1
            allTemps.append(int(val))

            json.append({'{#GPU}': gpuBlocks})
            sender.append('"%s" mini.gpu.info[gpu%s,ID] "%s"' %
                          (HOST, gpuBlocks, removeQuotes(gpuid)))

            json.append({'{#GPUTEMP}': gpuBlocks})
            sender.append('"%s" mini.gpu.temp[gpu%s] "%s"' %
                          (HOST, gpuBlocks, val))

    if gpuBlocks != -1:
        if allTemps:
            error = None
            sender.append('"%s" mini.gpu.temp[MAX] "%s"' %
                          (HOST, max(allTemps)))
        else:
            error = 'NOGPUTEMPS'  # unreachable
    else:
        error = 'NOGPUS'

    return sender, json, error