def export(self, name, columns, points): """Write the points to the ZeroMQ server.""" logger.debug("Export {} stats to ZeroMQ".format(name)) # Create DB input data = dict(zip(columns, points)) # Do not publish empty stats if data == {}: return False # Glances envelopes the stats in a publish message with two frames: # - First frame containing the following prefix (STRING) # - Second frame with the Glances plugin name (STRING) # - Third frame with the Glances plugin stats (JSON) message = [b(self.prefix), b(name), asbytes(json.dumps(data))] # Write data to the ZeroMQ bus # Result can be view: tcp://host:port try: self.client.send_multipart(message) except Exception as e: logger.error("Cannot export {} stats to ZeroMQ ({})".format( name, e)) return True
def export(self, name, columns, points): """Write the points to the ZeroMQ server.""" logger.debug("Export {} stats to ZeroMQ".format(name)) # Create DB input data = dict(zip(columns, points)) # Do not publish empty stats if data == {}: return False # Glances envelopes the stats in a publish message with two frames: # - First frame containing the following prefix (STRING) # - Second frame with the Glances plugin name (STRING) # - Third frame with the Glances plugin stats (JSON) message = [b(self.prefix), b(name), asbytes(json.dumps(data))] # Write data to the ZeroMQ bus # Result can be view: tcp://host:port try: self.client.send_multipart(message) except Exception as e: logger.error("Cannot export {} stats to ZeroMQ ({})".format(name, e)) return True
def save_password(self, hashed_password): """Save the hashed password to the Glances folder.""" # Create the glances directory safe_makedirs(self.password_dir) # Create/overwrite the password file with open(self.password_file, 'wb') as file_pwd: file_pwd.write(b(hashed_password))
def deflate_compress(data, compress_level=6): """Compress given data using the DEFLATE algorithm""" # Init compression zobj = zlib.compressobj(compress_level, zlib.DEFLATED, zlib.MAX_WBITS, zlib.DEF_MEM_LEVEL, zlib.Z_DEFAULT_STRATEGY) # Return compressed object return zobj.compress(b(data)) + zobj.flush()
def save_password(self, hashed_password): """Save the hashed password to the Glances folder.""" # Check if the Glances folder already exists if not os.path.exists(self.password_path): # Create the Glances folder try: os.makedirs(self.password_path) except OSError as e: logger.error("Cannot create Glances directory: {0}".format(e)) return # Create/overwrite the password file with open(self.password_filepath, 'wb') as file_pwd: file_pwd.write(b(hashed_password))
def sha256_hash(self, plain_password): """Return the SHA-256 of the given password.""" return hashlib.sha256(b(plain_password)).hexdigest()