Ylianst / MeshCentral

A complete web-based remote monitoring and management web site. Once setup you can install agents and perform remote desktop session to devices on the local network or over the Internet.
https://meshcentral.com
Apache License 2.0
4.27k stars 571 forks source link

Applying agent customizations after installation #3793

Open smartekIT opened 2 years ago

smartekIT commented 2 years ago

HI, I know if I go to a device console and issue a command "agentupdate" then it should update that agent. Well the above didn't work for me, i even tried to push the default server core to one agent but I clearly see in that pc that the .mesh file didn't get any modification.

So, I thought i could do force reinstall or update or upload server core to all agents at once, but couldn't find such option. My story started when i decided to change the displayname of the service (not the service name) in config.js and then roll those changes out to all agents. unfortunately I can't find how to roll those changes out, or if there is an option for that which i'm not aware of. Thanks in advanced for guiding me to the correct way of doing it.

smartekIT commented 2 years ago

by the way I'm using v1.0.0 I just noticed after doing "agentupdate" in the console for that device it did update it, based on the log file in the mesh directory on the device:

[2022-01-09 02:44:51 AM] [80645B8D669A2A74] ..\microstack\ILibParsers.c:10746 (0,0) SelfUpdate -> Current Version: f4b1a7daa7bad99bda1eb62d0756d80792327a44
[2022-01-09 02:44:51 AM] [80645B8D669A2A74] ..\microstack\ILibParsers.c:10746 (0,0) SelfUpdate -> Updating and restarting service...
[2022-02-22 09:34:48 PM] [C0A2CB8FEFAA7414] ..\microstack\ILibParsers.c:10805 (0,0) SelfUpdate -> Current Version: 22744773169b32a8b7c4382dba41a897b5c2d63c

but how to force update or reinstall for all agents is still a mystery for me :) Also when an agent get updated, shouldn't the new values in config.js take place? like the new service DisplayName and CompanyName

      "agentCustomization": {
        "displayName": "Example Agent",
        "description": "Meshcentral® Agent , management system.",
        "companyName": "Company Name Pty Ltd",
        "serviceName": "meshagent",
        "installText": "some text",
        "image": "agent-logo.png",
        "fileName": "MeshAgent",
        "foregroundColor": "#FFFFFF",
        "backgroundColor": "#003669"
      },
krayon007 commented 2 years ago

In the console tab, if you type versions it will tell you all the version info, to see if the agent updated... As far as those customization fields. Most of those only apply to newly installed agents, because most of those fields are related to the installer and the info passed to the windows service manager... Those usually can't be applied to a service after it's already been installed unless you uninstall and then reinstall.

krayon007 commented 2 years ago

We're looking into being able to apply some of those settings after the fact, such as color, translations, etc.

Ylianst commented 2 years ago

So, the proper ask here is not to ask that agents be reinstalled but rather that agent customization be applied after agent installation. This is something Bryan and I can work on.

smartekIT commented 2 years ago

Thank you guys for this, how about having an option to force update for all agents at once instead of individual agents via console tab? is that possible?

VINISHVV commented 2 years ago

Thank you guys for this, how about having an option to force update for all agents at once instead of individual agents via console tab? is that possible?

@smartekIT - Force agent update option is available in Meshcentral from v0.7.70. Please refer here

smartekIT commented 2 years ago

Thanks @VINISHVV, stupid me I didn't see that. I wish we have the same option for re-install agent so it applied all the new agent customization setting by installing over silently.

with the current situation the only option I think we have is to push for powershell script and execute it.

for example:

$progresspreference = 'silentlyContinue'
[Net.ServicePointManager]::SecurityProtocol = "Tls12, Tls11, Tls, Ssl3"
Invoke-WebRequest 'https://example.com/meshagents?id=4&meshid=XXXXXXXXXXXXXXXXXXX&installflags=0' -OutFile C:\MeshAgent_Setup.exe
$progressPreference = 'Continue'
Start-Process C:\MeshAgent_Setup.exe -Wait -ArgumentList '-fullinstall'
Remove-Item -LiteralPath C:\MeshAgent_Setup.exe -force
exit
Ylianst commented 2 years ago

So right, forcing an agent update will not update the .msh file and so, will not update customizations. Bryan and I need to work on this. We have other ways of sending that data to the agent.

smartekIT commented 2 years ago

So right, forcing an agent update will not update the .msh file and so, will not update customizations. Bryan and I need to work on this. We have other ways of sending that data to the agent.

But I tried the above script and it did update all my customization, as long as the service name and company name still the same, it will update the reset.

i even tried that manually by downloading the new agent into a machine, then after opening it i click on update and it did the same provided that i click on update button on the new agent installer i downloaded, not he update button on the installed agent in the program directory.

i know you guys have better way of doing it and i was hopping for that, but i at least i tell you exactly how it worked for me through that script.

Thanks heaps guys for such a wonderful support.

Ylianst commented 2 years ago

Ha right! A full reinstall of the agent to update the .MSH will work. You could also have just update the meshagent.msh with new customizations and restarted the agent. In any case, I think it's reasonable that if customizations are changed on the server, they propagate to the agents so, we will do some of that in the future.

smartekIT commented 2 years ago

Ha right! A full reinstall of the agent to update the .MSH will work. You could also have just update the meshagent.msh with new customizations and restarted the agent. In any case, I think it's reasonable that if customizations are changed on the server, they propagate to the agents so, we will do some of that in the future.

Thanks. then I will follow your advise until this feature is ready. here what I would use to update meshagent.msh :

#requires -Version 1.0
$file = "$env:SystemDrive\Program Files\MeshAgent\meshagent.msh"
$content = (Get-Content -Path $file -ReadCount 0).Replace('displayName=OLDName','displayName=NewName')
Set-Content -Path $file -Value $content -Encoding UTF-8
net stop meshagent
net start meshagent
exit
smartekIT commented 2 years ago

hi @Ylianst , To have that option 'Force Agent Update' in the Group Action button in the devices Page, we need to disable the agent automatic update in the config.js :

  "settings": {
    "noAgentUpdate": "1"
  }

can we make it to have that option always showing regardless of automatic agent update settings please? because some times even if we have the automatic agent update enabled, we still need to force update some agents for fixing them for many reasons like updating a new agent binary without code sign ssl lock ...etc.

Thanks heaps

smartekIT commented 2 years ago

@Ylianst , @krayon007 , I know you guys are busy, but I hope you cooking something in the background regarding this.

Thanks heaps

si458 commented 7 months ago

i have been working on a feature which extends the msh command in the console tab! what do people thing? its only a start but we can integrate more at a later date

Proper usage: msh [get|set|delete]
msh get MeshServer
msh set abc "xyz"
msh delete abc

self explanitory really, get the value meshserver from the msh and tell me what it is set the value abc in msh to xyz delete the value abc in msh

you can also just call msh still to get the whole msh file thats loaded in memory in JSON form

i have also found you need to service restart to get things to apply 30% of the time (no idea why?)

also you cannot use JSON in the console set command! so u cant change the translation line in msh for example due to the way meshcore phases the console command you send

this would allow you to change the displayName, image, etc in the msh file which is used for customisation