Пример #1
0
def extractDescriptors(data, lineNumber, offset):
    output = {}
    ln = lineNumber
    descOffset = 0
    while ln < len(data):
        line = data[ln]
        searchDesc = re.search(r'^(\s*)(.*)Descriptors?:\s*$', line,
                               re.IGNORECASE)
        searchStatus = re.search(r'^(\s*)(.*Status)?:\s*(.*)$', line,
                                 re.IGNORECASE)
        searchKeyValue = re.search(r'^\s*(\S+)\s+([0-9].*)$', line)
        searchOffset = re.search(r'^(\s*)', line)
        if searchOffset:
            lineOffset = len(searchOffset.group(1))

        if lineOffset < offset:
            ln -= 1
            break

        if searchDesc:
            descOffset = len(searchDesc.group(1)) + 2
            desc, ln = extractDescriptors(data, ln + 1, descOffset)
            name = camelCase(searchDesc.group(2).strip())
            output[name] = desc

        elif searchStatus:
            statusOffset = len(searchStatus.group(1)) + 2
            desc, ln = extractDescriptors(data, ln + 1, statusOffset)
            name = camelCase(searchStatus.group(2).strip())
            if searchStatus.group(3).strip() != '':
                desc['value'] = searchStatus.group(3).strip()
            output[name] = desc

        elif searchKeyValue:
            key = searchKeyValue.group(1).strip(':')
            value = searchKeyValue.group(2).strip()
            valueSplit = re.search(r'^(\S+)\s+(\S.*)$', value)
            if valueSplit:
                value = [valueSplit.group(1), valueSplit.group(2)]
            if key in output:
                output[key] = [output[key], value]
            else:
                output[key] = value

        else:
            if not 'data' in output:
                output['data'] = []
            output['data'].append(line.strip())

        ln += 1
    return output, ln
Пример #2
0
def parser_disk(stdout, stderr):
    output = {}
    sectionsNames = []
    sectionsMask = ''
    totalLength = 0
    columnPaths = []
    if stdout:
        for line in stdout.splitlines():
            if re.match(r'disk.*reads', line, re.IGNORECASE):
                topHeader = re.split(r'\s+', line)
                if topHeader:
                    for value in topHeader:
                        sectionsNames.append(value.strip().strip('-').lower())
                        totalLength += len(value) + 1
                        sectionsMask += str(len(value) + 1) + 's'

            elif not sectionsMask:
                continue

            if re.match(r'.*total.*merged.*sectors.*', line):
                lineFix = line + (' ' * (totalLength - len(line)))
                if sys.version_info[0] != 2:
                    lineFix = bytes(lineFix, 'utf-8')

                sectionData = unpack(sectionsMask, lineFix)
                if sectionData:
                    index = 0

                    for sec in sectionData:
                        if PY2:
                            secStrip = sec.strip()
                        else:
                            secStrip = str(sec.strip(), 'utf-8')

                        topColumns = re.split(r'\s+', secStrip)
                        if topColumns:

                            for column in topColumns:
                                if column:
                                    columnPaths.append(
                                        camelCase('%s %s' % (
                                            sectionsNames[index],
                                            column,
                                        )))
                                else:
                                    columnPaths.append(
                                        '%s' % (sectionsNames[index], ))
                        index += 1
            else:
                entry = {}
                columns = re.split(r'\s+', line)
                for ci, cv in enumerate(columns):
                    if ci < len(columnPaths):
                        entry[columnPaths[ci]] = cv
                if 'disk' in entry:
                    output[entry['disk']] = entry

    return {'output': output}
Пример #3
0
def parser(stdout, stderr):
    output = {}
    if stdout:
        for line in stdout.splitlines():
            lineMatch = re.search(r'^([^:]+):\s*(.*)', line)
            if lineMatch:
                output[camelCase(lineMatch.group(1))] = lineMatch.group(2)
    
    return {'output': output}
Пример #4
0
def parser_stats(stdout, stderr):
    output = {}
    if stdout:
        for line in stdout.splitlines():
            entry = re.search(r'^\s*(\d+)\s+(.*)$', line)
            if entry:
                output[camelCase(
                    entry.group(2).strip())] = entry.group(1).strip()

    return {'output': output}
Пример #5
0
def parser(stdout, stderr):
    output = {}
    if stdout:
        for line in stdout.splitlines():
            keyValueSearch = re.search(r'^([^:]+):\s*(.*)$', line,
                                       re.IGNORECASE)
            if keyValueSearch:
                key = keyValueSearch.group(1).strip(':')
                value = keyValueSearch.group(2).strip()

                valueSearch = re.search(r'(.*)\s+(.*)$', value)
                if valueSearch:
                    output[camelCase(key)] = {
                        'value': valueSearch.group(1),
                        'type': valueSearch.group(2)
                    }
                else:
                    output[camelCase(key)] = {'value': value, 'type': ''}

    return {'output': output}
Пример #6
0
def parser(stdout, stderr):
    output = {}
    if stdout:
        for line in stdout.splitlines():
            entry = {}
            kv = re.findall(r'(\S[^=]+)=\"([^"]*)\"', line)
            if kv:
                for pair in kv:
                    entry[camelCase(pair[0])] = pair[1].strip()

            if 'name' in entry:
                output[entry['name']] = entry

    return {'output': output}
Пример #7
0
def parser(stdout, stderr):
    output = {}
    if stdout:
        for block in re.split(r'\r\r|\n\n|\r\n\r\n', stdout):
            sub = {}
            for line in block.splitlines():
                values = re.search(r'([^\t]+)\s*:\s*(.*)$', line)
                if values:
                    sub[camelCase(
                        values.group(1).strip())] = values.group(2).strip()

            if 'name' in sub:
                output[sub['name']] = sub

    return {'output': output}
Пример #8
0
def parser(stdout, stderr):
    output = {}
    slot = None
    if stdout:
        for line in stdout.splitlines():
            slotSearch = re.search(r'^Slot:\s+(.*)$', line, re.IGNORECASE)
            if slotSearch:
                slot = slotSearch.group(1).strip()
                output[slot] = {}

            keyValueSearch = re.search(r'^(\S[^:]+):\s+(.*)$', line)
            if slot and keyValueSearch:
                output[slot][camelCase(keyValueSearch.group(1))] = keyValueSearch.group(2).strip()

    return {'output': output}
Пример #9
0
def parser(stdout, stderr):
    output = {}
    columns = None
    if stdout:
        typeName = ''
        for line in stdout.splitlines():
            if re.search(r'total\s+used', line, re.IGNORECASE):
                columns = re.split(r'\s+', line.strip())

            entrySearch = re.search(r'^([^:]+):\s+(.*)$', line)
            if columns and entrySearch:
                type = camelCase(entrySearch.group(1))
                output[type] = {}
                for idx, value in enumerate(re.split(r'\s+', entrySearch.group(2).strip())):
                    if idx < len(columns):
                        output[type][columns[idx]] = value

    return {'output': output}
Пример #10
0
def parser(stdout, stderr):
    output = {}
    ignoredLines = []
    if stdout:
        device = ''
        for line in stdout.splitlines():
            dev = re.search(r'^>>> Device: (\S+)', line)
            kv = re.search(r'^(\w[^=]+)=(.*)$', line)
            if dev:
                device = dev.group(1)
                output[device] = {}
            elif kv:
                output[device][camelCase(kv.group(1))] = kv.group(2)
            else:
                ignoredLines.append(line)
                pass

    return {'output': output, 'ignored': ignoredLines}
Пример #11
0
def parser(stdout, stderr):
    output = {}
    deviceType = None
    if stdout:
        for line in stdout.splitlines():
            dt = re.search(r'^([^:]+):', line)
            if dt:
                deviceType = camelCase(dt.group(1))
                output[deviceType] = {}

            dv = re.search(r'^\s*(\d+)\s*(.*)$', line)
            if dv and deviceType:
                id = dv.group(1)
                name = dv.group(2)
                if not name in output[deviceType]:
                    output[deviceType][name] = []

                output[deviceType][name].append(id)

    return {'output': output}
Пример #12
0
def parser(stdout, stderr):
    output = {'processor': {}, 'hardware': {}, 'oth': {}}

    if stdout:
        for block in re.split(r'\r\r|\n\n|\r\n\r\n', stdout):
            sub = {}
            for line in block.splitlines():
                values = re.search(r'([^\t]+)\s*:\s*(.*)$', line)
                if values:
                    sub[camelCase(
                        values.group(1).strip())] = values.group(2).strip()

            if 'processor' in sub:
                output['processor'][sub['processor']] = sub

            elif 'hardware' in sub:
                output['hardware'] = sub

            else:
                output['oth'] = sub

    return {'output': output}
Пример #13
0
def parser(stdout, stderr):
    dmiSections = {
        '0': 'BIOS',
        '1': 'System',
        '2': 'Base Board',
        '3': 'Chassis',
        '4': 'Processor',
        '5': 'Memory Controller',
        '6': 'Memory Module',
        '7': 'Cache',
        '8': 'Port Connector',
        '9': 'System Slots',
        '10': 'On Board Devices',
        '11': 'OEM Strings',
        '12': 'System Configuration Options',
        '13': 'BIOS Language',
        '14': 'Group Associations',
        '15': 'System Event Log',
        '16': 'Physical Memory Array',
        '17': 'Memory Device',
        '18': '32-bit Memory Error',
        '19': 'Memory Array Mapped Address',
        '20': 'Memory Device Mapped Address',
        '21': 'Built-in Pointing Device',
        '22': 'Portable Battery',
        '23': 'System Reset',
        '24': 'Hardware Security',
        '25': 'System Power Controls',
        '26': 'Voltage Probe',
        '27': 'Cooling Device',
        '28': 'Temperature Probe',
        '29': 'Electrical Current Probe',
        '30': 'Out-of-band Remote Access',
        '31': 'Boot Integrity Services',
        '32': 'System Boot',
        '33': '64-bit Memory Error',
        '34': 'Management Device',
        '35': 'Management Device Component',
        '36': 'Management Device Threshold Data',
        '37': 'Memory Channel',
        '38': 'IPMI Device',
        '39': 'Power Supply'
    }
    section = None
    output = {}

    if stdout:
        for line in stdout.splitlines():
            if line.strip() == '':
                section = None

            handleSearch = re.search(
                r'^Handle\s+([^,]+),\s+DMI type\s+([^,]+),', line,
                re.IGNORECASE)
            if handleSearch:
                handle = handleSearch.group(1)
                dmiType = handleSearch.group(2)
                if dmiType in dmiSections:
                    section = camelCase(dmiSections[dmiType])
                    output[section] = {
                        '__handle': handle,
                        '__dmiType': dmiType
                    }

            entry = re.search(r'^\s+([^:]+):\s+(.*)$', line)
            if section and entry:
                output[section][camelCase(
                    entry.group(1))] = entry.group(2).strip()

    return {'output': output}
Пример #14
0
def parser(stdout, stderr):
    output = {'devices': {}, 'parents': {}}
    types = {
        'P': 'path',
        'N': 'node',
        'L': 'linkPriority',
        'E': 'entry',
        'S': 'link'
    }
    device = None
    parent = None
    if stdout:
        for line in stdout.splitlines():
            deviceSearch = re.search(r'^>>> Device: (\S+)', line)
            if deviceSearch:
                device = deviceSearch.group(1)
                output['devices'][device] = {
                    'parents': [],
                    'entry': {},
                    'link': []
                }
                parent = None

            if not device:
                continue

            keyValue = re.search(r'^(\S):\s+(.*)$', line)
            if keyValue:
                key = keyValue.group(1)
                value = keyValue.group(2).strip()
                if key in types:
                    key = types[key]

                if key == 'entry':
                    valueSearch = re.search(r'^([^=]+)=(.*)$', value)
                    if valueSearch:
                        subkey = valueSearch.group(1).lower()
                        subvalue = valueSearch.group(2).strip()
                        output['devices'][device]['entry'][subkey] = subvalue

                elif key == 'link':
                    output['devices'][device]['link'].append(value)

                else:
                    output['devices'][device][key] = value

            deviceLook = re.search(r'^\s+looking at device \'([^\']+)', line)
            if deviceLook:
                parent = deviceLook.group(1)
                if not parent in output['parents']:
                    output['parents'][parent] = {}
                output['devices'][device]['parents'].append(parent)

            parentDeviceLook = re.search(r'^\s+looking at device \'([^\']+)',
                                         line)
            if parentDeviceLook:
                parent = parentDeviceLook.group(1)
                if not parent in output['parents']:
                    output['parents'][parent] = {}
                output['devices'][device]['parents'].append(parent)

            if parent:
                parentKeyValue = re.search(r'^\s+([^=]+)=="([^"]+)"', line)
                if parentKeyValue:
                    key = parentKeyValue.group(1).lower()
                    value = parentKeyValue.group(2)

                    multipleValues = re.match(r'^(\s+\d+)+$', value)
                    if multipleValues:
                        value = re.split(r'\s+', value.strip())

                    keyAttr = re.match(r'^(\S+){([^}]+)}', key, re.IGNORECASE)
                    if keyAttr:
                        attrType = keyAttr.group(1).lower()
                        if not attrType in output['parents'][parent]:
                            output['parents'][parent][attrType] = {}

                        attrKey = camelCase(keyAttr.group(2))
                        output['parents'][parent][attrType][attrKey] = value

                    else:
                        output['parents'][parent][key] = value

    return {'output': output}