Debian Codegraph @

src/centreon/common/aruba/snmp/mode/memory.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 centreon::common::aruba::snmp::mode::memory;
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 instances => $self->{instance},
33 label => 'usage', nlabel => 'memory.usage.bytes',
34 unit => 'B',
35 value => $self->{result_values}->{used},
36 warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}, total => $self->{result_values}->{total}, cast_int => 1),
37 critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}, total => $self->{result_values}->{total}, cast_int => 1),
38 min => 0, max => $self->{result_values}->{total});
39 }
40
41 sub custom_usage_threshold {
42 my ($self, %options) = @_;
43
44 my $exit = $self->{perfdata}->threshold_check(
45 value => $self->{result_values}->{prct_used},
46 threshold => [
47 { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' },
48 { label => 'warning-' . $self->{thlabel}, exit_litteral => 'warning' }
49 ]
50 );
51 return $exit;
52 }
53
54 sub custom_usage_output {
55 my ($self, %options) = @_;
56
57 my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total});
58 my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used});
59 my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free});
60
61 my $msg = sprintf("Usage Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)",
62 $total_size_value . " " . $total_size_unit,
63 $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used},
64 $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free});
65 return $msg;
66 }
67
68 sub custom_usage_calc {
69 my ($self, %options) = @_;
70
71 $self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_sysExtMemorySize'} * 1024;
72 $self->{result_values}->{used} = $options{new_datas}->{$self->{instance} . '_sysExtMemoryUsed'} * 1024;
73 $self->{result_values}->{free} = $self->{result_values}->{total} - $self->{result_values}->{used};
74 $self->{result_values}->{prct_free} = $self->{result_values}->{free} * 100 / $self->{result_values}->{total};
75 $self->{result_values}->{prct_used} = $self->{result_values}->{used} * 100 / $self->{result_values}->{total};
76 return 0;
77 }
78
79 sub set_counters {
80 my ($self, %options) = @_;
81
82 $self->{maps_counters_type} = [
83 { name => 'memory', type => 1, cb_prefix_output => 'prefix_output',
84 message_multiple => 'All memory pools are ok' }
85 ];
86
87 $self->{maps_counters}->{memory} = [
88 { label => 'usage', set => {
89 key_values => [ { name => 'sysExtMemoryUsed' }, { name => 'sysExtMemorySize' } ],
90 closure_custom_calc => $self->can('custom_usage_calc'),
91 closure_custom_output => $self->can('custom_usage_output'),
92 closure_custom_perfdata => $self->can('custom_usage_perfdata'),
93 closure_custom_threshold_check => $self->can('custom_usage_threshold')
94 }
95 }
96 ];
97 }
98
99 sub prefix_output {
100 my ($self, %options) = @_;
101
102 return "Memory '" . $options{instance_value}->{display} . "' ";
103 }
104
105 sub new {
106 my ($class, %options) = @_;
107 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
108 bless $self, $class;
109
110 $options{options}->add_options(arguments => {});
111
112 return $self;
113 }
114
115 my $oid_wlsxSysExtMemoryEntry = '.1.3.6.1.4.1.14823.2.2.1.2.1.15.1';
116
117 my $mapping = {
118 sysExtMemorySize => { oid => '.1.3.6.1.4.1.14823.2.2.1.2.1.15.1.2' }, # in KB
119 sysExtMemoryUsed => { oid => '.1.3.6.1.4.1.14823.2.2.1.2.1.15.1.3' }, # in KB
120 };
121
122 sub manage_selection {
123 my ($self, %options) = @_;
124
125 my $snmp_result = $options{snmp}->get_table(
126 oid => $oid_wlsxSysExtMemoryEntry,
127 start => $mapping->{sysExtMemorySize}->{oid},
128 end => $mapping->{sysExtMemoryUsed}->{oid},
129 nothing_quit => 1
130 );
131
132 $self->{memory} = {};
133
134 foreach my $oid (keys %{$snmp_result}) {
135 next if ($oid !~ /^$mapping->{sysExtMemorySize}->{oid}\.(.*)/);
136 my $instance = $1;
137
138 my $result = $options{snmp}->map_instance(
139 mapping => $mapping,
140 results => $snmp_result,
141 instance => $instance
142 );
143
144 $self->{memory}->{$instance} = { %{$result}, display => $instance };
145 }
146
147 if (scalar(keys %{$self->{memory}}) <= 0) {
148 $self->{output}->add_option_msg(short_msg => "Cannot find memory informations");
149 $self->{output}->option_exit();
150 }
151 }
152
153 1;
154
155 __END__
156
157 =head1 MODE
158
159 Check memory usage (WLSX-SYSTEMEXT-MIB).
160
161 =over 8
162
163 =item B<--warning-usage>
164
165 Warning threshold in percent.
166
167 =item B<--critical-usage>
168
169 Critical threshold in percent.
170
171 =back
172
173 =cut
174