Debian Codegraph @

src/network/cyberoam/snmp/mode/storage.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 network::cyberoam::snmp::mode::storage;
22
23 use base qw(centreon::plugins::templates::counter);
24
25 use strict;
26 use warnings;
27
28 sub custom_usage_perfdata {
29 my ($self, %options) = @_;
30
31 $self->{output}->perfdata_add(
32 label => 'used', unit => 'B',
33 value => $self->{result_values}->{used},
34 warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, total => $self->{result_values}->{total}, cast_int => 1),
35 critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, total => $self->{result_values}->{total}, cast_int => 1),
36 min => 0, max => $self->{result_values}->{total}
37 );
38 }
39
40 sub custom_usage_output {
41 my ($self, %options) = @_;
42
43 my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total});
44 my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used});
45 my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free});
46
47 return sprintf(
48 "Storage Usage Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)",
49 $total_size_value . " " . $total_size_unit,
50 $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used},
51 $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free}
52 );
53 }
54
55 sub custom_usage_calc {
56 my ($self, %options) = @_;
57
58 $self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_total'};
59 $self->{result_values}->{used} = $options{new_datas}->{$self->{instance} . '_used'};
60 $self->{result_values}->{free} = $options{new_datas}->{$self->{instance} . '_total'} - $options{new_datas}->{$self->{instance} . '_used'};
61 $self->{result_values}->{prct_free} = $self->{result_values}->{free} * 100 / $self->{result_values}->{total};
62 $self->{result_values}->{prct_used} = $self->{result_values}->{used} * 100 / $self->{result_values}->{total};
63 return 0;
64 }
65
66 sub set_counters {
67 my ($self, %options) = @_;
68
69 $self->{maps_counters_type} = [
70 { name => 'storage', type => 0 }
71 ];
72
73 $self->{maps_counters}->{storage} = [
74 { label => 'usage', set => {
75 key_values => [ { name => 'used' }, { name => 'total' } ],
76 closure_custom_calc => $self->can('custom_usage_calc'),
77 closure_custom_output => $self->can('custom_usage_output'),
78 closure_custom_perfdata => $self->can('custom_usage_perfdata'),
79 threshold_use => 'prct_used'
80 }
81 }
82 ];
83 }
84
85 sub new {
86 my ($class, %options) = @_;
87 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
88 bless $self, $class;
89
90 $options{options}->add_options(arguments => {
91 });
92
93 return $self;
94 }
95
96 sub add_counters {
97 my ($self, %options) = @_;
98
99 return if (!defined($options{result}->{disk_total}));
100
101 $self->{storage} = {
102 used => $options{result}->{disk_used_prct} * $options{result}->{disk_total} * 1024 * 1024 / 100,
103 total => $options{result}->{disk_total} * 1024 * 1024
104 };
105 }
106
107 sub manage_selection {
108 my ($self, %options) = @_;
109
110 my $mapping = {
111 v17 => {
112 disk_total => { oid => '.1.3.6.1.4.1.21067.2.1.2.3.1' }, # diskCapacity - MB
113 disk_used_prct => { oid => '.1.3.6.1.4.1.21067.2.1.2.3.2' } # diskPercentUsage
114 },
115 v18 => {
116 disk_total => { oid => '.1.3.6.1.4.1.2604.5.1.2.4.1' }, # sfosDiskCapacity - MB
117 disk_used_prct => { oid => '.1.3.6.1.4.1.2604.5.1.2.4.2' } # sfosDiskPercentUsage
118 }
119 };
120
121 my $snmp_result = $options{snmp}->get_leef(
122 oids => [ map($_->{oid} . '.0', values(%{$mapping->{v17}}), values(%{$mapping->{v18}})) ],
123 nothing_quit => 1
124 );
125
126 my $result = $options{snmp}->map_instance(mapping => $mapping->{v17}, results => $snmp_result, instance => 0);
127 $self->add_counters(result => $result);
128 $result = $options{snmp}->map_instance(mapping => $mapping->{v18}, results => $snmp_result, instance => 0);
129 $self->add_counters(result => $result);
130 }
131
132 1;
133
134 __END__
135
136 =head1 MODE
137
138 Check storage usage.
139
140 =over 8
141
142 =item B<--warning-usage>
143
144 Warning threshold (in percent).
145
146 =item B<--critical-usage>
147
148 Critical threshold (in percent).
149
150 =back
151
152 =cut