Skip to main content

Automate Agent - Auto Repair

Summary

This auto-fix script will check if a machine that has gone offline in Automate is online in Control. If found to be online in Control, it will look at whether it's a duplicate instance, and then an attempt to restart the Automate agent will be made through the RMM+ integration. The script sets a state to either Offline, Broken, or Undetermined to indicate status. If the agent is returned online, the script state will be cleared.

Set the System Property Agent_Repair_Duplicate_Check_Enabled to 1 to look for duplicate computers; by default, the script will not look for duplicate instances of the machine.

Set the System Property Agent_Repair_Re_Install_Enabled to 0 to disable the reinstall feature of the script; by default, the script will attempt to reinstall the Automate agent if necessary.

Time Saved by Automation: 30 Minutes

Requirements

RMM+ solution should be properly configured in the environment.

Sample Run

The script must be run with the Set Environment = 1 setting for the first time after the update. This will create the system properties used by the script.

Sample Run 1

For Regular Execution:

Sample Run 2

By default, the script will be called by the Monitor - No Checkin for More Than 30 Days.

Dependencies

Sub Scripts

Variables

NameDescription
STATUSSUCCESS/FAILED returned by the monitor set.
DuplicateCheckValue of the system property Agent_Repair_Duplicate_Check_Enabled.
Re-InstallValue of the system property Agent_Repair_Re_Install_Enabled.
TicketCreationCategoryTicket category value for this script to use when creating a ticket. The script will not create any ticket for manual execution. Ticket category can be set in the monitor set's alerting tab or from the groups where the monitor set is enabled. Refer to the Ticket Creation section of this article for further information.
SerialNumberSerial Number of the computer.
RetireStatementSQL Query used to retire the computers.
OnlineOnline status of the computer in ScreenConnect Portal returned by the Script - ScreenConnect Client - Connectivity - Audit. 1: Online; 0: Offline; -2: Undetermined (RMM+ Solution is not configured properly), -3: Machine Error (Plugin results contain error type message), -4: Incorrect Agent Guid.
AgentOnlineStatus of the agent in ConnectWise Automate after attempting to fix the problem.
SubjectSubject of the ticket to create on Script Failure. Agent Reinstall Failed/Broken Agent - %clientname%//%computername%
BodyInformation to add to the ticket for script failure.
TickidID of an existing new/open ticket to comment.
ParsedLogsThe last 20 lines of the LTerrors.txt file to add to the ticket.
CommandCommand to be executed on the machine from the ScreenConnect portal using the Script - ScreenConnect Client - Command - Execute.

User Properties

NameExampleRequiredDescription
SetEnvironment1Mandatory for the First run post updateIt is mandatory to run the Script with SetEnvironment parameter set to 1 for the first run after updating the script.

System Properties

NameExampleRequiredDescription
RMMPlus_AccessKeyajw8fh2p93ufn;o31ifu2091j23oifTrueThis is the key set up in the CW Control RMM+ Plugin so Automate can reach out to gain access to the API.
RMMPlus_HeadersOrigin:site.site.comTrueThis is the URL (without http/https) for the CW Control server. This value needs to match the value in the RMM+ Plugin configuration in CW Control.
RMMPlus_StaleAgentThreshold30TrueThe number of days to indicate what a "stale" agent is to the scripts. 30 is the default.
RMMPlus_Timeout1000TrueThe default timeout for commands run via RMM+ through Automate. 1000 is the default.
Agent_Repair_Duplicate_Check_Enabled0PartiallyRunning the script with SetEnvironment parameter equals 1 will create this property with the default value of 0. Set it to 1 to look for duplicate computers; by default, the script will not look for duplicate instances of the machine.
Agent_Repair_Re_Install_Enabled1PartiallyRunning the script with SetEnvironment parameter equals 1 will create this property with the default value of 1. Set it to 0 to disable the reinstall feature of the script; by default, the script will attempt to reinstall the Automate agent if necessary.

Script States

NameExampleDescription
AgentStatusBrokenOffline
ScriptRunTime2023-07-10 08:40:20Run time of the script to be used by the Dataview - Agent - Agent Check-in Health.
OnlineInScreenConnectSinceMinutesSession not found, 12234, -1213Outcome of the plugin result. Usually the time in minutes for which the computer is online in ScreenConnect. (-ve time indicates that the machine is offline for that many minutes). This state is further used as the "Command Result" column of the Dataview - Agent - Agent Check-in Health.

Output

  • Script Logs
  • Script States
  • Ticket (Only if executed from the monitor set)
  • Dataview

Ticketing

To enable ticketing on failure, the ticket category must be set in the alerting tab of the monitor set calling the script, or at the group level if the monitor set is enabled on the group. Also, the script will not create any tickets for manual executions.

From Monitor Set:
Monitor Set

From Group:
Group 1
Group 2

Ticket Subject: Agent Reinstall Failed/Broken Agent - \\<clientname>//\\<computername>

Ticket Body (Windows OS):

The agent <computername> was found to be offline in Automate and online in Control. An attempt was made to reinstall the agent; however, the Computer ID %computerid% is still not checking in. The last user according to Automate was <lastuser>. If this variable is blank, then Automate was unable to determine the last logged-in user.

Manual remediation is required. If you can access the machine, please download the lterrors.txt file typically located in the root Windows directory in the LTSvc folder. (Typical path is C:/Windows/LTSvc/lterrors.txt) This log file may help troubleshoot why the agent isn't able to check in. Most common errors are related to .NET or TLS issues.

The last 20 lines from the log file are as follows:
<ParsedLogs>

Ticket Body (Non-Windows OS):

The agent <computername> was found to be offline in Automate and online in Control. An attempt was made to reinstall the agent; however, the Computer ID <computerid> is still not checking in. The last user according to Automate was <lastuser>. If this variable is blank, then Automate was unable to determine the last logged-in user.

Manual remediation is required.

Example <ParsedLogs>:

LTService  v230.222   - 7/10/2023 10:04:22 AM   - Background Worker: AccomplishPostWindowsUpdateSettingRestart: Resetting registry value for Windows Update service start type.:::
LTService v230.222 - 7/10/2023 10:04:22 AM - Background Worker: AccomplishPostWindowsUpdateSettingRestart: Trying to start the Windows Update service if it is not already running.:::
LTService v230.222 - 7/10/2023 10:04:22 AM - Background Worker: AccomplishPostWindowsUpdateSettingRestart: Windows Update service verified running. End of background worker.:::
LTService v230.222 - 7/10/2023 10:11:49 AM - WebRqst: [https://labtech.provaltech.com/LabTech](https://labtech.provaltech.com/LabTech) : ConnectFailure : Unable to connect to the remote server : inner: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 78.46.72.162:443 : :::
LTService v230.222 - 7/10/2023 11:39:34 AM - Heartbeat send Status already sending:::
LTService v230.222 - 7/10/2023 11:51:29 AM - Successfully synchronized monitors with database: Monitors are synchronized with database.:::
LTService v230.222 - 7/10/2023 1:04:06 PM - Test Server: [https://labtech.provaltech.com](https://labtech.provaltech.com) svrs:2:::
LTService v230.222 - 7/10/2023 1:04:13 PM - Setting Windows 10 Update service Auto-Update policy.:::
LTService v230.222 - 7/10/2023 1:04:13 PM - Setting Windows Update startup type to 'Disabled' so we can stop the service after applying the policy. This stops the service from downloading updates.:::
LTService v230.222 - 7/10/2023 1:04:13 PM - Running PowerShell command to have Windows Update service check for updates which will apply registry settings.:::
LTService v230.222 - 7/10/2023 1:04:15 PM - Stopping Windows Update service to block the download of updates after applying policy from registry settings.:::
LTService v230.222 - 7/10/2023 1:04:16 PM - Creating background worker to accomplish the post-windows update setting restart action.:::
LTService v230.222 - 7/10/2023 1:04:16 PM - Background Worker: AccomplishPostWindowsUpdateSettingRestart: Waiting 10 seconds to restart service.:::
LTService v230.222 - 7/10/2023 1:04:26 PM - Background Worker: AccomplishPostWindowsUpdateSettingRestart: Resetting registry value for Windows Update service start type.:::
LTService v230.222 - 7/10/2023 1:04:26 PM - Background Worker: AccomplishPostWindowsUpdateSettingRestart: Trying to start the Windows Update service if it is not already running.:::
LTService v230.222 - 7/10/2023 1:04:27 PM - Background Worker: AccomplishPostWindowsUpdateSettingRestart: Windows Update service verified running. End of background worker.:::
LTService v230.222 - 7/10/2023 2:53:50 PM - Heartbeat send Status already sending:::
LTService v230.222 - 7/10/2023 3:37:46 PM - Heartbeat send Status already sending:::
LTService v230.222 - 7/10/2023 3:51:31 PM - Successfully synchronized monitors with database: Monitors are synchronized with database.:::
LTService v230.222 - 7/10/2023 3:55:48 PM - Heartbeat send Status already sending:::