When performing a custom sensor and attempting to display the value of a variable, it shows 0.

# Obtener el tamaño del archivo 
$SizeArchivo = (Get-Item $ServerArchivo).Length

#mandar datos a PRTG
"<prtg>"
    "<result>"
    "<channel>Free size disc</channel>"
    "<unit>BytesDisk</unit>"
    "<value>$SizeArchivo</value>"
    "</result>"
"</prtg>"

Article Comments

Attention: This article is a record of a conversation with the Paessler support team. The information in this conversation is not updated to preserve the historical record. As a result, some of the information or recommendations in this conversation might be out of date.

What is the value you are especting to receive?

For example, if the value you are expecting is a "string", then the issue in this code is that the value of the $SizeArchivo variable is not being properly formatted as a string, which can cause it to display as 0 in the output. To fix this, you can explicitly convert the value to a string using the ToString() method, like so:

# get file size
$SizeArchivo = (Get-Item $ServerArchivo).Length


#send data to PRTG
"<prtg>"
    "<result>"
    "<channel>Free size disc</channel>"
    "<unit>BytesDisk</unit>"
    "<value>" + $SizeArchivo.ToString() + "</value>"
    "</result>"
"</prtg>"

By using the ToString() method, the value of $SizeArchivo will be properly converted to a string that can be displayed correctly in the PRTG output.


Apr, 2023 - Permalink

El problema que veo es que si muestra el dato de tamaño del archivo al monitorear un archivo local (en el servidor del PRTG) pero cuando quiero monitorear un archivo de otro servidor me muestra el dato en 0, el usuario utilizado es administrador de dominio, ejecuto este script en powershell y me muestra bien los datos, pero en PRTG me da el valor en 0

----------------------------ENGLISH---------------------------------------------------

The problem I see is that when monitoring a local file (on the PRTG server) it displays the file size data correctly. However, when trying to monitor a file on another server, it shows the data as 0. The user being used is a domain administrator, and when I run this script in PowerShell, it shows the data correctly. But in PRTG, it gives me a value of 0.


Jun, 2023 - Permalink

LISTO, el problema era la opcion: Choose a security context to run the EXE/script file.


Jun, 2023 - Permalink