line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package # hide from PAUSE |
2
|
|
|
|
|
|
|
FakeCollectd; |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
=head1 NAME |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
FakeCollectd - Provides in-place replacement for testing L plugins. |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 SYNOPSIS |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
Used internally by Test::Collectd::Plugins. |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=cut |
13
|
|
|
|
|
|
|
|
14
|
5
|
|
|
5
|
|
4957
|
use Carp qw/croak/; |
|
5
|
|
|
|
|
7
|
|
|
5
|
|
|
|
|
560
|
|
15
|
|
|
|
|
|
|
require Exporter; |
16
|
|
|
|
|
|
|
push @ISA, qw/Exporter/; |
17
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( |
18
|
|
|
|
|
|
|
all => [qw( |
19
|
|
|
|
|
|
|
TYPE_CONFIG |
20
|
|
|
|
|
|
|
TYPE_INIT |
21
|
|
|
|
|
|
|
TYPE_READ |
22
|
|
|
|
|
|
|
TYPE_WRITE |
23
|
|
|
|
|
|
|
TYPE_SHUTDOWN |
24
|
|
|
|
|
|
|
TYPE_LOG |
25
|
|
|
|
|
|
|
TYPE_NOTIF |
26
|
|
|
|
|
|
|
TYPE_FLUSH |
27
|
|
|
|
|
|
|
TYPE_DATASET |
28
|
|
|
|
|
|
|
LOG_DEBUG |
29
|
|
|
|
|
|
|
LOG_INFO |
30
|
|
|
|
|
|
|
LOG_NOTICE |
31
|
|
|
|
|
|
|
LOG_WARNING |
32
|
|
|
|
|
|
|
LOG_ERR |
33
|
|
|
|
|
|
|
NOTIF_FAILURE |
34
|
|
|
|
|
|
|
NOTIF_WARNING |
35
|
|
|
|
|
|
|
NOTIF_OKAY |
36
|
|
|
|
|
|
|
$hostname_g |
37
|
|
|
|
|
|
|
$interval_g |
38
|
|
|
|
|
|
|
plugin_register |
39
|
|
|
|
|
|
|
plugin_dispatch_values |
40
|
|
|
|
|
|
|
plugin_log |
41
|
|
|
|
|
|
|
WARN |
42
|
|
|
|
|
|
|
%FakeCollectd |
43
|
|
|
|
|
|
|
)], |
44
|
|
|
|
|
|
|
); |
45
|
|
|
|
|
|
|
push @EXPORT, @{$EXPORT_TAGS{all}}; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
our $VERSION = "0.1000"; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
our $interval_g = 10; |
50
|
|
|
|
|
|
|
our $hostname_g = "localhost"; |
51
|
|
|
|
|
|
|
our %FakeCollectd; |
52
|
|
|
|
|
|
|
|
53
|
5
|
|
|
5
|
|
21
|
use constant TYPE_CONFIG => "config"; |
|
5
|
|
|
|
|
6
|
|
|
5
|
|
|
|
|
273
|
|
54
|
5
|
|
|
5
|
|
20
|
use constant TYPE_INIT => "init"; |
|
5
|
|
|
|
|
5
|
|
|
5
|
|
|
|
|
165
|
|
55
|
5
|
|
|
5
|
|
34
|
use constant TYPE_READ => "read"; |
|
5
|
|
|
|
|
5
|
|
|
5
|
|
|
|
|
159
|
|
56
|
5
|
|
|
5
|
|
16
|
use constant TYPE_WRITE => "write"; |
|
5
|
|
|
|
|
4
|
|
|
5
|
|
|
|
|
133
|
|
57
|
5
|
|
|
5
|
|
15
|
use constant TYPE_SHUTDOWN => "shutdown"; |
|
5
|
|
|
|
|
5
|
|
|
5
|
|
|
|
|
158
|
|
58
|
5
|
|
|
5
|
|
18
|
use constant TYPE_LOG => "log"; |
|
5
|
|
|
|
|
3
|
|
|
5
|
|
|
|
|
156
|
|
59
|
5
|
|
|
5
|
|
20
|
use constant TYPE_NOTIF => "notify"; |
|
5
|
|
|
|
|
3
|
|
|
5
|
|
|
|
|
139
|
|
60
|
5
|
|
|
5
|
|
19
|
use constant TYPE_FLUSH => "flush"; |
|
5
|
|
|
|
|
4
|
|
|
5
|
|
|
|
|
611
|
|
61
|
5
|
|
|
5
|
|
16
|
use constant TYPE_DATASET => "init"; |
|
5
|
|
|
|
|
5
|
|
|
5
|
|
|
|
|
134
|
|
62
|
|
|
|
|
|
|
|
63
|
5
|
|
|
5
|
|
19
|
use constant LOG_DEBUG => 7; |
|
5
|
|
|
|
|
4
|
|
|
5
|
|
|
|
|
131
|
|
64
|
5
|
|
|
5
|
|
17
|
use constant LOG_INFO => 6; |
|
5
|
|
|
|
|
4
|
|
|
5
|
|
|
|
|
163
|
|
65
|
5
|
|
|
5
|
|
15
|
use constant LOG_NOTICE => 5; |
|
5
|
|
|
|
|
5
|
|
|
5
|
|
|
|
|
139
|
|
66
|
5
|
|
|
5
|
|
14
|
use constant LOG_WARNING => 4; |
|
5
|
|
|
|
|
4
|
|
|
5
|
|
|
|
|
127
|
|
67
|
5
|
|
|
5
|
|
16
|
use constant LOG_ERR => 3; |
|
5
|
|
|
|
|
5
|
|
|
5
|
|
|
|
|
138
|
|
68
|
|
|
|
|
|
|
|
69
|
5
|
|
|
5
|
|
13
|
use constant NOTIF_FAILURE => 1; |
|
5
|
|
|
|
|
5
|
|
|
5
|
|
|
|
|
123
|
|
70
|
5
|
|
|
5
|
|
15
|
use constant NOTIF_WARNING => 2; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
124
|
|
71
|
5
|
|
|
5
|
|
16
|
use constant NOTIF_OKAY => 4; |
|
5
|
|
|
|
|
5
|
|
|
5
|
|
|
|
|
1366
|
|
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head2 plugin_register (CALLBACK_TYPE, PLUGIN_NAME, CALLBACK_NAME) |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
Will Populate %FakeCollectd using provided arguments. |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=cut |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub plugin_register { |
80
|
30
|
|
|
30
|
1
|
5537
|
my ($type,$name,$data) = @_; |
81
|
30
|
|
|
|
|
34
|
my $caller = scalar caller 0; |
82
|
30
|
|
|
|
|
55
|
$FakeCollectd{$caller}->{Name} = $name; |
83
|
30
|
100
|
|
|
|
79
|
if ($type eq TYPE_CONFIG) { |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
84
|
7
|
|
|
|
|
32
|
$FakeCollectd{$name}->{Callback}->{Config} = $caller."::".$data; |
85
|
|
|
|
|
|
|
} elsif ($type eq TYPE_INIT) { |
86
|
5
|
|
|
|
|
13
|
$FakeCollectd{$name}->{Callback}->{Init} = $caller."::".$data; |
87
|
|
|
|
|
|
|
} elsif ($type eq TYPE_READ) { |
88
|
18
|
|
|
|
|
50
|
$FakeCollectd{$name}->{Callback}->{Read} = $caller."::".$data; |
89
|
|
|
|
|
|
|
} else { |
90
|
0
|
|
|
|
|
0
|
die "$type not supported (yet)"; |
91
|
|
|
|
|
|
|
} |
92
|
30
|
|
|
|
|
44
|
1; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head2 plugin_dispatch_values ( value_type ) |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
Populates %FakeCollectd with the data. |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=cut |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub plugin_dispatch_values { |
102
|
10
|
|
|
10
|
1
|
4000328
|
my $caller = scalar caller 0; |
103
|
10
|
50
|
|
|
|
37
|
unless (ref $_[0] eq "HASH") { |
104
|
0
|
|
|
|
|
0
|
croak "plugin_dispatch_values $caller: dispatch can only be called using HASHREF arg"; |
105
|
0
|
|
|
|
|
0
|
return undef; |
106
|
|
|
|
|
|
|
} |
107
|
10
|
|
|
|
|
26
|
my $plugin = $_[0] -> {plugin}; |
108
|
10
|
50
|
|
|
|
22
|
unless (defined $plugin) { |
109
|
0
|
|
|
|
|
0
|
croak "plugin_dispatch_values $caller: no 'plugin' key in dispatch"; |
110
|
0
|
|
|
|
|
0
|
return undef; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
# confused here as to which PK to use |
113
|
|
|
|
|
|
|
# use both! |
114
|
10
|
|
|
|
|
11
|
push @{$FakeCollectd{$plugin}->{Values}}, \@_; |
|
10
|
|
|
|
|
39
|
|
115
|
10
|
|
|
|
|
14
|
push @{$FakeCollectd{$caller}->{Values}}, \@_; |
|
10
|
|
|
|
|
29
|
|
116
|
10
|
|
|
|
|
21
|
1; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head2 WARN |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
Replaces Warning function |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=cut |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
sub WARN { |
126
|
0
|
|
|
0
|
1
|
|
plugin_log (LOG_WARNING, @_); |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head2 plugin_log |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
Replaces log function |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=cut |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
sub plugin_log { |
136
|
0
|
|
|
0
|
1
|
|
eval {croak join " ", @_} |
|
0
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
1; |
140
|
|
|
|
|
|
|
|