]> granicus.if.org Git - icinga2/commitdiff
Rewrite the check_kernel script and implement support for RHEL, Fedora and Ubuntu.
authorGunnar Beutner <gunnar@beutner.name>
Sat, 31 May 2014 06:26:02 +0000 (08:26 +0200)
committerGunnar Beutner <gunnar@beutner.name>
Sat, 31 May 2014 07:13:01 +0000 (09:13 +0200)
Fixes #6332

debian/config/check_kernel [deleted file]
debian/config/kernel.conf [deleted file]
debian/control
debian/icinga2-common.install
etc/CMakeLists.txt
etc/icinga2/conf.d/commands.conf
etc/icinga2/conf.d/hosts/localhost/kernel.conf [new file with mode: 0644]
etc/icinga2/scripts/check_kernel

diff --git a/debian/config/check_kernel b/debian/config/check_kernel
deleted file mode 100644 (file)
index ffb6040..0000000
+++ /dev/null
@@ -1 +0,0 @@
-nagios ALL=(ALL:ALL) NOPASSWD: /etc/icinga2/scripts/check_kernel
diff --git a/debian/config/kernel.conf b/debian/config/kernel.conf
deleted file mode 100644 (file)
index 0f89073..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-/*
- * This check requires the "sudo" and "binutils" packages to be installed.
- * You will also need to add the following line to your /etc/sudoers file:
- * nagios ALL=(ALL:ALL) NOPASSWD: /etc/icinga2/scripts/check_kernel
- */
-
-object Service "kernel" {
-  import "generic-service"
-
-  host_name = "localhost"
-  check_command = "kernel"
-}
-
index c0540d51899a2de5e9f4e8a8cd2c93113a9d0234..1d635774a7d8cbf43bc423933dc07f7865323076 100644 (file)
@@ -40,7 +40,7 @@ Description: host and network monitoring system
 
 Package: icinga2-common
 Architecture: all
-Depends: adduser, sudo, binutils, ${misc:Depends}
+Depends: adduser, lsb-release, ${misc:Depends}
 Description: host and network monitoring system - common files
  Icinga 2 is still in development and not ready for production use!
  .
index 7d585b164bd0fd683518314cd2de4f5a2910d7be..a9f72565cab5810183095b2d7a4a086646e72380 100644 (file)
@@ -1,8 +1,6 @@
 debian/tmp/etc/icinga2
 debian/tmp/etc/logrotate.d
 debian/config/apt.conf        etc/icinga2/conf.d/hosts/localhost
-debian/config/kernel.conf     etc/icinga2/conf.d/hosts/localhost
-debian/config/check_kernel    etc/sudoers.d
 usr/bin/icinga2-build*
 usr/bin/icinga2-sign-key
 usr/sbin/icinga2-*-feature
index 030af32fe6c717a8c24ad9ff6fefc7631c59c569..0ee812d773b5c2b2ddd11a8f7e073ed963e11b42 100644 (file)
@@ -35,6 +35,7 @@ install_if_not_exists(icinga2/conf.d/hosts/localhost.conf ${CMAKE_INSTALL_SYSCON
 install_if_not_exists(icinga2/conf.d/hosts/localhost/disk.conf ${CMAKE_INSTALL_SYSCONFDIR}/icinga2/conf.d/hosts/localhost)
 install_if_not_exists(icinga2/conf.d/hosts/localhost/http.conf ${CMAKE_INSTALL_SYSCONFDIR}/icinga2/conf.d/hosts/localhost)
 install_if_not_exists(icinga2/conf.d/hosts/localhost/icinga.conf ${CMAKE_INSTALL_SYSCONFDIR}/icinga2/conf.d/hosts/localhost)
+install_if_not_exists(icinga2/conf.d/hosts/localhost/kernel.conf ${CMAKE_INSTALL_SYSCONFDIR}/icinga2/conf.d/hosts/localhost)
 install_if_not_exists(icinga2/conf.d/hosts/localhost/load.conf ${CMAKE_INSTALL_SYSCONFDIR}/icinga2/conf.d/hosts/localhost)
 install_if_not_exists(icinga2/conf.d/hosts/localhost/procs.conf ${CMAKE_INSTALL_SYSCONFDIR}/icinga2/conf.d/hosts/localhost)
 install_if_not_exists(icinga2/conf.d/hosts/localhost/ssh.conf ${CMAKE_INSTALL_SYSCONFDIR}/icinga2/conf.d/hosts/localhost)
index 16c0d63bbdfcd81f41631d9f0ae771b4354ec478..1be51ef6b5b3dc3517d3400b15d279e746e3fa6e 100644 (file)
@@ -3,7 +3,7 @@
 object CheckCommand "kernel" {
   import "plugin-check-command"
 
-  command = [ "sudo", SysconfDir + "/icinga2/scripts/check_kernel" ]
+  command = [ SysconfDir + "/icinga2/scripts/check_kernel" ]
 }
 
 object NotificationCommand "mail-host-notification" {
diff --git a/etc/icinga2/conf.d/hosts/localhost/kernel.conf b/etc/icinga2/conf.d/hosts/localhost/kernel.conf
new file mode 100644 (file)
index 0000000..2341140
--- /dev/null
@@ -0,0 +1,7 @@
+object Service "kernel" {
+  import "generic-service"
+
+  host_name = "localhost"
+  check_command = "kernel"
+}
+
index 817c11e57108db0541271647068b04a539f8b95b..77ad623914f39ad6f3de923e0ee8cf3b772f6209 100755 (executable)
 #!/bin/bash
-
-# Check if the running kernel has the same version string as the on-disk
-# kernel image.
-
-# Copyright 2008 Peter Palfrader
+# Icinga 2
+# Copyright (C) 2012-2014 Icinga Development Team (http://www.icinga.org)
 #
-# 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:
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
 #
-# The above copyright notice and this permission notice shall be
-# included in all copies or substantial portions of the Software.
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
 #
-# 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"
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software Foundation
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+
+if [ -e /etc/debian_version ]; then
+       if [ "$(lsb_release -s -i)" = "Debian" ]; then
+               latest_kernel=$(dpkg-query -W -f='${Version}' linux-image-$(uname -r))
+               current_kernel=$(uname -v | awk '{print $4}')
+
+               if [ "x$latest_kernel" != "x$current_kernel" ]; then
+                       echo "A kernel upgrade is available: $(uname -r) ($latest_kernel) - currently running: $(uname -r) ($current_kernel)"
+                       exit 2
+               fi
+       else
+               IFS=$'\n'
+               for pkginfo in $(dpkg-query -W -f '${Source}\t${Depends}\n' 'linux-image-*'); do
+                       source=$(echo $pkginfo | cut -f1 -d$'\t')
+                       if [ "$source" != "linux-meta" -a "$source" != "linux-latest" ]; then
+                               continue
+                       fi
+
+                       depends=$(echo $pkginfo | cut -f2 -d$'\t')
+                       IFS=','
+                       for depend in $depends; do
+                               name=$(echo $depend | awk '{print $1}')
+                               if ! echo $name | grep -E linux-image-[0-9] >/dev/null; then
+                                       continue
+                               fi
+                               version=$(echo $depend | cut -f3- -d-)
+                               if [ "$name" != "linux-image-$(uname -r)" ]; then
+                                       echo "A kernel upgrade is available: $version - currently running: $(uname -r)"
+                                       exit 2
+                               fi
+                       done
+                       IFS=$'\n'
+               done
        fi
-       if [ "$off" -eq "0" ]; then
-               zcat < "$image"
-               return
-       elif [ "$off" -ne "-1" ]; then
-               (dd ibs="$off" skip=1 count=0 && dd bs=512k) < "$image"  2>/dev/null | zcat 2>/dev/null
-               return
-       fi
-
-       echo "ERROR: Unable to extract kernel image." 2>&1
-       exit 1
-}
-
-searched=""
-for on_disk in \
-       "/boot/vmlinuz-`uname -r`"\
-       "/boot/vmlinux-`uname -r`"; do
-
-       if [ -e "$on_disk" ]; then
-               on_disk_version="`get_image "$on_disk" | strings | grep 'Linux version' | head -n1`"
-               [ -z "$on_disk_version" ] || break
-               on_disk_version="`cat "$on_disk" | strings | grep 'Linux version' | head -n1`"
-               [ -z "$on_disk_version" ] || break
-
-               echo "UNKNOWN: Failed to get a version string from image $on_disk"
-               exit $UNKNOWN
+elif [ -e /etc/redhat-release ]; then
+       latest_kernel=`rpm -q --last kernel | head -n 1 | awk '{print $1}' | cut -f2- -d-`
+       current_kernel=`uname -r`
+       if [ "x$latest_kernel" != "x$current_kernel" ]; then
+               echo "A kernel upgrade is available: $latest_kernel - currently running: $current_kernel"
+               exit 2
        fi
-       searched="$searched $on_disk"
-done
-
-if ! [ -e "$on_disk" ]; then
-       echo "WARNING: Did not find a kernel image (checked$searched) - I have no idea which kernel I am running"
-       exit $WARNING
-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
-
-on_disk_version_ubuntu="$(echo "$on_disk_version" | sed -r 's/ \([^(]+\)$//')"
-
-if [ "$running_version" != "$on_disk_version" -a "$running_version" != "$on_disk_version_ubuntu" ]; 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
+       echo "Unsupported OS/distribution."
+       exit 3
 fi
+
+echo "Kernel version: `uname -a`"
+exit 0