Files
charm-ceph-mon/files/nagios/collect_ceph_status.sh
Edin Sarajlic b8af44aefa Add nagios check for expected number of OSDs
This check does not require manually setting the number of expected
OSDs.

Initially, the charm sets the count (per-host) to that of what's
present in the OSD tree. The count will be updated (on a per-host
basis) when the number of OSDs grows, but not when it shrinks. There
is a charm action to reset the expected count using information from
the OSD tree.

Closes-Bug: #1952985
Change-Id: Ia6a060bf151908c1d4159e6bdffa7bfe1f0a7988
2022-10-05 13:02:54 +00:00

34 lines
774 B
Bash
Executable File

#!/bin/bash
# Copyright (C) 2014 Canonical
# All Rights Reserved
# Author: Jacek Nykis <jacek.nykis@canonical.com>
LOCK=/var/lock/ceph-status.lock
lockfile-create -r2 --lock-name $LOCK > /dev/null 2>&1
if [ $? -ne 0 ]; then
exit 1
fi
trap "rm -f $LOCK > /dev/null 2>&1" exit
DATA_DIR="/var/lib/nagios"
if [ ! -d $DATA_DIR ]; then
mkdir -p $DATA_DIR
fi
DATA_FILE="${DATA_DIR}/cat-ceph-status.txt"
TMP_FILE=$(mktemp -p ${DATA_DIR})
ceph status --format json >${TMP_FILE}
chown root:nagios ${TMP_FILE}
chmod 0640 ${TMP_FILE}
mv ${TMP_FILE} ${DATA_FILE}
DATA_FILE="${DATA_DIR}/current-ceph-osd-count.json"
TMP_FILE=$(mktemp -p ${DATA_DIR})
ceph osd tree --format json > ${TMP_FILE}
chown root:nagios ${TMP_FILE}
chmod 0640 ${TMP_FILE}
mv ${TMP_FILE} ${DATA_FILE}