Skip to content

Instantly share code, notes, and snippets.

@mateusz-fiolka
Created February 12, 2013 09:36
Show Gist options
  • Save mateusz-fiolka/4761204 to your computer and use it in GitHub Desktop.
Save mateusz-fiolka/4761204 to your computer and use it in GitHub Desktop.
#!/bin/bash
timestamp=$(date +"%s")
FLOOR=100
RANGE=999
number=0 #initialize
while [ "$number" -le $FLOOR ]
do
number=$RANDOM
let "number %= $RANGE" # Scales $number down within $RANGE.
done
x=0;
retval=1;
while [ $x -le 2 -a $retval -eq 1 ] ; do
/usr/bin/snmptrap -v 2c -Ci -Lo -c $2 $1 '' NAGIOS-NOTIFY-MIB::nagiosHostEventTable \
nHostname s "$3" \
nHostAlias s "$4" \
nHostStateID i $5 \
nHostGroupName s "$6" \
nHostDurationSec i $7 \
nHostOutput s "$8" \
nHostPerfData s "$9" \
nHostLastCheck i "$timestamp" \
nHostAttempt i "$number"
retval=$?
[ $retval -eq 0 ] && echo "Trap send succesfully, snmptrap exit code: [$retval]"
x=$(( $x + 1 ))
if [ $retval -eq 1 ]; then
echo "Trap failed, snmptrap exit code: [$retval]"
[ $x -le 2 ] && sleep 3
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment