13 use lib
"$FindBin::Bin/lib/lib/perl5";
16 plan
( tests
=> 2857 );
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";
25 my $servicep= "Dummy Service";
27 # create test host/service
28 TestUtils
::prepare_obj_config
('t/data/omd/testconf1', '/omd/sites/'.$site.'/etc/nagios/conf.d', $site);
30 # decrease pnp interval
31 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" });
33 # set thruk as default
34 TestUtils
::test_command
({ cmd
=> $omd_bin." config $site set DEFAULT_GUI thruk" });
35 TestUtils
::test_command
({ cmd
=> $omd_bin." start $site" });
37 # set token for post requests
38 push @INC, '/omd/sites/'.$site.'/share/thruk/lib';
39 use_ok
('Thruk::Utils::Cache');
40 use_ok
('Thruk::Config');
41 set_test_user_token
();
47 'template' => 'sla_host.tt',
49 'params.timeperiod' => 'last12months',
50 'params.host' => $host,
51 'params.breakdown' => 'months',
52 'params.unavailable' => [ 'down', 'unreachable' ],
53 'params.graph_min_sla' => 90,
54 'params.decimals' => 2,
55 'send_type_1' => 'month',
63 ##################################################
66 { 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:/' },
67 { cmd
=> "/bin/su - $site -c 'lib/nagios/plugins/check_http -t 20 -H localhost -u /$site/thruk -e 401'", like
=> '/HTTP OK:/' },
68 { 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:/' },
69 { 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:/' },
70 { 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:/' },
71 { 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:/' },
72 { cmd
=> "/bin/su - $site -c './bin/thruk -l'", like
=> "/$site/" },
73 { cmd
=> "/bin/su - $site -c './bin/thruk -l --local'", like
=> "/$site/" },
74 { cmd
=> "/bin/su - $site -c './bin/naglint ./etc/nagios/conf.d/commands.cfg'", like
=> "/check_local_load/" },
78 { cmd
=> "/bin/su - $site -c './etc/init.d/thruk restart'", like
=> '/\([\d\ ]+\)\ OK/' },
81 { cmd
=> "/bin/su - $site -c './etc/init.d/thruk restart'", like
=> '/only available for apaches/', exit => 1 },
84 for my $report (@
{$reports}) {
86 for my $key (keys %{$report}) {
87 for my $val (ref $report->{$key} eq 'ARRAY' ? @
{$report->{$key}} : $report->{$key}) {
88 push @
{$args}, $key.'='.$val;
92 { cmd
=> "/bin/su - $site -c './bin/thruk -A omdadmin \"/thruk/cgi-bin/reports2.cgi?action=save&report=9999&".join('&', @
{$args})."\"'",
93 like
=> "/OK - report updated/" },
94 { cmd
=> "/bin/su - $site -c 'omd reload crontab'", like
=> [ '/OK/' ] },
95 { cmd
=> "/bin/su - $site -c '/usr/bin/crontab -l | grep -i thruk | grep -v cron.d'", like
=> [ '/9999/' ] },
96 { cmd
=> "/bin/su - $site -c './bin/thruk -a report=9999 --local'", like
=> [ '/%PDF\-1\.4/', '/%%EOF/' ] },
97 { cmd
=> "/bin/su - $site -c './bin/thruk -A omdadmin \"/thruk/cgi-bin/reports2.cgi?action=remove&report=9999\"'", like
=> '/OK - report removed/' },
104 { url
=> "/thruk/side.html", like
=> '/<title>Thruk<\/title>/' },
105 { url
=> "", like
=> '/<title>Thruk<\/title>/' },
106 { url
=> "/thruk/index.html", like
=> '/<title>Thruk<\/title>/' },
107 { url
=> "/thruk/startup.html", like
=> '/<title>Thruk Monitoring Webinterface<\/title>/' },
108 { url
=> "/thruk/docs/index.html", like
=> '/<title>Documentation<\/title>/' },
109 { url
=> "/thruk/main.html", like
=> '/<title>Thruk Monitoring Webinterface<\/title>/' },
112 { url
=> '/thruk/cgi-bin/avail.cgi', 'like' => '/Availability Report/' },
113 { 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/' },
116 { url
=> '/thruk/cgi-bin/extinfo.cgi?type=1&host='.$host },
117 { url
=> '/thruk/cgi-bin/extinfo.cgi?type=2&host='.$host.'&service='.$service },
120 { url
=> '/thruk/cgi-bin/config.cgi', 'like' => '/Configuration/' },
121 { url
=> '/thruk/cgi-bin/config.cgi?type=hosts', 'like' => '/Configuration/' },
122 { url
=> '/thruk/cgi-bin/config.cgi?type=services', 'like' => '/Configuration/' },
125 { url
=> '/thruk/cgi-bin/history.cgi', like
=> '/Alert History/' },
126 { url
=> '/thruk/cgi-bin/history.cgi?host=all', like
=> '/Alert History/' },
127 { url
=> '/thruk/cgi-bin/history.cgi?host='.$host, like
=> '/Alert History/' },
128 { url
=> '/thruk/cgi-bin/history.cgi?host='.$host.'&service='.$service, like
=> '/Alert History/' },
131 { url
=> '/thruk/cgi-bin/notifications.cgi', like
=> '/All Hosts and Services/' },
134 { url
=> '/thruk/cgi-bin/outages.cgi', like
=> '/Network Outages/' },
137 { url
=> '/thruk/cgi-bin/showlog.cgi', like
=> '/Event Log/' },
140 { url
=> '/thruk/cgi-bin/status.cgi', like
=> '/Current Network Status/' },
141 { url
=> '/thruk/cgi-bin/status.cgi?host='.$host, like
=> '/Current Network Status/' },
144 { url
=> '/thruk/cgi-bin/summary.cgi', like
=> '/Alert Summary Report/' },
147 { url
=> '/thruk/cgi-bin/tac.cgi', like
=> '/Tactical Monitoring Overview/' },
150 { 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/' },
151 { 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/' },
154 { url
=> '/thruk/cgi-bin/statusmap.cgi?host=all', like
=> '/Network Map/' },
157 { url
=> '/thruk/cgi-bin/minemap.cgi', like
=> '/Mine Map/' },
160 { url
=> '/thruk/cgi-bin/conf.cgi', like
=> '/Config Tool/' },
161 { url
=> '/thruk/cgi-bin/conf.cgi?sub=thruk', like
=> [ '/Config Tool/', '/title_prefix/', '/use_wait_feature/'] },
162 { url
=> '/thruk/cgi-bin/conf.cgi?sub=cgi', like
=> [ '/Config Tool/', '/show_context_help/', '/use_pending_states/' ] },
163 { url
=> '/thruk/cgi-bin/conf.cgi?sub=users', like
=> [ '/Config Tool/', '/select user to change/' ] },
164 { url
=> '/thruk/cgi-bin/conf.cgi?sub=users&action=change&data.username=omdadmin', like
=> [ '/Config Tool/', '/remove password/', '/authorized_for_all_services/' ] },
165 { url
=> '/thruk/cgi-bin/conf.cgi?sub=objects', like
=> [ '/Config Tool/', '/select host to change/' ] },
166 { url
=> '/thruk/cgi-bin/conf.cgi?sub=objects&apply=yes', like
=> [ '/Config Tool/', '/There are no pending changes to commit/' ] },
167 { 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 },
168 { url
=> '/thruk/cgi-bin/conf.cgi?sub=objects&action=browser', like
=> [ '/Config Tool/', '/commands.cfg/' ] },
171 { url
=> '/thruk/cgi-bin/reports2.cgi', like
=> '/Reporting/' },
172 { url
=> '/thruk/cgi-bin/reports2.cgi', post
=> { 'action' => 'save', 'report' => '9999', 'name' => 'Service SLA Report for '.$host.' - '.$servicep, 'template' => 'sla_service.tt', 'params.sla' => 95, 'params.timeperiod' => 'last12months', 'params.host' => $host, 'params.service' => $servicep, 'params.breakdown' => 'months', 'params.unavailable' => ['critical', 'unknown' ], 'params.decimals' => 2, 'params.graph_min_sla' => 90 }, like
=> '/success_message/' },
173 { url
=> '/thruk/cgi-bin/reports2.cgi?report=9999&action=update' },
174 { url
=> '/thruk/cgi-bin/reports2.cgi', waitfor
=> 'reports2.cgi\?report=9999\&refresh=0' },
175 { url
=> '/thruk/cgi-bin/reports2.cgi?report=9999', like
=> [ '/%PDF-1.4/', '/%%EOF/' ] },
176 { url
=> '/thruk/cgi-bin/reports2.cgi', post
=> { 'action' => 'remove', 'report' => 9999 }, like
=> '/report removed/' },
178 # recurring downtimes
179 { url
=> '/thruk/cgi-bin/extinfo.cgi', post
=> { '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/' },
180 { url
=> '/thruk/cgi-bin/extinfo.cgi', post
=> { 'type' => 6, 'target' => 'host', 'recurring' => 'remove', 'nr' => 999, 'host' => $host }, like
=> '/recurring downtime removed/' },
182 # usercontent examples
183 { url
=> '/thruk/usercontent/backgrounds/world.png', like
=> '/PNG/' },
188 { url
=> '/thruk/cgi-bin/bp.cgi?action=new&bp_label=New Test Business Process', like
=> '/New Test Business Process/', skip_link_check
=> ['.cgi'] },
189 { url
=> '/thruk/cgi-bin/bp.cgi', post
=> { 'action' => 'commit', 'bp' => 1 }, like
=> '/New Test Business Process/', skip_link_check
=> ['.cgi'] },
190 { url
=> '/thruk/cgi-bin/status.cgi', waitfor
=> 'New\ Test\ Business\ Process' },
191 { url
=> '/thruk/cgi-bin/bp.cgi', post
=> { 'action' => 'remove', 'bp' => 1 }, skip_link_check
=> ['.cgi'] },
196 { url
=> '/thruk/cgi-bin/bp.cgi?action=new&bp_label=New Test Business Process', like
=> '/New Test Business Process/', skip_link_check
=> ['.cgi'] },
197 { url
=> '/thruk/cgi-bin/bp.cgi', post
=> { 'action' => 'commit', 'bp' => 1 }, like
=> '/New Test Business Process/', skip_link_check
=> ['.cgi'] },
198 { url
=> '/thruk/cgi-bin/bp.cgi', post
=> { 'action' => 'remove', 'bp' => 1 }, skip_link_check
=> ['.cgi'] },
202 { url
=> '/thruk/cgi-bin/tac.cgi', like
=> '/Password/', unlike
=> [ '/internal server error/'] },
207 for my $url ( @
{$urls}, @
{$shared_urls}, @
{$own_urls}, @
{$cookie_urls} ) {
208 $url->{'url'} = "http://localhost/".$site.$url->{'url'};
209 $url->{'auth'} = $auth;
210 $url->{'unlike'} = [ '/internal server error/', '/"\/thruk\//', '/\'\/thruk\//' ] unless defined $url->{'unlike'};
212 $url->{'post'}->{'token'} = 'test';
216 for my $core (qw
/nagios shinken icinga/) {
217 ##################################################
219 TestUtils
::test_command
({ cmd
=> $omd_bin." stop $site" });
220 TestUtils
::test_command
({ cmd
=> $omd_bin." config $site set CORE $core" });
221 TestUtils
::test_command
({ cmd
=> $omd_bin." config $site set APACHE_MODE own" });
222 TestUtils
::restart_system_apache
();
223 unlink("/omd/sites/$site/tmp/run/live");
224 TestUtils
::test_command
({ cmd
=> $omd_bin." start $site" }) or TestUtils
::bail_out_clean
("No need to test Thruk without proper startup");
225 TestUtils
::wait_for_file
("/omd/sites/$site/tmp/run/live") or TestUtils
::bail_out_clean
("No need to test Thruk without livestatus connection");
226 unlink("/omd/sites/$site/tmp/thruk/thruk.cache");
227 unlink("/omd/sites/$site/var/thruk/obj_retention.dat");
229 TestUtils
::test_command
({ cmd
=> "/bin/su - $site -c './bin/thruk -A omdadmin \"cmd.cgi?cmd_typ=7&cmd_mod=2&host=omd-$site&service=Dummy+Service&start_time=now&force_check=on&btnSubmit=Commit\" --local'", like
=> '/Command request successfully submitted/', errlike
=> '/cmd: COMMAND/' });
230 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");;
232 for my $test (@
{$tests}) {
233 TestUtils
::test_command
($test);
235 for my $test (@
{$own_tests}) {
236 TestUtils
::test_command
($test);
238 ##################################################
239 # and request some pages
240 for my $url ( @
{$urls} ) {
241 TestUtils
::test_url
($url);
243 for my $url ( @
{$own_urls} ) {
244 TestUtils
::test_url
($url);
247 ##################################################
248 # switch webserver to shared mode
249 TestUtils
::test_command
({ cmd
=> $omd_bin." stop $site" });
250 TestUtils
::test_command
({ cmd
=> $omd_bin." config $site set APACHE_MODE shared" });
251 TestUtils
::restart_system_apache
();
252 unlink("/omd/sites/$site/tmp/run/live");
253 TestUtils
::test_command
({ cmd
=> $omd_bin." start $site" });
254 TestUtils
::wait_for_file
("/omd/sites/$site/tmp/run/live") or TestUtils
::bail_out_clean
("No need to test Thruk without livestatus connection");
256 ##################################################
257 # then run tests again
258 for my $test (@
{$tests}) {
259 TestUtils
::test_command
($test);
261 for my $test (@
{$shared_tests}) {
262 TestUtils
::test_command
($test);
264 ##################################################
265 # and request some pages
266 for my $url ( @
{$urls} ) {
267 TestUtils
::test_url
($url);
269 for my $url ( @
{$shared_urls} ) {
270 TestUtils
::test_url
($url);
273 my $log = "/omd/sites/$site/var/log/thruk.log";
274 my $tlog = '/tmp/thruk_test_error.log';
275 is
(-f
$log, 1, "log exists");
277 `/bin/cat $log | /bin/grep -v 'cmd: COMMAND' | /bin/grep -v ' started ' | /bin/grep -v 'templates precompiled in' > $tlog 2>&1`;
278 is
(-s
$tlog, 0, "log is empty") or diag
(Dumper
(`cat $log`));
282 ##################################################
284 TestUtils
::test_command
({ cmd
=> $omd_bin." stop $site" });
285 TestUtils
::test_command
({ cmd
=> $omd_bin." config $site set CORE nagios" });
286 TestUtils
::test_command
({ cmd
=> $omd_bin." config $site set APACHE_MODE own" });
287 TestUtils
::test_command
({ cmd
=> $omd_bin." config $site set THRUK_COOKIE_AUTH on" });
288 unlink("/omd/sites/$site/tmp/run/live");
289 TestUtils
::test_command
({ cmd
=> $omd_bin." start $site", like
=> '/OK/' });
290 TestUtils
::wait_for_file
("/omd/sites/$site/tmp/run/live") or TestUtils
::bail_out_clean
("No need to test Thruk without livestatus connection");
291 TestUtils
::restart_system_apache
();
292 TestUtils
::test_command
({ cmd
=> $omd_bin." start $site thruk", like
=> '/OK/' });
294 TestUtils
::test_command
({ cmd
=> $omd_bin." status $site apache", like
=> '/running/' });
295 for my $url ( @
{$cookie_urls} ) {
296 TestUtils
::test_url
($url);
299 ##################################################
301 TestUtils
::restart_system_apache
();
302 TestUtils
::remove_test_site
($site);
305 ##################################################
306 sub set_test_user_token
{
307 my $file = '/omd/sites/'.$site.'/var/thruk/token';
308 local $ENV{'THRUK_CONFIG'} = '/omd/sites/'.$site.'/etc/thruk/';
309 my $config = Thruk
::Config
::get_config
();
310 my $store = Thruk
::Utils
::Cache
->new($file);
311 my $tokens = $store->get('token');
312 $tokens->{'omdadmin'} = { token
=> 'test', time => time() };
313 $store->set('token', $tokens);
314 `chown $site:$site $file`;
315 ok
(-s
$file, $file." exists") or TestUtils
::bail_out_clean
("no further testing without token");