check_disk_snmp.pl 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #!/usr/bin/perl
  2. # cm@financial.com 07/2002
  3. use strict;
  4. use Net::SNMP;
  5. if ($#ARGV ne 3) {
  6. print "Worng number of Arguments\n";
  7. exit 1;
  8. }
  9. my ($host, $device, $warnpercent, $errpercent) = @ARGV;
  10. if ($warnpercent >= $errpercent) {
  11. print "Errorratio must be higher then Warnratio!\n";
  12. exit 1;
  13. }
  14. my ($session, $error) = Net::SNMP->session(
  15. -hostname => $host,
  16. -nonblocking => 0x0,
  17. -username => 'XXXXX',
  18. -authpassword => 'XXXXXXXX',
  19. -authprotocol => 'md5',
  20. -version => '3',
  21. );
  22. if ($@) {
  23. print "SNMP-Error occured";
  24. exit 1;
  25. }
  26. my $result=undef;
  27. my $deviceSize=".1.3.6.1.2.1.25.2.3.1.5.$device";
  28. my $deviceUsed=".1.3.6.1.2.1.25.2.3.1.6.$device";
  29. #my $deviceName=".1.3.6.1.2.1.25.3.7.1.2.1536.$device";
  30. my $deviceName=".1.3.6.1.2.1.25.2.3.1.3.$device";
  31. my @OID=($deviceSize, $deviceUsed, $deviceName);
  32. $result = $session->get_request(
  33. -varbindlist => \@OID,
  34. );
  35. if (!defined($result)) {
  36. printf("ERROR: %s.\n", $session->error);
  37. $session->close;
  38. exit 1;
  39. }
  40. my $ratio=$result->{$deviceUsed}*100/$result->{$deviceSize};
  41. if ($ratio > $errpercent){
  42. printf("CRITICAL: %s usage %.2f%%\n", $result->{$deviceName}, $ratio);
  43. exit 2;
  44. }
  45. if ($ratio > $warnpercent){
  46. printf("WARNING: %s usage %.2f%%\n", $result->{$deviceName}, $ratio);
  47. exit 1;
  48. }
  49. printf("OK: %s usage %.2f%%\n", $result->{$deviceName}, $ratio);
  50. exit 0;