Debian Codegraph @

src/os/hpux/local/mode/liststorages.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 os::hpux::local::mode::liststorages;
22
23 use base qw(centreon::plugins::mode);
24
25 use strict;
26 use warnings;
27
28 sub new {
29 my ($class, %options) = @_;
30 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
31 bless $self, $class;
32
33 $options{options}->add_options(arguments => {});
34
35 return $self;
36 }
37
38 sub check_options {
39 my ($self, %options) = @_;
40 $self->SUPER::init(%options);
41 }
42
43 sub manage_selection {
44 my ($self, %options) = @_;
45
46 my ($stdout) = $options{custom}->execute_command(
47 command => 'bdf',
48 command_options => '2>&1',
49 no_quit => 1
50 );
51
52 my $results = {};
53 my @lines = split(/\n/, $stdout);
54 # Header not needed
55 shift @lines;
56 while (my $line = shift @lines) {
57 # When the line is too long, the FS name is printed on a separated line
58 if ($line !~ /^(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)/) {
59 $line .= " " . shift(@lines);
60 }
61 next if ($line !~ /^(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)/);
62 my ($fs, $size, $mount) = ($1, $2 * 1024, $6);
63
64 $results->{$mount} = { fs => $fs, size => $size };
65 }
66
67 return $results;
68 }
69
70 sub run {
71 my ($self, %options) = @_;
72
73 my $results = $self->manage_selection(custom => $options{custom});
74 foreach my $name (sort(keys %$results)) {
75 $self->{output}->output_add(
76 long_msg => sprintf(
77 '[name: %s][fs: %s][size: %s]',
78 $name,
79 $results->{$name}->{fs},
80 $results->{$name}->{size}
81 )
82 );
83 }
84
85 $self->{output}->output_add(
86 severity => 'OK',
87 short_msg => 'List storages:'
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 => ['name', 'fs', 'size']);
97 }
98
99 sub disco_show {
100 my ($self, %options) = @_;
101
102 my $results = $self->manage_selection(custom => $options{custom});
103 foreach my $name (sort(keys %$results)) {
104 $self->{output}->add_disco_entry(
105 name => $name,
106 fs => $results->{$name}->{fs},
107 size => $results->{$name}->{size}
108 );
109 }
110 }
111
112 1;
113
114 __END__
115
116 =head1 MODE
117
118 List storages.
119
120 Command used: bdf 2>&1
121
122 =over 8
123
124 =back
125
126 =cut