• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
ControlUp Community

ControlUp Community

Connect, Learn, and Grow

  • Blog
  • Archives
  • Findings
  • Meetups
  • Videos
  • Events
  • Categories
    • ControlUp One Platform
    • ControlUp for Apps
    • ControlUp for Compliance
    • ControlUp Dashboards
    • ControlUp for Desktops
    • ControlUp for VDI
    • ControlUp Scripts & Triggers
    • ControlUp Synthetic Monitoring
    • ControlUp Workflows
  • Topics
    • Logos & Wallpaper
    • ControlUp.com
  • Join

Is there a ControlUp script to reset the hypervisor connection of VDIs with a specific power state?

Posted on May 26, 2023

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
Topics: Citrix, Databases, Logs, PowerShell, Scripts

Ask Us Anything, Connect, Learn, and Grow with the ControlUp Community!

Login to the ControlUp Community to ask us anything, stay up-to-date on what’s new and coming soon and meet other like-minded techies like you.

Not already a member? Join Today!

Primary Sidebar

ControlUp Academy

Enroll in ControlUp Academy for expert-led technical training, equipping you with skills to effectively deploy, manage, and grow your ControlUp investment.

Learn here >

Rotating Images

Hidden Gem from our Community on Slack!

ControlUp Betas - What's Coming Next?
NEW ControlUp Features - Stay Up-to-Date!
ControlUp Scripts - Scripting, Zero to Hero
Latest KB Articles - Be the First to Learn

Video Tutorials Library

Visit our technical how-to videos, offering step-by-step tutorials on advanced features, troubleshooting, and best practices.

Watch here >

ControlUp Blog

Check out the ControlUp blog for expert advice and in-depth analysis.

Read here >

ControlUp Script Library

Visit the ControlUp technical script library, which offers a multitude of pre-built scripts and custom actions for your monitoring and troubleshooting requirements.

See here >

ControlUp Support

Visit the ControlUp support home and to delve deeper into ControlUp DEX solutions.

Browse here >

Footer

      

ControlUp Community
Of Techie, By Techie, For Techie!

Terms of Use | Privacy Policy | Security
Dive Deeper, Learn more at ControlUp.com

  • facebook
  • twitter
  • youtube
  • linkedin

© 2023–2026 ControlUp Technologies LTD, All Rights Reserved.

We use cookies to ensure that we give you the best experience on our website. by continuing to use this site you agree to our Cookie policy..