Debian Codegraph @

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