line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Monitoring::Plugin::Config; |
2
|
|
|
|
|
|
|
|
3
|
6
|
|
|
6
|
|
84
|
use 5.006; |
|
6
|
|
|
|
|
19
|
|
4
|
6
|
|
|
6
|
|
23
|
use strict; |
|
6
|
|
|
|
|
7
|
|
|
6
|
|
|
|
|
97
|
|
5
|
6
|
|
|
6
|
|
41
|
use warnings; |
|
6
|
|
|
|
|
7
|
|
|
6
|
|
|
|
|
155
|
|
6
|
|
|
|
|
|
|
|
7
|
6
|
|
|
6
|
|
25
|
use Carp; |
|
6
|
|
|
|
|
8
|
|
|
6
|
|
|
|
|
287
|
|
8
|
6
|
|
|
6
|
|
26
|
use File::Spec; |
|
6
|
|
|
|
|
8
|
|
|
6
|
|
|
|
|
156
|
|
9
|
6
|
|
|
6
|
|
44
|
use base qw(Config::Tiny); |
|
6
|
|
|
|
|
9
|
|
|
6
|
|
|
|
|
2226
|
|
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
|
21
|
my $class = shift; |
25
|
|
|
|
|
|
|
|
26
|
15
|
50
|
|
|
|
22
|
unless ($_[0]) { |
27
|
|
|
|
|
|
|
SEARCH: { |
28
|
15
|
50
|
33
|
|
|
18
|
if ($ENV{MONITORING_CONFIG_PATH} || $ENV{NAGIOS_CONFIG_PATH}) { |
|
15
|
|
|
|
|
32
|
|
29
|
15
|
|
33
|
|
|
48
|
for (split /:/, ($ENV{MONITORING_CONFIG_PATH} || $ENV{NAGIOS_CONFIG_PATH})) { |
30
|
30
|
|
|
|
|
199
|
my $file = File::Spec->catfile($_, $FILENAME1); |
31
|
30
|
100
|
|
|
|
402
|
unshift(@_, $file), last SEARCH if -f $file; |
32
|
15
|
|
|
|
|
133
|
$file = File::Spec->catfile($_, $FILENAME2); |
33
|
15
|
50
|
|
|
|
97
|
unshift(@_, $file), last SEARCH if -f $file; |
34
|
15
|
|
|
|
|
92
|
$file = File::Spec->catfile($_, $FILENAME3); |
35
|
15
|
50
|
|
|
|
94
|
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
|
|
|
|
41
|
die "Cannot find '$FILENAME1', '$FILENAME2' or '$FILENAME3' in any standard location.\n" unless $_[0]; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
15
|
|
|
|
|
19
|
$CURRENT_FILE = $_[0]; |
55
|
15
|
|
|
|
|
53
|
$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
|
885
|
my $class = ref $_[0] ? ref shift : shift; |
63
|
15
|
|
|
|
|
32
|
my $self = bless {}, $class; |
64
|
15
|
50
|
|
|
|
29
|
return undef unless defined $_[0]; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
# Parse the file |
67
|
15
|
|
|
|
|
17
|
my $ns = '_'; |
68
|
15
|
|
|
|
|
16
|
my $counter = 0; |
69
|
15
|
|
|
|
|
628
|
foreach ( split /(?:\015{1,2}\012|\015|\012)/, shift ) { |
70
|
525
|
|
|
|
|
470
|
$counter++; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# Skip comments and empty lines |
73
|
525
|
100
|
|
|
|
844
|
next if /^\s*(?:\#|\;|$)/; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
# Handle section headers |
76
|
405
|
100
|
|
|
|
709
|
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
|
|
|
437
|
$self->{$ns = $1} ||= {}; |
81
|
120
|
|
|
|
|
144
|
next; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
# Handle properties |
85
|
285
|
50
|
|
|
|
735
|
if ( /^\s*([^=]+?)\s*=\s*(.*?)\s*$/ ) { |
86
|
285
|
|
|
|
|
271
|
push @{$self->{$ns}->{$1}}, $2; |
|
285
|
|
|
|
|
610
|
|
87
|
285
|
|
|
|
|
329
|
next; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
0
|
return $self->_error( "Syntax error at line $counter: '$_'" ); |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
15
|
|
|
|
|
85
|
$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
|
48
|
sub mp_getfile { return $CURRENT_FILE; } |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
1; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
__END__ |