thruk: update to 2.10
[omd.git] / t / 20-package_pnp4nagios.t
blobf2c67be152ebb60892897785d9d6a15efd55d1e2
1 #!/usr/bin/env perl
3 use warnings;
4 use strict;
5 use Test::More;
6 use File::Copy;
8 BEGIN {
9 use lib('t');
10 require TestUtils;
11 import TestUtils;
12 use FindBin;
13 use lib "$FindBin::Bin/lib/lib/perl5";
16 plan( tests => 153 );
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");
23 # create test host/service
24 TestUtils::prepare_obj_config('t/data/omd/testconf1', '/omd/sites/'.$site.'/etc/nagios/conf.d', $site);
26 # decrease pnp interval
27 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" });
29 ##################################################
30 # prepare initial data
31 TestUtils::test_command({ cmd => $omd_bin." start $site" });
32 # submit a forced check, so we have initial perf data
33 TestUtils::test_command({ cmd => "/bin/su - $site -c './lib/nagios/plugins/check_http -H localhost -a omdadmin:omd -u /$site/nagios/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:/' });
34 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 pnp without existing rrd");;
36 # copy page test config
37 for my $cfg (qw/pages-static-ok.cfg pages-static-err.cfg pages-regex-ok.cfg pages-regex-err.cfg/) {
38 ok(copy("t/data/pnp4nagios/$cfg", "/omd/sites/$site/etc/pnp4nagios/pages/$cfg"), "copy test config $cfg");
41 ##################################################
42 # then execute some checks
43 my $tests = [
44 { cmd => "/bin/su - $site -c 'lib/nagios/plugins/check_http -H localhost -u /$site/pnp4nagios -e 401'", like => '/HTTP OK:/' },
45 { cmd => "/bin/su - $site -c 'lib/nagios/plugins/check_http -H localhost -a omdadmin:omd -u /$site/pnp4nagios -e 301'", like => '/HTTP OK:/' },
46 { cmd => "/bin/su - $site -c 'lib/nagios/plugins/check_http -H localhost -a omdadmin:omd -u /$site/pnp4nagios/index.php -e 302'", like => '/HTTP OK:/' },
47 { cmd => "/bin/su - $site -c 'lib/nagios/plugins/check_http -H localhost -a omdadmin:omd -u /$site/pnp4nagios/graph?host=omd-$site -e 200'", like => '/HTTP OK:/' },
48 { cmd => "/bin/su - $site -c 'lib/nagios/plugins/check_http -H localhost -a omdadmin:omd -u \"/$site/pnp4nagios/graph?host=omd-$site&srv=Dummy+Service\" -e 200'", like => '/HTTP OK:/' },
49 { cmd => "/bin/su - $site -c 'lib/nagios/plugins/check_http -H localhost -a omdadmin:omd -u \"/$site/pnp4nagios/image?host=omd-$site&srv=Dummy+Service\" -e 200'", like => '/HTTP OK:/' },
50 { cmd => "/bin/su - $site -c 'lib/nagios/plugins/check_http -H localhost -a omdadmin:omd -u \"/$site/pnp4nagios/json?host=omd-$site\" -e 200'", like => '/HTTP OK:/' },
51 { cmd => "/bin/su - $site -c 'lib/nagios/plugins/check_http -H localhost -a omdadmin:omd -u \"/$site/pnp4nagios/json?host=omd-$site&srv=Dummy+Service\" -e 200'", like => '/HTTP OK:/' },
52 { cmd => "/bin/su - $site -c 'lib/nagios/plugins/check_http -H localhost -a omdadmin:omd -u \"/$site/pnp4nagios/mobile\" -e 200'", like => '/HTTP OK:/' },
53 { cmd => "/bin/su - $site -c 'lib/nagios/plugins/check_http -H localhost -a omdadmin:omd -u \"/$site/pnp4nagios/mobile/overview\" -e 200'", like => '/HTTP OK:/' },
54 { cmd => "/bin/su - $site -c 'lib/nagios/plugins/check_http -H localhost -a omdadmin:omd -u \"/$site/pnp4nagios/mobile/search\" -e 200'", like => '/HTTP OK:/' },
55 { cmd => "/bin/su - $site -c 'lib/nagios/plugins/check_http -H localhost -a omdadmin:omd -u \"/$site/pnp4nagios/mobile/pages\" -e 200'", like => '/HTTP OK:/' },
56 { cmd => "/bin/su - $site -c 'lib/nagios/plugins/check_http -H localhost -a omdadmin:omd -u \"/$site/pnp4nagios/mobile/host/omd-$site\" -e 200'", like => '/HTTP OK:/' },
57 { cmd => "/bin/su - $site -c 'lib/nagios/plugins/check_http -H localhost -a omdadmin:omd -u \"/$site/pnp4nagios/mobile/host/omd-$site/Dummy+Service\" -e 200'", like => '/HTTP OK:/' },
58 { cmd => "/bin/su - $site -c 'lib/nagios/plugins/check_http -H localhost -a omdadmin:omd -u \"/$site/pnp4nagios/pdf?host=omd-$site&srv=Dummy+Service\" -e 200'", like => '/HTTP OK:/' },
59 #### pages ####
60 { cmd => "/bin/su - $site -c 'lib/nagios/plugins/check_http -H localhost -a omdadmin:omd -u /$site/pnp4nagios/page?page=pages-static-ok -e 200'", like => '/HTTP OK:/' },
61 { cmd => "/bin/su - $site -c 'lib/nagios/plugins/check_http -H localhost -a omdadmin:omd -u /$site/pnp4nagios/page?page=pages-regex-ok -e 200'", like => '/HTTP OK:/' },
62 { cmd => "/bin/su - $site -c 'lib/nagios/plugins/check_http -H localhost -a omdadmin:omd -vvv -u /$site/pnp4nagios/page?page=pages-static-err -e 200'", like => '/ERROR:/' },
63 { cmd => "/bin/su - $site -c 'lib/nagios/plugins/check_http -H localhost -a omdadmin:omd -vvv -u /$site/pnp4nagios/page?page=pages-regex-err -e 200'", like => '/ERROR:/' },
64 { cmd => $omd_bin." stop $site" },
66 for my $test (@{$tests}) {
67 TestUtils::test_command($test);
70 ##################################################
71 # cleanup test site
72 TestUtils::remove_test_site($site);
74 ##################################################
75 # Create test Site for npcd test
77 $site = TestUtils::create_test_site() or TestUtils::bail_out_clean("no further testing without site");
79 # create test host/service
80 TestUtils::prepare_obj_config('t/data/omd/testconf1', '/omd/sites/'.$site.'/etc/nagios/conf.d', $site);
82 # decrease pnp interval
83 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" });
85 ##################################################
86 # prepare initial data
87 TestUtils::test_command({ cmd => $omd_bin." config $site set PNP4NAGIOS npcd" });
88 TestUtils::test_command({ cmd => $omd_bin." start $site" });
89 # submit a forced check, so we have initial perf data
90 TestUtils::test_command({ cmd => "/bin/su - $site -c './lib/nagios/plugins/check_http -H localhost -a omdadmin:omd -u /$site/nagios/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:/' });
91 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 pnp without existing rrd");;
94 ##################################################
95 # then execute some checks
96 $tests = [
97 { cmd => "/bin/su - $site -c 'lib/nagios/plugins/check_http -H localhost -u /$site/pnp4nagios -e 401'", like => '/HTTP OK:/' },
98 { cmd => "/bin/su - $site -c 'lib/nagios/plugins/check_http -H localhost -a omdadmin:omd -u /$site/pnp4nagios -e 301'", like => '/HTTP OK:/' },
99 { cmd => "/bin/su - $site -c 'lib/nagios/plugins/check_http -H localhost -a omdadmin:omd -u /$site/pnp4nagios/index.php -e 302'", like => '/HTTP OK:/' },
100 { cmd => "/bin/su - $site -c 'lib/nagios/plugins/check_http -H localhost -a omdadmin:omd -u /$site/pnp4nagios/graph?host=omd-$site -e 200'", like => '/HTTP OK:/' },
101 { cmd => "/bin/su - $site -c 'lib/nagios/plugins/check_http -H localhost -a omdadmin:omd -u \"/$site/pnp4nagios/graph?host=omd-$site&srv=Dummy+Service\" -e 200'", like => '/HTTP OK:/' },
102 { cmd => "/bin/su - $site -c 'lib/nagios/plugins/check_http -H localhost -a omdadmin:omd -u \"/$site/pnp4nagios/image?host=omd-$site&srv=Dummy+Service\" -e 200'", like => '/HTTP OK:/' },
103 { cmd => $omd_bin." stop $site" },
105 for my $test (@{$tests}) {
106 TestUtils::test_command($test);
109 ##################################################
110 # cleanup test site
111 TestUtils::remove_test_site($site);