def convert_oid_value(type_, value):
    if type_ == 'Counter32':
        return v2c.Counter32(tryIntConvert(value[0]))

    elif type_ == 'Counter64':
        return rfc1902.Counter64(long(value[0]))

    elif type_ == 'Gauge32':
        return v2c.Gauge32(tryIntConvert(value[0]))

    elif type_ == 'Hex-STRING':
        value = [sanitize_dotted(x) for x in value]
        res = ''.join([chr(int(c, 16)) for c in ' '.join(value).split(' ')])
        return res

    elif type_ == 'INTEGER':
        return tryIntConvert(value[0])

    elif type_ == 'IpAddress':
        value[0] = sanitize_dotted(value[0])
        return v2c.IpAddress(value[0])

    elif type_ == 'OID':
        return v2c.ObjectIdentifier(value[0])

    elif type_ == 'STRING':
        return encode_mac('\n'.join(value))

    elif type_ == 'Timeticks':
        return v2c.TimeTicks(int(value[0]))
Example #2
0
    def add_oid_value(self, oid, type_, value):
        if type_ == 'Counter32':
            self.oids[oid] = v2c.Counter32(self.tryIntConvert(value[0]))

        elif type_ == 'Counter64':
            self.oids[oid] = rfc1902.Counter64(long(value[0]))

        elif type_ == 'Gauge32':
            self.oids[oid] = v2c.Gauge32(self.tryIntConvert(value[0]))

        elif type_ == 'Hex-STRING':
            value = [sanitize_dotted(x) for x in value]
            self.oids[oid] = ''.join(
                [chr(int(c, 16)) for c in ' '.join(value).split(' ')])

        elif type_ == 'INTEGER':
            self.oids[oid] = self.tryIntConvert(value[0])

        elif type_ == 'IpAddress':
            value[0] = sanitize_dotted(value[0])
            self.oids[oid] = v2c.IpAddress(value[0])

        elif type_ == 'OID':
            self.oids[oid] = v2c.ObjectIdentifier(value[0])

        elif type_ == 'STRING':
            self.oids[oid] = '\n'.join(value)

        elif type_ == 'Timeticks':
            self.oids[oid] = v2c.TimeTicks(int(value[0]))
Example #3
0
    def get_oids(self):
        oids = {}

        system = '.1.3.6.1.2.1.1'
        ifTable = '.1.3.6.1.2.1.2.2.1'
        ipAddrTable = '.1.3.6.1.2.1.4.20.1'
        dot1dTpFdbTable = '.1.3.6.1.2.1.17.4.3.1'
        dot1dBasePortEntry = '.1.3.6.1.2.1.17.1.4.1'

        oids[system + '.1.0'] = '%s simulated' % self.name  # sysDescr
        # sysObjectID
        oids[system + '.2.0'] = v2c.ObjectIdentifier('.1.3.6.1.4.1.9.1.516')
        oids[system + '.4.0'] = "*****@*****.**"  # sysContact
        oids[system + '.5.0'] = self.name  # sysName
        oids[system + '.6.0'] = "Somewhere"  # sysLocation

        for index, interface in enumerate(self.interfaces, 1):
            oids[ifTable + '.1.%s' % index] = index  # ifindex
            oids[ifTable + '.2.%s' % index] = 'interface%s' % index  # id
            oids[ifTable + '.3.%s' % index] = 6  # type = ethernetCsmacd
            oids[ifTable + '.4.%s' % index] = 1500  # mtu
            oids[ifTable + '.5.%s' % index] = v2c.Gauge32(1000 ** 3)  # mtu
            oids[ifTable + '.6.%s' % index] = interface['mac']  # MAC
            oids[ifTable + '.7.%s' % index] = 1  # adminStatus = up
            oids[ifTable + '.8.%s' % index] = 1  # operStatus = up

            ip = asip(int2id(index, 4))
            oids[ipAddrTable + '.1.%s' % ip] = v2c.IpAddress(ip)
            oids[ipAddrTable + '.2.%s' % ip] = index
            oids[ipAddrTable + '.3.%s' % ip] = v2c.IpAddress(self.netmask)

            for clientmac in interface['clientmacs']:
                oids[dot1dTpFdbTable + '.1.%s' % asoid(clientmac)] = clientmac
                # dot1dTpFdbPort
                oids[dot1dTpFdbTable + '.2.%s' % asoid(clientmac)] = index
                # dot1dTpFdbStatus = learned
                oids[dot1dTpFdbTable + '.3.%s' % asoid(clientmac)] = 3

            # binds port number and interface index
            oids[dot1dBasePortEntry + '.1.%s' % index] = index  # port number
            oids[dot1dBasePortEntry + '.2.%s' % index] = index  # ifindex

        return oids