Hi DSA and Debian Nagios maintainers,

please find attached patches that fix three issues with your nagios plugin script 'dsa-check-running-kernel', respectively 'check_running_kernel' in
Debian package nagios-plugins-contrib:

1/ detect missing filter (e.g. xzcat) and warn about it. (fixes #780098)
2/ enhance sed regex on on_disk_version for vendor != Debian. Fixes kernel
   detection on Ubuntu installations.
3/ iterate over all installed kernels that are either equal to or have a
   newer timestamp than running kernel. Fixes detection of newer kernels
   for new kernel releases, e.g. in Debian unstable, Debian testing.
   Additionally fixes kernel update detection on distros that have a
   different policy regarding kernel security updates and install a new
   kernel file at every update, like Red Hat based distros.

All patches are against head (a3a621a387886e12a23fcf3d1c0837b7a5a5db14) of
git repository https://db.debian.org/git/dsa-nagios.git.

Cheers,
 jonas
From af5d31c89a6e466bda9a2474baf0fbddd04fc87b Mon Sep 17 00:00:00 2001
From: Jonas Meurer <[email protected]>
Date: Mon, 9 Mar 2015 15:04:29 +0100
Subject: [PATCH 1/3] detect missing filter (e.g. xzcat) and warn about it.

---
 dsa-nagios-checks/checks/dsa-check-running-kernel |    5 +++++
 1 file changed, 5 insertions(+)

diff --git a/dsa-nagios-checks/checks/dsa-check-running-kernel b/dsa-nagios-checks/checks/dsa-check-running-kernel
index 6a6994b..c56f35c 100755
--- a/dsa-nagios-checks/checks/dsa-check-running-kernel
+++ b/dsa-nagios-checks/checks/dsa-check-running-kernel
@@ -129,6 +129,11 @@ cat_vmlinux() {
 	filter="$3"
 	hdroff="$4"
 
+	if ! which $filter >/dev/null; then
+		echo "UNKNOWN: filter command '$filter' missing, perhaps install xz-utils?"
+		exit $UNKNOWN
+	fi
+
 	get_offset "$image" $header | head -n 5 | while read off; do
 		(if [ "$off" != 0 ]; then
 		   dd ibs="$((off+hdroff))" skip=1 count=0
-- 
1.7.10.4

From a443363a2ce13fd690e1404718ff6d4150b64594 Mon Sep 17 00:00:00 2001
From: Jonas Meurer <[email protected]>
Date: Mon, 9 Mar 2015 15:06:13 +0100
Subject: [PATCH 2/3] enhance sed regex on on_disk_version for vendor !=
 Debian. Fixes kernel detection on Ubuntu installations.

---
 dsa-nagios-checks/checks/dsa-check-running-kernel |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/dsa-nagios-checks/checks/dsa-check-running-kernel b/dsa-nagios-checks/checks/dsa-check-running-kernel
index c56f35c..15ba81e 100755
--- a/dsa-nagios-checks/checks/dsa-check-running-kernel
+++ b/dsa-nagios-checks/checks/dsa-check-running-kernel
@@ -199,7 +199,7 @@ for on_disk in \
 			if [ -x /usr/bin/lsb_release ] ; then
 				vendor=$(lsb_release -i -s)
 				if [ -n "$vendor" ] && [ "xDebian" != "x$vendor" ] ; then
-					on_disk_version=$( echo $on_disk_version|sed -e "s/ ($vendor [[:alnum:]\.-]\+ [[:alnum:]\.]\+)//")
+					on_disk_version=$( echo $on_disk_version|sed -e "s/ ($vendor [[:alnum:]\.-]\+ [[:alnum:]\.-]\+)//")
 				fi
 			fi
 			[ -z "$on_disk_version" ] || break
-- 
1.7.10.4

From c1d4320754507a57c987fda66117d62ea44cc26e Mon Sep 17 00:00:00 2001
From: Jonas Meurer <[email protected]>
Date: Mon, 9 Mar 2015 15:15:07 +0100
Subject: [PATCH 3/3] iterate over all installed kernels that are either equal
 to or have a newer timestamp than running kernel. Fixes
 detection of newer kernels for new kernel releases,
 e.g. in Debian unstable, Debian testing. Additionally
 fixes kernel update detection on distros that have a
 different policy regarding kernel security updates and
 install a new kernel file at every update, like Red Hat
 based distros.

---
 dsa-nagios-checks/checks/dsa-check-running-kernel |   10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/dsa-nagios-checks/checks/dsa-check-running-kernel b/dsa-nagios-checks/checks/dsa-check-running-kernel
index 15ba81e..2f9a68a 100755
--- a/dsa-nagios-checks/checks/dsa-check-running-kernel
+++ b/dsa-nagios-checks/checks/dsa-check-running-kernel
@@ -185,9 +185,9 @@ fi
 
 searched=""
 for on_disk in \
-	"/boot/vmlinuz-`uname -r`"\
-	"/boot/vmlinux-`uname -r`"\
-	"/boot/kfreebsd-`uname -r`.gz"; do
+	$(find /boot/ -name 'vmlinuz*' -and -name "vmlinuz-$(uname -r)" -or -name 'vmlinuz*' -and -newer "/boot/vmlinuz-$(uname -r)" | sort) \
+	$(find /boot/ -name 'kfreebsd*' -and -name "kfreebsd-$(uname -r).gz" -or -name 'kfreebsd*' -and -newer "/boot/kfreebsd-$(uname -r).gz" | sort)
+; do
 
 	if [ -e "$on_disk" ]; then
 		if [ -z "$STRINGS" ]; then
@@ -202,9 +202,9 @@ for on_disk in \
 					on_disk_version=$( echo $on_disk_version|sed -e "s/ ($vendor [[:alnum:]\.-]\+ [[:alnum:]\.-]\+)//")
 				fi
 			fi
-			[ -z "$on_disk_version" ] || break
+			[ -z "$on_disk_version" ] || continue
 			on_disk_version="`cat "$on_disk" | $STRINGS | grep 'Linux version' | head -n1`"
-			[ -z "$on_disk_version" ] || break
+			[ -z "$on_disk_version" ] || continue
 
 			echo "UNKNOWN: Failed to get a version string from image $on_disk"
 			exit $UNKNOWN
-- 
1.7.10.4

Reply via email to