check_ifstatus.t 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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( "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 fakehost -v 3 --seclevel rubbish --secname foobar" );
  27. is( $res->return_code, 3, "invalid seclevel" );
  28. like( $res->output, "/Must define a valid security level/", "Output contains 'Must define a valid security level'" );
  29. SKIP: {
  30. skip "no snmp host defined", 2 if ( ! $host_snmp );
  31. $res = NPTest->testCmd( "./$plugin -H $host_snmp -C $snmp_community ");
  32. like($res->output, '/^.*host.*interfaces up/', "String contains host.*interfaces up");
  33. $res = NPTest->testCmd( "./$plugin -H $host_snmp -C rubbish");
  34. cmp_ok( $res->return_code, '==', 2, "Exit CRITICAL for community 'rubbish'" );
  35. }
  36. SKIP: {
  37. skip "no non responsive host defined", 1 if ( ! $host_nonresponsive );
  38. $res = NPTest->testCmd( "./$plugin -H $host_nonresponsive -C $snmp_community");
  39. cmp_ok( $res->return_code, '==', 2, "Exit CRITICAL with non responsive host" );
  40. }
  41. SKIP: {
  42. skip "no invalid host defined", 2 if ( ! $hostname_invalid );
  43. $res = NPTest->testCmd( "./$plugin -H $hostname_invalid -C $snmp_community");
  44. cmp_ok( $res->return_code, '==', 3, "Exit UNKNOWN with invalid host" );
  45. like($res->output, "/Unable to resolve.*$hostname_invalid/", "String matches unable to resolve.*$hostname_invalid");
  46. }
  47. }