mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-22 21:24:41 +02:00
Rewrite the check_kernel script and implement support for RHEL, Fedora and Ubuntu.
Fixes #6332
This commit is contained in:
parent
eae6e75f94
commit
32e6e6ff04
1
debian/config/check_kernel
vendored
1
debian/config/check_kernel
vendored
@ -1 +0,0 @@
|
|||||||
nagios ALL=(ALL:ALL) NOPASSWD: /etc/icinga2/scripts/check_kernel
|
|
13
debian/config/kernel.conf
vendored
13
debian/config/kernel.conf
vendored
@ -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"
|
|
||||||
}
|
|
||||||
|
|
2
debian/control
vendored
2
debian/control
vendored
@ -40,7 +40,7 @@ Description: host and network monitoring system
|
|||||||
|
|
||||||
Package: icinga2-common
|
Package: icinga2-common
|
||||||
Architecture: all
|
Architecture: all
|
||||||
Depends: adduser, sudo, binutils, ${misc:Depends}
|
Depends: adduser, lsb-release, ${misc:Depends}
|
||||||
Description: host and network monitoring system - common files
|
Description: host and network monitoring system - common files
|
||||||
Icinga 2 is still in development and not ready for production use!
|
Icinga 2 is still in development and not ready for production use!
|
||||||
.
|
.
|
||||||
|
2
debian/icinga2-common.install
vendored
2
debian/icinga2-common.install
vendored
@ -1,8 +1,6 @@
|
|||||||
debian/tmp/etc/icinga2
|
debian/tmp/etc/icinga2
|
||||||
debian/tmp/etc/logrotate.d
|
debian/tmp/etc/logrotate.d
|
||||||
debian/config/apt.conf etc/icinga2/conf.d/hosts/localhost
|
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-build*
|
||||||
usr/bin/icinga2-sign-key
|
usr/bin/icinga2-sign-key
|
||||||
usr/sbin/icinga2-*-feature
|
usr/sbin/icinga2-*-feature
|
||||||
|
@ -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/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/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/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/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/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)
|
install_if_not_exists(icinga2/conf.d/hosts/localhost/ssh.conf ${CMAKE_INSTALL_SYSCONFDIR}/icinga2/conf.d/hosts/localhost)
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
object CheckCommand "kernel" {
|
object CheckCommand "kernel" {
|
||||||
import "plugin-check-command"
|
import "plugin-check-command"
|
||||||
|
|
||||||
command = [ "sudo", SysconfDir + "/icinga2/scripts/check_kernel" ]
|
command = [ SysconfDir + "/icinga2/scripts/check_kernel" ]
|
||||||
}
|
}
|
||||||
|
|
||||||
object NotificationCommand "mail-host-notification" {
|
object NotificationCommand "mail-host-notification" {
|
||||||
|
7
etc/icinga2/conf.d/hosts/localhost/kernel.conf
Normal file
7
etc/icinga2/conf.d/hosts/localhost/kernel.conf
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
object Service "kernel" {
|
||||||
|
import "generic-service"
|
||||||
|
|
||||||
|
host_name = "localhost"
|
||||||
|
check_command = "kernel"
|
||||||
|
}
|
||||||
|
|
@ -1,109 +1,65 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
# Icinga 2
|
||||||
# Check if the running kernel has the same version string as the on-disk
|
# Copyright (C) 2012-2014 Icinga Development Team (http://www.icinga.org)
|
||||||
# kernel image.
|
|
||||||
|
|
||||||
# Copyright 2008 Peter Palfrader
|
|
||||||
#
|
#
|
||||||
# Permission is hereby granted, free of charge, to any person obtaining
|
# This program is free software; you can redistribute it and/or
|
||||||
# a copy of this software and associated documentation files (the
|
# modify it under the terms of the GNU General Public License
|
||||||
# "Software"), to deal in the Software without restriction, including
|
# as published by the Free Software Foundation; either version 2
|
||||||
# without limitation the rights to use, copy, modify, merge, publish,
|
# of the License, or (at your option) any later version.
|
||||||
# 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
|
# This program is distributed in the hope that it will be useful,
|
||||||
# included in all copies or substantial portions of the Software.
|
# 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,
|
# You should have received a copy of the GNU General Public License
|
||||||
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
# along with this program; if not, write to the Free Software Foundation
|
||||||
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
# 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;
|
if [ -e /etc/debian_version ]; then
|
||||||
WARNING=1;
|
if [ "$(lsb_release -s -i)" = "Debian" ]; then
|
||||||
CRITICAL=2;
|
latest_kernel=$(dpkg-query -W -f='${Version}' linux-image-$(uname -r))
|
||||||
UNKNOWN=3;
|
current_kernel=$(uname -v | awk '{print $4}')
|
||||||
|
|
||||||
get_offset() {
|
if [ "x$latest_kernel" != "x$current_kernel" ]; then
|
||||||
local file needle
|
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
|
||||||
|
|
||||||
file="$1"
|
depends=$(echo $pkginfo | cut -f2 -d$'\t')
|
||||||
needle="$2"
|
IFS=','
|
||||||
perl -e '
|
for depend in $depends; do
|
||||||
undef $/;
|
name=$(echo $depend | awk '{print $1}')
|
||||||
$i = index(<>, "'"$needle"'");
|
if ! echo $name | grep -E linux-image-[0-9] >/dev/null; then
|
||||||
if ($i < 0) {
|
continue
|
||||||
exit 1;
|
fi
|
||||||
};
|
version=$(echo $depend | cut -f3- -d-)
|
||||||
print $i,"\n"' < "$file"
|
if [ "$name" != "linux-image-$(uname -r)" ]; then
|
||||||
}
|
echo "A kernel upgrade is available: $version - currently running: $(uname -r)"
|
||||||
|
exit 2
|
||||||
get_image() {
|
fi
|
||||||
local image GZHDR1 GZHDR2 off
|
done
|
||||||
|
IFS=$'\n'
|
||||||
image="$1"
|
done
|
||||||
|
|
||||||
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
|
fi
|
||||||
if [ "$off" -eq "0" ]; then
|
elif [ -e /etc/redhat-release ]; then
|
||||||
zcat < "$image"
|
latest_kernel=`rpm -q --last kernel | head -n 1 | awk '{print $1}' | cut -f2- -d-`
|
||||||
return
|
current_kernel=`uname -r`
|
||||||
elif [ "$off" -ne "-1" ]; then
|
if [ "x$latest_kernel" != "x$current_kernel" ]; then
|
||||||
(dd ibs="$off" skip=1 count=0 && dd bs=512k) < "$image" 2>/dev/null | zcat 2>/dev/null
|
echo "A kernel upgrade is available: $latest_kernel - currently running: $current_kernel"
|
||||||
return
|
exit 2
|
||||||
fi
|
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
|
|
||||||
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
|
else
|
||||||
echo "OK: Running kernel matches on disk image: [$running_version]"
|
echo "Unsupported OS/distribution."
|
||||||
exit $OK
|
exit 3
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
echo "Kernel version: `uname -a`"
|
||||||
|
exit 0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user