7 use Template
::Plugin
::Date
;
14 use lib
"$FindBin::Bin/lib/lib/perl5";
19 ##################################################
21 chomp(my $modgearman_version = qx(grep "^VERSION " packages
/mod-gearman/Makefile
| awk
'{ print \$3 }'));
22 chomp(my $libgearman_version = qx(grep "^VERSION " packages
/gearmand/Makefile
| awk
'{ print \$3 }'));
23 isnt
($modgearman_version, '', "got modgearman_version") or BAIL_OUT
("need mod-gearman version");
24 isnt
($libgearman_version, '', "got libgearman_version") or BAIL_OUT
("need lib-gearman version");;
26 ##################################################
27 # create our test site
28 my $omd_bin = TestUtils
::get_omd_bin
();
30 for my $core (qw
/nagios icinga/) {
31 my $site = TestUtils
::create_test_site
() or TestUtils
::bail_out_clean
("no further testing without site");
32 my $host = "omd-".$site;
33 my $service = "Dummy+Service";
35 # make tests more reliable
36 TestUtils
::test_command
({ cmd
=> "/usr/bin/env sed -i -e 's/^idle-timeout=30/idle-timeout=300/g' /opt/omd/sites/$site/etc/mod-gearman/worker.cfg" });
37 TestUtils
::file_contains
({file
=> "/opt/omd/sites/$site/etc/mod-gearman/worker.cfg", like
=> ['/^idle\-timeout=300/mx'] });
39 # increase worker loglevel
40 TestUtils
::test_command
({ cmd
=> "/usr/bin/env sed -i -e 's/^debug=0/debug=2/g' /opt/omd/sites/$site/etc/mod-gearman/worker.cfg" });
41 TestUtils
::file_contains
({file
=> "/opt/omd/sites/$site/etc/mod-gearman/worker.cfg", like
=> ['/^debug=2/mx'] });
43 # create test host/service
44 TestUtils
::prepare_obj_config
('t/data/omd/testconf1', '/omd/sites/'.$site.'/etc/'.$core.'/conf.d', $site);
46 ##################################################
47 # decrease status update interval
48 TestUtils
::test_command
({ cmd
=> "/usr/bin/env sed -i -e 's/^status_update_interval=30/status_update_interval=3/g' /opt/omd/sites/$site/etc/$core/$core.d/tuning.cfg" });
50 ##################################################
52 my $tpd = Template
::Plugin
::Date
->new();
53 my $now = $tpd->format(time(), '%Y-%m-%d %H:%M:%S');
58 { cmd
=> $omd_bin." config $site set CORE $core" },
59 { cmd
=> $omd_bin." config $site set MOD_GEARMAN on" },
60 { cmd
=> "/usr/bin/test -s /omd/sites/$site/etc/mod-gearman/secret.key", "exit" => 0 },
61 { cmd
=> "/bin/su - $site -c 'rm -f var/*/retention.dat'", like
=> '/^$/' },
62 { cmd
=> $omd_bin." start $site", like
=> [ '/gearmand\.\.\.OK/', '/gearman_worker\.\.\.OK/'], sleep => 1 },
63 { cmd
=> $omd_bin." status $site", like
=> [ '/gearmand:\s+running/', '/gearman_worker:\s*running/'] },
64 { cmd
=> "/bin/su - $site -c './lib/nagios/plugins/check_http -H localhost -a omdadmin:omd -u /$site/$core/cgi-bin/cmd.cgi -e 200 -P \"cmd_typ=7&cmd_mod=2&host=omd-$site&service=Dummy+Service&start_time=$now&force_check=on&btnSubmit=Commit\" -r \"successfully submitted\"'", like
=> '/HTTP OK:/' },
65 { cmd
=> "/bin/su - $site -c './lib/nagios/plugins/check_http -H localhost -a omdadmin:omd -u /$site/$core/cgi-bin/cmd.cgi -e 200 -P \"cmd_typ=7&cmd_mod=2&host=omd-$site&service=perl+test&start_time=$now&force_check=on&btnSubmit=Commit\" -r \"successfully submitted\"'", like
=> '/HTTP OK:/' },
67 for my $test (@
{$preps}) {
68 TestUtils
::test_command
($test) or TestUtils
::bail_out_clean
("no further testing without proper preparation");
71 ##################################################
74 { cmd
=> "/bin/grep 'Event broker module.*mod_gearman.o.*initialized successfully' /omd/sites/$site/var/$core/$core.log", like
=> '/successfully/' },
75 { cmd
=> "/bin/grep 'mod_gearman: initialized version ".$modgearman_version." \(libgearman ".$libgearman_version."\)' /omd/sites/$site/var/$core/$core.log", like
=> '/initialized/' },
76 { cmd
=> "/bin/su - $site -c 'bin/send_gearman --server=localhost:4730 --keyfile=etc/mod-gearman/secret.key --host=$host --message=test'" },
77 { cmd
=> "/bin/su - $site -c 'bin/send_gearman --server=localhost:4730 --keyfile=etc/mod-gearman/secret.key --host=$host --service=$service --message=test'" },
78 { cmd
=> "/bin/grep -i 'mod_gearman: ERROR' /omd/sites/$site/var/$core/$core.log", 'exit' => 1, like
=> '/^\s*$/' },
79 { cmd
=> "/bin/grep -i 'mod_gearman: WARN' /omd/sites/$site/var/$core/$core.log", 'exit' => 1, like
=> '/^\s*$/' },
80 { cmd
=> "/bin/su - $site -c 'lib/$core/plugins/check_gearman -H localhost:4730'", like
=> '/check_gearman OK/' },
81 { cmd
=> "/bin/su - $site -c 'lib/$core/plugins/check_gearman -H localhost:4730 -q host'", like
=> '/check_gearman OK/' },
83 for my $test (@
{$tests}) {
84 TestUtils
::test_command
($test);
87 #--- wait for all services being checked
88 TestUtils
::wait_for_content
({
89 url
=> "http://localhost/$site/$core/cgi-bin/status.cgi?host=$host&servicestatustypes=1&hoststatustypes=15",
90 auth
=> "OMD Monitoring Site $site:omdadmin:omd",
91 like
=> [ "0 Matching Service" ],
95 # verify the jobs done
96 my $test = { cmd
=> "/bin/su - $site -c 'lib/$core/plugins/check_gearman -H localhost:4730 -q worker_".hostname
." -t 10 -s check'", like
=> [ '/check_gearman OK/' ] };
97 TestUtils
::test_command
($test);
98 chomp($test->{'stdout'});
99 unlike
($test->{'stdout'}, qr/jobs=0c/, "worker has jobs done: ".$test->{'stdout'});
101 if( $test->{'stdout'} =~ m/worker=(\d+)/ ) { $worker = $1 }
102 ok
($worker >= 3, "worker number >= 3: $worker") or diag
($test->{'stdout'});
104 TestUtils
::file_contains
({file
=> "/opt/omd/sites/$site/var/log/gearman/worker.log", like
=> ['/Using Embedded Perl interpreter for: .*check_webinject/', '/Embedded Perl successfully compiled/', '/^output=.*find\ any\ test/mx'], unlike
=> ['/\[ERROR\]/'] });
106 ##################################################
108 TestUtils
::test_command
({ cmd
=> $omd_bin." stop $site" });
109 TestUtils
::remove_test_site
($site);