Debian Codegraph @

src/network/juniper/trapeze/snmp/mode/apstatus.pm

raw
1 #
2 # Copyright 2015 Centreon (http://www.centreon.com/)
3 #
4 # Centreon is a full-fledged industry-strength solution that meets
5 # the needs in IT infrastructure and application monitoring for
6 # service performance.
7 #
8 # Licensed under the Apache License, Version 2.0 (the "License");
9 # you may not use this file except in compliance with the License.
10 # You may obtain a copy of the License at
11 #
12 # http://www.apache.org/licenses/LICENSE-2.0
13 #
14 # Unless required by applicable law or agreed to in writing, software
15 # distributed under the License is distributed on an "AS IS" BASIS,
16 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 # See the License for the specific language governing permissions and
18 # limitations under the License.
19 #
20
21 package network::juniper::trapeze::snmp::mode::apstatus;
22
23 use base qw(centreon::plugins::templates::counter);
24
25 use strict;
26 use warnings;
27 use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold);
28
29 sub custom_status_output {
30 my ($self, %options) = @_;
31 my $msg;
32
33 if ($self->{result_values}->{opstatus} eq 'disabled') {
34 $msg = ' is disabled';
35 } else {
36 $msg = 'Status : ' . $self->{result_values}->{opstatus};
37 }
38 return $msg;
39 }
40
41 sub custom_status_calc {
42 my ($self, %options) = @_;
43
44 $self->{result_values}->{opstatus} = $options{new_datas}->{$self->{instance} . '_opstatus'};
45 $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'};
46 return 0;
47 }
48
49 sub set_counters {
50 my ($self, %options) = @_;
51
52 $self->{maps_counters_type} = [
53 { name => 'global', type => 0, cb_init => 'skip_global', },
54 { name => 'ap', type => 1, cb_prefix_output => 'prefix_ap_output', message_multiple => 'All AP status are ok' }
55 ];
56 $self->{maps_counters}->{global} = [
57 { label => 'total', set => {
58 key_values => [ { name => 'total' } ],
59 output_template => 'Total ap : %s',
60 perfdatas => [
61 { label => 'total', value => 'total', template => '%s',
62 min => 0 },
63 ],
64 }
65 },
66 ];
67 $self->{maps_counters}->{ap} = [
68 { label => 'status', threshold => 0, set => {
69 key_values => [ { name => 'opstatus' }, { name => 'display' } ],
70 closure_custom_calc => $self->can('custom_status_calc'),
71 closure_custom_output => $self->can('custom_status_output'),
72 closure_custom_perfdata => sub { return 0; },
73 closure_custom_threshold_check => \&catalog_status_threshold,
74 }
75 },
76 ];
77 }
78
79 sub new {
80 my ($class, %options) = @_;
81 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
82 bless $self, $class;
83
84 $options{options}->add_options(arguments =>
85 {
86 "filter-name:s" => { name => 'filter_name' },
87 "warning-status:s" => { name => 'warning_status', default => '' },
88 "critical-status:s" => { name => 'critical_status', default => '%{opstatus} !~ /init|redundant|operationnal/' },
89 });
90
91 return $self;
92 }
93
94 sub check_options {
95 my ($self, %options) = @_;
96 $self->SUPER::check_options(%options);
97
98 $self->change_macros(macros => ['warning_status', 'critical_status']);
99 }
100
101 sub skip_global {
102 my ($self, %options) = @_;
103
104 scalar(keys %{$self->{ap}}) > 1 ? return(0) : return(1);
105 }
106
107 sub prefix_ap_output {
108 my ($self, %options) = @_;
109
110 return "AP '" . $options{instance_value}->{display} . "' ";
111 }
112
113 my %map_ap_status = (
114 1 => 'cleared',
115 2 => 'init',
116 3 => 'bootStarted',
117 4 => 'imageDownloaded',
118 5 => 'connectFailed',
119 6 => 'configuring',
120 7 => 'operationnal',
121 10 => 'redundant',
122 20 => 'connOutage',
123 );
124
125 my $mapping_name_oid = {
126 trpzApStatApStatusApName => { oid => '.1.3.6.1.4.1.14525.4.5.1.1.2.1.8' },
127 };
128 my $mapping_state_oid = {
129 trpzApStatApStatusApState => { oid => '.1.3.6.1.4.1.14525.4.5.1.1.2.1.5', map => \%map_ap_status },
130 };
131
132 sub manage_selection {
133 my ($self, %options) = @_;
134
135 $self->{ap} = {};
136 $self->{global} = { total => 0};
137 $self->{results} = $options{snmp}->get_multiple_table(oids => [{ oid => $mapping_name_oid->{trpzApStatApStatusApName}->{oid} },
138 { oid => $mapping_state_oid->{trpzApStatApStatusApState}->{oid} },
139 ],
140 nothing_quit => 1);
141
142 foreach my $oid (keys %{$self->{results}->{ $mapping_name_oid->{trpzApStatApStatusApName}->{oid} }}) {
143 $oid =~ /^$mapping_name_oid->{trpzApStatApStatusApName}->{oid}\.(.*)$/;
144 my $instance = $1;
145 my $result = $options{snmp}->map_instance(mapping => $mapping_name_oid, results => $self->{results}->{ $mapping_name_oid->{trpzApStatApStatusApName}->{oid} }, instance => $instance);
146 my $result2 = $options{snmp}->map_instance(mapping => $mapping_state_oid, results => $self->{results}->{ $mapping_state_oid->{trpzApStatApStatusApState}->{oid} }, instance => $instance);
147 if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
148 $result->{trpzApStatApStatusApName} !~ /$self->{option_results}->{filter_name}/) {
149 $self->{output}->output_add(long_msg => "Skipping '" . $result->{trpzApStatApStatusApName} . "': no matching filter.", debug => 1);
150 next;
151 }
152
153 $self->{global}->{total}++;
154 $self->{ap}->{$instance} = { display => $result->{trpzApStatApStatusApName},
155 opstatus => $result2->{trpzApStatApStatusApState}};
156 }
157
158 if (scalar(keys %{$self->{ap}}) <= 0) {
159 $self->{output}->output_add(severity => 'OK',
160 short_msg => 'No AP associated, check your filter ? ');
161 }
162 }
163
164 1;
165
166 __END__
167
168 =head1 MODE
169
170 Check AP status.
171
172 =over 8
173
174 =item B<--filter-name>
175
176 Filter AP name (can be a regexp).
177
178 =item B<--warning-status>
179
180 Define the conditions to match for the status to be WARNING.
181 You can use the following variables: %{opstatus}, %{display}
182
183 =item B<--critical-status>
184
185 Define the conditions to match for the status to be CRITICAL (default: '%{opstatus} !~ /init|redundant|operationnal/').
186 You can use the following variables: %{opstatus}, %{display}
187
188 =item B<--warning-total>
189
190 Set warning threshold for number of AP linked to the WLC
191
192 =item B<--critical-total>
193
194 Set critical threshold for number of AP linked to the WLC
195
196 =back
197
198 =cut