Jump to content
bigdessert

RMM+ ScreenConnect Plugin with Labtech Integration

Recommended Posts

I don't know if this helps or not but here's some additional info. I have replaced part of our web address as well as the RMM+ key.

 

Parameters:

cmd.exe!!! /c "powershell -command "& "Invoke-RestMethod -Method Post -Uri 'http://mycompany.hostedrmm.com:8040/App_Extensions/8e78224d-79db-4dbb-b62a-833276b46c6e/Service.ashx/ExecuteCommand' -Body'[\"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\",\"e0749814-5306-4dce-ae88-e1f70e97984f\",\"ipconfig\",\"10\"]' -ContentType 'application/json'";"

 

Output:

The string starting:

At line:1 char:281

+ & Invoke-RestMethod -Method Post -Uri 'http://mycompany.hostedrmm.com:8040/App_E

xtensions/8e78224d-79db-4dbb-b62a-833276b46c6e/Service.ashx/ExecuteCommand' -Bo

dy'["XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX","e0749814-5306-4dce-ae88-e1f70e97984f","ip

config","10"]' -ContentType 'application/json <<<< ';

is missing the terminator: '.

At line:1 char:283

+ & Invoke-RestMethod -Method Post -Uri 'http://mycompany.hostedrmm.com:8040/App_E

xtensions/8e78224d-79db-4dbb-b62a-833276b46c6e/Service.ashx/ExecuteCommand' -Bo

dy'["XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX","e0749814-5306-4dce-ae88-e1f70e97984f","ip

config","10"]' -ContentType 'application/json'; <<<<

+ CategoryInfo : ParserError: (;:String) [], ParentContainsErrorR

ecordException

+ FullyQualifiedErrorId : TerminatorExpectedAtEndOfString

Edited by Guest

Share this post


Link to post
Share on other sites

You don't need the plugin to be able to pass commands to screenconnect. You can call the webservice and do everything via powershell. The examples work very well.

Share this post


Link to post
Share on other sites

After my last post I saw your most recent posting on the second page.

 

I'm attaching a file containing a script of mine. It should install three scripts

1) A script which executes ipconfig on a machine.

2) The generic script 1) calls to execute the command

3) a script which loads your variables, called by 2) You will need to insert your password in here

 

each of the script is prefixed by "ixp-", so you should be able to find them if they are imported somewhere strange.

 

Are you aware that you posted the password to your screenconnect server? I haven't tried it, but if its valid, you've given open access to the world to every machine with SC installed.

ixp-ScreenConnect - Exe command ipconfig.7z

Share this post


Link to post
Share on other sites

First off, thanks for pointing out the accesskey in my post. I caught it in the output but not from the parameters. I've changed it here and will change it in the extension and script. Second, thanks for the info. I'll take a look at your scripts and see what I can do.

Share this post


Link to post
Share on other sites

@BigDessert

 

Can your plugin support terminal commands down to a MAC or linux box running ScreenConnect? From what it looks like is your plugin is set to run commands using cmd.exe on Windows. Can we add a OS vendor type that will change behavior so it executes commands on MAC ?

Share this post


Link to post
Share on other sites

How would you use this (purpose)? I understand the isOnLine function which I am now using in the next version of plugin but what would I use this for in relation to the computerID i am getting the SCGUID for?

Share this post


Link to post
Share on other sites

Sky is the limit. It was added for a particular use case where someone wanted to create a script to cleanup leftover printers that SC sometimes leaves behind. They wanted to run this script on all systems except for those with hosts connected to them.

 

I could think of many reasons like creating a script in LT to find out who is connected to what....reports...who knows.

 

The IsOnline tells us if the guest is online or not.

 

The HostsConnected tells us if the host side is connected or not.

Share this post


Link to post
Share on other sites

Ah.. I do know I could use a list of screen connect agents offline currently that I could match to computerID's inside of LabTech. This would allow me to make a list that would work in the opposite way and restart SC agents from LabTech if they went south. Not that I suspect that is as much of an issue..

Share this post


Link to post
Share on other sites

RMM Plus is really awesome.

Below is the "offline server" monitor I created yesterday and decided to share.

It is a rawsql monitor and all the variables are at the top for an easy adjustment.

The monitor will attempt to restart the agent before it alerts.

I run the monitor every 2 minutes.

There is a note above each variable.

If you read the notes, everything will make sense.

=============================================================

### minimum last contact date before sending a reset command through ScreenConnect

SET @date_contact_reset = DATE_ADD(NOW(),INTERVAL -8 MINUTE);

### or minimum last heartbeat date before sending a reset command through ScreenConnect

SET @date_heartbeat_reset = DATE_ADD(NOW(),INTERVAL -4 MINUTE);

### frequency for sending the reset commands after the first alert; before the first alert the reset command is sent every time the monitor runs

SET @reset_frequency = 60;

### minimum last contact date before alerting

SET @date_contact_alert = DATE_ADD(NOW(),INTERVAL -14 MINUTE);

### or minimum last heartbeat date before alerting

SET @date_heartbeat_alert = DATE_ADD(NOW(),INTERVAL -10 MINUTE);

### agent ID of the ScreenConnect server; variable can be set to a specific ComputerID, but you will have to update the monitor if you reinstall your ScreenConnect agent; make sure the server can execute "Invoke-RestMethod" (powershell v2 required)

SET @sc_id = (SELECT c.ComputerID FROM computers c WHERE c.Name = '');

### ScreenConnect RMM Plus access key

SET @accesskey = '';

### get command execution url for ScreenConnect

SET @sc_url = (SELECT CONCAT(URL,':',Port,'/App_Extensions/8e78224d-79db-4dbb-b62a-833276b46c6e/Service.ashx/ExecuteCommand') FROM plugin_screenconnect_config);

### command to run on the offline agent through ScreenConnect

SET @reset_command = 'sc stop LTSvcMon & sc stop LTService & ping localhost -n 5 & taskkill /IM LTTray.exe /F /T & taskkill /IM LTSvcMon.exe /F /T & taskkill /IM LTSVC.exe /F /T & sc start LTSvcMon & sc start LTService';

### Computer level EDF saying in example that the agent is under MSP contract

SET @contract_edf = ;

### List of workstations to include in the monitor; by default the monitor will only monitor servers under the MSP contact

SET @included_workstations = '';

### List ofservers to exclude from the monitor

SET @excluded_servers = '';

 

CREATE TEMPORARY TABLE IF NOT EXISTS offline3471420 (INDEX (ComputerID,sc_guid)) (SELECT c.ComputerID

,c.LastContact

,hb.LastHeartbeatTime

,IF(sc.SessionGUID IS NULL,'',sc.SessionGUID) AS sc_guid

,IF(sc.SessionGUID IS NULL,'',CONCAT('CMD!!!/C "powershell -command "& "Invoke-RestMethod -Method Post -Uri \'',@sc_url,'\' -Body \'[\\"',@accesskey,'\\", \\"',sc.SessionGUID,'\\", \\"',@reset_command,'\\", \\"10\\"]\' -ContentType \'application/json\'";"')) AS sc_cmd

FROM `extrafielddata` edf

LEFT JOIN computers c ON c.ComputerID = edf.ID

LEFT JOIN plugin_screenconnect_scinstalled sc ON sc.ComputerID = edf.ID

LEFT JOIN heartbeatcomputers hb ON hb.ComputerID = edf.ID

WHERE (c.OS LIKE '%Server%' OR FIND_IN_SET(c.Name, @included_workstations) <> 0)

AND FIND_IN_SET(c.Name, @excluded_servers) = 0

AND edf.ExtraFieldID = @contract_edf

AND edf.Value

AND (c.LastContact < @date_contact_reset OR hb.LastHeartbeatTime < @date_heartbeat_reset));

 

CREATE TEMPORARY TABLE IF NOT EXISTS reset3471420 (INDEX (ComputerID)) (SELECT cmdmax.ComputerID, cmdmax.LastReset, cmd.Output AS LastResetOutput

FROM (SELECT o.ComputerID, o.sc_cmd, MAX(cmd.DateUpdated) AS LastReset

FROM offline3471420 o

LEFT JOIN commands cmd ON cmd.Parameters = o.sc_cmd

WHERE cmd.ComputerID = @sc_id

GROUP BY o.ComputerID) cmdmax

LEFT JOIN commands cmd ON cmd.Parameters = cmdmax.sc_cmd AND cmd.DateUpdated = cmdmax.LastReset);

 

INSERT IGNORE INTO commands (ComputerID,Command,Parameters,Output) SELECT @sc_id, 2, o.sc_cmd, ''

FROM offline3471420 o

LEFT JOIN reset3471420 r USING (ComputerID)

WHERE r.LastReset IS NULL

OR r.LastReset < o.LastContact

OR r.LastReset < DATE_ADD(NOW(),INTERVAL -@reset_frequency MINUTE)

OR (o.LastContact > @date_contact_alert AND o.LastHeartbeatTime > @date_heartbeat_alert);

 

CREATE TEMPORARY TABLE IF NOT EXISTS result3471420 (INDEX (ComputerID)) (SELECT o.ComputerID

,o.LastContact

,o.LastHeartbeatTime AS LastHeartbeat

,IF(r.LastReset IS NULL,'>24h or Never',r.LastReset) AS LastReset

,IF(r.LastResetOutput IS NULL,'',r.LastResetOutput) AS LastResetOutput

,o.sc_guid

,o.sc_cmd

FROM offline3471420 o

LEFT JOIN reset3471420 r USING (ComputerID)

WHERE (o.LastContact < @date_contact_alert OR o.LastHeartbeatTime < @date_heartbeat_alert));

 

DROP TABLE offline3471420;

DROP TABLE reset3471420;

 

SELECT

r.LastContact AS TestValue,

r.LastHeartbeat AS IDentityField,

r.ComputerID,

r.LastReset,

r.LastResetOutput,

r.sc_guid,

r.sc_cmd,

c.Uptime,

c.Name AS ComputerName,

l.Name AS LocationName,

cl.Name AS ClientName,

c.Username,

c.OS,

c.IdleTime,

c.ComputerID AS ComputerID,

l.LocationID AS LocationID,

cl.ClientID AS ClientID,

acd.NoAlerts,

acd.UpTimeStart,

acd.UpTimeEnd

FROM result3471420 r

LEFT JOIN computers c USING (ComputerID)

LEFT JOIN clients cl USING (ClientID)

LEFT JOIN locations l USING (LocationID)

LEFT JOIN AgentComputerData acd USING (ComputerID)

ORDER BY cl.Name, l.Name;

 

DROP TABLE result3471420;

Edited by Guest

Share this post


Link to post
Share on other sites
Ah.. I do know I could use a list of screen connect agents offline currently that I could match to computerID's inside of LabTech. This would allow me to make a list that would work in the opposite way and restart SC agents from LabTech if they went south. Not that I suspect that is as much of an issue..

 

Would it be beneficial to have a function for instance OfflineAgents and OnlineAgents that would return an array of GUIDs?

Share this post


Link to post
Share on other sites

This is another rawsql monitor that finds agent that are unable to finish executing command.

The monitor doesn't need an alert template, because the reset command is pushed through the INSERT to the commands table.

==================================================================================================

### minimum last update date on running commands before sending a reset command through ScreenConnect; how long the commands are allowed to execute

SET @date_command_reset = DATE_ADD(NOW(),INTERVAL -60 MINUTE);

### number of old commands that triggers a reset command through ScreenConnect

SET @count_command_reset = 2;

### frequency for sending the reset commands; number of minutes to wait before sending another reset through ScreenConnect

SET @reset_frequency = 60;

### get ID of the ScreenConnect server; variable can be set to a specific ComputerID, but you will have to update the monitor if you reinstall your ScreenConnect agent; make sure the server can execute "Invoke-RestMethod" (powershell v2 required); it doesn't have to be a ScreenConnect server but it is recommended for security reasons

SET @sc_id = (SELECT c.ComputerID FROM computers c WHERE c.Name = '');

### ScreenConnect RMM Plus access key

SET @accesskey = '';

### command execution url for ScreenConnect

SET @sc_url = (SELECT CONCAT(URL,':',Port,'/App_Extensions/8e78224d-79db-4dbb-b62a-833276b46c6e/Service.ashx/ExecuteCommand') FROM plugin_screenconnect_config);

### command to run through ScreenConnect

SET @reset_command = 'sc stop LTSvcMon & sc stop LTService & ping localhost -n 5 & taskkill /IM LTTray.exe /F /T & taskkill /IM LTSvcMon.exe /F /T & taskkill /IM LTSVC.exe /F /T & sc start LTSvcMon & sc start LTService';

### List of command IDs to exclude from the monitor; some of the commands are normal to execute for a long time

SET @excluded_commands = '';

 

CREATE TEMPORARY TABLE IF NOT EXISTS issue3471958 (INDEX (ComputerID)) (SELECT c.ComputerID

,COUNT(c.ComputerID) AS CmdCount

FROM commands cmd

LEFT JOIN computers c USING (ComputerID)

WHERE cmd.Status = 2

AND FIND_IN_SET(cmd.Command, @excluded_commands) = 0

AND cmd.DateUpdated < @date_command_reset

AND c.LastContact < DATE_ADD(NOW(),INTERVAL -8 MINUTE)

GROUP BY cmd.ComputerID

HAVING CmdCount >= @count_command_reset);

 

CREATE TEMPORARY TABLE IF NOT EXISTS sccmd3471958 (INDEX (ComputerID,sc_guid)) (SELECT i.ComputerID

,i.CmdCount

,IF(sc.SessionGUID IS NULL,'',sc.SessionGUID) AS sc_guid

,IF(sc.SessionGUID IS NULL,'',CONCAT('CMD!!!/C "powershell -command "& "Invoke-RestMethod -Method Post -Uri \'',@sc_url,'\' -Body \'[\\"',@accesskey,'\\", \\"',sc.SessionGUID,'\\", \\"',@reset_command,'\\", \\"10\\"]\' -ContentType \'application/json\'";"')) AS sc_cmd

FROM issue3471958 i

LEFT JOIN plugin_screenconnect_scinstalled sc USING (ComputerID));

 

DROP TABLE issue3471958;

 

CREATE TEMPORARY TABLE IF NOT EXISTS reset3471958 (INDEX (ComputerID)) (SELECT cmdmax.ComputerID, cmdmax.LastReset, cmd.Output AS LastResetOutput

FROM (SELECT sc.ComputerID, sc.sc_cmd, MAX(cmd.DateUpdated) AS LastReset

FROM sccmd3471958 sc

LEFT JOIN commands cmd ON cmd.Parameters = sc.sc_cmd

WHERE cmd.ComputerID = @sc_id

GROUP BY sc.ComputerID) cmdmax

LEFT JOIN commands cmd ON cmd.Parameters = cmdmax.sc_cmd AND cmd.DateUpdated = cmdmax.LastReset);

 

INSERT IGNORE INTO commands (ComputerID,Command,Parameters,Output) SELECT @sc_id, 2, sc.sc_cmd, ''

FROM sccmd3471958 sc

LEFT JOIN reset3471958 r USING (ComputerID)

WHERE r.LastReset IS NULL

OR r.LastReset < DATE_ADD(NOW(),INTERVAL -@reset_frequency MINUTE);

 

CREATE TEMPORARY TABLE IF NOT EXISTS result3471958 (INDEX (ComputerID)) (SELECT sc.ComputerID

,sc.CmdCount

,IF(r.LastReset IS NULL,'>24h or Never',r.LastReset) AS LastReset

,IF(r.LastResetOutput IS NULL,'',r.LastResetOutput) AS LastResetOutput

,sc.sc_guid

,sc.sc_cmd

FROM sccmd3471958 sc

LEFT JOIN reset3471958 r USING (ComputerID));

 

DROP TABLE sccmd3471958;

DROP TABLE reset3471958;

 

SELECT

r.CmdCount AS TestValue,

r.ComputerID AS IDentityField,

r.CmdCount,

r.LastReset,

r.LastResetOutput,

r.sc_guid,

r.sc_cmd,

c.Uptime,

c.Name AS ComputerName,

l.Name AS LocationName,

cl.Name AS ClientName,

c.Username,

c.OS,

c.IdleTime,

c.ComputerID AS ComputerID,

l.LocationID AS LocationID,

cl.ClientID AS ClientID,

acd.NoAlerts,

acd.UpTimeStart,

acd.UpTimeEnd

FROM result3471958 r

LEFT JOIN computers c USING (ComputerID)

LEFT JOIN clients cl USING (ClientID)

LEFT JOIN locations l USING (LocationID)

LEFT JOIN AgentComputerData acd USING (ComputerID)

ORDER BY cl.Name, l.Name;

 

DROP TABLE result3471958;

Share this post


Link to post
Share on other sites

Is it possible to add a function to end a session to the RMM+ plugin? We'd like to be able to script that when agents are removed.

Share this post


Link to post
Share on other sites
Is it possible to add a function to end a session to the RMM+ plugin? We'd like to be able to script that when agents are removed.

 

Added new EndSession function. Keep a look out for version 1.0.7 showing up as an available update in the coming days.

Share this post


Link to post
Share on other sites

I created a cleanup script that removes dead entries from both databases.

When setting it up, set both the ID for the labtech server and the access key for RMM+ in the global variables.

 

The script defaults to cleaning up agents that haven't checked in for the past month ( -2592000 seconds ) and will also remove entries from the plugin_screenconnect tables for the SessionID that is being removed.

 

 

 

In order to use this, go to the dashboard and set a scheduled client script ( I set mine up to be weekly, but choose whatever interval you prefer ).

59ec9443be627_RMMScreenConnectCleanup.png.deda599746ee378bd3a18a95c4d48054.png

ScreenConnect Access Session Cleanup.zip

59ec9443c1334_ScheduledClientScript.png.d5969c91ce5daf0f5647681002c10a85.png

Share this post


Link to post
Share on other sites

How would I run a powershell command against on offline agent if we have a cloud hosted LT server? I can't run the LTServer Shell Execute command. We don't have admin permissions to run powershell on the cloud hosted server.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...