microsoft / mdatp-xplat

Microsoft Defender for macOS/Linux - config samples, auxiliary tools
MIT License
187 stars 188 forks source link

Fix high_cpu_parser.py (looking for wrong key) #100

Closed JonathanBrockhausen closed 1 year ago

JonathanBrockhausen commented 1 year ago

This script is currently broken with the newest version of mdatp. It throws this error:

Traceback (most recent call last): File "C:\Users\\mde-analyzer\high_cpu_parser_old.py", line 35, in lines = sorted(vals, key=lambda k: int(k['total_files_scanned']), reverse=True) File "C:\Users\\mde-analyzer\high_cpu_parser_old.py", line 35, in lines = sorted(vals, key=lambda k: int(k['total_files_scanned']), reverse=True) KeyError: 'total_files_scanned'

The output from the diagnostics function of mdatp returns data formatted as such:

{"id":807,"isActive":true,"maxFileScanTime":"0","name":"networkd-dispat","path":"/usr/bin/python3.10","resourceScanTime":"0","scannedFilePaths":null,"totalEventsSent":"0","totalFilesScanned":"0","totalScanTime":"0"}

The python script looks for the key 'total_files_scanned' while the output returns it in camelCase, it seems that the agent was changed but in any case, the script can be fixed by changing the total_files_scanned to totalFilesScanned