Debian Codegraph @

src/storage/huawei/oceanstor/snmp/mode/listcontrollers.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 storage::huawei::oceanstor::snmp::mode::listcontrollers;
22
23 use base qw(centreon::plugins::mode);
24
25 use strict;
26 use warnings;
27 use storage::huawei::oceanstor::snmp::mode::resources qw($health_status $running_status);
28
29 sub new {
30 my ($class, %options) = @_;
31 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
32 bless $self, $class;
33
34 $options{options}->add_options(arguments => {
35 });
36
37 return $self;
38 }
39
40 sub check_options {
41 my ($self, %options) = @_;
42 $self->SUPER::init(%options);
43 }
44
45 my $mapping = {
46 id => { oid => '.1.3.6.1.4.1.34774.4.1.23.5.2.1.1' }, # hwInfoControllerID
47 health_status => { oid => '.1.3.6.1.4.1.34774.4.1.23.5.2.1.2', map => $health_status }, # hwInfoControllerHealthStatus
48 running_status => { oid => '.1.3.6.1.4.1.34774.4.1.23.5.2.1.3', map => $running_status }, # hwInfoControllerRunningStatus
49 };
50 my $oid_controller_entry = '.1.3.6.1.4.1.34774.4.1.23.5.2.1'; # hwInfoControllerEntry
51
52 sub manage_selection {
53 my ($self, %options) = @_;
54
55 my $snmp_result = $options{snmp}->get_table(
56 oid => $oid_controller_entry,
57 end => $mapping->{running_status}->{oid}
58 );
59
60 my $controllers = {};
61 foreach my $oid (keys %$snmp_result) {
62 next if ($oid !~ /^$mapping->{id}->{oid}\.(.*)$/);
63 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $1);
64 $controllers->{$1} = $result;
65 }
66
67 return $controllers;
68 }
69
70 sub run {
71 my ($self, %options) = @_;
72
73 my $controllers = $self->manage_selection(%options);
74 foreach (sort keys %$controllers) {
75 $self->{output}->output_add(
76 long_msg => sprintf(
77 '[id: %s] [health status: %s] [running status: %s]',
78 $controllers->{$_}->{id},
79 $controllers->{$_}->{health_status},
80 $controllers->{$_}->{running_status}
81 )
82 );
83 }
84
85 $self->{output}->output_add(
86 severity => 'OK',
87 short_msg => 'List controllers:'
88 );
89 $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
90 $self->{output}->exit();
91 }
92
93 sub disco_format {
94 my ($self, %options) = @_;
95
96 $self->{output}->add_disco_format(elements => [keys %$mapping]);
97 }
98
99 sub disco_show {
100 my ($self, %options) = @_;
101
102 my $controllers = $self->manage_selection(%options);
103 foreach (sort keys %$controllers) {
104 $self->{output}->add_disco_entry(
105 %{$controllers->{$_}}
106 );
107 }
108 }
109
110 1;
111
112 __END__
113
114 =head1 MODE
115
116 List controllers.
117
118 =over 8
119
120 =back
121
122 =cut
123