Dzahn has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/373135 )

Change subject: icinga: add plugin to check for long running screens
......................................................................

icinga: add plugin to check for long running screens

Bug: T165348
Change-Id: Ic72511092b685fd758f2c0f6d7410a715eed9ecc
---
A modules/icinga/files/check_long_screens
1 file changed, 64 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/operations/puppet 
refs/changes/35/373135/1

diff --git a/modules/icinga/files/check_long_screens 
b/modules/icinga/files/check_long_screens
new file mode 100755
index 0000000..df821ad
--- /dev/null
+++ b/modules/icinga/files/check_long_screens
@@ -0,0 +1,64 @@
+#!/bin/bash
+# icinga/nagios plugin to detect long-running screen sessions
+#
+# https://phabricator.wikimedia.org/T165348
+#
+# Daniel Zahn (<dz...@wikimedia.org>) - Wikimedia Foundation Inc.
+#
+
+set -eu
+usage() { echo "Usage: $0 -w <warn> -c <crit>" 1>&2; exit 1; }
+
+declare -i WARN_TIME="60"
+declare -i CRIT_TIME="120"
+
+DEBUG=false
+
+while getopts "w:c:" o; do
+    case "${o}" in
+    w)
+       WARN_TIME=${OPTARG}
+       ;;
+    c)
+       CRIT_TIME=${OPTARG}
+       ;;
+    *)
+       usage
+       ;;
+    esac
+done
+
+if [ $WARN_TIME == 0 ] || [ $CRIT_TIME == 0 ]; then
+    usage
+fi
+
+SCREEN_PID=""
+RUN_TIME=0
+PGREP=$(which pgrep)
+PS=$(which ps)
+XARGS=$(which xargs)
+
+for SCREEN_PID in $(${PGREP} -f SCREEN)
+  do
+     RUN_TIME=$(${PS} -o etimes= -p ${SCREEN_PID} | ${XARGS})
+     if $DEBUG; then
+         echo "Found a screen with PID ${SCREEN_PID}. It's been running since 
${RUN_TIME} seconds."
+     fi
+     if [ $RUN_TIME -gt $CRIT_TIME ]; then
+         echo "CRIT: Long running screen session. (PID ${SCREEN_PID}, 
${RUN_TIME}s > ${CRIT_TIME}s)"
+         exit 2
+     fi
+     if [ $RUN_TIME -gt $WARN_TIME ]; then
+         echo "WARN: Long running screen session. (PID ${SCREEN_PID}, 
${RUN_TIME}s > ${WARN_TIME}s)"
+         exit 1
+     fi
+     if [ $RUN_TIME -le $WARN_TIME ] && [ $RUN_TIME -le $CRIT_TIME ] ; then
+         echo "OK: No long running screen sessions detected."
+         exit 0
+     fi
+done
+
+echo "UNKNOWN: something went wrong with the plugin. check $0"
+exit 3
+
+

-- 
To view, visit https://gerrit.wikimedia.org/r/373135
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic72511092b685fd758f2c0f6d7410a715eed9ecc
Gerrit-PatchSet: 1
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: Dzahn <dz...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to