-
Hahn Axel (hahn) authoredHahn Axel (hahn) authored
check_ceph_osd 2.39 KiB
#!/bin/bash
# ======================================================================
#
# Icinga/ Nagios Check
# CEPH STATUS / HEALTH
#
# ----------------------------------------------------------------------
#
# REQUIREMENTS:
# - ceph
#
# SYNTAX:
# - check_ceph_status
# No parameter required
#
# RESULT:
# OK = all OSDs up
# CRITITCAL = min. 1 OSD is down
# UNKNOWN = ceph osd tree is not executable
#
# ----------------------------------------------------------------------
# 2020-03-04 v1.0 <axel.hahn@iml.unibe.ch>
# 2020-03-05 v1.1 <axel.hahn@iml.unibe.ch> added params -w -c
# 2020-03-05 v1.2 <axel.hahn@iml.unibe.ch> switch to ph.* helper functions
# ======================================================================
. `dirname $0`/inc_pluginfunctions
tmpfile=/tmp/ceph_status_output_$$
# ----------------------------------------------------------------------
# FUNCTIONS
# ----------------------------------------------------------------------
# fetch lines of OSD entries only from output of ceph osd tree
function getOsd(){
grep "^\ *[0-9]" $tmpfile
}
# ----------------------------------------------------------------------
# MAIN
# ----------------------------------------------------------------------
sudo /bin/ceph osd tree > $tmpfile 2>&1
if [ $? -ne 0 ]; then
rm -f $tmpfile
ph.abort "UNKNOWN: ceph is not available or no sudo permissions to execute ceph commands."
fi
# set default / override from command line params
typeset -i iWarnLimit=` ph.getValueWithParam 1 w "$@"`
typeset -i iCriticalLimit=` ph.getValueWithParam 2 c "$@"`
typeset -i iOsdTotal=` getOsd | wc -l`
typeset -i iOsdDown=` getOsd | awk '{ print $4 }' | grep "down" | wc -l`
typeset -i iOsdUp=` getOsd | awk '{ print $4 }' | grep "up" | wc -l`
if [ $iOsdDown -lt $iWarnLimit ]; then
ph.setStatus "ok"
else
if [ $iOsdDown -ge $iCriticalLimit ]; then
ph.setStatus "critical"
else
ph.setStatus "warning"
fi
fi
ph.status "Check of available OSDs - $iOsdTotal OSDs total .. $iOsdUp up .. $iOsdDown down (Limits: warn at $iWarnLimit; critical $iCriticalLimit)"
cat $tmpfile
rm -f $tmpfile
ph.perfadd "osd-total" "${iOsdTotal}" "" "" 0 ${iOsdTotal}
ph.perfadd "osd-up" "${iOsdUp}" "" "" 0 ${iOsdTotal}
ph.perfadd "osd-down" "${iOsdDown}" "" "" 0 ${iOsdTotal}
ph.exit
# ----------------------------------------------------------------------