forked from throwsb/nagios-checks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_cpu-hpux.pl
executable file
·88 lines (70 loc) · 1.97 KB
/
check_cpu-hpux.pl
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/perl
###################
# check script to monitor CPU usage on a HP-UX server.
#
# The script is maintained at https://github.com/throwsb/nagios-checks/
#
# Licensed under GNU GPLv3 - see the LICENSE file in the git repository.
#
###################
use POSIX;
use Getopt::Std;
use Sys::Hostname;
$TRUE = 1;
$FALSE = 0;
$STATUS_OK=0;
$STATUS_WARN=1;
$STATUS_CRIT=2;
$STATUS_UNKNWN=3;
($MYNAME = $0) =~ s/.*\///;
($HOST) = split /\./, hostname();
$DEBUG=$FALSE;
$STATUS = "UNKNOWN";
$CRITICAL = 15;
$WARNING = 20;
$SAR = "/usr/bin/sar 1 5";
getopts('dc:w:') or Usage();
$DEBUG = $TRUE if ($opt_d);
$CRITICAL = $opt_c if ($opt_c);
$WARNING = $opt_w if ($opt_w);
if ($WARNING <= $CRITICAL) {
Usage();
}
sub Usage {
warn <<EOF;
$MYNAME - Checks the CPU usage on a HP-UX.
usage: $MYNAME -c <critical value> -w <warning value>
-c <interger>
Exit with a critical status if greater than the total CPU idle. The
critical value can not be higher than the warning status.
-w <interger>
Exit with a warning status if greater than the total CPU idle. The
warning value can not be lower than the critical value.
EOF
print ("UNKOWN: CPU $AVG: \%USER:$USR \%SYSTEM:$SYS \%IOWAIT:$WIO \%IDLE:$IDL\n");
exit($STATUS_UNKNWN);
}
foreach (`$SAR`) {
($AVG,$USR,$SYS,$WIO,$IDL) = split(/\s+/,$_);
Debug("av > $AVG, usr > $USR,sys > $SYS,io > $WIO,idle > $IDL");
}
if ($AVG ne "Average") {
print ("UNKOWN: CPU $AVG: \%USER:$USR \%SYSTEM:$SYS \%IOWAIT:$WIO \%IDLE:$IDL\n");
exit($STATUS_UNKNWN);
} else {
if ($CRITICAL > $IDL) {
print ("CRITICAL: CPU $AVG: \%USER:$USR \%SYSTEM:$SYS \%IOWAIT:$WIO \%IDLE:$IDL\n");
exit($STATUS_CRIT);
}elsif ($WARNING > $IDL) {
print ("WARNING: CPU $AVG: \%USER:$USR \%SYSTEM:$SYS \%IOWAIT:$WIO \%IDLE:$IDL\n");
exit($STATUS_WARN);
}else {
print ("OK: CPU $AVG: \%USER:$USR \%SYSTEM:$SYS \%IOWAIT:$WIO \%IDLE:$IDL\n");
exit($STATUS_OK);
}
}
sub Debug
{
my ($msg) = @_;
warn "$msg\n" if ($DEBUG);
}