diff --git a/scripts/swift/check_swift_dispersion b/scripts/swift/check_swift_dispersion index 97bca22..1daa78f 100755 --- a/scripts/swift/check_swift_dispersion +++ b/scripts/swift/check_swift_dispersion @@ -24,6 +24,7 @@ import os import sys import json +from sys import argv STATE_OK=0 STATE_WARNING=1 @@ -31,29 +32,32 @@ STATE_CRITICAL=2 STATE_UNKNOWN=3 STATE_DEPENDENT=4 +dispersion_config = os.getenv("SWIFT_DISPERSION_CONFIG", "/etc/swift/swift.conf") +if len(argv) > 1: + dispersion_config = argv[1] + with os.popen("swift-dispersion-report -j %s" \ - % os.getenv("SWIFT_DISPERSION_CONFIG", "/etc/swift/swift.conf")) as report: + % dispersion_config) as report: stats = json.load(report) msgs = [] state = STATE_OK +missing_critical = int(os.getenv("SWIFT_DISPERSION_MISSING_CRITICAL", 3)) +if len(argv) > 2: + missing_critical = int(argv[2]) # type_ is either "objects", "container" for type_, values in stats.iteritems(): msgs.append("%.2f%% %ss found" % (values['pct_found'], type_)) - if values['missing_one'] > 0: - msgs.append("%d %ss missing one copy" % (values['missing_one'], type_)) - state = max(state, STATE_WARNING) - - if values['missing_two'] > 0: - msgs.append("%d %ss missing two copies" % (values['missing_two'], type_)) - state = max(state, STATE_WARNING) - - if values['missing_all'] > 0: - msgs.append("%d %ss missing ALL copies" % (values['missing_all'], type_)) - state = max(state, STATE_CRITICAL) + for i in range(1,missing_critical+1): + if values.get("missing_%i" % i, 0) > 0: + msgs.append("%d %ss missing %i copies" % (values["missing_%i" % i], type_, i)) + if i >= missing_critical: + state = max(state, STATE_CRITICAL) + else: + state = max(state, STATE_WARNING) print ", ".join(msgs) sys.exit(state)