Hello, i´am new in this python script thing, and i´am trying to show the name of my cluster owner with the following script.

I dont know how to return the information.... Does anyone can help me?

  1. -*- coding: UTF-8 -*- import os import json

def func_cluster(): os.system(r'C:\Users\victor.salomao\Downloads\PSTools\PsExec
mqprod01 -u username -p password cmd.exe /v /c echo ^%computername^% > ClusterOwner.log')

arquivo = open('ClusterOwner.log') cluster_owner = arquivo.read()

arquivo.close()

estrutura = {"prtg": {"result": [{"channel": "First channel", "value": ""}]}} estrutura['prtg']['result'][0]['value'] = cluster_owner

with open('data.json', 'w') as arquivo: json.dump(estrutura, arquivo)

with open('data.json', 'r') as f: data = json.load(f)

return data

func_cluster()


Article Comments

Hello Giacometti,

Thank you very much for your knowledge base post.

Please check either the exemplary expected standard output format for XML or JSON which can be found in PRTG under Setup | PRTG API | Custom Sensors | ADVANCED SCRIPT AND HTTP DATA SENSORS | XML/JSON Return Format.
Alternatively, please check the example Python file (sensore_example.py) located in C:\Program Files (x86)\PRTG Network Monitor\Custom Sensors\python on your PRTG Core Server.

Best regards,
Sebastian


May, 2017 - Permalink

I got it!!!

Do you know if PRTG stores the variables of script in memory? i changed some values and still showing the old ones.

i already excluded the sensor and added a new one but nothing changed.


May, 2017 - Permalink

Hello Giacometti,

well done! No, results are not cached in the memory. Please enable Write EXE result to disk in the sensor settings. This function will store the last result received from the script with the file name "Result of Sensor [ID].txt" to the "Logs (Sensors)" directory (on the Master node, if in a cluster). This is for debugging purposes. The file will be overridden with each scanning interval.
Please check the output in this log file, I assume that it matches with the values shown in PRTG.

Best regards,
Sebastian


May, 2017 - Permalink