Debian Codegraph @

src/storage/huawei/oceanstor/snmp/mode/liststoragepools.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::liststoragepools;
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 name => { oid => '.1.3.6.1.4.1.34774.4.1.23.4.2.1.2' }, # hwInfoStoragePoolName
47 domain_name => { oid => '.1.3.6.1.4.1.34774.4.1.23.4.2.1.4' }, # hwInfoStoragePoolDiskDomainName
48 health_status => { oid => '.1.3.6.1.4.1.34774.4.1.23.4.2.1.5', map => $health_status }, # hwInfoStoragePoolHealthStatus
49 running_status => { oid => '.1.3.6.1.4.1.34774.4.1.23.4.2.1.6', map => $running_status }, # hwInfoStoragePoolRunningStatus
50 };
51 my $oid_sp_entry = '.1.3.6.1.4.1.34774.4.1.23.4.2.1'; # hwInfoStoragePoolEntry
52
53 sub manage_selection {
54 my ($self, %options) = @_;
55
56 my $snmp_result = $options{snmp}->get_table(
57 oid => $oid_sp_entry,
58 end => $mapping->{running_status}->{oid}
59 );
60
61 my $sp = {};
62 foreach my $oid (keys %$snmp_result) {
63 next if ($oid !~ /^$mapping->{name}->{oid}\.(.*)$/);
64 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $1);
65 $sp->{$1} = $result;
66 }
67
68 return $sp;
69 }
70
71 sub run {
72 my ($self, %options) = @_;
73
74 my $sp = $self->manage_selection(%options);
75 foreach (sort keys %$sp) {
76 $self->{output}->output_add(
77 long_msg => sprintf(
78 '[name: %s] [domain name: %s] [health status: %s] [running status: %s]',
79 $sp->{$_}->{name},
80 $sp->{$_}->{domain_name},
81 $sp->{$_}->{health_status},
82 $sp->{$_}->{running_status}
83 )
84 );
85 }
86
87 $self->{output}->output_add(
88 severity => 'OK',
89 short_msg => 'List storage pools:'
90 );
91 $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
92 $self->{output}->exit();
93 }
94
95 sub disco_format {
96 my ($self, %options) = @_;
97
98 $self->{output}->add_disco_format(elements => [keys %$mapping]);
99 }
100
101 sub disco_show {
102 my ($self, %options) = @_;
103
104 my $sp = $self->manage_selection(%options);
105 foreach (sort keys %$sp) {
106 $self->{output}->add_disco_entry(
107 %{$sp->{$_}}
108 );
109 }
110 }
111
112 1;
113
114 __END__
115
116 =head1 MODE
117
118 List storage pools.
119
120 =over 8
121
122 =back
123
124 =cut
125