i have a problem with ssh script and ssh advanced script the connection return me a strange simbol and the ssh advanced go in error for junk after </prtg> the junk is [1]+ Done(127) eTXEJ@Rv

this is the log

[INFO][3/11/2021 4:36:07 PM] Opening Connection
[INFO][3/11/2021 4:36:07 PM] Shell: $SHELL = /bin/bash
 72567 pts/1    00:00:00 sh
[1]+  Done(127)               eTXEJ@Rv

[INFO][3/11/2021 4:36:07 PM] Sending command /var/prtg/scriptsxml/check_cpu.sh 
[INFO][3/11/2021 4:36:08 PM] Sending EOF
[INFO][3/11/2021 4:36:08 PM] Reading PaeSSH result
[INFO][3/11/2021 4:36:08 PM] [STDOUT] <?xml version="1.0" encoding="UTF-8" ?>
<prtg>
   <result>
       <channel>%usr</channel>
         <value> <Unit> CPU </Unit> <float>
 all </float></value>
   </result>
   <result>
       <channel>%nice</channel>
         <value> <Unit> CPU </Unit> <float>
0.79 </float></value>
   </result>
   <result>
       <channel>%sys</channel>
         <value> <Unit> CPU </Unit> <float>
 0.00 </float></value>
   </result>
<result>
       <channel>%iowait</channel>
         <value> <Unit> CPU </Unit> <float>
 0.16 </float></value>
   </result>
<result>
       <channel>%irq</channel>
         <value> <Unit> CPU </Unit> <float>
 0.02  </float></value>
   </result>
<result>
       <channel>%soft</channel>
         <value> <Unit> CPU </Unit> <float>
 0.00  </float></value>
   </result>
<result>
       <channel>%steal</channel>
         <value> <Unit> CPU </Unit> <float>
 0.02  </float></value>
   </result>
<result>
<channel>%guest</channel>
         <value> <Unit> CPU </Unit> <float>
 0.02 </float></value>
   </result>
<result>
<channel>%gnice</channel>
         <value> <Unit> CPU </Unit> <float>
 0.00  </float></value>
   </result>
<result>
<channel>%idle</channel>
         <value> <Unit> CPU </Unit> <float>
0.00  </float></value>
   </result>
</prtg>
[1]+  Done(127)               eTXEJ@Rv

[INFO][3/11/2021 4:36:08 PM] [STDERR] 
[INFO][3/11/2021 4:36:08 PM] Sending exit
[INFO][3/11/2021 4:36:08 PM] Sending EOF

of course if i lunch the scritp on the vm the result is correct i have the last version 21.1.66.1623+


Article Comments

ok, now is ok. i was in error, i selected use sudo with password but is correct in my enviroment to use sudo without sudo. Now i have all data but in integer


Mar, 2021 - Permalink

Hello Michele,

Thank you for your messages.

According to the screenshots you provided, the structure of the response returned to PRTG is incorrect.

The response should follow the structure as illustrated below, as indicated in our manual right here: https://www.paessler.com/manuals/prtg/custom_sensors#advanced_sensors

<?xml version="1.0" encoding="UTF-8" ?>
<prtg>
<result>
<channel>NAME</channel>
<value>VALUE</value>
<Unit> CPU </Unit>
<float> 1 </float>
</result>
</prtg>

NAME and VALUE must be replaced with the information you want.

Regards.


Mar, 2021 - Permalink

ok thanks a lot. Now i have corrected the error but the data are incorrect


Mar, 2021 - Permalink

Thank you for your feedback.

Can you please create the sensor anew (do not duplicate it) and check if the values are correct afterwards.

Regards.


Mar, 2021 - Permalink

yes, i have recreated. it seems the cut not work fine in script launched by prtg but is fine in ssh session. here the script

#!/bin/sh
cpu="$(mpstat 1 1 | sed -n '4p')"
#$cpu | cut -d ' ' -f

echo -n "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>
<prtg>
<result>
<channel>%usr</channel>
<value>"
usr=$(echo $cpu | cut -d " " -f 4)
echo -n "$usr</value>
<unit> percent </unit>
<float> 1 </float>
</result>
<result>
<channel>%nice</channel>
<value>"
nice=$(echo $cpu | cut -d " " -f 5)
echo -n "$nice</value>
<Unit> percent </Unit>
<float> 1 </float>
</result>
<result>
<channel>%sys</channel>
<value>"
sys=$(echo $cpu | cut -d " " -f 6)
echo -n "$sys</value>
<Unit>percent</Unit>
<float>1</float>
</result>
<result>
<channel>%iowait</channel>
<value>"
iowait=$(echo $cpu | cut -d " " -f 7)
echo -n "$iowait</value>
<Unit>percent</Unit>
<float>1</float>
</result>
<result>
<channel>%irq</channel>
<value>"
irq=$(echo $cpu | cut -d " " -f 8)
echo -n "$irq</value>
<Unit>percent</Unit>
<float>1</float>
</result>
<result>
<channel>%soft</channel>
<value>"
soft=$(echo $cpu | cut -d " " -f 9)
echo -n "$soft</value>
<Unit>percent</Unit>
<float>1</float>
</result>
<result>
<channel>%steal</channel>
<value>"
steal=$(echo $cpu | cut -d " " -f 10)
echo -n "$steal</value>
<Unit>percent</Unit>
<float>1</float>
</result>
<result>
<channel>%guest</channel>
<value>"
guest=$(echo $cpu | cut -d " " -f 11)
echo -n "$guest</value>
<Unit>percent</Unit>
<float>1</float>
</result>
<result>
<channel>%gnice</channel>
<value>"
gnice=$(echo $cpu | cut -d " " -f 12)
echo -n "$gnice</value>
<Unit>percent</Unit>
<float>1</float>
</result>
<result>
<channel>%idle</channel>
<value>"
idle=$(echo $cpu | cut -d " " -f 13)
echo "$idle</value>
<Unit>percent</Unit>
<float>1</float>
</result>
</prtg>"

here the screenshot of command
so if i use echo $cpu | cut -d " " -f 3 in ssh session i get 0.38 throught prtg sensor (i used save result) i get all. so i've increased all by 1 and seems fine


Mar, 2021 - Permalink

Hi,

Thank you for the update, is the SSH Script Advanced sensor working properly since the modification you made?

Regards.


Mar, 2021 - Permalink

Yes it's running fine. I don't understand why i have to increase the field of cut throught prtg script


Mar, 2021 - Permalink

That behavior is effectively not expected, however it seems to be limited to the script you provided. We will have a look to the SSH sensor however as the issue is solved it has a low priority.

To avoid such issue, I would recommend to use a loop here to generate the JSON as well as execute the cut command only once and store its values inside a list.

Regards.


Mar, 2021 - Permalink

ok, so with json i could use a list without cut? how can i do this?


Mar, 2021 - Permalink

Hello,

You need to use the command cut to create a list in which the CPU values will be stored. You will need an other list with the channels name on which the script can loop to dynamically generate the JSON (<result>...</result>).

Here is a structure which could be used:

  • Create list of channels name
  • Create list of CPU values
  • open response structure with echo -n "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>
  • Use loop to generate each channel with <result>...</result>
  • Close the response with </prtg>

Here is a website which explains how to use list in bash: https://linuxconfig.org/how-to-use-arrays-in-bash-script

Please, notice that we do not provide support for custom scripts, therefore I can only provide the indications mentioned above.

Regards.


Mar, 2021 - Permalink