File: 90_extreme_tags.t.in

package info (click to toggle)
nagios-plugin-check-multi 0.26-3.1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,156 kB
  • ctags: 37
  • sloc: perl: 2,296; makefile: 415; sh: 239
file content (114 lines) | stat: -rw-r--r-- 3,620 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#! @PERL@ -w -I ..
#
# Process Tests via check_multi
# thanks to Ton Voon for his persistency on testing ;)
#

use strict;
use Test::More;
use FindBin;
use lib "$FindBin::Bin";
use NPTest;
use testopts;

my $t;

#--- add $libexec_dir to PATH to be sure that plugins will be called from libexec_dir
my $libexec_dir="@libexecdir@";
$ENV{PATH}="$libexec_dir:$ENV{PATH}";

#--- check needed plugins for tests
my @plugins=(
	"echo",
	"@PERL@",
);
foreach my $plugin (@plugins) {
	my $path_to_plugin=`which $plugin`; chomp $path_to_plugin;
	if (! -x "$path_to_plugin") {
		plan skip_all => "tests because component $plugin not found or not executable as \'$path_to_plugin\'";
	}
}
if (! -r "@localstatedir@/rw/live") {
	plan skip_all => "tests because live socket \'@localstatedir@/rw/live\' not found or not readable - is @nagios_name@ running and livestatus module loaded?";
}
unless (eval "require Monitoring::Livestatus;1") {
	plan skip_all => "tests because perl module Monitoring::Livestatus is not installed";
}

plan tests => 160;

my $result;
my $testopts=testopts::get_testopts;

#-------------------------------------------------------------------------------
#--- random tags ---------------------------------------------------------------
#-------------------------------------------------------------------------------
my $macrolen=80;
my $valid_tag_chars=`@PERL@ ../check_multi -x 'eval [ chars ] = print "\$opt{set}{valid_tag_chars}\"; exit 0;'`;
print "valid_tag_chars:>>>$valid_tag_chars<<<\n";
my @tag_chars=();
for (my $i=32;$i<256; $i++) {
        if (eval("chr($i)=~/[$valid_tag_chars]+/")) {
                push @tag_chars,chr($i) if (chr($i)!~/\$/);
        }
}
print "tag_chars:>>>".join('',@tag_chars)."<<<\n";
for (my $i=1;$i<=40;$i++) {
	my $tag="";
	for (my $j=0;$j<$macrolen;$j++) {
                $tag.=$tag_chars[int(rand($#tag_chars))];
	}
	$result = NPTest->testCmd(
		"@PERL@ ../check_multi $testopts -s report=1 ".
		" -x 'command [ $tag ] = echo \"$tag\"'",
	);
	is(
	        $result->return_code,
	        0,
		"tag with random character set - RC0 - passed"
	);
	like(
		$result->output,
		"/OK - 1 plugins checked, 1 ok/",
		"$i ($tag)"
	);
}

#-------------------------------------------------------------------------------
#--- random macros -------------------------------------------------------------
#-------------------------------------------------------------------------------
$macrolen=80;
my $valid_macro_chars=`@PERL@ ../check_multi -x 'eval [ chars ] = print "\$opt{set}{valid_macro_chars}\"; exit 0;'`;
print "valid_macro_chars:>>>$valid_macro_chars<<<\n";
my @macro_chars=();
for (my $i=32;$i < 256; $i++) {
        if (eval("chr($i)=~/[$valid_macro_chars]+/")&& $i!=10 && $i!=13) {
                push @macro_chars,chr($i);
        }
}
print "tag_chars:>>>".join('',@macro_chars)."<<<\n";
for (my $i=1;$i<=40;$i++) {
	my $macro="";
	for (my $j=0;$j<$macrolen;$j++) {
                $macro.=$macro_chars[int(rand($#macro_chars))];
	}
	$ENV{CHECK_MULTI_TESTMACRO}="$macro";
	$result = NPTest->testCmd(
		"@PERL@ ../check_multi $testopts -s report=1 ".
		" -x 'command [ macro ] = echo \"\$CHECK_MULTI_TESTMACRO\$\"'",
	);
	is(
	        $result->return_code,
	        0,
		"tag with random character set - RC0 - passed"
	);
	my $regex=$macro;
	#$regex=~s/([^A-Za-z0-9]?)/\\\1/g;
	like(
		$result->output,
		#"/OK - 1 plugins checked, 1 ok\n.*\[ 1\] macro [$valid_macro_chars\$]+/",
		#"/OK - 1 plugins checked, 1 ok.*\] macro [$valid_macro_chars\$]{$macrolen}/",
		"/OK - 1 plugins checked, 1 ok[^\]]*\] macro [$valid_macro_chars\$]{$macrolen}/",
		"$i ($macro)"
	);
}