File: //opt/perf/bin/ovtrap
#!/bin/sh
# @(#)ovtrap 11.00.020 25FEB2010 =*=
#
# script to send a v1 snmp trap to requested location
#
# usage: ovtrap [-s severity] host alarm message
#
oops() {
echo "ovtrap ERROR: $*"
echo
echo "usage: ovtrap [-s severity] host alarm message"
echo " where severity is Normal, Minor, Warning, Major or Critical"
exit $OOPS
} # end oops
IsAgentBitDifferentFromOSBit()
{
typeset ret=0
if [ -f /etc/redhat-release ]
then
# For RHEL 4 x64/ia64 we support 32 bit agent
VERSION=`cat /etc/redhat-release | sed s/.*release\ // | sed s/\ .*// \
| cut -d. -f1`
if [ $VERSION -eq 4 ]
then
ret=1
fi
elif [ -f /etc/SuSE-release ]
then
# For SLES 9 x64/ia64 we support 32 bit agent
VERSION=`cat /etc/SuSE-release | grep 'VERSION *= *' | \
sed -e 's%.*= *%%' | cut -d. -f1`
if [ $VERSION -eq 9 ]
then
ret=1
fi
fi
return ${ret}
}
#
# MAIN
#
OOPS=0
# Determine which platform this script is running on:
SYS="`uname -s`"
REV="`uname -r`"
TRAPSEND="trapsend"
case "$SYS" in
HP-UX)
SYS="HP-UX"
PATH=${PATH}:/usr/bin:/usr/sbin
export PATH
BIN_DIR="/opt/perf/bin"
;;
Sun*)
SYS="SUN"
PATH=${PATH}:/usr/bin:/usr/sbin:/usr/ucb
export PATH
BIN_DIR="/opt/perf/bin"
;;
OSF1)
SYS="OSF"
PATH=${PATH}:/usr/bin:/usr/sbin
export PATH
BIN_DIR="/usr/opt/perf/bin"
;;
Linux)
PATH=${PATH}:/bin:/usr/bin:/usr/ucb:/usr/ccs/bin:/usr/bin/X11:/opt/perf/bin
export PATH
IsAgentBitDifferentFromOSBit
if [ "`uname -m`" = "ia64" -o "`uname -m`" = "x86_64" ] && [ -d /opt/perf/lib64 ]; then
IsAgentBitDifferentFromOSBit
if [ $? -eq 0 ]
then
export SR_MGR_CONF_DIR="/opt/perf/lib64"
else
export SR_MGR_CONF_DIR="/opt/perf/lib"
fi
else
export SR_MGR_CONF_DIR="/opt/perf/lib"
fi
TRAPSEND="trapsend -v1"
if [ -f /etc/debian_version ]
then
LINUXOS=`cat /etc/debian_version`
else
LINUXOS=`cat /etc/*-release`
fi
BIN_DIR="/opt/perf/bin"
;;
*)
SYS="AIX"
if [ -f /usr/lpp/perf/lib64/libnums.a ]; then
export SR_MGR_CONF_DIR="/usr/lpp/perf/lib64"
fi
BIN_DIR="/usr/lpp/perf/bin"
;;
esac
SEVERITY="Warning"
TEMPLATE_NO="58916872"
if [ ! -x $BIN_DIR/trapsend ]
then
OOPS=11
oops "Missing binary $BIN_DIR/trapsend. Check installation."
fi
if [ -z "$1" ]
then
OOPS=13
oops "You must enter the host name and alarm message for ovtrap."
fi
case "$1" in
-s)
shift
SEVERITY="$1"
case "$SEVERITY" in
[Nn][Oo][Rr][Mm][Aa][Ll])
SEVERITY="Normal"
TEMPLATE_NO="58916872"
shift
;;
[Ww][Aa][Rr][Nn][Ii][Nn][Gg])
SEVERITY="Warning"
TEMPLATE_NO="50462720"
shift
;;
[Mm][Ii][Nn][Oo][Rr])
SEVERITY="Minor"
TEMPLATE_NO="50462721"
shift
;;
[Mm][Aa][Jj][Oo][Rr])
SEVERITY="Major"
TEMPLATE_NO="58851329"
shift
;;
[Cc][Rr][Ii][Tt][Ii][Cc][Aa][Ll])
SEVERITY="Critical"
TEMPLATE_NO="58851330"
shift
;;
*)
OOPS=14
oops "Invalid severity value for ovtrap."
;;
esac
;;
-*)
OOPS=15
oops "Invalid option for ovtrap."
;;
*)
;;
esac
HOST="$1"
if [ "$HOST" = "" ]
then
OOPS=16
oops "Must supply host name for ovtrap."
else
shift
fi
ALARM="$@"
if [ "$ALARM" = "" ]
then
OOPS=17
oops "Must supply the alarm message for ovtrap."
fi
case "$SEVERITY" in
Normal )
$BIN_DIR/$TRAPSEND "$HOST" public 6 "$TEMPLATE_NO" \
1.3.6.1.4.1.11.2.17.1 0 \
1.3.6.1.4.1.11.2.17.1.0 -i 14 \
1.3.6.1.4.1.11.2.17.2.0 -D "`hostname`" \
1.3.6.1.4.1.11.2.17.3.0 -D "$SEVERITY: $ALARM" \
1.3.6.1.4.1.11.2.17.4.0 -D "$ALARM" \
1.3.6.1.4.1.11.2.17.2.6.0 -D "OVPA"
;;
Major | Warning | Minor | Critical)
$BIN_DIR/$TRAPSEND "$HOST" public 6 "$TEMPLATE_NO" \
1.3.6.1.4.1.11.2.17.1 0 \
1.3.6.1.4.1.11.2.17.1.0 -i 14 \
1.3.6.1.4.1.11.2.17.2.0 -D "`hostname`" \
1.3.6.1.4.1.11.2.17.3.0 -D "OVPA" \
1.3.6.1.4.1.11.2.17.4.0 -D "" \
1.3.6.1.4.1.11.2.17.4.0 -D "$SEVERITY: $ALARM" \
1.3.6.1.4.1.11.2.17.2.6.0 -D "OVPA"
;;
esac
OOPS=$?
if [ $OOPS != 0 ]
then
oops "Warning: Non-zero return code to ovtrap from trapsend."
fi