Code cleaning

This commit is contained in:
Benjamin Renard 2022-12-15 18:28:21 +01:00
parent c3f1fd1e04
commit 7e6ae28c54

View file

@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# Nagios plugin to check Ceph cluster state
#
@ -40,13 +40,13 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
import sys
import os
import json
import subprocess
import re
import argparse
import json
import os
import re
import subprocess
import sys
# default ceph values
CEPH_COMMAND = '/usr/bin/ceph'
@ -185,7 +185,7 @@ ceph_cmd.append('status')
ceph_cmd.append('--format=json')
# exec command
p = subprocess.Popen(ceph_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
with subprocess.Popen(ceph_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) as p:
output, err = p.communicate()
if not output:
@ -209,7 +209,7 @@ total_mon = data['monmap'].get('num_mons', len(data['monmap'].get('mons', [])))
if not total_mon:
print("UNKNOWN : fail to retreive total number of monitors")
sys.exit(STATUS['UNKNOWN'])
total_mon_up = len(data.get('quorum', data['health'].get('timechecks', dict()).get('mons', [])))
total_mon_up = len(data.get('quorum', data['health'].get('timechecks', {}).get('mons', [])))
if not total_mon_up:
print("UNKNOWN : fail to retreive total number of UP monitors")
sys.exit(STATUS['UNKNOWN'])