Debian Codegraph @

src/storage/hp/primera/restapi/mode/listdisks.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::hp::primera::restapi::mode::listdisks;
22
23 use strict;
24 use warnings;
25
26 use base qw(centreon::plugins::mode);
27
28 sub new {
29 my ($class, %options) = @_;
30 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
31 bless $self, $class;
32
33 return $self;
34 }
35
36 sub check_options {
37 my ($self, %options) = @_;
38 $self->SUPER::init(%options);
39 }
40
41 sub run {
42 my ($self, %options) = @_;
43
44 my $response = $options{custom}->request_api( endpoint => '/api/v1/disks' );
45 my $disks = $response->{members};
46
47 $self->{disks} = [];
48
49 for my $disk (@{$disks}) {
50 push @{$self->{disks}}, {
51 id => $disk->{id},
52 position => $disk->{position},
53 size => $disk->{totalSizeMiB},
54 manufacturer => $disk->{manufacturer},
55 model => $disk->{model},
56 serial => $disk->{serialNumber}
57 };
58 $self->{output}->output_add(
59 long_msg => sprintf(
60 "[id: %s][position: %s][size: %s][manufacturer: %s][model: %s][serial: %s]",
61 $disk->{id},
62 $disk->{position},
63 $disk->{totalSizeMiB},
64 $disk->{manufacturer},
65 $disk->{model},
66 $disk->{serialNumber}
67 )
68 );
69 }
70
71 if (!defined($options{disco_show})) {
72 $self->{output}->output_add(severity => 'OK', short_msg => 'Disks:');
73 $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
74 }
75 }
76
77 sub disco_format {
78 my ($self, %options) = @_;
79
80 $self->{output}->add_disco_format(elements => [ 'id', 'position','size', 'manufacturer', 'model', 'serial' ]);
81 }
82
83 sub disco_show {
84 my ($self, %options) = @_;
85
86 $options{disco_show} = 1;
87 $self->run(%options);
88
89 for my $disk (@{$self->{disks}}) {
90 $self->{output}->add_disco_entry(
91 id => $disk->{id},
92 position => $disk->{position},
93 size => $disk->{size},
94 manufacturer => $disk->{manufacturer},
95 model => $disk->{model},
96 serial => $disk->{serial}
97 );
98 }
99 }
100
101 1;
102
103 __END__
104
105 =head1 MODE
106
107 List physical disks using the HPE Primera REST API.
108
109 =back
110
111 =cut