#!/bin/bash # https://linux.die.net/man/1/snmptrap echo "################################################################################" >> /usr/lib/zabbix/alertscripts/log_snmptraps_test.txt echo "EJECUCION DE TRAPSEND.SH" >> /usr/lib/zabbix/alertscripts/log_snmptraps_test.txt echo -e "\nALERT_MESSAGE: " >> /usr/lib/zabbix/alertscripts/log_snmptraps_test.txt echo $2 >> /usr/lib/zabbix/alertscripts/log_snmptraps_test.txt HOST_TEMIP="xx.xx.xxx.xx:xxxx" SNMP_COMMUNITY="public" ALERT_SUBJECT=$1 ALERT_MESSAGE=$2 ID=$(echo $ALERT_MESSAGE | awk -F 'enterprises.4100.1.1 type=2 value=INTEGER: ' '{print $2}' | cut -d ' ' -f1) CASO_USO=$(echo $ALERT_MESSAGE | awk -F 'enterprises.4100.1.2 type=4 value=STRING: ' '{print $2}' | cut -d '"' -f2) SERVER=$(echo $ALERT_MESSAGE | awk -F 'enterprises.4100.1.3 type=4 value=STRING: ' '{print $2}' | cut -d '"' -f2) MSGCORTO=$(echo $ALERT_MESSAGE | awk -F 'enterprises.4100.1.4 type=4 value=STRING: ' '{print $2}' | cut -d '"' -f2) MSGLARGO=$(echo $ALERT_MESSAGE | awk -F 'enterprises.4100.1.5 type=4 value=STRING: ' '{print $2}' | cut -d '"' -f2) TIPO_ALERTA=$(echo $ALERT_MESSAGE | awk -F 'Trigger_name:SNMP Trap Trigger:Trigger_status:' '{print $2}' | cut -d: -f1) IP_SERVER=$(echo $ALERT_MESSAGE | awk -F 'enterprises.4100.1.8 type=64 value=IpAddress: ' '{print $2}') SEVERIDAD=$(echo $ALERT_MESSAGE | awk -F 'enterprises.4100.1.6 type=4 value=STRING: ' '{print $2}' | cut -d '"' -f2) CLEAR="_" SET="_" if [[ $TIPO_ALERTA == "OK" ]];then CLEAR="CLEAR" else SET="SET" fi echo -e "\nSEVERIDAD: " >> /usr/lib/zabbix/alertscripts/log_snmptraps_test.txt echo $SEVERIDAD >> /usr/lib/zabbix/alertscripts/log_snmptraps_test.txt # Envio de trap snmptrap -v2c -c ${SNMP_COMMUNITY} ${HOST_TEMIP} \'\' .1.3.6.1.4.1.32542.1.1.1.2 \ .1.3.6.1.4.1.32542.1.1.1.1.1.1 i "$ID" \ .1.3.6.1.4.1.32542.1.1.1.1.1.2 i 1 \ .1.3.6.1.4.1.32542.1.1.1.1.1.3 s "$CASO_USO" \ .1.3.6.1.4.1.32542.1.1.1.1.1.4 s "$SERVER" \ .1.3.6.1.4.1.32542.1.1.1.1.1.5 s "$MSGCORTO" \ .1.3.6.1.4.1.32542.1.1.1.1.1.6 s "$MSGLARGO" \ .1.3.6.1.4.1.32542.1.1.1.1.1.7 s "$SET" \ .1.3.6.1.4.1.32542.1.1.1.1.1.8 s "$CLEAR" \ .1.3.6.1.4.1.32542.1.1.1.1.1.9 a "$IP_SERVER" \ .1.3.6.1.4.1.32542.1.1.1.1.1.10 s "$SEVERIDAD" # LOG echo -e "\nTRAP ENVIADO: " >> /usr/lib/zabbix/alertscripts/log_snmptraps_test.txt echo " snmptrap -v2c -c ${SNMP_COMMUNITY} ${HOST_TEMIP} \'\' .1.3.6.1.4.1.32542.1.1.1.2 \ .1.3.6.1.4.1.32542.1.1.1.1.1.1 i "$ID" \ .1.3.6.1.4.1.32542.1.1.1.1.1.2 i 1 \ .1.3.6.1.4.1.32542.1.1.1.1.1.3 s "$CASO_USO" \ .1.3.6.1.4.1.32542.1.1.1.1.1.4 s "$SERVER" \ .1.3.6.1.4.1.32542.1.1.1.1.1.5 s "$MSGCORTO" \ .1.3.6.1.4.1.32542.1.1.1.1.1.6 s "$MSGLARGO" \ .1.3.6.1.4.1.32542.1.1.1.1.1.7 s "$SET" \ .1.3.6.1.4.1.32542.1.1.1.1.1.8 s "$CLEAR" \ .1.3.6.1.4.1.32542.1.1.1.1.1.9 a "$IP_SERVER" \ .1.3.6.1.4.1.32542.1.1.1.1.1.10 s "$SEVERIDAD" " >> /usr/lib/zabbix/alertscripts/log_snmptraps_test.txt exit 0