summaryrefslogtreecommitdiffstats
path: root/contrib/check_disk_snmp.pl
blob: 96862e1c323edaad5bc89a9742c99368448101a5 (plain)
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
#!/usr/bin/perl
# cm@financial.com 07/2002
use strict;
use Net::SNMP;

if ($#ARGV ne 3) {
	print "Worng number of Arguments\n";
	exit 1;
}


my ($host, $device, $warnpercent, $errpercent) = @ARGV;
if ($warnpercent >= $errpercent) {
	print "Errorratio must be higher then Warnratio!\n";
	exit 1;
}

my ($session, $error) = Net::SNMP->session(
	-hostname	=>	$host,
	-nonblocking	=>	0x0,
	-username	=>	'XXXXX',
	-authpassword	=>	'XXXXXXXX',
	-authprotocol	=>	'md5',
	-version	=>	'3',
	);

if ($@) {
	print "SNMP-Error occured";
	exit 1;
}
my $result=undef;


my $deviceSize=".1.3.6.1.2.1.25.2.3.1.5.$device";
my $deviceUsed=".1.3.6.1.2.1.25.2.3.1.6.$device";
#my $deviceName=".1.3.6.1.2.1.25.3.7.1.2.1536.$device";
my $deviceName=".1.3.6.1.2.1.25.2.3.1.3.$device";
my @OID=($deviceSize, $deviceUsed, $deviceName);
$result = $session->get_request(
	-varbindlist => \@OID,
	);

if (!defined($result)) {
	printf("ERROR: %s.\n", $session->error);
	$session->close;
	exit 1;
}

my $ratio=$result->{$deviceUsed}*100/$result->{$deviceSize};

if ($ratio > $errpercent){
	printf("CRITICAL: %s usage %.2f%%\n", $result->{$deviceName}, $ratio);
	exit 2;
}
if ($ratio > $warnpercent){
	printf("WARNING: %s usage %.2f%%\n", $result->{$deviceName}, $ratio);
        exit 1;
}

printf("OK: %s usage %.2f%%\n", $result->{$deviceName}, $ratio);
exit 0;