X-Git-Url: http://git.onelab.eu/?p=monitor.git;a=blobdiff_plain;f=nagios%2Ftest%2Fcommon.sh;fp=nagios%2Ftest%2Fcommon.sh;h=0a86152b18548f596993b464ad5bfd701611c8d6;hp=0000000000000000000000000000000000000000;hb=976e2654ef6da1dff75c0216338d4c9863e42a73;hpb=9fc85e489ba906d8535348a69b0ad124041f6890 diff --git a/nagios/test/common.sh b/nagios/test/common.sh new file mode 100644 index 0000000..0a86152 --- /dev/null +++ b/nagios/test/common.sh @@ -0,0 +1,66 @@ +#!/bin/bash + +function percent_true () +{ + PERCENT=$1 + + # If R is uniformly random, then it will be less than a threshold PERCENT of the time. + P=$(( $PERCENT * 32786 / 100 )) + R=$RANDOM + + if [ $R -gt $P ] ; then + echo "2" + else + echo "0" + fi +} + +function random_delay () +{ + MAX=$1 + + R=$RANDOM + P=$(( $R * $MAX / 32786 )) + + echo $P +} + +function random_sample () +{ + file=$1 + length=$(wc -l $file | awk '{print $1}') + R=$RANDOM + R_MAX=32786 + index=$(( $R * $length / $R_MAX )) + + V=`tail -$(( $length - $index )) $file | head -1` + echo $V +} + +function str_to_state () +{ + case "$1" in + "OK:") + echo "0" + ;; + "WARNING:") + echo "1" + ;; + *) + echo "2" + ;; + esac +} + +function open_http () +{ + exec 3<> /dev/tcp/$1/80 + echo "GET /index.html HTTP/1.0" 1>&3 +} + +function close_http () +{ + echo 1>&3 + while read 0<&3; do echo $REPLY >/dev/null; done +} +