]> git.proxmox.com Git - mirror_frr.git/blame - doc/user/snmptrap.rst
doc: use :abbr:
[mirror_frr.git] / doc / user / snmptrap.rst
CommitLineData
42fc5d26
QY
1Handling SNMP Traps
2===================
3
4To handle snmp traps make sure your snmp setup of frr works
5correctly as described in the frr documentation in :ref:`SNMP_Support`.
6
7The BGP4 mib will send traps on peer up/down events. These should be
8visible in your snmp logs with a message similar to:
9
29adcd50 10.. clicmd:: snmpd[13733]: Got trap from peer on fd 14
42fc5d26
QY
11
12To react on these traps they should be handled by a trapsink. Configure
13your trapsink by adding the following lines to :file:`/etc/snmpd/snmpd.conf`:
14
15::
16
17 # send traps to the snmptrapd on localhost
18 trapsink localhost
19
20
21This will send all traps to an snmptrapd running on localhost. You can
22of course also use a dedicated management station to catch traps.
23Configure the snmptrapd daemon by adding the following line to
24:file:`/etc/snmpd/snmptrapd.conf`:
25
26::
27
28 traphandle .1.3.6.1.4.1.3317.1.2.2 /etc/snmp/snmptrap_handle.sh
29
30
31This will use the bash script :file:`/etc/snmp/snmptrap_handle.sh` to handle
32the BGP4 traps. To add traps for other protocol daemons, lookup their
33appropriate OID from their mib. (For additional information about which
34traps are supported by your mib, lookup the mib on
35`http://www.oidview.com/mibs/detail.html <http://www.oidview.com/mibs/detail.html>`_).
36
37Make sure snmptrapd is started.
38
39The snmptrap_handle.sh script I personally use for handling BGP4 traps
40is below. You can of course do all sorts of things when handling traps,
41like sound a siren, have your display flash, etc., be creative ;).
42
43@verbatim
44#!/bin/bash
45
46# routers name
47ROUTER=`hostname -s`
48
49#email address use to sent out notification
50EMAILADDR="john@doe.com"
51#email address used (allongside above) where warnings should be sent
52EMAILADDR_WARN="sms-john@doe.com"
53
54# type of notification
55TYPE="Notice"
56
57# local snmp community for getting AS belonging to peer
58COMMUNITY="<community>"
59
60# if a peer address is in $WARN_PEERS a warning should be sent
61WARN_PEERS="192.0.2.1"
62
63# get stdin
64INPUT=`cat -`
65
66# get some vars from stdin
67uptime=`echo $INPUT | cut -d' ' -f5`
68peer=`echo $INPUT | cut -d' ' -f8 | sed -e 's/SNMPv2-SMI::mib-2.15.3.1.14.//g'`
69peerstate=`echo $INPUT | cut -d' ' -f13`
70errorcode=`echo $INPUT | cut -d' ' -f9 | sed -e 's/\\"//g'`
71suberrorcode=`echo $INPUT | cut -d' ' -f10 | sed -e 's/\\"//g'`
72remoteas=`snmpget -v2c -c $COMMUNITY localhost SNMPv2-SMI::mib-2.15.3.1.9.$peer | cut -d' ' -f4`
73
74WHOISINFO=`whois -h whois.ripe.net " -r AS$remoteas" | egrep '(as-name|descr)'`
75asname=`echo "$WHOISINFO" | grep "^as-name:" | sed -e 's/^as-name://g' -e 's/ //g' -e 's/^ //g' | uniq`
76asdescr=`echo "$WHOISINFO" | grep "^descr:" | sed -e 's/^descr://g' -e 's/ //g' -e 's/^ //g' | uniq`
77
78# if peer address is in $WARN_PEER, the email should also
79# be sent to $EMAILADDR_WARN
80for ip in $WARN_PEERS; do
81if [ "x$ip" == "x$peer" ]; then
82EMAILADDR="$EMAILADDR,$EMAILADDR_WARN"
83TYPE="WARNING"
84break
85fi
86done
87
88# convert peer state
89case "$peerstate" in
901) peerstate="Idle" ;;
912) peerstate="Connect" ;;
923) peerstate="Active" ;;
934) peerstate="Opensent" ;;
945) peerstate="Openconfirm" ;;
956) peerstate="Established" ;;
96*) peerstate="Unknown" ;;
97esac
98
99# get textual messages for errors
100case "$errorcode" in
10100)
102error="No error"
103suberror=""
104;;
10501)
106error="Message Header Error"
107case "$suberrorcode" in
10801) suberror="Connection Not Synchronized" ;;
10902) suberror="Bad Message Length" ;;
11003) suberror="Bad Message Type" ;;
111*) suberror="Unknown" ;;
112esac
113;;
11402)
115error="OPEN Message Error"
116case "$suberrorcode" in
11701) suberror="Unsupported Version Number" ;;
11802) suberror="Bad Peer AS" ;;
11903) suberror="Bad BGP Identifier" ;;
12004) suberror="Unsupported Optional Parameter" ;;
12105) suberror="Authentication Failure" ;;
12206) suberror="Unacceptable Hold Time" ;;
123*) suberror="Unknown" ;;
124esac
125;;
12603)
127error="UPDATE Message Error"
128case "$suberrorcode" in
12901) suberror="Malformed Attribute List" ;;
13002) suberror="Unrecognized Well-known Attribute" ;;
13103) suberror="Missing Well-known Attribute" ;;
13204) suberror="Attribute Flags Error" ;;
13305) suberror="Attribute Length Error" ;;
13406) suberror="Invalid ORIGIN Attribute" ;;
13507) suberror="AS Routing Loop" ;;
13608) suberror="Invalid NEXT_HOP Attribute" ;;
13709) suberror="Optional Attribute Error" ;;
13810) suberror="Invalid Network Field" ;;
13911) suberror="Malformed AS_PATH" ;;
140*) suberror="Unknown" ;;
141esac
142;;
14304)
144error="Hold Timer Expired"
145suberror=""
146;;
14705)
148error="Finite State Machine Error"
149suberror=""
150;;
15106)
152error="Cease"
153case "$suberrorcode" in
15401) suberror="Maximum Number of Prefixes Reached" ;;
15502) suberror="Administratively Shutdown" ;;
15603) suberror="Peer Unconfigured" ;;
15704) suberror="Administratively Reset" ;;
15805) suberror="Connection Rejected" ;;
15906) suberror="Other Configuration Change" ;;
16007) suberror="Connection collision resolution" ;;
16108) suberror="Out of Resource" ;;
16209) suberror="MAX" ;;
163*) suberror="Unknown" ;;
164esac
165;;
166*)
167error="Unknown"
168suberror=""
169;;
170esac
171
172# create textual message from errorcodes
173if [ "x$suberror" == "x" ]; then
174NOTIFY="$errorcode ($error)"
175else
176NOTIFY="$errorcode/$suberrorcode ($error/$suberror)"
177fi
178
179# form a decent subject
180SUBJECT="$TYPE: $ROUTER [bgp] $peer is $peerstate: $NOTIFY"
181# create the email body
182MAIL=`cat << EOF
183BGP notification on router $ROUTER.
184
185Peer: $peer
186AS: $remoteas
187New state: $peerstate
188Notification: $NOTIFY
189
190Info:
191$asname
192$asdescr
193
194Snmpd uptime: $uptime
195EOF`
196
197# mail the notification
198echo "$MAIL" | mail -s "$SUBJECT" $EMAILADDR
199@end verbatim
200