def pack(self): if self._value >= (1 << 64): raise OverflowError("too large to be packed") if self._value >= (1 << 32): return rfc1902.Counter64(self._value) if self._value >= 0: return rfc1902.Integer(self._value) if self._value >= -(1 << 31): return rfc1902.Integer(self._value) raise OverflowError("too small to be packed")
def set_d_b_unsigned(entry, value): error_indication, error_status, error_index, var_binds = cmdGen.setCmd( cmdgen.CommunityData('federated'), cmdgen.UdpTransportTarget(('34.215.95.184', 161)), (entry, rfc1902.Counter64(value)), ) # Check for errors and print out results if error_indication: log.error(error_indication) else: if error_status: log.debug('%s at %s' % (error_status.prettyPrint(), error_index and var_binds[int(error_index) - 1] or '?')) else: for name, val in var_binds: log.debug('%s = %s' % (name.prettyPrint(), val.prettyPrint()))
def _to_pysnmp(self, value): """ Convert connection plugin object into pysnmp objects """ if value is None: return None if isinstance(value, OctetString): return rfc1902.OctetString(str(value.value)) if isinstance(value, ObjectIdentifier): return rfc1902.ObjectName(str(value.value)) if isinstance(value, Integer32): return rfc1902.Integer32(int(value.value)) if isinstance(value, Counter32): return rfc1902.Counter32(long(value.value)) if isinstance(value, IpAddress): return rfc1902.IpAddress(str(value.value)) if isinstance(value, Gauge32): return rfc1902.Gauge32(long(value.value)) if isinstance(value, TimeTicks): return rfc1902.TimeTicks(long(value.value)) if isinstance(value, Opaque): return rfc1902.Opaque(value.value) # FIXME if isinstance(value, Counter64): return rfc1902.Counter64(str(value.value)) raise SnmpError('Invalid type: %s' % value.__class__.__name__)
def pack(self): if self._value >= (1 << 64): raise OverflowError("too large to be packed") if self._value < 0: raise OverflowError("too small to be packed") return rfc1902.Counter64(self._value)
def convert_to_counter64(self, value): """Converts a value to a SNMP Counter64 object.""" return rfc1902.Counter64(value)
def counter64(self, value): return rfc1902.Counter64(value)
expect(snmp_value.value()).to(equal(5)) expect(snmp_value.type_text()).to(equal('Integer')) with context('when type is Integer32'): with it('checks value and type'): snmp_data = rfc1902.Integer32(5) snmp_value = PySnmpValue(snmp_data) expect(snmp_value.value()).to(equal(5)) expect(snmp_value.type_text()).to(equal('Integer32')) with context('when type is Counter64'): with it('checks value and type'): snmp_data = rfc1902.Counter64(42) snmp_value = PySnmpValue(snmp_data) expect(snmp_value.value()).to(equal(42)) expect(snmp_value.type_text()).to(equal('Counter64')) with context('when type is OctetString'): with it('checks value and type'): snmp_data = rfc1902.OctetString(b'HG8110') snmp_value = PySnmpValue(snmp_data) expect(snmp_value.value()).to(equal(b'HG8110')) expect(snmp_value.type_text()).to(equal('OctetString'))