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
|
|
5545
|
use Carp qw/croak/; |
|
5
|
|
|
|
|
8
|
|
|
5
|
|
|
|
|
624
|
|
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
|
|
|
|
|
7
|
|
|
5
|
|
|
|
|
318
|
|
54
|
5
|
|
|
5
|
|
18
|
use constant TYPE_INIT => "init"; |
|
5
|
|
|
|
|
4
|
|
|
5
|
|
|
|
|
190
|
|
55
|
5
|
|
|
5
|
|
13
|
use constant TYPE_READ => "read"; |
|
5
|
|
|
|
|
6
|
|
|
5
|
|
|
|
|
179
|
|
56
|
5
|
|
|
5
|
|
27
|
use constant TYPE_WRITE => "write"; |
|
5
|
|
|
|
|
7
|
|
|
5
|
|
|
|
|
173
|
|
57
|
5
|
|
|
5
|
|
16
|
use constant TYPE_SHUTDOWN => "shutdown"; |
|
5
|
|
|
|
|
4
|
|
|
5
|
|
|
|
|
167
|
|
58
|
5
|
|
|
5
|
|
17
|
use constant TYPE_LOG => "log"; |
|
5
|
|
|
|
|
4
|
|
|
5
|
|
|
|
|
185
|
|
59
|
5
|
|
|
5
|
|
16
|
use constant TYPE_NOTIF => "notify"; |
|
5
|
|
|
|
|
6
|
|
|
5
|
|
|
|
|
175
|
|
60
|
5
|
|
|
5
|
|
15
|
use constant TYPE_FLUSH => "flush"; |
|
5
|
|
|
|
|
5
|
|
|
5
|
|
|
|
|
172
|
|
61
|
5
|
|
|
5
|
|
15
|
use constant TYPE_DATASET => "init"; |
|
5
|
|
|
|
|
6
|
|
|
5
|
|
|
|
|
158
|
|
62
|
|
|
|
|
|
|
|
63
|
5
|
|
|
5
|
|
14
|
use constant LOG_DEBUG => 7; |
|
5
|
|
|
|
|
5
|
|
|
5
|
|
|
|
|
171
|
|
64
|
5
|
|
|
5
|
|
14
|
use constant LOG_INFO => 6; |
|
5
|
|
|
|
|
5
|
|
|
5
|
|
|
|
|
172
|
|
65
|
5
|
|
|
5
|
|
15
|
use constant LOG_NOTICE => 5; |
|
5
|
|
|
|
|
5
|
|
|
5
|
|
|
|
|
165
|
|
66
|
5
|
|
|
5
|
|
13
|
use constant LOG_WARNING => 4; |
|
5
|
|
|
|
|
5
|
|
|
5
|
|
|
|
|
159
|
|
67
|
5
|
|
|
5
|
|
15
|
use constant LOG_ERR => 3; |
|
5
|
|
|
|
|
5
|
|
|
5
|
|
|
|
|
155
|
|
68
|
|
|
|
|
|
|
|
69
|
5
|
|
|
5
|
|
16
|
use constant NOTIF_FAILURE => 1; |
|
5
|
|
|
|
|
4
|
|
|
5
|
|
|
|
|
159
|
|
70
|
5
|
|
|
5
|
|
18
|
use constant NOTIF_WARNING => 2; |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
244
|
|
71
|
5
|
|
|
5
|
|
16
|
use constant NOTIF_OKAY => 4; |
|
5
|
|
|
0
|
|
4
|
|
|
5
|
|
|
|
|
1567
|
|
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
|
0
|
|
|
30
|
1
|
0
|
my ($type,$name,$data) = @_; |
81
|
30
|
|
|
|
|
5727
|
my $caller = scalar caller 0; |
82
|
30
|
|
|
|
|
36
|
$FakeCollectd{$caller}->{Name} = $name; |
83
|
30
|
100
|
|
|
|
70
|
if ($type eq TYPE_CONFIG) { |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
84
|
30
|
|
|
|
|
78
|
$FakeCollectd{$name}->{Callback}->{Config} = $caller."::".$data; |
85
|
|
|
|
|
|
|
} elsif ($type eq TYPE_INIT) { |
86
|
7
|
|
|
|
|
59
|
$FakeCollectd{$name}->{Callback}->{Init} = $caller."::".$data; |
87
|
|
|
|
|
|
|
} elsif ($type eq TYPE_READ) { |
88
|
5
|
|
|
|
|
13
|
$FakeCollectd{$name}->{Callback}->{Read} = $caller."::".$data; |
89
|
|
|
|
|
|
|
} else { |
90
|
18
|
|
|
|
|
83
|
die "$type not supported (yet)"; |
91
|
|
|
|
|
|
|
} |
92
|
0
|
|
|
|
|
0
|
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
|
30
|
|
|
10
|
1
|
44
|
my $caller = scalar caller 0; |
103
|
10
|
50
|
|
|
|
4000401
|
unless (ref $_[0] eq "HASH") { |
104
|
10
|
|
|
|
|
40
|
croak "plugin_dispatch_values $caller: dispatch can only be called using HASHREF arg"; |
105
|
0
|
|
|
|
|
0
|
return undef; |
106
|
|
|
|
|
|
|
} |
107
|
0
|
|
|
|
|
0
|
my $plugin = $_[0] -> {plugin}; |
108
|
10
|
50
|
|
|
|
16
|
unless (defined $plugin) { |
109
|
10
|
|
|
|
|
31
|
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
|
0
|
|
|
|
|
0
|
push @{$FakeCollectd{$plugin}->{Values}}, \@_; |
|
10
|
|
|
|
|
12
|
|
115
|
10
|
|
|
|
|
41
|
push @{$FakeCollectd{$caller}->{Values}}, \@_; |
|
10
|
|
|
|
|
14
|
|
116
|
10
|
|
|
|
|
21
|
1; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head2 WARN |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
Replaces Warning function |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=cut |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
sub WARN { |
126
|
10
|
|
|
0
|
1
|
23
|
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
|
|
|
|
|
|
|
|