line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Monitoring::GLPlugin::Commandline::Extraopts; |
2
|
2
|
|
|
2
|
|
9
|
use strict; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
49
|
|
3
|
2
|
|
|
2
|
|
7
|
use File::Basename; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
138
|
|
4
|
2
|
|
|
2
|
|
8
|
use strict; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
859
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
sub new { |
7
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
8
|
0
|
|
|
|
|
|
my %params = @_; |
9
|
|
|
|
|
|
|
my $self = { |
10
|
|
|
|
|
|
|
file => $params{file}, |
11
|
|
|
|
|
|
|
commandline => $params{commandline}, |
12
|
0
|
|
|
|
|
|
config => {}, |
13
|
|
|
|
|
|
|
section => 'default_no_section', |
14
|
|
|
|
|
|
|
}; |
15
|
0
|
|
|
|
|
|
bless $self, $class; |
16
|
0
|
|
|
|
|
|
$self->prepare_file_and_section(); |
17
|
0
|
|
|
|
|
|
$self->init(); |
18
|
0
|
|
|
|
|
|
return $self; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub prepare_file_and_section { |
22
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
23
|
0
|
0
|
|
|
|
|
if (! defined $self->{file}) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# ./check_stuff --extra-opts |
25
|
0
|
|
|
|
|
|
$self->{section} = basename($0); |
26
|
0
|
|
|
|
|
|
$self->{file} = $self->get_default_file(); |
27
|
|
|
|
|
|
|
} elsif ($self->{file} =~ /^[^@]+$/) { |
28
|
|
|
|
|
|
|
# ./check_stuff --extra-opts=special_opts |
29
|
0
|
|
|
|
|
|
$self->{section} = $self->{file}; |
30
|
0
|
|
|
|
|
|
$self->{file} = $self->get_default_file(); |
31
|
|
|
|
|
|
|
} elsif ($self->{file} =~ /^@(.*)/) { |
32
|
|
|
|
|
|
|
# ./check_stuff --extra-opts=@/etc/myconfig.ini |
33
|
0
|
|
|
|
|
|
$self->{section} = basename($0); |
34
|
0
|
|
|
|
|
|
$self->{file} = $1; |
35
|
|
|
|
|
|
|
} elsif ($self->{file} =~ /^(.*?)@(.*)/) { |
36
|
|
|
|
|
|
|
# ./check_stuff --extra-opts=special_opts@/etc/myconfig.ini |
37
|
0
|
|
|
|
|
|
$self->{section} = $1; |
38
|
0
|
|
|
|
|
|
$self->{file} = $2; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub get_default_file { |
43
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
44
|
0
|
|
|
|
|
|
foreach my $default (qw(/etc/nagios/plugins.ini |
45
|
|
|
|
|
|
|
/usr/local/nagios/etc/plugins.ini |
46
|
|
|
|
|
|
|
/usr/local/etc/nagios/plugins.ini |
47
|
|
|
|
|
|
|
/etc/opt/nagios/plugins.ini |
48
|
|
|
|
|
|
|
/etc/nagios-plugins.ini |
49
|
|
|
|
|
|
|
/usr/local/etc/nagios-plugins.ini |
50
|
|
|
|
|
|
|
/etc/opt/nagios-plugins.ini)) { |
51
|
0
|
0
|
|
|
|
|
if (-f $default) { |
52
|
0
|
|
|
|
|
|
return $default; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
} |
55
|
0
|
|
|
|
|
|
return undef; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub init { |
59
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
60
|
0
|
0
|
|
|
|
|
if (! defined $self->{file}) { |
|
|
0
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
$self->{errors} = sprintf 'no extra-opts file specified and no default file |
62
|
|
|
|
|
|
|
found'; |
63
|
|
|
|
|
|
|
} elsif (! -f $self->{file}) { |
64
|
0
|
|
|
|
|
|
$self->{errors} = sprintf 'could not open %s', $self->{file}; |
65
|
|
|
|
|
|
|
} else { |
66
|
0
|
|
|
|
|
|
my $data = do { local (@ARGV, $/) = $self->{file}; <> }; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
my $in_section = 'default_no_section'; |
68
|
0
|
|
|
|
|
|
foreach my $line (split(/\n/, $data)) { |
69
|
0
|
0
|
|
|
|
|
if ($line =~ /\[(.*)\]/) { |
|
|
0
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
$in_section = $1; |
71
|
|
|
|
|
|
|
} elsif ($line =~ /(.*?)\s*=\s*(.*)/) { |
72
|
0
|
|
|
|
|
|
$self->{config}->{$in_section}->{$1} = $2; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub is_valid { |
79
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
80
|
0
|
|
|
|
|
|
return ! exists $self->{errors}; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
sub overwrite { |
83
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
84
|
0
|
0
|
|
|
|
|
if (scalar(keys %{$self->{config}->{default_no_section}}) > 0) { |
|
0
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
|
foreach (keys %{$self->{config}->{default_no_section}}) { |
|
0
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
|
$self->{commandline}->{$_} = $self->{config}->{default_no_section}->{$_}; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
} |
89
|
0
|
0
|
|
|
|
|
if (exists $self->{config}->{$self->{section}}) { |
90
|
0
|
|
|
|
|
|
foreach (keys %{$self->{config}->{$self->{section}}}) { |
|
0
|
|
|
|
|
|
|
91
|
0
|
|
|
|
|
|
$self->{commandline}->{$_} = $self->{config}->{$self->{section}}->{$_}; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
1; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
__END__ |