line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Monitoring::GLPlugin::Commandline; |
2
|
5
|
|
|
5
|
|
39
|
use strict; |
|
5
|
|
|
|
|
13
|
|
|
5
|
|
|
|
|
167
|
|
3
|
5
|
|
|
5
|
|
32
|
use IO::File; |
|
5
|
|
|
|
|
13
|
|
|
5
|
|
|
|
|
966
|
|
4
|
5
|
|
|
5
|
|
37
|
use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3, DEPENDENT => 4 }; |
|
5
|
|
|
|
|
12
|
|
|
5
|
|
|
|
|
24602
|
|
5
|
|
|
|
|
|
|
our %ERRORS = ( |
6
|
|
|
|
|
|
|
'OK' => OK, |
7
|
|
|
|
|
|
|
'WARNING' => WARNING, |
8
|
|
|
|
|
|
|
'CRITICAL' => CRITICAL, |
9
|
|
|
|
|
|
|
'UNKNOWN' => UNKNOWN, |
10
|
|
|
|
|
|
|
'DEPENDENT' => DEPENDENT, |
11
|
|
|
|
|
|
|
); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our %STATUS_TEXT = reverse %ERRORS; |
14
|
|
|
|
|
|
|
our $AUTOLOAD; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub new { |
18
|
7
|
|
|
7
|
0
|
32
|
my ($class, %params) = @_; |
19
|
|
|
|
|
|
|
require Monitoring::GLPlugin::Commandline::Getopt |
20
|
7
|
100
|
|
|
|
1435
|
if ! grep /BEGIN/, keys %Monitoring::GLPlugin::Commandline::Getopt::; |
21
|
7
|
|
|
|
|
126
|
my $self = { |
22
|
|
|
|
|
|
|
perfdata => [], |
23
|
|
|
|
|
|
|
messages => { |
24
|
|
|
|
|
|
|
ok => [], |
25
|
|
|
|
|
|
|
warning => [], |
26
|
|
|
|
|
|
|
critical => [], |
27
|
|
|
|
|
|
|
unknown => [], |
28
|
|
|
|
|
|
|
}, |
29
|
|
|
|
|
|
|
args => [], |
30
|
|
|
|
|
|
|
opts => Monitoring::GLPlugin::Commandline::Getopt->new(%params), |
31
|
|
|
|
|
|
|
modes => [], |
32
|
|
|
|
|
|
|
statefilesdir => undef, |
33
|
|
|
|
|
|
|
}; |
34
|
7
|
|
|
|
|
25
|
foreach (qw(shortname usage version url plugin blurb extra |
35
|
|
|
|
|
|
|
license timeout)) { |
36
|
63
|
|
|
|
|
111
|
$self->{$_} = $params{$_}; |
37
|
|
|
|
|
|
|
} |
38
|
7
|
|
|
|
|
19
|
bless $self, $class; |
39
|
7
|
|
33
|
|
|
66
|
$self->{plugin} ||= $Monitoring::GLPlugin::pluginname; |
40
|
7
|
|
|
|
|
24
|
$self->{name} = $self->{plugin}; |
41
|
7
|
|
|
|
|
38
|
$Monitoring::GLPlugin::plugin = $self; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub AUTOLOAD { |
45
|
7
|
|
|
7
|
|
25
|
my ($self, @params) = @_; |
46
|
7
|
50
|
|
|
|
31
|
return if ($AUTOLOAD =~ /DESTROY/); |
47
|
|
|
|
|
|
|
$self->debug("AUTOLOAD %s\n", $AUTOLOAD) |
48
|
7
|
50
|
|
|
|
38
|
if $self->{opts}->verbose >= 2; |
49
|
7
|
50
|
|
|
|
49
|
if ($AUTOLOAD =~ /^.*::(add_arg|override_opt|create_opt)$/) { |
50
|
7
|
|
|
|
|
43
|
$self->{opts}->$1(@params); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub DESTROY { |
55
|
2
|
|
|
2
|
|
39
|
my ($self) = @_; |
56
|
|
|
|
|
|
|
# ohne dieses DESTROY rennt nagios_exit in obiges AUTOLOAD rein |
57
|
|
|
|
|
|
|
# und fliegt aufs Maul, weil {opts} bereits nicht mehr existiert. |
58
|
|
|
|
|
|
|
# Unerklaerliches Verhalten. |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub debug { |
62
|
0
|
|
|
0
|
0
|
0
|
my ($self, $format, @message) = @_; |
63
|
0
|
|
|
|
|
0
|
my $tracefile = "/tmp/".$Monitoring::GLPlugin::pluginname.".trace"; |
64
|
0
|
0
|
|
|
|
0
|
$self->{trace} = -f $tracefile ? 1 : 0; |
65
|
0
|
0
|
0
|
|
|
0
|
if ($self->opts->verbose && $self->opts->verbose > 10) { |
66
|
0
|
|
|
|
|
0
|
printf("%s: ", scalar localtime); |
67
|
0
|
|
|
|
|
0
|
printf($format, @message); |
68
|
0
|
|
|
|
|
0
|
printf "\n"; |
69
|
|
|
|
|
|
|
} |
70
|
0
|
0
|
|
|
|
0
|
if ($self->{trace}) { |
71
|
0
|
|
|
|
|
0
|
my $logfh = IO::File->new(); |
72
|
0
|
|
|
|
|
0
|
$logfh->autoflush(1); |
73
|
0
|
0
|
|
|
|
0
|
if ($logfh->open($tracefile, "a")) { |
74
|
0
|
|
|
|
|
0
|
$logfh->printf("%s: ", scalar localtime); |
75
|
0
|
|
|
|
|
0
|
$logfh->printf($format, @message); |
76
|
0
|
|
|
|
|
0
|
$logfh->printf("\n"); |
77
|
0
|
|
|
|
|
0
|
$logfh->close(); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub opts { |
83
|
459
|
|
|
459
|
0
|
1218
|
my ($self) = @_; |
84
|
459
|
|
|
|
|
2085
|
return $self->{opts}; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub getopts { |
88
|
5
|
|
|
5
|
0
|
18
|
my ($self) = @_; |
89
|
5
|
|
|
|
|
27
|
$self->opts->getopts(); |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub add_message { |
93
|
0
|
|
|
0
|
0
|
|
my ($self, $code, @messages) = @_; |
94
|
0
|
0
|
|
|
|
|
$code = (qw(ok warning critical unknown))[$code] if $code =~ /^\d+$/; |
95
|
0
|
|
|
|
|
|
$code = lc $code; |
96
|
0
|
|
|
|
|
|
push @{$self->{messages}->{$code}}, @messages; |
|
0
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub selected_perfdata { |
100
|
0
|
|
|
0
|
0
|
|
my ($self, $label) = @_; |
101
|
0
|
0
|
0
|
|
|
|
if ($self->opts->can("selectedperfdata") && $self->opts->selectedperfdata) { |
102
|
0
|
|
|
|
|
|
my $pattern = $self->opts->selectedperfdata; |
103
|
0
|
0
|
|
|
|
|
return ($label =~ /$pattern/i) ? 1 : 0; |
104
|
|
|
|
|
|
|
} else { |
105
|
0
|
|
|
|
|
|
return 1; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
sub add_perfdata { |
110
|
0
|
|
|
0
|
0
|
|
my ($self, %args) = @_; |
111
|
|
|
|
|
|
|
#printf "add_perfdata %s\n", Data::Dumper::Dumper(\%args); |
112
|
|
|
|
|
|
|
#printf "add_perfdata %s\n", Data::Dumper::Dumper($self->{thresholds}); |
113
|
|
|
|
|
|
|
# |
114
|
|
|
|
|
|
|
# wenn warning, critical, dann wird von oben ein expliziter wert mitgegeben |
115
|
|
|
|
|
|
|
# wenn thresholds |
116
|
|
|
|
|
|
|
# wenn label in |
117
|
|
|
|
|
|
|
# warningx $self->{thresholds}->{$label}->{warning} existiert |
118
|
|
|
|
|
|
|
# dann nimm $self->{thresholds}->{$label}->{warning} |
119
|
|
|
|
|
|
|
# ansonsten thresholds->default->warning |
120
|
|
|
|
|
|
|
# |
121
|
|
|
|
|
|
|
|
122
|
0
|
|
|
|
|
|
my $label = $args{label}; |
123
|
0
|
|
|
|
|
|
my $value = $args{value}; |
124
|
0
|
|
0
|
|
|
|
my $uom = $args{uom} || ""; |
125
|
0
|
|
|
|
|
|
my $format = '%d'; |
126
|
|
|
|
|
|
|
|
127
|
0
|
0
|
0
|
|
|
|
if ($self->opts->can("morphperfdata") && $self->opts->morphperfdata) { |
128
|
|
|
|
|
|
|
# 'Intel [R] Interface (\d+) usage'='nic$1' |
129
|
0
|
|
|
|
|
|
foreach my $key (keys %{$self->opts->morphperfdata}) { |
|
0
|
|
|
|
|
|
|
130
|
0
|
0
|
|
|
|
|
if ($label =~ /$key/) { |
131
|
0
|
|
|
|
|
|
my $replacement = '"'.$self->opts->morphperfdata->{$key}.'"'; |
132
|
0
|
|
|
|
|
|
my $oldlabel = $label; |
133
|
0
|
|
|
|
|
|
$label =~ s/$key/$replacement/ee; |
|
0
|
|
|
|
|
|
|
134
|
0
|
0
|
|
|
|
|
if (exists $self->{thresholds}->{$oldlabel}) { |
135
|
0
|
|
|
|
|
|
%{$self->{thresholds}->{$label}} = %{$self->{thresholds}->{$oldlabel}}; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
} |
140
|
0
|
0
|
|
|
|
|
if ($value =~ /\./) { |
141
|
0
|
0
|
|
|
|
|
if (defined $args{places}) { |
142
|
0
|
|
|
|
|
|
$value = sprintf '%.'.$args{places}.'f', $value; |
143
|
|
|
|
|
|
|
} else { |
144
|
0
|
|
|
|
|
|
$value = sprintf "%.2f", $value; |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
} else { |
147
|
0
|
|
|
|
|
|
$value = sprintf "%d", $value; |
148
|
|
|
|
|
|
|
} |
149
|
0
|
|
|
|
|
|
my $warn = ""; |
150
|
0
|
|
|
|
|
|
my $crit = ""; |
151
|
0
|
0
|
|
|
|
|
my $min = defined $args{min} ? $args{min} : ""; |
152
|
0
|
0
|
|
|
|
|
my $max = defined $args{max} ? $args{max} : ""; |
153
|
0
|
0
|
0
|
|
|
|
if ($args{thresholds} || (! exists $args{warning} && ! exists $args{critical})) { |
|
|
|
0
|
|
|
|
|
154
|
0
|
0
|
|
|
|
|
if (exists $self->{thresholds}->{$label}->{warning}) { |
|
|
0
|
|
|
|
|
|
155
|
0
|
|
|
|
|
|
$warn = $self->{thresholds}->{$label}->{warning}; |
156
|
|
|
|
|
|
|
} elsif (exists $self->{thresholds}->{default}->{warning}) { |
157
|
0
|
|
|
|
|
|
$warn = $self->{thresholds}->{default}->{warning}; |
158
|
|
|
|
|
|
|
} |
159
|
0
|
0
|
|
|
|
|
if (exists $self->{thresholds}->{$label}->{critical}) { |
|
|
0
|
|
|
|
|
|
160
|
0
|
|
|
|
|
|
$crit = $self->{thresholds}->{$label}->{critical}; |
161
|
|
|
|
|
|
|
} elsif (exists $self->{thresholds}->{default}->{critical}) { |
162
|
0
|
|
|
|
|
|
$crit = $self->{thresholds}->{default}->{critical}; |
163
|
|
|
|
|
|
|
} |
164
|
|
|
|
|
|
|
} else { |
165
|
0
|
0
|
|
|
|
|
if ($args{warning}) { |
166
|
0
|
|
|
|
|
|
$warn = $args{warning}; |
167
|
|
|
|
|
|
|
} |
168
|
0
|
0
|
|
|
|
|
if ($args{critical}) { |
169
|
0
|
|
|
|
|
|
$crit = $args{critical}; |
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
} |
172
|
0
|
0
|
|
|
|
|
if ($uom eq "%") { |
173
|
0
|
|
|
|
|
|
$min = 0; |
174
|
0
|
|
|
|
|
|
$max = 100; |
175
|
|
|
|
|
|
|
} |
176
|
0
|
0
|
|
|
|
|
if (defined $args{places}) { |
177
|
|
|
|
|
|
|
# cut off excessive decimals which may be the result of a division |
178
|
|
|
|
|
|
|
# length = places*2, no trailing zeroes |
179
|
0
|
0
|
|
|
|
|
if ($warn ne "") { |
180
|
|
|
|
|
|
|
$warn = join("", map { |
181
|
0
|
|
|
|
|
|
s/\.0+$//; $_ |
|
0
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
} map { |
183
|
0
|
|
|
|
|
|
s/(\.[1-9]+)0+$/$1/; $_ |
|
0
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
} map { |
185
|
0
|
0
|
|
|
|
|
/[\+\-\d\.]+/ ? sprintf '%.'.2*$args{places}.'f', $_ : $_; |
|
0
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
} split(/([\+\-\d\.]+)/, $warn)); |
187
|
|
|
|
|
|
|
} |
188
|
0
|
0
|
|
|
|
|
if ($crit ne "") { |
189
|
|
|
|
|
|
|
$crit = join("", map { |
190
|
0
|
|
|
|
|
|
s/\.0+$//; $_ |
|
0
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
} map { |
192
|
0
|
|
|
|
|
|
s/(\.[1-9]+)0+$/$1/; $_ |
|
0
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
} map { |
194
|
0
|
0
|
|
|
|
|
/[\+\-\d\.]+/ ? sprintf '%.'.2*$args{places}.'f', $_ : $_; |
|
0
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
} split(/([\+\-\d\.]+)/, $crit)); |
196
|
|
|
|
|
|
|
} |
197
|
0
|
0
|
|
|
|
|
if ($min ne "") { |
198
|
|
|
|
|
|
|
$min = join("", map { |
199
|
0
|
|
|
|
|
|
s/\.0+$//; $_ |
|
0
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
} map { |
201
|
0
|
|
|
|
|
|
s/(\.[1-9]+)0+$/$1/; $_ |
|
0
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
} map { |
203
|
0
|
0
|
|
|
|
|
/[\+\-\d\.]+/ ? sprintf '%.'.2*$args{places}.'f', $_ : $_; |
|
0
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
} split(/([\+\-\d\.]+)/, $min)); |
205
|
|
|
|
|
|
|
} |
206
|
0
|
0
|
|
|
|
|
if ($max ne "") { |
207
|
|
|
|
|
|
|
$max = join("", map { |
208
|
0
|
|
|
|
|
|
s/\.0+$//; $_ |
|
0
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
} map { |
210
|
0
|
|
|
|
|
|
s/(\.[1-9]+)0+$/$1/; $_ |
|
0
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
} map { |
212
|
0
|
0
|
|
|
|
|
/[\+\-\d\.]+/ ? sprintf '%.'.2*$args{places}.'f', $_ : $_; |
|
0
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
} split(/([\+\-\d\.]+)/, $max)); |
214
|
|
|
|
|
|
|
} |
215
|
|
|
|
|
|
|
} |
216
|
0
|
0
|
|
|
|
|
push @{$self->{perfdata}}, sprintf("'%s'=%s%s;%s;%s;%s;%s", |
|
0
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
$label, $value, $uom, $warn, $crit, $min, $max) |
218
|
|
|
|
|
|
|
if $self->selected_perfdata($label); |
219
|
|
|
|
|
|
|
} |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
sub add_pandora { |
222
|
0
|
|
|
0
|
0
|
|
my ($self, %args) = @_; |
223
|
0
|
|
|
|
|
|
my $label = $args{label}; |
224
|
0
|
|
|
|
|
|
my $value = $args{value}; |
225
|
|
|
|
|
|
|
|
226
|
0
|
0
|
|
|
|
|
if ($args{help}) { |
227
|
0
|
|
|
|
|
|
push @{$self->{pandora}}, sprintf("# HELP %s %s", $label, $args{help}); |
|
0
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
} |
229
|
0
|
0
|
|
|
|
|
if ($args{type}) { |
230
|
0
|
|
|
|
|
|
push @{$self->{pandora}}, sprintf("# TYPE %s %s", $label, $args{type}); |
|
0
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
} |
232
|
0
|
0
|
|
|
|
|
if ($args{labels}) { |
233
|
0
|
|
|
|
|
|
push @{$self->{pandora}}, sprintf("%s{%s} %s", $label, |
234
|
|
|
|
|
|
|
join(",", map { |
235
|
0
|
|
|
|
|
|
sprintf '%s="%s"', $_, $args{labels}->{$_}; |
236
|
0
|
|
|
|
|
|
} keys %{$args{labels}}), |
|
0
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
$value); |
238
|
|
|
|
|
|
|
} else { |
239
|
0
|
|
|
|
|
|
push @{$self->{pandora}}, sprintf("%s %s", $label, $value); |
|
0
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
} |
241
|
|
|
|
|
|
|
} |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
sub add_html { |
244
|
0
|
|
|
0
|
0
|
|
my ($self, $line) = @_; |
245
|
0
|
|
|
|
|
|
push @{$self->{html}}, $line; |
|
0
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
} |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
sub suppress_messages { |
249
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
250
|
0
|
|
|
|
|
|
$self->{suppress_messages} = 1; |
251
|
|
|
|
|
|
|
} |
252
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
sub clear_messages { |
254
|
0
|
|
|
0
|
0
|
|
my ($self, $code) = @_; |
255
|
0
|
0
|
|
|
|
|
$code = (qw(ok warning critical unknown))[$code] if $code =~ /^\d+$/; |
256
|
0
|
|
|
|
|
|
$code = lc $code; |
257
|
0
|
|
|
|
|
|
$self->{messages}->{$code} = []; |
258
|
|
|
|
|
|
|
} |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
sub reduce_messages_short { |
261
|
0
|
|
|
0
|
0
|
|
my ($self, $message) = @_; |
262
|
0
|
|
0
|
|
|
|
$message ||= "no problems"; |
263
|
0
|
0
|
0
|
|
|
|
if ($self->opts->report && $self->opts->report eq "short") { |
264
|
0
|
|
|
|
|
|
$self->clear_messages(OK); |
265
|
0
|
0
|
|
|
|
|
$self->add_message(OK, $message) if ! $self->check_messages(); |
266
|
|
|
|
|
|
|
} |
267
|
|
|
|
|
|
|
} |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
sub reduce_messages { |
270
|
0
|
|
|
0
|
0
|
|
my ($self, $message) = @_; |
271
|
0
|
|
0
|
|
|
|
$message ||= "no problems"; |
272
|
0
|
|
|
|
|
|
$self->clear_messages(OK); |
273
|
0
|
0
|
|
|
|
|
$self->add_message(OK, $message) if ! $self->check_messages(); |
274
|
|
|
|
|
|
|
} |
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
sub check_messages { |
277
|
0
|
|
|
0
|
0
|
|
my ($self, %args) = @_; |
278
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
# Add object messages to any passed in as args |
280
|
0
|
|
|
|
|
|
for my $code (qw(critical warning unknown ok)) { |
281
|
0
|
|
0
|
|
|
|
my $messages = $self->{messages}->{$code} || []; |
282
|
0
|
0
|
|
|
|
|
if ($args{$code}) { |
283
|
0
|
0
|
|
|
|
|
unless (ref $args{$code} eq 'ARRAY') { |
284
|
0
|
0
|
|
|
|
|
if ($code eq 'ok') { |
285
|
0
|
|
|
|
|
|
$args{$code} = [ $args{$code} ]; |
286
|
|
|
|
|
|
|
} |
287
|
|
|
|
|
|
|
} |
288
|
0
|
|
|
|
|
|
push @{$args{$code}}, @$messages; |
|
0
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
} else { |
290
|
0
|
|
|
|
|
|
$args{$code} = $messages; |
291
|
|
|
|
|
|
|
} |
292
|
|
|
|
|
|
|
} |
293
|
0
|
|
|
|
|
|
my %arg = %args; |
294
|
0
|
0
|
|
|
|
|
$arg{join} = ' ' unless defined $arg{join}; |
295
|
|
|
|
|
|
|
|
296
|
|
|
|
|
|
|
# Decide $code |
297
|
0
|
|
|
|
|
|
my $code = OK; |
298
|
0
|
0
|
0
|
|
|
|
$code ||= CRITICAL if @{$arg{critical}}; |
|
0
|
|
|
|
|
|
|
299
|
0
|
0
|
0
|
|
|
|
$code ||= WARNING if @{$arg{warning}}; |
|
0
|
|
|
|
|
|
|
300
|
0
|
0
|
0
|
|
|
|
$code ||= UNKNOWN if @{$arg{unknown}}; |
|
0
|
|
|
|
|
|
|
301
|
0
|
0
|
|
|
|
|
return $code unless wantarray; |
302
|
|
|
|
|
|
|
|
303
|
|
|
|
|
|
|
# Compose message |
304
|
0
|
|
|
|
|
|
my $message = ''; |
305
|
0
|
0
|
|
|
|
|
if ($arg{join_all}) { |
306
|
|
|
|
|
|
|
$message = join( $arg{join_all}, |
307
|
0
|
0
|
|
|
|
|
map { @$_ ? join( $arg{'join'}, @$_) : () } |
308
|
|
|
|
|
|
|
$arg{critical}, |
309
|
|
|
|
|
|
|
$arg{warning}, |
310
|
|
|
|
|
|
|
$arg{unknown}, |
311
|
0
|
0
|
|
|
|
|
$arg{ok} ? (ref $arg{ok} ? $arg{ok} : [ $arg{ok} ]) : [] |
|
|
0
|
|
|
|
|
|
312
|
|
|
|
|
|
|
); |
313
|
|
|
|
|
|
|
} |
314
|
|
|
|
|
|
|
|
315
|
|
|
|
|
|
|
else { |
316
|
0
|
0
|
0
|
|
|
|
$message ||= join( $arg{'join'}, @{$arg{critical}} ) |
|
0
|
|
|
|
|
|
|
317
|
|
|
|
|
|
|
if $code == CRITICAL; |
318
|
0
|
0
|
0
|
|
|
|
$message ||= join( $arg{'join'}, @{$arg{warning}} ) |
|
0
|
|
|
|
|
|
|
319
|
|
|
|
|
|
|
if $code == WARNING; |
320
|
0
|
0
|
0
|
|
|
|
$message ||= join( $arg{'join'}, @{$arg{unknown}} ) |
|
0
|
|
|
|
|
|
|
321
|
|
|
|
|
|
|
if $code == UNKNOWN; |
322
|
0
|
|
|
|
|
|
$message ||= ref $arg{ok} ? join( $arg{'join'}, @{$arg{ok}} ) : $arg{ok} |
323
|
0
|
0
|
0
|
|
|
|
if $arg{ok}; |
|
|
0
|
|
|
|
|
|
324
|
|
|
|
|
|
|
} |
325
|
|
|
|
|
|
|
|
326
|
0
|
|
|
|
|
|
return ($code, $message); |
327
|
|
|
|
|
|
|
} |
328
|
|
|
|
|
|
|
|
329
|
|
|
|
|
|
|
sub status_code { |
330
|
0
|
|
|
0
|
0
|
|
my ($self, $code) = @_; |
331
|
0
|
0
|
|
|
|
|
$code = (qw(ok warning critical unknown))[$code] if $code =~ /^\d+$/; |
332
|
0
|
|
|
|
|
|
$code = uc $code; |
333
|
0
|
0
|
0
|
|
|
|
$code = $ERRORS{$code} if defined $code && exists $ERRORS{$code}; |
334
|
0
|
0
|
0
|
|
|
|
$code = UNKNOWN unless defined $code && exists $STATUS_TEXT{$code}; |
335
|
0
|
|
|
|
|
|
return "$STATUS_TEXT{$code}"; |
336
|
|
|
|
|
|
|
} |
337
|
|
|
|
|
|
|
|
338
|
|
|
|
|
|
|
sub perfdata_string { |
339
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
340
|
0
|
0
|
|
|
|
|
if (scalar (@{$self->{perfdata}})) { |
|
0
|
|
|
|
|
|
|
341
|
0
|
|
|
|
|
|
return join(" ", @{$self->{perfdata}}); |
|
0
|
|
|
|
|
|
|
342
|
|
|
|
|
|
|
} else { |
343
|
0
|
|
|
|
|
|
return ""; |
344
|
|
|
|
|
|
|
} |
345
|
|
|
|
|
|
|
} |
346
|
|
|
|
|
|
|
|
347
|
|
|
|
|
|
|
sub metrics_string { |
348
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
349
|
0
|
0
|
|
|
|
|
if (scalar (@{$self->{metrics}})) { |
|
0
|
|
|
|
|
|
|
350
|
0
|
|
|
|
|
|
return join("\n", @{$self->{metrics}}); |
|
0
|
|
|
|
|
|
|
351
|
|
|
|
|
|
|
} else { |
352
|
0
|
|
|
|
|
|
return ""; |
353
|
|
|
|
|
|
|
} |
354
|
|
|
|
|
|
|
} |
355
|
|
|
|
|
|
|
|
356
|
|
|
|
|
|
|
sub html_string { |
357
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
358
|
0
|
0
|
|
|
|
|
if (scalar (@{$self->{html}})) { |
|
0
|
|
|
|
|
|
|
359
|
0
|
|
|
|
|
|
return join(" ", @{$self->{html}}); |
|
0
|
|
|
|
|
|
|
360
|
|
|
|
|
|
|
} else { |
361
|
0
|
|
|
|
|
|
return ""; |
362
|
|
|
|
|
|
|
} |
363
|
|
|
|
|
|
|
} |
364
|
|
|
|
|
|
|
|
365
|
|
|
|
|
|
|
sub nagios_exit { |
366
|
0
|
|
|
0
|
0
|
|
my ($self, $code, $message, $arg) = @_; |
367
|
0
|
0
|
0
|
|
|
|
$code = $ERRORS{$code} if defined $code && exists $ERRORS{$code}; |
368
|
0
|
0
|
0
|
|
|
|
$code = UNKNOWN unless defined $code && exists $STATUS_TEXT{$code}; |
369
|
0
|
0
|
|
|
|
|
$message = '' unless defined $message; |
370
|
0
|
0
|
0
|
|
|
|
if (ref $message && ref $message eq 'ARRAY') { |
371
|
0
|
|
|
|
|
|
$message = join(' ', map { chomp; $_ } @$message); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
372
|
|
|
|
|
|
|
} else { |
373
|
0
|
|
|
|
|
|
chomp $message; |
374
|
|
|
|
|
|
|
} |
375
|
0
|
0
|
|
|
|
|
if ($self->opts->negate) { |
376
|
0
|
|
|
|
|
|
my $original_code = $code; |
377
|
0
|
|
|
|
|
|
foreach my $from (keys %{$self->opts->negate}) { |
|
0
|
|
|
|
|
|
|
378
|
0
|
0
|
0
|
|
|
|
if ((uc $from) =~ /^(OK|WARNING|CRITICAL|UNKNOWN)$/ && |
379
|
|
|
|
|
|
|
(uc $self->opts->negate->{$from}) =~ /^(OK|WARNING|CRITICAL|UNKNOWN)$/) { |
380
|
0
|
0
|
|
|
|
|
if ($original_code == $ERRORS{uc $from}) { |
381
|
0
|
|
|
|
|
|
$code = $ERRORS{uc $self->opts->negate->{$from}}; |
382
|
|
|
|
|
|
|
} |
383
|
|
|
|
|
|
|
} |
384
|
|
|
|
|
|
|
} |
385
|
|
|
|
|
|
|
} |
386
|
0
|
|
|
|
|
|
my $output = "$STATUS_TEXT{$code}"; |
387
|
0
|
0
|
0
|
|
|
|
$output .= " - $message" if defined $message && $message ne ''; |
388
|
0
|
0
|
0
|
|
|
|
if ($self->opts->can("morphmessage") && $self->opts->morphmessage) { |
389
|
|
|
|
|
|
|
# 'Intel [R] Interface (\d+) usage'='nic$1' |
390
|
|
|
|
|
|
|
# '^OK.*'="alles klar" '^CRITICAL.*'="alles hi" |
391
|
0
|
|
|
|
|
|
foreach my $key (keys %{$self->opts->morphmessage}) { |
|
0
|
|
|
|
|
|
|
392
|
0
|
0
|
|
|
|
|
if ($output =~ /$key/) { |
393
|
0
|
|
|
|
|
|
my $replacement = '"'.$self->opts->morphmessage->{$key}.'"'; |
394
|
0
|
|
|
|
|
|
$output =~ s/$key/$replacement/ee; |
|
0
|
|
|
|
|
|
|
395
|
|
|
|
|
|
|
} |
396
|
|
|
|
|
|
|
} |
397
|
|
|
|
|
|
|
} |
398
|
0
|
0
|
|
|
|
|
if ($self->opts->negate) { |
399
|
|
|
|
|
|
|
# negate again: --negate "UNKNOWN - no peers"=ok |
400
|
0
|
|
|
|
|
|
my $original_code = $code; |
401
|
0
|
|
|
|
|
|
foreach my $from (keys %{$self->opts->negate}) { |
|
0
|
|
|
|
|
|
|
402
|
0
|
0
|
|
|
|
|
if ((uc $self->opts->negate->{$from}) =~ /^(OK|WARNING|CRITICAL|UNKNOWN)$/) { |
403
|
0
|
0
|
|
|
|
|
if ($output =~ /$from/) { |
404
|
0
|
|
|
|
|
|
$code = $ERRORS{uc $self->opts->negate->{$from}}; |
405
|
0
|
|
|
|
|
|
$output =~ s/^.*? -/$STATUS_TEXT{$code} -/; |
406
|
|
|
|
|
|
|
} |
407
|
|
|
|
|
|
|
} |
408
|
|
|
|
|
|
|
} |
409
|
|
|
|
|
|
|
} |
410
|
0
|
0
|
|
|
|
|
$output =~ s/\|/!/g if $output; |
411
|
0
|
0
|
|
|
|
|
if (scalar (@{$self->{perfdata}})) { |
|
0
|
|
|
|
|
|
|
412
|
0
|
|
|
|
|
|
$output .= " | ".$self->perfdata_string(); |
413
|
|
|
|
|
|
|
} |
414
|
0
|
|
|
|
|
|
$output .= "\n"; |
415
|
0
|
0
|
0
|
|
|
|
if ($self->opts->can("isvalidtime") && ! $self->opts->isvalidtime) { |
416
|
0
|
|
|
|
|
|
$code = OK; |
417
|
0
|
|
|
|
|
|
$output = "OK - outside valid timerange. check results are not relevant now. original message was: ". |
418
|
|
|
|
|
|
|
$output; |
419
|
|
|
|
|
|
|
} |
420
|
0
|
0
|
|
|
|
|
if (! exists $self->{suppress_messages}) { |
421
|
0
|
|
|
|
|
|
print $output; |
422
|
|
|
|
|
|
|
} |
423
|
0
|
|
|
|
|
|
exit $code; |
424
|
|
|
|
|
|
|
} |
425
|
|
|
|
|
|
|
|
426
|
|
|
|
|
|
|
sub set_thresholds { |
427
|
0
|
|
|
0
|
0
|
|
my ($self, %params) = @_; |
428
|
0
|
0
|
|
|
|
|
if (exists $params{metric}) { |
429
|
0
|
|
|
|
|
|
my $metric = $params{metric}; |
430
|
|
|
|
|
|
|
# erst die hartcodierten defaultschwellwerte |
431
|
0
|
|
|
|
|
|
$self->{thresholds}->{$metric}->{warning} = $params{warning}; |
432
|
0
|
|
|
|
|
|
$self->{thresholds}->{$metric}->{critical} = $params{critical}; |
433
|
|
|
|
|
|
|
# dann die defaultschwellwerte von der kommandozeile |
434
|
0
|
0
|
|
|
|
|
if (defined $self->opts->warning) { |
435
|
0
|
|
|
|
|
|
$self->{thresholds}->{$metric}->{warning} = $self->opts->warning; |
436
|
|
|
|
|
|
|
} |
437
|
0
|
0
|
|
|
|
|
if (defined $self->opts->critical) { |
438
|
0
|
|
|
|
|
|
$self->{thresholds}->{$metric}->{critical} = $self->opts->critical; |
439
|
|
|
|
|
|
|
} |
440
|
|
|
|
|
|
|
# dann die ganz spezifischen schwellwerte von der kommandozeile |
441
|
0
|
0
|
|
|
|
|
if ($self->opts->warningx) { # muss nicht auf defined geprueft werden, weils ein hash ist |
442
|
|
|
|
|
|
|
# Erst schauen, ob einer * beinhaltet. Von denen wird vom Laengsten |
443
|
|
|
|
|
|
|
# bis zum Kuerzesten probiert, ob die matchen. Der laengste Match |
444
|
|
|
|
|
|
|
# gewinnt. |
445
|
0
|
|
|
|
|
|
my @keys = keys %{$self->opts->warningx}; |
|
0
|
|
|
|
|
|
|
446
|
0
|
|
|
|
|
|
my @stringkeys = (); |
447
|
0
|
|
|
|
|
|
my @regexkeys = (); |
448
|
0
|
|
|
|
|
|
foreach my $key (sort { length($b) > length($a) } @keys) { |
|
0
|
|
|
|
|
|
|
449
|
0
|
0
|
|
|
|
|
if ($key =~ /\*/) { |
450
|
0
|
|
|
|
|
|
push(@regexkeys, $key); |
451
|
|
|
|
|
|
|
} else { |
452
|
0
|
|
|
|
|
|
push(@stringkeys, $key); |
453
|
|
|
|
|
|
|
} |
454
|
|
|
|
|
|
|
} |
455
|
0
|
|
|
|
|
|
foreach my $key (@regexkeys) { |
456
|
0
|
0
|
|
|
|
|
next if $metric !~ /$key/; |
457
|
0
|
|
|
|
|
|
$self->{thresholds}->{$metric}->{warning} = $self->opts->warningx->{$key}; |
458
|
0
|
|
|
|
|
|
last; |
459
|
|
|
|
|
|
|
} |
460
|
|
|
|
|
|
|
# Anschliessend nochmal schauen, ob es einen nicht-Regex-Volltreffer gibt |
461
|
0
|
|
|
|
|
|
foreach my $key (@stringkeys) { |
462
|
0
|
0
|
|
|
|
|
next if $key ne $metric; |
463
|
0
|
|
|
|
|
|
$self->{thresholds}->{$metric}->{warning} = $self->opts->warningx->{$key}; |
464
|
0
|
|
|
|
|
|
last; |
465
|
|
|
|
|
|
|
} |
466
|
|
|
|
|
|
|
} |
467
|
0
|
0
|
|
|
|
|
if ($self->opts->criticalx) { |
468
|
0
|
|
|
|
|
|
my @keys = keys %{$self->opts->criticalx}; |
|
0
|
|
|
|
|
|
|
469
|
0
|
|
|
|
|
|
my @stringkeys = (); |
470
|
0
|
|
|
|
|
|
my @regexkeys = (); |
471
|
0
|
|
|
|
|
|
foreach my $key (sort { length($b) > length($a) } @keys) { |
|
0
|
|
|
|
|
|
|
472
|
0
|
0
|
|
|
|
|
if ($key =~ /\*/) { |
473
|
0
|
|
|
|
|
|
push(@regexkeys, $key); |
474
|
|
|
|
|
|
|
} else { |
475
|
0
|
|
|
|
|
|
push(@stringkeys, $key); |
476
|
|
|
|
|
|
|
} |
477
|
|
|
|
|
|
|
} |
478
|
0
|
|
|
|
|
|
foreach my $key (@regexkeys) { |
479
|
0
|
0
|
|
|
|
|
next if $metric !~ /$key/; |
480
|
0
|
|
|
|
|
|
$self->{thresholds}->{$metric}->{critical} = $self->opts->criticalx->{$key}; |
481
|
0
|
|
|
|
|
|
last; |
482
|
|
|
|
|
|
|
} |
483
|
|
|
|
|
|
|
# Anschliessend nochmal schauen, ob es einen nicht-Regex-Volltreffer gibt |
484
|
0
|
|
|
|
|
|
foreach my $key (@stringkeys) { |
485
|
0
|
0
|
|
|
|
|
next if $key ne $metric; |
486
|
0
|
|
|
|
|
|
$self->{thresholds}->{$metric}->{critical} = $self->opts->criticalx->{$key}; |
487
|
0
|
|
|
|
|
|
last; |
488
|
|
|
|
|
|
|
} |
489
|
|
|
|
|
|
|
} |
490
|
|
|
|
|
|
|
} else { |
491
|
|
|
|
|
|
|
$self->{thresholds}->{default}->{warning} = |
492
|
0
|
0
|
|
|
|
|
defined $self->opts->warning ? $self->opts->warning : defined $params{warning} ? $params{warning} : 0; |
|
|
0
|
|
|
|
|
|
493
|
|
|
|
|
|
|
$self->{thresholds}->{default}->{critical} = |
494
|
0
|
0
|
|
|
|
|
defined $self->opts->critical ? $self->opts->critical : defined $params{critical} ? $params{critical} : 0; |
|
|
0
|
|
|
|
|
|
495
|
|
|
|
|
|
|
} |
496
|
|
|
|
|
|
|
} |
497
|
|
|
|
|
|
|
|
498
|
|
|
|
|
|
|
sub force_thresholds { |
499
|
0
|
|
|
0
|
0
|
|
my ($self, %params) = @_; |
500
|
0
|
0
|
|
|
|
|
if (exists $params{metric}) { |
501
|
0
|
|
|
|
|
|
my $metric = $params{metric}; |
502
|
0
|
|
0
|
|
|
|
$self->{thresholds}->{$metric}->{warning} = $params{warning} || 0; |
503
|
0
|
|
0
|
|
|
|
$self->{thresholds}->{$metric}->{critical} = $params{critical} || 0; |
504
|
|
|
|
|
|
|
} else { |
505
|
0
|
|
0
|
|
|
|
$self->{thresholds}->{default}->{warning} = $params{warning} || 0; |
506
|
0
|
|
0
|
|
|
|
$self->{thresholds}->{default}->{critical} = $params{critical} || 0; |
507
|
|
|
|
|
|
|
} |
508
|
|
|
|
|
|
|
} |
509
|
|
|
|
|
|
|
|
510
|
|
|
|
|
|
|
sub get_thresholds { |
511
|
0
|
|
|
0
|
0
|
|
my ($self, @params) = @_; |
512
|
0
|
0
|
|
|
|
|
if (scalar(@params) > 1) { |
513
|
0
|
|
|
|
|
|
my %params = @params; |
514
|
0
|
|
|
|
|
|
my $metric = $params{metric}; |
515
|
|
|
|
|
|
|
return ($self->{thresholds}->{$metric}->{warning}, |
516
|
0
|
|
|
|
|
|
$self->{thresholds}->{$metric}->{critical}); |
517
|
|
|
|
|
|
|
} else { |
518
|
|
|
|
|
|
|
return ($self->{thresholds}->{default}->{warning}, |
519
|
0
|
|
|
|
|
|
$self->{thresholds}->{default}->{critical}); |
520
|
|
|
|
|
|
|
} |
521
|
|
|
|
|
|
|
} |
522
|
|
|
|
|
|
|
|
523
|
|
|
|
|
|
|
sub check_thresholds { |
524
|
0
|
|
|
0
|
0
|
|
my ($self, @params) = @_; |
525
|
0
|
|
|
|
|
|
my $level = $ERRORS{OK}; |
526
|
0
|
|
|
|
|
|
my $warningrange; |
527
|
|
|
|
|
|
|
my $criticalrange; |
528
|
0
|
|
|
|
|
|
my $value; |
529
|
0
|
0
|
|
|
|
|
if (scalar(@params) > 1) { |
530
|
0
|
|
|
|
|
|
my %params = @params; |
531
|
0
|
|
|
|
|
|
$value = $params{value}; |
532
|
0
|
|
|
|
|
|
my $metric = $params{metric}; |
533
|
0
|
0
|
|
|
|
|
if ($metric ne 'default') { |
534
|
|
|
|
|
|
|
$warningrange = exists $self->{thresholds}->{$metric}->{warning} ? |
535
|
|
|
|
|
|
|
$self->{thresholds}->{$metric}->{warning} : |
536
|
0
|
0
|
|
|
|
|
$self->{thresholds}->{default}->{warning}; |
537
|
|
|
|
|
|
|
$criticalrange = exists $self->{thresholds}->{$metric}->{critical} ? |
538
|
|
|
|
|
|
|
$self->{thresholds}->{$metric}->{critical} : |
539
|
0
|
0
|
|
|
|
|
$self->{thresholds}->{default}->{critical}; |
540
|
|
|
|
|
|
|
} else { |
541
|
|
|
|
|
|
|
$warningrange = (defined $params{warning}) ? |
542
|
0
|
0
|
|
|
|
|
$params{warning} : $self->{thresholds}->{default}->{warning}; |
543
|
|
|
|
|
|
|
$criticalrange = (defined $params{critical}) ? |
544
|
0
|
0
|
|
|
|
|
$params{critical} : $self->{thresholds}->{default}->{critical}; |
545
|
|
|
|
|
|
|
} |
546
|
|
|
|
|
|
|
} else { |
547
|
0
|
|
|
|
|
|
$value = $params[0]; |
548
|
0
|
|
|
|
|
|
$warningrange = $self->{thresholds}->{default}->{warning}; |
549
|
0
|
|
|
|
|
|
$criticalrange = $self->{thresholds}->{default}->{critical}; |
550
|
|
|
|
|
|
|
} |
551
|
0
|
0
|
|
|
|
|
if (! defined $warningrange) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
552
|
|
|
|
|
|
|
# there was no set_thresholds for defaults, no --warning, no --warningx |
553
|
|
|
|
|
|
|
} elsif ($warningrange =~ /^([-+]?[0-9]*\.?[0-9]+)$/) { |
554
|
|
|
|
|
|
|
# warning = 10, warn if > 10 or < 0 |
555
|
|
|
|
|
|
|
$level = $ERRORS{WARNING} |
556
|
0
|
0
|
0
|
|
|
|
if ($value > $1 || $value < 0); |
557
|
|
|
|
|
|
|
} elsif ($warningrange =~ /^([-+]?[0-9]*\.?[0-9]+):$/) { |
558
|
|
|
|
|
|
|
# warning = 10:, warn if < 10 |
559
|
|
|
|
|
|
|
$level = $ERRORS{WARNING} |
560
|
0
|
0
|
|
|
|
|
if ($value < $1); |
561
|
|
|
|
|
|
|
} elsif ($warningrange =~ /^~:([-+]?[0-9]*\.?[0-9]+)$/) { |
562
|
|
|
|
|
|
|
# warning = ~:10, warn if > 10 |
563
|
|
|
|
|
|
|
$level = $ERRORS{WARNING} |
564
|
0
|
0
|
|
|
|
|
if ($value > $1); |
565
|
|
|
|
|
|
|
} elsif ($warningrange =~ /^([-+]?[0-9]*\.?[0-9]+):([-+]?[0-9]*\.?[0-9]+)$/) { |
566
|
|
|
|
|
|
|
# warning = 10:20, warn if < 10 or > 20 |
567
|
|
|
|
|
|
|
$level = $ERRORS{WARNING} |
568
|
0
|
0
|
0
|
|
|
|
if ($value < $1 || $value > $2); |
569
|
|
|
|
|
|
|
} elsif ($warningrange =~ /^@([-+]?[0-9]*\.?[0-9]+):([-+]?[0-9]*\.?[0-9]+)$/) { |
570
|
|
|
|
|
|
|
# warning = @10:20, warn if >= 10 and <= 20 |
571
|
|
|
|
|
|
|
$level = $ERRORS{WARNING} |
572
|
0
|
0
|
0
|
|
|
|
if ($value >= $1 && $value <= $2); |
573
|
|
|
|
|
|
|
} |
574
|
0
|
0
|
|
|
|
|
if (! defined $criticalrange) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
575
|
|
|
|
|
|
|
# there was no set_thresholds for defaults, no --critical, no --criticalx |
576
|
|
|
|
|
|
|
} elsif ($criticalrange =~ /^([-+]?[0-9]*\.?[0-9]+)$/) { |
577
|
|
|
|
|
|
|
# critical = 10, crit if > 10 or < 0 |
578
|
|
|
|
|
|
|
$level = $ERRORS{CRITICAL} |
579
|
0
|
0
|
0
|
|
|
|
if ($value > $1 || $value < 0); |
580
|
|
|
|
|
|
|
} elsif ($criticalrange =~ /^([-+]?[0-9]*\.?[0-9]+):$/) { |
581
|
|
|
|
|
|
|
# critical = 10:, crit if < 10 |
582
|
|
|
|
|
|
|
$level = $ERRORS{CRITICAL} |
583
|
0
|
0
|
|
|
|
|
if ($value < $1); |
584
|
|
|
|
|
|
|
} elsif ($criticalrange =~ /^~:([-+]?[0-9]*\.?[0-9]+)$/) { |
585
|
|
|
|
|
|
|
# critical = ~:10, crit if > 10 |
586
|
|
|
|
|
|
|
$level = $ERRORS{CRITICAL} |
587
|
0
|
0
|
|
|
|
|
if ($value > $1); |
588
|
|
|
|
|
|
|
} elsif ($criticalrange =~ /^([-+]?[0-9]*\.?[0-9]+):([-+]?[0-9]*\.?[0-9]+)$/) { |
589
|
|
|
|
|
|
|
# critical = 10:20, crit if < 10 or > 20 |
590
|
|
|
|
|
|
|
$level = $ERRORS{CRITICAL} |
591
|
0
|
0
|
0
|
|
|
|
if ($value < $1 || $value > $2); |
592
|
|
|
|
|
|
|
} elsif ($criticalrange =~ /^@([-+]?[0-9]*\.?[0-9]+):([-+]?[0-9]*\.?[0-9]+)$/) { |
593
|
|
|
|
|
|
|
# critical = @10:20, crit if >= 10 and <= 20 |
594
|
|
|
|
|
|
|
$level = $ERRORS{CRITICAL} |
595
|
0
|
0
|
0
|
|
|
|
if ($value >= $1 && $value <= $2); |
596
|
|
|
|
|
|
|
} |
597
|
0
|
|
|
|
|
|
return $level; |
598
|
|
|
|
|
|
|
} |
599
|
|
|
|
|
|
|
|
600
|
|
|
|
|
|
|
sub strequal { |
601
|
0
|
|
|
0
|
0
|
|
my($self, $str1, $str2) = @_; |
602
|
0
|
0
|
0
|
|
|
|
return 1 if ! defined $str1 && ! defined $str2; |
603
|
0
|
0
|
0
|
|
|
|
return 0 if ! defined $str1 && defined $str2; |
604
|
0
|
0
|
0
|
|
|
|
return 0 if defined $str1 && ! defined $str2; |
605
|
0
|
0
|
|
|
|
|
return 1 if $str1 eq $str2; |
606
|
0
|
|
|
|
|
|
return 0; |
607
|
|
|
|
|
|
|
} |
608
|
|
|
|
|
|
|
|
609
|
|
|
|
|
|
|
1; |
610
|
|
|
|
|
|
|
|
611
|
|
|
|
|
|
|
__END__ |