I am trying to develop a custom sensor using the advanced python script sensor. The script should list the folders and files of a subdirectory located at a network shared windows folder. The folder is mapped as a network drive in the prtg server.
The script works correctly when executed from a cmd window on the prtg server but when executed from the sensor it can not find/access the network shared folder.
I have tried using the mapped drive and also unc paths but with no luck.
I have configured the sensor to run on the local probe using the Administrator Windows user (the same that the cmd uses).
bellow you can find the base script I am using:
# -*- coding: utf-8 -*- import json import sys import os from prtg.sensor.result import CustomSensorResult from prtg.sensor.units import ValueUnit if __name__ == "__main__": try: # data = json.loads(sys.argv[1]) path_temp = "\\\\HOST\\folder\\path" #path_temp = "Z:\\folder\\path" #print(path_temp+" "+str(os.path.exists(path_temp))+" "+os.getlogin()) csr = CustomSensorResult(text=path_temp+" "+str(os.path.exists(path_temp))+" "+os.getlogin()) print(csr.json_result) except Exception as e: csr = CustomSensorResult(text="Python Script execution error") csr.error = "Python Script execution error: %s" % str(e) print(csr.json_result)
Result from cmd:
{"prtg": {"text": "Z:\\workswift True Administrator", "result": [{"Channel": "Percentage", "Value": 87, "Unit": "Percent", "SpeedSize": "One", "VolumeSize": "One", "SpeedTime": "Second", "Mode": "Absolute", "LimitMaxError": "90", "LimitMode": 1, "LimitMinError": "10", "LimitErrorMsg": "Percentage too high"}, {"Channel": "Response Time", "Value": 4711, "Unit": "TimeResponse", "SpeedSize": "One", "VolumeSize": "One", "SpeedTime": "Second", "Mode": "Absolute"}]}}
Result from PRTG Sersor
{"prtg": {"text": "Z:\\workswift False Administrator", "result": [{"Channel": "Percentage", "Value": 87, "Unit": "Percent", "SpeedSize": "One", "VolumeSize": "One", "SpeedTime": "Second", "Mode": "Absolute", "LimitMaxError": "90", "LimitMode": 1, "LimitMinError": "10", "LimitErrorMsg": "Percentage too high"}, {"Channel": "Response Time", "Value": 4711, "Unit": "TimeResponse", "SpeedSize": "One", "VolumeSize": "One", "SpeedTime": "Second", "Mode": "Absolute"}]}}
the difference is that when run from prtg the os.path.exists(path_temp) resolves to False but not true.
PRTG VERSION: latest Python Version: PRTGs Installation: Windows Server 2016
Thank you in advance
Add comment