blib/lib/Ym/ymcommon.pl

filter: Statementstmt 5.1% 10 / 194 Branchbran 0.0% 0 / 108 Conditioncond 0.0% 0 / 42 MC/DCmcdc 0.0% 0 / 24 Subroutinesub 15.7% 3 / 19 Podpod 0.0% 0 / 16 totaltotal 3.2% 13 / 403 CC 85 SCAR 59.0
CC
85
Cov
3%
GetObjectList
1056.0
Backup
132.0
VerifyDataStructure
90.0
CRAP 363.3
« blib/lib/Ym/ymparse.pl ↑ Summary blib/lib/Ym/ymgen.pl »
1 #!/usr/bin/perl
2  
3 package Ym;
4  
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use Ym;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 0 ▶sub TouchTree {
Subroutine TouchTree: not called CC=2 SCAR=17.9
Pod undocumented
11 0 my ($tree) = @_;
12 0 ▶ die "TouchTree: tree reference is missing in args.\n" unless $tree;
Branch: 1 branch
BranchTrueFalseTotal
unless $tree 0 0 0
13  
14 0 $tree->{'meta'}->{'tree_mod_time'} = time();
15 }
16  
17 0 ▶sub TouchConfigs {
Subroutine TouchConfigs: not called CC=2 SCAR=17.9
Pod undocumented
18 0 my ($tree) = @_;
19 0 my $sub_name = 'TouchConfigs';
20  
21 0 ▶ defined($tree)
Branch: 1 branch
BranchTrueFalseTotal
defined $tree or die "${sub_name}: tree reference is missing in args.\n" 0 0 0
22 or die "$sub_name: tree reference is missing in args.\n";
23  
24 0 $tree->{'meta'}->{'configs_gen_time'} = time();
25 }
26  
27 0 ▶sub SetMeta {
Subroutine SetMeta: not called CC=4 SCAR=30.0
Pod undocumented
28 0 my ($tree, $opts) = @_;
29 0 my $sub_name = 'SetMeta';
30  
31 0 ▶ defined($tree)
Branch: 1 branch
BranchTrueFalseTotal
defined $tree or die "${sub_name}: tree reference is missing in args.\n" 0 0 0
32 or die "$sub_name: tree reference is missing in args.\n";
33  
34 0 ▶ $opts = {} unless $opts;
Branch: 1 branch
BranchTrueFalseTotal
unless $opts 0 0 0
35  
36 0 foreach my $k (keys %$opts) {
37 0 $tree->{'meta'}->{$k} = $opts->{$k};
38 }
39 }
40  
41 0 ▶sub GetMeta {
Subroutine GetMeta: not called CC=4 SCAR=30.0
Pod undocumented
42 0 my ($tree, $opt) = @_;
43 0 my $sub_name = 'GetMeta';
44  
45 0 ▶ defined($tree)
Branch: 1 branch
BranchTrueFalseTotal
defined $tree or die "${sub_name}: tree reference is missing in args.\n" 0 0 0
46 or die "$sub_name: tree reference is missing in args.\n";
47  
48 0 ▶ defined($opt)
Branch: 1 branch
BranchTrueFalseTotal
defined $opt or die "${sub_name}: option name is missing in args.\n" 0 0 0
49 or die "$sub_name: option name is missing in args.\n";
50  
51 0 ▶ if (defined($tree->{'meta'}->{$opt})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $tree->{'meta'}{$opt}) { } 0 0 0
52 0 return $tree->{'meta'}->{$opt};
53 }
54 else {
55 0 return undef;
56 }
57 }
58  
59 0 ▶sub Ask_For_Change {
Subroutine Ask_For_Change: not called CC=7 SCAR=40.3
Pod undocumented
60  
61 # Check if it is safe to auto generate configs for Nagios.
62  
63 0 my ($tree) = @_;
64 0 my $sub_name = 'Ask_For_Change';
65  
66 0 ▶ defined($tree)
Branch: 1 branch
BranchTrueFalseTotal
defined $tree or die "${sub_name}: tree reference is missing in args.\n" 0 0 0
67 or die "$sub_name: tree reference is missing in args.\n";
68  
69 0 my $tree_mod_time = GetMeta($tree, 'tree_mod_time');
70 0 my $configs_gen_time = GetMeta($tree, 'configs_gen_time');
71  
72 0 $tree_mod_time |= 0;
73 0 $configs_gen_time |= 0;
74  
75 0 for my $c (@Ym::NAGIOS_CONFIGS) {
76 0 my $file = "$Ym::NAGIOS_CFG_DIR/$c";
77  
78 0 ▶ next unless (-e $file);
Branch: 1 branch
BranchTrueFalseTotal
unless -e $file 0 0 0
79  
80 0 my $mtime = (stat("$Ym::NAGIOS_CFG_DIR/$c"))[9];
81  
82 0 ▶ if ($mtime < $tree_mod_time
Branch: 1 branch
BranchTrueFalseTotal
if ($mtime < $tree_mod_time or $configs_gen_time > 0 and $mtime > $configs_gen_time) 0 0 0
Condition0%0/6
$mtime < $tree_mod_time or $configs_gen_time > 0 and $mtime > $configs_gen_time
l!l&&r!l&&!r
000
$configs_gen_time > 0 and $mtime > $configs_gen_time
!ll&&!rl&&r
000
MC/DC0%0/3
$mtime < $tree_mod_time or $configs_gen_time > 0 and $mtime > $configs_gen_time
$mtime < $tree_mod_time $configs_gen_time > 0 $mtime > $configs_gen_time
Truth table0%0/4
A or B and C
A= $mtime < $tree_mod_timeB= $configs_gen_time > 0C= $mtime > $configs_gen_time
ABCresult
1XX1
0111
00X0
0100
83 || ($configs_gen_time > 0 && $mtime > $configs_gen_time))
84 {
85 0 return 0;
86 }
87 }
88  
89 0 return 1;
90 }
91  
92 0 ▶sub GetMembers {
Subroutine GetMembers: not called CC=4 SCAR=30.0
Pod undocumented
93 0 my ($group, $grp_branch) = @_;
94  
95 0 my @members = ();
96  
97 0 ▶ if(!defined($grp_branch)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $grp_branch and defined $grp_branch->{$group}) 0 0 0
Condition0%0/3
defined $grp_branch and defined $grp_branch->{$group}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $grp_branch and defined $grp_branch->{$group}
defined $grp_branch defined $grp_branch->{$group}
Truth table0%0/3
A and B
A= defined $grp_branchB= defined $grp_branch->{$group}
ABresult
0X0
100
111
98 || !defined($grp_branch->{$group}))
99 {
100 0 return \@members;
101 }
102  
103 0 foreach my $m (split (/[,:;\s]+/o,
104 $grp_branch->{$group}->{'members'}))
105 {
106 0 push(@members, $m);
107 }
108  
109 0 return \@members;
110  
111 # Note thar there may be hostgroup_members or contactgroup_members attribute
112 # If so, we should recursively look into other groups.
113 # I'll add this feature if someone need it.
114 }
115  
116 0 ▶sub read_file_macros {
Subroutine read_file_macros: not called CC=3 SCAR=24.8
Pod undocumented
117 0 my ($f) = @_;
118 0 my $sub_name = 'read_file_macros';
119 0 my $file_contents = '';
120  
121 0 ▶ if ($f !~ /^READ_FILE=(.*)/o) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($f =~ /^READ_FILE=(.*)/o) 0 0 0
122  
123 0 die "$sub_name: Error in argument: [$f]. ".
124 "File name is missing.\n";
125 }
126
127 0 my $fname = $1;
128  
129 0 ▶ open(LIST, "<$fname") or die "Can't open [$fname]: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
open LIST, "<$fname" or die "Can't open [$fname]: $!\n" 0 0 0
130 0 $/ = undef;
131  
132 0 $file_contents = <LIST>;
133  
134 0 close(LIST);
135  
136 0 return \$file_contents;
137 }
138  
139 0 ▶sub GetObjectList {
Subroutine GetObjectList: not called CC=32 SCAR=69.6
Pod undocumented
140 0 my ($obj_ref, $grp_ref, $opts) = @_;
141 0 my $sub_name = 'GetObjectList';
142  
143 0 ▶ $opts = {} unless $opts;
Branch: 1 branch
BranchTrueFalseTotal
unless $opts 0 0 0
144  
145 0 my $res;
146 0 @$res = [];
147  
148 # Check for empty input
149 0 ▶ if(!defined($obj_ref) && !defined($grp_ref)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $obj_ref or defined $grp_ref) 0 0 0
Condition0%0/3
defined $obj_ref or defined $grp_ref
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $obj_ref or defined $grp_ref
defined $obj_ref defined $grp_ref
Truth table0%0/3
A or B
A= defined $obj_refB= defined $grp_ref
ABresult
1X1
011
000
150 0 return $res;
151 }
152  
153 # Check args type
154 0 ▶ if(defined($obj_ref)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $obj_ref and !ref($obj_ref) || ref $obj_ref ne "ARRAY") 0 0 0
Condition0%0/6
defined $obj_ref and !ref($obj_ref) || ref $obj_ref ne "ARRAY"
!ll&&!rl&&r
000
not ref $obj_ref or ref $obj_ref ne "ARRAY"
l!l&&r!l&&!r
000
MC/DC0%0/3
defined $obj_ref and !ref($obj_ref) || ref $obj_ref ne "ARRAY"
defined $obj_ref not ref $obj_ref ref $obj_ref ne "ARRAY"
Truth table0%0/4
A and not(B) or C
A= defined $obj_refB= not ref $obj_refC= ref $obj_ref ne "ARRAY"
ABCresult
0XX0
1000
11X1
1011
155 && (!ref($obj_ref) || ref($obj_ref) ne 'ARRAY'))
156 {
157 0 die "$sub_name: first argument must be an array reference\n";
158 }
159  
160 0 ▶ if(defined($grp_ref)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $grp_ref and !ref($grp_ref) || ref $grp_ref ne "ARRAY") 0 0 0
Condition0%0/6
defined $grp_ref and !ref($grp_ref) || ref $grp_ref ne "ARRAY"
!ll&&!rl&&r
000
not ref $grp_ref or ref $grp_ref ne "ARRAY"
l!l&&r!l&&!r
000
MC/DC0%0/3
defined $grp_ref and !ref($grp_ref) || ref $grp_ref ne "ARRAY"
defined $grp_ref not ref $grp_ref ref $grp_ref ne "ARRAY"
Truth table0%0/4
A and not(B) or C
A= defined $grp_refB= not ref $grp_refC= ref $grp_ref ne "ARRAY"
ABCresult
0XX0
1000
11X1
1011
161 && (!ref($grp_ref) || ref($grp_ref) ne 'ARRAY'))
162 {
163 0 die "$sub_name: second argument must be an array reference\n";
164 }
165  
166 # Check for mandatory options
167 0 ▶ if(defined($obj_ref)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $obj_ref) 0 0 0
168 0 ▶ if(defined($opts->{'allow_regexp_in_obj'})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opts->{"allow_regexp_in_obj"} and not defined $opts->{"obj_branch"}) 0 0 0
Condition0%0/3
defined $opts->{"allow_regexp_in_obj"} and not defined $opts->{"obj_branch"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $opts->{"allow_regexp_in_obj"} and not defined $opts->{"obj_branch"}
defined $opts->{"allow_regexp_in_obj"} not defined $opts->{"obj_branch"}
Truth table0%0/3
A and not(B)
A= defined $opts->{"allow_regexp_in_obj"}B= not defined $opts->{"obj_branch"}
ABresult
0X0
100
111
169 && !defined($opts->{'obj_branch'}))
170 {
171 0 die "$sub_name: Programmer error - 'obj_branch' option is not set.\n";
172 }
173 }
174  
175 0 ▶ if(defined($grp_ref)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $grp_ref and not defined $opts->{"grp_branch"}) 0 0 0
Condition0%0/3
defined $grp_ref and not defined $opts->{"grp_branch"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $grp_ref and not defined $opts->{"grp_branch"}
defined $grp_ref not defined $opts->{"grp_branch"}
Truth table0%0/3
A and not(B)
A= defined $grp_refB= not defined $opts->{"grp_branch"}
ABresult
0X0
100
111
176 && !defined($opts->{'grp_branch'}))
177 {
178 0 die "$sub_name: Programmer error - 'grp_branch' option is not set.\n";
179 }
180  
181 0 my $split_pattern = '[,:;\n\s]+';
182 0 my %tmp = ();
183 0 my $verbose = $Ym::VERBOSE;
184  
185 0 ▶ if(defined($obj_ref)) { # Extract objects
Branch: 1 branch
BranchTrueFalseTotal
if (defined $obj_ref) 0 0 0
186  
187 0 my $obj_raw = '';
188  
189 0 foreach my $item (@$obj_ref) {
190 0 ▶ if ($item =~ /^\/(.*)\//o) { # If item contains REGEXP
Branch: 1 branch
BranchTrueFalseTotal
if ($item =~ m[^/(.*)/]o) { } 0 0 0
191 0 my $regex = $1;
192
193 0 ▶ ($verbose) && print "Found REGEXP $1\n";
Branch: 1 branch
BranchTrueFalseTotal
$verbose and print "Found REGEXP $1\n" 0 0 0
194  
195 0 ▶ unless($opts->{'allow_regex_in_obj'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($opts->{"allow_regex_in_obj"}) 0 0 0
196 0 die "$sub_name: invalid argument [$item]. ".
197 "No regex allowed in this command.\n";
198 }
199  
200 0 foreach my $obj (keys %{$opts->{'obj_branch'}}) {
201 0 ▶ if ($obj =~ /$regex/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($obj =~ /$regex/) 0 0 0
202 0 $tmp{$obj} = 1;
203 }
204 }
205 }
206 else {
207 0 ▶ if($item =~ /^READ_FILE/o) { # READ_FILE macros found
Branch: 1 branch
BranchTrueFalseTotal
if ($item =~ /^READ_FILE/o) { } 0 0 0
208
209 0 ▶ ($verbose) && print "Found MACROS $item\n";
Branch: 1 branch
BranchTrueFalseTotal
$verbose and print "Found MACROS $item\n" 0 0 0
210
211 0 $obj_raw = ${read_file_macros($item)};
212 }
213 else {
214 0 $obj_raw = $item;
215 }
216  
217 # Split obj_raw and add objects to %tmp
218 0 foreach my $obj (split($split_pattern, $obj_raw)) {
219 0 $tmp{$obj} = 1;
220 }
221 }
222 }
223 } # End extract objects
224  
225 0 ▶ if(defined($grp_ref)) { # Extract group members
Branch: 1 branch
BranchTrueFalseTotal
if (defined $grp_ref) 0 0 0
226
227 0 my $grp_raw = '';
228  
229 0 foreach my $item (@$grp_ref) {
230  
231 0 ▶ if ($item =~ /^\/(.*)\//o) { # If item contains REGEXP
Branch: 1 branch
BranchTrueFalseTotal
if ($item =~ m[^/(.*)/]o) 0 0 0
232 0 die "$sub_name: invalid argument [$item]. ".
233 "No regexp allowed in group definition.\n";
234 }
235  
236 0 ▶ if($item =~ /^READ_FILE/o) { # READ_FILE macros found
Branch: 1 branch
BranchTrueFalseTotal
if ($item =~ /^READ_FILE/o) { } 0 0 0
237
238 0 ▶ ($verbose) && print "Found MACROS $item\n";
Branch: 1 branch
BranchTrueFalseTotal
$verbose and print "Found MACROS $item\n" 0 0 0
239  
240 0 $grp_raw = ${read_file_macros($item)};
241 }
242 else {
243 0 $grp_raw = $item;
244 }
245 }
246  
247 # Split grp_raw, find members for each group and add them to %tmp
248 0 foreach my $grp (split($split_pattern, $grp_raw)) {
249  
250 0 my $grp_members = GetMembers($grp, $opts->{'grp_branch'});
251  
252 0 foreach my $m (@$grp_members) {
253 0 $tmp{$m} = 1;
254 }
255 }
256 } # End extract group members
257  
258 0 @$res = keys %tmp;
259  
260 0 return $res;
261 }
262  
263 0 ▶sub VerifyDataStructure {
Subroutine VerifyDataStructure: not called CC=9 SCAR=45.0
Pod undocumented
264 0 my ($tree) = @_;
265  
266 0 foreach my $class (sort keys %$tree) {
267 0 ▶ next if ($class eq "config" || $class eq "meta");
Branch: 1 branch
BranchTrueFalseTotal
if $class eq "config" or $class eq "meta" 0 0 0
Condition0%0/3
$class eq "config" or $class eq "meta"
l!l&&r!l&&!r
000
MC/DC0%0/2
$class eq "config" or $class eq "meta"
$class eq "config" $class eq "meta"
Truth table0%0/3
A or B
A= $class eq "config"B= $class eq "meta"
ABresult
1X1
011
000
268  
269 0 foreach my $object (keys %{$tree->{$class}}) {
270 0 my $count = scalar(keys %{$tree->{$class}->{$object}});
271  
272 0 ▶ if ($count eq 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($count eq 0) 0 0 0
273 0 print "Object: $class -> $object has too few elements $count\n";
274 }
275  
276 0 ▶ if ($class =~ /hosts|service_dependencies/o) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class =~ /hosts|service_dependencies/o) 0 0 0
277  
278 0 ▶ my $k = ($class eq "hosts") ? "services" : "service_dependencies";
Branch: 1 branch
BranchTrueFalseTotal
$class eq 'hosts' ? : 0 0 0
279  
280 0 my $count = scalar(keys %{$tree->{$class}->{$object}->{$k}});
281  
282 0 ▶ if ($count eq 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($count eq 0) 0 0 0
283 0 print "Object: $class -> $object -> $k has too few elements $count\n";
284 }
285 }
286 }
287 }
288 }
289  
290 0 ▶sub ShowDiff {
Subroutine ShowDiff: not called CC=1 SCAR=6.9
Pod undocumented
291 # Shows difference between two (previous and current) versions of data structure
292  
293 0 my ($old, $new) = @_;
294  
295 0 ▶ sub Compare($$) {
Subroutine Compare: not called CC=7 SCAR=40.3
Pod undocumented
296 0 my ($one, $two) = @_;
297 0 my @res;
298  
299 0 foreach my $class (keys %{$one}) {
300  
301 0 foreach my $object (keys %{$one->{$class}}) {
302 0 ▶ if (!defined($two->{$class}->{$object})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $two->{$class}{$object}) 0 0 0
303  
304 0 push @res, "{$class}->{$object}";
305 0 next;
306 }
307 0 ▶ if ($class eq "hosts") {
Branch: 1 branch
BranchTrueFalseTotal
if ($class eq "hosts") 0 0 0
308  
309 0 foreach my $srv (keys %{$one->{$class}->{$object}->{'services'}}) {
310  
311 0 ▶ if (!defined($two->{$class}->{$object}->{'services'}->{$srv})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $two->{$class}{$object}{"services"}{$srv}) 0 0 0
312 0 push @res, "{$class}->{$object}->{services}->{$srv}";
313 }
314 }
315 }
316 }
317 }
318 0 return \@res;
319 }
320  
321 0 ▶ sub PrintDiff {
Subroutine PrintDiff: not called CC=4 SCAR=30.0
Pod undocumented
322 0 my ($ref, $prefix) = @_;
323 0 my $sub_name = 'PrintDiff';
324  
325 0 ▶ if (ref($ref) ne "ARRAY") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $ref ne "ARRAY") 0 0 0
326 0 warn("$sub_name: first argument must be an ARRAY reference\n");
327 0 return 0;
328 }
329  
330 0 ▶ if (scalar(@$ref) > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$ref > 0) 0 0 0
331 0 foreach my $l (@$ref) {
332 0 print "$prefix $l\n";
333 }
334 }
335 }
336  
337 0 my $deleted = Compare($old, $new);
338 0 my $added = Compare($new, $old);
339  
340 0 PrintDiff($deleted, "Deleted");
341 0 PrintDiff($added, "Added");
342  
343 0 return 1;
344 }
345  
346 0 ▶sub GetStruct {
Subroutine GetStruct: not called CC=5 SCAR=34.0
Pod undocumented
347 0 my ($file, $cfg) = @_;
348 0 my $ref;
349  
350 0 ▶ if (-e $file) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $file) { } 0 0 0
351 0 ▶ ($Ym::VERBOSE) && print "Reading structure from file\n\n";
Branch: 1 branch
BranchTrueFalseTotal
$Ym::VERBOSE and print "Reading structure from file\n\n" 0 0 0
352 0 ▶ $ref = Storable::retrieve($file)
Branch: 1 branch
BranchTrueFalseTotal
$ref = Storable::retrieve($file) or die "GetStruct: Can't load structure file $file : $!\n" 0 0 0
353 or die "GetStruct: Can't load structure file $file : $!\n";
354 }
355 else {
356 0 ▶ ($Ym::VERBOSE) && print "Ym::MakeTree\n";
Branch: 1 branch
BranchTrueFalseTotal
$Ym::VERBOSE and print "Ym::MakeTree\n" 0 0 0
357 0 $ref = Ym::MakeTree($cfg);
358 }
359 0 return $ref;
360 }
361  
362 0 ▶sub CloneStruct {
Subroutine CloneStruct: not called CC=2 SCAR=17.9
Pod undocumented
363 0 my ($tree) = @_;
364 0 ▶ my $clone = Storable::dclone($tree)
Branch: 1 branch
BranchTrueFalseTotal
my $clone = &Storable::dclone($tree) or die "CloneStruct: Can't clone structure : $!\n" 0 0 0
365 or die "CloneStruct: Can't clone structure : $!\n";
366  
367 0 return $clone;
368 }
369  
370 0 ▶sub SaveStruct {
Subroutine SaveStruct: not called CC=3 SCAR=24.8
Pod undocumented
371 0 my ($tree, $file) = @_;
372 0 my $tmp_file = "$file.tmp";
373 0 my $sub_name = 'SaveStruct';
374  
375 0 ▶ Storable::store($tree, $tmp_file)
Branch: 1 branch
BranchTrueFalseTotal
Storable::store($tree, $tmp_file) or warn "${sub_name}: Store fo $tmp_file failed\n" 0 0 0
376 or warn "$sub_name: Store fo $tmp_file failed\n";
377  
378 0 ▶ rename($tmp_file, $file)
Branch: 1 branch
BranchTrueFalseTotal
rename $tmp_file, $file or warn "${sub_name}: Failed to rename $tmp_file to $file\n" 0 0 0
379 or warn "$sub_name: Failed to rename $tmp_file to $file\n";
380 }
381  
382 0 ▶sub Backup {
Subroutine Backup: not called CC=11 SCAR=48.8
Pod undocumented
383 0 my ($opts) = @_;
384 0 my $sub_name = 'Backup';
385
386 0 ▶ $opts = {} unless $opts;
Branch: 1 branch
BranchTrueFalseTotal
unless $opts 0 0 0
387  
388 0 my $stamp=`date +%Y-%m-%d_%H-%M-%S`;
389 0 chomp($stamp);
390  
391 0 ▶ if(!defined($Ym::BACKUP_PATH)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $Ym::BACKUP_PATH) 0 0 0
392 0 die "$sub_name: [BACKUP_PATH] variable is not defined in config.\n";
393 }
394  
395 0 ▶ unless( -d $Ym::BACKUP_PATH && -w $Ym::BACKUP_PATH ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $Ym::BACKUP_PATH and -w $Ym::BACKUP_PATH) 0 0 0
Condition0%0/3
-d $Ym::BACKUP_PATH and -w $Ym::BACKUP_PATH
!ll&&!rl&&r
000
MC/DC0%0/2
-d $Ym::BACKUP_PATH and -w $Ym::BACKUP_PATH
-d $Ym::BACKUP_PATH -w $Ym::BACKUP_PATH
Truth table0%0/3
A and B
A= -d $Ym::BACKUP_PATHB= -w $Ym::BACKUP_PATH
ABresult
0X0
100
111
396 0 die "$sub_name: [$Ym::BACKUP_PATH] is not a writable dir.\n";
397 }
398  
399 0 my $bckp_dir = "$Ym::BACKUP_PATH/$stamp";
400  
401 0 ▶ opendir(DIR, $Ym::NAGIOS_CFG_DIR)
Branch: 1 branch
BranchTrueFalseTotal
opendir DIR, $Ym::NAGIOS_CFG_DIR or die "${sub_name}: Can not open [$Ym::NAGIOS_CFG_DIR]: $!\n" 0 0 0
402 or die "$sub_name: Can not open [$Ym::NAGIOS_CFG_DIR]: $!\n";
403  
404 0 ▶ my @contents = grep { /^[^.]/o && /\.cfg$/o && -f "$Ym::NAGIOS_CFG_DIR/$_" } readdir(DIR);
Condition0%0/6
/^[^.]/o && /\.cfg$/o && -f "$Ym::NAGIOS_CFG_DIR/$_"
!ll&&!rl&&r
000
/^[^.]/o and /\.cfg$/o
!ll&&!rl&&r
000
MC/DC0%0/3
/^[^.]/o && /\.cfg$/o && -f "$Ym::NAGIOS_CFG_DIR/$_"
/^[^.]/o /\.cfg$/o -f "$Ym::NAGIOS_CFG_DIR/$_"
Truth table0%0/4
A and B && C
A= /^[^.]/oB= /\.cfg$/oC= -f "$Ym::NAGIOS_CFG_DIR/$_"
ABCresult
0XX0
10X0
1100
1111
405  
406 0 closedir(DIR);
407  
408 0 ▶ mkdir($bckp_dir)
Branch: 1 branch
BranchTrueFalseTotal
mkdir $bckp_dir or die "${sub_name}: Can not create [$bckp_dir]: $!\n" 0 0 0
409 or die "$sub_name: Can not create [$bckp_dir]: $!\n";
410  
411 0 foreach my $f (@contents) {
412 0 ▶ File::Copy::copy("$Ym::NAGIOS_CFG_DIR/$f", "$bckp_dir/$f")
Branch: 1 branch
BranchTrueFalseTotal
File::Copy::copy("$Ym::NAGIOS_CFG_DIR/$f", "$bckp_dir/$f") or die "${sub_name}: Can not copy [$Ym::NAGIOS_CFG_DIR/$f] to [$bckp_dir/$f]: $!\n" 0 0 0
413 or die "$sub_name: Can not copy [$Ym::NAGIOS_CFG_DIR/$f] to [$bckp_dir/$f]: $!\n";
414 }
415  
416 0 return $bckp_dir;
417 }
418  
419 1 1;
« blib/lib/Ym/ymparse.pl ↑ Summary blib/lib/Ym/ymgen.pl »