--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/check_lvmthin Fri Jun 10 14:32:23 2016 +0200
@@ -0,0 +1,147 @@
+#!/bin/sh -e
+
+ME=$(basename $0)
+echo $ME
+NAME='LVMTHIN'
+E=3
+INFO=
+PERFDATA=
+
+lvsresults=$(mktemp /tmp/$ME.XXX)
+
+cleanup() {
+ [ -n "$lvsresults" ] && rm $lvsresults;
+}
+
+nagiosexit() {
+ local STATUS='UNKNOWN'
+ if [ $E = '2' ]; then STATUS='CRITICAL'
+ elif [ $E = '1' ]; then STATUS='WARNING'
+ elif [ $E = '0' ]; then STATUS='OK'
+ fi
+ echo "$NAME $STATUS${INFO:+: ${INFO}}${PERFDATA:+|$PERFDATA}"
+ exit $E
+}
+
+trap 'trap - EXIT; cleanup; nagiosexit $E' INT QUIT TERM EXIT
+
+die() {
+ INFO="$@"
+ exit 3
+}
+
+parse_lvs() {
+ results=$1
+ label=$2
+ while read vg lv u; do
+ addinfo=
+ if [ "$u" '>' "$C" ]; then
+ E=2
+ addinfo='yes'
+ elif [ "$u" '>' "$W" ]; then
+ [ $E != '2' ] && E=1
+ addinfo='yes'
+ fi
+ [ -n "$addinfo" ] && INFO="${INFO:+${INFO}; }$vg/$lv$label $u%"
+ PERFDATA="${PERFDATA:+${PERFDATA} }$vg/$lv$label=$u%;$W%;$C%;;"
+ done <$results
+}
+
+W='80.00'
+C='90.00'
+T=
+P=
+
+while getopts "hm?c:p:t:w:" opt; do
+ case $opt in
+ h|\?)
+ cleanup; exec pod2usage -verbose 1 -exit 0 $0
+ ;;
+ m)
+ cleanup; exec pod2usage -verbose 3 -exit 0 $0
+ ;;
+ c)
+ C="$OPTARG"
+ ;;
+ p)
+ P="$P $OPTARG"
+ ;;
+ t)
+ T=$T $OPTARG
+ ;;
+ w)
+ W=$OPTARG
+ ;;
+ esac
+done
+shift $((OPTIND-1))
+
+lvs --noheadings -S 'segtype=thin||segtype=thin-pool' -o vg_name,lv_name,data_percent $T $P >$lvsresults; parse_lvs $lvsresults
+lvs --noheadings -S 'segtype=thin-pool' -o vg_name,lv_name,metadata_percent $P >$lvsresults; parse_lvs $lvsresults '(meta)'
+
+[ $E = '3' ] && E=0
+exit $E
+
+: <<EOP
+
+=encoding utf8
+
+=pod
+
+=head1 NAME
+
+check_lvmthin - check usage of thin provisioned logical volumes (lvm)
+
+=head1 SYNOPSIS
+
+check_lvmthin [-t volume] [-p volume]
+
+check_lvmthin -h|-?|-m
+
+=head1 DESCRIPTION
+
+This script checks the usage of thin provisioned logical volumes.
+
+=head1 OPTIONS
+
+=over
+
+=item B<-h|-?>
+
+Display help.
+
+=item B<-m>
+
+Display man page.
+
+=item B<-c> I<threshold>
+
+Exit with status 'CRITICAL' if any checked volume uses more than I<threshold> percent of its size.
+
+=item B<-t> I<thinlv>
+
+check usage of thin provisioned logical volume I<thinlv>.
+
+=item B<-p> I<poollv>
+
+check data and metadata usage of pool volume I<poollv>.
+
+=item B<-w> I<threshold>
+
+Exit with status 'WARNING' if any checked volume uses more than I<threshold> percent of its size.
+
+=back
+
+I<thinlv> and I<poollv> should be given as names understood by lvs. thresholds should be given in decimal notation with 2 positions after the decimal point.
+
+=head1 EXAMPLE
+
+check_lvmthin -w 76.54 -t vg/lv
+
+=head1 AUTHOR
+
+Matthias Förste <foerste@schlittermann.de>
+
+=cut
+
+EOP