2- Change the script /etc/snmp/snmptrapd.conf file and include "disableAuthorization yes"
# Example configuration file for snmptrapd
# No traps are handled by default, you must edit this file!
# authCommunity log,execute,net public
# traphandle SNMPv2-MIB::coldStart /usr/bin/bin/my_great_script cold
4- Startup a simple SNMP trap daemon to log traps to the /tmp/traps.log file for testing purposes.
nohup snmptrapd -m ALL -A -n -Lf /tmp/traps.log &
5- Invoke a test trap to ensure that the snmptrapd is logging appropriately to /tmp/traps.log and the Apache Ambari MIB is being respected.
snmptrap -v 2c -c public localhost '' APACHE-AMBARI-MIB::apacheAmbariAlert alertDefinitionName s "definitionName" alertDefinitionHash s "definitionHash" alertName s "name" alertText s "text" alertState i 0 alertHost s "host" alertService s "service" alertComponent s "component"
6- You should be able to see the below traps in /tmp/traps.log.
7- Now we will be creating the script which will be used by Ambari for sending SNMP traps.
Create a file that contains the script, named /tmp/snmp_mib_script.sh, in this example. It's recommended to create this file in a more permanent directory for actual use.
Format of the Alert Script--
if [[ $4 == "OK" ]]; then
elif [[ $4 == "UNKNOWN" ]]; then
elif [[ $4 == "WARNING" ]]; then
elif [[ $4 == "CRITICAL" ]]; then
/usr/bin/snmptrap -v 2c \
-c $COMMUNITY $HOST '' APACHE-AMBARI-MIB::apacheAmbariAlert \
alertDefinitionId i 0 \
alertDefinitionName s "$1" \
alertDefinitionHash s "n/a" \
alertName s "$2" \
alertText s "$5" \
alertState i $STATE \
alertHost s `hostname` \
alertService s "$3" \
Note-- Make Sure to change the Host with the desired sandbox or host where you want to send the traps.