Skip to content
Open
Show file tree
Hide file tree
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
34 changes: 27 additions & 7 deletions src/check_ceph_df
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ import os
import subprocess
import sys

__version__ = '1.7.1'
__version__ = '1.8.0'

# default ceph values
CEPH_COMMAND = '/usr/bin/ceph'
CEPH_ADM_COMMAND = '/usr/sbin/cephadm'

# nagios exit code
STATUS_OK = 0
Expand All @@ -38,6 +39,7 @@ def main():
# parse args
parser = argparse.ArgumentParser(description="'ceph df' nagios plugin.")
parser.add_argument('-e','--exe', help='ceph executable [%s]' % CEPH_COMMAND)
parser.add_argument('-A','--admexe', help='cephadm executable [%s]' % CEPH_ADM_COMMAND)
parser.add_argument('-c','--conf', help='alternative ceph conf file')
parser.add_argument('-m','--monaddress', help='ceph monitor address[:port]')
parser.add_argument('-i','--id', help='ceph client id')
Expand All @@ -48,13 +50,20 @@ def main():
parser.add_argument('-W','--warn', help="warn above this percent RAW USED", type=float)
parser.add_argument('-C','--critical', help="critical alert above this percent RAW USED", type=float)
parser.add_argument('-V','--version', help='show version and exit', action='store_true')
parser.add_argument('-a','--cephadm', help='uses cephadm to execute the command', action='store_true')
args = parser.parse_args()

# validate args
cephadm_exec = args.admexe if args.admexe else CEPH_ADM_COMMAND
ceph_exec = args.exe if args.exe else CEPH_COMMAND
if not os.path.exists(ceph_exec):
print("ERROR: ceph executable '%s' doesn't exist" % ceph_exec)
return STATUS_UNKNOWN
if args.cephadm:
if not os.path.exists(cephadm_exec):
print("ERROR: cephadm executable '%s' doesn't exist" % cephadm_exec)
return STATUS_UNKNOWN
else:
if not os.path.exists(ceph_exec):
print("ERROR: ceph executable '%s' doesn't exist" % ceph_exec)
return STATUS_UNKNOWN

if args.version:
print('version %s' % __version__)
Expand All @@ -74,6 +83,17 @@ def main():

# build command
ceph_df = [ceph_exec]

if args.cephadm:
# Prepend the command with the cephadm binary and the shell command
ceph_df = [cephadm_exec, 'shell']

if args.keyring:
ceph_df.append('-v')
ceph_df.append('%s:%s:ro' % (args.keyring, args.keyring))
ceph_df.append('--')
ceph_df.append(ceph_exec)

if args.monaddress:
ceph_df.append('-m')
ceph_df.append(args.monaddress)
Expand Down Expand Up @@ -216,9 +236,9 @@ def main():
return STATUS_OK

#for
elif err:
# read only first line of error
one_line = err.split('\n')[0]
elif p.returncode != 0:
# read only first line of error, cephadm prints 4 lines
one_line = err.split('\n')[4 if args.cephadm else 0]
if '-1 ' in one_line:
idx = one_line.rfind('-1 ')
print('ERROR: %s: %s' % (ceph_exec, one_line[idx+len('-1 '):]))
Expand Down
27 changes: 23 additions & 4 deletions src/check_ceph_mgr
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ import subprocess
import sys
import json

__version__ = '1.0.0'
__version__ = '1.1.0'

# default ceph values
CEPH_EXEC = '/usr/bin/ceph'
CEPH_COMMAND = 'mgr dump -f json'
CEPH_ADM_COMMAND = '/usr/sbin/cephadm'

CEPH_MGR_DUMP_EXAMPLE = '''
$ ceph --version
Expand Down Expand Up @@ -102,23 +103,31 @@ def main():
# parse args
parser = argparse.ArgumentParser(description="'ceph mgr dump' nagios plugin.")
parser.add_argument('-e', '--exe', help='ceph executable [%s]' % CEPH_EXEC)
parser.add_argument('-A','--admexe', help='cephadm executable [%s]' % CEPH_ADM_COMMAND)
parser.add_argument('-c', '--conf', help='alternative ceph conf file')
parser.add_argument('-m', '--monaddress', help='ceph monitor to use for queries (address[:port])')
parser.add_argument('-i', '--id', help='ceph client id')
parser.add_argument('-n', '--name', help='ceph client name')
parser.add_argument('-k', '--keyring', help='ceph client keyring file')
parser.add_argument('-V', '--version', help='show version and exit', action='store_true')
parser.add_argument('-a','--cephadm', help='uses cephadm to execute the command', action='store_true')
args = parser.parse_args()

if args.version:
print("version {}".format(__version__))
return STATUS_OK

# validate args
cephadm_exec = args.admexe if args.admexe else CEPH_ADM_COMMAND
ceph_exec = args.exe if args.exe else CEPH_EXEC
if not os.path.exists(ceph_exec):
print("MGR ERROR: ceph executable '{}' doesn't exist".format(ceph_exec))
return STATUS_UNKNOWN
if args.cephadm:
if not os.path.exists(cephadm_exec):
print("ERROR: cephadm executable '%s' doesn't exist" % cephadm_exec)
return STATUS_UNKNOWN
else:
if not os.path.exists(ceph_exec):
print("MGR ERROR: ceph executable '{}' doesn't exist".format(ceph_exec))
return STATUS_UNKNOWN

if args.conf and not os.path.exists(args.conf):
print("MGR ERROR: ceph conf file '{}' doesn't exist".format(args.conf))
Expand All @@ -130,6 +139,16 @@ def main():

# build command
ceph_cmd = [ceph_exec]
if args.cephadm:
# Prepend the command with the cephadm binary and the shell command
ceph_cmd = [cephadm_exec, 'shell']

if args.keyring:
ceph_cmd.append('-v')
ceph_cmd.append('%s:%s:ro' % (args.keyring, args.keyring))
ceph_cmd.append('--')
ceph_cmd.append(ceph_exec)

if args.monaddress:
ceph_cmd.append('-m')
ceph_cmd.append(args.monaddress)
Expand Down
28 changes: 24 additions & 4 deletions src/check_ceph_mon
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ import subprocess
import sys
import json

__version__ = '1.5.0'
__version__ = '1.6.0'

# default ceph values
CEPH_EXEC = '/usr/bin/ceph'
CEPH_COMMAND = 'quorum_status'
CEPH_ADM_COMMAND = '/usr/sbin/cephadm'

# nagios exit code
STATUS_OK = 0
Expand Down Expand Up @@ -77,23 +78,31 @@ def main():
# parse args
parser = argparse.ArgumentParser(description="'ceph quorum_status' nagios plugin.")
parser.add_argument('-e','--exe', help='ceph executable [%s]' % CEPH_EXEC)
parser.add_argument('-A','--admexe', help='cephadm executable [%s]' % CEPH_ADM_COMMAND)
parser.add_argument('-c','--conf', help='alternative ceph conf file')
parser.add_argument('-m','--monaddress', help='ceph monitor to use for queries (address[:port])')
parser.add_argument('-i','--id', help='ceph client id')
parser.add_argument('-k','--keyring', help='ceph client keyring file')
parser.add_argument('-V','--version', help='show version and exit', action='store_true')
parser.add_argument('-I','--monid', help='mon ID to be checked for availability')
parser.add_argument('-a','--cephadm', help='uses cephadm to execute the command', action='store_true')
args = parser.parse_args()

if args.version:
print('version %s' % __version__)
return STATUS_OK

# validate args
cephadm_exec = args.admexe if args.admexe else CEPH_ADM_COMMAND
ceph_exec = args.exe if args.exe else CEPH_EXEC
if not os.path.exists(ceph_exec):
print("MON ERROR: ceph executable '%s' doesn't exist" % ceph_exec)
return STATUS_UNKNOWN
if args.cephadm:
if not os.path.exists(cephadm_exec):
print("ERROR: cephadm executable '%s' doesn't exist" % cephadm_exec)
return STATUS_UNKNOWN
else:
if not os.path.exists(ceph_exec):
print("ERROR: ceph executable '%s' doesn't exist" % ceph_exec)
return STATUS_UNKNOWN

if args.conf and not os.path.exists(args.conf):
print("MON ERROR: ceph conf file '%s' doesn't exist" % args.conf)
Expand All @@ -109,6 +118,17 @@ def main():

# build command
ceph_cmd = [ceph_exec]

if args.cephadm:
# Prepend the command with the cephadm binary and the shell command
ceph_cmd = [cephadm_exec, 'shell']

if args.keyring:
ceph_cmd.append('-v')
ceph_cmd.append('%s:%s:ro' % (args.keyring, args.keyring))
ceph_cmd.append('--')
ceph_cmd.append(ceph_exec)

if args.monaddress:
ceph_cmd.append('-m')
ceph_cmd.append(args.monaddress)
Expand Down
48 changes: 35 additions & 13 deletions src/check_ceph_osd
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ import subprocess
import sys
import socket

__version__ = '1.5.2'
__version__ = '1.6.0'

# default ceph values
CEPH_ADM_COMMAND = '/usr/sbin/cephadm'
CEPH_COMMAND = '/usr/bin/ceph'

# nagios exit code
Expand All @@ -41,6 +42,7 @@ def main():
# parse args
parser = argparse.ArgumentParser(description="'ceph osd' nagios plugin.")
parser.add_argument('-e','--exe', help='ceph executable [%s]' % CEPH_COMMAND)
parser.add_argument('-A','--admexe', help='cephadm executable [%s]' % CEPH_ADM_COMMAND)
parser.add_argument('-c','--conf', help='alternative ceph conf file')
parser.add_argument('-m','--monaddress', help='ceph monitor address[:port]')
parser.add_argument('-i','--id', help='ceph client id')
Expand All @@ -50,13 +52,22 @@ def main():
parser.add_argument('-I','--osdid', help='osd id', required=False)
parser.add_argument('-C','--crit', help='Number of failed OSDs to trigger critical (default=2)',type=int,default=2, required=False)
parser.add_argument('-o','--out', help='check osds that are set OUT', default=False, action='store_true', required=False)
parser.add_argument('-a','--cephadm', help='uses cephadm to execute the command', action='store_true')
args = parser.parse_args()

# validate args
cephadm_exec = args.admexe if args.admexe else CEPH_ADM_COMMAND
ceph_exec = args.exe if args.exe else CEPH_COMMAND
if not os.path.exists(ceph_exec):
print("OSD ERROR: ceph executable '%s' doesn't exist" % ceph_exec)
return STATUS_UNKNOWN

if args.cephadm:
if not os.path.exists(cephadm_exec):
print("ERROR: cephadm executable '%s' doesn't exist" % cephadm_exec)
return STATUS_UNKNOWN
else:
if not os.path.exists(ceph_exec):
print("ERROR: ceph executable '%s' doesn't exist" % ceph_exec)
return STATUS_UNKNOWN


if args.version:
print('version %s' % __version__)
Expand Down Expand Up @@ -89,18 +100,29 @@ def main():

# build command
ceph_cmd = [ceph_exec]

if args.cephadm:
# Prepend the command with the cephadm binary and the shell command
ceph_cmd = [cephadm_exec, 'shell']

if args.keyring:
ceph_cmd.append('-v')
ceph_cmd.append('%s:%s:ro' % (args.keyring, args.keyring))
ceph_cmd.append('--')
ceph_cmd.append(ceph_exec)

if args.monaddress:
ceph_cmd.append('-m')
ceph_cmd.append(args.monaddress)
ceph_cmd.append('-m')
ceph_cmd.append(args.monaddress)
if args.conf:
ceph_cmd.append('-c')
ceph_cmd.append(args.conf)
ceph_cmd.append('-c')
ceph_cmd.append(args.conf)
if args.id:
ceph_cmd.append('--id')
ceph_cmd.append(args.id)
ceph_cmd.append('--id')
ceph_cmd.append(args.id)
if args.keyring:
ceph_cmd.append('--keyring')
ceph_cmd.append(args.keyring)
ceph_cmd.append('--keyring')
ceph_cmd.append(args.keyring)
ceph_cmd.append('osd')
ceph_cmd.append('dump')

Expand All @@ -109,7 +131,7 @@ def main():
output, err = p.communicate()
output = output.decode('utf8')

if err or not output:
if p.returncode != 0 or not output:
print("OSD ERROR: %s" % err)
return STATUS_ERROR

Expand Down
Loading