From 219ecea44e190d1720c976deb02645d4388bd772 Mon Sep 17 00:00:00 2001
From: Fulvio Galeazzi <fulvio.galeazzi@garr.it>
Date: Fri, 17 Nov 2017 00:24:14 +0100
Subject: [PATCH] 2017-11-17:  FG;  Added full and near-full thresholds.

---
 Ceph/Config/userparameter_ceph.conf |  2 ++
 Ceph/Script/cephHealth.pl           | 39 ++++++++++++++++++++++++++---
 2 files changed, 38 insertions(+), 3 deletions(-)

diff --git a/Ceph/Config/userparameter_ceph.conf b/Ceph/Config/userparameter_ceph.conf
index 9cff661..61c9e9f 100644
--- a/Ceph/Config/userparameter_ceph.conf
+++ b/Ceph/Config/userparameter_ceph.conf
@@ -11,6 +11,8 @@ UserParameter=ceph.global.slowosd[*],/etc/zabbix/scripts/cephHealth.pl $1 --slow
 UserParameter=ceph.global.slowreq[*],/etc/zabbix/scripts/cephHealth.pl $1 --slowreq
 UserParameter=ceph.osd.nearfull[*],/etc/zabbix/scripts/cephHealth.pl $1 --nearfull
 UserParameter=ceph.osd.full[*],/etc/zabbix/scripts/cephHealth.pl $1 --full
+UserParameter=ceph.osd.thrnearfull[*],/etc/zabbix/scripts/cephHealth.pl $1 --nearfullth
+UserParameter=ceph.osd.thrfull[*],/etc/zabbix/scripts/cephHealth.pl $1 --fullth
 UserParameter=ceph.osd.down[*],/etc/zabbix/scripts/cephOsdStat.pl $1 -s down
 UserParameter=ceph.osd.up[*],/etc/zabbix/scripts/cephOsdStat.pl $1 -s up
 UserParameter=ceph.osd.out[*],/etc/zabbix/scripts/cephOsdStat.pl $1 -s out
diff --git a/Ceph/Script/cephHealth.pl b/Ceph/Script/cephHealth.pl
index 73b2d34..4e1cb61 100755
--- a/Ceph/Script/cephHealth.pl
+++ b/Ceph/Script/cephHealth.pl
@@ -71,7 +71,7 @@ chomp $_sudo;
 ### Options
 our($opt_exec, $opt_become, $opt_cluster, $opt_user, $opt_keyring, $opt_monhost,
     $opt_status, $opt_slow_osd, $opt_slow_req, $opt_object_degraded, $opt_object_misplaced, 
-    $opt_fraction, $opt_full, $opt_nearfull, $opt_filter, $opt_debug, $opt_h);
+    $opt_fraction, $opt_fullth, $opt_nearfullth, $opt_full, $opt_nearfull, $opt_filter, $opt_debug, $opt_h);
 if (@ARGV > 0) {
     GetOptions("e=s"=>\$opt_exec,
                "b"  =>\$opt_become,
@@ -85,6 +85,8 @@ if (@ARGV > 0) {
                "od" =>\$opt_object_degraded,
                "om" =>\$opt_object_misplaced,
                "f"  =>\$opt_fraction,
+               "fullth" =>\$opt_fullth,
+               "nearfullth" =>\$opt_nearfullth,
                "full" =>\$opt_full,
                "nearfull" =>\$opt_nearfull,
                "s=s"=>\$opt_filter,
@@ -150,14 +152,45 @@ my $doOsdNearFull = 0;
 if (defined $opt_nearfull) {
     $doOsdNearFull = 1;
 }
+my $doOsdFullth = 0;
+if (defined $opt_fullth) {
+    $doOsdFullth = 1;
+}
+my $doOsdNearFullth = 0;
+if (defined $opt_nearfullth) {
+    $doOsdNearFullth = 1;
+}
 my @matchStr = ();
 if (defined $opt_filter) {
     @matchStr = split(/,/,$opt_filter);
 }
 #
-my $sumDo = $doStatus + $doSlowOsd + $doSlowReq + $doObjectDeg + $doObjectMis + $doOsdFull + $doOsdNearFull;
+my $sumDo = $doStatus + $doSlowOsd + $doSlowReq + $doObjectDeg + $doObjectMis + $doOsdFull + $doOsdNearFull + $doOsdFullth + $doOsdNearFullth;
 if ($sumDo > 1) {
-    fail_usage "Either status or slow_requests/osds or objectsDeg/objectsMis or OSD_full/OSD_nearfull.";
+    fail_usage "Either status or slow_requests/osds or objectsDeg/objectsMis or OSD_full/OSD_nearfull or OSD_fullTh/OSD_nearfullTh.";
+}
+
+# Fetch the "pg dump" data and put it in an array
+if ($doOsdFullth + $doOsdNearFullth) {
+    my @_pgdata = `$cephCmd pg dump 2> /dev/null`;
+    chomp @_pgdata;
+    foreach my $_pgline (@_pgdata) {
+	if ($doOsdFullth) {
+	    if ($_pgline =~ m/^full\S+\s+([-+]?[0-9]*\.?[0-9]+)/) {
+		print $1."\n";
+		exit 0;
+	    }
+	} elsif ($doOsdNearFullth) {
+	    if ($_pgline =~ m/^nearfull\S+\s+([-+]?[0-9]*\.?[0-9]+)/) {
+		print $1."\n";
+		exit 0;
+	    }
+	}
+	if ($_pgline =~ m/^\d+/) {
+	    print "-1"."\n";
+	    exit 0;
+	}
+    }
 }
 
 # Fetch the data and put it in an array
-- 
GitLab