line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/perl -w |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Ym; |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
30
|
|
6
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
27
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
5
|
use Ym; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
573
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub TimeCycleStat { |
11
|
0
|
|
|
0
|
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
|
|
|
|
|
|
|
sub myLookup { |
21
|
0
|
|
|
0
|
0
|
|
my ($tree, $leaf, $opt, $tmpl_type) = @_; |
22
|
0
|
|
|
|
|
|
my $ret = 0; |
23
|
0
|
0
|
|
|
|
|
if (defined($leaf->{$opt})) { |
24
|
0
|
|
|
|
|
|
$ret = $leaf->{$opt}; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
else { |
27
|
0
|
0
|
|
|
|
|
if (defined($leaf->{'use'})) { |
28
|
0
|
|
|
|
|
|
my $template = $leaf->{'use'}; |
29
|
0
|
0
|
|
|
|
|
if (!defined($tree->{$tmpl_type}->{$template})) { |
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
|
|
|
|
|
|
|
sub CountK { |
40
|
0
|
|
|
0
|
0
|
|
my ($tree, $ref) = @_; |
41
|
|
|
|
|
|
|
|
42
|
0
|
0
|
|
|
|
|
unless (defined($tree->{'config'}->{'interval_length'})) { |
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
|
0
|
|
|
|
|
if (defined($ref->{'service_description'})) { |
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
|
0
|
0
|
|
|
|
|
my $retry_interval = |
64
|
|
|
|
|
|
|
defined($ref->{$retry_field_name}) |
65
|
|
|
|
|
|
|
? $ref->{$retry_field_name} |
66
|
|
|
|
|
|
|
: myLookup($tree, $ref, $retry_field_name, $tmpl_type); |
67
|
|
|
|
|
|
|
|
68
|
0
|
0
|
|
|
|
|
my $max_attempts = |
69
|
|
|
|
|
|
|
defined($ref->{'max_check_attempts'}) |
70
|
|
|
|
|
|
|
? $ref->{'max_check_attempts'} |
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'}}) { |
|
0
|
|
|
|
|
|
|
79
|
0
|
0
|
|
|
|
|
($verbose) && print "$h\n"; |
80
|
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
my $href = $tree->{'hosts'}->{$h}; |
82
|
0
|
|
|
|
|
|
my $k = CountK($tree, $href); |
83
|
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
|
push(@{$stat{$k}->{'hosts'}}, $h); |
|
0
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
|
foreach my $s (keys %{$href->{'services'}}) { |
|
0
|
|
|
|
|
|
|
87
|
0
|
0
|
|
|
|
|
($verbose) && print " $s\n"; |
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; |