12 use lib
"$FindBin::Bin/lib/lib/perl5";
17 # create our test site
18 my $omd_bin = TestUtils
::get_omd_bin
();
19 my $site = TestUtils
::create_test_site
() or BAIL_OUT
("no further testing without site");
20 my $package = "check_multi";
21 my $host = "omd-$package";
22 my $auth = 'OMD Monitoring Site '.$site.':omdadmin:omd';
24 # create test host/service
25 TestUtils
::prepare_obj_config
('t/data/omd/testconf1', '/omd/sites/'.$site.'/etc/nagios/conf.d', $site);
27 # prepare check_multi test environment (from skel/etc/check_multi/test)
28 TestUtils
::test_command
({ cmd
=> $omd_bin." config $site set DEFAULT_GUI welcome" });
29 TestUtils
::test_command
({ cmd
=> "/bin/cp t/packages/check_multi/test/localhost.cfg /omd/sites/$site/etc/nagios/conf.d/check_multi_test.cfg" });
30 TestUtils
::test_command
({ cmd
=> "/usr/bin/test -d /omd/sites/$site/etc/check_multi || /bin/mkdir /omd/sites/$site/etc/check_multi" });
31 TestUtils
::test_command
({ cmd
=> "/bin/cp t/packages/check_multi/test/* /omd/sites/$site/etc/check_multi" });
32 TestUtils
::test_command
({ cmd
=> "/bin/sed -i -e 's/sleep_time = 15/sleep_time = 2/' -e 's/perfdata_file_processing_interval = 15/perfdata_file_processing_interval = 2/' /omd/sites/$site/etc/pnp4nagios/npcd.cfg" });
33 TestUtils
::test_command
({ cmd
=> "/bin/sed -i -e 's/log_external_commands=0/log_external_commands=1/' /omd/sites/$site/etc/shinken/shinken.d/logging.cfg" });
34 TestUtils
::test_command
({ cmd
=> "/bin/echo 'max_service_check_spread=1' >> /omd/sites/$site/etc/shinken/shinken.d/tuning.cfg" });
35 TestUtils
::test_command
({ cmd
=> $omd_bin." start $site" }) or TestUtils
::bail_out_clean
("No need to test $package without proper startup");
36 TestUtils
::wait_for_file
("/omd/sites/$site/tmp/run/live") or TestUtils
::bail_out_clean
("No need to test $package without livestatus connection");
38 # check_multi's own tests
39 #TestUtils::test_command({ cmd => "/bin/sh -c '(cd packages/check_multi/check_multi/plugins/t; make OMD_SITE=test OMD_ROOT=/tmp test-all test-extreme)'" });
43 url
=> '/nagios/cgi-bin/status.cgi?host=all',
45 '/Service Status Details/',
46 '/livestatus.*plugins checked/ms',
47 '/nagios.*\d+ plugins checked/ms',
48 '/pnp4nagios.*\d+ plugins checked/ms',
49 '/statusdat.*\d+ plugins checked/ms',
50 '/system.*\d+ plugins checked/ms',
55 url
=> '/thruk/side.html', # startup fcgi daemon
58 url
=> '/thruk/cgi-bin/status.cgi?host=all',
60 '/Service Status Details/',
61 '/livestatus.*plugins checked/ms',
62 '/nagios.*\d+ plugins checked/ms',
63 '/pnp4nagios.*\d+ plugins checked/ms',
64 '/statusdat.*\d+ plugins checked/ms',
65 '/system.*\d+ plugins checked/ms',
69 url
=> "/nagios/cgi-bin/status.cgi?host=$host",
71 "/Service Status Details/",
72 '/livestatus.*plugins checked/ms',
73 '/nagios.*\d+ plugins checked/ms',
74 '/pnp4nagios.*\d+ plugins checked/ms',
75 '/statusdat.*\d+ plugins checked/ms',
76 '/system.*\d+ plugins checked/ms',
81 url
=> "/nagios/cgi-bin/extinfo.cgi?type=2&host=$host&service=pnp4nagios",
83 '/Service.*pnp4nagios/',
84 '/pnp4nagios.*\d+ plugins checked/ms',
88 '/var_updated_recently/',
89 '/process_perfdata_timeout/',
90 '/error_in_npcd_log/',
94 url
=> "/nagios/cgi-bin/extinfo.cgi?type=2&host=$host&service=nagios",
96 '/Service.*nagios.*On Host/',
98 '/ROOT.*\/omd\/sites\/testsite/',
100 '/checkresults_dir/',
104 url
=> "/pnp4nagios/graph?host=$host&srv=disk_root",
106 '/Service details omd-check_multi.*disk_root/',
110 # url => "/nagios/cgi-bin/extinfo.cgi?type=2&host=$host&service=statusdat",
112 # '/Service.*statusdat.*On Host.*omd-check_multi/ms',
113 # #'/all_omd-check_multi_livestatus.*plugins checked/ms',
114 # '/all_omd-check_multi_nagios.*\d+ plugins checked/ms',
115 # '/all_omd-check_multi_pnp4nagios.*pnp4nagios.*\d+ plugins checked/ms',
116 # '/all_omd-check_multi_.*statusdat.*\d+ plugins checked/ms',
117 # '/all_omd-check_multi_system.*system.*\d+ plugins checked/ms',
120 # "/read_status_dat: cannot open /omd/sites/$site/tmp/nagios/status.dat/ms",
124 # url => "/nagios/cgi-bin/extinfo.cgi?type=2&host=$host&service=livestatus",
126 # "/Service.*livestatus.*On Host.*$host/ms",
127 # '/livestatus.*plugins checked/ms',
128 # '/all_omd-check_multi_nagios.*\d+ plugins checked/ms',
129 # '/all_omd-check_multi_pnp4nagios.*pnp4nagios.*\d+ plugins checked/ms',
132 # "/all_omd-check_multi_.*: no output, no stderr - check your plugin and the tmp directory /omd/sites/$site/tmp/check_multi/ms",
138 foreach my $url ( @
{$urls} ) {
139 $url->{'url'} = "http://localhost/".$site.$url->{'url'};
140 $url->{'auth'} = $auth;
141 push @
{$url->{'unlike'}}, '/internal server error/';
144 for my $core (qw
/nagios/) {
145 #--- perform proper initialization
146 TestUtils
::test_command
({ cmd
=> $omd_bin." stop $site" });
147 TestUtils
::test_command
({ cmd
=> $omd_bin." config $site set CORE $core" });
148 TestUtils
::test_command
({ cmd
=> $omd_bin." start $site" }) or TestUtils
::bail_out_clean
("No need to test $package without proper startup");
149 TestUtils
::wait_for_file
("/omd/sites/$site/tmp/run/nagios.cmd") or TestUtils
::bail_out_clean
("No need to test $package without proper startup");;
151 #--- reschedule all checks and wait for result (note: shinken cmd.cgi is to be addressed via nagios CGIs)
152 #TestUtils::test_command({ cmd => "/bin/su - $site -c './lib/nagios/plugins/check_http -t 30 -H localhost -a omdadmin:omd -u /$site/nagios/cgi-bin/cmd.cgi -e 200 -P \"cmd_typ=17&host=$host&cmd_mod=2&start_time=2222-22-22:22%3A22%3A22&force_check=on&btnSubmit=Commit\" -r \"Your command request was successfully submitted\"'", like => '/HTTP OK:/' });
153 TestUtils
::test_command
({ cmd
=> "/bin/su - $site -c './lib/nagios/plugins/check_http -t 30 -H localhost -a omdadmin:omd -u /$site/nagios/cgi-bin/cmd.cgi -e 200 -P \"cmd_typ=7&cmd_mod=2&host=$host&service=nagios&start_time=2010-11-06+09%3A46%3A02&force_check=on&btnSubmit=Commit\" -r \"Your command request was successfully submitted\"'", like
=> '/HTTP OK:/' });
154 TestUtils
::test_command
({ cmd
=> "/bin/su - $site -c './lib/nagios/plugins/check_http -t 30 -H localhost -a omdadmin:omd -u /$site/nagios/cgi-bin/cmd.cgi -e 200 -P \"cmd_typ=7&cmd_mod=2&host=$host&service=pnp4nagios&start_time=2010-11-06+09%3A46%3A02&force_check=on&btnSubmit=Commit\" -r \"Your command request was successfully submitted\"'", like
=> '/HTTP OK:/' });
155 TestUtils
::test_command
({ cmd
=> "/bin/su - $site -c './lib/nagios/plugins/check_http -t 30 -H localhost -a omdadmin:omd -u /$site/nagios/cgi-bin/cmd.cgi -e 200 -P \"cmd_typ=7&cmd_mod=2&host=$host&service=system&start_time=2010-11-06+09%3A46%3A02&force_check=on&btnSubmit=Commit\" -r \"Your command request was successfully submitted\"'", like
=> '/HTTP OK:/' });
156 TestUtils
::test_command
({ cmd
=> "/bin/su - $site -c './lib/nagios/plugins/check_http -t 30 -H localhost -a omdadmin:omd -u /$site/nagios/cgi-bin/cmd.cgi -e 200 -P \"cmd_typ=7&cmd_mod=2&host=$host&service=statusdat&start_time=2010-11-06+09%3A46%3A02&force_check=on&btnSubmit=Commit\" -r \"Your command request was successfully submitted\"'", like
=> '/HTTP OK:/' });
157 TestUtils
::test_command
({ cmd
=> "/bin/su - $site -c './lib/nagios/plugins/check_http -t 30 -H localhost -a omdadmin:omd -u /$site/nagios/cgi-bin/cmd.cgi -e 200 -P \"cmd_typ=7&cmd_mod=2&host=$host&service=livestatus&start_time=2010-11-06+09%3A46%3A02&force_check=on&btnSubmit=Commit\" -r \"Your command request was successfully submitted\"'", like
=> '/HTTP OK:/' });
159 #--- check_multi specific cgi.cfg setting
160 TestUtils
::test_command
({ cmd
=> "/bin/sed -i -e 's/escape_html_tags=1/escape_html_tags=0/' /omd/sites/$site/etc/$core/cgi.cfg" });
162 #--- wait for all services being checked
163 TestUtils
::wait_for_content
(
165 url
=> "http://localhost/$site/nagios/cgi-bin/status.cgi?host=$host&servicestatustypes=1&hoststatustypes=15",
166 auth
=> "OMD Monitoring Site $site:omdadmin:omd",
167 like
=> [ "0 of 0 Matching Services" ],
171 TestUtils
::wait_for_file
("/omd/sites/$site/var/pnp4nagios/perfdata/omd-$site/Dummy_Service_omd-dummy.rrd");
172 TestUtils
::wait_for_file
("/omd/sites/$site/tmp/run/live") or TestUtils
::bail_out_clean
("No need to test $package without livestatus connection");
173 TestUtils
::wait_for_file
("/omd/sites/$site/tmp/nagios/status.dat") or TestUtils
::bail_out_clean
("No need to test $package without existing status.dat");
175 for my $url ( @
{$urls} ) {
176 TestUtils
::test_url
($url);
180 TestUtils
::test_command
({ cmd
=> TestUtils
::config
('APACHE_INIT')." restart" });
181 TestUtils
::remove_test_site
($site);