|  line  | 
 stmt  | 
 bran  | 
 cond  | 
 sub  | 
 pod  | 
 time  | 
 code  | 
| 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 package Nagios::Plugin;  | 
| 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
4
 | 
5
 | 
 
 | 
 
 | 
  
5
  
 | 
 
 | 
161630
 | 
 use Nagios::Plugin::Functions qw(:codes %ERRORS %STATUS_TEXT @STATUS_CODES);  | 
| 
 
 | 
5
 | 
 
 | 
 
 | 
 
 | 
 
 | 
19
 | 
    | 
| 
 
 | 
5
 | 
 
 | 
 
 | 
 
 | 
 
 | 
1224
 | 
    | 
| 
5
 | 
5
 | 
 
 | 
 
 | 
  
5
  
 | 
 
 | 
31
 | 
 use Params::Validate qw(:all);  | 
| 
 
 | 
5
 | 
 
 | 
 
 | 
 
 | 
 
 | 
8
 | 
    | 
| 
 
 | 
5
 | 
 
 | 
 
 | 
 
 | 
 
 | 
810
 | 
    | 
| 
6
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
7
 | 
5
 | 
 
 | 
 
 | 
  
5
  
 | 
 
 | 
28
 | 
 use strict;  | 
| 
 
 | 
5
 | 
 
 | 
 
 | 
 
 | 
 
 | 
15
 | 
    | 
| 
 
 | 
5
 | 
 
 | 
 
 | 
 
 | 
 
 | 
151
 | 
    | 
| 
8
 | 
5
 | 
 
 | 
 
 | 
  
5
  
 | 
 
 | 
28
 | 
 use warnings;  | 
| 
 
 | 
5
 | 
 
 | 
 
 | 
 
 | 
 
 | 
38
 | 
    | 
| 
 
 | 
5
 | 
 
 | 
 
 | 
 
 | 
 
 | 
179
 | 
    | 
| 
9
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
10
 | 
5
 | 
 
 | 
 
 | 
  
5
  
 | 
 
 | 
27
 | 
 use Carp;  | 
| 
 
 | 
5
 | 
 
 | 
 
 | 
 
 | 
 
 | 
9
 | 
    | 
| 
 
 | 
5
 | 
 
 | 
 
 | 
 
 | 
 
 | 
341
 | 
    | 
| 
11
 | 
5
 | 
 
 | 
 
 | 
  
5
  
 | 
 
 | 
30
 | 
 use base qw(Class::Accessor::Fast);  | 
| 
 
 | 
5
 | 
 
 | 
 
 | 
 
 | 
 
 | 
8
 | 
    | 
| 
 
 | 
5
 | 
 
 | 
 
 | 
 
 | 
 
 | 
5909
 | 
    | 
| 
12
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
13
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 Nagios::Plugin->mk_accessors(qw(  | 
| 
14
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 								shortname  | 
| 
15
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 								perfdata   | 
| 
16
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 								messages   | 
| 
17
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 								opts  | 
| 
18
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 								threshold  | 
| 
19
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 								));  | 
| 
20
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
21
 | 
5
 | 
 
 | 
 
 | 
  
5
  
 | 
 
 | 
21024
 | 
 use Exporter;  | 
| 
 
 | 
5
 | 
 
 | 
 
 | 
 
 | 
 
 | 
12
 | 
    | 
| 
 
 | 
5
 | 
 
 | 
 
 | 
 
 | 
 
 | 
7509
 | 
    | 
| 
22
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 our @ISA = qw(Exporter);  | 
| 
23
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 our @EXPORT = (@STATUS_CODES);  | 
| 
24
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 our @EXPORT_OK = qw(%ERRORS %STATUS_TEXT);  | 
| 
25
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
26
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 # CPAN stupidly won't index this module without a literal $VERSION here,  | 
| 
27
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 #   so we're forced to duplicate it explicitly  | 
| 
28
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 # Make sure you update $Nagios::Plugin::Functions::VERSION too  | 
| 
29
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 our $VERSION = "0.36";  | 
| 
30
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
31
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub new {  | 
| 
32
 | 
24
 | 
 
 | 
 
 | 
  
24
  
 | 
  
0
  
 | 
15047
 | 
 	my $class = shift;  | 
| 
33
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 #	my %args = @_;  | 
| 
34
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
35
 | 
24
 | 
 
 | 
 
 | 
 
 | 
 
 | 
823
 | 
 	my %args = validate( @_,  | 
| 
36
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 		{  | 
| 
37
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 			shortname => 0,  | 
| 
38
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 			usage     => 0,  | 
| 
39
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 			version   => 0,  | 
| 
40
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 			url       => 0,  | 
| 
41
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 			plugin    => 0,  | 
| 
42
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 			blurb     => 0,  | 
| 
43
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 			extra     => 0,  | 
| 
44
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 			license   => 0,  | 
| 
45
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 			timeout   => 0  | 
| 
46
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 		},  | 
| 
47
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 	);  | 
| 
48
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
49
 | 
24
 | 
 
 | 
 
 | 
 
 | 
 
 | 
184
 | 
 	my $shortname = Nagios::Plugin::Functions::get_shortname(\%args);  | 
| 
50
 | 
24
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
75
 | 
 	delete $args{shortname} if (exists $args{shortname});  | 
| 
51
 | 
24
 | 
 
 | 
 
 | 
 
 | 
 
 | 
158
 | 
 	my $self = {  | 
| 
52
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 		shortname => $shortname,  | 
| 
53
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 		perfdata  => [],           # to be added later  | 
| 
54
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 		messages  => {  | 
| 
55
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 			warning  => [],  | 
| 
56
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 			critical => [],  | 
| 
57
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 			ok       => []  | 
| 
58
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 		},  | 
| 
59
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 		opts      => undef,        # see below  | 
| 
60
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 		threshold => undef,        # defined later  | 
| 
61
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 	};  | 
| 
62
 | 
24
 | 
 
 | 
 
 | 
 
 | 
 
 | 
61
 | 
 	bless $self, $class;  | 
| 
63
 | 
24
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
89
 | 
 	if (exists $args{usage}) {  | 
| 
64
 | 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
987
 | 
 		require Nagios::Plugin::Getopt;  | 
| 
65
 | 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
14
 | 
 		$self->opts( new Nagios::Plugin::Getopt(%args) );  | 
| 
66
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 	}  | 
| 
67
 | 
24
 | 
 
 | 
 
 | 
 
 | 
 
 | 
109
 | 
 	return $self;  | 
| 
68
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
69
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
70
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub add_perfdata {  | 
| 
71
 | 
2
 | 
 
 | 
 
 | 
  
2
  
 | 
  
1
  
 | 
34
 | 
     my ($self, %args) = @_;  | 
| 
72
 | 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
821
 | 
     require Nagios::Plugin::Performance;  | 
| 
73
 | 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
15
 | 
     my $perf = Nagios::Plugin::Performance->new(%args);  | 
| 
74
 | 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
29
 | 
     push @{$self->perfdata}, $perf;  | 
| 
 
 | 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
9
 | 
    | 
| 
75
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
76
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub all_perfoutput {  | 
| 
77
 | 
56
 | 
 
 | 
 
 | 
  
56
  
 | 
  
0
  
 | 
870
 | 
     my $self = shift;  | 
| 
78
 | 
56
 | 
 
 | 
 
 | 
 
 | 
 
 | 
75
 | 
     return join(" ", map {$_->perfoutput} (@{$self->perfdata}));  | 
| 
 
 | 
27
 | 
 
 | 
 
 | 
 
 | 
 
 | 
109
 | 
    | 
| 
 
 | 
56
 | 
 
 | 
 
 | 
 
 | 
 
 | 
122
 | 
    | 
| 
79
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
80
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
81
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub set_thresholds {   | 
| 
82
 | 
6
 | 
 
 | 
 
 | 
  
6
  
 | 
  
1
  
 | 
617
 | 
     my $self = shift;   | 
| 
83
 | 
6
 | 
 
 | 
 
 | 
 
 | 
 
 | 
1810
 | 
     require Nagios::Plugin::Threshold;  | 
| 
84
 | 
6
 | 
 
 | 
 
 | 
 
 | 
 
 | 
32
 | 
     return $self->threshold( Nagios::Plugin::Threshold->set_thresholds(@_));   | 
| 
85
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
86
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
87
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 # NP::Functions wrappers  | 
| 
88
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub nagios_exit {  | 
| 
89
 | 
19
 | 
 
 | 
 
 | 
  
19
  
 | 
  
1
  
 | 
7832
 | 
     my $self = shift;  | 
| 
90
 | 
19
 | 
 
 | 
 
 | 
 
 | 
 
 | 
88
 | 
     Nagios::Plugin::Functions::nagios_exit(@_, { plugin => $self });  | 
| 
91
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
92
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub nagios_die {  | 
| 
93
 | 
23
 | 
 
 | 
 
 | 
  
23
  
 | 
  
1
  
 | 
6026
 | 
     my $self = shift;  | 
| 
94
 | 
23
 | 
 
 | 
 
 | 
 
 | 
 
 | 
133
 | 
     Nagios::Plugin::Functions::nagios_die(@_, { plugin => $self });  | 
| 
95
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
96
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub die {  | 
| 
97
 | 
6
 | 
 
 | 
 
 | 
  
6
  
 | 
  
1
  
 | 
9
 | 
     my $self = shift;  | 
| 
98
 | 
6
 | 
 
 | 
 
 | 
 
 | 
 
 | 
29
 | 
     Nagios::Plugin::Functions::nagios_die(@_, { plugin => $self });  | 
| 
99
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
100
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub max_state {  | 
| 
101
 | 
0
 | 
 
 | 
 
 | 
  
0
  
 | 
  
1
  
 | 
0
 | 
     Nagios::Plugin::Functions::max_state(@_);  | 
| 
102
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
103
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub max_state_alt {  | 
| 
104
 | 
0
 | 
 
 | 
 
 | 
  
0
  
 | 
  
1
  
 | 
0
 | 
     Nagios::Plugin::Functions::max_state_alt(@_);  | 
| 
105
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
106
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
107
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 # top level interface to Nagios::Plugin::Threshold  | 
| 
108
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub check_threshold {  | 
| 
109
 | 
20
 | 
 
 | 
 
 | 
  
20
  
 | 
  
1
  
 | 
2445
 | 
 	my $self = shift;  | 
| 
110
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
111
 | 
20
 | 
 
 | 
 
 | 
 
 | 
 
 | 
28
 | 
 	my %args;  | 
| 
112
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
113
 | 
20
 | 
  
100
  
 | 
  
 66
  
 | 
 
 | 
 
 | 
121
 | 
 	if ( $#_ == 0 && (! ref $_[0] || ref $_[0] eq "ARRAY" )) {  # one positional param  | 
| 
 
 | 
 
 | 
 
 | 
  
 66
  
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
114
 | 
14
 | 
 
 | 
 
 | 
 
 | 
 
 | 
38
 | 
 		%args = (check => shift);  | 
| 
115
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 	}  | 
| 
116
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 	else {  | 
| 
117
 | 
6
 | 
 
 | 
 
 | 
 
 | 
 
 | 
652
 | 
 		%args = validate ( @_, {  # named params  | 
| 
118
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 			check => 1,  | 
| 
119
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 			warning => 0,  | 
| 
120
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 			critical => 0,  | 
| 
121
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 		} );  | 
| 
122
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 	}  | 
| 
123
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
124
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 	# in order of preference, get warning and critical from  | 
| 
125
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 	#  1.  explicit arguments to check_threshold  | 
| 
126
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 	#  2.  previously explicitly set threshold object  | 
| 
127
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 	#  3.  implicit options from Getopts object  | 
| 
128
 | 
19
 | 
  
100
  
 | 
  
 66
  
 | 
 
 | 
 
 | 
131
 | 
 	if ( exists $args{warning} || exists $args{critical} ) {  | 
| 
 
 | 
 
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
 
 | 
 
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
129
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
10
 | 
 		$self->set_thresholds(  | 
| 
130
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 			warning  => $args{warning},  | 
| 
131
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 			critical => $args{critical},  | 
| 
132
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 		);  | 
| 
133
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 	}  | 
| 
134
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 	elsif ( defined $self->threshold ) {  | 
| 
135
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 		# noop  | 
| 
136
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 	}  | 
| 
137
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 	elsif ( defined $self->opts ) {  | 
| 
138
 | 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
31
 | 
 		$self->set_thresholds(  | 
| 
139
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 			warning  => $self->opts->warning,  | 
| 
140
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 			critical => $self->opts->critical,  | 
| 
141
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 		);  | 
| 
142
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 	}  | 
| 
143
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 	else {  | 
| 
144
 | 
4
 | 
 
 | 
 
 | 
 
 | 
 
 | 
55
 | 
 		return UNKNOWN;  | 
| 
145
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 	}  | 
| 
146
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 	  | 
| 
147
 | 
15
 | 
 
 | 
 
 | 
 
 | 
 
 | 
231
 | 
 	return $self->threshold->get_status($args{check});  | 
| 
148
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
149
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
150
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 # top level interface to my Nagios::Plugin::Getopt object  | 
| 
151
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub add_arg {  | 
| 
152
 | 
3
 | 
 
 | 
 
 | 
  
3
  
 | 
  
1
  
 | 
893
 | 
     my $self = shift;  | 
| 
153
 | 
3
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
8
 | 
 	$self->opts->arg(@_) if $self->_check_for_opts;  | 
| 
154
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
155
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub getopts {  | 
| 
156
 | 
2
 | 
 
 | 
 
 | 
  
2
  
 | 
  
1
  
 | 
684
 | 
     my $self = shift;  | 
| 
157
 | 
2
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
5
 | 
 	$self->opts->getopts(@_) if $self->_check_for_opts;  | 
| 
158
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
159
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
160
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub _check_for_opts {  | 
| 
161
 | 
5
 | 
 
 | 
 
 | 
  
5
  
 | 
 
 | 
9
 | 
 	my $self = shift;  | 
| 
162
 | 
5
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
14
 | 
 	croak  | 
| 
163
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 		"You have to supply a 'usage' param to Nagios::Plugin::new() if you want to use Getopts from your Nagios::Plugin object."  | 
| 
164
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 			unless ref $self->opts() eq 'Nagios::Plugin::Getopt';  | 
| 
165
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
27
 | 
 	return $self;  | 
| 
166
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
167
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
168
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
169
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
170
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 # -------------------------------------------------------------------------  | 
| 
171
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 # NP::Functions::check_messages helpers and wrappers  | 
| 
172
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
173
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub add_message {  | 
| 
174
 | 
18
 | 
 
 | 
 
 | 
  
18
  
 | 
  
1
  
 | 
998
 | 
     my $self = shift;  | 
| 
175
 | 
18
 | 
 
 | 
 
 | 
 
 | 
 
 | 
44
 | 
     my ($code, @messages) = @_;  | 
| 
176
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
177
 | 
18
 | 
  
100
  
 | 
  
100
  
 | 
 
 | 
 
 | 
391
 | 
     croak "Invalid error code '$code'"  | 
| 
178
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         unless defined($ERRORS{uc $code}) || defined($STATUS_TEXT{$code});  | 
| 
179
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
180
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     # Store messages using strings rather than numeric codes  | 
| 
181
 | 
16
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
41
 | 
     $code = $STATUS_TEXT{$code} if $STATUS_TEXT{$code};  | 
| 
182
 | 
16
 | 
 
 | 
 
 | 
 
 | 
 
 | 
24
 | 
     $code = lc $code;   | 
| 
183
 | 
16
 | 
  
100
  
 | 
  
100
  
 | 
 
 | 
 
 | 
283
 | 
     croak "Error code '$code' not supported by add_message"  | 
| 
184
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         if $code eq 'unknown' || $code eq 'dependent';  | 
| 
185
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
186
 | 
14
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
36
 | 
     $self->messages($code, []) unless $self->messages->{$code};  | 
| 
187
 | 
14
 | 
 
 | 
 
 | 
 
 | 
 
 | 
82
 | 
     push @{$self->messages->{$code}}, @messages;  | 
| 
 
 | 
14
 | 
 
 | 
 
 | 
 
 | 
 
 | 
30
 | 
    | 
| 
188
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
189
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
190
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub check_messages {  | 
| 
191
 | 
30
 | 
 
 | 
 
 | 
  
30
  
 | 
  
1
  
 | 
17689
 | 
     my $self = shift;  | 
| 
192
 | 
30
 | 
 
 | 
 
 | 
 
 | 
 
 | 
82
 | 
     my %args = @_;  | 
| 
193
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
194
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     # Add object messages to any passed in as args  | 
| 
195
 | 
30
 | 
 
 | 
 
 | 
 
 | 
 
 | 
60
 | 
     for my $code (qw(critical warning ok)) {  | 
| 
196
 | 
90
 | 
 
 | 
  
 50
  
 | 
 
 | 
 
 | 
230
 | 
         my $messages = $self->messages->{$code} || [];  | 
| 
197
 | 
90
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
507
 | 
         if ($args{$code}) {  | 
| 
198
 | 
48
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
104
 | 
             unless (ref $args{$code} eq 'ARRAY') {  | 
| 
199
 | 
4
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
10
 | 
                 if ($code eq 'ok') {  | 
| 
200
 | 
4
 | 
 
 | 
 
 | 
 
 | 
 
 | 
11
 | 
                     $args{$code} = [ $args{$code} ];  | 
| 
201
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
                 } else {  | 
| 
202
 | 
0
 | 
 
 | 
 
 | 
 
 | 
 
 | 
0
 | 
                     croak "Invalid argument '$code'"   | 
| 
203
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
                 }  | 
| 
204
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
             }  | 
| 
205
 | 
48
 | 
 
 | 
 
 | 
 
 | 
 
 | 
41
 | 
             push @{$args{$code}}, @$messages;  | 
| 
 
 | 
48
 | 
 
 | 
 
 | 
 
 | 
 
 | 
134
 | 
    | 
| 
206
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         }  | 
| 
207
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         else {  | 
| 
208
 | 
42
 | 
 
 | 
 
 | 
 
 | 
 
 | 
97
 | 
             $args{$code} = $messages;  | 
| 
209
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         }  | 
| 
210
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     }  | 
| 
211
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
212
 | 
30
 | 
 
 | 
 
 | 
 
 | 
 
 | 
126
 | 
     Nagios::Plugin::Functions::check_messages(%args);  | 
| 
213
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
214
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
215
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 # -------------------------------------------------------------------------  | 
| 
216
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
217
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 1;  | 
| 
218
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
219
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 #vim:et:sw=4  | 
| 
220
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
221
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 __END__  |