-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcheck_all_open_files.sh
executable file
·71 lines (64 loc) · 1.71 KB
/
check_all_open_files.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/bash
#
# Inspired by: http://pissedoffadmins.com/nagios/nagios-tomcat-open-files-check.html
#
# Author: Gregor Binder
# Mail: [email protected]
# https://github.com/wefixit-AT/nagios_check_all_open_files
# Adapted for BGHW by Johannes Starosta <[email protected]>
# Bash strict mode, to make debugging easier see http://redsymbol.net/articles/unofficial-bash-strict-mode/
set -euo pipefail
IFS=$'\n\t'
SUDO=$(which sudo)
LSOF=$(which lsof)
PGREP=$(which pgrep)
WC=$(which wc)
PROGRAM=""
ERROR_CODE=-1
set +u
if [ -z "$1" ] || [ -z "$2" ] || [ "$2" -lt "$1" ] ; then
echo "Usage: $0 warning critical program"
echo " warning: int"
echo " critical: int and >= warning"
echo " program: Optional String with name of program"
echo "IMPORTANT: sudo must set without password asking to allow lsof"
exit $ERROR_CODE
else
WARNING=$1
CRITICAL=$2
fi
if [ ! -z "$3" ];then
PROGRAM="$3"
fi
set -u
function checkExitStatus {
if [ "$1" -ne 0 ]; then
echo "!!! command failure !!! $2"
exit -1
fi
}
if [ -z "$PROGRAM" ];then
LSOF=$("$SUDO" "$LSOF" | "$WC" -l)
else
PGREP=$("$PGREP" --full "$3")
summe=0
for i in $PGREP
do
tmp=$("$SUDO" "$LSOF" -p "$i" | "$WC" -l)
summe=$((summe + tmp))
done
LSOF=$summe
fi
if [ "$LSOF" -lt "$WARNING" ]; then
echo "OK $LSOF files open|files=$LSOF;$WARNING;$CRITICAL;0"
ERROR_CODE=0
else
if [ "$LSOF" -ge "$WARNING" ] && [ "$LSOF" -le "$CRITICAL" ]; then
echo "WARN $LSOF files open|files=$LSOF;$WARNING;$CRITICAL;0"
ERROR_CODE=1
elif [ "$LSOF" -ge "$CRITICAL" ]; then
echo "CRIT $LSOF files open|files=$LSOF;$WARNING;$CRITICAL;0"
ERROR_CODE=2
fi
fi
exit $ERROR_CODE