PRTG custom script returns valid XML but dashboard complains

paxdiablo picture paxdiablo · Apr 29, 2015 · Viewed 7.6k times · Source

I have a PRTG custom script in the EXEXML directory which has been configured within the PRTG dashboard.

When I run it manually, I get the following output which, as far as I'm aware, is perfectly valid:

<prtg>
  <result>
    <channel>MaxCPUWL1</channel>
    <value>113</value>
  </result>
  <text>OK</text>
</prtg>

In fact, I have another script which pretty much generates the same format, including identical CR/LF sequences at the end of the lines:

<prtg>
  <result>
    <channel>Item age</channel>
    <value>14</value>
  </result>
  <text>April 15, 2015</text>
</prtg>

I've even checked in detail the output of both to ensure I haven't done something stupid, like use channe1 (with a one) instead of channel (with an L).

And yet, with the first one, I keep getting in the dashboard:

XML: The returned xml does not match the expected schema. (code: PE233) -- JSON: The returned json does not match the expected structure (Invalid JSON.). (code: PE231)

What could be causing this problem?

Answer

paxdiablo picture paxdiablo · Apr 30, 2015

If you edit the properties of the sensor, you can capture the output of the executable under certain conditions:

o Discard EXE result
o Write EXE result to disk
o Write EXE result to disk in case of error

A good way to see what your custom sensor is doing is to set that middle option (normally the first is set) and then go and look for the file Result of Sensor XXXX.txt (where XXXX is the sensor ID) in the sensor logs directory, such as:

C:\ProgramData\Paessler\PRTG Network Monitor\Logs (Sensors)

That should show you any errors that are occurring in the script, or at least the output that is confusing the PRTG sensor output analysis.

In this particular case, it was having trouble running the pscp command to go out and retrieve a file from a remote server, but this approach should hopefully be able to evaluate and fix a wide variety of problems.