From: Peter Palfrader Date: Mon, 5 May 2008 17:12:46 +0000 (+0000) Subject: [project @ peter@palfrader.org-20080505171246-ny9adauh38g8izbk] X-Git-Url: https://git.adam-barratt.org.uk/?a=commitdiff_plain;h=f348589eb139fd7ebf6b67d2da48a7670b979ac1;hp=7c5bbaea78439d10c033f0751680e59d1bb98c7d;p=mirror%2Fdsa-nagios.git [project @ peter@palfrader.org-20080505171246-ny9adauh38g8izbk] Add dsa-check-running-kernel --- diff --git a/dsa-nagios-nrpe-config/debian/changelog b/dsa-nagios-nrpe-config/debian/changelog index c089d2c..696623a 100644 --- a/dsa-nagios-nrpe-config/debian/changelog +++ b/dsa-nagios-nrpe-config/debian/changelog @@ -1,3 +1,9 @@ +dsa-nagios-nrpe-config (36) unstable; urgency=low + + * Add dsa-check-running-kernel + + -- Peter Palfrader Mon, 5 May 2008 17:11:54 +0000 + dsa-nagios-nrpe-config (35) unstable; urgency=low * dsa-check-raid-mpt diff --git a/dsa-nagios-nrpe-config/debian/copyright b/dsa-nagios-nrpe-config/debian/copyright index 59e2523..db7930c 100644 --- a/dsa-nagios-nrpe-config/debian/copyright +++ b/dsa-nagios-nrpe-config/debian/copyright @@ -19,6 +19,11 @@ dsa-check-dabackup: License: MIT ######################################################################## -dsa-check-raid-3ware +dsa-check-raid-3ware: Copyright: 2006 Peter Palfrader License: MIT + +######################################################################## +dsa-check-running-kernel: + Copyright: 2008 Peter Palfrader + License: MIT diff --git a/dsa-nagios-nrpe-config/debian/rules b/dsa-nagios-nrpe-config/debian/rules index df8c8b0..dcd7b8c 100755 --- a/dsa-nagios-nrpe-config/debian/rules +++ b/dsa-nagios-nrpe-config/debian/rules @@ -18,6 +18,7 @@ install: install -m 755 dsa-check-raid-mpt $(CURDIR)/debian/dsa-nagios-nrpe-config/usr/lib/nagios/plugins install -m 755 dsa-check-raid-sw $(CURDIR)/debian/dsa-nagios-nrpe-config/usr/lib/nagios/plugins install -m 755 dsa-check-raid-3ware $(CURDIR)/debian/dsa-nagios-nrpe-config/usr/lib/nagios/plugins + install -m 755 dsa-check-running-kernel $(CURDIR)/debian/dsa-nagios-nrpe-config/usr/lib/nagios/plugins install -m 755 dsa-check-da-in-aliases $(CURDIR)/debian/dsa-nagios-nrpe-config/usr/lib/nagios/plugins install -m 755 dsa-check-dabackup $(CURDIR)/debian/dsa-nagios-nrpe-config/usr/lib/nagios/plugins install -m 755 dsa-check-udldap-freshness $(CURDIR)/debian/dsa-nagios-nrpe-config/usr/lib/nagios/plugins diff --git a/dsa-nagios-nrpe-config/dsa-check-running-kernel b/dsa-nagios-nrpe-config/dsa-check-running-kernel new file mode 100755 index 0000000..7d2cb3a --- /dev/null +++ b/dsa-nagios-nrpe-config/dsa-check-running-kernel @@ -0,0 +1,95 @@ +#!/bin/bash + +# Check if the running kernel has the same version string as the on-disk +# kernel image. + +# Copyright 2008 Peter Palfrader +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +OK=0; +WARNING=1; +CRITICAL=2; +UNKNOWN=3; + +get_offset() { + local file needle + + file="$1" + needle="$2" + perl -e ' + undef $/; + $i = index(<>, "'"$needle"'"); + if ($i < 0) { + exit 1; + }; + print $i,"\n"' < "$file" +} + +get_image() { + local image GZHDR1 GZHDR2 off + + image="$1" + + GZHDR1="\x1f\x8b\x08\x00" + GZHDR2="\x1f\x8b\x08\x08" + + off=`get_offset "$image" $GZHDR1` + [ "$?" != "0" ] && off="-1" + if [ "$off" -eq "-1" ]; then + off=`get_offset "$image" $GZHDR2` + [ "$?" != "0" ] && off="-1" + fi + if [ "$off" -eq "0" ]; then + zcat < "$image" + elif [ "$off" -ne "-1" ]; then + (dd ibs="$off" skip=1 count=0 && dd bs=512k) < "$image" 2>/dev/null | zcat 2>/dev/null + fi + + echo "ERROR: Unable to extract kernel image." 2>&1 + exit 1 +} + +on_disk="/boot/vmlinuz-`uname -r`" + +if ! [ -e "$on_disk" ] ; then + echo "WARNING: $on_disk does not exist - I have no idea which kernel I am running" + exit $WARN +fi + +on_disk_version="`get_image $on_disk | strings | grep 'Linux version' | head -n1`" +if [ -z "$on_disk_version" ] ; then + echo "UNKNOWN: Failed to get a version string from image $on_disk" + exit $UNKNOWN +fi + +running_version="`cat /proc/version`" +if [ -z "$running_version" ] ; then + echo "UNKNOWN: Failed to get a version string from running system" + exit $UNKNOWN +fi + +if [ "$running_version" != "$on_disk_version" ]; then + echo "WARNING: Running kernel does not match on-disk kernel image: [$running_version != $on_disk_version]" + exit $WARNING +else + echo "OK: Running kernel matches on disk image: [$running_version]" + exit $OK +fi