Posts tagged Traps
Posts tagged Traps
This post has an install script towards the bottom which will install SNMP Daemon and its required configuration for you. That feat is the result of many hours of work. The BASH scripting only took an hour or two to knock together, the main effort was getting SNMP working with no errors with both IPv4 and IPv6 support; MIB support and SNMP Traps sent for notification of events.
I have tested the script using ubuntu 11.04 and more recently with revision 1.1 of the scrpt I have tested with ubuntu 8.04.
NOTE: With NET-SNMP version 5.4.1 on ubuntu 8.0.4 I did notice that the only way to remove the error “getaddrinfo: Name or service not known” on startup was to remove the IPv6 parameters from the listening address, IPv6 lookups do work on 8.0.4 but you do have to live with some early immature code issues.
I suggest you copy the script below and paste into a file on your ubuntu system and make sure you chmod the file to make it executable from root;
chmod 755 <script-name>
should do it.
If you have a number of machines to install SNMP on, I suggest you change the defaults towards the top of the script to match your network and environment requirements this will make for a simpler and faster install.
#!/bin/bash
#
# SNMP install
#by Paul Miller
#Revisions:
#1.0 - Initial
#1.1 - corrections after testing with ubuntu 8.04 LTS
#CHANGE DEFAULT script variables here before running
def_READ_ONLY_SECRET=”public”
def_READ_WRITE_SECRET=”private”
def_IPv4_SUBNET=”192.168.0.0/24”
def_IPv6_SUBNET=”2001:470:812c::/64”
def_SYS_LOC=”New Zealand”
def_SYS_CONT_NAME=”Paul Miller”
def_SYS_CONT_EMAIL=”idkpmiller@sip2serve.com”
def_TRAP_COMMUNITY=”idknet”
def_TRAP_RECEIVER=”nms.sip2serve.com” # IP or FQDN of a SNMP TRAP recievering
server
#====END of User Varables==================
#check current user is root
(( `id -u` )) && echo “Must be ran as root, try prefixxing with sudo.” && exit 1
#clear the screen
clear
# Get Input from User
echo “Capture User Options:”
echo “=====================”
echo “Please answer the following questions.”
echo “Hitting return will continue with the default option”
echo
echo
read -p “System Location [$def_SYS_LOC]: ” -e t1
if [ -n “$t1” ]; then def_SYS_LOC=”$t1”;fi
read -p “System Contact Name [$def_SYS_CONT_NAME]: ” -e t1
if [ -n “$t1” ]; then def_SYS_CONT_NAME=”$t1”;fi
read -p “System Contact Email [$def_SYS_CONT_EMAIL]: ” -e t1
if [ -n “$t1” ]; then def_SYS_CONT_EMAIL=”$t1”;fi
read -p “Trap Community String [$def_TRAP_COMMUNITY]: ” -e t1
if [ -n “$t1” ]; then def_TRAP_COMMUNITY=”$t1”;fi
read -p “NMS or Trap Reciever Address (IP or FQDN) [$def_TRAP_RECEIVER]: ” -e t1
if [ -n “$t1” ]; then def_TRAP_RECEIVER=”$t1”;fi
read -p “IPv4 subnets that can access SNMP on System [$def_IPv4_SUBNET]: ” -e t1
if [ -n “$t1” ]; then def_IPv4_SUBNET=”$t1”;fi
read -p “IPv6 subnets that can access SNMP on System [$def_IPv6_SUBNET]: ” -e t1
if [ -n “$t1” ]; then def_IPv6_SUBNET=”$t1”;fi
read -p “Read Only Community String [$def_READ_ONLY_SECRET]: ” -e t1
if [ -n “$t1” ]; then def_READ_ONLY_SECRET=”$t1”;fi
read -p “Read Write Community String [$def_READ_WRITE_SECRET]: ” -e t1
if [ -n “$t1” ]; then def_READ_WRITE_SECRET=”$t1”;fi
cat «EOF
=====================
The Answers provided:
=====================
System Location: $def_SYS_LOC
System Contact: $def_SYS_CONT_NAME
System Contact Email: $def_SYS_CONT_EMAIL
RO Community String: $def_READ_ONLY_SECRET
RW Community String $def_READ_WRITE_SECRET
Trap Community String: $def_TRAP_COMMUNITY
Trap Reciever Address: $def_TRAP_RECEIVER
IPv4 Subnet ACL: $def_IPv4_SUBNET
IPv6 Subnet ACL: $def_IPv6_SUBNET
EOF
read -p “Press Y to continue with Install.” -n 1
if [[ ! $REPLY =~ ^[Yy]$ ]]
then
echo “”
echo “Goodbye!”
exit 1
fi
# update system
echo “”
echo “###############################################”
echo “update system”
apt-get -qq update
# install requirements
echo “install requirements”
apt-get -y -qq install snmp
apt-get -y -qq install snmp-mibs-downloader
apt-get -y -qq install snmpd
apt-get -y -qq install libsnmp-base
# Configure SNMP
echo “Configure SNMP”
echo “###############”
cat «EOF > /etc/snmp/snmp.conf
#
# As the snmp packages come without MIB files due to license reasons, loading
# of MIBs is disabled by default. If you added the MIBs you can reenable
# loaging them by commenting out the following line.
#mibs :
EOF
echo “/etc/snmp/snmp.conf - DONE.”
#==========================================
cat «EOF > /etc/snmp/snmpd.conf
############### Generic config information ###############
agentAddress udp:161,udp6:161
sysLocation $def_SYS_LOC
sysServices 72
sysContact $def_SYS_CONT_NAME <$def_SYS_CONT_EMAIL>
rocommunity $def_READ_ONLY_SECRET $def_IPv4_SUBNET
rocommunity6 $def_READ_ONLY_SECRET $def_IPv6_SUBNET
rwcommunity $def_READ_WRITE_SECRET
rwcommunity6 $def_READ_WRITE_SECRET
trapcommunity $def_TRAP_COMMUNITY
trap2sink $def_TRAP_RECEIVER
############### Common config directives ###############
disk /
disk /var
disk /usr
disk /tmp
swap 16000
#linkUpDownNotifications yes
#defaultMonitors yes
master agentx
############### Node specific config directives ###############
EOF
echo “/etc/snmp/snmpd.conf - DONE.”
#==========================================
cat «EOF > /etc/snmp/snmptrapd.conf
#
# PLEASE: read the snmptrapd.conf(5) manual page as well!
#
TRAPDRUN=yes
EOF
echo “/etc/snmp/snmptrapd.conf - DONE.”
#==========================================
cat «EOF > /etc/default/snmpd
SNMPDRUN=yes
SNMPDOPTS=’-Lsd -Lf /dev/null -u snmp -g snmp -I -smux -p /var/run/snmpd.pid’
TRAPDRUN=no
TRAPDOPTS=’-Lsd -p /var/run/snmptrapd.pid’
SNMPDCOMPAT=yes
EOF
echo “/etc/default/snmpd - DONE.”
#==========================================
echo ‘###############’
echo ‘Starting SNMP ‘
echo ‘###############’
/etc/init.d/snmpd restart
sleep 5
if [ “$(pidof snmpd)” ]
then
clear
cat «EOF
Installation and Configuration of snmp
was successful.
INSTRUCTIONS
============
you can test snmp by using the following commands
for IPv4 systems:
snmpwalk -c public -v 2c localhost sysname
for IPv6 systems:
snmpwalk -c public -v 2c udp6:::1 sysname
EOF
else
echo “snmpd FAILED! to start”
echo “Not sure what went wrong.”
fi
exit
Revision: 1.0 - Initial post
1.1 - corrections after testing with ubuntu 8.04