line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Monitoring::Plugin::Config; |
2
|
|
|
|
|
|
|
|
3
|
6
|
|
|
6
|
|
110
|
use 5.006; |
|
6
|
|
|
|
|
17
|
|
|
6
|
|
|
|
|
224
|
|
4
|
6
|
|
|
6
|
|
27
|
use strict; |
|
6
|
|
|
|
|
8
|
|
|
6
|
|
|
|
|
178
|
|
5
|
6
|
|
|
6
|
|
24
|
use warnings; |
|
6
|
|
|
|
|
9
|
|
|
6
|
|
|
|
|
179
|
|
6
|
|
|
|
|
|
|
|
7
|
6
|
|
|
6
|
|
26
|
use Carp; |
|
6
|
|
|
|
|
14
|
|
|
6
|
|
|
|
|
1115
|
|
8
|
6
|
|
|
6
|
|
33
|
use File::Spec; |
|
6
|
|
|
|
|
7
|
|
|
6
|
|
|
|
|
161
|
|
9
|
6
|
|
|
6
|
|
25
|
use base qw(Config::Tiny); |
|
6
|
|
|
|
|
73
|
|
|
6
|
|
|
|
|
3110
|
|
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
|
11
|
my $class = shift; |
25
|
|
|
|
|
|
|
|
26
|
15
|
50
|
|
|
|
26
|
unless ($_[0]) { |
27
|
|
|
|
|
|
|
SEARCH: { |
28
|
15
|
50
|
33
|
|
|
11
|
if ($ENV{MONITORING_CONFIG_PATH} || $ENV{NAGIOS_CONFIG_PATH}) { |
|
15
|
|
|
|
|
36
|
|
29
|
15
|
|
33
|
|
|
59
|
for (split /:/, ($ENV{MONITORING_CONFIG_PATH} || $ENV{NAGIOS_CONFIG_PATH})) { |
30
|
30
|
|
|
|
|
206
|
my $file = File::Spec->catfile($_, $FILENAME1); |
31
|
30
|
100
|
|
|
|
307
|
unshift(@_, $file), last SEARCH if -f $file; |
32
|
15
|
|
|
|
|
75
|
$file = File::Spec->catfile($_, $FILENAME2); |
33
|
15
|
50
|
|
|
|
69
|
unshift(@_, $file), last SEARCH if -f $file; |
34
|
15
|
|
|
|
|
60
|
$file = File::Spec->catfile($_, $FILENAME3); |
35
|
15
|
50
|
|
|
|
64
|
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
|
|
|
|
30
|
die "Cannot find '$FILENAME1', '$FILENAME2' or '$FILENAME3' in any standard location.\n" unless $_[0]; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
15
|
|
|
|
|
20
|
$CURRENT_FILE = $_[0]; |
55
|
15
|
|
|
|
|
66
|
$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
|
690
|
my $class = ref $_[0] ? ref shift : shift; |
63
|
15
|
|
|
|
|
37
|
my $self = bless {}, $class; |
64
|
15
|
50
|
|
|
|
27
|
return undef unless defined $_[0]; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
# Parse the file |
67
|
15
|
|
|
|
|
14
|
my $ns = '_'; |
68
|
15
|
|
|
|
|
15
|
my $counter = 0; |
69
|
15
|
|
|
|
|
752
|
foreach ( split /(?:\015{1,2}\012|\015|\012)/, shift ) { |
70
|
525
|
|
|
|
|
362
|
$counter++; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# Skip comments and empty lines |
73
|
525
|
100
|
|
|
|
1017
|
next if /^\s*(?:\#|\;|$)/; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
# Handle section headers |
76
|
405
|
100
|
|
|
|
764
|
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
|
|
|
454
|
$self->{$ns = $1} ||= {}; |
81
|
120
|
|
|
|
|
108
|
next; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
# Handle properties |
85
|
285
|
50
|
|
|
|
768
|
if ( /^\s*([^=]+?)\s*=\s*(.*?)\s*$/ ) { |
86
|
285
|
|
|
|
|
199
|
push @{$self->{$ns}->{$1}}, $2; |
|
285
|
|
|
|
|
581
|
|
87
|
285
|
|
|
|
|
274
|
next; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
0
|
return $self->_error( "Syntax error at line $counter: '$_'" ); |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
15
|
|
|
|
|
110
|
$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
|
38
|
sub mp_getfile { return $CURRENT_FILE; } |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
1; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
__END__ |