check_snmp.t 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #! /usr/bin/perl -w -I ..
  2. #
  3. # Test check_snmp by having an actual SNMP agent running
  4. #
  5. use strict;
  6. use Test::More;
  7. use NPTest;
  8. use FindBin qw($Bin);
  9. my $port_snmp = 16100 + int(rand(100));
  10. my $running = 1;
  11. # Start up server
  12. my @pids;
  13. my $pid = fork();
  14. if ($pid) {
  15. # Parent
  16. push @pids, $pid;
  17. # give our agent some time to startup
  18. sleep(1);
  19. } else {
  20. # Child
  21. #print "child\n";
  22. print "Please contact SNMP at: $port_snmp\n";
  23. close(STDERR); # Coment out to debug snmpd problems (most errors sent there are OK)
  24. exec("snmpd -c tests/conf/snmpd.conf -C -f -r udp:$port_snmp");
  25. }
  26. END {
  27. foreach my $pid (@pids) {
  28. if ($pid) { print "Killing $pid\n"; kill "INT", $pid }
  29. }
  30. };
  31. if ($ARGV[0] && $ARGV[0] eq "-d") {
  32. while (1) {
  33. sleep 100;
  34. }
  35. }
  36. my $tests = 3;
  37. if (-x "./check_snmp") {
  38. plan tests => $tests;
  39. } else {
  40. plan skip_all => "No check_snmp compiled";
  41. }
  42. my $res;
  43. $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.0");
  44. cmp_ok( $res->return_code, '==', 0, "Exit OK when querying a multi-line string" );
  45. like($res->output, '/^SNMP OK - /', "String contains SNMP OK");
  46. like($res->output, '/'.quotemeta('SNMP OK - "Cisco Internetwork Operating System SoftwareIOS (tm) Catalyst 4000 L3 Switch Software (cat4000-I9K91S-M), Version
  47. 12.2(20)EWA, RELEASE SOFTWARE (fc1)
  48. Technical Support: http://www.cisco.com/techsupport
  49. Copyright (c) 1986-2004 by cisco Systems, Inc.
  50. "').'/m', "String contains all lines");
  51. print $res->output;