What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general.

Learn more

PRTG Network Monitor

Intuitive to Use. Easy to manage.
More than 500,000 users rely on Paessler PRTG every day. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free Download

Top Tags


View all Tags

SSH Script Advanced - Invalid JSON

Votes:

0

Hi,

When it comes to this sensor and Linux/JSON I am fairly new so lease bare with me on this.

Goal: Is to get the size of a directory on a volume that is used by a CentOS server. I only have SSH access to the server from PRTG.

Script code dirSize=$(du -sh /home/data/sites/portal-acceptation/www/media/orders/ | awk '{print $1}') echo 0:$dirSize:OK

Running the script manually on the server gives me, what I think is the correct format [root@pvh scriptsxml]# bash dirsize.sh 0:133G:OK [root@pvh scriptsxml]#

The 133G is the size of the folder as I am writing this.

The sensor keeps returning 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)

Where did I took a wrong exit?

centos json ssh

Created on Sep 15, 2017 2:19:42 PM



2 Replies

Votes:

0

Hi there,

It seems that you are using the Advanced Sensor which expects a XML/JSON result. Please use the normal "SSH Script" sensor instead or change the result to JSON/XML according to PRTG documentation under "Setup > PRTG API > Custom Sensors".

Best regards.

Created on Sep 18, 2017 9:10:20 AM by  Dariusz Gorka [Paessler Support]



Votes:

0

Actually, I was working on that this morning... ;-)

Got it working with the SSH Script sensor

{{{dirSize=$(du -sh /location_on_disk/ | awk '{print $1}' | sed 's/[G]$')

echo "0:$dirSize:OK"}}}

This code is now working for me and it is reporting the size of the folder. Return code and message is not important for now.

The | sed 's/[G]$' behind it was to trim the G from the response. The sensor did not like that.

Thanks for helping out

Created on Sep 18, 2017 10:07:09 AM




Disclaimer: The information in the Paessler Knowledge Base comes without warranty of any kind. Use at your own risk. Before applying any instructions please exercise proper system administrator housekeeping. You must make sure that a proper backup of all your data is available.