docs - adding more debug

silversword411 committed Jun 25, 2022 at 10:42 UTC 7100b07b193ad83aa50f9f5b6c8ff7354ca7e68d
1 file changed +95 -5
docs/docs/meshcentral/debugging.md
+95 -5
@@ -6,7 +6,22 @@ Make sure you understand how MeshCentral works with your browser using chrome de
6 <iframe width="320" height="180" src="https://www.youtube.com/embed/3vI4URd3VzU" frameborder="0" allowfullscreen></iframe>
7 </div>
8
9 -## Enabling trace in your browser Dev Tools
9 +## MeshCentral Server
10 +
11 +### Useful config.js settings
12 +
13 +<https://github.com/Ylianst/MeshCentral/blob/master/meshcentral-config-schema.json>
14 +
15 +```json
16 +"AgentsInRAM": false,
17 +"AgentUpdateBlockSize": 2048,
18 +"agentUpdateSystem": 1,
19 +"noAgentUpdate": 1,
20 +"WsCompression": false,
21 +"AgentWsCompression": false,
22 +```
23 +
24 +### Enabling trace in your browser Dev Tools
25
26 `Trace=1` as a parameter in chrome dev tools for debugging
27
@@ -34,7 +49,7 @@ If you want to change node to meshcentral in journalctl, add this to /etc/system
49 SyslogIdentifier=meshcentral
50 ```
51
37 -## Server: Logging it all
52 +### Logging it all
53
54 To log everything that's possible, prepare the log directory.
55
@@ -84,7 +99,7 @@ You'll then have 3 files:
99
100 `log.txt` will now log everything in the Trace tab
101
87 -## Restricting server to specific IP(s)
102 +### Restricting server to specific IP(s)
103
104 When doing debugging on my development server, I use this line in the settings section to block all agent connections except the agent I want:
105
@@ -94,16 +109,91 @@ When doing debugging on my development server, I use this line in the settings s
109
110 Of course, this is just for debugging.
111
97 -## Finding system ID types
112 +### Finding system ID types
113
114 <https://serverurl/meshagents> aka trying figure out what this is
115
116 ![ID](images/determine-id.png)
117
103 -## Determine Agent capabilities
118 +### Pull down cert .crt file from internet
119 +
120 +[See #1662](https://github.com/Ylianst/MeshCentral/issues/1662#issuecomment-666559391) We have run into this challenge before, where our .crt file expired and then all our agents were unable to connect. In our case, the TLS cert was available on the internet, and thus, we were able to use these commands to update it:
121 +
122 +```bash
123 +echo -n \| openssl s_client -connect yourdomain.com:443 2> /dev/null\| sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > /opt/meshcentral/meshcentral-data/webserver-cert-public.crt
124 +service meshcentral restart
125 +```
126 +
127 +## MeshAgent
128 +
129 +### Determine Agent capabilities
130
131 On the server goto the agents console tab. Type:
132
133 ```
134 info
135 ```
136 +
137 +### Useful MeshAgent.msh flags
138 +
139 +<https://github.com/Ylianst/MeshAgent/blob/master/meshcore/agentcore.h#L190>
140 +
141 +```json
142 +controlChannelDebug=1
143 +logUpdate=1
144 +```
145 +
146 +### Obtain generated .msh File
147 +
148 +If you need a trick to get the .msh file, you can add ?debug=1 to the URL and click "Add Agent", there will be an extra link to download it.
149 +
150 +### MeshAgent Commands
151 +
152 +```
153 +MeshAgent run
154 +MeshAgent dbTool.js list
155 +```
156 +
157 +Forcing Core version from Cmdline
158 +
159 +* Download meschore.js and rename to CoreModule.js and put it alongside MeshAgent.exe
160 +* Stop MeshAgent service
161 +* Run `MeshAgent.exe dbTool.js import CoreModule`
162 +
163 +### On the fly Patching MeshAgent
164 +
165 +[MeshAgent#89 (comment)](https://github.com/Ylianst/MeshAgent/issues/89#issuecomment-949901720)
166 +
167 +There are two ways to do this... When debugging, and making changes, you can modify the .js file directly, and just save it in the same folder as the agent binary... The agent will use the .js file from disc if it's there, if it's newer than the one compiled in the binary. You don't even need to restart the agent. You can just clear the core, and reload the core.....
168 +
169 +When you are satisfied with your changes to the .js file, you can use the clipboard, in the following fashion:
170 +
171 +```bash
172 +meshagent -exec "require('clipboard').nativeAddCompressedModule('foo');process.exit();"
173 +```
174 +
175 +if the file you modified isn't in the same folder as the agent binary, you can use the following command if you don't want to move the file, and edit it directly in the modules folder:
176 +
177 +```bash
178 +meshagent -exec "setModulePath('pathToFolder');require('clipboard').nativeAddCompressedModule('foo');process.exit();"
179 +```
180 +
181 +This command is just like the previous, except it searches for modules in the path specified.
182 +
183 +Just substitute foo, with the name of the module that you modified. It will load the module from disc, compress it, and save it into the clipboard.. So you can just load up your editor for ILibDuktape_Polyfills.c, and find where that particular module is defined... and paste directly from the clipboard... The clipboard will contain all the necessary C code to uncompress and load the module.
184 +
185 +If the compressed result is relatively long, it will auto break it up into multiple lines to work around an issue with visual studio's maximum string literal limitations.
186 +
187 +### Agent Debugging using MeshCore JS Debugger
188 +
189 +[(#119)](https://github.com/Ylianst/MeshAgent/issues/119) How to test changes to the meshagent and recompile them.
190 +
191 +* Copy duktape-debugger.js to the mesh directory on the target machine.
192 +* From the console tab of the agent, enter this command, substituting the port number you want to use instead of 9999
193 +`eval "attachDebugger({ webport: 9999 })"`
194 +
195 +Then open your browser to http://localhost:9999 or whatever port you used.
196 +
197 +!!!note
198 + If you pause the debugger, and happen to forget about it, the agent will automatically kill itself and restart because it will think that a thread is stuck. Default debugger timeout is 10 minutes, you may find a log entry saved to disk saying "Microstack Thread STUCK", or something similar.
199 +