-
Notifications
You must be signed in to change notification settings - Fork 1
/
check_solaris_mem
executable file
·72 lines (62 loc) · 1.07 KB
/
check_solaris_mem
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
72
#!/bin/bash
Syntax() {
echo " "
echo " Command Syntax: check_solaris_mem [-H host] [-c val] [-w val]"
echo " "
exit 3
}
if [[ $# == 0 ]]; 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
output=$(ssh nagios@$host "/usr/bin/vmstat 1 3 | /usr/bin/tail -1")
if [[ -z $output ]]; then
echo "SSH Error"
exit 3
fi
freeMemory=$(echo "$output" | awk '{print ($5 / 1024)}' | cut -d'.' -f 1)
output=$(ssh nagios@$host "/usr/sbin/prtconf")
if [[ -z $output ]]; then
echo "SSH Error"
exit 3
fi
totalMemory=$(echo "$output" | grep "Memory size:" | awk '{print ($3)}')
usedMemory=$(echo "scale=2; 100 - (($freeMemory / $totalMemory) * 100)" | bc -l)
ok=0
status="OK"
if (($(echo "$usedMemory > $valw" | bc -l))); then
ok=1
status="WARNING"
fi
if (($(echo "$usedMemory > $valc" | bc -l))); then
ok=2
status="CRITICAL"
fi
echo "MEMORY $status :: MemUsed = $usedMemory% | MemUsed=$usedMemory%;$valw;$valc"
exit $ok