check_ifoperstatus.t 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #! /usr/bin/perl -w -I ..
  2. #
  3. # SNMP Test via check_ifoperstatus
  4. #
  5. #
  6. use strict;
  7. use Test::More;
  8. use NPTest;
  9. my $tests = 15;
  10. plan tests => $tests;
  11. my $res;
  12. my $plugin = "check_ifoperstatus";
  13. SKIP: {
  14. skip "$plugin is not created", $tests if ( ! -x $plugin );
  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 (assumes snmp v1)" );
  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. $res = NPTest->testCmd( "./$plugin" );
  24. is( $res->return_code, 3, "No arguments" );
  25. like( $res->output, '/usage/', "Output contains usage" );
  26. $res = NPTest->testCmd( "./$plugin -H fakehostname" );
  27. is( $res->return_code, 3, "No key/descr specified" );
  28. like( $res->output, '/Either a valid snmp key/', "Output contains 'Either a valid snmp key'" );
  29. $res = NPTest->testCmd( "./$plugin -H fakehost -k 1 -v 3 --seclevel rubbish --secname foobar" );
  30. is( $res->return_code, 3, "invalid seclevel" );
  31. like( $res->output, "/Must define a valid security level/", "Output contains 'Must define a valid security level'" );
  32. SKIP: {
  33. skip "no snmp host defined", 6 if ( ! $host_snmp );
  34. $res = NPTest->testCmd( "./$plugin -H $host_snmp -C $snmp_community -k 1");
  35. cmp_ok( $res->return_code, '==', 0, "Exit OK for ifindex 1" );
  36. like($res->output, '/^OK.*Interface.*is up/', "String contains OK Interface is up");
  37. $res = NPTest->testCmd( "./$plugin -H $host_snmp -C $snmp_community -d lo");
  38. cmp_ok( $res->return_code, '==', 0, "Exit OK for ifdescr lo" );
  39. like($res->output, '/^OK.*Interface.*is up/', "String contains OK Interface is up");
  40. $res = NPTest->testCmd( "./$plugin -H $host_snmp -C $snmp_community -k 1 -n rubbish");
  41. cmp_ok( $res->return_code, '==', 3, "Exit UNKNOWN if interface name doesn't match" );
  42. like($res->output, '/doesn\'t match snmp value/', "String contains 'doesn't match snmp value'");
  43. }
  44. SKIP: {
  45. skip "no non responsive host defined", 1 if ( ! $host_nonresponsive );
  46. $res = NPTest->testCmd( "./$plugin -H $host_nonresponsive -C $snmp_community -k 1");
  47. cmp_ok( $res->return_code, '==', 1, "Exit WARNING with non responsive host" );
  48. }
  49. SKIP: {
  50. skip "no invalid host defined", 2 if ( ! $hostname_invalid );
  51. $res = NPTest->testCmd( "./$plugin -H $hostname_invalid -C $snmp_community -k 1");
  52. cmp_ok( $res->return_code, '==', 3, "Exit UNKNOWN with invalid host" );
  53. like($res->output, "/Unable to resolve.*$hostname_invalid/", "String matches unable to resolve.*$hostname_invalid");
  54. }
  55. }