check_snmp.t 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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::More;
  9. use NPTest;
  10. use vars qw($tests);
  11. BEGIN {$tests = 14; plan tests => $tests}
  12. my $res;
  13. SKIP: {
  14. skip "check_snmp is not compiled", $tests if ( ! -x "./check_snmp" );
  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. SKIP: {
  24. skip "no snmp host defined", 10 if ( ! $host_snmp );
  25. $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0 -w 1: -c 1:");
  26. cmp_ok( $res->return_code, '==', 0, "Exit OK when querying uptime" );
  27. like($res->output, '/^SNMP OK - \d+/', "String contains SNMP OK");
  28. $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysDescr.0");
  29. cmp_ok( $res->return_code, '==', 0, "Exit OK when querying sysDescr" );
  30. unlike($res->perf_output, '/sysDescr/', "Perfdata doesn't contain string values");
  31. $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w 1:1 -c 1:1");
  32. cmp_ok( $res->return_code, '==', 0, "Exit OK when querying hrSWRunIndex.1" );
  33. like($res->output, '/^SNMP OK - 1\s.*$/', "String fits SNMP OK and output format");
  34. $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w 0 -c 1:");
  35. cmp_ok( $res->return_code, '==', 1, "Exit WARNING when querying hrSWRunIndex.1 and warn-th doesn't apply " );
  36. like($res->output, '/^SNMP WARNING - \*1\*\s.*$/', "String matches SNMP WARNING and output format");
  37. $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w :0 -c 0");
  38. cmp_ok( $res->return_code, '==', 2, "Exit CRITICAL when querying hrSWRunIndex.1 and crit-th doesn't apply" );
  39. like($res->output, '/^SNMP CRITICAL - \*1\*\s.*$/', "String matches SNMP CRITICAL and ouput format");
  40. }
  41. SKIP: {
  42. skip "no non responsive host defined", 2 if ( ! $host_nonresponsive );
  43. $res = NPTest->testCmd( "./check_snmp -H $host_nonresponsive -C $snmp_community -o system.sysUpTime.0 -w 1: -c 1:");
  44. cmp_ok( $res->return_code, '==', 3, "Exit UNKNOWN with non responsive host" );
  45. like($res->output, '/SNMP problem - /', "String matches SNMP Problem");
  46. }
  47. SKIP: {
  48. skip "no non invalid host defined", 2 if ( ! $hostname_invalid );
  49. $res = NPTest->testCmd( "./check_snmp -H $hostname_invalid -C $snmp_community -o system.sysUpTime.0 -w 1: -c 1:");
  50. cmp_ok( $res->return_code, '==', 3, "Exit UNKNOWN with non responsive host" );
  51. like($res->output, '/SNMP problem - /', "String matches SNMP Problem");
  52. }
  53. }