def gmetric_meta(NAME, TYPE, UNITS, SLOPE, TMAX, DMAX, EXTRAS=None): """ Arguments are in all upper-case to match XML """ packer = Packer() packer.pack_int(128) # "gmetadata_full" packer.pack_string('nickg-macbook.local') packer.pack_string(NAME) packer.pack_bool(False) packer.pack_string(TYPE) packer.pack_string(NAME) packer.pack_string(UNITS) packer.pack_int(slope_str2int[SLOPE]) # map slope string to int packer.pack_uint(int(TMAX)) packer.pack_uint(int(DMAX)) if EXTRAS is None: packer.pack_uint(0) else: packer.pack_uint(len(EXTRAS)) for k,v in EXTRAS.iteritems(): packer.pack_string(k) packer.pack_string(v) return packer.get_buffer()
def gmetric_meta(NAME, TYPE, UNITS, SLOPE, TMAX, DMAX, EXTRAS=None): """ Arguments are in all upper-case to match XML """ packer = Packer() packer.pack_int(128) # "gmetadata_full" packer.pack_string('nickg-macbook.local') packer.pack_string(NAME) packer.pack_bool(False) packer.pack_string(TYPE) packer.pack_string(NAME) packer.pack_string(UNITS) packer.pack_int(slope_str2int[SLOPE]) # map slope string to int packer.pack_uint(int(TMAX)) packer.pack_uint(int(DMAX)) if EXTRAS is None: packer.pack_uint(0) else: packer.pack_uint(len(EXTRAS)) for k, v in EXTRAS.iteritems(): packer.pack_string(k) packer.pack_string(v) return packer.get_buffer()
def gmetric_value(NAME, VAL): packer = Packer() packer.pack_int(128+5) # string packer.pack_string('nickg-macbook.local') packer.pack_string(NAME) packer.pack_bool(False) packer.pack_string('%s') packer.pack_string(VAL) return packer.get_buffer()
def gmetric_value(NAME, VAL): packer = Packer() packer.pack_int(128 + 5) # string packer.pack_string('nickg-macbook.local') packer.pack_string(NAME) packer.pack_bool(False) packer.pack_string('%s') packer.pack_string(VAL) return packer.get_buffer()
def send_metareq(self, values, address): packer = Packer() packer.pack_int(136) if not values['spoof']: packer.pack_string(address[0]) else: packer.pack_string(":".join((address[0], values['hostname']))) packer.pack_string(values['metricname']) packer.pack_bool(values['spoof']) self.transport.write(packer.get_buffer(),address) return
def sendV3Data(self, sock, address, value): if time.time() - self.lastMetadataSendTime >= self.metadataInterval: self.sendMetadata(sock, address) packer = Packer() packer.pack_enum(self.formatIDs[self.type]) packer.pack_string(self.hostname) packer.pack_string(self.name) packer.pack_bool(False) # spoof = false packer.pack_string(self.format) self.packValue(packer, value) sock.sendto(packer.get_buffer(), address)
def sendMetadata(self, sock, address): self.lastMetadataSendTime = time.time() packer = Packer() packer.pack_enum(self.formatIDs['full']) packer.pack_string(self.hostname) packer.pack_string(self.name) packer.pack_bool(False) # spoof = false packer.pack_string(self.type) packer.pack_string(self.name) packer.pack_string(self.units) if self.slope == 'zero': slope = 0 else: slope = 3 packer.pack_uint(slope) packer.pack_uint(self.tmax) packer.pack_uint(self.dmax) packer.pack_uint(len(self.meta)) # array length for name, value in self.meta.items(): packer.pack_string(name) packer.pack_string(value) sock.sendto(packer.get_buffer(), address)
def pack(self, packer: Packer) -> None: packer.pack_bool(self.value)