aboutsummaryrefslogtreecommitdiff
path: root/modules/pkgs/check_mdstat
diff options
context:
space:
mode:
authorIgor Pashev <pashev.igor@gmail.com>2016-09-29 13:51:44 +0300
committerIgor Pashev <pashev.igor@gmail.com>2016-09-29 13:51:44 +0300
commit62f28d30a069135f9c48678507203958adfc334f (patch)
tree7f38af0c8d3f445ee8cc50906a639baec7011127 /modules/pkgs/check_mdstat
parent1af9e6589bdd18e6ba7eeabf073aa7d710020cdd (diff)
downloadnixsap-62f28d30a069135f9c48678507203958adfc334f.tar.gz
Moved everything into ./modules
Diffstat (limited to 'modules/pkgs/check_mdstat')
-rwxr-xr-xmodules/pkgs/check_mdstat/check_mdstat50
-rw-r--r--modules/pkgs/check_mdstat/default.nix26
2 files changed, 76 insertions, 0 deletions
diff --git a/modules/pkgs/check_mdstat/check_mdstat b/modules/pkgs/check_mdstat/check_mdstat
new file mode 100755
index 0000000..32fc168
--- /dev/null
+++ b/modules/pkgs/check_mdstat/check_mdstat
@@ -0,0 +1,50 @@
+#!/usr/bin/env bash
+
+stat=/proc/mdstat
+
+if [ ! -e "$stat" ]; then
+ echo "WARNING: $stat does not exist"
+ exit 1
+fi
+
+if [ ! -r "$stat" ]; then
+ echo "WARNING: cannot read $stat"
+ exit 1
+fi
+
+count=$(grep ^md -c "$stat")
+
+if [ "$count" -eq 0 ]; then
+ echo 'WARNING: no arrays found.'
+ exit 1
+elif [ "$count" -eq 1 ]; then
+ out="Linux Software RAID: $count array"
+else
+ out="Linux Software RAID: $count arrays"
+fi
+
+degrated=$(grep -c '\[.*_.*\]' "$stat")
+recovering=$(awk '/recovery/ {print $4}' "$stat")
+resyncing=$(awk '/resync/ {print $4}' "$stat")
+
+if [ -n "$recovering" ]; then
+ out="$out, recovering: $recovering"
+elif [ -n "$resyncing" ]; then
+ out="$out, resyncing: $resyncing"
+elif [ "$degrated" -gt 0 ]; then
+ out="$out, degrated: $degrated"
+fi
+
+if [ "$degrated" -gt 0 ]; then
+ echo "CRITICAL: $out."
+ exit 2
+fi
+
+if [ -n "$recovering$resyncing" ]; then
+ echo "WARNING: $out."
+ exit 1
+fi
+
+echo "OK: $out."
+exit 0
+
diff --git a/modules/pkgs/check_mdstat/default.nix b/modules/pkgs/check_mdstat/default.nix
new file mode 100644
index 0000000..5e645fd
--- /dev/null
+++ b/modules/pkgs/check_mdstat/default.nix
@@ -0,0 +1,26 @@
+{ stdenv, gawk, gnugrep }:
+
+stdenv.mkDerivation {
+ name = "check_mdstat";
+ src = ./check_mdstat;
+ outputs = [ "out" "conf" ];
+ unpackPhase = ":";
+ installPhase = ''
+ mkdir -p $out/bin
+
+ cp "$src" $out/bin/check_mdstat
+
+ substituteInPlace "$out/bin/"* \
+ --replace awk '${gawk}/bin/awk' \
+ --replace grep '${gnugrep}/bin/grep'
+
+ chmod +x "$out/bin/"*
+
+ cat <<CONF > $conf
+ object CheckCommand "mdstat" {
+ import "plugin-check-command"
+ command = [ "$out/bin/check_mdstat" ]
+ }
+ CONF
+ '';
+}