18 January 2014

Installing Net-SNMP and SNMPTT in Fedora 20

Documenting this on-the-fly for my reference and anyone else who would find it useful.

After freshly installing Fedora 20, I was perplexed to find that it didn't have gcc or g++ installed. So step 1 is to get them. (You don't really have to use sudo in all steps below)

sudo yum install gcc 

sudo yum install gcc-c++

You can also optionally install mysql (if you wish to have MYSQL Trap Logging) like so:

sudo yum install mysql
sudo yum install mysql-server
sudo yum install mysql-devel
sudo chgrp -R mysql /var/lib/mysql
sudo chmod -R 770 /var/lib/mysql
sudo service mysqld start 


Also ensure Perl and a supporting module is installed:

sudo yum install perl

(you might be able to install all supporting modules for Perl like this: "sudo yum install perl-*", do give it a shot. It'll be a larger download though)

You'll need two ExtUtils of Perl which you can either install separately like this:

sudo yum install perl-ExtUtils-MakeMaker
sudo yum install perl-ExtUtils-Embed

or install everything in one go like so:

sudo yum install perl-ExtUtils-*

For running snmptt, you'll also need:

sudo yum install perl-Config-*
 
 

Then download Net-SNMP, and extract it into your /usr/local/ folder with:

sudo tar -xvzf net-snmp-5.7.2.tar.gz.

Navigate into the newly created net-snmp directory and type:


sudo ./configure --enable-embedded-perl --enable-shared --with-mysql

Or if you don't want embedded perl, type (you'll need to install with embedded perl for this tutorial):

sudo ./configure --with-perl-modules --with-mysql

You'll be given a lot of options. Just keep pressing enter for all of them (unless you want to configure it differently).
Once configuration is done, type:

sudo make -j 4

The -j 4 is to tell make that it can use the four cores of my processor. It works faster this way, by dividing the make process into separate jobs which complete parallelly. You can also simply type "sudo make". At any point if you want to redo the make process, type "sudo make clean" and you'll be able to start from the configure step again.


Now you can optionally start "make test" which is not really required, but it is what helped me find out that I didn't have ExtUtils-MakeMaker installed. I wasn't able to make install without it, and the net-snmp mailing list was unable to figure it out either. I updated the mailing list with the solution when I found it.

sudo make test
sudo make install 

...and tadaah! You now have net-snmp installed!
The snmptrapd file which snmptt requires, you'll now find installed in /usr/local/sbin/snmptrapd

To be able to start and stop snmptrapd, a script is also included.
sudo cp /usr/local/net-snmp-5.7.2/dist/snmptrapd-init.d /etc/rc.d/init.d/snmptrapd

You can optionally use the above script to start snmptrapd with the command "sudo service snmptrapd start"or "snmptrapd -On"



------------------------------------

Now for snmptt:

Extract the snmptt tar file into /usr/local/ using:

sudo tar -xvzf snmptt_1.4.tgz

Navigate into the newly created snmptt_1.4 directory and create a file named snmptrapd.conf:

sudo vim snmptrapd.conf



To test out snmptrapd, add the line "disableAuthorization yes" to the snmptrapd.conf file (remove this line later for proper authorizations) and type the following command at the terminal:

sudo /usr/local/sbin/snmptrapd -f -Lo -c /usr/local/snmptt_1.4/snmptrapd.conf

snmptrapd will start and will keep listening for traps.
Meanwhile, download and start a MIB browser like the one iReasoning has.
Go to Tools > Trap sender in the MIB browser and type the address to send traps to, as "localhost" (without the quotes). Then click the "Send Trap" and immediately, you'll see the trap being received at the terminal where you started snmptrapd.


You have the choice of installing snmptt as a standard handler or as an embedded handler. I'd recommend installing as the embedded handler, because it is loaded when snmptrapd is started, so it won't need a process to be created everytime a trap is received (which is what happens with the standard handler). Type the following commands:

sudo cp snmptt /usr/sbin 
sudo chmod +x /usr/sbin/snmptt
sudo cp snmptthandler-embedded /usr/sbin/
sudo mkdir /etc/snmp/
sudo cp snmptt.ini /etc/snmp/ (you can change settings in this file)

sudo cp examples/snmptt.conf.generic /etc/snmp/snmptt.conf
sudo mkdir /var/log/snmptt/

Open the snmptrapd.conf file and add the following line to it "perl do "/usr/sbin/snmptthandler-embedded";"

sudo mkdir /var/spool/snmptt

sudo cp snmptt-init.d /etc/rc.d/init.d/snmptt (this is a script that can be used to start and stop snmptt)

and now add snmptt as a service:
sudo chkconfig --add snmptt

Configure snmptt to start at runlevel 2345
sudo chkconfig --level 2345 snmptt on

The above command will start snmptt automatically on reboot. You can also start it right now using:

sudo service snmptt start

To stop it, use:
 
sudo service snmptt stop


Copy a script to rotate log files:
sudo cp snmptt.logrotate /etc/logrotate.d/snmptt (you can edit this file if you wish)



No comments: