line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Monitoring::Plugin::Config; |
2
|
|
|
|
|
|
|
|
3
|
6
|
|
|
6
|
|
77
|
use 5.006; |
|
6
|
|
|
|
|
15
|
|
|
6
|
|
|
|
|
160
|
|
4
|
6
|
|
|
6
|
|
19
|
use strict; |
|
6
|
|
|
|
|
8
|
|
|
6
|
|
|
|
|
124
|
|
5
|
6
|
|
|
6
|
|
20
|
use warnings; |
|
6
|
|
|
|
|
7
|
|
|
6
|
|
|
|
|
148
|
|
6
|
|
|
|
|
|
|
|
7
|
6
|
|
|
6
|
|
23
|
use Carp; |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
972
|
|
8
|
6
|
|
|
6
|
|
24
|
use File::Spec; |
|
6
|
|
|
|
|
6
|
|
|
6
|
|
|
|
|
118
|
|
9
|
6
|
|
|
6
|
|
21
|
use base qw(Config::Tiny); |
|
6
|
|
|
|
|
55
|
|
|
6
|
|
|
|
|
2521
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
my $FILENAME1 = 'plugins.ini'; |
12
|
|
|
|
|
|
|
my $FILENAME2 = 'nagios-plugins.ini'; |
13
|
|
|
|
|
|
|
my $FILENAME3 = 'monitoring-plugins.ini'; |
14
|
|
|
|
|
|
|
my $CURRENT_FILE = undef; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# Config paths ending in nagios (search for $FILENAME1) |
17
|
|
|
|
|
|
|
my @MONITORING_CONFIG_PATH = qw(/etc/nagios /usr/local/nagios/etc /usr/local/etc/nagios /etc/opt/nagios); |
18
|
|
|
|
|
|
|
# Config paths not ending in nagios (search for $FILENAME2) |
19
|
|
|
|
|
|
|
my @CONFIG_PATH = qw(/etc /usr/local/etc /etc/opt); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# Override Config::Tiny::read to default the filename, if not given |
22
|
|
|
|
|
|
|
sub read |
23
|
|
|
|
|
|
|
{ |
24
|
15
|
|
|
15
|
1
|
16
|
my $class = shift; |
25
|
|
|
|
|
|
|
|
26
|
15
|
50
|
|
|
|
23
|
unless ($_[0]) { |
27
|
|
|
|
|
|
|
SEARCH: { |
28
|
15
|
50
|
33
|
|
|
11
|
if ($ENV{MONITORING_CONFIG_PATH} || $ENV{NAGIOS_CONFIG_PATH}) { |
|
15
|
|
|
|
|
39
|
|
29
|
15
|
|
33
|
|
|
49
|
for (split /:/, ($ENV{MONITORING_CONFIG_PATH} || $ENV{NAGIOS_CONFIG_PATH})) { |
30
|
30
|
|
|
|
|
163
|
my $file = File::Spec->catfile($_, $FILENAME1); |
31
|
30
|
100
|
|
|
|
299
|
unshift(@_, $file), last SEARCH if -f $file; |
32
|
15
|
|
|
|
|
58
|
$file = File::Spec->catfile($_, $FILENAME2); |
33
|
15
|
50
|
|
|
|
53
|
unshift(@_, $file), last SEARCH if -f $file; |
34
|
15
|
|
|
|
|
52
|
$file = File::Spec->catfile($_, $FILENAME3); |
35
|
15
|
50
|
|
|
|
49
|
unshift(@_, $file), last SEARCH if -f $file; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
} |
38
|
0
|
|
|
|
|
0
|
for (@MONITORING_CONFIG_PATH) { |
39
|
0
|
|
|
|
|
0
|
my $file = File::Spec->catfile($_, $FILENAME1); |
40
|
0
|
0
|
|
|
|
0
|
unshift(@_, $file), last SEARCH if -f $file; |
41
|
|
|
|
|
|
|
} |
42
|
0
|
|
|
|
|
0
|
for (@CONFIG_PATH) { |
43
|
0
|
|
|
|
|
0
|
my $file = File::Spec->catfile($_, $FILENAME2); |
44
|
0
|
0
|
|
|
|
0
|
unshift(@_, $file), last SEARCH if -f $file; |
45
|
0
|
|
|
|
|
0
|
$file = File::Spec->catfile($_, $FILENAME3); |
46
|
0
|
0
|
|
|
|
0
|
unshift(@_, $file), last SEARCH if -f $file; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
# Use die instead of croak, so we can pass a clean message downstream |
51
|
15
|
50
|
|
|
|
32
|
die "Cannot find '$FILENAME1', '$FILENAME2' or '$FILENAME3' in any standard location.\n" unless $_[0]; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
15
|
|
|
|
|
15
|
$CURRENT_FILE = $_[0]; |
55
|
15
|
|
|
|
|
45
|
$class->SUPER::read( @_ ); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# Straight from Config::Tiny - only changes are repeated property key support |
59
|
|
|
|
|
|
|
# Would be nice if we could just override the per-line handling ... |
60
|
|
|
|
|
|
|
sub read_string |
61
|
|
|
|
|
|
|
{ |
62
|
15
|
50
|
|
15
|
1
|
615
|
my $class = ref $_[0] ? ref shift : shift; |
63
|
15
|
|
|
|
|
34
|
my $self = bless {}, $class; |
64
|
15
|
50
|
|
|
|
24
|
return undef unless defined $_[0]; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
# Parse the file |
67
|
15
|
|
|
|
|
13
|
my $ns = '_'; |
68
|
15
|
|
|
|
|
15
|
my $counter = 0; |
69
|
15
|
|
|
|
|
659
|
foreach ( split /(?:\015{1,2}\012|\015|\012)/, shift ) { |
70
|
525
|
|
|
|
|
294
|
$counter++; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# Skip comments and empty lines |
73
|
525
|
100
|
|
|
|
782
|
next if /^\s*(?:\#|\;|$)/; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
# Handle section headers |
76
|
405
|
100
|
|
|
|
638
|
if ( /^\s*\[\s*(.+?)\s*\]\s*$/ ) { |
77
|
|
|
|
|
|
|
# Create the sub-hash if it doesn't exist. |
78
|
|
|
|
|
|
|
# Without this sections without keys will not |
79
|
|
|
|
|
|
|
# appear at all in the completed struct. |
80
|
120
|
|
50
|
|
|
377
|
$self->{$ns = $1} ||= {}; |
81
|
120
|
|
|
|
|
106
|
next; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
# Handle properties |
85
|
285
|
50
|
|
|
|
657
|
if ( /^\s*([^=]+?)\s*=\s*(.*?)\s*$/ ) { |
86
|
285
|
|
|
|
|
163
|
push @{$self->{$ns}->{$1}}, $2; |
|
285
|
|
|
|
|
520
|
|
87
|
285
|
|
|
|
|
239
|
next; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
0
|
return $self->_error( "Syntax error at line $counter: '$_'" ); |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
15
|
|
|
|
|
87
|
$self; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
0
|
|
|
0
|
1
|
0
|
sub write { croak "Write access not permitted" } |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
# Return last file used by read(); |
99
|
15
|
|
|
15
|
0
|
31
|
sub mp_getfile { return $CURRENT_FILE; } |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
1; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
__END__ |