| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Monitoring::TT::Input::CSV; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1608
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
29
|
|
|
4
|
1
|
|
|
1
|
|
17
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
28
|
|
|
5
|
1
|
|
|
1
|
|
11
|
use utf8; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
6
|
|
|
6
|
1
|
|
|
1
|
|
23
|
use Monitoring::TT::Log qw/error warn info debug trace/; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
65
|
|
|
7
|
1
|
|
|
1
|
|
5
|
use Monitoring::TT::Utils; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
580
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
##################################################################### |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 NAME |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
Monitoring::TT::Input::CSV - Input CSV data |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
CSV Input for Hosts and Contacts |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=cut |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
##################################################################### |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 CONSTRUCTOR |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head2 new |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
new(%options) |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=cut |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub new { |
|
32
|
1
|
|
|
1
|
1
|
658
|
my($class, %options) = @_; |
|
33
|
|
|
|
|
|
|
my $self = { |
|
34
|
|
|
|
|
|
|
'fields' => { |
|
35
|
|
|
|
|
|
|
'hosts' => [qw/name alias address type tags groups apps/], |
|
36
|
|
|
|
|
|
|
'contacts' => [qw/name alias email roles tags groups/], |
|
37
|
|
|
|
|
|
|
}, |
|
38
|
1
|
|
|
|
|
36
|
'montt' => $options{'montt'}, |
|
39
|
|
|
|
|
|
|
}; |
|
40
|
1
|
|
|
|
|
3
|
bless $self, $class; |
|
41
|
1
|
|
|
|
|
2
|
return $self; |
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
##################################################################### |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head1 METHODS |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head2 get_types |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
get_types($list_of_folders) |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
return supported types for this input type |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=cut |
|
55
|
|
|
|
|
|
|
sub get_types { |
|
56
|
1
|
|
|
1
|
1
|
4
|
my($self, $folders) = @_; |
|
57
|
1
|
|
|
|
|
2
|
my $types = []; |
|
58
|
1
|
|
|
|
|
1
|
for my $dir (@{$folders}) { |
|
|
1
|
|
|
|
|
3
|
|
|
59
|
1
|
|
|
|
|
1
|
for my $type (sort keys %{$self->{'fields'}}) { |
|
|
1
|
|
|
|
|
10
|
|
|
60
|
2
|
|
|
|
|
6
|
my $pattern = $dir.'/'.$type.'*.csv'; |
|
61
|
2
|
|
|
|
|
9
|
trace('looking for csv file: '.$pattern); |
|
62
|
2
|
|
|
|
|
136
|
my @files = glob($pattern); |
|
63
|
2
|
|
|
|
|
8
|
for my $f (@files) { |
|
64
|
2
|
|
|
|
|
8
|
debug('found csv file: '.$f); |
|
65
|
2
|
|
|
|
|
2
|
push @{$types}, $type; |
|
|
2
|
|
|
|
|
6
|
|
|
66
|
|
|
|
|
|
|
} |
|
67
|
|
|
|
|
|
|
} |
|
68
|
|
|
|
|
|
|
} |
|
69
|
1
|
|
|
|
|
4
|
return Monitoring::TT::Utils::get_uniq_sorted($types); |
|
70
|
|
|
|
|
|
|
} |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
##################################################################### |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head2 read |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
read csv file |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=cut |
|
79
|
|
|
|
|
|
|
sub read { |
|
80
|
1
|
|
|
1
|
1
|
659
|
my($self, $dir, $type) = @_; |
|
81
|
1
|
|
|
|
|
2
|
my $data = []; |
|
82
|
1
|
|
|
|
|
3
|
my $pattern = $dir.'/'.$type.'*.csv'; |
|
83
|
1
|
|
|
|
|
59
|
my @files = glob($pattern); |
|
84
|
1
|
|
|
|
|
3
|
for my $file (@files) { |
|
85
|
2
|
|
|
|
|
10
|
info("reading $type from $file"); |
|
86
|
2
|
50
|
|
|
|
62
|
open(my $fh, '<', $file) or die('cannot read '.$file.': '.$!); |
|
87
|
2
|
|
|
|
|
45
|
while(my $line = <$fh>) { |
|
88
|
7
|
100
|
|
|
|
20
|
next if substr($line, 0, 1) eq '#'; |
|
89
|
5
|
|
|
|
|
7
|
chomp($line); |
|
90
|
5
|
100
|
|
|
|
28
|
next if $line =~ m/^\s*$/gmx; |
|
91
|
2
|
|
|
|
|
12
|
my @d = split(/\s*;\s*/mx, $line); |
|
92
|
2
|
|
|
|
|
4
|
my $d = {}; |
|
93
|
2
|
|
|
|
|
3
|
my $x = 0; |
|
94
|
2
|
|
|
|
|
3
|
for my $k (@{$self->{'fields'}->{$type}}) { |
|
|
2
|
|
|
|
|
7
|
|
|
95
|
14
|
|
|
|
|
29
|
$d->{$k} = $d[$x]; |
|
96
|
14
|
|
|
|
|
16
|
$x++; |
|
97
|
|
|
|
|
|
|
} |
|
98
|
|
|
|
|
|
|
|
|
99
|
2
|
|
|
|
|
5
|
$d->{'file'} = $file; |
|
100
|
2
|
|
|
|
|
6
|
$d->{'line'} = $.; |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
# bring tags in shape |
|
103
|
2
|
|
|
|
|
8
|
$d->{'tags'} = Monitoring::TT::Utils::parse_tags($d->{'tags'}); |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
# bring groups in shape |
|
106
|
2
|
|
|
|
|
6
|
$d->{'groups'} = Monitoring::TT::Utils::parse_groups($d->{'groups'}); |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
# bring apps in shape |
|
109
|
2
|
50
|
|
|
|
6
|
$d->{'apps'} = Monitoring::TT::Utils::parse_tags($d->{'apps'}) if $type eq 'hosts'; |
|
110
|
|
|
|
|
|
|
|
|
111
|
2
|
|
|
|
|
4
|
push @{$data}, $d; |
|
|
2
|
|
|
|
|
13
|
|
|
112
|
|
|
|
|
|
|
} |
|
113
|
2
|
|
|
|
|
16
|
close($fh); |
|
114
|
2
|
|
|
|
|
3
|
debug("read ".(scalar @{$data})." $type from $file"); |
|
|
2
|
|
|
|
|
11
|
|
|
115
|
|
|
|
|
|
|
} |
|
116
|
1
|
|
|
|
|
3
|
return $data; |
|
117
|
|
|
|
|
|
|
} |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
##################################################################### |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head1 AUTHOR |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
Sven Nierlein, 2013, |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=cut |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
1; |