1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
|
#! /bin/sh -f
AGENT=/etc/snmpd
CONF=/etc/snmpd.conf
INFO=/etc/snmpd.agentinfo
## default is configured: MIB=/usr/lib/snmpd.mib
MIB=/usr/lib/snmpd.mib
TMP=/tmp/snmpd.$$
trap "rm -f $TMP" 1 2 3 13 15
POSTURE= PASSWORD=
for A in "$@"
do
case "$A" in
-mini|-semi|-very)
if [ ! -z "$POSTURE" ]; then
echo "use -mini, -semi, or -very exactly once" 1>&2
echo "usage: agent-boot.sh [-mini/-semi/-very] password" \
1>&2
exit 1
fi
POSTURE="$A"
;;
-*) echo "unknown option: $A" 1>&2
echo "usage: agent-boot.sh [-mini/-semi/-very] password" 1>&2
exit 1
;;
*) if [ ! -z "$PASSWORD" ]; then
echo "use password only once" 1>&2
echo "usage: agent-boot.sh [-mini/-semi/-very] password" \
1>&2
exit 1
else
PASSWORD="$A"
fi
;;
esac
done
if [ -z "$POSTURE" ]; then
LEVEL=very
else
LEVEL="`echo $POSTURE | sed -e s%-%%`"
fi
AGENTID=`netstat -in | awk '
/^Name /{ next }
/^lo/ { next }
{
split($4,quad,".")
printf "%02x%02x%02x%02x", 0, 0, 0, 35;
printf "%02x%02x%02x%02x", quad[1], quad[2], quad[3], quad[4];
printf "%02x%02x%02x%02x\n", 0, 0, 0, 0;
exit 0
}
END { exit 1 }
'`
if [ -z "$AGENTID" ]; then
echo "unable to determine IP-address" 1>&2
exit 1
fi
if [ ! -f ../mib.txt -o ! -x authkey ]; then
echo "need to run script from the apps/ directory" 1>&2
exit 1
fi
umask 0022
if [ ! -f $AGENT ]; then
if (cp snmpd $AGENT) 2>/dev/null; then
echo "created $AGENT"
else
echo "unable to create $AGENT, you must copy snmpd by hand..."
fi
fi
if [ ! -f $INFO ]; then
if (echo 0 > $INFO) 2>/dev/null; then
echo "created $INFO"
else
echo "unable to create $INFO, you must do so by hand..."
fi
else
echo "warning: file $INFO already exists"
fi
if [ ! -f $MIB ]; then
if (cp ../mib.txt $MIB) 2>/dev/null; then
echo "created $MIB"
else
echo "unable to create $MIB, you must copy ../mib.txt by hand..."
fi
else
echo "warning: file $MIB already exists"
fi
echo -n "generating key from password... "
KEY=`./authkey "$PASSWORD" "$AGENTID" | awk '{ print $NF }'`
if [ -z "$KEY" ]; then
exit 1
fi
echo "done."
umask 0077
echo "\
#
# snmpd.conf - created `date`
#
#
#
# view configuration
#
# viewName OID included/excluded
#
# internet
view all .1.3.6.1 included
# internet
view mini .1.3.6.1 included
# system, snmp, usecAgent, usecStats
view semi .1.3.6.1.2.1.1 included
view semi .1.3.6.1.2.1.11 included
view semi .1.3.6.1.6.3.6.1.1 included
view semi .1.3.6.1.6.3.6.1.2 included
# snmp, usecAgent, usecStats
view semi .1.3.6.1.2.1.11 included
view semi .1.3.6.1.6.3.6.1.1 included
view semi .1.3.6.1.6.3.6.1.2 included
#
#
# user configuration
#
# noneRV noneWV authRV authWV userName[/authKey]
#
user $LEVEL - all all public/0x$KEY
#
#
# community configuration
#
# commName readV writeV
#
community public $LEVEL -
" > $TMP
if [ ! -f $CONF ]; then
if (mv $TMP $CONF) 2>/dev/null; then
echo "created $CONF"
else
echo "unable to create $CONF, you must copy $TMP by hand..."
fi
else
echo "
*** file $CONF already exists, newly-generated configuration left in
$TMP"
fi
echo "
*** to run agent, the file /etc/rc.local needs these lines:
if [ -f $AGENT ]; then
MIBFILE=$MIB $AGENT >/dev/null 2>&1 & echo -n ' snmpd'
fi"
exit 0
|