check_xbps: Catch "transaction aborted" error, return CRITICAL for updates

- Check return code of "xbps-install" call
- CRITICAL instead of WARNING when updates available
- Use return code from plugin class
This commit is contained in:
Sven Velt 2016-11-24 19:36:26 +01:00
parent 8fafec4e98
commit 58c8caecea

View file

@ -88,7 +88,7 @@ def run_command(cmdline):
stderr = subprocess.PIPE
)
except OSError:
plugin.back2nagios(3, 'Could not execute command line: %s' % subprocess.list2cmdline(cmdline))
plugin.back2nagios(plugin.RETURNCODE['UNKNOWN'], 'Could not execute command line: %s' % subprocess.list2cmdline(cmdline))
(sout,serr) = cmd.communicate()
plugin.verbose(2, 'Runtime %.3fs' % (time.time() - tstart, ) )
@ -112,7 +112,7 @@ if plugin.options.sync_repo_index:
serr and plugin.verbose(3, serr, prefix='stderr: ')
plugin.verbose(2, 'Return code: %d' % rc)
if rc != 0 and plugin.options.fail_on_sync_failure:
plugin.back2nagios(2, 'Syncing of repository index files failed')
plugin.back2nagios(plugin.RETURNCODE['CRITICAL'], 'Syncing of repository index files failed')
##############################################################################
@ -122,6 +122,14 @@ sout and plugin.verbose(3, sout, prefix='stdout: ')
serr and plugin.verbose(3, serr, prefix='stderr: ')
plugin.verbose(2, 'Return code: %d' % rc)
if rc == 8:
# RC 8: Transaction aborted due to unresolved shlibs.
plugin.back2nagios(plugin.RETURNCODE['WARNING'], serr[-1], serr[:-1])
elif rc not in [0, 6]:
# RC 0: Packages to update
# RC 6: Package(s) already installed
plugin.back2nagios(plugin.RETURNCODE['WARNING'], 'Unknown returncode "%s", please contact the author of plugin or open an issue!' % rc)
action = {'remove':[], 'update':[], 'install':[],}
arch = {}
repo = {}
@ -182,7 +190,7 @@ else:
stats += '%s from %s, ' % (v, k)
multiline.append(stats[:-2])
plugin.remember_check('Updates', plugin.RETURNCODE['WARNING'], out, multilineoutput=multiline)
plugin.remember_check('Updates', plugin.RETURNCODE['CRITICAL'], out, multilineoutput=multiline)
# Exit
plugin.brain2output()