Beispiel #1
0
def compress_files(list_path, node_type):
    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 Agent.get_all_groups(limit=None)['items']
                ]
                zf.writestr("remote_groups.txt", '\n'.join(local_groups),
                            compression)
            except Exception as e:
                raise WazuhException(3001, str(e))

    return zipped_file.getvalue()
Beispiel #2
0
def show_groups():
    groups_data = Agent.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(
        Agent.get_agents_without_group()['totalItems']))
Beispiel #3
0
 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 Agent.get_all_groups(limit=None)['items']
     }
     for removed_group in local_groups - remote_group_set:
         try:
             Agent.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)))
Beispiel #4
0
def show_groups():
    groups_data = Agent.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']))