Debian Codegraph @

src/network/nortel/standard/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::nortel::standard::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 '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 prefix_memory_output {
42 my ($self, %options) = @_;
43
44 return "Memory '" . $options{instance_value}->{display} . "' ";
45 }
46
47 sub set_counters {
48 my ($self, %options) = @_;
49
50 $self->{maps_counters_type} = [
51 { name => 'memory', type => 1, cb_prefix_output => 'prefix_memory_output', message_multiple => 'All memory usages are ok', skipped_code => { -10 => 1 } }
52 ];
53
54 $self->{maps_counters}->{memory} = [
55 { label => 'usage', nlabel => 'memory.usage.bytes', set => {
56 key_values => [ { name => 'used' }, { name => 'free' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' }, { name => 'display' } ],
57 closure_custom_output => $self->can('custom_usage_output'),
58 perfdatas => [
59 { template => '%d', min => 0, max => 'total', unit => 'B', cast_int => 1, label_extra_instance => 1 }
60 ]
61 }
62 },
63 { label => 'usage-free', display_ok => 0, nlabel => 'memory.free.bytes', display_ok => 0, set => {
64 key_values => [ { name => 'free' }, { name => 'used' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' }, { name => 'display' } ],
65 closure_custom_output => $self->can('custom_usage_output'),
66 perfdatas => [
67 { template => '%d', min => 0, max => 'total', unit => 'B', cast_int => 1, label_extra_instance => 1 }
68 ]
69 }
70 },
71 { label => 'usage-prct', nlabel => 'memory.usage.percentage', display_ok => 0, set => {
72 key_values => [ { name => 'prct_used' }, { name => 'used' }, { name => 'free' }, { name => 'prct_free' }, { name => 'total' }, { name => 'display' } ],
73 closure_custom_output => $self->can('custom_usage_output'),
74 perfdatas => [
75 { template => '%.2f', min => 0, max => 100, unit => '%', label_extra_instance => 1 }
76 ]
77 }
78 }
79 ];
80 }
81
82 sub new {
83 my ($class, %options) = @_;
84 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
85 bless $self, $class;
86
87 $options{options}->add_options(arguments => {});
88
89 return $self;
90 }
91
92 my $mapping = {
93 s5ChasUtilMemoryAvailable => { oid => '.1.3.6.1.4.1.45.1.6.3.8.1.1.9' }
94 };
95 my $mapping_khi = {
96 rcKhiSlotMemUsed => { oid => '.1.3.6.1.4.1.2272.1.85.10.1.1.6' }, # KB
97 rcKhiSlotMemFree => { oid => '.1.3.6.1.4.1.2272.1.85.10.1.1.7' } # KB
98 };
99 my $oid_rcKhiSlotPerfEntry = '.1.3.6.1.4.1.2272.1.85.10.1.1';
100
101 sub check_khi {
102 my ($self, %options) = @_;
103
104 my $snmp_result = $options{snmp}->get_table(
105 oid => $oid_rcKhiSlotPerfEntry,
106 start => $mapping_khi->{rcKhiSlotMemUsed}->{oid},
107 end => $mapping_khi->{rcKhiSlotMemFree}->{oid},
108 nothing_quit => 1
109 );
110
111 foreach (keys %$snmp_result) {
112 next if (! /^$mapping_khi->{rcKhiSlotMemUsed}->{oid}\.(\d+)$/);
113 my $instance = $1;
114 my $result = $options{snmp}->map_instance(mapping => $mapping_khi, results => $snmp_result, instance => $instance);
115
116 my $total = ($result->{rcKhiSlotMemUsed} * 1024) + ($result->{rcKhiSlotMemFree} * 1024);
117 $self->{memory}->{'slot_' . $1} = {
118 display => 'slot_' . $1,
119 used => $result->{rcKhiSlotMemUsed} * 1024,
120 free => $result->{rcKhiSlotMemFree} * 1024,
121 prct_used => ($result->{rcKhiSlotMemUsed} * 1024 * 100 / $total),
122 prct_free => ($result->{rcKhiSlotMemFree} * 1024 * 100 / $total),
123 total => $total
124 };
125 }
126 }
127
128 sub manage_selection {
129 my ($self, %options) = @_;
130
131 my $snmp_result = $options{snmp}->get_table(
132 oid => $mapping->{s5ChasUtilMemoryAvailable}->{oid}
133 );
134
135 $self->{memory} = {};
136 foreach my $oid (keys %$snmp_result) {
137 next if ($oid !~ /^$mapping->{s5ChasUtilMemoryAvailable}->{oid}\.(.*)/);
138 my $instance = $1;
139 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance);
140
141 $self->{memory}->{$instance} = {
142 display => $instance,
143 prct_used => 100 - $result->{s5ChasUtilMemoryAvailable}
144 };
145 }
146
147 if (scalar(keys %{$self->{memory}}) <= 0) {
148 $self->check_khi(snmp => $options{snmp});
149 }
150 }
151
152 1;
153
154 __END__
155
156 =head1 MODE
157
158 Check memory usages.
159
160 =over 8
161
162 =item B<--warning-*> B<--critical-*>
163
164 Thresholds.
165 Can be: 'usage' (B), 'usage-free' (B), 'usage-prct' (%).
166
167 =back
168
169 =cut