13 use lib
"$FindBin::Bin/lib/lib/perl5";
16 plan
( tests
=> 2774 );
18 ##################################################
19 # create our test site
20 my $omd_bin = TestUtils
::get_omd_bin
();
21 my $site = TestUtils
::create_test_site
() or TestUtils
::bail_out_clean
("no further testing without site");
22 my $auth = 'OMD Monitoring Site '.$site.':omdadmin:omd';
23 my $host = "omd-".$site;
24 my $service = "Dummy+Service";
26 # create test host/service
27 TestUtils
::prepare_obj_config
('t/data/omd/testconf1', '/omd/sites/'.$site.'/etc/nagios/conf.d', $site);
29 # decrease pnp interval
30 TestUtils
::test_command
({ cmd
=> "/usr/bin/env sed -i -e 's/^perfdata_file_processing_interval = 15/perfdata_file_processing_interval = 2/g' -e 's/^sleep_time = 15/sleep_time = 2/g' /opt/omd/sites/$site/etc/pnp4nagios/npcd.cfg" });
32 # set thruk as default
33 TestUtils
::test_command
({ cmd
=> $omd_bin." config $site set DEFAULT_GUI thruk" });
34 TestUtils
::test_command
({ cmd
=> $omd_bin." start $site" });
39 'template' => 'sla_host.tt',
41 'params.timeperiod' => 'last12months',
42 'params.host' => $host,
43 'params.breakdown' => 'months',
44 'params.unavailable' => [ 'down', 'unreachable' ],
45 'params.graph_min_sla' => 90,
46 'params.decimals' => 2,
47 'send_type_1' => 'month',
55 ##################################################
58 { cmd
=> "/bin/su - $site -c 'lib/nagios/plugins/check_http -t 60 -H localhost -a omdadmin:omd -u /$site/thruk/side.html -e 200'", like
=> '/HTTP OK:/' },
59 { cmd
=> "/bin/su - $site -c 'lib/nagios/plugins/check_http -t 20 -H localhost -u /$site/thruk -e 401'", like
=> '/HTTP OK:/' },
60 { cmd
=> "/bin/su - $site -c 'lib/nagios/plugins/check_http -t 60 -H localhost -a omdadmin:omd -u /$site/thruk -e 301'", like
=> '/HTTP OK:/' },
61 { cmd
=> "/bin/su - $site -c 'lib/nagios/plugins/check_http -t 60 -H localhost -a omdadmin:omd -u /$site/thruk/ -e 200'", like
=> '/HTTP OK:/' },
62 { cmd
=> "/bin/su - $site -c 'lib/nagios/plugins/check_http -t 20 -H localhost -a omdadmin:omd -u \"/$site/thruk/cgi-bin/status.cgi?hostgroup=all&style=hostdetail\" -e 200 -r \"Host Status Details For All Host Groups\"'", like
=> '/HTTP OK:/' },
63 { cmd
=> "/bin/su - $site -c 'lib/nagios/plugins/check_http -t 20 -H localhost -a omdadmin:omd -u \"/$site/thruk/cgi-bin/tac.cgi\" -e 200 -r \"Logged in as <i>omdadmin<\/i>\"'", like
=> '/HTTP OK:/' },
64 { cmd
=> "/bin/su - $site -c './bin/thruk -l'", like
=> "/$site/" },
65 { cmd
=> "/bin/su - $site -c './bin/thruk -l --local'", like
=> "/$site/" },
66 { cmd
=> "/bin/su - $site -c './bin/naglint ./etc/nagios/conf.d/commands.cfg'", like
=> "/check_local_load/" },
70 { cmd
=> "/bin/su - $site -c './etc/init.d/thruk restart'", like
=> '/\([\d\ ]+\)\ OK/' },
73 { cmd
=> "/bin/su - $site -c './etc/init.d/thruk restart'", like
=> '/only available for apaches/', exit => 1 },
76 for my $report (@
{$reports}) {
78 for my $key (keys %{$report}) {
79 for my $val (ref $report->{$key} eq 'ARRAY' ? @
{$report->{$key}} : $report->{$key}) {
80 push @
{$args}, $key.'='.$val;
84 { cmd
=> "/bin/su - $site -c './bin/thruk -A omdadmin \"/thruk/cgi-bin/reports2.cgi?action=save&report=9999&".join('&', @
{$args})."\"'",
85 like
=> "/OK - report updated/" },
86 { cmd
=> "/bin/su - $site -c 'omd reload crontab'", like
=> [ '/OK/' ] },
87 { cmd
=> "/bin/su - $site -c '/usr/bin/crontab -l | grep -i thruk | grep -v cron.d'", like
=> [ '/9999/' ] },
88 { cmd
=> "/bin/su - $site -c './bin/thruk -a report=9999 --local'", like
=> [ '/%PDF\-1\.4/', '/%%EOF/' ] },
89 { cmd
=> "/bin/su - $site -c './bin/thruk -A omdadmin \"/thruk/cgi-bin/reports2.cgi?action=remove&report=9999\"'", like
=> '/OK - report removed/' },
96 { url
=> "/thruk/side.html", like
=> '/<title>Thruk<\/title>/' },
97 { url
=> "", like
=> '/<title>Thruk<\/title>/' },
98 { url
=> "/thruk/index.html", like
=> '/<title>Thruk<\/title>/' },
99 { url
=> "/thruk/docs/index.html", like
=> '/<title>Documentation<\/title>/' },
100 { url
=> "/thruk/main.html", like
=> '/<title>Thruk Monitoring Webinterface<\/title>/' },
103 { url
=> '/thruk/cgi-bin/avail.cgi', 'like' => '/Availability Report/' },
104 { url
=> '/thruk/cgi-bin/avail.cgi?host='.$host.'&timeperiod=last7days&smon=1&sday=13&syear=2010&shour=0&smin=0&ssec=0&emon=1&eday=14&eyear=2010&ehour=24&emin=0&esec=0&rpttimeperiod=&assumeinitialstates=yes&assumestateretention=yes&assumestatesduringnotrunning=yes&includesoftstates=no&initialassumedservicestate=0&backtrack=4', 'like' => '/Availability Report/' },
107 { url
=> '/thruk/cgi-bin/extinfo.cgi?type=1&host='.$host },
108 { url
=> '/thruk/cgi-bin/extinfo.cgi?type=2&host='.$host.'&service='.$service },
111 { url
=> '/thruk/cgi-bin/config.cgi', 'like' => '/Configuration/' },
112 { url
=> '/thruk/cgi-bin/config.cgi?type=hosts', 'like' => '/Configuration/' },
113 { url
=> '/thruk/cgi-bin/config.cgi?type=services', 'like' => '/Configuration/' },
116 { url
=> '/thruk/cgi-bin/history.cgi', like
=> '/Alert History/' },
117 { url
=> '/thruk/cgi-bin/history.cgi?host=all', like
=> '/Alert History/' },
118 { url
=> '/thruk/cgi-bin/history.cgi?host='.$host, like
=> '/Alert History/' },
119 { url
=> '/thruk/cgi-bin/history.cgi?host='.$host.'&service='.$service, like
=> '/Alert History/' },
122 { url
=> '/thruk/cgi-bin/notifications.cgi', like
=> '/All Hosts and Services/' },
125 { url
=> '/thruk/cgi-bin/outages.cgi', like
=> '/Network Outages/' },
128 { url
=> '/thruk/cgi-bin/showlog.cgi', like
=> '/Event Log/' },
131 { url
=> '/thruk/cgi-bin/status.cgi', like
=> '/Current Network Status/' },
132 { url
=> '/thruk/cgi-bin/status.cgi?host='.$host, like
=> '/Current Network Status/' },
135 { url
=> '/thruk/cgi-bin/summary.cgi', like
=> '/Alert Summary Report/' },
138 { url
=> '/thruk/cgi-bin/tac.cgi', like
=> '/Tactical Monitoring Overview/' },
141 { url
=> '/thruk/cgi-bin/trends.cgi?host='.$host.'&t1=1264820912&t2=1265425712&includesoftstates=no&assumestateretention=yes&assumeinitialstates=yes&assumestatesduringnotrunning=yes&initialassumedhoststate=0&backtrack=4', 'like' => '/Host and Service State Trends/' },
142 { url
=> '/thruk/cgi-bin/trends.cgi?host='.$host.'&service='.$service.'&t1=1264820912&t2=1265425712&includesoftstates=no&assumestateretention=yes&assumeinitialstates=yes&assumestatesduringnotrunning=yes&initialassumedservicestate=0&backtrack=4', 'like' => '/Host and Service State Trends/' },
145 { url
=> '/thruk/cgi-bin/statusmap.cgi?host=all', like
=> '/Network Map/' },
148 { url
=> '/thruk/cgi-bin/minemap.cgi', like
=> '/Mine Map/' },
151 { url
=> '/thruk/cgi-bin/conf.cgi', like
=> '/Config Tool/' },
152 { url
=> '/thruk/cgi-bin/conf.cgi?sub=thruk', like
=> [ '/Config Tool/', '/title_prefix/', '/use_wait_feature/'] },
153 { url
=> '/thruk/cgi-bin/conf.cgi?sub=cgi', like
=> [ '/Config Tool/', '/show_context_help/', '/use_pending_states/' ] },
154 { url
=> '/thruk/cgi-bin/conf.cgi?sub=users', like
=> [ '/Config Tool/', '/select user to change/' ] },
155 { url
=> '/thruk/cgi-bin/conf.cgi?sub=users&action=change&data.username=omdadmin', like
=> [ '/Config Tool/', '/remove password/', '/authorized_for_all_services/' ] },
156 { url
=> '/thruk/cgi-bin/conf.cgi?sub=objects', like
=> [ '/Config Tool/', '/select host to change/' ] },
157 { url
=> '/thruk/cgi-bin/conf.cgi?sub=objects&apply=yes', like
=> [ '/Config Tool/', '/There are no pending changes to commit/' ] },
158 { url
=> '/thruk/cgi-bin/conf.cgi?sub=objects&type=host&data.name=generic-host', like
=> [ '/Config Tool/', '/Template:\s+generic\-host/', '/templates.cfg/' ], skip_html_links
=> 1 },
159 { url
=> '/thruk/cgi-bin/conf.cgi?sub=objects&action=browser', like
=> [ '/Config Tool/', '/commands.cfg/' ] },
162 { url
=> '/thruk/cgi-bin/reports2.cgi', like
=> '/Reporting/' },
163 { url
=> '/thruk/cgi-bin/reports2.cgi?action=save&report=9999&name=Service%20SLA%20Report%20for%20'.$host.'%20-%20'.$service.'&template=sla_service.tt¶ms.sla=95¶ms.timeperiod=last12months¶ms.host='.$host.'¶ms.service='.$service.'¶ms.breakdown=months¶ms.unavailable=critical¶ms.unavailable=unknown¶ms.decimals=2¶ms.graph_min_sla=90', like
=> '/success_message/' },
164 { url
=> '/thruk/cgi-bin/reports2.cgi?report=9999&action=update' },
165 { url
=> '/thruk/cgi-bin/reports2.cgi', waitfor
=> 'reports2.cgi\?report=9999\&refresh=0' },
166 { url
=> '/thruk/cgi-bin/reports2.cgi?report=9999', like
=> [ '/%PDF-1.4/', '/%%EOF/' ] },
167 { url
=> '/thruk/cgi-bin/reports2.cgi?action=remove&report=9999', like
=> '/report removed/' },
169 # recurring downtimes
170 { url
=> '/thruk/cgi-bin/extinfo.cgi?type=6&recurring=save&target=host&host='.$host.'&comment=automatic+downtime&send_type_1=month&send_day_1=1&week_day_1=&send_hour_1=0&send_minute_1=0&duration=120&childoptions=0&nr=999', like
=> '/recurring downtime saved/' },
171 { url
=> '/thruk/cgi-bin/extinfo.cgi?type=6&target=host&recurring=remove&nr=999&host='.$host, like
=> '/recurring downtime removed/' },
176 { url
=> '/thruk/cgi-bin/bp.cgi?action=new&bp_label=New Test Business Process', like
=> '/New Test Business Process/', skip_link_check
=> ['.cgi'] },
177 { url
=> '/thruk/cgi-bin/bp.cgi?action=commit&bp=1', follow
=> 1, like
=> '/New Test Business Process/', skip_link_check
=> ['.cgi'] },
178 { url
=> '/thruk/cgi-bin/status.cgi', waitfor
=> 'New\ Test\ Business\ Process' },
179 { url
=> '/thruk/cgi-bin/bp.cgi?action=remove&bp=1', follow
=> 1, skip_link_check
=> ['.cgi'] },
184 { url
=> '/thruk/cgi-bin/bp.cgi?action=new&bp_label=New Test Business Process', like
=> '/New Test Business Process/', skip_link_check
=> ['.cgi'] },
185 { url
=> '/thruk/cgi-bin/bp.cgi?action=commit&bp=1', follow
=> 1, like
=> '/New Test Business Process/', skip_link_check
=> ['.cgi'] },
186 { url
=> '/thruk/cgi-bin/bp.cgi?action=remove&bp=1', follow
=> 1, skip_link_check
=> ['.cgi'] },
190 { url
=> '/thruk/cgi-bin/tac.cgi', follow
=> 1, like
=> '/Password/' },
195 for my $url ( @
{$urls}, @
{$shared_urls}, @
{$own_urls}, @
{$cookie_urls} ) {
196 $url->{'url'} = "http://localhost/".$site.$url->{'url'};
197 $url->{'auth'} = $auth;
198 $url->{'unlike'} = [ '/internal server error/', '/"\/thruk\//', '/\'\/thruk\//' ];
201 for my $core (qw
/nagios shinken icinga/) {
202 ##################################################
204 TestUtils
::test_command
({ cmd
=> $omd_bin." stop $site" });
205 TestUtils
::test_command
({ cmd
=> $omd_bin." config $site set CORE $core" });
206 TestUtils
::test_command
({ cmd
=> $omd_bin." config $site set APACHE_MODE own" });
207 TestUtils
::test_command
({ cmd
=> TestUtils
::config
('APACHE_INIT')." restart" });
208 TestUtils
::test_command
({ cmd
=> $omd_bin." start $site" }) or TestUtils
::bail_out_clean
("No need to test Thruk without proper startup");
209 TestUtils
::wait_for_file
("/omd/sites/$site/tmp/run/live") or TestUtils
::bail_out_clean
("No need to test Thruk without livestatus connection");
210 unlink("/omd/sites/$site/tmp/thruk/thruk.cache");
211 unlink("/omd/sites/$site/var/thruk/obj_retention.dat");
213 TestUtils
::test_command
({ cmd
=> "/bin/su - $site -c './lib/nagios/plugins/check_http -H localhost -a omdadmin:omd -u /$site/thruk/cgi-bin/cmd.cgi -e 200 -P \"cmd_typ=7&cmd_mod=2&host=omd-$site&service=Dummy+Service&start_time=2010-11-06+09%3A46%3A02&force_check=on&btnSubmit=Commit\" -r \"Your command request was successfully submitted\"'", like
=> '/HTTP OK:/' });
214 TestUtils
::wait_for_file
("/omd/sites/$site/var/pnp4nagios/perfdata/omd-$site/Dummy_Service_omd-dummy.rrd") or TestUtils
::bail_out_clean
("No need to test Thruk without working pnp");;
216 for my $test (@
{$tests}) {
217 TestUtils
::test_command
($test);
219 for my $test (@
{$own_tests}) {
220 TestUtils
::test_command
($test);
222 ##################################################
223 # and request some pages
224 for my $url ( @
{$urls} ) {
225 TestUtils
::test_url
($url);
227 for my $url ( @
{$own_urls} ) {
228 TestUtils
::test_url
($url);
231 ##################################################
232 # switch webserver to shared mode
233 TestUtils
::test_command
({ cmd
=> $omd_bin." stop $site" });
234 TestUtils
::test_command
({ cmd
=> $omd_bin." config $site set APACHE_MODE shared" });
235 TestUtils
::test_command
({ cmd
=> TestUtils
::config
('APACHE_INIT')." restart" });
236 TestUtils
::test_command
({ cmd
=> $omd_bin." start $site" });
238 ##################################################
239 # then run tests again
240 for my $test (@
{$tests}) {
241 TestUtils
::test_command
($test);
243 for my $test (@
{$shared_tests}) {
244 TestUtils
::test_command
($test);
246 ##################################################
247 # and request some pages
248 for my $url ( @
{$urls} ) {
249 TestUtils
::test_url
($url);
251 for my $url ( @
{$shared_urls} ) {
252 TestUtils
::test_url
($url);
255 my $log = "/omd/sites/$site/var/log/thruk.log";
256 my $tlog = '/tmp/thruk_test_error.log';
257 is
(-f
$log, 1, "log exists");
259 `/bin/cat $log | /bin/grep -v 'cmd: COMMAND' | /bin/grep -v ' started ' | /bin/grep -v 'templates precompiled in' > $tlog 2>&1`;
260 is
(-s
$tlog, 0, "log is empty") or diag
(Dumper
(`cat $log`));
264 ##################################################
266 TestUtils
::test_command
({ cmd
=> $omd_bin." stop $site" });
267 TestUtils
::test_command
({ cmd
=> $omd_bin." config $site set CORE nagios" });
268 TestUtils
::test_command
({ cmd
=> $omd_bin." config $site set APACHE_MODE own" });
269 TestUtils
::test_command
({ cmd
=> $omd_bin." config $site set THRUK_COOKIE_AUTH on" });
270 TestUtils
::test_command
({ cmd
=> $omd_bin." start $site", like
=> '/OK/' });
271 TestUtils
::test_command
({ cmd
=> TestUtils
::config
('APACHE_INIT')." restart" });
272 TestUtils
::test_command
({ cmd
=> $omd_bin." start $site thruk", like
=> '/OK/' });
274 TestUtils
::test_command
({ cmd
=> $omd_bin." status $site apache", like
=> '/running/' });
275 for my $url ( @
{$cookie_urls} ) {
276 TestUtils
::test_url
($url);
279 ##################################################
281 TestUtils
::test_command
({ cmd
=> TestUtils
::config
('APACHE_INIT')." restart" });
282 TestUtils
::remove_test_site
($site);