2017-05-19 22:22:40 +02:00
|
|
|
#!/usr/bin/perl
|
|
|
|
#
|
|
|
|
# Checks for status.cgi
|
|
|
|
|
|
|
|
use warnings;
|
|
|
|
use strict;
|
|
|
|
use Test::More;
|
|
|
|
use FindBin qw($Bin);
|
|
|
|
|
|
|
|
chdir $Bin or die "Cannot chdir";
|
|
|
|
|
|
|
|
my $topdir = "$Bin/..";
|
|
|
|
my $cgi_dir = "$topdir/cgi";
|
|
|
|
my $cgi = "$cgi_dir/status.cgi";
|
|
|
|
|
|
|
|
my $output;
|
|
|
|
|
2017-05-19 23:37:19 +02:00
|
|
|
plan tests => 9;
|
2017-05-19 22:22:40 +02:00
|
|
|
|
|
|
|
my $numhosts;
|
|
|
|
|
|
|
|
$output = `NAGIOS_CGI_CONFIG=etc/cgi.cfg REMOTE_USER=nagiosadmin REQUEST_METHOD=GET QUERY_STRING=host=all $cgi`;
|
|
|
|
like( $output, '/status.cgi\?host=all&sorttype=1&sortoption=1/', "Host value should be set to all if host=all passed in" );
|
|
|
|
|
|
|
|
# Bit of a hacky way to count number of hosts
|
|
|
|
$numhosts = grep /title=/, split("\n", $output);
|
|
|
|
|
|
|
|
ok( $numhosts > 1, "Got $numhosts hosts, which is more than 1");
|
|
|
|
|
|
|
|
$output = `NAGIOS_CGI_CONFIG=etc/cgi.cfg REMOTE_USER=nagiosadmin REQUEST_METHOD=GET QUERY_STRING=host=host1 $cgi`;
|
|
|
|
like( $output, '/status.cgi\?host=host1&sorttype=1&sortoption=1/', "Host value should be set to specific host if passed in" );
|
2017-05-19 23:37:19 +02:00
|
|
|
like( $output, '/1 Matching Services/', "Found the one host" );
|
2017-05-19 22:22:40 +02:00
|
|
|
|
|
|
|
$output = `NAGIOS_CGI_CONFIG=etc/cgi.cfg REMOTE_USER=nagiosadmin REQUEST_METHOD=GET QUERY_STRING=host= $cgi`;
|
|
|
|
like( $output, '/status.cgi\?host=&sorttype=1&sortoption=1/', "Host value kept as blank if set to blank" );
|
2017-05-19 23:37:19 +02:00
|
|
|
like( $output, '/0 Matching Services/', "Got no hosts because looking for a blank name" );
|
2017-05-19 22:22:40 +02:00
|
|
|
|
|
|
|
$output = `NAGIOS_CGI_CONFIG=etc/cgi.cfg REMOTE_USER=nagiosadmin REQUEST_METHOD=GET $cgi`;
|
|
|
|
like( $output, '/status.cgi\?host=all&sorttype=1&sortoption=1/', "Host value should be set to all if nothing set initially" );
|
|
|
|
|
|
|
|
$_ = grep /title=/, split("\n", $output);
|
|
|
|
is( $_, $numhosts, "Same number of hosts" );
|
|
|
|
|
2017-05-19 23:37:19 +02:00
|
|
|
$output = `NAGIOS_CGI_CONFIG=etc/cgi.cfg REMOTE_USER=second REQUEST_METHOD=GET QUERY_STRING=host=all $cgi`;
|
|
|
|
like( $output, '/1 Matching Services/', "Got 1 service, as permission only allows one host");
|
|
|
|
|