Debian Codegraph @

src/network/ruckus/ap/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 network::ruckus::ap::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 if ($self->{result_values}->{total} > 0) {
32 $self->{output}->perfdata_add(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 } else {
38 $self->{output}->perfdata_add(label => 'used', unit => '%',
39 value => $self->{result_values}->{prct_used},
40 warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}),
41 critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}),
42 min => 0, max => 100);
43 }
44 }
45
46 sub custom_usage_threshold {
47 my ($self, %options) = @_;
48
49 my $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{prct_used}, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{label}, exit_litteral => 'warning' } ]);
50 return $exit;
51 }
52
53 sub custom_usage_output {
54 my ($self, %options) = @_;
55
56 my $msg = 'Memory Used: ' . $self->{result_values}->{prct_used} . '%';
57 if ($self->{result_values}->{total} > 0) {
58 my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total});
59 my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used});
60 my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free});
61
62 $msg = sprintf("Memory Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)",
63 $total_size_value . " " . $total_size_unit,
64 $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used},
65 $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free});
66 }
67 return $msg;
68 }
69
70 sub custom_usage_calc {
71 my ($self, %options) = @_;
72
73 $self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_total'};
74 $self->{result_values}->{prct_used} = $options{new_datas}->{$self->{instance} . '_prct_used'};
75
76 if ($self->{result_values}->{total} > 0) {
77 $self->{result_values}->{used} = int($self->{result_values}->{prct_used} * $self->{result_values}->{total} / 100);
78 $self->{result_values}->{free} = $self->{result_values}->{total} - $self->{result_values}->{used};
79 $self->{result_values}->{prct_free} = 100 - $self->{result_values}->{prct_used};
80 }
81 return 0;
82 }
83
84 sub set_counters {
85 my ($self, %options) = @_;
86
87 $self->{maps_counters_type} = [
88 { name => 'memory', type => 0 }
89 ];
90
91 $self->{maps_counters}->{memory} = [
92 { label => 'usage', set => {
93 key_values => [ { name => 'prct_used' }, { name => 'total' } ],
94 closure_custom_calc => $self->can('custom_usage_calc'),
95 closure_custom_output => $self->can('custom_usage_output'),
96 closure_custom_perfdata => $self->can('custom_usage_perfdata'),
97 closure_custom_threshold_check => $self->can('custom_usage_threshold'),
98 }
99 },
100 ];
101 }
102
103 sub new {
104 my ($class, %options) = @_;
105 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
106 bless $self, $class;
107
108 $options{options}->add_options(arguments =>
109 {
110 });
111
112 return $self;
113 }
114
115 sub manage_selection {
116 my ($self, %options) = @_;
117
118 my $oid_ruckusSystemMemoryUtil = '.1.3.6.1.4.1.25053.1.1.11.1.1.1.2.0';
119 my $oid_ruckusSystemMemSize = '.1.3.6.1.4.1.25053.1.1.11.1.1.1.10.0';
120 my $oid_ruckusUnleashedSystemStatsMemoryUtil = '.1.3.6.1.4.1.25053.1.15.1.1.1.15.14.0';
121 my $snmp_result = $options{snmp}->get_leef(oids => [$oid_ruckusSystemMemoryUtil, $oid_ruckusSystemMemSize, $oid_ruckusUnleashedSystemStatsMemoryUtil], nothing_quit => 1);
122
123 $self->{memory} = {
124 prct_used => defined($snmp_result->{$oid_ruckusSystemMemoryUtil}) ? $snmp_result->{$oid_ruckusSystemMemoryUtil} : $snmp_result->{$oid_ruckusUnleashedSystemStatsMemoryUtil},
125 total => defined($snmp_result->{$oid_ruckusSystemMemSize}) ? $snmp_result->{$oid_ruckusSystemMemSize} : 0,
126 };
127 }
128
129 1;
130
131 __END__
132
133 =head1 MODE
134
135 Check memory usage.
136
137 =over 8
138
139 =item B<--warning-usage>
140
141 Warning threshold (in percent).
142
143 =item B<--critical-usage>
144
145 Critical threshold (in percent).
146
147 =back
148
149 =cut