check_ifstatus.t 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 = 9;
  10. plan tests => $tests;
  11. my $res;
  12. my $plugin = "check_ifstatus";
  13. SKIP: {
  14. skip "$plugin is not created", $tests if ( ! -x $plugin );
  15. my $host_snmp = getTestParameter( "NP_HOST_SNMP", "A host providing an SNMP Service", "localhost");
  16. my $snmp_community = getTestParameter( "NP_SNMP_COMMUNITY",
  17. "The SNMP Community string for SNMP Testing",
  18. "public");
  19. my $host_nonresponsive = getTestParameter( "NP_HOST_NONRESPONSIVE",
  20. "The hostname of system not responsive to network requests", "10.0.0.1" );
  21. my $hostname_invalid = getTestParameter( "NP_HOSTNAME_INVALID",
  22. "An invalid (not known to DNS) hostname",
  23. "nosuchhost" );
  24. $res = NPTest->testCmd( "./$plugin" );
  25. is( $res->return_code, 3, "No arguments" );
  26. like( $res->output, '/usage/', "Output contains usage" );
  27. $res = NPTest->testCmd( "./$plugin -H fakehost -v 3 --seclevel rubbish --secname foobar" );
  28. is( $res->return_code, 3, "invalid seclevel" );
  29. like( $res->output, "/Must define a valid security level/", "Output contains 'Must define a valid security level'" );
  30. SKIP: {
  31. skip "no snmp host defined", 2 if ( ! $host_snmp );
  32. $res = NPTest->testCmd( "./$plugin -H $host_snmp -C $snmp_community ");
  33. like($res->output, '/^.*host.*interfaces up/', "String contains host.*interfaces up");
  34. $res = NPTest->testCmd( "./$plugin -H $host_snmp -C rubbish");
  35. cmp_ok( $res->return_code, '==', 2, "Exit CRITICAL for community 'rubbish'" );
  36. }
  37. # These checks need a complete command line. An invalid community is used so
  38. # the tests can run on hosts w/o snmp host/community in NPTest.cache. Execution will fail anyway
  39. SKIP: {
  40. skip "no non responsive host defined", 1 if ( ! $host_nonresponsive );
  41. $res = NPTest->testCmd( "./$plugin -H $host_nonresponsive -C np_foobar");
  42. cmp_ok( $res->return_code, '==', 2, "Exit CRITICAL with non responsive host" );
  43. }
  44. SKIP: {
  45. skip "no invalid host defined", 2 if ( ! $hostname_invalid );
  46. $res = NPTest->testCmd( "./$plugin -H $hostname_invalid -C np_foobar");
  47. cmp_ok( $res->return_code, '==', 3, "Exit UNKNOWN with invalid host" );
  48. like($res->output, "/Unable to resolve.*$hostname_invalid/", "String matches unable to resolve.*$hostname_invalid");
  49. }
  50. }