You will need to setup your device to send SNMP traps to the Nagios Core server, it is different for each piece of hardware, you will need to work with your vendor to determine how to set it up.
For the Core side, the general process is this:
As an example, let's say that I want to show linkUp and linkDown traps in Nagios for a Cisco switch.
First you need to configure the Cisco switch to send them to the Nagios server.
Then run the script from the document to setup SNMP traps on Nagios (I know it says for XI but it works for Core as well).
Then you would add the appropriate MIB files to /usr/share/snmp/mibs
- In our example the MIB file that we need is already on the system (/usr/share/snmp/mibs/IF-MIB.txt)
- By default snmptt comes installed with some default traps that we want to get rid of:
Then run the addmib command on the file:
- This will add it to the /etc/snmp/snmptt.conf file with the proper EXEC line that will put it into Nagios.
Code: Select all
addmib /usr/share/snmp/mibs/IF-MIB.txt
Here are the entries it creates:
Code: Select all
MIB: IF-MIB (file:/usr/share/snmp/mibs/IF-MIB.txt) converted on Thu Sep 3 13:59:59 2015 using snmpttconvertmib v1.3
#
#
#
EVENT linkDown .1.3.6.1.6.3.1.1.5.3 "Status Events" Normal
FORMAT A linkDown trap signifies that the SNMP entity, acting in $*
EXEC /usr/local/bin/snmptraphandling.py "$r" "SNMP Traps" "$s" "$@" "$-*" "A linkDown trap signifies that the SNMP entity, acting in $*"
SDESC
A linkDown trap signifies that the SNMP entity, acting in
an agent role, has detected that the ifOperStatus object for
one of its communication links is about to enter the down
state from some other state (but not from the notPresent
state). This other state is indicated by the included value
of ifOperStatus.
Variables:
1: ifIndex
2: ifAdminStatus
3: ifOperStatus
EDESC
#
#
#
EVENT linkUp .1.3.6.1.6.3.1.1.5.4 "Status Events" Normal
FORMAT A linkUp trap signifies that the SNMP entity, acting in an $*
EXEC /usr/local/bin/snmptraphandling.py "$r" "SNMP Traps" "$s" "$@" "$-*" "A linkUp trap signifies that the SNMP entity, acting in an $*"
SDESC
A linkUp trap signifies that the SNMP entity, acting in an
agent role, has detected that the ifOperStatus object for
one of its communication links left the down state and
transitioned into some other state (but not into the
notPresent state). This other state is indicated by the
included value of ifOperStatus.
Variables:
1: ifIndex
2: ifAdminStatus
3: ifOperStatus
EDESC
Notice how they both say Normal, we know that linkUp should be Normal but we want linkDown to be Critical so we would change this line from:
Code: Select all
EVENT linkDown .1.3.6.1.6.3.1.1.5.3 "Status Events" Normal
To:
Code: Select all
EVENT linkDown .1.3.6.1.6.3.1.1.5.3 "Status Events" Critical
Now we restart the snmptt service (every time you use addmib or edit your /etc/snmp/snmptt.conf file you need to restart snmtt server so that changes take effect):
Now you should setup the service in Nagios:
The template:
Code: Select all
define service {
name snmp_trap_template
service_description SNMP Trap Template
active_checks_enabled 1 ; Active service checks are enabled
passive_checks_enabled 1 ; Passive service checks are enabled/accepted
parallelize_check 1 ; Active service checks should be parallelized
process_perf_data 0
obsess_over_service 0 ; We should obsess over this service (if necessary)
check_freshness 0 ; Default is to NOT check service 'freshness'
notifications_enabled 1 ; Service notifications are enabled
event_handler_enabled 1 ; Service event handler is enabled
flap_detection_enabled 1 ; Flap detection is enabled
process_perf_data 1 ; Process performance data
retain_status_information 1 ; Retain status information across program restarts
retain_nonstatus_information 1 ; Retain non-status information across program restarts
check_command check-host-alive ; This will be used to reset the service to "OK"
is_volatile 1
check_period 24x7
max_check_attempts 1
normal_check_interval 1
retry_check_interval 1
notification_interval 60
notification_period 24x7
notification_options w,u,c,r
contact_groups nagiosadmins ; Modify this to match your Nagios contactgroup definitions
register 0
}
The service:
Code: Select all
define service {
use snmp_trap_template
hostgroup_name switches,routers
service_description SNMP Trap
check_interval 60 ; Don't clear for 1 hour
}
Now restart the Nagios service:
Now generate the trap on the device (pull a network cable on our device, or you can test with the snmptrap command) and it should send it in, the process is:
device > snmptrapd > snmptt > snmptraphandling.py > Nagios
You can watch the log files under /var/log/snmptt/* for the trap to come in, the trap hostname needs to be identical (IP or name (case-sensitive)) to what is in Nagios for it to work.
You may need to adjust these settings in your /etc/snmp/snmptt.ini file to what you want them set as:
Code: Select all
# SNMPTRAPD passes the IP address of device sending the trap, and the IP address of the
# actual SNMP agent. These addresses could differ if the trap was sent on behalf of another
# device (relay, proxy etc).
# If DNS is enabled, the agent IP address is converted to a host name using a DNS lookup
# (which includes the local hosts file, depending on how the OS is configured). This name
# will be used for: NODES entry matches, hostname field in logged traps (file / database),
# and the $A variable. Host names on the NODES line will be resolved and the IP address
# will then be used for comparing.
# Set to 0 to disable DNS resolution
# Set to 1 to enable DNS resolution
dns_enable = 1
# Set to 0 to enable the use of FQDN (Fully Qualified Domain Names). If a host name is
# passed to SNMPTT that contains a domain name, it will not be altered in any way by
# SNMPTT. This also affects resolve_value_ip_addresses.
# Set to 1 to have SNMPTT strip the domain name from the host name passed to it. For
# example, server01.domain.com would be changed to server01
# Set to 2 to have SNMPTT strip the domain name from the host name passed to it
# based on the list of domains in strip_domain_list
strip_domain = 1
Don't forget to restart snmptt if you make changes to the /etc/snmp/snmptt.ini as well: