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