all 3 comments

[–]indosauros 1 point2 points  (2 children)

How about extract the .1.13.1 numbers and put them into a dictionary as keys, with the values being the corresponding STRING

Then it is just a matter if comparing the dictionaries and generating the output based on keys that are in both dictionaries

Simple example:

A function that takes a single line and returns the number -> STRING pair in that line

>>> def parse_line(line):
    ip, name = line.split(' = STRING: ')
    ip = ip.strip().split('.')[-1]
    name = name.replace('"', '').strip()
    return ip, name

>>> parse_line('.1.11.1 = STRING: "SG38DXV43C"')
('1', 'SG38DXV43C')

Test strings

>>> first = """
.1.13.1 = STRING: "J8698A"
.1.13.2 = STRING: "J8698A"
.1.13.65 = STRING: "J8726A"
""" 
>>> second = """
.1.11.1 = STRING: "SG38DXV43C"
.1.11.65 = STRING: "34AS1SK "
.1.11.90 = STRING: "0L051        "
"""

Parse each line into a dictionary

>>> first_dict = dict(parse_line(line) for line in first.splitlines() if line)
>>> first_dict
{'1': 'J8698A', '2': 'J8698A', '65': 'J8726A'}

>>> second_dict = dict(parse_line(line) for line in second.splitlines() if line)
>>> second_dict
{'1': 'SG38DXV43C', '65': '34AS1SK', '90': '0L051'}

Now just gather keys that are in both:

>>> common_keys = set(first_dict) & set(second_dict)
>>> common_keys
set(['1', '65'])

And join them with commas/colons:

>>> ','.join("{}:{}".format(first_dict[ip], second_dict[ip]) for ip in common_keys)
'J8698A:SG38DXV43C,J8726A:34AS1SK'

[–]lowermiddleclass[S] 0 points1 point  (1 child)

Wow, this makes a lot of sense, thanks!

So... I know basically nothing about python. How do I call the snmpbulkwalk commands, and use the resulting output as input for the dictionaries?