Debian Codegraph @

src/network/cisco/firepower/fxos/snmp/mode/faults.pm

raw
1 #
2 # Copyright 2024 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::cisco::firepower::fxos::snmp::mode::faults;
22
23 use base qw(centreon::plugins::templates::counter);
24
25 use strict;
26 use warnings;
27 use centreon::plugins::misc;
28 use centreon::plugins::statefile;
29 use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
30
31 sub custom_status_output {
32 my ($self, %options) = @_;
33
34 return sprintf(
35 "fault '%s' [severity: %s] [type: %s] [ack: %s] [description: %s] %s",
36 $self->{result_values}->{object},
37 $self->{result_values}->{severity},
38 $self->{result_values}->{type},
39 $self->{result_values}->{acknowledged},
40 $self->{result_values}->{description},
41 $self->{result_values}->{generation_time}
42 );
43 }
44
45
46 sub prefix_global_output {
47 my ($self, %options) = @_;
48
49 return 'Faults ';
50 }
51
52 sub set_counters {
53 my ($self, %options) = @_;
54
55 $self->{maps_counters_type} = [
56 { name => 'global', type => 0, cb_prefix_output => 'prefix_global_output' },
57 { name => 'faults', type => 2, message_multiple => '0 fault(s) detected', display_counter_problem => { nlabel => 'faults.problems.current.count', min => 0 },
58 group => [ { name => 'fault', skipped_code => { -11 => 1 } } ]
59 }
60 ];
61
62 $self->{maps_counters}->{global} = [
63 { label => 'faults-total', nlabel => 'faults.total.count', display_ok => 0, set => {
64 key_values => [ { name => 'total' } ],
65 output_template => 'total: %s',
66 perfdatas => [
67 { template => '%s', min => 0 }
68 ]
69 }
70 }
71 ];
72
73 foreach (('critical', 'major', 'warning', 'minor', 'info')) {
74 push @{$self->{maps_counters}->{global}},
75 { label => 'faults-' . $_, nlabel => 'faults.' . $_ . '.count', display_ok => 0, set => {
76 key_values => [ { name => $_ }, { name => 'total' } ],
77 output_template => $_ . ': %s',
78 perfdatas => [
79 { template => '%s', min => 0, max => 'total' }
80 ]
81 }
82 };
83 }
84
85
86 $self->{maps_counters}->{fault} = [
87 {
88 label => 'status',
89 type => 2,
90 warning_default => '%{severity} =~ /minor|warning/',
91 critical_default => '%{severity} =~ /major|critical/',
92 set => {
93 key_values => [
94 { name => 'severity' }, { name => 'type' },
95 { name => 'acknowledged'}, { name => 'since' },
96 { name => 'object' }, { name => 'description' },
97 { name => 'generation_time' }
98 ],
99 closure_custom_output => $self->can('custom_status_output'),
100 closure_custom_perfdata => sub { return 0; },
101 closure_custom_threshold_check => \&catalog_status_threshold_ng
102 }
103 },
104 ];
105 }
106
107 sub new {
108 my ($class, %options) = @_;
109 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
110 bless $self, $class;
111
112 $options{options}->add_options(arguments => {
113 'memory' => { name => 'memory' },
114 'timezone:s' => { name => 'timezone' }
115 });
116
117 centreon::plugins::misc::mymodule_load(
118 output => $self->{output},
119 module => 'DateTime',
120 error_msg => "Cannot load module 'DateTime'."
121 );
122 $self->{statefile_cache} = centreon::plugins::statefile->new(%options);
123 return $self;
124 }
125
126 sub check_options {
127 my ($self, %options) = @_;
128 $self->SUPER::check_options(%options);
129
130 if (defined($self->{option_results}->{memory})) {
131 $self->{statefile_cache}->check_options(%options);
132 }
133
134 $self->{option_results}->{timezone} = 'GMT' if (!defined($self->{option_results}->{timezone}) || $self->{option_results}->{timezone} eq '');
135 }
136
137 my $map_ack = { 1 => 'yes', 2 => 'no' };
138 my $map_severity = {
139 0 => 'cleared', 1 => 'info', 2 => 'condition',
140 3 => 'warning', 4 => 'minor',
141 5 => 'major', 6 => 'critical'
142 };
143 my $map_type = {
144 0 => 'generic', 1 => 'configuration', 2 => 'fsm',
145 3 => 'network', 4 => 'server', 5 => 'management',
146 6 => 'equipment', 7 => 'environmental', 8 => 'operational',
147 9 => 'connectivity', 10 => 'security',
148 11 => 'sysdebug', 65536 => 'any'
149 };
150
151 my $mapping = {
152 object => { oid => '.1.3.6.1.4.1.9.9.826.1.1.1.1.2' }, # cfprFaultInstDn
153 acknowledged => { oid => '.1.3.6.1.4.1.9.9.826.1.1.1.1.6', map => $map_ack }, # cfprFaultInstAck
154 created => { oid => '.1.3.6.1.4.1.9.9.826.1.1.1.1.10' }, # cfprFaultInstCreated
155 description => { oid => '.1.3.6.1.4.1.9.9.826.1.1.1.1.11' }, # cfprFaultInstDescr
156 severity => { oid => '.1.3.6.1.4.1.9.9.826.1.1.1.1.20', map => $map_severity }, # cfprFaultInstSeverity
157 type => { oid => '.1.3.6.1.4.1.9.9.826.1.1.1.1.22', map => $map_type } # cfprFaultInstType
158 };
159
160 sub manage_selection {
161 my ($self, %options) = @_;
162
163 my $snmp_result = $options{snmp}->get_multiple_table(
164 oids => [ map({ oid => $_->{oid} }, values(%$mapping)) ],
165 return_type => 1
166 );
167
168 my $last_time;
169 if (defined($self->{option_results}->{memory})) {
170 $self->{statefile_cache}->read(statefile => 'cisco_firepower_fxos_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port(). '_' . $self->{mode});
171 $last_time = $self->{statefile_cache}->get(name => 'last_time');
172 }
173
174 $self->{global} = { total => 0, critical => 0, major => 0, warning => 0, minor => 0, info => 0 };
175 $self->{faults}->{global} = { fault => {} };
176
177 my $current_time = time();
178 foreach my $oid (keys %$snmp_result) {
179 next if ($oid !~ /^$mapping->{severity}->{oid}\.(.*)$/);
180 my $instance = $1;
181 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance);
182
183 my @date = unpack 'n C6 a C2', $result->{created};
184 my $timezone = $self->{option_results}->{timezone};
185 if (defined($date[8])) {
186 $timezone = sprintf("%s%02d%02d", $date[7], $date[8], $date[9]);
187 }
188
189 my $tz = centreon::plugins::misc::set_timezone(name => $timezone);
190 my $dt = DateTime->new(
191 year => $date[0], month => $date[1], day => $date[2], hour => $date[3], minute => $date[4], second => $date[5],
192 %$tz
193 );
194
195 next if (defined($self->{option_results}->{memory}) && defined($last_time) && $last_time > $dt->epoch);
196
197 my $diff_time = $current_time - $dt->epoch();
198
199 $self->{faults}->{global}->{fault}->{ $result->{object} } = {
200 since => $diff_time,
201 generation_time => centreon::plugins::misc::change_seconds(value => $diff_time),
202 %$result
203 };
204
205 $self->{global}->{total}++;
206 $self->{global}->{ $result->{severity} }++
207 if (defined($self->{global}->{ $result->{severity} }));
208 }
209
210 if (defined($self->{option_results}->{memory})) {
211 $self->{statefile_cache}->write(data => { last_time => $current_time });
212 }
213 }
214
215 1;
216
217 __END__
218
219 =head1 MODE
220
221 Check faults.
222
223 =over 8
224
225 =item B<--warning-status>
226
227 Define the conditions to match for the status to be WARNING (default: '%{severity} =~ /minor|warning/).
228 You can use the following variables: %{description}, %{object}, %{severity}, %{type}, %{acknowledged}, %{since}
229
230 =item B<--critical-status>
231
232 Define the conditions to match for the status to be CRITICAL (default: '%{severity} =~ /major|critical/').
233 You can use the following variables: %{description}, %{object}, %{severity}, %{type}, %{since}
234
235 =item B<--timezone>
236
237 Timezone options (the date from the equipment overload that option). Default is 'GMT'.
238
239 =item B<--memory>
240
241 Only check new alarms.
242
243 =item B<--warning-*> B<--critical-*>
244
245 Thresholds.
246 Can be: 'faults-total', 'faults-critical', 'faults-major', 'faults-warning', 'faults-minor', 'faults-info'.
247
248 =back
249
250 =cut