check_xbps.py: Added --sudo
- "--sudo": Prepend all commands - Improved error handling
This commit is contained in:
parent
18c70c0a12
commit
21b7b687a0
|
@ -54,6 +54,7 @@ plugin = MonitoringPlugin(
|
|||
plugin.add_cmdlineoption('-P', '--path-xbps-install', 'xbps_install', 'full path to xbps-install', default='/usr/bin/xbps-install')
|
||||
plugin.add_cmdlineoption('-S', '--sync-repo-index', 'sync_repo_index', 'sync repository index files at startup', default=False, action='store_true')
|
||||
plugin.add_cmdlineoption('', '--ignore-sync-failure', 'fail_on_sync_failure', 'ignore repo index sync failures', default=True, action='store_false')
|
||||
plugin.add_cmdlineoption('', '--sudo', 'sudo', 'call "xbps-install" with sudo', default=False, action='store_true')
|
||||
|
||||
plugin.add_cmdlineoption('', '--mymonplugins-testmode', 'mymonplugins_testmode', None, default=False, action='store_true')
|
||||
|
||||
|
@ -80,6 +81,10 @@ lxc-2.0.4_1 update x86_64 https://repo.voidlinux.eu/current 1837102 468024'''.sp
|
|||
|
||||
def run_command(cmdline):
|
||||
tstart = time.time()
|
||||
if plugin.options.sudo:
|
||||
new = ['sudo', '-n', '--']
|
||||
new.extend(cmdline)
|
||||
cmdline = new
|
||||
plugin.verbose(1, 'Running command line: %s' % subprocess.list2cmdline(cmdline))
|
||||
try:
|
||||
cmd = subprocess.Popen(
|
||||
|
@ -111,8 +116,8 @@ if plugin.options.sync_repo_index:
|
|||
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 != 0 and plugin.options.fail_on_sync_failure:
|
||||
plugin.back2nagios(plugin.RETURNCODE['CRITICAL'], 'Syncing of repository index files failed')
|
||||
if plugin.options.fail_on_sync_failure and (rc != 0 or 'ERROR:' in ' '.join(serr)):
|
||||
plugin.back2nagios(plugin.RETURNCODE['CRITICAL'], 'Syncing of repository index files failed', multiline=serr)
|
||||
|
||||
##############################################################################
|
||||
|
||||
|
@ -122,6 +127,11 @@ sout and plugin.verbose(3, sout, prefix='stdout: ')
|
|||
serr and plugin.verbose(3, serr, prefix='stderr: ')
|
||||
plugin.verbose(2, 'Return code: %d' % rc)
|
||||
|
||||
if plugin.options.sudo and 'sudo: ' in ' '.join(serr):
|
||||
# Running with sudo
|
||||
if rc == 1:
|
||||
# sudo RC 1: a password is required
|
||||
plugin.back2nagios(plugin.RETURNCODE['CRITICAL'], ' '.join(serr))
|
||||
if rc == 8:
|
||||
# RC 8: Transaction aborted due to unresolved shlibs.
|
||||
plugin.back2nagios(plugin.RETURNCODE['WARNING'], serr[-1], serr[:-1])
|
||||
|
|
Loading…
Reference in a new issue