Changes between Version 3 and Version 4 of OMDeventhandlers

Show
Ignore:
Timestamp:
10/04/11 12:33:41 (8 years ago)
Author:
jonmills (IP: 152.54.8.104)
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • OMDeventhandlers

    v3 v4  
    141141}}} 
    142142 
     143=== add_vm.sh script === 
     144 
     145 * The purpose of the add_vm.sh script is to figure out if all the KVM Virtual Machines running on a Node Controller are being monitored, and if not, to add the VM and its IP address into Check_MK's configuration. 
     146 * The script is called directly by cmk_reinventory.sh, rather than triggered by a Nagios Event.  The reason is because no such event exists to trigger this script!  When "Check_MK inventory" discovers a new type of KVM check, it brings that up as a new service in Nagios.  But because it's initial state is OK, it never triggers an event.  (Events are only triggered by a state change, and going from non-existent to OK is not a state change in Nagios' view.) 
     147 
     148{{{ 
     149#!/bin/bash 
     150# 
     151# Event handler script for re-inventorying a host when the 
     152# "Check_MK inventory" check comes back telling you that there 
     153# are unchecked services on a host. 
     154 
     155export 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" 
     156 
     157# Command executed by Nagios was  
     158#       /opt/omd/site/`whoami`/local/bin/cmk_addhost.sh $HOSTNAME$ 
     159# 
     160# ${OMD_ROOT} should be an env var set by OMD itself... 
     161 
     162HOSTNAME=$1 
     163NODE=$(echo $HOSTNAME | awk -F. '{print $1}') 
     164LOG=/tmp/add_vm.sh 
     165touch $LOG 
     166 
     167# This yields the hostnames of VMs running on $HOSTNAME 
     168VMLIST=$(grep 'qemu' ${OMD_ROOT}/var/check_mk/autochecks/${HOSTNAME}.mk | \ 
     169        awk '{print $3}' | sed 's/'\','//' | sed 's/'\''//') 
     170echo "VMs running on $HOSTNAME are:" > $LOG 
     171echo $VMLIST >> $LOG 
     172 
     173for INSTANCE in $VMLIST 
     174do 
     175        #First, see if the INSTANCE exists in the hosts.mk file 
     176        if [ $(grep $INSTANCE ${OMD_ROOT}/etc/check_mk/conf.d/hosts.mk >/dev/null; echo $?) = 1 ]; then 
     177 
     178                # We need to add it to the ipaddresses.mk file for fakedns 
     179                IP=$(euca-describe-addresses | grep $INSTANCE | awk '{print $2}') 
     180                echo "Instance $INSTANCE on $HOSTNAME has IP $IP" >> $LOG 
     181                [ $IP ] && sed -i '/ipaddresses/a'\"''$INSTANCE'" : "'$IP'",\' ${OMD_ROOT}/etc/check_mk/conf.d/ipaddresses.mk >> $LOG 
     182 
     183                # Add this hostname to the hosts.mk file, sorting it right below its KVM nodes's name 
     184                [ $IP ] && sed -i '/'$HOSTNAME'/a'\'''$INSTANCE'|ping|vm|'$NODE\','\''' ${OMD_ROOT}/etc/check_mk/conf.d/hosts.mk >> $LOG         
     185 
     186                # Now inventory the new host 
     187                echo "cmk -Iu $INSTANCE" >> $LOG 
     188                ${OMD_ROOT}/bin/cmk -Iu ${INSTANCE} >> $LOG 
     189        fi 
     190done; 
     191 
     192# Now reload Nagios 
     193[ $INSTANCE ] && ${OMD_ROOT}/bin/cmk -O >> $LOG 
     194 
     195exit 0 
     196}}} 
     197 
    143198== Host Check Eventhandler == 
    144199