From 827e17f4547aede83f98cabe9e9f0bd5fa30d0e5 Mon Sep 17 00:00:00 2001 From: Ethan Galstad Date: Mon, 12 Aug 2002 23:09:48 +0000 Subject: [PATCH] Updated to use getopt (Christoph Maser) git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@69 f882894a-f735-0410-b71e-b25c423dba1c --- contrib/check_disk_snmp.pl | 44 ++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/contrib/check_disk_snmp.pl b/contrib/check_disk_snmp.pl index 96862e1..a09343d 100644 --- a/contrib/check_disk_snmp.pl +++ b/contrib/check_disk_snmp.pl @@ -2,25 +2,39 @@ # cm@financial.com 07/2002 use strict; use Net::SNMP; +use Getopt::Std; -if ($#ARGV ne 3) { - print "Worng number of Arguments\n"; +my %opts =( + u => 'nobody', # snmp user + l => 'authNoPriv', # snmp security level + a => 'MD5', # snmp authentication protocol + A => 'nopass', # authentication protocol pass phrase. + x => 'DES', # privacy protocol + m => 'localhost', # host + d => 1, # devicenumber + w => 70, # warnratio + c => 85, # critical ratio + h => 0, + ); + +getopts('m:u:l:a:A:x:d:w:c:h',\%opts); + +if ( $opts{'h'} ) { + print "Usage: $0 [ -u ] [ -l ] [ -a ] [ -A ] [ -x ] [ -m ] [ -d ] [ -w ] [ -c = $errpercent) { +if ($opts{'w'} >= $opts{'c'}) { print "Errorratio must be higher then Warnratio!\n"; exit 1; } my ($session, $error) = Net::SNMP->session( - -hostname => $host, + -hostname => $opts{'m'}, -nonblocking => 0x0, - -username => 'XXXXX', - -authpassword => 'XXXXXXXX', - -authprotocol => 'md5', + -username => $opts{'u'}, + -authpassword => $opts{'A'}, + -authprotocol => $opts{'a'}, -version => '3', ); @@ -31,10 +45,9 @@ if ($@) { 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 $deviceSize=".1.3.6.1.2.1.25.2.3.1.5.$opts{'d'}"; +my $deviceUsed=".1.3.6.1.2.1.25.2.3.1.6.$opts{'d'}"; +my $deviceName=".1.3.6.1.2.1.25.2.3.1.3.$opts{'d'}"; my @OID=($deviceSize, $deviceUsed, $deviceName); $result = $session->get_request( -varbindlist => \@OID, @@ -48,15 +61,14 @@ if (!defined($result)) { my $ratio=$result->{$deviceUsed}*100/$result->{$deviceSize}; -if ($ratio > $errpercent){ +if ($ratio > $opts{'c'}){ printf("CRITICAL: %s usage %.2f%%\n", $result->{$deviceName}, $ratio); exit 2; } -if ($ratio > $warnpercent){ +if ($ratio > $opts{'w'}){ printf("WARNING: %s usage %.2f%%\n", $result->{$deviceName}, $ratio); exit 1; } printf("OK: %s usage %.2f%%\n", $result->{$deviceName}, $ratio); exit 0; - -- 2.30.2