I'm using a custom SSH script to retrieve the state of a service on a Ubuntu server. I added test123 to the array to check if I receive a down state on my channel. But PRTG displays all services are running, even test123. What am I missing here?

Script:

#!/bin/bash
#
array=(psa apache2 test123 )

function check_service {
 service $1 status > /dev/null 2>&1
        if [ $? -ne 0 ]; then
                echo -n "1:$?:Down"
        else
                echo -n "0:$?:OK"
        fi
}

echo "<prtg>"

# <-- Start
for i in "${array[@]}"
do

echo -n "   <result>
       <channel>Service: $i</channel>
         <value>"
check_service $i
echo "</value>
         <ValueLookup>icr.linux.ssh</ValueLookup>
  </result>"
done
# End -->
echo "</prtg>"
exit

Custom lookup file:

<?xml version="1.0" encoding="UTF-8"?> <ValueLookup id="icr.linux.ssh" desiredValue="0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="PaeValueLookup.xsd"> <Lookups> <SingleInt state="Ok" value="0"> Running </SingleInt> <SingleInt state="Warning" value="1"> Stopped </SingleInt> </Lookups> </ValueLookup>

The XML output from the PRTG log:

<prtg> <result> <channel>Service: psa</channel> <value>0:1:OK</value> <ValueLookup>icr.linux.ssh</ValueLookup> </result> <result> <channel>Service: apache2</channel> <value>0:1:OK</value> <ValueLookup>icr.linux.ssh</ValueLookup> </result> <result> <channel>Service: test123</channel> <value>1:0:Down</value> <ValueLookup>icr.linux.ssh</ValueLookup> </result> </prtg>

Thank you in advance


Article Comments

Hi John,

I think you mixed here something up.
If you want to use a SSH Script sensor the output is only following:

returncode:value:message

If you are using the SSH Script Advanced sensor you need to use following output:

 <prtg>
           <result>
           <channel>First channel</channel>
           <value>10</value>
           </result>
           <result>
           <channel>Second channel</channel>
           <value>20</value>
           </result>
           </prtg>

This means you need to either change the sensor type (you only can use one channel) or you need to change your output accordingly. ----- Kind regards

Felix Wiesneth - Team Tech Support


May, 2022 - Permalink