def send_message(message):
    address, family, connection_protocol = receiver_sockets_params[0]
    SSL_socket = SocketController(address,
                                  family=family,
                                  connection_protocol=connection_protocol)
    try:
        SSL_socket.open()
    except ssl.SSLError as exception:
        # We did not expect this error, fail test
        raise
    SSL_socket.send(message, size=False)
    response = SSL_socket.receive().decode()
    SSL_socket.close()
    return response
def get_remote_configuration(component_name, config):
    socket_path = os.path.join(WAZUH_PATH, 'queue', 'sockets')
    dest_socket = os.path.join(socket_path, component_name)
    command = f"getconfig {config}"

    # Socket connection
    s = SocketController(dest_socket)

    try:
        # Send message
        s.send(command.encode(), True)

        # Receive response
        rec_msg_ok, rec_msg = s.receive(True).decode().split(" ", 1)
    except socket.timeout as error:
        s.close()
        raise TimeoutError(error)

    try:
        if rec_msg_ok.startswith('ok'):
            remote_configuration = json.loads(rec_msg)
            for element in remote_configuration['wmodules']:
                if 'gcp-pubsub' in element:
                    remote_configuration_gcp = element['gcp-pubsub']
        else:
            s.close()
            raise ValueError(rec_msg_ok)
    except UnboundLocalError as error:
        s.close()
        raise TimeoutError(error)
    return remote_configuration_gcp
Example #3
0
def get_remote_configuration(component_name, config):
    socket_path = os.path.join(WAZUH_PATH, 'queue', 'ossec')
    dest_socket = os.path.join(socket_path, component_name)
    command = f"getconfig {config}"
    host_type = 'agent' if 'agent' in WAZUH_SERVICE else 'server'

    # Socket connection
    s = SocketController(dest_socket)

    try:
        # Send message
        s.send(command.encode(), True)

        # Receive response
        rec_msg_ok, rec_msg = s.receive(True).decode().split(" ", 1)
    except socket.timeout as error:
        s.close()
        raise TimeoutError(error)

    try:
        if rec_msg_ok.startswith('ok'):
            remote_configuration = json.loads(rec_msg)
            if host_type == 'server':
                remote_configuration_gcp = remote_configuration['wmodules'][6][
                    'gcp-pubsub']
            else:
                if sys.platform == 'darwin':
                    remote_configuration_gcp = remote_configuration[
                        'wmodules'][3]['gcp-pubsub']
                else:
                    remote_configuration_gcp = remote_configuration[
                        'wmodules'][5]['gcp-pubsub']
        else:
            s.close()
            raise ValueError(rec_msg_ok)
    except UnboundLocalError as error:
        s.close()
        raise TimeoutError(error)
    return remote_configuration_gcp