Debian Codegraph @

src/storage/netapp/ontap/snmp/mode/listfilesys.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::netapp::ontap::snmp::mode::listfilesys;
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 'filter-name:s' => { name => 'filter_name' },
35 'filter-type:s' => { name => 'filter_type' },
36 'skip-total-zero' => { name => 'skip_total_zero' }
37 });
38
39 return $self;
40 }
41
42 sub check_options {
43 my ($self, %options) = @_;
44 $self->SUPER::init(%options);
45 }
46
47 my %map_types = (
48 1 => 'traditionalVolume',
49 2 => 'flexibleVolume',
50 3 => 'aggregate',
51 4 => 'stripedAggregate',
52 5 => 'stripedVolume'
53 );
54
55 my $mapping = {
56 dfFileSys => { oid => '.1.3.6.1.4.1.789.1.5.4.1.2' },
57 dfKBytesTotal => { oid => '.1.3.6.1.4.1.789.1.5.4.1.3' },
58 dfType => { oid => '.1.3.6.1.4.1.789.1.5.4.1.23', map => \%map_types },
59 df64TotalKBytes => { oid => '.1.3.6.1.4.1.789.1.5.4.1.29' },
60 dfVserver => { oid => '.1.3.6.1.4.1.789.1.5.4.1.34' },
61 };
62
63 sub manage_selection {
64 my ($self, %options) = @_;
65
66 my $snmp_result = $options{snmp}->get_multiple_table(
67 oids => [
68 { oid => $mapping->{dfFileSys}->{oid} },
69 { oid => $mapping->{dfKBytesTotal}->{oid} },
70 { oid => $mapping->{dfType}->{oid} },
71 { oid => $mapping->{df64TotalKBytes}->{oid} },
72 { oid => $mapping->{dfVserver}->{oid} },
73 ],
74 return_type => 1,
75 nothing_quit => 1
76 );
77
78 $self->{fs} = {};
79 foreach my $oid (keys %$snmp_result) {
80 next if ($oid !~ /^$mapping->{dfFileSys}->{oid}\.(.*)$/);
81 my $instance = $1;
82 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance);
83
84 if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
85 $result->{dfFileSys} !~ /$self->{option_results}->{filter_name}/) {
86 $self->{output}->output_add(long_msg => "skipping '" . $result->{dfFileSys} . "': no matching filter.", debug => 1);
87 next;
88 }
89 if (defined($self->{option_results}->{filter_type}) && $self->{option_results}->{filter_type} ne '' &&
90 $result->{dfType} !~ /$self->{option_results}->{filter_type}/) {
91 $self->{output}->output_add(long_msg => "skipping '" . $result->{dfFileSys} . "': no matching filter.", debug => 1);
92 next;
93 }
94
95 $self->{fs}->{$instance} = {
96 name => $result->{dfFileSys},
97 total => defined($result->{df64TotalKBytes}) ? $result->{df64TotalKBytes} * 1024 : $result->{dfKBytesTotal} * 1024,
98 type => $result->{dfType},
99 vserver => $result->{dfVserver}
100 };
101 }
102 }
103
104 sub run {
105 my ($self, %options) = @_;
106
107 $self->manage_selection(%options);
108 foreach my $instance (sort keys %{$self->{fs}}) {
109 next if (defined($self->{option_results}->{skip_total_zero}) && $self->{fs}->{$instance}->{total} == 0);
110
111 $self->{output}->output_add(long_msg => '[instance = ' . $instance . '] ' .
112 "[name = '" . $self->{fs}->{$instance}->{name} . "'] " .
113 "[type = '" . $self->{fs}->{$instance}->{type} . "'] " .
114 "[vserver = '" . $self->{fs}->{$instance}->{vserver} . "'] " .
115 "[total = '" . $self->{fs}->{$instance}->{total} . "']");
116 }
117
118 $self->{output}->output_add(severity => 'OK',
119 short_msg => 'List filesys:');
120 $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
121 $self->{output}->exit();
122 }
123
124 sub disco_format {
125 my ($self, %options) = @_;
126
127 $self->{output}->add_disco_format(elements => ['name', 'total', 'type', 'vserver']);
128 }
129
130 sub disco_show {
131 my ($self, %options) = @_;
132
133 $self->manage_selection(%options);
134 foreach my $instance (sort keys %{$self->{fs}}) {
135 next if (defined($self->{option_results}->{skip_total_zero}) && $self->{fs}->{$instance}->{total} == 0);
136
137 $self->{output}->add_disco_entry(%{$self->{fs}->{$instance}});
138 }
139 }
140
141 1;
142
143 __END__
144
145 =head1 MODE
146
147 List filesystems (volumes and aggregates also).
148
149 =over 8
150
151 =item B<--filter-name>
152
153 Filter the filesystem name.
154
155 =item B<--filter-type>
156
157 Filter filesystem type (a regexp. Example: 'flexibleVolume|aggregate').
158
159 =item B<--skip-total-zero>
160
161 Don't display filesys with total equals 0.
162
163 =back
164
165 =cut
166