-
Notifications
You must be signed in to change notification settings - Fork 1
/
check_linux_cpu
executable file
·68 lines (58 loc) · 1.08 KB
/
check_linux_cpu
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
Syntaxe()
{
echo " "
echo " Command Syntaxe: check_linux_cpu [-H host] [-c val] [-w val] "
echo " "
exit 3;
}
if [[ $# -ne 6 ]]
then
Syntaxe
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
Syntaxe
exit;;
*) shift;;
esac
done
command="vmstat 1 3 | awk '{ print \$13\" \"\$14\" \"\$15\" \"\$16\" \"\$17 }' | tail -1"
output=$(ssh nagios@$host "$command")
if [[ -z $output ]]
then
echo "SSH Error"
exit 3
fi
us=$(echo $output | cut -d " " -f1 )
sy=$(echo $output | cut -d " " -f2 )
id=$(echo $output | cut -d " " -f3 )
wa=$(echo $output | cut -d " " -f4 )
pc=$(echo $output | cut -d " " -f5 )
total=$(expr $us + $sy + $wa)
exitCode=0
status="OK"
if (( $total > $valw ))
then
exitCode=1
status="WARNING"
fi
if (( $total > $valc ))
then
exitCode=2
status="CRITCAL"
fi
echo "CPU $status : Total usage $total% | total=$total%;$valw;$valc user=$us% system=$sy% iowait=$wa% idle=$id%"
exit $exitCode