# File lib/smart_proxy_monitoring_icinga2/icinga2_client.rb, line 41
      def events_socket(endpoint)
        uri = URI.parse([baseurl, endpoint].join(''))
        socket = TCPSocket.new(uri.host, uri.port)

        ssl_context = OpenSSL::SSL::SSLContext.new
        ssl_context.ca_file = cacert

        if ssl
          ssl_context.set_params(verify_mode: OpenSSL::SSL::VERIFY_PEER)
        else
          ssl_context.set_params(verify_mode: OpenSSL::SSL::VERIFY_NONE)
        end

        if certificate_request?
          ssl_context.cert = cert
          ssl_context.key = key
        end

        ssl_socket = OpenSSL::SSL::SSLSocket.new(socket, ssl_context)
        ssl_socket.sync_close = true
        ssl_socket.connect

        ssl_socket.write "POST #{uri.request_uri} HTTP/1.1\r\n"
        ssl_socket.write "Accept: application/json\r\n"
        unless certificate_request?
          auth = Base64.encode64("#{user}:#{password}")
          ssl_socket.write "Authorization: Basic #{auth}"
        end
        ssl_socket.write "\r\n"

        ssl_socket
      end