summaryrefslogtreecommitdiffstats
path: root/web/attachments/158752-patch-check_disk_snmp.pl-snmpv1-2-win
diff options
context:
space:
mode:
Diffstat (limited to 'web/attachments/158752-patch-check_disk_snmp.pl-snmpv1-2-win')
-rw-r--r--web/attachments/158752-patch-check_disk_snmp.pl-snmpv1-2-win299
1 files changed, 299 insertions, 0 deletions
diff --git a/web/attachments/158752-patch-check_disk_snmp.pl-snmpv1-2-win b/web/attachments/158752-patch-check_disk_snmp.pl-snmpv1-2-win
new file mode 100644
index 0000000..7db3a88
--- /dev/null
+++ b/web/attachments/158752-patch-check_disk_snmp.pl-snmpv1-2-win
@@ -0,0 +1,299 @@
1--- check_disk_snmp.pl.org 2005-12-05 15:06:35.815047753 -0500
2+++ check_disk_snmp.pl 2005-12-05 15:17:23.142768392 -0500
3@@ -1,74 +1,257 @@
4 #!/usr/bin/perl
5-# cm@financial.com 07/2002
6+# ----------------------------------------------------------------------------
7+# Name: check_disk_snmp.pl
8+# Version: 1.1
9+# Description: This script will check the disk space usage using SNMP for
10+# both Unix and Windows hosts. The warning and critical values
11+# can be specified using ratios (default) or free bytes.
12+# ----------------------------------------------------------------------------
13+# ChangeLog:
14+#
15+# July, 2002: cm@financial.com
16+# -Original release
17+#
18+# Oct 14, 2005: Alex Burger <alex_b@users.sourceforge.net>
19+# - Added support for SNMP version 1 and 2
20+# - Added support for checking free bytes instead of only usage ratio
21+# - Added support for selecting a device by specifying a substring of the
22+# device description such as c:, d: etc.
23+# - Added support for hostname:port
24+# ----------------------------------------------------------------------------
25+# This program is free software; you can redistribute it and/or modify
26+# it under the terms of the GNU General Public License as published by
27+# the Free Software Foundation; either version 2 of the License, or
28+# (at your option) any later version.
29+#
30+# This program is distributed in the hope that it will be useful,
31+# but WITHOUT ANY WARRANTY; without even the implied warranty of
32+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33+# GNU General Public License for more details.
34+#
35+# You should have received a copy of the GNU General Public License
36+# along with this program; if not, write to the Free Software
37+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
38+# ----------------------------------------------------------------------------
39 use strict;
40 use Net::SNMP;
41 use Getopt::Std;
42+my ($warn_bytes, $critical_bytes);
43
44 my %opts =(
45- u => 'nobody', # snmp user
46- l => 'authNoPriv', # snmp security level
47- a => 'MD5', # snmp authentication protocol
48- A => 'nopass', # authentication protocol pass phrase.
49- x => 'DES', # privacy protocol
50+ u => 'nobody', # snmp user (v3) or snmp community string (v1/2c)
51+ l => 'authNoPriv', # snmp security level (v3)
52+ a => 'MD5', # snmp authentication protocol (v3)
53+ A => 'nopass', # authentication protocol pass phrase. (v3)
54+ x => 'DES', # privacy protocol (v3)
55 m => 'localhost', # host
56- d => 1, # devicenumber
57- w => 70, # warnratio
58- c => 85, # critical ratio
59+ d => 1, # devicenumber
60+ w => 70, # usage warnratio or bytes free
61+ c => 85, # usage critical ratio or bytes free
62+ v => 3,
63+ t => 'ratio', # ratio or bytes
64 h => 0,
65- );
66+ );
67
68-getopts('m:u:l:a:A:x:d:w:c:h',\%opts);
69+getopts('m:u:l:a:A:x:d:w:c:v:t:h',\%opts);
70
71 if ( $opts{'h'} ) {
72- print "Usage: $0 [ -u <username> ] [ -l <snmp security level>] [ -a <snmp authentication protocol> ] [ -A <authentication protocol pass phrase> ] [ -x <snmp privacy protocol> ] [ -m <hostname>] [ -d <devicenumber> ] [ -w <warning ratio> ] [ -c <critical ratio ]\n";
73+ print "Usage: $0 [ -v <snmp version (3)> ]\n";
74+ print " [ -u <username or community name> ] [ -l <snmp security level>]\n";
75+ print " [ -a <snmp authentication protocol> ]\n";
76+ print " [ -A <authentication protocol pass phrase> ]\n";
77+ print " [ -x <snmp privacy protocol> ] [ -m <hostname>]\n";
78+ print " [ -d <devicenumber or description> ] [ -w <warning ratio or bytes free> ]\n";
79+ print " [ -c <critical ratio or bytes free> ] [ -t <(ratio)|bytes> ]\n\n";
80+ print "SNMP V3 example using ratio for device number 2:\n";
81+ print "$0 -u nobody -l authPriv -a MD5 -A nopass -x DES \\\n";
82+ print " -m server1 -d 2 -w 70 -c 85\n\n";
83+ print "SNMP V1 example using ratio for device number 2:\n";
84+ print "$0 -v 1 -u public -m server1 -d 2 -w 70 -c 85\n\n";
85+ print "SNMP V1 example using bytes for device number 2\n";
86+ print "$0 -v 1 -u public -m server1 -d 2 -w 10Gb -c 900Mb \\\n";
87+ print " -t bytes\n\n";
88+ print "SNMP V1 example using bytes free for device description that contains 'c:'\n";
89+ print "$0 -v 1 -u public -m server1 -d 'c:' -w 10Gb -c 900Mb \\\n";
90+ print " -t bytes\n\n";
91+ print "Note: The device list can be retreived using Net-SNMP's snmpwalk:\n";
92+ print " snmpwalk -v 1 -c public server01 .1.3.6.1.2.1.25.2.3.1\n\n";
93 exit 1;
94 }
95
96-if ($opts{'w'} >= $opts{'c'}) {
97- print "Errorratio must be higher then Warnratio!\n";
98- exit 1;
99+if ($opts{'t'} eq "ratio") {
100+ if ($opts{'w'} >= $opts{'c'}) {
101+ print "Errorratio must be higher then Warnratio!\n";
102+ exit 3;
103+ }
104+}
105+else {
106+ # For 'bytes' mode, allow user to specify size using k, M, G or T
107+ ($warn_bytes, $critical_bytes) = ($opts{'w'}, $opts{'c'});
108+
109+ if ($warn_bytes =~ /(.*)T/i) {
110+ $warn_bytes = $1 * 1099511627776; # 1024 * 1024 * 1024 * 1024
111+ }
112+ elsif ($warn_bytes =~ /(.*)G.*/i) {
113+ $warn_bytes = $1 * 1073741824; # 1024 * 1024 * 1024
114+ }
115+ elsif ($warn_bytes =~ /(.*)M.*/i) {
116+ $warn_bytes = $1 * 1048576; # 1024 * 1024
117+ }
118+ elsif ($warn_bytes =~ /(.*)k.*/i) {
119+ $warn_bytes = $1 * 1024;
120+ }
121+
122+ if ($critical_bytes =~ /(.*)T/i) {
123+ $critical_bytes = $1 * 1099511627776; # 1024 * 1024 * 1024 * 1024
124+ }
125+ elsif ($critical_bytes =~ /(.*)G.*/i) {
126+ $critical_bytes = $1 * 1073741824; # 1024 * 1024 * 1024
127+ }
128+ elsif ($critical_bytes =~ /(.*)M.*/i) {
129+ $critical_bytes = $1 * 1048576; # 1024 * 1024
130+ }
131+ elsif ($critical_bytes =~ /(.*)k.*/i) {
132+ $critical_bytes = $1 * 1024;
133+ }
134+
135+ if ($warn_bytes <= $critical_bytes) {
136+ print "Critical bytes free must be lower then Warning bytes free!\n";
137+ exit 3;
138+ }
139 }
140
141-my ($session, $error) = Net::SNMP->session(
142- -hostname => $opts{'m'},
143- -nonblocking => 0x0,
144- -username => $opts{'u'},
145- -authpassword => $opts{'A'},
146- -authprotocol => $opts{'a'},
147- -version => '3',
148- );
149+# Allow hostname:port for -m
150+my $hostname = $opts{'m'};
151+my $port = 161; # Default to port 161
152+if ($hostname =~ /(.*):(.*)/) {
153+ $hostname = $1;
154+ $port = $2;
155+}
156+
157+my $session;
158+my $error;
159+if ($opts{'v'} == 3) {
160+ ($session, $error) = Net::SNMP->session(
161+ -hostname => $hostname,
162+ -port => $port,
163+ -nonblocking => 0x0,
164+ -username => $opts{'u'},
165+ -authpassword => $opts{'A'},
166+ -authprotocol => $opts{'a'},
167+ -version => '3',
168+ );
169+}
170+else {
171+ ($session, $error) = Net::SNMP->session(
172+ -hostname => $hostname,
173+ -port => $port,
174+ -nonblocking => 0x0,
175+ -community => $opts{'u'},
176+ -version => $opts{'v'},
177+ );
178+}
179
180 if ($@) {
181 print "SNMP-Error occured";
182- exit 1;
183+ exit 3;
184 }
185 my $result=undef;
186
187+my $device_id = $opts{'d'};
188+
189+if ($device_id =~ /^(\D+)$/) {
190+ # Non numeric device. Search for matching description in all drives.
191+ # If we don't find it, set device number to 999.
192+ #print "non numeric device: $1\n\n";
193+
194+ my $i=1;
195+ $device_id = 999;
196+ while (1) {
197+ my $deviceName=".1.3.6.1.2.1.25.2.3.1.3.$i"; # HOST-RESOURCES-MIB::hrStorageDescr
198+
199+ my $result = $session->get_request(
200+ -varbindlist => [$deviceName]
201+ );
202+
203+ if (!defined($result)) {
204+ $session->close;
205+ last;
206+ }
207+
208+ if ($result->{$deviceName} =~ /$opts{'d'}/i) {
209+ #print "Found matching device: $result->{$deviceName}\n";
210+ $device_id = $i;
211+ last;
212+ }
213+ $i++;
214+ }
215+}
216
217-my $deviceSize=".1.3.6.1.2.1.25.2.3.1.5.$opts{'d'}";
218-my $deviceUsed=".1.3.6.1.2.1.25.2.3.1.6.$opts{'d'}";
219-my $deviceName=".1.3.6.1.2.1.25.2.3.1.3.$opts{'d'}";
220-my @OID=($deviceSize, $deviceUsed, $deviceName);
221-$result = $session->get_request(
222+my $deviceUnits=".1.3.6.1.2.1.25.2.3.1.4.$device_id"; # HOST-RESOURCES-MIB::hrStorageAllocationUnits
223+my $deviceSize=".1.3.6.1.2.1.25.2.3.1.5.$device_id"; # HOST-RESOURCES-MIB::hrStorageSize
224+my $deviceUsed=".1.3.6.1.2.1.25.2.3.1.6.$device_id"; # HOST-RESOURCES-MIB::hrStorageUsed
225+my $deviceName=".1.3.6.1.2.1.25.2.3.1.3.$device_id"; # HOST-RESOURCES-MIB::hrStorageDescr
226+my @OID=($deviceUnits, $deviceSize, $deviceUsed, $deviceName);
227+my $result = $session->get_request(
228 -varbindlist => \@OID,
229 );
230
231 if (!defined($result)) {
232 printf("ERROR: %s.\n", $session->error);
233 $session->close;
234- exit 1;
235+ exit 3;
236 }
237
238-my $ratio=$result->{$deviceUsed}*100/$result->{$deviceSize};
239+if ($opts{'t'} eq "ratio") {
240+ my $ratio=$result->{$deviceUsed}*100/$result->{$deviceSize};
241
242-if ($ratio > $opts{'c'}){
243- printf("CRITICAL: %s usage %.2f%%\n", $result->{$deviceName}, $ratio);
244- exit 2;
245+ if ($ratio > $opts{'c'}){
246+ printf("CRITICAL: %s usage %.2f%%\n", $result->{$deviceName}, $ratio);
247+ exit 2;
248+ }
249+ if ($ratio > $opts{'w'}){
250+ printf("WARNING: %s usage %.2f%%\n", $result->{$deviceName}, $ratio);
251+ exit 1;
252+ }
253+
254+ printf("OK: %s usage %.2f%%\n", $result->{$deviceName}, $ratio);
255+ exit 0;
256 }
257-if ($ratio > $opts{'w'}){
258- printf("WARNING: %s usage %.2f%%\n", $result->{$deviceName}, $ratio);
259- exit 1;
260+else {
261+ #print "Bytes...\n";
262+ # Calculate actual size in bytes
263+ my $b_deviceSize = $result->{$deviceSize} * $result->{$deviceUnits};
264+ my $b_deviceUsed = $result->{$deviceUsed} * $result->{$deviceUnits};
265+ my $b_free = $b_deviceSize - $b_deviceUsed;
266+ my $b_free_units;
267+
268+ if ($b_free > 1099511627776) {
269+ $b_free_units = (int ($b_free / 1099511627776 * 100) / 100);
270+ $b_free_units .= "Tb";
271+ }
272+ elsif ($b_free > 1073741824) {
273+ $b_free_units = (int ($b_free / 1073741824 * 100) / 100);
274+ $b_free_units .= "Gb";
275+ }
276+ elsif ($b_free > 1048576) {
277+ $b_free_units = (int ($b_free / 1048576 * 100) / 100);
278+ $b_free_units .= "Mb";
279+ }
280+ elsif ($b_free > 1024) {
281+ $b_free_units = (int ($b_free / 1024 * 100) / 100);
282+ $b_free_units .= "kb";
283+ }
284+
285+ if ($b_free < $critical_bytes){
286+ printf("CRITICAL: %s free: %s\n", $result->{$deviceName}, $b_free_units);
287+ exit 2;
288+ }
289+ if ($b_free < $warn_bytes){
290+ printf("WARNING: %s free: %s\n", $result->{$deviceName}, $b_free_units);
291+ exit 1;
292+ }
293+
294+ printf("OK: %s free: %s\n", $result->{$deviceName}, $b_free_units);
295+ exit 0;
296 }
297
298-printf("OK: %s usage %.2f%%\n", $result->{$deviceName}, $ratio);
299-exit 0;