| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
#!/usr/bin/perl -w |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Ym; |
|
4
|
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
9
|
use warnings; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
78
|
|
|
6
|
1
|
|
|
1
|
|
7
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
40
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
6
|
use Ym; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
3161
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub PlaceHost { |
|
11
|
0
|
|
|
0
|
0
|
|
my ($branch, $tree) = @_; |
|
12
|
0
|
|
|
|
|
|
my $np = "host_name"; # Name prefix |
|
13
|
0
|
|
|
|
|
|
my $tp = "name"; # Template prefix |
|
14
|
|
|
|
|
|
|
|
|
15
|
0
|
0
|
0
|
|
|
|
if (defined($branch->{$np})) { |
|
|
|
0
|
0
|
|
|
|
|
|
16
|
0
|
|
|
|
|
|
my $name = $branch->{$np}; |
|
17
|
0
|
|
|
|
|
|
$tree->{'hosts'}->{$name} = $branch; |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
} |
|
20
|
|
|
|
|
|
|
elsif (defined($branch->{$tp}) && defined($branch->{'register'}) && $branch->{'register'} == 0) { |
|
21
|
0
|
|
|
|
|
|
my $name = $branch->{$tp}; |
|
22
|
0
|
|
|
|
|
|
$tree->{'host_templates'}->{$name} = $branch; |
|
23
|
|
|
|
|
|
|
} |
|
24
|
|
|
|
|
|
|
else { |
|
25
|
0
|
|
|
|
|
|
return 0; |
|
26
|
|
|
|
|
|
|
} |
|
27
|
0
|
|
|
|
|
|
return 1; |
|
28
|
|
|
|
|
|
|
} |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub PlaceService { |
|
31
|
0
|
|
|
0
|
0
|
|
my ($branch, $tree) = @_; |
|
32
|
0
|
|
|
|
|
|
my $np = "host_name"; |
|
33
|
0
|
|
|
|
|
|
my $sp = "service_description"; |
|
34
|
0
|
|
|
|
|
|
my $tp = "name"; # Template prefix |
|
35
|
|
|
|
|
|
|
|
|
36
|
0
|
0
|
0
|
|
|
|
if (defined($branch->{$np}) && defined($branch->{$sp})) { |
|
|
|
0
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
my $hn = $branch->{$np}; |
|
38
|
0
|
|
|
|
|
|
my $sn = $branch->{$sp}; |
|
39
|
0
|
|
|
|
|
|
$tree->{'hosts'}->{$hn}->{'services'}->{$sn} = $branch; |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
} |
|
42
|
|
|
|
|
|
|
elsif (defined($branch->{$tp}) && defined($branch->{'register'}) && $branch->{'register'} == 0) { |
|
43
|
0
|
|
|
|
|
|
my $name = $branch->{$tp}; |
|
44
|
0
|
|
|
|
|
|
$tree->{'service_templates'}->{$name} = $branch; |
|
45
|
|
|
|
|
|
|
} |
|
46
|
|
|
|
|
|
|
else { |
|
47
|
0
|
|
|
|
|
|
return 0; |
|
48
|
|
|
|
|
|
|
} |
|
49
|
0
|
|
|
|
|
|
return 1; |
|
50
|
|
|
|
|
|
|
} |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub PlaceHostgroup { |
|
53
|
0
|
|
|
0
|
0
|
|
my ($branch, $tree) = @_; |
|
54
|
0
|
|
|
|
|
|
my $np = "hostgroup_name"; |
|
55
|
|
|
|
|
|
|
|
|
56
|
0
|
0
|
|
|
|
|
if (defined($branch->{$np})) { |
|
57
|
0
|
|
|
|
|
|
my $name = $branch->{$np}; |
|
58
|
0
|
|
|
|
|
|
$tree->{'hostgroups'}->{$name} = $branch; |
|
59
|
|
|
|
|
|
|
} |
|
60
|
|
|
|
|
|
|
else { |
|
61
|
0
|
|
|
|
|
|
return 0; |
|
62
|
|
|
|
|
|
|
} |
|
63
|
0
|
|
|
|
|
|
return 1; |
|
64
|
|
|
|
|
|
|
} |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub PlaceCommand { |
|
67
|
0
|
|
|
0
|
0
|
|
my ($branch, $tree) = @_; |
|
68
|
0
|
|
|
|
|
|
my $np = "command_name"; |
|
69
|
|
|
|
|
|
|
|
|
70
|
0
|
0
|
|
|
|
|
if (defined($branch->{$np})) { |
|
71
|
0
|
|
|
|
|
|
my $name = $branch->{$np}; |
|
72
|
0
|
|
|
|
|
|
$tree->{'commands'}->{$name} = $branch; |
|
73
|
|
|
|
|
|
|
} |
|
74
|
|
|
|
|
|
|
else { |
|
75
|
0
|
|
|
|
|
|
return 0; |
|
76
|
|
|
|
|
|
|
} |
|
77
|
0
|
|
|
|
|
|
return 1; |
|
78
|
|
|
|
|
|
|
} |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub PlaceContactgroup { |
|
81
|
0
|
|
|
0
|
0
|
|
my ($branch, $tree) = @_; |
|
82
|
0
|
|
|
|
|
|
my $np = "contactgroup_name"; |
|
83
|
|
|
|
|
|
|
|
|
84
|
0
|
0
|
|
|
|
|
if (defined($branch->{$np})) { |
|
85
|
0
|
|
|
|
|
|
my $name = $branch->{$np}; |
|
86
|
0
|
|
|
|
|
|
$tree->{'contactgroups'}->{$name} = $branch; |
|
87
|
|
|
|
|
|
|
} |
|
88
|
|
|
|
|
|
|
else { |
|
89
|
0
|
|
|
|
|
|
return 0; |
|
90
|
|
|
|
|
|
|
} |
|
91
|
0
|
|
|
|
|
|
return 1; |
|
92
|
|
|
|
|
|
|
} |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub PlaceContact { |
|
95
|
0
|
|
|
0
|
0
|
|
my ($branch, $tree) = @_; |
|
96
|
0
|
|
|
|
|
|
my $np = "contact_name"; # Name prefix |
|
97
|
0
|
|
|
|
|
|
my $tp = "name"; # Template prefix |
|
98
|
|
|
|
|
|
|
|
|
99
|
0
|
0
|
0
|
|
|
|
if (defined($branch->{$np})) { |
|
|
|
0
|
0
|
|
|
|
|
|
100
|
0
|
|
|
|
|
|
my $name = $branch->{$np}; |
|
101
|
0
|
|
|
|
|
|
$tree->{'contacts'}->{$name} = $branch; |
|
102
|
|
|
|
|
|
|
} |
|
103
|
|
|
|
|
|
|
elsif (defined($branch->{$tp}) |
|
104
|
|
|
|
|
|
|
&& defined($branch->{'register'}) |
|
105
|
|
|
|
|
|
|
&& $branch->{'register'} == 0) |
|
106
|
|
|
|
|
|
|
{ |
|
107
|
0
|
|
|
|
|
|
my $name = $branch->{$tp}; |
|
108
|
0
|
|
|
|
|
|
$tree->{'contact_templates'}->{$name} = $branch; |
|
109
|
|
|
|
|
|
|
} |
|
110
|
|
|
|
|
|
|
else { |
|
111
|
0
|
|
|
|
|
|
return 0; |
|
112
|
|
|
|
|
|
|
} |
|
113
|
0
|
|
|
|
|
|
return 1; |
|
114
|
|
|
|
|
|
|
} |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
sub PlaceTimeperiod { |
|
117
|
0
|
|
|
0
|
0
|
|
my ($branch, $tree) = @_; |
|
118
|
0
|
|
|
|
|
|
my $np = "timeperiod_name"; |
|
119
|
|
|
|
|
|
|
|
|
120
|
0
|
0
|
|
|
|
|
if (defined($branch->{$np})) { |
|
121
|
0
|
|
|
|
|
|
my $name = $branch->{$np}; |
|
122
|
0
|
|
|
|
|
|
$tree->{'timeperiods'}->{$name} = $branch; |
|
123
|
|
|
|
|
|
|
} |
|
124
|
|
|
|
|
|
|
else { |
|
125
|
0
|
|
|
|
|
|
return 0; |
|
126
|
|
|
|
|
|
|
} |
|
127
|
0
|
|
|
|
|
|
return 1; |
|
128
|
|
|
|
|
|
|
} |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
sub PlaceServiceDependency { |
|
131
|
0
|
|
|
0
|
0
|
|
my ($branch, $tree) = @_; |
|
132
|
0
|
|
|
|
|
|
my $hp = "dependent_host_name"; |
|
133
|
0
|
|
|
|
|
|
my $sp = "dependent_service_description"; |
|
134
|
|
|
|
|
|
|
|
|
135
|
0
|
0
|
0
|
|
|
|
if (defined($branch->{$hp}) && defined($branch->{$sp})) { |
|
136
|
0
|
|
|
|
|
|
my $dependent_host = $branch->{$hp}; |
|
137
|
0
|
|
|
|
|
|
my $service_name = $branch->{$sp}; |
|
138
|
0
|
|
|
|
|
|
my $c = 0; |
|
139
|
0
|
0
|
|
|
|
|
if (defined($tree->{'service_dependencies'}->{$dependent_host}->{'service_dependencies'})) { |
|
140
|
0
|
|
|
|
|
|
foreach (keys %{$tree->{'service_dependencies'}->{$dependent_host}->{'service_dependencies'}}) { |
|
|
0
|
|
|
|
|
|
|
|
141
|
0
|
|
|
|
|
|
++$c; |
|
142
|
|
|
|
|
|
|
} |
|
143
|
|
|
|
|
|
|
} |
|
144
|
0
|
|
|
|
|
|
$tree->{'service_dependencies'}->{$dependent_host}->{'service_dependencies'}->{$c} = $branch; |
|
145
|
|
|
|
|
|
|
} |
|
146
|
|
|
|
|
|
|
else { |
|
147
|
0
|
|
|
|
|
|
return 0; |
|
148
|
|
|
|
|
|
|
} |
|
149
|
0
|
|
|
|
|
|
return 1; |
|
150
|
|
|
|
|
|
|
} |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
sub PlaceHostDependency { |
|
153
|
0
|
|
|
0
|
0
|
|
my ($branch, $tree) = @_; |
|
154
|
0
|
|
|
|
|
|
my $hp = "dependent_host_name"; |
|
155
|
0
|
|
|
|
|
|
my $mhp = "host_name"; |
|
156
|
|
|
|
|
|
|
|
|
157
|
0
|
0
|
0
|
|
|
|
if (defined($branch->{$hp}) && defined($branch->{$mhp})) { |
|
158
|
0
|
|
|
|
|
|
my $dependent_host = $branch->{$hp}; |
|
159
|
0
|
|
|
|
|
|
my $master_host = $branch->{$mhp}; |
|
160
|
0
|
|
|
|
|
|
$tree->{'host_dependencies'}->{$dependent_host}->{'host_dependencies'}->{$master_host} = $branch; |
|
161
|
|
|
|
|
|
|
} |
|
162
|
|
|
|
|
|
|
else { |
|
163
|
0
|
|
|
|
|
|
return 0; |
|
164
|
|
|
|
|
|
|
} |
|
165
|
0
|
|
|
|
|
|
return 1; |
|
166
|
|
|
|
|
|
|
} |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
sub ParseFile { |
|
169
|
0
|
|
|
0
|
0
|
|
my $cfg = shift; |
|
170
|
0
|
|
|
|
|
|
my $lc = 0; # Line counter |
|
171
|
0
|
|
|
|
|
|
my @err_msg; # Error messages |
|
172
|
0
|
|
|
|
|
|
my $verbose = $Ym::VERBOSE; |
|
173
|
0
|
|
|
|
|
|
my $debug = $Ym::DEBUG; |
|
174
|
0
|
|
|
|
|
|
my %s; |
|
175
|
|
|
|
|
|
|
|
|
176
|
0
|
0
|
|
|
|
|
open(CFG, "$cfg") or die "Can't open $cfg : $!\n"; |
|
177
|
0
|
|
|
|
|
|
while () { |
|
178
|
0
|
0
|
|
|
|
|
if (scalar(@err_msg) > 0) { |
|
179
|
0
|
|
|
|
|
|
print "Errors occured while reading $cfg\n@err_msg\n"; |
|
180
|
0
|
|
|
|
|
|
die; |
|
181
|
|
|
|
|
|
|
} |
|
182
|
0
|
|
|
|
|
|
++$lc; |
|
183
|
0
|
0
|
|
|
|
|
next if /^\s*[#;]/o; |
|
184
|
0
|
|
|
|
|
|
chomp; |
|
185
|
0
|
0
|
|
|
|
|
if (/^\s*define\s+(\w+)\s*{/o) { |
|
186
|
0
|
|
|
|
|
|
my $dn = $1; # definition name |
|
187
|
0
|
|
|
|
|
|
my %d; # hash to store definition |
|
188
|
0
|
|
|
|
|
|
while ((my $l = ) !~ /^\s*}/o) { |
|
189
|
0
|
|
|
|
|
|
++$lc; |
|
190
|
0
|
0
|
|
|
|
|
next if ($l =~ /^\s*[#;]/o); |
|
191
|
0
|
0
|
|
|
|
|
next if ($l =~ /^\s*$/); |
|
192
|
0
|
|
|
|
|
|
chomp($l); |
|
193
|
0
|
0
|
|
|
|
|
if ($l !~ /(\w+)\s+(.+)$/o) { |
|
194
|
0
|
|
|
|
|
|
push @err_msg, "Error in line $lc: $l"; |
|
195
|
0
|
|
|
|
|
|
last; |
|
196
|
|
|
|
|
|
|
} |
|
197
|
0
|
|
|
|
|
|
my ($k, $v) = ($1, $2); |
|
198
|
0
|
|
|
|
|
|
$v =~ s/\s*[#;].*//o; |
|
199
|
0
|
|
|
|
|
|
$v =~ s/\s+$//o; |
|
200
|
0
|
0
|
|
|
|
|
($debug) && print "$k => $v\n"; |
|
201
|
0
|
|
|
|
|
|
$d{$k} = $v; |
|
202
|
|
|
|
|
|
|
} |
|
203
|
0
|
|
|
|
|
|
++$lc; |
|
204
|
0
|
0
|
|
|
|
|
($debug) && print "\n"; |
|
205
|
0
|
0
|
|
|
|
|
if ("$dn" eq "host") { |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
206
|
0
|
0
|
|
|
|
|
unless (PlaceHost(\%d, \%s)) { |
|
207
|
0
|
|
|
|
|
|
push @err_msg, "Error in " . Dumper(\%d); |
|
208
|
|
|
|
|
|
|
} |
|
209
|
|
|
|
|
|
|
} |
|
210
|
|
|
|
|
|
|
elsif ("$dn" eq "service") { |
|
211
|
0
|
0
|
|
|
|
|
unless (PlaceService(\%d, \%s)) { |
|
212
|
0
|
|
|
|
|
|
push @err_msg, "Error in " . Dumper(\%d); |
|
213
|
|
|
|
|
|
|
} |
|
214
|
|
|
|
|
|
|
} |
|
215
|
|
|
|
|
|
|
elsif ("$dn" eq "hostgroup") { |
|
216
|
0
|
0
|
|
|
|
|
unless (PlaceHostgroup(\%d, \%s)) { |
|
217
|
0
|
|
|
|
|
|
push @err_msg, "Error in " . Dumper(\%d); |
|
218
|
|
|
|
|
|
|
} |
|
219
|
|
|
|
|
|
|
} |
|
220
|
|
|
|
|
|
|
elsif ("$dn" eq "command") { |
|
221
|
0
|
0
|
|
|
|
|
unless (PlaceCommand(\%d, \%s)) { |
|
222
|
0
|
|
|
|
|
|
push @err_msg, "Error in " . Dumper(\%d); |
|
223
|
|
|
|
|
|
|
} |
|
224
|
|
|
|
|
|
|
} |
|
225
|
|
|
|
|
|
|
elsif ("$dn" eq "contactgroup") { |
|
226
|
0
|
0
|
|
|
|
|
unless (PlaceContactgroup(\%d, \%s)) { |
|
227
|
0
|
|
|
|
|
|
push @err_msg, "Error in " . Dumper(\%d); |
|
228
|
|
|
|
|
|
|
} |
|
229
|
|
|
|
|
|
|
} |
|
230
|
|
|
|
|
|
|
elsif ("$dn" eq "contact") { |
|
231
|
0
|
0
|
|
|
|
|
unless (PlaceContact(\%d, \%s)) { |
|
232
|
0
|
|
|
|
|
|
push @err_msg, "Error in " . Dumper(\%d); |
|
233
|
|
|
|
|
|
|
} |
|
234
|
|
|
|
|
|
|
} |
|
235
|
|
|
|
|
|
|
elsif ("$dn" eq "timeperiod") { |
|
236
|
0
|
0
|
|
|
|
|
unless (PlaceTimeperiod(\%d, \%s)) { |
|
237
|
0
|
|
|
|
|
|
push @err_msg, "Error in " . Dumper(\%d); |
|
238
|
|
|
|
|
|
|
} |
|
239
|
|
|
|
|
|
|
} |
|
240
|
|
|
|
|
|
|
elsif ("$dn" eq "servicedependency") { |
|
241
|
0
|
0
|
|
|
|
|
unless (PlaceServiceDependency(\%d, \%s)) { |
|
242
|
0
|
|
|
|
|
|
push @err_msg, "Error in " . Dumper(\%d); |
|
243
|
|
|
|
|
|
|
} |
|
244
|
|
|
|
|
|
|
} |
|
245
|
|
|
|
|
|
|
elsif ("$dn" eq "hostdependency") { |
|
246
|
0
|
0
|
|
|
|
|
unless (PlaceHostDependency(\%d, \%s)) { |
|
247
|
0
|
|
|
|
|
|
push @err_msg, "Error in " . Dumper(\%d); |
|
248
|
|
|
|
|
|
|
} |
|
249
|
|
|
|
|
|
|
} |
|
250
|
|
|
|
|
|
|
else { |
|
251
|
0
|
|
|
|
|
|
push @err_msg, "Unknown definition type: define $dn"; |
|
252
|
|
|
|
|
|
|
} |
|
253
|
|
|
|
|
|
|
} |
|
254
|
|
|
|
|
|
|
} |
|
255
|
0
|
|
|
|
|
|
close(CFG); |
|
256
|
|
|
|
|
|
|
|
|
257
|
0
|
|
|
|
|
|
return %s; |
|
258
|
|
|
|
|
|
|
} |
|
259
|
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
sub MakeTree { |
|
261
|
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
# Accepts path to Nagios main config file and makes list of included configs. |
|
263
|
|
|
|
|
|
|
# Then parses each cfg file using ParseFile. |
|
264
|
|
|
|
|
|
|
# After that we should merge all results from each ParseFile call and return |
|
265
|
|
|
|
|
|
|
# a reference to full hash. |
|
266
|
|
|
|
|
|
|
|
|
267
|
0
|
|
|
0
|
0
|
|
my ($nagios_cfg, $opts) = @_; |
|
268
|
|
|
|
|
|
|
|
|
269
|
0
|
0
|
|
|
|
|
die("MakeTree: requires nagios config file name") |
|
270
|
|
|
|
|
|
|
unless $nagios_cfg; |
|
271
|
|
|
|
|
|
|
|
|
272
|
0
|
0
|
|
|
|
|
$opts = {} unless $opts; |
|
273
|
0
|
0
|
|
|
|
|
$opts->{'nagios_cfg_base'} = $opts->{'old_base'} if $opts->{'old_base'}; |
|
274
|
0
|
0
|
|
|
|
|
$opts->{'real_base'} = $opts->{'new_base'} if $opts->{'new_base'}; |
|
275
|
|
|
|
|
|
|
|
|
276
|
0
|
0
|
0
|
|
|
|
die("MakeTree: nagios_cfg_base and real_base must be both defined or undefined") |
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
277
|
|
|
|
|
|
|
if $opts->{'nagios_cfg_base'} && !$opts->{'real_base'} |
|
278
|
|
|
|
|
|
|
|| !$opts->{'nagios_cfg_base'} && $opts->{'real_base'}; |
|
279
|
|
|
|
|
|
|
|
|
280
|
0
|
|
|
|
|
|
my @refs; # Store references on cfg parts |
|
281
|
|
|
|
|
|
|
my %main; # Resulting hash |
|
282
|
0
|
0
|
|
|
|
|
open(NAGIOS_MAIN, "$nagios_cfg") or die "Can't open $nagios_cfg : $!\n"; |
|
283
|
0
|
|
|
|
|
|
while () { |
|
284
|
0
|
|
|
|
|
|
chomp; |
|
285
|
0
|
0
|
|
|
|
|
if (/^(\w+)\s*=\s*([^;#]+)$/o) { |
|
286
|
0
|
0
|
|
|
|
|
if ("$1" eq "cfg_file") { |
|
287
|
0
|
|
|
|
|
|
my $include_file = $2; |
|
288
|
0
|
0
|
0
|
|
|
|
if ($opts->{'nagios_cfg_base'} && $opts->{'real_base'}) { |
|
289
|
0
|
|
|
|
|
|
$include_file =~ s/^$opts->{'nagios_cfg_base'}//; |
|
290
|
0
|
|
|
|
|
|
$include_file = $opts->{'real_base'} . "/" . $include_file; |
|
291
|
|
|
|
|
|
|
} |
|
292
|
0
|
|
|
|
|
|
push @{$main{'config'}->{'cfg_file'}}, $include_file; |
|
|
0
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
} |
|
294
|
|
|
|
|
|
|
else { |
|
295
|
0
|
|
|
|
|
|
$main{'config'}->{$1} = $2; |
|
296
|
|
|
|
|
|
|
} |
|
297
|
|
|
|
|
|
|
} |
|
298
|
|
|
|
|
|
|
} |
|
299
|
0
|
|
|
|
|
|
close(NAGIOS_MAIN); |
|
300
|
|
|
|
|
|
|
|
|
301
|
0
|
0
|
|
|
|
|
if (scalar(@{$main{'config'}->{'cfg_file'}}) < 1) { |
|
|
0
|
|
|
|
|
|
|
|
302
|
0
|
|
|
|
|
|
die "No cfg_file directive found in nagios.cfg\n"; |
|
303
|
|
|
|
|
|
|
} |
|
304
|
0
|
|
|
|
|
|
my $max_mod_time = 0; |
|
305
|
|
|
|
|
|
|
|
|
306
|
0
|
|
|
|
|
|
foreach my $curr_cfg (@{$main{'config'}->{'cfg_file'}}) { |
|
|
0
|
|
|
|
|
|
|
|
307
|
0
|
|
|
|
|
|
chomp($curr_cfg); |
|
308
|
0
|
|
|
|
|
|
$curr_cfg =~ s/^cfg_file=//o; |
|
309
|
0
|
0
|
|
|
|
|
next if ($curr_cfg eq 'ndomod.cfg'); |
|
310
|
|
|
|
|
|
|
|
|
311
|
0
|
|
|
|
|
|
my %h = ParseFile($curr_cfg); |
|
312
|
|
|
|
|
|
|
|
|
313
|
0
|
|
|
|
|
|
my $mtime = (stat($curr_cfg))[9]; |
|
314
|
0
|
0
|
|
|
|
|
if ($mtime > $max_mod_time) {$max_mod_time = $mtime;} |
|
|
0
|
|
|
|
|
|
|
|
315
|
|
|
|
|
|
|
|
|
316
|
|
|
|
|
|
|
# Merge in resulting hash |
|
317
|
0
|
|
|
|
|
|
foreach my $k (keys %h) { |
|
318
|
0
|
0
|
|
|
|
|
if (!defined($main{$k})) { |
|
319
|
0
|
|
|
|
|
|
$main{$k} = $h{$k}; |
|
320
|
|
|
|
|
|
|
} |
|
321
|
|
|
|
|
|
|
else { |
|
322
|
0
|
|
|
|
|
|
foreach my $sk (keys %{$h{$k}}) { |
|
|
0
|
|
|
|
|
|
|
|
323
|
0
|
0
|
|
|
|
|
if (!defined($main{$k}->{$sk})) { |
|
324
|
0
|
|
|
|
|
|
$main{$k}->{$sk} = $h{$k}->{$sk}; |
|
325
|
|
|
|
|
|
|
} |
|
326
|
|
|
|
|
|
|
else { |
|
327
|
0
|
|
|
|
|
|
warn "Conflict entries in config!\n"; |
|
328
|
0
|
|
|
|
|
|
warn Dumper($main{$k}->{$sk}); |
|
329
|
0
|
|
|
|
|
|
warn Dumper($h{$k}->{$sk}); |
|
330
|
0
|
|
|
|
|
|
warn "Last config was $curr_cfg\n"; |
|
331
|
0
|
|
|
|
|
|
exit; |
|
332
|
|
|
|
|
|
|
} |
|
333
|
|
|
|
|
|
|
} |
|
334
|
|
|
|
|
|
|
} |
|
335
|
|
|
|
|
|
|
} |
|
336
|
|
|
|
|
|
|
} |
|
337
|
|
|
|
|
|
|
Ym::SetMeta( |
|
338
|
0
|
|
|
|
|
|
\%main, |
|
339
|
|
|
|
|
|
|
{ |
|
340
|
|
|
|
|
|
|
'tree_mod_time' => 0, |
|
341
|
|
|
|
|
|
|
'configs_gen_time' => $max_mod_time, |
|
342
|
|
|
|
|
|
|
} |
|
343
|
|
|
|
|
|
|
); |
|
344
|
|
|
|
|
|
|
|
|
345
|
0
|
|
|
|
|
|
return \%main; |
|
346
|
|
|
|
|
|
|
} |
|
347
|
|
|
|
|
|
|
|
|
348
|
|
|
|
|
|
|
1; |