Last active
January 2, 2016 10:29
-
-
Save Luzifer/8290705 to your computer and use it in GitHub Desktop.
Simple Nagios check for NRPE / PeriodicNoise to check whether an Ubuntu server required reboot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import apt, os, re, sys, subprocess | |
if os.path.exists('/var/run/reboot-required'): | |
print 'reboot-required marker file exists' | |
sys.exit(1) | |
kernels = [] | |
cache = apt.Cache(memonly=True) | |
for package in cache: | |
if package.installed and re.match('^linux-image-[0-9].*', package.name): | |
kernels.append(package.name) | |
kernels.sort() | |
latest = kernels[-1] | |
active_kernel = subprocess.check_output(['uname', '-r']).strip() | |
if 'linux-image-%s' % active_kernel == latest: | |
print 'reboot-required marker not found, kernel matches' | |
sys.exit(0) | |
else: | |
print 'reboot-required marker not found, kernel version does not match: %s != %s' % (latest, active_kernel) | |
sys.exit(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment