Hi, i need to check that asterisk trunk is active. I need to make 30 sensors with different trunk names. I ended up with such ssh script: #!/bin/bash var1=$1 if [ "$var1" == OK ] then echo "0:200:running" else echo "2:404:UNREACHABLE" fi

and i give this parameter to prtg "/usr/sbin/asterisk -rx "sip show peers" |grep 9859204943 |awk '{print $7}'| sed 2,2d"

What am i doing wrong? if i making script like this: #!/bin/bash var1=$(/usr/sbin/asterisk -rx "sip show peers" |grep 9857617234 |awk '{print $7}'| sed 2,2d) if [ "$var1" == OK ] then echo "0:200:running" else echo "2:404:UNREACHABLE" fi

Everything is working fine, but in this case i need 30 different scripts, i need somehow to fill "Number" 9857617234 in the sensor parameters.


Article Comments

Hey kmorozov,

Thank you very much for your KB-posting.

Please try to use the following line:

var1=$(/usr/sbin/asterisk -rx "sip show peers" |grep $1 |awk '{print $7}'| sed 2,2d)

instead of

var1=$(/usr/sbin/asterisk -rx "sip show peers" |grep 9857617234 |awk '{print $7}'| sed 2,2d)

That way, you only need to commit the number "9859204943" as parameter in the sensor settings in PRTG.

Best regards,
Sven


Mar, 2017 - Permalink

Thank you very much for reply, when I'm doing as u advised prtg always show error message, which means that script doesn't receive parameter. Maybe there is another way to make it without var1=$, or maybe I need to commit somewhere in the script.


Mar, 2017 - Permalink

Hey kmorozov,

Please try to use the following script:

#!/bin/bash
value=$1
var=$(/usr/sbin/asterisk -rx "sip show peers" | grep ${value} |awk '{print $7}'| sed 2,2d)

if [[ $var == OK ]]; then
 echo "0:200:running"
else
 echo "2:404:UNREACHABLE"
fi

Does it work?


Mar, 2017 - Permalink

No, only errors again. Maybe it because its value in value?


Mar, 2017 - Permalink

Probably - when you run it manually, write $value to the console as well so you can see the actual value. Probably the wrong column is selected via awk or sed?


Mar, 2017 - Permalink

If I run script via console like this:

#!/bin/bash
value=9859204943
var=$(/usr/sbin/asterisk -rx "sip show peers" | grep ${value} |awk '{print $7}'| sed 2,2d)

if [[ $var == OK ]]; then
 echo "0:200:running"
else
 echo "2:404:UNREACHABLE"
fi

I receive 0:200:running as it should be, maybe some sensor settings is wrong ?


Mar, 2017 - Permalink

Could you execute the script like this: ./script.sh 9859204943

Remember to configure value to be $1 instead of the current numerical value. Same result?


Mar, 2017 - Permalink

Same, it works fine: 0:200:running


Mar, 2017 - Permalink

So that means that the script sensor doesn't provide the correct value as parameter. Could you post the sensor config, specifically the parameter field?


Mar, 2017 - Permalink

I found the problem, in parameter field was "9859204943", it worked with '9859204943'


Mar, 2017 - Permalink

Finally :-)

Glad to hear that you were able to solve the issue.

Wish you a great day.


Mar, 2017 - Permalink

Thank you very much, this sensor will help me a lot.


Mar, 2017 - Permalink

Hi, I have some issue..

My script running well in linux, but still unreachable on prtg..

this my script :

#!/bin/bash
value='callcentergif/callcenterg'
var=$(/usr/sbin/asterisk -rx "sip show peers" | grep ${value} |awk '{print $7}'| sed 2,2d)

if [[ $var == OK ]]; then
 echo "0:200:RUNNING"
else
 echo "2:404:UNREACHABLE"
fi

and this my prtg setting :

Parameters : -value 'callcentergif/callcenterg'

Anyone can help? Thanks


Nov, 2019 - Permalink

The parameters in Bash don't work like this. Could you evaluate the issue further? What problem does the Sensor message disclose?


Nov, 2019 - Permalink