forked from throwsb/nagios-checks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_memory-isilon.pl
executable file
·131 lines (107 loc) · 3.33 KB
/
check_memory-isilon.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/usr/bin/perl
###################
# check script to monitor memory usage on an EMC Isilon node.
#
# 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 = 90;
$WARNING = 80;
$SWALK = "/usr/bin/snmpwalk -Oq -v2c";
$LINUXOIDMemTot = ".1.3.6.1.4.1.2021.4.5";
$LINUXOIDMemAvail = ".1.3.6.1.4.1.2021.4.6";
$LINUXOIDMemCache = ".1.3.6.1.4.1.2021.4.15";
$MemTot = "0";
$MemAvail = "0";
$MemCache = "0";
$MemFree = "0";
$MemUsed = "100"; ##Setting used to 100% for default value##
$SNMPCOM = "";
$HOST = "";
$tmp = "";
getopts('dc:w:C:h:') or Usage();
$DEBUG = $TRUE if ($opt_d);
$CRITICAL = $opt_c if ($opt_c);
$WARNING = $opt_w if ($opt_w);
$SNMPCOM = $opt_C if ($opt_C);
$HOST = $opt_h if ($opt_h);
if ($WARNING >= $CRITICAL) {
print ("\n Warning is greater than or equal to Critical: W:$WARNING C:$CRITICAL\n");
Usage();
}elsif ($SNMPCOM eq "") {
print ("\nEnter the SNMP community name:\n");
Usage();
}elsif ($HOST eq "" ) {
print ("\nEnter the Host name:\n");
Usage();
}
sub Usage {
warn <<EOF;
$MYNAME - Checks the memory usage on a EMC Isilon Node with a SNMP query.
usage: $MYNAME -c <critical value> -w <warning value> -C <SNMP Community Name> -h <host>
-c <interger>
Exit with a critical status if greater than the percent of free memory.
-w <interger>
Exit with a warning status if greater than the percent of free memory.
-C <SNMP Community name>
The snmp comunity name used by the server. e.g. public
-h <hostname>
The hostname of the server that is being queried.
EOF
print ("UNKNOWN:AVAIL: $MemAvail, CACHE:$MemCache, TOT:$MemTot FREE:$MemFree USED:$MemUsed\%\n");
exit($STATUS_UNKNWN);
}
GetSnmp ();
CalcMem ();
NagiosStatus ();
sub GetSnmp {
Debug("$SWALK -c $SNMPCOM $HOST $LINUXOIDMemTot");
($tmp,$MemTot) = split(/ /,`$SWALK -c $SNMPCOM $HOST $LINUXOIDMemTot`);
chomp($MemTot);
Debug("$SWALK -c $SNMPCOM $HOST $LINUXOIDMemCache");
($tmp,$MemCache) = split(/ /,`$SWALK -c $SNMPCOM $HOST $LINUXOIDMemCache`);
chomp($MemCache);
Debug("$SWALK -c $SNMPCOM $HOST $LINUXOIDMemFree");
($tmp,$MemAvail) = split(/ /,`$SWALK -c $SNMPCOM $HOST $LINUXOIDMemAvail`);
chomp($MemAvail);
Debug("$HOST > AVAIL:$MemAvail, CACHE:$MemCache, TOT:$MemTot, FREE:$MemFree ");
}
sub CalcMem {
##$MemFree=$MemCache+$MemAvail;
$MemFree=$MemAvail;
Debug(" ceil> ((($MemTot minus $MemFree) times 100) div by MemTot)");
$MemUsed = ceil((($MemTot - $MemFree)*100)/$MemTot);
Debug("AVAIL:$MemAvail, CACHE:$MemCache, TOT:$MemTot FREE:$MemFree USED:$MemUsed\%");
}
sub NagiosStatus {
if ($CRITICAL < $MemUsed) {
print ("CRITICAL: TOT:$MemTot AVAIL:$MemAvail CACHE:$MemCache FREE:$MemFree USED:$MemUsed\%\n");
exit($STATUS_CRIT);
}elsif ($WARNING < $MemUsed) {
print ("WARNING: TOT:$MemTot AVAIL:$MemAvail CACHE:$MemCache FREE:$MemFree USED:$MemUsed\%\n");
exit($STATUS_WARN);
}else {
print ("OK: TOT:$MemTot AVAIL:$MemAvail CACHE:$MemCache FREE:$MemFree USED:$MemUsed\%\n");
exit($STATUS_OK);
}
}
sub Debug
{
my ($msg) = @_;
warn "$msg\n" if ($DEBUG);
}