diff options
author | Ethan Galstad <egalstad@users.sourceforge.net> | 2002-08-12 23:09:48 +0000 |
---|---|---|
committer | Ethan Galstad <egalstad@users.sourceforge.net> | 2002-08-12 23:09:48 +0000 |
commit | 827e17f4547aede83f98cabe9e9f0bd5fa30d0e5 (patch) | |
tree | 8c7a830310a77bf2084dffaf9cdcb5166f1c7e95 /contrib | |
parent | cf34ddfdeb9235440b847548a321b49eb6bb94f3 (diff) | |
download | monitoring-plugins-827e17f4547aede83f98cabe9e9f0bd5fa30d0e5.tar.gz |
Updated to use getopt (Christoph Maser)
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@69 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'contrib')
-rw-r--r-- | contrib/check_disk_snmp.pl | 44 |
1 files changed, 28 insertions, 16 deletions
diff --git a/contrib/check_disk_snmp.pl b/contrib/check_disk_snmp.pl index 96862e1c..a09343dc 100644 --- a/contrib/check_disk_snmp.pl +++ b/contrib/check_disk_snmp.pl | |||
@@ -2,25 +2,39 @@ | |||
2 | # cm@financial.com 07/2002 | 2 | # cm@financial.com 07/2002 |
3 | use strict; | 3 | use strict; |
4 | use Net::SNMP; | 4 | use Net::SNMP; |
5 | use Getopt::Std; | ||
5 | 6 | ||
6 | if ($#ARGV ne 3) { | 7 | my %opts =( |
7 | print "Worng number of Arguments\n"; | 8 | u => 'nobody', # snmp user |
9 | l => 'authNoPriv', # snmp security level | ||
10 | a => 'MD5', # snmp authentication protocol | ||
11 | A => 'nopass', # authentication protocol pass phrase. | ||
12 | x => 'DES', # privacy protocol | ||
13 | m => 'localhost', # host | ||
14 | d => 1, # devicenumber | ||
15 | w => 70, # warnratio | ||
16 | c => 85, # critical ratio | ||
17 | h => 0, | ||
18 | ); | ||
19 | |||
20 | getopts('m:u:l:a:A:x:d:w:c:h',\%opts); | ||
21 | |||
22 | if ( $opts{'h'} ) { | ||
23 | 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"; | ||
8 | exit 1; | 24 | exit 1; |
9 | } | 25 | } |
10 | 26 | ||
11 | 27 | if ($opts{'w'} >= $opts{'c'}) { | |
12 | my ($host, $device, $warnpercent, $errpercent) = @ARGV; | ||
13 | if ($warnpercent >= $errpercent) { | ||
14 | print "Errorratio must be higher then Warnratio!\n"; | 28 | print "Errorratio must be higher then Warnratio!\n"; |
15 | exit 1; | 29 | exit 1; |
16 | } | 30 | } |
17 | 31 | ||
18 | my ($session, $error) = Net::SNMP->session( | 32 | my ($session, $error) = Net::SNMP->session( |
19 | -hostname => $host, | 33 | -hostname => $opts{'m'}, |
20 | -nonblocking => 0x0, | 34 | -nonblocking => 0x0, |
21 | -username => 'XXXXX', | 35 | -username => $opts{'u'}, |
22 | -authpassword => 'XXXXXXXX', | 36 | -authpassword => $opts{'A'}, |
23 | -authprotocol => 'md5', | 37 | -authprotocol => $opts{'a'}, |
24 | -version => '3', | 38 | -version => '3', |
25 | ); | 39 | ); |
26 | 40 | ||
@@ -31,10 +45,9 @@ if ($@) { | |||
31 | my $result=undef; | 45 | my $result=undef; |
32 | 46 | ||
33 | 47 | ||
34 | my $deviceSize=".1.3.6.1.2.1.25.2.3.1.5.$device"; | 48 | my $deviceSize=".1.3.6.1.2.1.25.2.3.1.5.$opts{'d'}"; |
35 | my $deviceUsed=".1.3.6.1.2.1.25.2.3.1.6.$device"; | 49 | my $deviceUsed=".1.3.6.1.2.1.25.2.3.1.6.$opts{'d'}"; |
36 | #my $deviceName=".1.3.6.1.2.1.25.3.7.1.2.1536.$device"; | 50 | my $deviceName=".1.3.6.1.2.1.25.2.3.1.3.$opts{'d'}"; |
37 | my $deviceName=".1.3.6.1.2.1.25.2.3.1.3.$device"; | ||
38 | my @OID=($deviceSize, $deviceUsed, $deviceName); | 51 | my @OID=($deviceSize, $deviceUsed, $deviceName); |
39 | $result = $session->get_request( | 52 | $result = $session->get_request( |
40 | -varbindlist => \@OID, | 53 | -varbindlist => \@OID, |
@@ -48,15 +61,14 @@ if (!defined($result)) { | |||
48 | 61 | ||
49 | my $ratio=$result->{$deviceUsed}*100/$result->{$deviceSize}; | 62 | my $ratio=$result->{$deviceUsed}*100/$result->{$deviceSize}; |
50 | 63 | ||
51 | if ($ratio > $errpercent){ | 64 | if ($ratio > $opts{'c'}){ |
52 | printf("CRITICAL: %s usage %.2f%%\n", $result->{$deviceName}, $ratio); | 65 | printf("CRITICAL: %s usage %.2f%%\n", $result->{$deviceName}, $ratio); |
53 | exit 2; | 66 | exit 2; |
54 | } | 67 | } |
55 | if ($ratio > $warnpercent){ | 68 | if ($ratio > $opts{'w'}){ |
56 | printf("WARNING: %s usage %.2f%%\n", $result->{$deviceName}, $ratio); | 69 | printf("WARNING: %s usage %.2f%%\n", $result->{$deviceName}, $ratio); |
57 | exit 1; | 70 | exit 1; |
58 | } | 71 | } |
59 | 72 | ||
60 | printf("OK: %s usage %.2f%%\n", $result->{$deviceName}, $ratio); | 73 | printf("OK: %s usage %.2f%%\n", $result->{$deviceName}, $ratio); |
61 | exit 0; | 74 | exit 0; |
62 | |||