Debian Codegraph @

src/network/adva/fsp150/snmp/mode/components/card.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::adva::fsp150::snmp::mode::components::card;
22
23 use strict;
24 use warnings;
25 use network::adva::fsp150::snmp::mode::components::resources qw(
26 $map_card_type $oids
27 get_secondary_states
28 );
29
30 my $mapping = {
31 slotEntityIndex => { oid => '.1.3.6.1.4.1.2544.1.12.3.1.3.1.2' },
32 slotCardType => { oid => '.1.3.6.1.4.1.2544.1.12.3.1.3.1.4', map => $map_card_type },
33 slotSecondaryState => { oid => '.1.3.6.1.4.1.2544.1.12.3.1.3.1.15' }
34 };
35
36 sub load {
37 my ($self) = @_;
38
39 push @{$self->{request}},
40 { oid => $mapping->{slotEntityIndex}->{oid} },
41 { oid => $mapping->{slotCardType}->{oid} },
42 { oid => $mapping->{slotSecondaryState}->{oid} };
43 }
44
45 sub check {
46 my ($self) = @_;
47
48 $self->{output}->output_add(long_msg => 'checking cards');
49 $self->{components}->{card} = { name => 'cards', total => 0, skip => 0 };
50 return if ($self->check_filter(section => 'card'));
51
52 my $results = {
53 %{$self->{results}->{ $mapping->{slotEntityIndex}->{oid} }},
54 %{$self->{results}->{ $mapping->{slotCardType}->{oid} }},
55 %{$self->{results}->{ $mapping->{slotSecondaryState}->{oid} }}
56 };
57 foreach my $oid ($self->{snmp}->oid_lex_sort(keys %$results)) {
58 next if ($oid !~ /^$mapping->{slotEntityIndex}->{oid}\.(\d+)\.(\d+)\.(\d+)$/);
59
60 my ($ne_index, $shelf_index, $card_index, $instance) = ($1, $2, $3, $1 . '.' . $2 . '.' . $3);
61 my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $results, instance => $instance);
62
63 my $ne_name = $self->{results}->{ $oids->{neName} }->{ $oids->{neName} . '.' . $ne_index };
64 my $entity_name = $self->{results}->{ $oids->{entPhysicalName} }->{ $oids->{entPhysicalName} . '.' . $result->{slotEntityIndex} };
65 my $name = $ne_name . ':' . $entity_name;
66 my $secondary_states = get_secondary_states(state => $result->{slotSecondaryState});
67
68 my $secondary_str = join(',', @$secondary_states);
69 if ($secondary_str =~ /mainteance/) {
70 $self->{output}->output_add(
71 long_msg => sprintf("skipping card '%s': in maintenance mode", $name)
72 );
73 next;
74 }
75
76 next if ($self->check_filter(section => 'card', instance => $result->{slotCardType} . '.' . $instance));
77 $self->{components}->{card}->{total}++;
78
79 $self->{output}->output_add(
80 long_msg => sprintf(
81 "card '%s' secondary status is '%s' [instance: %s].",
82 $name,
83 $secondary_str,
84 $result->{slotCardType} . '.' . $instance
85 )
86 );
87
88 my $exit = 'ok';
89 foreach (@$secondary_states) {
90 my $exit_tmp = $self->get_severity(label => 'secondary', section => 'card', instance => $result->{slotCardType} . '.' . $instance, value => $_);
91 $exit = $self->{output}->get_most_critical(status => [ $exit, $exit_tmp ]);
92 }
93 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
94 $self->{output}->output_add(
95 severity => $exit,
96 short_msg => sprintf(
97 "card '%s' secondary status is '%s'",
98 $name,
99 $secondary_str
100 )
101 );
102 }
103 }
104 }
105
106 1;