Hello VMware Community,
I'm encountering an issue when trying to connect to an HTML console via WebSocket. Below is the process I followed and the error I'm experiencing. Any guidance would be greatly appreciated.
Using Python, I retrieved VNC connection information for a virtual machine. The code snippet used is as follows:
Using Python, I retrieved VNC connection information for a virtual machine. The code snippet used is as follows:
try:
ticket = vm.AcquireMksTicket()
print("VNC connection information for {}:".format(vm_name))
print("Host: {}".format(ticket.host))
print("Port: {}".format(ticket.port))
print("Ticket: {}".format(ticket.ticket))
print("SSL thumbprint: {}".format(ticket.sslThumbprint))
except vmodl.MethodFault as e:
print("Failed to get VNC connection information: {}".format(e.msg))
exit(1)
This resulted in the following
VNC connection information for dev-test - 10.xxxxxxxxxxxx:
Host: ch1-dev-esxi1.lab.local
Port: 902
Ticket: 52xxxxxxxxxxxxxxxxxxxxxxxx
SSL thumbprint: [Thumbprint]
Issue:
However, when attempting to use this information to connect to the HTML console, I'm facing a WebSocket connection failure. The error message is:
WebSocket connection to 'wss://[IP]:[Port]/ticket/[Ticket-ID]' failed
Here's the HTML and JavaScript code I used for the connection:
<!DOCTYPE html>
... [Rest of the HTML code] ...
<script>
var wmks = WMKS.createWMKS("wmksContainer",{})
.register(WMKS.CONST.Events.CONNECTION_STATE_CHANGE, function(event, data){
if(data.state == WMKS.CONST.ConnectionState.CONNECTED){
console.log("connection state change: connected");
}
});
wmks.connect("wss://ch1-dev-esxi1.lab.local:902/ticket/52dxxxxxxxxxxxxxxx");
</script>
</body>
</html>
Additional Checks:
I'm unsure why this WebSocket connection is failing. Has anyone experienced a similar issue or can provide some insights into what might be going wrong?
Thank you in advance for your help!
Hi @mdusman
Did you manage to sort this issue, I'm also experiencing this issue
Yes. I resolved the issue.
Can you share the snippet of code you are using? I will try to help.
@mdusman
from vcenter, im getting the ticket and the url "wss://02LUM11:443/ticket/c6051953a5b7**********"
and the html code that was gotten from wmware websorket HTML console
https://vdc-download.vmware.com/vmwb-repository/dcr-public/42c380d0-4736-41fc-aa3d-76fe5e1bdc81/5fb6...
below is the html code I'm using
<title>Console</title>
<link rel="stylesheet" type="text/css" href="/static/css/wmks-all.css" />
<script type="text/javascript" src="/static/wmks.min.js"></script>
<script type="text/javascript" src="http://code.jquery.com/jquery-3.4.1.min.js"></script>
<script type="text/javascript" src="http://code.jquery.com/ui/1.12.0/jquery-ui.min.js"></script>
</head>
<body>
<div id="wmksContainer" style="position:absolute;width:100%;height:100%"></div>
<script>
var wmks = WMKS.createWMKS("wmksContainer",{})
.register(WMKS.CONST.Events.CONNECTION_STATE_CHANGE, function(event,data){
if(data.state == WMKS.CONST.ConnectionState.CONNECTED){
console.log("connection state change : connected");}
});
wmks.connect("wss://02LUM11:443/ticket/c6051953a5b7**********");
</script>
</body>
</html>
Hi @Ellybee
Okay since you are using this url wss://02LUM11:443/ticket/c6051953a5b7**********"
Please check following
1. 02LUM11:443 (this should have a valid certificate). If you are using self-signed certificate, go to 02LUM11 in your browser and accept its certificate and then retry connection. This part is important because browsers does not accept self-signed certificate automatically.
2. In Vcenter there are two functions to acquire ticket AcquireTicket and AcquireWebMKSTicket. Ticket obtained by first method works in our case. . Check this URL
Sample Javascript Code - HTML Console SDK Programming Guide (vmware.com)
2a. If you are using python code use
vm.AcquireTicket(ticketType='webmks')
Let me know if this helps or if you have any further questions.