Debian Codegraph @

src/network/moxa/switch/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::moxa::switch::snmp::mode::memory;
22
23 use base qw(centreon::plugins::templates::counter);
24
25 use strict;
26 use warnings;
27
28 sub custom_memory_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 "memory 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 => 'global', type => 0, skipped_code => { -10 => 1 } }
47 ];
48
49 $self->{maps_counters}->{global} = [
50 { label => 'memory-usage', nlabel => 'memory.usage.bytes', set => {
51 key_values => [ { name => 'used' }, { name => 'free' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ],
52 closure_custom_output => $self->can('custom_memory_usage_output'),
53 perfdatas => [
54 { template => '%d', min => 0, max => 'total', unit => 'B', cast_int => 1 }
55 ]
56 }
57 },
58 { label => 'memory-usage-free', display_ok => 0, nlabel => 'memory.free.bytes', set => {
59 key_values => [ { name => 'free' }, { name => 'used' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ],
60 closure_custom_output => $self->can('custom_memory_usage_output'),
61 perfdatas => [
62 { template => '%d', min => 0, max => 'total', unit => 'B', cast_int => 1 }
63 ]
64 }
65 },
66 { label => 'memory-usage-prct', display_ok => 0, nlabel => 'memory.usage.percentage', set => {
67 key_values => [ { name => 'prct_used' }, { name => 'free' }, { name => 'used' }, { name => 'prct_free' }, { name => 'total' } ],
68 closure_custom_output => $self->can('custom_memory_usage_output'),
69 perfdatas => [
70 { template => '%.2f', min => 0, max => 100, unit => '%' }
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
84 return $self;
85 }
86
87 my $mapping = {
88 iks6726a => {
89 total => { oid => '.1.3.6.1.4.1.8691.7.116.1.56' },
90 free => { oid => '.1.3.6.1.4.1.8691.7.116.1.57' },
91 used => { oid => '.1.3.6.1.4.1.8691.7.116.1.58' }
92 },
93 eds405a => {
94 total => { oid => '.1.3.6.1.4.1.8691.7.6.1.56' },
95 free => { oid => '.1.3.6.1.4.1.8691.7.6.1.57' },
96 used => { oid => '.1.3.6.1.4.1.8691.7.6.1.58' }
97 },
98 edsp506e => {
99 total => { oid => '.1.3.6.1.4.1.8691.7.162.1.56' },
100 free => { oid => '.1.3.6.1.4.1.8691.7.162.1.57' },
101 used => { oid => '.1.3.6.1.4.1.8691.7.162.1.58' }
102 },
103 edsp506a => {
104 total => { oid => '.1.3.6.1.4.1.8691.7.41.1.56' },
105 free => { oid => '.1.3.6.1.4.1.8691.7.41.1.57' },
106 used => { oid => '.1.3.6.1.4.1.8691.7.41.1.58' }
107 }
108 };
109
110 sub manage_selection {
111 my ($self, %options) = @_;
112
113 my $snmp_result = $options{snmp}->get_leef(
114 oids => [
115 map(
116 $_->{oid} . '.0',
117 values(%{$mapping->{iks6726a}}),
118 values(%{$mapping->{eds405a}}),
119 values(%{$mapping->{edsp506e}}),
120 values(%{$mapping->{edsp506a}})
121 )
122 ],
123 nothing_quit => 1
124 );
125
126 foreach (keys %$mapping) {
127 my $result = $options{snmp}->map_instance(mapping => $mapping->{$_}, results => $snmp_result, instance => 0);
128 next if (!defined($result->{total}));
129 $self->{global} = $result;
130 $self->{global}->{prct_used} = $result->{used} * 100 / $result->{total};
131 $self->{global}->{prct_free} = $result->{free} * 100 / $result->{total};
132 last;
133 }
134 }
135
136 1;
137
138 __END__
139
140 =head1 MODE
141
142 Check memory usage
143
144 =over 8
145
146 =item B<--warning-*> B<--critical-*>
147
148 Thresholds.
149 Can be: 'memory-usage-prct', 'memory-usage', 'memory-usage-free',
150
151 =back
152
153 =cut