-
Notifications
You must be signed in to change notification settings - Fork 1
/
check_linux_openFiles
69 lines (57 loc) · 1.07 KB
/
check_linux_openFiles
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
#!/bin/bash
Syntax()
{
echo " "
echo " Command Syntax: check_linux_openFiles [-H host] [-c val] [-w val]"
echo " "
exit 3;
}
if [[ $# -ne 6 ]]
then
Syntax
fi
valw=0
valc=0
host=""
while [[ $# > 0 ]]
do
par=$1
case $par in
-c) shift
valc=$1;;
-w) shift
valw=$1;;
-H) shift
host=$1;;
-h) shift
Syntax
exit;;
*) shift;;
esac
done
maxHandles=$(ssh nagios@$host "cat /proc/sys/fs/file-max")
if [[ -z $maxHandles ]]
then
echo "SSH Error"
exit 3
fi
usedHandles=$(ssh nagios@$host "cat /proc/sys/fs/file-nr | cut -d$'\t' -f 1")
if [[ -z $usedHandles ]]
then
echo "SSH Error"
exit 3
fi
percentageUsed=$(echo "$usedHandles $maxHandles" | awk '{printf "%.2f", (($1 / $2) * 100)}')
exitCode=0
status="OK"
if (( $(echo "$percentageUsed > $valw" | bc -l) ))
then
exitCode=1
status="WARNING"
fi
if (( $(echo "$percentageUsed > $valc" | bc -l) ))
then
exitCode=2
status="CRITICAL"
fi
echo "OpenFiles $status :: Percentage of file handles used: $percentageUsed% | OpenFiles=$percentageUsed%"