New command line syntax

Signed-off-by: Sven Velt <sven@velt.de>
This commit is contained in:
Sven Velt 2011-01-12 16:25:11 +01:00
parent 7a1e5339a9
commit 4e909d694f

View file

@ -305,63 +305,68 @@ class CheckNAF(SNMPMonitoringPlugin):
def main(): def main():
plugin = CheckNAF(pluginname='check_naf', tagforstatusline='NAF', description=u'Monitoring NetApp™ FAS systems', version='0.9') plugin = CheckNAF(pluginname='check_naf', tagforstatusline='NAF', description=u'Monitoring NetApp™ FAS systems', version='0.9')
plugin.add_cmdlineoption('', '--check', 'check', 'check or list of checks', default='') plugin.add_cmdlineoption('', '--check', 'check', 'OBSOLETE - use new syntax!', default='')
plugin.add_cmdlineoption('', '--target', 'target', 'target or list of targets', default='') plugin.add_cmdlineoption('', '--target', 'target', 'OBSOLETE - use new syntax!', default='')
plugin.add_cmdlineoption('-w', '', 'warn', 'warning thresold or a list of it', default='') plugin.add_cmdlineoption('-w', '', 'warn', 'OBSOLETE - use new syntax!', default='')
plugin.add_cmdlineoption('-c', '', 'crit', 'warning thresold or a list of it', default='') plugin.add_cmdlineoption('-c', '', 'crit', 'OBSOLETE - use new syntax!', default='')
plugin.parse_cmdlineoptions() plugin.parse_cmdlineoptions()
plugin.prepare_snmp() plugin.prepare_snmp()
if ',' in plugin.options.check: if plugin.options.check or plugin.options.target:
checks = plugin.options.check.split(',') import sys
checks.reverse() arguments = plugin.options.check
for s in [plugin.options.target, plugin.options.warn, plugin.options.crit]:
arguments += ':' + s
plugin.back2nagios(3, 'Obsolete syntax - please use new syntax: "%s %s"' % (sys.argv[0], arguments))
checks = []
for quad in plugin.args:
quad = quad.split(':')
quad = (quad + ['', '', ''])[:4] # Fix length to 4, fill with ''
# Convert list of checks to list
if ',' in quad[0]:
quad[0] = quad[0].split(',')
else: else:
checks = [plugin.options.check,] quad[0] = [quad[0],]
if ',' in plugin.options.target: # Convert list of targets to list
targets = plugin.options.target.split(',') if ',' in quad[1]:
quad[1] = quad[1].split(',')
else: else:
targets = [plugin.options.target,] quad[1] = [quad[1],]
while len(checks): for target in quad[1]:
check = checks.pop() for check in quad[0]:
checks.append(tuple([check, target, quad[2], quad[3]]))
target = None if len(checks) == 0:
arguments = None plugin.back2nagios(3, 'No check specified!')
if ':' in check:
target = ':'.join(check.split(':')[1:]) for quad in checks:
check = check.split(':')[0] (check, target, warn, crit) = tuple(quad)
if ':' in target:
arguments = ':'.join(target.split(':')[1:])
target = target.split(':')[0]
if check == 'global': if check == 'global':
result = plugin.check_global() result = plugin.check_global()
elif check == 'cpu': elif check == 'cpu':
result = plugin.check_cpu() result = plugin.check_cpu(warn=warn, crit=crit)
elif check == 'disk': elif check == 'disk':
result = plugin.check_disk(target=target) result = plugin.check_disk(target=target, warn=warn, crit=crit)
elif check == 'nvram': elif check == 'nvram':
result = plugin.check_nvram() result = plugin.check_nvram()
elif check == 'version': elif check == 'version':
result = plugin.check_version() result = plugin.check_version()
elif check == 'vol_data':
elif check.startswith('vol_'): result = plugin.check_vol_data(volume=target, warn=warn, crit=crit)
combinedchecks = [check,]
while len(checks) > 0 and checks[0].startswith('vol_'):
combinedchecks.append(checks.pop())
for target in targets:
for check in combinedchecks:
if check == 'vol_data':
result = plugin.check_vol_data(target, plugin.options.warn, plugin.options.crit)
elif check == 'vol_snap': elif check == 'vol_snap':
result = plugin.check_vol_snap(target, plugin.options.warn, plugin.options.crit) result = plugin.check_vol_snap(volume=target, warn=warn, crit=crit)
elif check =='vol_inode': elif check =='vol_inode':
result = plugin.check_vol_inode(target, plugin.options.warn, plugin.options.crit) result = plugin.check_vol_inode(volume=target, warn=warn, crit=crit)
elif check =='vol_files': elif check =='vol_files':
result = plugin.check_vol_files(target, plugin.options.warn, plugin.options.crit) result = plugin.check_vol_files(volume=target, warn=warn, crit=crit)
# from pprint import pprint # from pprint import pprint
# pprint(plugin.dump_brain()) # pprint(plugin.dump_brain())