Sunday, October 27, 2013

nagios snmptt configuration

Hi folks after long time !. Today I'm going to demonstrate how to configure SNMP trap inside Nagios using SNMPTT. This simulation is done at Virtualbox 4.1.26 using two guest OS ( one guest act as server and running Nagios and snmptt, other is to generate SNMP trap and it is the client)

both guest are running Centos 6.3 32bit.

Server info :- ip 192.168.56.103
Client info :- 1p 192.168.56.104

I hope you have installed and configured the Nagios, If not you can follow installation guide
http://nagios.sourceforge.net/docs/nagioscore/4/en/quickstart-fedora.html

-----

So let's install snmptt. :)
download and extract latest version of SNMPTT. you can find official installation document from here
http://www.snmptt.org/docs/snmptt.shtml#Installation-Overview

For both server and client require net-snmp-lib , net-snmp-util so install them using using yum
yum install net-snmp-lib
yum install net-snmp-util


AT Server


1)Install prerequirement such as net-snmp, perl ,perl modules


[root@nagios ~]# yum install net-snmp
[root@nagios ~]# yum install perl

install perl cpan
[root@nagios ~]# yum install perl-CPAN

launch the CPAN using following command
[root@nagios ~]# perl -MCPAN -e shell

install following perlmodules 
(Getopt::Long,  Text::ParseWords ,SNMP, Config::IniFiles, Time::HiRes , Sys::Hostname , File::Basename, Text::Balanced )
for an instance
cpan[1]> install Text::ParseWords


This demonstration is done with Standard handler – with standlone mode which is straightforward (remember there is daemon mode)


2) Copy snmptt to /usr/sbin/ and ensure it is executable (chmod +x snmptt)

[root@nagios snmptt_1.3]# cp s[root@nagios snmptt_1.3]# chmod +x /usr/sbin/snmptt nmptt /usr/sbin/

3) Copy snmptthandler to /usr/sbin/ and ensure it is executable (chmod +x snmptthandler)

[root@nagios snmptt_1.3]# cp snmptthandler /usr/sbin/
[root@nagios snmptt_1.3]# chmod +x /usr/sbin/snmptthandler

4) Copy snmptt.ini to /etc/snmp/ or /etc/ and edit the options inside the file.

[root@nagios snmptt_1.3]# cp snmptt.ini /etc/snmp/

5) Create the log folder /var/log/snmptt/.

[root@nagios snmptt_1.3]# mkdir -p /var/log/snmptt/


6) For standlone mode:  Modify the Net-SNMP snmptrapd.conf file by adding the following line:

[root@nagios ~]# vim /etc/snmp/snmptrapd.conf
traphandle default /usr/sbin/snmptt
disableAuthorization yes

7) Edit the /etc/logrotate.d/snmptt and update the paths and rotate frequency as needed.

[root@nagios snmptt_1.3]# cp snmptt.logrotate /etc/logrotate.d/snmptt


8) Start snmptrapd using the command line:  snmptrapd -On.

[root@nagios snmptt_1.3]# snmptrapd –On

--

9) Convert MIB file


Copy eventhandler
[root@nagios ~]# cp /home/shehan/Downloads/nagios-4.0.1/contrib/eventhandlers/* /usr/local/nagios/libexec/eventhandlers

copy snmpttconvertmib into /usr/sbin/ folder
[root@nagios ~]# cp /home/shehan/Downloads/snmptt_1.3/snmpttconvertmib /usr/sbin/

then issue below command
[root@nagios ~]#snmpttconvertmib --in=/usr/share/snmp/mibs/SNMPv2-MIB.txt --out=/etc/snmp/snmptt.conf.SNMPv2-MIB \
--exec='/usr/local/nagios/libexec/eventhandlers/submit_check_result $r TRAP 1'


10) Edit /etc/snmp/snmptt.ini, and change below settings

[General]
mode = standalone
net_snmp_perl_enable = 1
unknown_trap_log_enable = 1

At end of file you can find line similar to this Add /etc/snmp/snmptt.conf.NET-SNMP-EXAMPLES-MIB like below

snmptt_conf_files = <<END
/etc/snmp/snmptt.conf
/etc/snmp/snmptt.conf.NET-SNMP-EXAMPLES-MIB
END


11) create host cfg file

[root@nagios ~]# vim /usr/local/nagios/etc/objects/remote-host.cfg
And add below (you may need to change ip host_name)


define host {
        use     linux-server
        host_name       remote-host
        alias           remote-host-alias
        address         192.168.56.104
        }

define service{
        use                        generic-service
        name                       trap-service
        register                   0
        service_description        TRAP
        is_volatile                1
        check_command              check-host-alive
        max_check_attempts         1
        normal_check_interval      1
        retry_check_interval       1
        notification_interval      31536000
        active_checks_enabled      0
        passive_checks_enabled     1
    check_period           24x7
        }

define service{
        use                        trap-service
        host_name                  remote-host
        }



12) Add blow command to nagios.cfg

[root@nagios ~]# vim /usr/local/nagios/etc/nagios.cfg
cfg_file=/usr/local/nagios/etc/objects/remote-host.cfg


13)allow snmp trap from firewall

[root@nagios ~]# iptables -I INPUT 1 -p udp --dport snmptrap -j ACCEPT

confirm the changes and then save using below command
[root@nagios ~]# iptabless –list
[root@nagios ~]# service iptables save

14) start service at server

[root@nagios ~]# service snmptrapd start
[root@nagios ~]# service snmpd start

configure to start at boot
[root@nagios ~]#chkconfig snmptrapd on
[root@nagios ~]#chkconfig snmpd on


AT Client,

generate SNMP trap message, this is SNMP v2 message

[root@localhost ~]# snmptrap -v 2c -c public 192.168.56.101 "" SNMPv2-MIB::coldStart coldStart  s "start"


AT Server


check below log messages
/var/log/messages
/var/log/snmptt/snmptt.log
And check nagios web interface.If everything works fine you can have similar output like below


nagios and  snmptt








----


Reference URLS

http://xavier.dusart.free.fr/nagios/en/snmptraps.html
http://hummy.wikidot.com/how-to-send-and-receive-snmp-traps
http://socketubs.org/docs/sysadmin/snmp_traps_nagios.html


Related Posts