Changes between Version 2 and Version 3 of OMDeventhandlers

Show
Ignore:
Timestamp:
10/04/11 12:18:58 (7 years ago)
Author:
jonmills (IP: 152.54.8.104)
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • OMDeventhandlers

    v2 v3  
    3030}}} 
    3131 
     32=== cmk_reinventory Eventhandler script === 
     33 
     34{{{ 
     35#!/bin/bash 
     36# 
     37# Event handler script for re-inventorying a host when the 
     38# "Check_MK Inventory" check comes back telling you that there 
     39# are unchecked services on a host. 
     40 
     41export PATH="/omd/sites/nagios/lib/perl5/bin:/omd/sites/nagios/local/bin:/omd/sites/nagios/bin:/omd/sites/nagios/local/lib/perl5/bin:/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/opt/local/bin:/opt/local/sbin" 
     42 
     43touch /tmp/cmk_reinventory 
     44 
     45# Note: The "Check_MK Inventory" check is enabled by having 
     46# something like the following in your main.mk file:  
     47#        
     48#       inventory_max_cachefile_age = 120 # seconds (Default: 120 seconds) 
     49#       inventory_check_interval = 120 # minutes 
     50#       inventory_check_severity = 1 
     51 
     52# What state is the "Check_MK Inventory" service in? 
     53 
     54# Command executed by Nagios was  
     55#       /opt/omd/site/`whoami`/local/bin/cmk_reinventory.sh $HOSTNAME$ $SERVICESTATE$ $SERVICESTATETYPE$ \ 
     56#               $SERVICEATTEMPT$ 
     57# 
     58# These are bash args brought in from the command line 
     59LOG=/tmp/cmk_reinventory 
     60HOSTNAME=$1 
     61SERVICESTATE=$2 
     62SERVICESTATETYPE=$3 
     63SERVICEATTEMPT=$4 
     64 
     65echo "$0" > $LOG 
     66echo `date` >> $LOG 
     67 
     68case "$SERVICESTATE" in 
     69 
     70OK) 
     71 
     72        # All services are checked, so don't do anything... 
     73        echo "SERVICESTATE is $SERVICESTATE" >> $LOG 
     74        echo "Run the add_vm.sh script against $HOSTNAME" >> $LOG 
     75        echo "${OMD_ROOT}/local/bin/add_vm.sh $HOSTNAME" >>$LOG 
     76        ${OMD_ROOT}/local/bin/add_vm.sh $HOSTNAME >>$LOG 
     77        ;; 
     78 
     79WARNING) 
     80 
     81        echo "SERVICESTATE is $SERVICESTATE" >> $LOG 
     82 
     83        # Because we defined 'inventory_check_severity = 1' in main.mk, 
     84        # unchecked services will result in a warning. Fix it! 
     85 
     86        case "$SERVICESTATETYPE" in 
     87        # We're in a "soft" state, meaning that Nagios is in the middle of retrying the 
     88        # check before it turns into a "hard" state and contacts get notified... 
     89 
     90        SOFT) 
     91 
     92                echo "SERVICESTATETYPE is $SERVICESTATETYPE" >> $LOG 
     93                # What check attempt are we on?  We don't want to restart the web server on the first 
     94                # check, because it may just be a fluke! 
     95 
     96                case "$SERVICEATTEMPT" in 
     97 
     98                # Wait until the check has been tried 3 times before executing the command. 
     99                3) 
     100                        echo "SERVICEATTEMPT is $SERVICEATTEMPT" >> $LOG 
     101 
     102                        #Do the work 
     103                        echo "Re-inventorying the host $HOSTNAME" >> $LOG 
     104                        cmk -Iu ${HOSTNAME} >> $LOG 
     105                        echo "Reloading nagios..." >> $LOG 
     106                        cmk -O >> $LOG 
     107                        echo "Run the add_vm.sh script against $HOSTNAME" >> $LOG 
     108                        echo "${OMD_ROOT}/local/bin/add_vm.sh $HOSTNAME" >>$LOG 
     109                        ${OMD_ROOT}/local/bin/add_vm.sh $HOSTNAME >>$LOG 
     110                        ;; 
     111                        esac 
     112                ;; 
     113 
     114        # If somehow we missed the 3rd try of the SOFT state, then we'll try again HARD 
     115        HARD) 
     116                echo "SERVICESTATETYPE is $SERVICESTATETYPE" >> $LOG 
     117                #Do the work 
     118                echo "Re-inventorying the host $HOSTNAME" >> $LOG 
     119                cmk -Iu ${HOSTNAME} >> $LOG 
     120                echo "Reloading nagios..." >> $LOG 
     121                cmk -O >> $LOG 
     122                echo "Run the add_vm.sh script against $HOSTNAME" >> $LOG 
     123                echo "${OMD_ROOT}/local/bin/add_vm.sh $HOSTNAME" >>$LOG 
     124                ${OMD_ROOT}/local/bin/add_vm.sh $HOSTNAME >>$LOG 
     125                ;; 
     126         
     127        esac 
     128        ;; 
     129 
     130UNKNOWN) 
     131        # Don't do anything; we handle it in the WARNING section... 
     132        ;; 
     133 
     134CRITICAL) 
     135 
     136        # Don't do anything; we handle it in the WARNING section... 
     137        ;; 
     138esac 
     139 
     140exit 0 
     141}}} 
    32142 
    33143== Host Check Eventhandler ==