Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support of openstack-swift from liberty #61

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions scripts/swift/check_swift_dispersion
Original file line number Diff line number Diff line change
Expand Up @@ -24,36 +24,40 @@
import os
import sys
import json
from sys import argv

STATE_OK=0
STATE_WARNING=1
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)