Skip to content

Instantly share code, notes, and snippets.

@JCotton1123
Created August 17, 2014 07:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JCotton1123/f73e75b9684591c307b8 to your computer and use it in GitHub Desktop.
Save JCotton1123/f73e75b9684591c307b8 to your computer and use it in GitHub Desktop.
Parse snmp mac notification trap
#!/bin/sh
LOG_FILE=/var/log/snmp/mactrap.log
read host
read ip
ip=`echo $ip | cut -d"[" -f2 | cut -d"]" -f1`
while read oid value
do
`echo $oid | grep 'CISCO-SMI::ciscoMgmt.215.1.1.8.1.2' > /dev/null`
if [ $? -eq 0 ]; then
timestamp=`date +"%Y-%m-%d %T"`
val=`echo $value | cut -d"=" -f2 | tr '\"' '\0'`
type=`echo $val | cut -d" " -f1`
vlan=`echo $val | cut -d" " -f2,3`
mac_addr=`echo $val | cut -d" " -f4,5,6,7,8,9`
port=`echo $val | cut -d" " -f10,11`
entry=`echo "$ip|$type|$vlan|$mac_addr|$port" | tr -d ' '`
echo "$timestamp|$entry" >> $LOG_FILE
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment