1 @c Documentation on configuring Quagga and snmpd for SNMP traps
2 @c contributed by Jeroen Simonetti, jsimonetti@denit.net
4 @node Handling SNMP Traps
5 @section Handling SNMP Traps
7 To handle snmp traps make sure your snmp setup of quagga works
8 correctly as described in the quagga documentation in @xref{SNMP Support}.
10 The BGP4 mib will send traps on peer up/down events. These should be
11 visible in your snmp logs with a message similar to:
13 @samp{snmpd[13733]: Got trap from peer on fd 14}
15 To react on these traps they should be handled by a trapsink. Configure
16 your trapsink by adding the following lines to @file{/etc/snmpd/snmpd.conf}:
19 # send traps to the snmptrapd on localhost
23 This will send all traps to an snmptrapd running on localhost. You can
24 of course also use a dedicated management station to catch traps.
25 Configure the snmptrapd daemon by adding the following line to
26 @file{/etc/snmpd/snmptrapd.conf}:
28 @c Documentation contributed by Jeroen Simonetti, jsimonetti@denit.net
31 traphandle .1.3.6.1.4.1.3317.1.2.2 /etc/snmp/snmptrap_handle.sh
34 This will use the bash script @file{/etc/snmp/snmptrap_handle.sh} to handle
35 the BGP4 traps. To add traps for other protocol daemons, lookup their
36 appropriate OID from their mib. (For additional information about which
37 traps are supported by your mib, lookup the mib on
38 @uref{http://www.oidview.com/mibs/detail.html}).
40 Make sure snmptrapd is started.
42 The snmptrap_handle.sh script I personally use for handling BGP4 traps
43 is below. You can of course do all sorts of things when handling traps,
44 like sound a siren, have your display flash, etc., be creative ;).
52 #email address use to sent out notification
53 EMAILADDR="john@doe.com"
54 #email address used (allongside above) where warnings should be sent
55 EMAILADDR_WARN="sms-john@doe.com"
57 # type of notification
60 # local snmp community for getting AS belonging to peer
61 COMMUNITY="<community>"
63 # if a peer address is in $WARN_PEERS a warning should be sent
64 WARN_PEERS="192.0.2.1"
70 # get some vars from stdin
71 uptime=`echo $INPUT | cut -d' ' -f5`
72 peer=`echo $INPUT | cut -d' ' -f8 | \
73 sed -e 's/SNMPv2-SMI::mib-2.15.3.1.14.//g'`
74 peerstate=`echo $INPUT | cut -d' ' -f13`
75 errorcode=`echo $INPUT | cut -d' ' -f9 | sed -e 's/\"//g'`
76 suberrorcode=`echo $INPUT | cut -d' ' -f10 | sed -e 's/\"//g'`
77 remoteas=`snmpget -v2c -c $COMMUNITY \
78 localhost SNMPv2-SMI::mib-2.15.3.1.9.$peer \
81 WHOISINFO=`whois -h whois.ripe.net " -r AS$remoteas" | \
82 egrep '(as-name|descr)'`
83 asname=`echo "$WHOISINFO" | grep "^as-name:" | \
84 sed -e 's/^as-name://g' -e 's/ //g' -e 's/^ //g' | uniq`
85 asdescr=`echo "$WHOISINFO" | grep "^descr:" | \
86 sed -e 's/^descr://g' -e 's/ //g' -e 's/^ //g' | uniq`
88 # if peer address is in $WARN_PEER, the email should also
89 # be sent to $EMAILADDR_WARN
90 for ip in $WARN_PEERS; do
91 if [ "x$ip" == "x$peer" ]; then
92 EMAILADDR="$EMAILADDR,$EMAILADDR_WARN"
101 1) peerstate="Idle" ;;
102 2) peerstate="Connect" ;;
103 3) peerstate="Active" ;;
104 4) peerstate="Opensent" ;;
105 5) peerstate="Openconfirm" ;;
106 6) peerstate="Established" ;;
107 *) peerstate="Unknown" ;;
110 # get textual messages for errors
117 error="Message Header Error"
118 case "$suberrorcode" in
119 01) suberror="Connection Not Synchronized" ;;
120 02) suberror="Bad Message Length" ;;
121 03) suberror="Bad Message Type" ;;
122 *) suberror="Unknown" ;;
126 error="OPEN Message Error"
127 case "$suberrorcode" in
128 01) suberror="Unsupported Version Number" ;;
129 02) suberror="Bad Peer AS" ;;
130 03) suberror="Bad BGP Identifier" ;;
131 04) suberror="Unsupported Optional Parameter" ;;
132 05) suberror="Authentication Failure" ;;
133 06) suberror="Unacceptable Hold Time" ;;
134 *) suberror="Unknown" ;;
138 error="UPDATE Message Error"
139 case "$suberrorcode" in
140 01) suberror="Malformed Attribute List" ;;
141 02) suberror="Unrecognized Well-known Attribute" ;;
142 03) suberror="Missing Well-known Attribute" ;;
143 04) suberror="Attribute Flags Error" ;;
144 05) suberror="Attribute Length Error" ;;
145 06) suberror="Invalid ORIGIN Attribute" ;;
146 07) suberror="AS Routing Loop" ;;
147 08) suberror="Invalid NEXT_HOP Attribute" ;;
148 09) suberror="Optional Attribute Error" ;;
149 10) suberror="Invalid Network Field" ;;
150 11) suberror="Malformed AS_PATH" ;;
151 *) suberror="Unknown" ;;
155 error="Hold Timer Expired"
159 error="Finite State Machine Error"
164 case "$suberrorcode" in
165 01) suberror="Maximum Number of Prefixes Reached" ;;
166 02) suberror="Administratively Shutdown" ;;
167 03) suberror="Peer Unconfigured" ;;
168 04) suberror="Administratively Reset" ;;
169 05) suberror="Connection Rejected" ;;
170 06) suberror="Other Configuration Change" ;;
171 07) suberror="Connection collision resolution" ;;
172 08) suberror="Out of Resource" ;;
173 09) suberror="MAX" ;;
174 *) suberror="Unknown" ;;
183 # create textual message from errorcodes
184 if [ "x$suberror" == "x" ]; then
185 NOTIFY="$errorcode ($error)"
187 NOTIFY="$errorcode/$suberrorcode ($error/$suberror)"
191 # form a decent subject
192 SUBJECT="$TYPE: $ROUTER [bgp] $peer is $peerstate: $NOTIFY"
193 # create the email body
195 BGP notification on router $ROUTER.
199 New state: $peerstate
200 Notification: $NOTIFY
206 Snmpd uptime: $uptime
209 # mail the notification
210 echo "$MAIL" | mail -s "$SUBJECT" $EMAILADDR