Debian Codegraph @

src/storage/buffalo/terastation/snmp/mode/arrayusage.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::buffalo::terastation::snmp::mode::arrayusage;
22
23 use base qw(centreon::plugins::templates::counter);
24
25 use strict;
26 use warnings;
27
28 sub custom_usage_output {
29 my ($self, %options) = @_;
30
31 my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total});
32 my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used});
33 my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free});
34
35 return sprintf(
36 "Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)",
37 $total_size_value . " " . $total_size_unit,
38 $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used},
39 $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free}
40 );
41 }
42
43 sub custom_usage_calc {
44 my ($self, %options) = @_;
45
46 $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'};
47 $self->{result_values}->{prct_used} = $options{new_datas}->{$self->{instance} . '_nasArrayUsed'};
48 $self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_nasArrayCapacity'} * 1024 * 1024 * 1024;
49 $self->{result_values}->{used} = int($self->{result_values}->{prct_used} * $self->{result_values}->{total} / 100);
50 $self->{result_values}->{free} = $self->{result_values}->{total} - $self->{result_values}->{used};
51 $self->{result_values}->{prct_free} = 100 - $self->{result_values}->{prct_used};
52 return 0;
53 }
54
55 sub set_counters {
56 my ($self, %options) = @_;
57
58 $self->{maps_counters_type} = [
59 { name => 'array', type => 1, cb_prefix_output => 'prefix_array_output', message_multiple => 'All arrays are ok' }
60 ];
61
62 $self->{maps_counters}->{array} = [
63 { label => 'usage', nlabel => 'array.space.usage.bytes', set => {
64 key_values => [ { name => 'display' }, { name => 'nasArrayCapacity' }, { name => 'nasArrayUsed' } ],
65 closure_custom_calc => $self->can('custom_usage_calc'),
66 closure_custom_output => $self->can('custom_usage_output'),
67 closure_custom_perfdata => $self->can('custom_usage_perfdata'),
68 threshold_use => 'prct_used',
69 perfdatas => [
70 { label => 'used', value => 'used', template => '%s',
71 unit => 'B', min => 0, max => 'total', cast_int => 1 }
72 ]
73 }
74 }
75 ];
76 }
77
78 sub new {
79 my ($class, %options) = @_;
80 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
81 bless $self, $class;
82
83 $options{options}->add_options(arguments => {
84 'filter-name:s' => { name => 'filter_name' }
85 });
86
87 return $self;
88 }
89
90 sub prefix_array_output {
91 my ($self, %options) = @_;
92
93 return "Array '" . $options{instance_value}->{display} . "' ";
94 }
95
96 my $mapping = {
97 nasArrayCapacity => { oid => '.1.3.6.1.4.1.5227.27.1.3.1.3' }, # in GB
98 nasArrayUsed => { oid => '.1.3.6.1.4.1.5227.27.1.3.1.4' } # in %
99 };
100
101 sub manage_selection {
102 my ($self, %options) = @_;
103
104 my $oid_nasArrayEntry = '.1.3.6.1.4.1.5227.27.1.3.1';
105 my $snmp_result = $options{snmp}->get_table(
106 oid => $oid_nasArrayEntry,
107 start => $mapping->{nasArrayCapacity}->{oid},
108 end => $mapping->{nasArrayUsed}->{oid},
109 nothing_quit => 1
110 );
111
112 $self->{array} = {};
113 foreach my $oid (keys %{$snmp_result}) {
114 next if ($oid !~ /^$mapping->{nasArrayCapacity}->{oid}\.(.*)/);
115 my $instance = $1;
116 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance);
117
118 if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
119 $instance !~ /$self->{option_results}->{filter_name}/) {
120 $self->{output}->output_add(long_msg => "skipping '" . $instance . "': no matching array name.", debug => 1);
121 next;
122 }
123 if ($result->{nasArrayUsed} == -1) {
124 $self->{output}->output_add(long_msg => "skipping '" . $instance . "': array not used.", debug => 1);
125 next;
126 }
127
128 $self->{array}->{$instance} = { display => $instance, %$result };
129 }
130
131 if (scalar(keys %{$self->{array}}) <= 0) {
132 $self->{output}->add_option_msg(short_msg => "No array found.");
133 $self->{output}->option_exit();
134 }
135 }
136
137 1;
138
139 __END__
140
141 =head1 MODE
142
143 Check array usages.
144
145 =over 8
146
147 =item B<--filter-name>
148
149 Filter by name (regexp can be used).
150
151 =item B<--warning-usage>
152
153 Warning threshold (in percent).
154
155 =item B<--critical-usage>
156
157 Critical threshold (in percent).
158
159 =back
160
161 =cut