Debian Codegraph @

src/storage/hp/3par/ssh/mode/volumeusage.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::3par::ssh::mode::volumeusage;
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 return sprintf(
35 "Usage Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)",
36 $total_size_value . " " . $total_size_unit,
37 $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used},
38 $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free}
39 );
40 }
41
42 sub set_counters {
43 my ($self, %options) = @_;
44
45 $self->{maps_counters_type} = [
46 { name => 'volume', type => 1, cb_prefix_output => 'prefix_volume_output', message_multiple => 'All volumes are ok' },
47 ];
48
49 $self->{maps_counters}->{volume} = [
50 { label => 'usage', nlabel => 'volume.space.usage.bytes', set => {
51 key_values => [ { name => 'used' }, { name => 'free' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' }, { name => 'display' }, ],
52 closure_custom_output => $self->can('custom_usage_output'),
53 perfdatas => [
54 { template => '%d', min => 0, max => 'total', unit => 'B', cast_int => 1, label_extra_instance => 1, instance_use => 'display' }
55 ]
56 }
57 },
58 { label => 'usage-free', display_ok => 0, nlabel => 'volume.space.free.bytes', set => {
59 key_values => [ { name => 'free' }, { name => 'used' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' }, { name => 'display' }, ],
60 closure_custom_output => $self->can('custom_usage_output'),
61 perfdatas => [
62 { template => '%d', min => 0, max => 'total', unit => 'B', cast_int => 1, label_extra_instance => 1, instance_use => 'display' }
63 ]
64 }
65 },
66 { label => 'usage-prct', display_ok => 0, nlabel => 'volume.space.usage.percentage', set => {
67 key_values => [ { name => 'prct_used' }, { name => 'display' } ],
68 output_template => 'Used : %.2f %%',
69 perfdatas => [
70 { template => '%.2f', min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'display' }
71 ]
72 }
73 }
74 ];
75 }
76
77 sub new {
78 my ($class, %options) = @_;
79 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
80 bless $self, $class;
81
82 $options{options}->add_options(arguments => {
83 'filter-name:s' => { name => 'filter_name' }
84 });
85
86 return $self;
87 }
88
89 sub prefix_volume_output {
90 my ($self, %options) = @_;
91
92 return "Volume '" . $options{instance_value}->{display} . "' ";
93 }
94
95 sub manage_selection {
96 my ($self, %options) = @_;
97
98 my ($result, $exit) = $options{custom}->execute_command(commands => ['showvv -showcols Id,Name,VSize_MB,Snp_Rsvd_MB,Snp_Used_MB,Adm_Rsvd_MB,Adm_Used_MB,Usr_Rsvd_MB,Usr_Used_MB']);
99
100 # Id Name VSize_MB Snp_Rsvd_MB Snp_Used_MB Adm_Rsvd_MB Adm_Used_MB Usr_Rsvd_MB Usr_Used_MB
101 #2056 .srdata 81920 0 0 0 0 81920 81920
102 # 0 admin 10240 0 0 0 0 10240 10240
103 # 494 DFS_DATA01 4608000 0 0 2560 2032 3156864 3147727
104 # 495 DFS_DATA02 1126400 0 0 1024 612 979072 966739
105 # 496 DFS_DATA03 16777216 0 0 10240 9576 15281920 15281185
106
107 $self->{volume} = {};
108 my @lines = split /\n/, $result;
109 foreach (@lines) {
110 next if (!/^\s*\d+\s+(\S+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/);
111 my ($name, $total, $snap_used, $adm_used, $usr_used) = ($1, $2 * 1024 * 1024, $4 * 1024 * 1024, $6 * 1024 * 1024, $8 * 1024 * 1024);
112
113 if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
114 $name !~ /$self->{option_results}->{filter_name}/) {
115 $self->{output}->output_add(long_msg => "skipping volume '" . $name . "': no matching filter.", debug => 1);
116 next;
117 }
118
119 my $used = $snap_used + $adm_used + $usr_used;
120 $self->{volume}->{$name} = {
121 display => $name,
122 total => $total,
123 used => $used,
124 free => ($total - $used) >= 0 ? ($total - $used) : 0,
125 prct_used => $used * 100 / $total,
126 prct_free => (100 - ($used * 100 / $total) >= 0) ? (100 - ($used * 100 / $total)) : 0
127 };
128 }
129
130 if (scalar(keys %{$self->{volume}}) <= 0) {
131 $self->{output}->add_option_msg(short_msg => "No volume found.");
132 $self->{output}->option_exit();
133 }
134 }
135
136 1;
137
138 __END__
139
140 =head1 MODE
141
142 Check volume usages.
143
144 =over 8
145
146 =item B<--filter-counters>
147
148 Only display some counters (regexp can be used).
149 Example: --filter-counters='^usage$'
150
151 =item B<--filter-name>
152
153 Filter volume name (can be a regexp).
154
155 =item B<--warning-*> B<--critical-*>
156
157 Thresholds.
158 Can be: 'usage' (B), 'usage-free' (B), 'usage-prct' (%).
159
160 =back
161
162 =cut