#!/bin/sh ############################################################ ## syslog_to_snmp.bash: version .20011206001 ## ## ## ## Purpose: syslog to snmp ## ## To send skyflow syslogs to the snmp serfver ## ## ## ## Setup: ## ## Create a fifo file: ## ## mkfifo /var/log/syslog.fifo ## ## ## ## Edit /etc/syslog.conf, appending this line to the end:## ## kern.warn;*.err;authpriv.none |/var/log/syslog.fifo ## ## ## ## Run in the background ## ## /root/bin/syslog_to_snmp.bash& ## ## ## ## Created by: John Stile ## ## T.R. Fullhart ## ## ## ## Context: ## ## This must be run with all mighty root. ## ############################################################ SNMserver="192.168.2.70" #not in use yet" SNMPtrap="/usr/bin/snmptrap" ####################################################### # check to see if they are root # # if they are not root, they can't edit the files # ####################################################### function am_i_root { Me=`whoami` if [[ $Me != "root" ]] then echo "\nGotta be su to run this ...." sleep 3 exit 1 fi } # not working yest #am_i_root ############################## ### Part of skyflow mib: # ############################## ## skyflowServicesMib 1.3.6.1.4.1.10872.1.1.3 ## ssMonGroup 1.3.6.1.4.1.10872.1.1.3.1 ## eventMessage 1.3.6.1.4.1.10872.1.1.3.1.6 ## eventDate 1.3.6.1.4.1.10872.1.1.3.1.7 ## eventSource 1.3.6.1.4.1.10872.1.1.3.1.8 ## eventFacility 1.3.6.1.4.1.10872.1.1.3.1.9 ## eventLevel 1.3.6.1.4.1.10872.1.1.3.1.10 ## ssNotificationsGroup 1.3.6.1.4.1.10872.1.1.3.1.20 ## ss-notif 1.3.6.1.4.1.10872.1.1.3.1.20.17 # the fifo to suck on LOGFILE=/var/log/syslog.fifo if [[ ! -r "$LOGFILE" ]]; then echo "$0: File not found: $LOGFILE" exit 1 fi while [ 1 ] do ########################################### # read the first line: ########################################### LINE=`head -1 "$LOGFILE"` echo "$LINE" ########################################### # Make sure it's a message we want ########################################### if ( echo "$LINE" | grep -q Msg ) then ########################################### # Set the variables based on the message: ########################################### Date=`echo "$LINE" | awk '{print $1" "$2" "$3}'` IP_Address=`echo "$LINE" | sed 's/.*Source\:\ \(.*\)\,\ Facility.*/\1/'` Facility=`echo "$LINE" |sed 's/.*Facility\:\ \(.*\)\,\ Level.*/\1/'` Level=`echo "$LINE" |sed 's/.*Level\:\ \(.*\)\,\ Msg.*/\1/'` Message=`echo "$LINE" | sed 's/.*Msg\:\ //'` # Echo for debug purposes # echo "LINE = $LINE" # echo "Message =$Message" # echo "Date =$Date" # echo "IP_Address =$IP_Address" # echo "Facility =$Facility" # echo "Level =$Level" ########################################### # Send the message ########################################### snmptrap -v 2c -c public $SNMserver '' .iso.3.6.1.4.1.10872.1.1.3.1.20.17 .iso.3.6.1.4.1.10872.1.1.3.1.6 s "$Message" .iso.3.6.1.4.1.10872.1.1.3.1.7 s "$Date" .iso.3.6.1.4.1.10872.1.1.3.1.8 a "$IP_Address" .iso.3.6.1.4.1.10872.1.1.3.1.9 i "$Facility" .iso.3.6.1.4.1.10872.1.1.3.1.10 i "$Level" fi done