MISP / misp-book

User guide of MISP
https://www.circl.lu/doc/misp/
255 stars 103 forks source link

Document PHP developer debugging / troubleshooting techniques #254

Open chrisinmtown opened 3 years ago

chrisinmtown commented 3 years ago

Document ways to see what the MISP PHP code is doing. All of the following require modifying php files:

(1) Change MISP server setting Security.debug from 0 to 1 or (caution) 2; then use function debug(). But as @iglocska points out, this will start pasting the debug messages directly in the pages you query and the API will include them too (be careful, the result will be invalid JSON for obvious reasons)

(2) Change MISP server setting Security.admin_debug from 0 to 1. But this is black magic to me and might be buggy, see https://github.com/MISP/MISP/issues/7131

(3) Write information directly to a file with this function:

file_put_contents('/path/to/output/file', json_encode($myvar) . PHP_EOL, FILE_APPEND));

(4) Use PHP method like this:

CakeLog::write('debug', 'Got here');

as described here:

https://book.cakephp.org/2/en/development/debugging.html#using-logging-to-debug

CakeLog is enabled by the following statement in /var/www/MISP/app/Config/bootstrap.php; it's present in bootstrap.default.php in the tip of "main" branch, double-check your instance to be sure:

App::uses('CakeLog', 'Log');

Gitter discussion here:

https://gitter.im/MISP/Support?at=605c80ba9ebdfd1640998e56

Wachizungu commented 3 years ago

You can enable MISP debug mode for site admins only (debug level will than be 1 for site admins unless the global level is 2). This prevents normal users having the debug styling in the GUI at the same time (can be useful for operational instances).

https://github.com/MISP/MISP/commit/ab26eafd632da3f8e08f78fadaa7a5614ea470f9

Wachizungu commented 3 years ago

For STIX ingestion errors: /var/www/MISP/app/tmp/logs/exec-errors.log