Debian Codegraph @

src/network/raisecom/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::raisecom::snmp::mode::memory;
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 return sprintf(
32 'Memory total: %s %s used: %s %s (%.2f%%) free: %s %s (%.2f%%)',
33 $self->{perfdata}->change_bytes(value => $self->{result_values}->{total}),
34 $self->{perfdata}->change_bytes(value => $self->{result_values}->{used}),
35 $self->{result_values}->{prct_used},
36 $self->{perfdata}->change_bytes(value => $self->{result_values}->{free}),
37 $self->{result_values}->{prct_free}
38 );
39 }
40
41 sub set_counters {
42 my ($self, %options) = @_;
43
44 $self->{maps_counters_type} = [
45 { name => 'memory', type => 0, skipped_code => { -10 => 1 } }
46 ];
47
48 $self->{maps_counters}->{memory} = [
49 { label => 'usage', nlabel => 'memory.usage.bytes', set => {
50 key_values => [ { name => 'used' }, { name => 'free' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ],
51 closure_custom_output => $self->can('custom_usage_output'),
52 perfdatas => [
53 { template => '%d', min => 0, max => 'total', unit => 'B', cast_int => 1 }
54 ]
55 }
56 },
57 { label => 'usage-free', display_ok => 0, nlabel => 'memory.free.bytes', set => {
58 key_values => [ { name => 'free' }, { name => 'used' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ],
59 closure_custom_output => $self->can('custom_usage_output'),
60 perfdatas => [
61 { template => '%d', min => 0, max => 'total', unit => 'B', cast_int => 1 }
62 ]
63 }
64 },
65 { label => 'usage-prct', display_ok => 0, nlabel => 'memory.usage.percentage', set => {
66 key_values => [ { name => 'prct_used' }, { name => 'used' }, { name => 'free' }, { name => 'prct_free' }, { name => 'total' } ],
67 closure_custom_output => $self->can('custom_usage_output'),
68 perfdatas => [
69 { template => '%.2f', min => 0, max => 100, unit => '%' }
70 ]
71 }
72 }
73 ];
74 }
75
76 sub new {
77 my ($class, %options) = @_;
78 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
79 bless $self, $class;
80
81 return $self;
82 }
83
84 sub manage_selection {
85 my ($self, %options) = @_;
86 $self->{snmp} = $options{snmp};
87
88 my $oid_raisecomAvailableMemory = '.1.3.6.1.4.1.8886.1.1.3.2.0';
89 my $oid_raisecomTotalMemory = '.1.3.6.1.4.1.8886.1.1.3.1.0';
90 my $oid_PON_raisecomAvailableMemory = '.1.3.6.1.4.1.8886.18.1.7.3.1.1.2.1.0';
91 my $oid_PON_raisecomTotalMemory = '.1.3.6.1.4.1.8886.18.1.7.3.1.1.1.1.0';
92
93 my $oids = [$oid_raisecomAvailableMemory, $oid_raisecomTotalMemory, $oid_PON_raisecomAvailableMemory, $oid_PON_raisecomTotalMemory];
94
95 my $result = $self->{snmp}->get_leef(oids => $oids, nothing_quit => 1);
96
97 my $free_size = defined($result->{$oid_raisecomAvailableMemory}) ? $result->{$oid_raisecomAvailableMemory} : $result->{$oid_PON_raisecomAvailableMemory};
98 my $total_size = defined($result->{$oid_raisecomTotalMemory}) ? $result->{$oid_raisecomTotalMemory} : $result->{$oid_PON_raisecomTotalMemory};
99 my $used_size = $total_size - $free_size;
100
101 my $prct_used = $used_size * 100 / $total_size;
102 my $prct_free = 100 - $prct_used;
103
104 my ($total_value, $total_unit) = $self->{perfdata}->change_bytes(value => $total_size);
105 my ($used_value, $used_unit) = $self->{perfdata}->change_bytes(value => $used_size);
106 my ($free_value, $free_unit) = $self->{perfdata}->change_bytes(value => $free_size);
107
108 $self->{memory} = {
109 total => $total_size,
110 used => $used_size,
111 free => $free_size,
112 prct_used => $prct_used,
113 prct_free => $prct_free
114 };
115 }
116
117 1;
118
119 __END__
120
121 =head1 MODE
122
123 Check memory usage.
124
125 =over 8
126
127 =item B<--warning-*> B<--critical-*>
128
129 Thresholds.
130 Can be: 'usage' (B), 'usage-free' (B), 'usage-prct' (%).
131
132 =back
133
134 =cut