* Added license information to the source file.
* Improved some comments to reflect that the plugin should work with YUM on any distribution. * Capitalised spelling of YUM in places where the program and not the binary itself is meant. * Merged a patch that adds structures for Nagios performance data. * Merged a patch that makes the check_yum working with newer versions of YUM, especially to get support for RHEL 6 based distributions. * Bumped version to 0.7.3.
This commit is contained in:
parent
6921ad1ee0
commit
0fefef80b2
98
check_yum
98
check_yum
@ -1,12 +1,12 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
"""Nagios plugin to test for Yum updates on RedHat/CentOS Linux.
|
||||
"""Nagios plugin to check the YUM package management system for package updates.
|
||||
Can optionally alert on any available updates as well as just
|
||||
security related updates"""
|
||||
|
||||
__author__ = "Hari Sekhon"
|
||||
__title__ = "Nagios Plugin for Yum updates on RedHat/CentOS systems"
|
||||
__version__ = "0.7.1"
|
||||
__title__ = "Nagios plugin to check the YUM package management system for package updates."
|
||||
__version__ = "0.7.3"
|
||||
|
||||
# Standard Nagios return codes
|
||||
OK = 0
|
||||
@ -29,19 +29,19 @@ from optparse import OptionParser
|
||||
DEFAULT_TIMEOUT = 30
|
||||
|
||||
|
||||
def end(status, message):
|
||||
def end(status, message, perfdata=''):
|
||||
"""Exits the plugin with first arg as the return code and the second
|
||||
arg as the message to output"""
|
||||
|
||||
check = "YUM "
|
||||
if status == OK:
|
||||
print "%sOK: %s" % (check, message)
|
||||
print "%sOK: %s | %s" % (check, message, perfdata)
|
||||
sys.exit(OK)
|
||||
elif status == WARNING:
|
||||
print "%sWARNING: %s" % (check, message)
|
||||
print "%sWARNING: %s | %s" % (check, message, perfdata)
|
||||
sys.exit(WARNING)
|
||||
elif status == CRITICAL:
|
||||
print "%sCRITICAL: %s" % (check, message)
|
||||
print "%sCRITICAL: %s | %s" % (check, message, perfdata)
|
||||
sys.exit(CRITICAL)
|
||||
else:
|
||||
print "UNKNOWN: %s" % message
|
||||
@ -159,7 +159,7 @@ class YumTester:
|
||||
|
||||
def check_returncode(self, returncode, output):
|
||||
"""Takes the returncode and output (as an array of lines)
|
||||
of the yum program execution and tests for failures, exits
|
||||
of the YUM program execution and tests for failures, exits
|
||||
with an appropriate message if any are found"""
|
||||
|
||||
if returncode == 0:
|
||||
@ -170,7 +170,7 @@ class YumTester:
|
||||
elif returncode == 200:
|
||||
if "lock" in output[-2] or "another copy is running" in output[-2]:
|
||||
msg = "Cannot check for updates, " \
|
||||
+ "another instance of yum is running"
|
||||
+ "another instance of YUM is running"
|
||||
if self.no_warn_on_lock:
|
||||
end(OK, msg)
|
||||
else:
|
||||
@ -181,7 +181,7 @@ class YumTester:
|
||||
else:
|
||||
if not 'Loading "security" plugin' in output \
|
||||
or "Command line error: no such option: --security" in output:
|
||||
end(UNKNOWN, "Security plugin for yum is required. Try to " \
|
||||
end(UNKNOWN, "Security plugin for YUM is required. Try to " \
|
||||
+ "'yum install yum-security' and then re-run " \
|
||||
+ "this plugin. Alternatively, to just alert on " \
|
||||
+ "any update which does not require the security " \
|
||||
@ -278,7 +278,7 @@ class YumTester:
|
||||
raise ValueError
|
||||
except ValueError:
|
||||
end(UNKNOWN, "Error parsing package information, invalid package " \
|
||||
+ "number, yum output may have changed. Please make " \
|
||||
+ "number, YUM output may have changed. Please make " \
|
||||
+ "sure you have upgraded to the latest version of " \
|
||||
+ "this plugin. If the problem persists, then please " \
|
||||
+ "contact the author for a fix")
|
||||
@ -289,7 +289,7 @@ class YumTester:
|
||||
count = 0
|
||||
re_package_format = \
|
||||
re.compile("^.+\.(i[3456]86|x86_64|noarch)\s+.+\s+.+$")
|
||||
# This is to work around a yum truncation issue effectively changing
|
||||
# This is to work around a YUM truncation issue effectively changing
|
||||
# the package output format. Currently only very long kmod lines
|
||||
# are seen to have caused this so we stick to what we know for safety
|
||||
# and raise an unknown error on anything else for maximum security
|
||||
@ -316,26 +316,36 @@ class YumTester:
|
||||
cmd = "%s --security check-update" % YUM
|
||||
|
||||
output = self.run(cmd)
|
||||
|
||||
re_security_summary = \
|
||||
re.compile("Needed \d+ of \d+ packages, for security")
|
||||
re_no_security_updates_available = \
|
||||
re.compile("No packages needed, for security, \d+ available")
|
||||
|
||||
re_security_summary_rhel5 = re.compile("Needed \d+ of \d+ packages, for security")
|
||||
re_security_summary_rhel6 = re.compile("\d+ package\(s\) needed for security, out of \d+ available")
|
||||
re_no_security_updates_available_rhel5 = re.compile("No packages needed, for security, \d+ available")
|
||||
re_no_security_updates_available_rhel6 = re.compile("No packages needed for security; \d+ packages available")
|
||||
summary_line_found = False
|
||||
for line in output:
|
||||
if re_no_security_updates_available.match(line):
|
||||
if re_no_security_updates_available_rhel5.match(line):
|
||||
summary_line_found = True
|
||||
number_security_updates = 0
|
||||
number_total_updates = line.split()[5]
|
||||
break
|
||||
elif re_security_summary.match(line):
|
||||
if re_no_security_updates_available_rhel6.match(line):
|
||||
summary_line_found = True
|
||||
number_security_updates = 0
|
||||
number_total_updates = line.split()[5]
|
||||
break
|
||||
if re_security_summary_rhel5.match(line):
|
||||
summary_line_found = True
|
||||
number_security_updates = line.split()[1]
|
||||
number_total_updates = line.split()[3]
|
||||
break
|
||||
if re_security_summary_rhel6.match(line):
|
||||
summary_line_found = True
|
||||
number_security_updates = line.split()[0]
|
||||
number_total_updates = line.split()[7]
|
||||
break
|
||||
|
||||
if not summary_line_found:
|
||||
end(WARNING, "Cannot find summary line in yum output. Please " \
|
||||
end(WARNING, "Cannot find summary line in YUM output. Please " \
|
||||
+ "make sure you have upgraded to the latest version " \
|
||||
+ "of this plugin. If the problem persists, please " \
|
||||
+ "contact the author for a fix")
|
||||
@ -344,7 +354,7 @@ class YumTester:
|
||||
number_security_updates = int(number_security_updates)
|
||||
number_total_updates = int(number_total_updates)
|
||||
except ValueError:
|
||||
end(WARNING, "Error parsing package information, yum output " \
|
||||
end(WARNING, "Error parsing package information, YUM output " \
|
||||
+ "may have changed. Please make sure you have " \
|
||||
+ "upgraded to the latest version of this plugin. " \
|
||||
+ "If the problem persists, the please contact the " \
|
||||
@ -450,7 +460,7 @@ def main():
|
||||
help="Does not distinguish between security and " \
|
||||
+ "non-security updates, but returns critical for " \
|
||||
+ "any available update. This may be used if the " \
|
||||
+ "yum security plugin is absent or you want to " \
|
||||
+ "YUM security plugin is absent or you want to " \
|
||||
+ "maintain every single package at the latest " \
|
||||
+ "version. You may want to use " \
|
||||
+ "--warn-on-any-update instead of this option")
|
||||
@ -472,7 +482,7 @@ def main():
|
||||
action="store_true",
|
||||
dest="no_cache_update",
|
||||
help="Run entirely from cache and do not update the " \
|
||||
+ "cache when running yum. Useful if you have " \
|
||||
+ "cache when running YUM. Useful if you have " \
|
||||
+ "'yum makecache' cronned so that the nagios " \
|
||||
+ "check itself doesn't have to do it, possibly " \
|
||||
+ "speeding up execution (by 1-2 seconds in tests)")
|
||||
@ -480,22 +490,22 @@ def main():
|
||||
parser.add_option( "--no-warn-on-lock",
|
||||
action="store_true",
|
||||
dest="no_warn_on_lock",
|
||||
help="Return OK instead of WARNING when yum is locked " \
|
||||
help="Return OK instead of WARNING when YUM is locked " \
|
||||
+ "and fails to check for updates due to another " \
|
||||
+ "instance running. This is not recommended from " \
|
||||
+ "the security standpoint, but may be wanted to " \
|
||||
+ "reduce the number of alerts that may " \
|
||||
+ "intermittently pop up when someone is running " \
|
||||
+ "yum interactively for package management")
|
||||
+ "YUM interactively for package management")
|
||||
|
||||
parser.add_option( "--enablerepo",
|
||||
dest="repository_to_enable",
|
||||
help="Explicitly enables a reposity when calling yum. "
|
||||
help="Explicitly enables a reposity when calling YUM. "
|
||||
+ "Can take a comma separated list of repositories")
|
||||
|
||||
parser.add_option( "--disablerepo",
|
||||
dest="repository_to_disable",
|
||||
help="Explicitly disables a repository when calling yum "
|
||||
help="Explicitly disables a repository when calling YUM "
|
||||
+ "Can take a comma separated list of repositories")
|
||||
|
||||
parser.add_option( "-t",
|
||||
@ -550,3 +560,37 @@ if __name__ == "__main__":
|
||||
except KeyboardInterrupt:
|
||||
print "Caught Control-C..."
|
||||
sys.exit(CRITICAL)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#Copyright © 2008–2012, Hari Sekhon <harisekhon@gmail.com>.
|
||||
#Copyright © 2012, Christoph Anton Mitterer <mail@christoph.anton.mitterer.name>.
|
||||
#All rights reserved.
|
||||
#
|
||||
#
|
||||
#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; version 2
|
||||
#of the License.
|
||||
#
|
||||
#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.
|
||||
#
|
||||
#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 Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
Reference in New Issue
Block a user