| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package JMX::Jmx4Perl::Nagios::MessageHandler; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
7
|
use Monitoring::Plugin::Functions qw(:codes %ERRORS %STATUS_TEXT); |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
176
|
|
|
4
|
1
|
|
|
1
|
|
8
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
740
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 NAME |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
JMX::Jmx4Perl::Nagios::MessageHandler - Handling Nagios exit message (one or |
|
9
|
|
|
|
|
|
|
many) |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=cut |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new { |
|
14
|
1
|
|
|
1
|
0
|
3
|
my $class = shift; |
|
15
|
1
|
|
|
|
|
3
|
my $self = { |
|
16
|
|
|
|
|
|
|
messages => {} |
|
17
|
|
|
|
|
|
|
}; |
|
18
|
1
|
|
33
|
|
|
8
|
bless $self,(ref($class) || $class); |
|
19
|
1
|
|
|
|
|
5
|
return $self; |
|
20
|
|
|
|
|
|
|
} |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub add_message { |
|
23
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
24
|
0
|
|
|
|
|
|
my ($code,@messages) = @_; |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
die "Invalid error code '$code'\n" |
|
27
|
0
|
0
|
0
|
|
|
|
unless defined($ERRORS{uc $code}) || defined($STATUS_TEXT{$code}); |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# Store messages using strings rather than numeric codes |
|
30
|
0
|
0
|
|
|
|
|
$code = $STATUS_TEXT{$code} if $STATUS_TEXT{$code}; |
|
31
|
0
|
|
|
|
|
|
$code = lc $code; |
|
32
|
|
|
|
|
|
|
|
|
33
|
0
|
0
|
|
|
|
|
$self->{messages}->{$code} = [] unless $self->{messages}->{$code}; |
|
34
|
0
|
|
|
|
|
|
push @{$self->{messages}->{$code}}, @messages; |
|
|
0
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
} |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub check_messages { |
|
38
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
39
|
0
|
|
|
|
|
|
my %arg = @_; |
|
40
|
|
|
|
|
|
|
|
|
41
|
0
|
|
|
|
|
|
for my $code (qw(critical warning ok unknown)) { |
|
42
|
0
|
|
0
|
|
|
|
$arg{$code} = $self->{messages}->{$code} || []; |
|
43
|
|
|
|
|
|
|
} |
|
44
|
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
my $code = OK; |
|
46
|
0
|
0
|
0
|
|
|
|
$code ||= UNKNOWN if @{$arg{unknown}}; |
|
|
0
|
|
|
|
|
|
|
|
47
|
0
|
0
|
0
|
|
|
|
$code ||= CRITICAL if @{$arg{critical}}; |
|
|
0
|
|
|
|
|
|
|
|
48
|
0
|
0
|
0
|
|
|
|
$code ||= WARNING if @{$arg{warning}}; |
|
|
0
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
my $message = join( "\n", |
|
51
|
0
|
0
|
|
|
|
|
map { @$_ ? join( "\n", @$_) : () } |
|
52
|
|
|
|
|
|
|
$arg{unknown}, |
|
53
|
|
|
|
|
|
|
$arg{critical}, |
|
54
|
|
|
|
|
|
|
$arg{warning}, |
|
55
|
0
|
0
|
|
|
|
|
$arg{ok} ? (ref $arg{ok} ? $arg{ok} : [ $arg{ok} ]) : [] |
|
|
|
0
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
); |
|
57
|
0
|
|
|
|
|
|
return ($code, $message); |
|
58
|
|
|
|
|
|
|
} |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
1; |