Fix for changes in the output of ceph 1.3+ 'df' command.

Previously, 'ceph df --format=json' outputted some JSON
information where the following keys were defined:
total_space,total_used,total_avail

As of ceph 1.3, the keys have changed somewhat and are now
defined as:
total_bytes,total_used_bytes,total_avail_bytes

This patch handles the new keys while retaining compatibility
for older versions..

Closes-bug: 1537250
Change-Id: Ia7ab59109fc5263cd742587c99e94d18ef28fdcc
This commit is contained in:
Vincent S. Cojot 2016-01-25 14:59:26 -05:00 committed by Simon Pasquier
parent 123838128d
commit f0c3a92d33
1 changed files with 13 additions and 3 deletions

View File

@ -49,9 +49,19 @@ def interpret_output_df(output):
warn_percent = int(sys.argv[1]) if len(sys.argv) >= 2 else 85
crit_percent = int(sys.argv[2]) if len(sys.argv) >= 3 else 98
total = int(data['stats']['total_space'])
used = int(data['stats']['total_used'])
avail = int(data['stats']['total_avail'])
if 'total_bytes' in data['stats']:
total = int(data['stats']['total_bytes'])
else:
total = int(data['stats']['total_space'])
if 'total_used_bytes' in data['stats']:
used = int(data['stats']['total_used_bytes'])
else:
used = int(data['stats']['total_used'])
if 'total_avail_bytes' in data['stats']:
avail = int(data['stats']['total_avail_bytes'])
else:
avail = int(data['stats']['total_avail'])
# Test correctness of values
if used + avail != total: