def compress_files(list_path, node_type, tobedeleted_files): zipped_file = BytesIO() with zipfile.ZipFile(zipped_file, 'w') as zf: # write files for f in list_path: try: zf.write(filename=common.ossec_path + f, arcname=f, compress_type=compression) except Exception as e: logging.error(str(WazuhException(3001, str(e)))) # write a file with the name of all the groups only if the node type is master if node_type == 'master': try: local_groups = [ x['name'] for x in group.get_all_groups(limit=None)['items'] ] zf.writestr("remote_groups.txt", '\n'.join(local_groups), compression) if len(tobedeleted_files) > 0: zf.writestr("remote_deleted.txt", '\n'.join(tobedeleted_files), compression) except Exception as e: raise WazuhException(3001, str(e)) return zipped_file.getvalue()
def show_groups(): groups_data = group.get_all_groups(limit=None) print("Groups ({0}):".format(groups_data['totalItems'])) for g in groups_data['items']: print(" {0} ({1})".format(g['name'], g['count'])) print("Unassigned agents: {0}.".format( group.get_agents_without_group()['totalItems']))
def check_groups(remote_group_set): """ Function to remove the groups that are on the local node and not in the remote node """ local_groups = {x['name'] for x in get_all_groups(limit=None)['items']} for removed_group in local_groups - remote_group_set: try: remove_group(removed_group) logging.info("Group {0} removed successfully".format(removed_group)) except Exception as e: logging.error("Error deleting group {0}: {1}".format(removed_group, str(e)))
def show_groups(): groups_data = group.get_all_groups(limit=None) print("Groups ({0}):".format(groups_data['totalItems'])) for g in groups_data['items']: print(" {0} ({1})".format(g['name'], g['count']))