line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# Devmon data object |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
package Xymon::Plugin::Server::Devmon; |
5
|
|
|
|
|
|
|
|
6
|
4
|
|
|
4
|
|
19645
|
use strict; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
128
|
|
7
|
|
|
|
|
|
|
|
8
|
4
|
|
|
4
|
|
384
|
use Xymon::Plugin::Server; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
3286
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 NAME |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
Xymon::Plugin::Server::Devmon - Devmon data object |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 SYNOPSIS |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
my $devmon = Xymon::Plugin::Server::Devmon |
17
|
|
|
|
|
|
|
->new(ds0 => 'GAUGE:600:0:U', |
18
|
|
|
|
|
|
|
ds1 => 'GAUGE:600:0:U'); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
$devmon->add_data(device1 => { ds0 => 0, ds1 => 2 }); |
21
|
|
|
|
|
|
|
$devmon->add_data(device2 => { ds0 => 0, ds1 => 2 }); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# add to data to be reported. |
24
|
|
|
|
|
|
|
my $status = Xymon::Plugin::Server::Status |
25
|
|
|
|
|
|
|
->new("localhost.localdomain", "test1"); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
$status->add_devmon($devmon); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 DESCRIPTION |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
This module handles data structure for Xymon 'devmon' module. |
32
|
|
|
|
|
|
|
To store data into RRD database, add entry to TEST2RRD variable |
33
|
|
|
|
|
|
|
in server config. |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
(named hobbitserver.cfg in Xymon 4.2, xymonserver.cfg in Xymon 4.3) |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
ex. |
38
|
|
|
|
|
|
|
TEST2RRD="cpu=la,disk,...(snipped)...,test1=devmon" |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head1 SUBROUTINES/METHODS |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head2 new(ds1 => dsdef1, ...) |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
Create devmon object with data store definition. |
46
|
|
|
|
|
|
|
(To know meanings of dsdef field, please read document in RRDTool.) |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=cut |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub new { |
51
|
6
|
|
|
6
|
1
|
1414
|
my $class = shift; |
52
|
6
|
|
|
|
|
25
|
my @datadef = @_; # key, def, key, def, ... |
53
|
|
|
|
|
|
|
|
54
|
6
|
|
|
|
|
12
|
my @dskeys; |
55
|
|
|
|
|
|
|
my %dsdefs; |
56
|
|
|
|
|
|
|
|
57
|
6
|
|
|
|
|
29
|
while (@datadef) { |
58
|
10
|
|
|
|
|
17
|
my $key = shift @datadef; |
59
|
10
|
|
|
|
|
22
|
push(@dskeys, $key); |
60
|
10
|
|
|
|
|
41
|
$dsdefs{$key} = shift @datadef; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
6
|
|
|
|
|
13
|
my $format_method = "_format_4_3"; |
64
|
6
|
|
|
|
|
10
|
my @ver = @{Xymon::Plugin::Server->version}; |
|
6
|
|
|
|
|
34
|
|
65
|
6
|
100
|
66
|
|
|
51
|
if ($ver[0] == 4 && $ver[1] <= 2) { |
66
|
3
|
|
|
|
|
7
|
$format_method = "_format_4_2"; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
6
|
|
|
|
|
39
|
my $self = { |
70
|
|
|
|
|
|
|
_dskeys => \@dskeys, |
71
|
|
|
|
|
|
|
_dsdefs => \%dsdefs, |
72
|
|
|
|
|
|
|
_format_method => $format_method, |
73
|
|
|
|
|
|
|
_data => [], |
74
|
|
|
|
|
|
|
}; |
75
|
|
|
|
|
|
|
|
76
|
6
|
|
|
|
|
30
|
bless $self, $class; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head2 add_data(devname, { ds1 => ds1value, ...}) |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
Set values for devname. |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=cut |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub add_data { |
86
|
10
|
|
|
10
|
1
|
67
|
my $self = shift; |
87
|
10
|
|
|
|
|
18
|
my ($key, $values) = @_; |
88
|
|
|
|
|
|
|
|
89
|
10
|
|
|
|
|
12
|
push(@{$self->{_data}}, [$key, $values]); |
|
10
|
|
|
|
|
58
|
|
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head2 format |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
Format data structure to report to Xymon. |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=cut |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub format { |
99
|
6
|
|
|
6
|
1
|
20
|
my $self = shift; |
100
|
6
|
|
|
|
|
9
|
my @ver = @{Xymon::Plugin::Server->version}; |
|
6
|
|
|
|
|
19
|
|
101
|
|
|
|
|
|
|
|
102
|
6
|
|
|
|
|
15
|
my $meth = $self->{_format_method}; |
103
|
6
|
|
|
|
|
32
|
$self->$meth(@_); |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub _format_4_2 { |
107
|
3
|
|
|
3
|
|
5
|
my $self = shift; |
108
|
3
|
|
|
|
|
3
|
my @ret; |
109
|
|
|
|
|
|
|
|
110
|
3
|
|
|
|
|
5
|
my $n = 20; |
111
|
3
|
|
|
|
|
16
|
my @defs = ('GAUGE:600:0:U') x $n; |
112
|
|
|
|
|
|
|
|
113
|
3
|
|
|
|
|
3
|
my $ndefs = scalar @{$self->{_dskeys}}; |
|
3
|
|
|
|
|
7
|
|
114
|
3
|
|
|
|
|
4
|
my %dsmap; |
115
|
|
|
|
|
|
|
|
116
|
3
|
|
|
|
|
11
|
for (my $i=0; $i<$ndefs; $i++) { |
117
|
5
|
|
|
|
|
6
|
my $key = $self->{_dskeys}->[$i]; |
118
|
5
|
|
|
|
|
21
|
$dsmap{$key} = sprintf("ds%d", $i); |
119
|
5
|
|
|
|
|
14
|
$defs[$i] = $self->{_dsdefs}->{$key}; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
3
|
|
|
|
|
11
|
push(@ret, "\n"); |
146
|
|
|
|
|
|
|
|
147
|
3
|
|
|
|
|
22
|
return join("\n", @ret); |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
sub _format_4_3 { |
151
|
3
|
|
|
3
|
|
6
|
my $self = shift; |
152
|
3
|
|
|
|
|
5
|
my @ret; |
153
|
|
|
|
|
|
|
|
154
|
3
|
|
|
|
|
6
|
push(@ret, "\n"); |
173
|
|
|
|
|
|
|
|
174
|
3
|
|
|
|
|
17
|
return join("\n", @ret); |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
1; |