I'm trying to use a custom Python script to count some files in a directory. In the code, I use this to count said files
file_count = sum((len(f) for _, _, f in os.walk("Q:\some\location")))
Testing with the included Python build works great, I am able to get an accurate count. However, when PRTG runs the script, the output is always wrong (always at 0 files, no matter how many are there). Even when I put out the log, the output was still wrong in the log. Then, to make absolutely sure, I copied-pasted the line in the log labeled Command Line:
into Powershell, and got the correct response. Somehow, only when PRTG runs it, I get the wrong values. The full script is located below:
import sys import json import os # get CustomSensorResult from paepy package from paepy.ChannelDefinition import CustomSensorResult if __name__ == "__main__": # start by counting the number of files in the directory file_count = sum((len(f) for _, _, f in os.walk("Q:\somewhere\over\there"))) if file_count == 0: result = CustomSensorResult("No error logs found") else: result = CustomSensorResult("One or more error logs detected") result.add_channel(channel_name="Connection Errors", is_limit_mode=True, limit_max_error=10, unit="Percent", value=file_count, is_float=False, primary_channel=True) print(result.get_json_result())
Add comment