check_snmp.t 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #! /usr/bin/perl -w -I ..
  2. #
  3. # Simple Network Management Protocol (SNMP) Test via check_snmp
  4. #
  5. # $Id$
  6. #
  7. use strict;
  8. use Test;
  9. use NPTest;
  10. use vars qw($tests);
  11. BEGIN {$tests = 12; plan tests => $tests}
  12. my $t;
  13. if ( -x "./check_snmp" )
  14. {
  15. my $host_snmp = getTestParameter( "host_snmp", "NP_HOST_SNMP", "localhost",
  16. "A host providing an SNMP Service");
  17. my $snmp_community = getTestParameter( "snmp_community", "NP_SNMP_COMMUNITY", "public",
  18. "The SNMP Community string for SNMP Testing" );
  19. my $host_nonresponsive = getTestParameter( "host_nonresponsive", "NP_HOST_NONRESPONSIVE", "10.0.0.1",
  20. "The hostname of system not responsive to network requests" );
  21. my $hostname_invalid = getTestParameter( "hostname_invalid", "NP_HOSTNAME_INVALID", "nosuchhost",
  22. "An invalid (not known to DNS) hostname" );
  23. my %exceptions = ( 3 => "No SNMP Server present?" );
  24. $t += checkCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0 -w 1: -c 1:",
  25. { 0 => 'continue', 3 => 'skip' }, '/^SNMP OK - \d+/', %exceptions );
  26. $t += checkCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w 1:1 -c 1:1",
  27. { 0 => 'continue', 3 => 'skip' }, '/^SNMP OK - 1\s*$/', %exceptions );
  28. $t += checkCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w 0 -c 1:",
  29. { 1 => 'continue', 3 => 'skip' }, '/^SNMP WARNING - \*1\*\s*$/', %exceptions );
  30. $t += checkCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w :0 -c 0",
  31. { 2 => 'continue', 3 => 'skip' }, '/^SNMP CRITICAL - \*1\*\s*$/', %exceptions );
  32. $t += checkCmd( "./check_snmp -H $host_nonresponsive -C $snmp_community -o system.sysUpTime.0 -w 1: -c 1:", 3, '/SNMP problem - /' );
  33. $t += checkCmd( "./check_snmp -H $hostname_invalid -C $snmp_community -o system.sysUpTime.0 -w 1: -c 1:", 3, '/SNMP problem - /' );
  34. }
  35. else
  36. {
  37. $t += skipMissingCmd( "./check_snmp", $tests );
  38. }
  39. exit(0) if defined($Test::Harness::VERSION);
  40. exit($tests - $t);