1
0

check_netping_io.pl 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/usr/bin/perl
  2. use strict;
  3. use Net::SNMP;
  4. my $netping_oids = {
  5. 'netpingIOlevel'=>'.1.3.6.1.4.1.25728.8900.1.1.2',
  6. 'netpingIOLineName'=>'.1.3.6.1.4.1.25728.8900.1.1.6',
  7. 'netpingIOCount'=>'.1.3.6.1.4.1.25728.8900.1.1.9'
  8. };
  9. exit if (!$ARGV[0]);
  10. my $TIMEOUT = 30;
  11. $SIG{ALRM} = sub { print "ERROR: No response\n"; exit 3; };
  12. alarm($TIMEOUT);
  13. my $hostip=$ARGV[0];
  14. my $line =$ARGV[1] || '1';
  15. my $community = $ARGV[2] || 'public';
  16. my $location_oid = '.1.3.6.1.2.1.1.6.0';
  17. my ($session, $error) = Net::SNMP->session(
  18. -hostname => shift || $hostip,
  19. -version => shift || 2,
  20. -community => shift || $community,
  21. -timeout => 5,
  22. -port => shift || 161
  23. );
  24. if (!defined($session)) {
  25. printf("ERROR: %s.\n", $error);
  26. exit 1;
  27. }
  28. my $line_oid = $netping_oids->{netpingIOlevel}.'.'.$line;
  29. my $desc_oid = $netping_oids->{netpingIOLineName}.'.'.$line;
  30. my $result = $session->get_request( -varbindlist => [$line_oid] );
  31. my $status = $result->{$line_oid};
  32. $result = $session->get_request( -varbindlist => [$desc_oid] );
  33. my $desc = $result->{$desc_oid};
  34. $result = $session->get_request( -varbindlist => [$location_oid] );
  35. my $location = $result->{$location_oid};
  36. $session->close;
  37. if ($status) {
  38. print("CRIT: $location $desc detected!\n");
  39. exit 2;
  40. }
  41. print("OK: $location $desc\n");
  42. exit 0;