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 45f91ba985
commit 3fefe3383b

View file

@ -88,7 +88,7 @@ def run_command(cmdline):
stderr = subprocess.PIPE stderr = subprocess.PIPE
) )
except OSError: 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() (sout,serr) = cmd.communicate()
plugin.verbose(2, 'Runtime %.3fs' % (time.time() - tstart, ) ) 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: ') serr and plugin.verbose(3, serr, prefix='stderr: ')
plugin.verbose(2, 'Return code: %d' % rc) plugin.verbose(2, 'Return code: %d' % rc)
if rc != 0 and plugin.options.fail_on_sync_failure: 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: ') serr and plugin.verbose(3, serr, prefix='stderr: ')
plugin.verbose(2, 'Return code: %d' % rc) 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':[],} action = {'remove':[], 'update':[], 'install':[],}
arch = {} arch = {}
repo = {} repo = {}
@ -182,7 +190,7 @@ else:
stats += '%s from %s, ' % (v, k) stats += '%s from %s, ' % (v, k)
multiline.append(stats[:-2]) 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 # Exit
plugin.brain2output() plugin.brain2output()