Hello, I am not a developper, I can run a small quick and dirty script I wrote but I wish there was a proper script to reset the hypervisor connection of VDIs with power state "Unknown".
Ref: (
Reset-BrokerHypervisorConnection -HypervisorConnectionUid
)
Assuming you are referring to a Citrix environment.
In my experience, this power state Unknown can have several causes. The cause I have seen the most is a temporary loss of connection between the Delivery Controller and the database.
I would recommend to have a look at the event log on your Delivery Controller(s) and see if you find eventID’s 1200, 1201 or 1202 (https://docs.citrix.com/en-us/citrix-virtual-apps-desktops/downloads/broker_events.htm).
If you find any of those since the last time the system booted the easiest fix is to reboot the Delivery Controller.
This could ofcourse be scripted, but would need loads of checks to make it safe to use in production. One can think of an election between the Delivery Controllers in an environment to determine an order in which to reboot if multiple Delivery Controllers experience the same issue. Also a cooldown period would be nice to prevent the Delivery Controllers rebooting continually when database stability is an issue.
The problem with automating this process will be that it will not fix the underlying issues, so it may be best to create a script to monitor for this issue, but not a script to fix it. If you would fix it automatically, I would recommend logging the fix event (e.g. in your IMS) to get an idea of the occurrence of the issue and get resources to research and fix the underlying issue.
I have scripted the following in Python for usage in PRTG in the past (PowerShell is very slow in reading the event-log), maybe this could be of help to you if it is rewritten to be used in ControlUp.
“`import win32evtlog
import datetime
import time
import json
import sys
import wmi
from prtg.sensor.result import CustomSensorResult
from prtg.sensor.units import ValueUnit
def date2sec(evt_date):
"""
This function converts dates with format
‘Thu Jul 13 08:22:34 2017’ to seconds since 1970.
"""
dt = datetime.datetime.strptime(evt_date, "%a %b %d %H:%M:%S %Y")
return dt.timestamp()
if name == "main":
try:
begin_sec = time.time()
data = json.loads(sys.argv[1])
server = data["host"]
prtg_parameters = data[‘params’]
split_parameters = dict(parameter.split(‘=’) for parameter in prtg_parameters.split(‘,’))
log_type = split_parameters[‘log_type’]
event_ids = split_parameters[‘event_ids’]
event_ids_list = list(event_ids.split(‘;’))
log_handle = win32evtlog.OpenEventLog(server, log_type)
flags = win32evtlog.EVENTLOG_BACKWARDS_READ | win32evtlog.EVENTLOG_SEQUENTIAL_READ
wmi_info = wmi.WMI(server)
system_data = wmi_info.Win32_PerfFormattedData_PerfOS_System()
uptime_seconds = int(system_data[-1].SystemUpTime)
event_count = 0
events = True
while events:
events = win32evtlog.ReadEventLog(log_handle, flags, 0)
seconds = begin_sec
for event in events:
the_time = event.TimeGenerated.Format()
seconds = date2sec(the_time)
if seconds < begin_sec – uptime_seconds:
break
for event_id in event_ids_list:
if event.EventID & 0x1fff == int(event_id):
event_count += 1
if seconds < begin_sec – uptime_seconds:
break # get out of while loop as well
win32evtlog.CloseEventLog(log_handle)
end_sec = time.time()
prtg_run_time = end_sec – begin_sec
csr = CustomSensorResult(text="Reboot this server if event is found")
csr.add_primary_channel(
name="Number of events since boot time",
value=event_count,
unit=ValueUnit.COUNT,
is_limit_mode=True,
limit_max_error=0.5,
limit_error_msg="Reboot this server if event is found"
)
csr.add_channel(
name="PRTG Runtime",
value=prtg_run_time,
unit=ValueUnit.TIMESECONDS
)
print(csr.json_result)
except Exception as e:
csr = CustomSensorResult(text="Python Script execution error")
csr.error = "Python Script execution error: %s" % str(e)
print(csr.json_result)“`
Maybe a job for you to convert this script? 🙂
Continue reading and comment on the thread ‘Is there a ControlUp script to reset the hypervisor connection of VDIs with a specific power state?’. Not a member? Join Here!
Categories: All Archives, ControlUp Scripts & Triggers