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