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 updateoctets(self, cn, inoctets, outoctets):
     num = int(cn[3:7])
     self.sv('IF-MIB::ifInOctets', num, v2c.Counter32(inoctets))
     self.sv('IF-MIB::ifOutOctets', num, v2c.Counter32(outoctets))