19.02.2013 Views

SNMP Trap Handling für Nagios

SNMP Trap Handling für Nagios

SNMP Trap Handling für Nagios

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>SNMP</strong> <strong>Trap</strong>handling <strong>für</strong> <strong>Nagios</strong><br />

mit snmptt und Shellscripts<br />

Martin Fürstenau<br />

mf@maerber.de<br />

1<br />

September 22, 2006


2<br />

<strong>SNMP</strong> <strong>Trap</strong> <strong>Handling</strong> <strong>für</strong> <strong>Nagios</strong><br />

Methode “<strong>Nagios</strong>”<br />

■ Voraussetzung: snmptrapd muss installiert sein<br />

■ Für jeden <strong>Trap</strong> ist in /etc/snmptrapd.conf ein handle zu<br />

definieren mit folgender Syntax:<br />

traphandle OID Eventhandler/Programm<br />

■ Die Handler übergeben ihr Erbebnis an NSCA<br />

■ Für jeden Handle ist ein Service Check zu übergeben<br />

■ Fazit<br />

■ Aufwendig<br />

■ Schwer zu warten<br />

■ Unflexibel<br />

September 22, 2006


3<br />

<strong>SNMP</strong> <strong>Trap</strong> <strong>Handling</strong> <strong>für</strong> <strong>Nagios</strong><br />

Besser mit snmptt (http://www.snmptt.org)<br />

■ Voraussetzung:<br />

■ snmptrapd muss installiert sein<br />

■ snmptt muss installiert sein<br />

■ Konfigurationsdateien f. snmptt werden per snmpttconvertmib aus<br />

MIBs generiert.<br />

■ Der Eventhandler submit_check_result sollte installiert sein<br />

■ Nachrichtenfluss:<br />

■ snmptrapd übergibt an snmptt<br />

■ snmptt bereitet den <strong>Trap</strong> auf und ruft<br />

■ einen Eventhandler (submit_check_result) auf<br />

■ oder ein Script, das seinerseits einen Eventhandler<br />

(submit_check_result) aufruft<br />

■ der Eventhandler übermittelt das als passiven Check an <strong>Nagios</strong><br />

September 22, 2006


#!/bin/sh<br />

4<br />

<strong>SNMP</strong> <strong>Trap</strong> <strong>Handling</strong> <strong>für</strong> <strong>Nagios</strong><br />

submit_check_result?? (1)<br />

# SUBMIT_CHECK_RESULT<br />

# Written by Ethan Galstad (nagios@nagios.org)<br />

# Last Modified: 02-18-2002<br />

#<br />

# This script will write a command to the <strong>Nagios</strong> command<br />

# file to cause <strong>Nagios</strong> to process a passive service check<br />

# result. Note: This script is intended to be run on the<br />

# same host that is running <strong>Nagios</strong>. If you want to<br />

# submit passive check results from a remote machine, look<br />

# at using the nsca addon.<br />

#<br />

# Arguments:<br />

# $1 = host_name (Short name of host that the service is<br />

# associated with)<br />

# $2 = svc_description (Description of the service)<br />

# $3 = return_code (An integer that determines the state<br />

# of the service check, 0=OK, 1=WARNING, 2=CRITICAL,<br />

# 3=UNKNOWN).<br />

# $4 = plugin_output (A text string that should be used<br />

# as the plugin output for the service check)<br />

September 22, 2006


5<br />

<strong>SNMP</strong> <strong>Trap</strong> <strong>Handling</strong> <strong>für</strong> <strong>Nagios</strong><br />

submit_check_result?? (2)<br />

echocmd="/bin/echo"<br />

CommandFile="/var/spool/nagios/nagios.cmd"<br />

# get the current date/time in seconds since UNIX epoch<br />

datetime=`date +%s`<br />

# create the command line to add to the command file<br />

cmdline="[$datetime] PROCESS_SERVICE_CHECK_RESULT;$1;$2;$3;$4"<br />

# append the command to the end of the command file<br />

`$echocmd $cmdline >> $CommandFile`<br />

September 22, 2006


6<br />

<strong>SNMP</strong> <strong>Trap</strong> <strong>Handling</strong> <strong>für</strong> <strong>Nagios</strong><br />

Konfiguration<br />

■ snmptrapd.conf:<br />

■ traphandle default /usr/sbin/snmptthandler<br />

■ snmptt.ini nach Handbuch<br />

■ Wesentlich d. letzte Abschnitt:<br />

[<strong>Trap</strong>Files]<br />

# A list of snmptt.conf files (this is NOT the snmptrapd.conf file).<br />

The COMPLETE path<br />

# and filename. Ex: '/etc/snmp/snmptt.conf'<br />

snmptt_conf_files =


7<br />

<strong>SNMP</strong> <strong>Trap</strong> <strong>Handling</strong> <strong>für</strong> <strong>Nagios</strong><br />

Beispiel Szenario APX<br />

■ 1 W2K-Server (1 x produktiv, 1 x icecold standby) Poing<br />

■ 1 Testserver Venlo NL<br />

■ 4 <strong>Trap</strong>s<br />

■ Start<br />

■ Stop<br />

■ Heartbeat<br />

■ Alle abgebrochenen Jobs und ihre Probleme<br />

■ Nur <strong>Trap</strong>s vom produktiven Server sollen akzeptiert werden<br />

■ Inhalte wie z.B. Abbruchcode, Severity etc. im Messagestring<br />

des <strong>Trap</strong>s<br />

September 22, 2006


8<br />

<strong>SNMP</strong> <strong>Trap</strong> <strong>Handling</strong> <strong>für</strong> <strong>Nagios</strong><br />

Konvertieren d. benötigten MIBS mit snmpttconvertmib<br />

■ Beispielergebnis /etc/snmptt/snmptt.conf.apx (1):<br />

#<br />

MIB: APX-MIB (file:./apmAPX.mib) converted on Fri Nov 4 16:00:13 2005<br />

using snmpttconvertmib v1.0<br />

#<br />

EVENT apxControlStart .1.3.6.1.4.1.1024.2.24.11.10.0.1081 "Status<br />

Events" Normal<br />

FORMAT Control started $*<br />

EXEC /usr/lib/nagios/ops_plugins/apx_start_trap_wrapper $r<br />

SDESC<br />

Control started<br />

Variables:<br />

1: apxControlState<br />

2: apx<strong>Trap</strong>ID<br />

EDESC<br />

#<br />

September 22, 2006


9<br />

<strong>SNMP</strong> <strong>Trap</strong> <strong>Handling</strong> <strong>für</strong> <strong>Nagios</strong><br />

Konvertieren d. benötigten MIBS mit snmpttconvertmib<br />

■ Beispielergebnis /etc/snmptt/snmptt.conf.apx (2):<br />

#<br />

EVENT apxControlShutdown .1.3.6.1.4.1.1024.2.24.11.10.0.1082 "Status<br />

Events" Normal<br />

FORMAT Control shutdown $*<br />

EXEC /usr/lib/nagios/ops_plugins/apx_stop_trap_wrapper $r<br />

SDESC<br />

Control shutdown<br />

Variables:<br />

1: apxControlState<br />

2: apx<strong>Trap</strong>ID<br />

EDESC<br />

#<br />

September 22, 2006


10<br />

<strong>SNMP</strong> <strong>Trap</strong> <strong>Handling</strong> <strong>für</strong> <strong>Nagios</strong><br />

Konvertieren d. benötigten MIBS mit snmpttconvertmib<br />

■ Beispielergebnis /etc/snmptt/snmptt.conf.apx (3):<br />

#<br />

EVENT apxHeartbeat .1.3.6.1.4.1.1024.2.24.11.10.0.1088 "Status<br />

Events" Normal<br />

FORMAT Control heartbeat $*<br />

EXEC /usr/lib/nagios/ops_plugins/apx_heartbeat_trap_wrapper $r<br />

SDESC<br />

Control heartbeat<br />

Variables:<br />

1: apxControlState<br />

2: apxLastAction<br />

3: apx<strong>Trap</strong>ID<br />

EDESC<br />

#<br />

September 22, 2006


11<br />

<strong>SNMP</strong> <strong>Trap</strong> <strong>Handling</strong> <strong>für</strong> <strong>Nagios</strong><br />

Konvertieren d. benötigten MIBS mit snmpttconvertmib<br />

■ Beispielergebnis /etc/snmptt/snmptt.conf.apx (4):<br />

#<br />

EVENT apxJobCancelled .1.3.6.1.4.1.1024.2.24.11.11.0.2004 "Status<br />

Events" Normal<br />

FORMAT Job cancelled $*<br />

EXEC /usr/lib/nagios/ops_plugins/apx_service_trap_wrapper $r $3 $5<br />

$2 $7 $1<br />

SDESC<br />

Job cancelled<br />

Variables:<br />

1: apx<strong>Trap</strong>ID<br />

2: apxJobkey<br />

3: apxJobname<br />

4: apxJobOID<br />

5: apxCondCode<br />

6: apxJobstate<br />

7: apxGroup<br />

EDESC<br />

September 22, 2006


12<br />

<strong>SNMP</strong> <strong>Trap</strong> <strong>Handling</strong> <strong>für</strong> <strong>Nagios</strong><br />

Die Logfiles (1)<br />

■ snmptrapd.log<br />

2006-09-03 08:32:50 ops-apx01.ops.oce.net [10.53.11.121] (via UDP:<br />

[10.53.11.121]:1048) TRAP, <strong>SNMP</strong> v1, community OCE_PO .<br />

1.3.6.1.4.1.1024.2.24.11.10 Enterprise Specific <strong>Trap</strong> (1081) Uptime: 450<br />

days, 4:48:25.32<br />

.1.3.6.1.4.1.1024.2.24.11.1.1 = STRING: "1081" .<br />

1.3.6.1.4.1.1024.2.24.11.1.201 = STRING: "1,5,0,141" .<br />

1.3.6.1.4.1.1024.2.24.11.1.202 = STRING: "RUN" .<br />

1.3.6.1.4.1.1024.2.24.11.1.203 = STRING: "03.09.2006 08:32:52"<br />

■ snmptt.log<br />

Sun Sep 3 08:32:50 2006 .1.3.6.1.4.1.1024.2.24.11.10.0.1081 Normal<br />

"Status Events" ops-apx01 - Control started 1081 1,5,0,141 RUN<br />

03.09.2006 08:32:52<br />

September 22, 2006


13<br />

<strong>SNMP</strong> <strong>Trap</strong> <strong>Handling</strong> <strong>für</strong> <strong>Nagios</strong><br />

Die Logfiles (2)<br />

■ snmptrapd.log<br />

2006-09-03 08:32:57 ops-apx01.ops.oce.net [10.53.11.121] (via UDP:<br />

[10.53.11.121]:1067) TRAP, <strong>SNMP</strong> v1, community OCE_PO<br />

.1.3.6.1.4.1.1024.2.24.11.10 Enterprise Specific <strong>Trap</strong> (1088) Uptime: 450<br />

days, 4:48:32.93<br />

.1.3.6.1.4.1.1024.2.24.11.1.1 = STRING: "1088" .<br />

1.3.6.1.4.1.1024.2.24.11.1.201 = STRING: "1,5,0,141" .<br />

1.3.6.1.4.1.1024.2.24.11.1.202 = STRING: "RUN" .<br />

1.3.6.1.4.1.1024.2.24.11.1.203 = STRING: "03.09.2006 08:32:59"<br />

■ snmptt.log<br />

Sun Sep 3 08:32:58 2006 .1.3.6.1.4.1.1024.2.24.11.10.0.1088 Normal<br />

"Status Events" ops-apx01 - Control heartbeat 1088 1,5,0,141 RUN<br />

03.09.2006 08:32:59<br />

September 22, 2006


14<br />

<strong>SNMP</strong> <strong>Trap</strong> <strong>Handling</strong> <strong>für</strong> <strong>Nagios</strong><br />

Die Logfiles (3)<br />

■ snmptrapd.log<br />

2006-09-06 12:15:33 ops-apx01.ops.oce.net [10.53.11.121] (via UDP:<br />

[10.53.11.121]:3344) TRAP, <strong>SNMP</strong> v1, community OCE_PO<br />

.1.3.6.1.4.1.1024.2.24.11.11 Enterprise Specific <strong>Trap</strong> (2004) Uptime: 453<br />

days, 8:31:06.25<br />

.1.3.6.1.4.1.1024.2.24.11.1.1 = STRING: "2004" .<br />

1.3.6.1.4.1.1024.2.24.11.1.101 = STRING: "1858194" .<br />

1.3.6.1.4.1.1024.2.24.11.1.102 = STRING: "RP651700_1" .<br />

1.3.6.1.4.1.1024.2.24.11.1.103 = STRING:<br />

"0x081190973FFC4642B68B026E2402423D" .1.3.6.1.4.1.1024.2.24.11.1.104 =<br />

STRING: "ABAP" .1.3.6.1.4.1.1024.2.24.11.1.106 = STRING: "?" .<br />

1.3.6.1.4.1.1024.2.24.11.1.107 = STRING: "MNLsev1"<br />

■ snmptt.log<br />

Wed Sep 6 12:15:33 2006 .1.3.6.1.4.1.1024.2.24.11.11.0.2004 Normal<br />

"Status Events" ops-apx01 - Job cancelled 2004 1858194 RP651700_1<br />

0x081190973FFC4642B68B026E2402423D ABAP ? MNLsev1<br />

September 22, 2006


15<br />

<strong>SNMP</strong> <strong>Trap</strong> <strong>Handling</strong> <strong>für</strong> <strong>Nagios</strong><br />

Define service (siehe snmptt Doku)<br />

define service{ Description<br />

host_name server01 Name of host<br />

service_description TRAP Name of service. What you use here must<br />

match the same value for the<br />

script<br />

is_volatile 1 Enables volatile services<br />

check_command check-host-alive Used to reset the status to OK when<br />

schedule an immediate check of this service<br />

is selected<br />

max_check_attempts 1 Leave as 1.<br />

normal_check_interval 1 Leave as 1<br />

retry_check_interval 1 Leave as 1<br />

passive_checks_enabled 1 Enables passive checks<br />

check_period none When this servcie can be checked. Because<br />

it is a passive service, it never needs to<br />

be automatically checked<br />

notification_interval 31536000 Notification interval.&nbsp; Set to a very high<br />

number to prevent you from getting pages of<br />

previously received traps (1 year - restart <strong>Nagios</strong><br />

at least once a year! - do not set to 0!).<br />

notification_period 24x7 When you can be notified. Can be changed<br />

notification_options w,u,c,r Notify on warning, unknown, critical and recovery<br />

notifications_enabled 1 Enable notifications<br />

contact_groups cg_core Name of contact group to notify<br />

September 22, 2006


16<br />

<strong>SNMP</strong> <strong>Trap</strong> <strong>Handling</strong> <strong>für</strong> <strong>Nagios</strong><br />

Definition Service Template (im Beispiel f.APX)<br />

define service{ name APX-SERVER<br />

register 0<br />

host_name ops-apx01<br />

passive_checks_enabled 1<br />

notifications_enabled 1<br />

is_volatile 1<br />

check_period none<br />

check_freshness 1<br />

max_check_attempts 1<br />

normal_check_interval 1<br />

flap_detection_enabled 0<br />

retry_check_interval 1<br />

contact_groups apx-admins,apx-admins_sms<br />

notification_interval 31536000<br />

notification_period 24x7<br />

}<br />

define service{ name APX-TRAP<br />

use APX-SERVER<br />

register 0<br />

# Nach 5 Stunden werden <strong>Trap</strong>s v. Service Checks zureuckgesetzt<br />

freshness_threshold 18000<br />

check_command apx_service_trap_reset<br />

notification_options c,w<br />

}<br />

September 22, 2006


17<br />

<strong>SNMP</strong> <strong>Trap</strong> <strong>Handling</strong> <strong>für</strong> <strong>Nagios</strong><br />

Definition Service (im Beispiel f.APX)<br />

define service{<br />

use APX-TRAP<br />

service_description RP818100<br />

}<br />

September 22, 2006


18<br />

<strong>SNMP</strong> <strong>Trap</strong> <strong>Handling</strong> <strong>für</strong> <strong>Nagios</strong><br />

Beispiel Wrapper: apx_heartbeat_trap_wrapperefinition (1)<br />

#!/bin/bash<br />

# Author: M.Fuerstenau, OPS, Poing<br />

# Purpose:<br />

# Will ge startet from snmptt (Config-file /etc/snmptt/snmptt.conf.apx)<br />

# Instead of being started directly from the mentioned config file<br />

# the use of this wrapper was necessary due to the fact that the<br />

# service name for the <strong>Nagios</strong> service has to be generated and<br />

# that strings like "APXsev1" must be mapped to the appropriate<br />

# <strong>Nagios</strong> return code<br />

HOST=$1<br />

NAGIOS_DIR=/etc/nagios<br />

# Pruefen, ob es den sendenden Host ueberhaupt gibt. Sonst raus.<br />

grep ^$HOST$ $NAGIOS_DIR/hosts/* 1>&2 > /dev/null<br />

RETCO=$?<br />

if [ $RETCO -ne 0 ]<br />

fi<br />

then<br />

exit 1<br />

September 22, 2006


19<br />

<strong>SNMP</strong> <strong>Trap</strong> <strong>Handling</strong> <strong>für</strong> <strong>Nagios</strong><br />

Beispiel Wrapper: apx_heartbeat_trap_wrapperefinition (2)<br />

# IP des produktiven Host ermitteln<br />

PROD_HOST=$(grep host_name $NAGIOS_DIR/services/APX-TRAP-template.cfg | awk<br />

'{print $2}')<br />

HOST_PROD_CFG=$(grep ^$PROD_HOST$ $NAGIOS_DIR/hosts/* | grep host_name |<br />

awk '{print $1}' | sed 's/:$//')<br />

PROD_IP=$(grep address $HOST_PROD_CFG | grep -v '#' | awk '{print $2}')<br />

# IP des anfragenden Hosts ermitteln (da der mal mit Hostname (Poing) oder<br />

IP (Venlo) daherkummt)<br />

STR_2_GREP=$(grep ^$HOST$ $NAGIOS_DIR/hosts/* | grep -v alias |awk '{print<br />

$2}')<br />

HOST_ASK_CFG=$(grep ^$HOST$ $NAGIOS_DIR/hosts/* | grep $STR_2_GREP | awk<br />

'{print $1}' | sed 's/:$//')<br />

ASK_IP=$(grep address $HOST_ASK_CFG | grep -v '#' | awk '{print $2}')<br />

if [ "$PROD_IP" = "$ASK_IP" ]<br />

fi<br />

then<br />

/usr/lib/nagios/eventhandlers/submit_check_result $HOST APX_Heartbeat 0<br />

"APX is running"<br />

exit 0<br />

else<br />

exit 1<br />

September 22, 2006


#!/bin/sh<br />

HOST=$1<br />

20<br />

<strong>SNMP</strong> <strong>Trap</strong> <strong>Handling</strong> <strong>für</strong> <strong>Nagios</strong><br />

Beispiel (Re)set: apx_heartbeat_alarm_set<br />

/usr/lib/nagios/eventhandlers/submit_check_result $HOST APX_Heartbeat<br />

2 "Heartbeat signal from APX is missing. Maybe system is not<br />

running!"<br />

exit 2<br />

September 22, 2006


21<br />

<strong>SNMP</strong> <strong>Trap</strong> <strong>Handling</strong> <strong>für</strong> <strong>Nagios</strong><br />

Beispiel Wrapper: apx_service_trap_wrapper (1)<br />

#!/bin/bash<br />

# Author: M.Fuerstenau, OPS, Poing<br />

# 18.11.2005<br />

#<br />

# Purpose:<br />

# Will ge startet from snmptt (Config-file /etc/snmptt/snmptt.conf.apx)<br />

# Instead of being started directly from the mentioned config file<br />

# the use of this wrapper was necessary due to the fact that the<br />

# service name for the <strong>Nagios</strong> service has to be generated and<br />

# that strings like "APXsev1" must be mapped to the appropriate<br />

# <strong>Nagios</strong> return code<br />

# Anzahl uebergebener Argumente pruefen<br />

if [ $# -ne 6 ]<br />

then<br />

echo $*<br />

echo "Wrong number of arguments - exiting"<br />

exit 1<br />

fi<br />

September 22, 2006


22<br />

<strong>SNMP</strong> <strong>Trap</strong> <strong>Handling</strong> <strong>für</strong> <strong>Nagios</strong><br />

Beispiel Wrapper: apx_service_trap_wrapper (2)<br />

# Uebergebene Argumente Variablen zuordnen<br />

HOST=$1<br />

APX_JOB_NAME=$2<br />

APX_COND_CODE=$3<br />

APX_JOB_KEY=$4<br />

APX_GROUP=$5<br />

APX_TRAP=$6<br />

# Globale Variablen setzen<br />

NAGIOS_DIR=/etc/nagios<br />

HAMLET=0<br />

# Pruefen, ob es den sendenden Host ueberhaupt gibt. Sonst raus.<br />

grep ^$HOST$ $NAGIOS_DIR/hosts/* 1>&2 > /dev/null<br />

RETCO=$?<br />

September 22, 2006


23<br />

<strong>SNMP</strong> <strong>Trap</strong> <strong>Handling</strong> <strong>für</strong> <strong>Nagios</strong><br />

Beispiel Wrapper: apx_service_trap_wrapper (3)<br />

if [ $RETCO -ne 0 ]<br />

then<br />

exit 1<br />

fi<br />

# IP des produktiven Host ermitteln<br />

PROD_HOST=$(grep host_name $NAGIOS_DIR/services/APX-TRAP-template.cfg | awk<br />

'{print $2}')<br />

HOST_PROD_CFG=$(grep ^$PROD_HOST$ $NAGIOS_DIR/hosts/* | grep host_name |<br />

awk '{print $1}' | sed 's/:$//')<br />

PROD_IP=$(grep address $HOST_PROD_CFG | grep -v '#' | awk '{print $2}')<br />

# IP des anfragenden Hosts ermitteln (da der mal mit Hostname (Poing) oder<br />

IP (Venlo) daherkummt)<br />

STR_2_GREP=$(grep ^$HOST$ $NAGIOS_DIR/hosts/* | grep -v alias |awk '{print<br />

$2}')<br />

HOST_ASK_CFG=$(grep ^$HOST$ $NAGIOS_DIR/hosts/* | grep $STR_2_GREP | awk<br />

'{print $1}' | sed 's/:$//')<br />

ASK_IP=$(grep address $HOST_ASK_CFG | grep -v '#' | awk '{print $2}')<br />

September 22, 2006


24<br />

<strong>SNMP</strong> <strong>Trap</strong> <strong>Handling</strong> <strong>für</strong> <strong>Nagios</strong><br />

Beispiel Wrapper: apx_service_trap_wrapper (4)<br />

if [ $RETCO -ne 0 ]<br />

then<br />

exit 1<br />

fi<br />

# IP des produktiven Host ermitteln<br />

PROD_HOST=$(grep host_name $NAGIOS_DIR/services/APX-TRAP-template.cfg | awk<br />

'{print $2}')<br />

HOST_PROD_CFG=$(grep ^$PROD_HOST$ $NAGIOS_DIR/hosts/* | grep host_name |<br />

awk '{print $1}' | sed 's/:$//')<br />

PROD_IP=$(grep address $HOST_PROD_CFG | grep -v '#' | awk '{print $2}')<br />

# IP des anfragenden Hosts ermitteln (da der mal mit Hostname (Poing) oder<br />

IP (Venlo) daherkummt)<br />

STR_2_GREP=$(grep ^$HOST$ $NAGIOS_DIR/hosts/* | grep -v alias |awk '{print<br />

$2}')<br />

HOST_ASK_CFG=$(grep ^$HOST$ $NAGIOS_DIR/hosts/* | grep $STR_2_GREP | awk<br />

'{print $1}' | sed 's/:$//')<br />

ASK_IP=$(grep address $HOST_ASK_CFG | grep -v '#' | awk '{print $2}')<br />

September 22, 2006


25<br />

<strong>SNMP</strong> <strong>Trap</strong> <strong>Handling</strong> <strong>für</strong> <strong>Nagios</strong><br />

Beispiel Wrapper: apx_service_trap_wrapper (5)<br />

# Katastophe oder Warnung - dass ist hier die Frage<br />

case "$APX_GROUP" in<br />

APXsev1) HAMLET=2 ;;<br />

APXsev2) HAMLET=1 ;;<br />

MNLsev1) HAMLET=2 ;;<br />

MNLsev2) HAMLET=1 ;;<br />

EUROCEsev1) HAMLET=2 ;;<br />

EUROCEsev2) HAMLET=1 ;;<br />

SMSTESTsev1) HAMLET=2 ;;<br />

SMSTESTsev2) HAMLET=1 ;;<br />

*) echo "Unknown groupcode - babe, it is impossible"<br />

esac<br />

September 22, 2006


26<br />

<strong>SNMP</strong> <strong>Trap</strong> <strong>Handling</strong> <strong>für</strong> <strong>Nagios</strong><br />

Beispiel Wrapper: apx_service_trap_wrapper (6)<br />

#<br />

# Pruefen of der den <strong>Trap</strong> sendende Host gleich dem ueberwachten ist. Wenn<br />

ja, weiter, sonst raus<br />

if [ "$PROD_IP" = "$ASK_IP" ]<br />

then<br />

/usr/lib/nagios/eventhandlers/submit_check_result $HOST $APX_JOB_NAME<br />

$HAMLET "Job $APX_JOB_NAME cancelled - Condition Code: $APX_COND_CODE -<br />

APX JobName $APX_JOB_KEY - APX Group $APX_GROUP - APX <strong>Trap</strong> ID $APX_TRAP"<br />

exit 0<br />

else<br />

exit 1<br />

fi<br />

September 22, 2006


27<br />

<strong>SNMP</strong> <strong>Trap</strong> <strong>Handling</strong> <strong>für</strong> <strong>Nagios</strong><br />

Beispiel Reset: apx_service_trap_reset<br />

#!/bin/sh<br />

echo "Ok. No error. No warning."<br />

exit 0<br />

September 22, 2006


28<br />

<strong>SNMP</strong> <strong>Trap</strong> <strong>Handling</strong> <strong>für</strong> <strong>Nagios</strong><br />

Beispiel: Start und Stop<br />

■ Auszug aus apx_start_trap_wrapper:<br />

if [ "$PROD_IP" = "$ASK_IP" ]<br />

then<br />

/usr/lib/nagios/eventhandlers/submit_check_result $HOST<br />

APX_Start_Stop 0 "APX started"<br />

exit 0<br />

else<br />

exit 1<br />

fi<br />

■ Auszug aus apx_stop_trap_wrapper:<br />

if [ "$PROD_IP" = "$ASK_IP" ]<br />

then<br />

/usr/lib/nagios/eventhandlers/submit_check_result $HOST<br />

APX_Start_Stop 2 "APX shutdown"<br />

exit 0<br />

else<br />

exit 1<br />

fi<br />

September 22, 2006

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!