VMware Cloud Community
leeplastic
Contributor
Contributor

connect-viserver times out randomly

Hi,

I have a script that runs each night and randomly it seems to fail to connect (I know for a fact this isn't a network issue)

So I've put a condition to check if there is a connection, if not, attempt to connect again up to a maximum of five times. However this reaches the maximum and as a result the script doesn't work.

My questions are:

Are there any blatant reasons why the script would fail to connect and is there anything obviously wrong with the reconnection attempts?

Thanks in advance.

$connect = connect-viserver $viServerName

If ($connect.IsConnected -ne $true)

{

while (($connect.IsConnected -ne $true) -and ($i -le 5))

{

sleep 15

$connect = connect-viserver $viServerName

if ($i -eq 5)

{

$failMsg = "Failed to connect to $viServerName after $i attempts"

$failMsg | out-file $logfile -append

}

$i++

}

}

0 Kudos
9 Replies
harkamal
Expert
Expert

If continuous ping is sucessfull, then perhaps it has to do something with the vcServer ?

have you checked event logs, if apache service is having any errors in eventlog, or some performance issues that vcServer is not able to cater to webservices requests

0 Kudos
RobMokkink
Expert
Expert

I see that you don't do a disconnect. I think there are to many active sessions on the vCenter server.

0 Kudos
leeplastic
Contributor
Contributor

I can see nothing obvious in the windows event logs and nothing in the Virtual Centre logs (Documents and Settings\All Users\Application Data\VMware\VMware VirtualCenter\Logs)

Tomcat logs dont seem that helpful either.

ps. there is a disconnect at the end of the script, I have only produced an excerpt here.

Thanks

0 Kudos
RobMokkink
Expert
Expert

Did you check the sessions in vcenter admin tab?

0 Kudos
leeplastic
Contributor
Contributor

yes.. there is not a problem with vi server exceeding sessions.

Thanks

0 Kudos
RobMokkink
Expert
Expert

Is the vCenter webaccess service running oke?

0 Kudos
leeplastic
Contributor
Contributor

I've been through all the services and everything looks to be running fine. I had also increased the connect re-tries to 100 times. I've checked the logic by replacing conditions for keyboard inputs and the script works as expected. I'm wondering if the $connect.IsConnected statement is not bringing back the desired result. I've modifed the script to log this. Script is attached

0 Kudos
harkamal
Expert
Expert

$connect.IsConnected is a buggy implementation.

I noticed earlier, calling $defaultVIServer breaks the connection intermittently. This was fixed in PowerCLI

Workaround,

$myVar = $DefaultVIServer

$myVar -eq $null

leeplastic
Contributor
Contributor

unfortunately the script failed again last night after it ran successfully the previous night.

I've now moved the script so it runs from the VI server, ruling out any network issues. I've been through the virtual centre logs and windows event viewer and nothing stands out. SCOM is showing the server to be healthy. What is interesting is that I have two similar scripts that are run within two minutes of each everyday, on no occasion does only one script succeed. If one fails, so does the second.

When the script failed VMWare Virtual Centre Server Service was running correctly.

0 Kudos