Code cleaning
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
Benjamin Renard 2022-12-17 00:10:09 +01:00
parent ce64743d30
commit c615db7bc5
2 changed files with 55 additions and 44 deletions

2
.pylintrc Normal file
View file

@ -0,0 +1,2 @@
[MESSAGES CONTROL]
disable=consider-using-f-string

View file

@ -1,42 +1,43 @@
#!/usr/bin/env python #!/usr/bin/env python
# """
# Nagios plugin to check Ceph cluster usage
# Nagios plugin to check Ceph cluster usage
# Usage: check_ceph_usage [options]
# Usage: check_ceph_usage [options]
# Options:
# -h, --help show this help message and exit Options:
# -d, --debug -h, --help show this help message and exit
# -b BIN, --bin=BIN Ceph binary (default: /usr/bin/ceph) -d, --debug
# --conf=CONF Ceph configuration file -b BIN, --bin=BIN Ceph binary (default: /usr/bin/ceph)
# -m MON, --mon=MON Ceph monitor address[:port] --conf=CONF Ceph configuration file
# -i ID, --id=ID Ceph client id -m MON, --mon=MON Ceph monitor address[:port]
# -k KEYRING, --keyring=KEYRING -i ID, --id=ID Ceph client id
# Ceph client keyring file -k KEYRING, --keyring=KEYRING
# -w WARNDATA, --warning-data=WARNDATA Ceph client keyring file
# Warning data threshold (default: 70%) -w WARNDATA, --warning-data=WARNDATA
# -c CRITDATA, --critical-data=CRITDATA Warning data threshold (default: 70%)
# Critical data threshold (default: 85%) -c CRITDATA, --critical-data=CRITDATA
# -W WARNALLOC, --warning-allocated=WARNALLOC Critical data threshold (default: 85%)
# Warning allocated threshold (default: 80%) -W WARNALLOC, --warning-allocated=WARNALLOC
# -C CRITALLOC, --critical-allocated=CRITALLOC Warning allocated threshold (default: 80%)
# Critical allocated threshold (default: 90%) -C CRITALLOC, --critical-allocated=CRITALLOC
# Critical allocated threshold (default: 90%)
# Copyright (c) 2013 Benjamin Renard <brenard@zionetrix.net>
# Copyright (c) 2013 Benjamin Renard <brenard@zionetrix.net>
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License version 2 This program is free software; you can redistribute it and/or
# as published by the Free Software Foundation. modify it under the terms of the GNU General Public License version 2
# as published by the Free Software Foundation.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of This program is distributed in the hope that it will be useful,
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the but WITHOUT ANY WARRANTY; without even the implied warranty of
# GNU General Public License for more details. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software You should have received a copy of the GNU General Public License
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 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 sys
import os import os
@ -150,7 +151,7 @@ parser.add_argument(
options = parser.parse_args() options = parser.parse_args()
# validate args # validate args
if not os.path.exists(options.bin): if not os.path.exists(options.bin):
print("ERROR: ceph executable '%s' doesn't exist" % options.bin) print("ERROR: ceph executable '%s' doesn't exist" % options.bin)
sys.exit(STATUS['UNKNOWN']) sys.exit(STATUS['UNKNOWN'])
@ -181,6 +182,7 @@ ceph_cmd.append('status')
ceph_cmd.append('--format=json') ceph_cmd.append('--format=json')
# exec command # exec command
# pylint: disable=consider-using-with
p = subprocess.Popen(ceph_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) p = subprocess.Popen(ceph_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output, err = p.communicate() output, err = p.communicate()
@ -198,10 +200,14 @@ if options.debug:
print("allocated: %s" % data['pgmap']['bytes_used']) print("allocated: %s" % data['pgmap']['bytes_used'])
print("total: %s" % data['pgmap']['bytes_total']) print("total: %s" % data['pgmap']['bytes_total'])
PER_DATA = round(int(data['pgmap']['data_bytes']) * 100 / int(data['pgmap']['bytes_total']), 1) PER_DATA = round(
int(data['pgmap']['data_bytes']) * 100 / int(data['pgmap']['bytes_total']),
1)
DATA_WARN_T = int(int(data['pgmap']['bytes_total']) * options.warndata / 100) DATA_WARN_T = int(int(data['pgmap']['bytes_total']) * options.warndata / 100)
DATA_CRIT_T = int(int(data['pgmap']['bytes_total']) * options.critdata / 100) DATA_CRIT_T = int(int(data['pgmap']['bytes_total']) * options.critdata / 100)
PER_ALLOC = round(int(data['pgmap']['bytes_used']) * 100 / int(data['pgmap']['bytes_total']), 1) PER_ALLOC = round(
int(data['pgmap']['bytes_used']) * 100 / int(data['pgmap']['bytes_total']),
1)
ALLOC_WARN_T = int(int(data['pgmap']['bytes_total']) * options.warnalloc / 100) ALLOC_WARN_T = int(int(data['pgmap']['bytes_total']) * options.warnalloc / 100)
ALLOC_CRIT_T = int(int(data['pgmap']['bytes_total']) * options.critalloc / 100) ALLOC_CRIT_T = int(int(data['pgmap']['bytes_total']) * options.critalloc / 100)
@ -217,10 +223,13 @@ else:
STATUS_TXT = 'OK' STATUS_TXT = 'OK'
print( print(
"%s - %s%% allocated / %s%% really used|allocated=%sB;%s;%s;0;%s,used=%sB;%s;%s;0;%s" % ( "%s - %s%% allocated / %s%% really used|"
"allocated=%sB;%s;%s;0;%s,used=%sB;%s;%s;0;%s" % (
STATUS_TXT, PER_ALLOC, PER_DATA, STATUS_TXT, PER_ALLOC, PER_DATA,
data['pgmap']['bytes_used'], ALLOC_WARN_T, ALLOC_CRIT_T, data['pgmap']['bytes_total'], data['pgmap']['bytes_used'], ALLOC_WARN_T, ALLOC_CRIT_T,
data['pgmap']['data_bytes'], DATA_WARN_T, DATA_CRIT_T, data['pgmap']['bytes_total'] data['pgmap']['bytes_total'],
data['pgmap']['data_bytes'], DATA_WARN_T, DATA_CRIT_T,
data['pgmap']['bytes_total']
) )
) )
sys.exit(STATUS[STATUS_TXT]) sys.exit(STATUS[STATUS_TXT])