1
0

check_ups_input1 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #!/usr/bin/perl
  2. use strict;
  3. use Net::SNMP;
  4. exit if (!$ARGV[0]);
  5. my $TIMEOUT = 30;
  6. $SIG{ALRM} = sub { print "ERROR: No response\n"; exit 3; };
  7. alarm($TIMEOUT);
  8. my $hostip=$ARGV[0];
  9. my ($session, $error) = Net::SNMP->session(
  10. -hostname => shift || $hostip,
  11. -community => shift || 'public',
  12. -timeout => 5,
  13. -port => shift || 161
  14. );
  15. if (!defined($session)) {
  16. printf("ERROR: %s.\n", $error);
  17. exit 1;
  18. }
  19. my $TIMEOUT = 30;
  20. $SIG{ALRM} = sub { print "ERROR: No response\n"; exit 3; };
  21. alarm($TIMEOUT);
  22. my $inputac = '1.3.6.1.4.1.318.1.1.1.3.2.3.0';
  23. my $result = $session->get_request(
  24. -varbindlist => [$inputac]
  25. );
  26. my $perf_data = "input=0;210;200;0;280;";
  27. if (!defined($result)) {
  28. printf("ERROR: %s. |".$perf_data."\n", $session->error);
  29. $session->close;
  30. exit 2;
  31. }
  32. $perf_data = "input=%s;210;200;0;280;";
  33. if (($result->{$inputac} < 201) or $result->{$inputac} > 255) {
  34. printf("ERROR Input AC: %sV |".$perf_data."\n",$result->{$inputac},$result->{$inputac});
  35. $session->close;
  36. exit 2;
  37. }
  38. printf("OK Input AC %sV |".$perf_data."\n", $result->{$inputac},$result->{$inputac});
  39. $session->close;
  40. exit 0;