nagios4/t/705nagiostats.t

38 lines
1.3 KiB
Perl
Raw Normal View History

2017-05-19 22:22:40 +02:00
#!/usr/bin/perl
#
# Checks nagiostats
use warnings;
use strict;
use Test::More;
use FindBin qw($Bin);
chdir $Bin or die "Cannot chdir";
my $topdir = "$Bin/..";
my $nagiostats = "$topdir/base/nagiostats";
my $etc = "$Bin/etc";
2017-05-19 23:37:19 +02:00
my $var = "$Bin/var";
2017-05-19 22:22:40 +02:00
2017-05-19 23:37:19 +02:00
plan tests => 10;
2017-05-19 22:22:40 +02:00
2017-05-19 23:37:19 +02:00
my $output = `$nagiostats -c "$etc/nagios-does-not-exist.cfg"`;
2017-05-19 22:22:40 +02:00
isnt( $?, 0, "Bad return code with no config file" );
like( $output, "/Error processing config file/", "No config file" );
$output = `$nagiostats -c "$etc/nagios-no-status.cfg"`;
isnt( $?, 0, "Bad return code with no status file" );
2017-05-19 23:37:19 +02:00
like( $output, "/Error reading status file '.*var/status.dat.no.such.file': No such file or directory/", "No config file" );
2017-05-19 22:22:40 +02:00
2017-05-19 23:37:19 +02:00
$output = `$nagiostats -c "$etc/nagios-no-status.cfg" -m -d NUMHSTUP`;
2017-05-19 22:22:40 +02:00
isnt( $?, 0, "Bad return code with no status file in MRTG mode" );
2017-05-19 23:37:19 +02:00
like( $output, "/^0\$/", "No UP host when no status file" );
2017-05-19 22:22:40 +02:00
2017-05-19 23:37:19 +02:00
$output = `$nagiostats -c "$etc/nagios-with-generated-status.cfg" -m -d NUMHOSTS`;
is( $?, 0, "Bad return code with implied status file in MRTG mode" );
unlike( $output, "/^0\$/", "Implied generated status file contains host(s)" );
$output = `$nagiostats -s "$var/status-generated.dat" -m -d NUMHOSTS`;
is( $?, 0, "Bad return code with explicit status file in MRTG mode" );
unlike( $output, "/^0\$/", "Explicit generated status file contains host(s)" );