mirror of
https://github.com/opinkerfi/nagios-plugins.git
synced 2024-11-22 10:23:46 +01:00
Added perfdata and longoutput with ERRATA IDs
Option added: -l - runs yum list-security to get advisories and packages Perfdata now shows how many updates are available.
This commit is contained in:
parent
cb9faf65e6
commit
61ca426c4b
@ -305,8 +305,27 @@ class YumTester:
|
|||||||
+ "of this plugin. If the problem persists, then " \
|
+ "of this plugin. If the problem persists, then " \
|
||||||
+ "please contact the author for a fix")
|
+ "please contact the author for a fix")
|
||||||
|
|
||||||
return number_packages
|
return number_packages, "'updates'=%s" % (number_packages)
|
||||||
|
|
||||||
|
def get_security_updateinfo(self):
|
||||||
|
"""Fetches errata numbers and package names"""
|
||||||
|
|
||||||
|
cmd = "%s list-security" % YUM
|
||||||
|
|
||||||
|
output = self.run(cmd)
|
||||||
|
|
||||||
|
errata = []
|
||||||
|
|
||||||
|
for line in output:
|
||||||
|
try:
|
||||||
|
if line.split()[1] != "security":
|
||||||
|
continue
|
||||||
|
except:
|
||||||
|
continue
|
||||||
|
(advisoryid, etype, package) = line.split()
|
||||||
|
errata.append( { "name": package, "advisory": advisoryid } )
|
||||||
|
|
||||||
|
return errata
|
||||||
|
|
||||||
def get_security_updates(self):
|
def get_security_updates(self):
|
||||||
"""Gets all updates, but differentiates between
|
"""Gets all updates, but differentiates between
|
||||||
@ -394,7 +413,7 @@ class YumTester:
|
|||||||
status = UNKNOWN
|
status = UNKNOWN
|
||||||
message = "code error - please contact author for a fix"
|
message = "code error - please contact author for a fix"
|
||||||
|
|
||||||
number_updates = self.get_all_updates()
|
number_updates, perfdata = self.get_all_updates()
|
||||||
if number_updates == 0:
|
if number_updates == 0:
|
||||||
status = OK
|
status = OK
|
||||||
message = "0 Updates Available"
|
message = "0 Updates Available"
|
||||||
@ -405,7 +424,7 @@ class YumTester:
|
|||||||
else:
|
else:
|
||||||
message = "%s Updates Available" % number_updates
|
message = "%s Updates Available" % number_updates
|
||||||
|
|
||||||
return status, message
|
return status, message, perfdata
|
||||||
|
|
||||||
|
|
||||||
def test_security_updates(self):
|
def test_security_updates(self):
|
||||||
@ -417,6 +436,8 @@ class YumTester:
|
|||||||
|
|
||||||
number_security_updates, number_other_updates = \
|
number_security_updates, number_other_updates = \
|
||||||
self.get_security_updates()
|
self.get_security_updates()
|
||||||
|
|
||||||
|
perfdata = "'security_updates'=%s 'other_updates'=%s" % (number_security_updates, number_other_updates)
|
||||||
if number_security_updates == 0:
|
if number_security_updates == 0:
|
||||||
status = OK
|
status = OK
|
||||||
message = "0 Security Updates Available"
|
message = "0 Security Updates Available"
|
||||||
@ -427,7 +448,6 @@ class YumTester:
|
|||||||
elif number_security_updates > 1:
|
elif number_security_updates > 1:
|
||||||
message = "%s Security Updates Available" \
|
message = "%s Security Updates Available" \
|
||||||
% number_security_updates
|
% number_security_updates
|
||||||
|
|
||||||
if number_other_updates != 0:
|
if number_other_updates != 0:
|
||||||
if self.warn_on_any_update and status != CRITICAL:
|
if self.warn_on_any_update and status != CRITICAL:
|
||||||
status = WARNING
|
status = WARNING
|
||||||
@ -437,7 +457,12 @@ class YumTester:
|
|||||||
message += ". %s Non-Security Updates Available" \
|
message += ". %s Non-Security Updates Available" \
|
||||||
% number_other_updates
|
% number_other_updates
|
||||||
|
|
||||||
return status, message
|
if number_security_updates and self.long_output:
|
||||||
|
errata = self.get_security_updateinfo()
|
||||||
|
for e in errata:
|
||||||
|
message += "\n%s - %s" % (e['advisory'], e['name'])
|
||||||
|
|
||||||
|
return status, message, perfdata
|
||||||
|
|
||||||
|
|
||||||
def vprint(self, threshold, message):
|
def vprint(self, threshold, message):
|
||||||
@ -508,6 +533,13 @@ def main():
|
|||||||
help="Explicitly disables a repository when calling YUM "
|
help="Explicitly disables a repository when calling YUM "
|
||||||
+ "Can take a comma separated list of repositories")
|
+ "Can take a comma separated list of repositories")
|
||||||
|
|
||||||
|
parser.add_option( "-l",
|
||||||
|
"--long-output",
|
||||||
|
action="store_true",
|
||||||
|
dest="long_output",
|
||||||
|
help="Shows more detailed output including the errata "
|
||||||
|
+ "ID.")
|
||||||
|
|
||||||
parser.add_option( "-t",
|
parser.add_option( "-t",
|
||||||
"--timeout",
|
"--timeout",
|
||||||
dest="timeout",
|
dest="timeout",
|
||||||
@ -544,14 +576,15 @@ def main():
|
|||||||
tester.timeout = options.timeout
|
tester.timeout = options.timeout
|
||||||
tester.verbosity = options.verbosity
|
tester.verbosity = options.verbosity
|
||||||
tester.warn_on_any_update = options.warn_on_any_update
|
tester.warn_on_any_update = options.warn_on_any_update
|
||||||
|
tester.long_output = options.long_output
|
||||||
|
|
||||||
if options.version:
|
if options.version:
|
||||||
print "%s - Version %s\n" \
|
print "%s - Version %s\n" \
|
||||||
% (__title__, __version__)
|
% (__title__, __version__)
|
||||||
sys.exit(OK)
|
sys.exit(OK)
|
||||||
|
|
||||||
result, output = tester.test_yum_updates()
|
result, output, perfdata = tester.test_yum_updates()
|
||||||
end(result, output)
|
end(result, output, perfdata)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
Loading…
Reference in New Issue
Block a user