check_disk_snmp.pl 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #!/usr/bin/perl
  2. # cm@financial.com 07/2002
  3. use strict;
  4. use Net::SNMP;
  5. use Getopt::Std;
  6. my %opts =(
  7. u => 'nobody', # snmp user
  8. l => 'authNoPriv', # snmp security level
  9. a => 'MD5', # snmp authentication protocol
  10. A => 'nopass', # authentication protocol pass phrase.
  11. x => 'DES', # privacy protocol
  12. m => 'localhost', # host
  13. d => 1, # devicenumber
  14. w => 70, # warnratio
  15. c => 85, # critical ratio
  16. h => 0,
  17. );
  18. getopts('m:u:l:a:A:x:d:w:c:h',\%opts);
  19. if ( $opts{'h'} ) {
  20. 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";
  21. exit 1;
  22. }
  23. if ($opts{'w'} >= $opts{'c'}) {
  24. print "Errorratio must be higher then Warnratio!\n";
  25. exit 1;
  26. }
  27. my ($session, $error) = Net::SNMP->session(
  28. -hostname => $opts{'m'},
  29. -nonblocking => 0x0,
  30. -username => $opts{'u'},
  31. -authpassword => $opts{'A'},
  32. -authprotocol => $opts{'a'},
  33. -version => '3',
  34. );
  35. if ($@) {
  36. print "SNMP-Error occured";
  37. exit 1;
  38. }
  39. my $result=undef;
  40. my $deviceSize=".1.3.6.1.2.1.25.2.3.1.5.$opts{'d'}";
  41. my $deviceUsed=".1.3.6.1.2.1.25.2.3.1.6.$opts{'d'}";
  42. my $deviceName=".1.3.6.1.2.1.25.2.3.1.3.$opts{'d'}";
  43. my @OID=($deviceSize, $deviceUsed, $deviceName);
  44. $result = $session->get_request(
  45. -varbindlist => \@OID,
  46. );
  47. if (!defined($result)) {
  48. printf("ERROR: %s.\n", $session->error);
  49. $session->close;
  50. exit 1;
  51. }
  52. my $ratio=$result->{$deviceUsed}*100/$result->{$deviceSize};
  53. if ($ratio > $opts{'c'}){
  54. printf("CRITICAL: %s usage %.2f%%\n", $result->{$deviceName}, $ratio);
  55. exit 2;
  56. }
  57. if ($ratio > $opts{'w'}){
  58. printf("WARNING: %s usage %.2f%%\n", $result->{$deviceName}, $ratio);
  59. exit 1;
  60. }
  61. printf("OK: %s usage %.2f%%\n", $result->{$deviceName}, $ratio);
  62. exit 0;