blib/lib/Ym/ymstat.pl

filter: Statementstmt 18.8% 10 / 53 Branchbran 0.0% 0 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 50.0% 3 / 6 Podpod 0.0% 0 / 3 totaltotal 16.2% 13 / 80 CC 12 SCAR 31.1
CC
12
Cov
14%
TimeCycleStat
30.0
CountK
30.0
myLookup
20.0
CRAP 22.5
« blib/lib/Ym/ymgen.pl ↑ Summary blib/lib/Ym.pm »
1 #!/usr/bin/perl -w
2  
3 package Ym;
4  
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use warnings;
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 TimeCycleStat {
Subroutine TimeCycleStat: not called CC=5 SCAR=34.0
Pod undocumented
11 0 my ($tree) = @_;
12  
13 0 my %stat = ();
14 0 my $verbose = 0;
15  
16 sub myLookup; # Function prototype definition for recursion calls.
17 # Determine value of definition ($opt) for specified object.
18 # If there is no clear definition, than we recursively look in templates.
19  
20 0 ▶ sub myLookup {
Subroutine myLookup: not called CC=4 SCAR=30.0
Pod undocumented
21 0 my ($tree, $leaf, $opt, $tmpl_type) = @_;
22 0 my $ret = 0;
23 0 ▶ if (defined($leaf->{$opt})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $leaf->{$opt}) { } 0 0 0
24 0 $ret = $leaf->{$opt};
25 }
26 else {
27 0 ▶ if (defined($leaf->{'use'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $leaf->{"use"}) 0 0 0
28 0 my $template = $leaf->{'use'};
29 0 ▶ if (!defined($tree->{$tmpl_type}->{$template})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $tree->{$tmpl_type}{$template}) 0 0 0
30 0 return $ret;
31 }
32 0 my $template_ref = $tree->{$tmpl_type}->{$template};
33 0 $ret = myLookup($tree, $template_ref, $opt, $tmpl_type);
34 }
35 }
36 0 return $ret;
37 }
38  
39 0 ▶ sub CountK {
Subroutine CountK: not called CC=5 SCAR=34.0
Pod undocumented
40 0 my ($tree, $ref) = @_;
41  
42 0 ▶ unless (defined($tree->{'config'}->{'interval_length'})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $tree->{"config"}{"interval_length"}) 0 0 0
43 0 die "Error: 'interval_length' option is not defined in nagios.cfg\n";
44 }
45 0 my $interval_length = $tree->{'config'}->{'interval_length'};
46  
47 0 my $retry_field_name = '';
48 0 my $tmpl_type = '';
49  
50 0 ▶ if (defined($ref->{'service_description'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ref->{'service_description'}) { } 0 0 0
51  
52 # Than it is a service
53 0 $retry_field_name = 'retry_check_interval';
54 0 $tmpl_type = 'service_templates';
55 }
56 else {
57  
58 # This is a host
59 0 $retry_field_name = 'retry_interval';
60 0 $tmpl_type = 'host_templates';
61 }
62  
63 my $retry_interval =
64 defined($ref->{$retry_field_name})
65 0 ▶ ? $ref->{$retry_field_name}
Branch: 1 branch
BranchTrueFalseTotal
defined $ref->{$retry_field_name} ? : 0 0 0
66 : myLookup($tree, $ref, $retry_field_name, $tmpl_type);
67  
68 my $max_attempts =
69 defined($ref->{'max_check_attempts'})
70 0 ▶ ? $ref->{'max_check_attempts'}
Branch: 1 branch
BranchTrueFalseTotal
defined $ref->{'max_check_attempts'} ? : 0 0 0
71 : myLookup($tree, $ref, 'max_check_attempts', $tmpl_type);
72  
73 0 my $k = $retry_interval * $max_attempts * $interval_length; # Value in seconds.
74  
75 0 return $k;
76 }
77  
78 0 foreach my $h (keys %{$tree->{'hosts'}}) {
79 0 ▶ ($verbose) && print "$h\n";
Branch: 1 branch
BranchTrueFalseTotal
$verbose and print "$h\n" 0 0 0
80  
81 0 my $href = $tree->{'hosts'}->{$h};
82 0 my $k = CountK($tree, $href);
83  
84 0 push(@{$stat{$k}->{'hosts'}}, $h);
85  
86 0 foreach my $s (keys %{$href->{'services'}}) {
87 0 ▶ ($verbose) && print " $s\n";
Branch: 1 branch
BranchTrueFalseTotal
$verbose and print " $s\n" 0 0 0
88  
89 0 my $sref = $href->{'services'}->{$s};
90 0 my $k = CountK($tree, $sref);
91  
92 #push(@{$stat{$k}->{'services'}}, "$h:$s");
93 0 $stat{$k}->{'services'}->{$s}++;
94 }
95 }
96  
97 0 print Dumper \%stat;
98 }
99  
100 1 1;
« blib/lib/Ym/ymgen.pl ↑ Summary blib/lib/Ym.pm »