Debian Codegraph @

src/centreon/common/force10/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::force10::snmp::mode::memory;
22
23 use base qw(centreon::plugins::templates::counter);
24
25 use strict;
26 use warnings;
27
28 sub prefix_memory_output {
29 my ($self, %options) = @_;
30
31 return "Memory '" . $options{instance_value}->{display} . "' usage ";
32 }
33
34 sub set_counters {
35 my ($self, %options) = @_;
36
37 $self->{maps_counters_type} = [
38 { name => 'memory', type => 1, cb_prefix_output => 'prefix_memory_output', message_multiple => 'All memory usages are ok' }
39 ];
40
41 $self->{maps_counters}->{memory} = [
42 { label => 'usage', nlabel => 'memory.usage.percentage', set => {
43 key_values => [ { name => 'usage' }, { name => 'display' } ],
44 output_template => '%.2f %%', output_error_template => "%s",
45 perfdatas => [
46 { label => 'used', template => '%.2f',
47 unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' }
48 ]
49 }
50 }
51 ];
52 }
53
54 sub new {
55 my ($class, %options) = @_;
56 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
57 bless $self, $class;
58
59 $options{options}->add_options(arguments => {
60 });
61
62 return $self;
63 }
64
65 my $mapping = {
66 sseries => {
67 mem_used => { oid => '.1.3.6.1.4.1.6027.3.10.1.2.9.1.5' } # chStackUnitMemUsageUtil
68 },
69 mseries => {
70 mem_used => { oid => '.1.3.6.1.4.1.6027.3.19.1.2.8.1.5' } # chStackUnitMemUsageUtil
71 },
72 zseries => {
73 mem_used => { oid => '.1.3.6.1.4.1.6027.3.25.1.2.3.1.4' } # chSysCpuUtilMemUsage
74 },
75 os9 => {
76 mem_used => { oid => '.1.3.6.1.4.1.6027.3.26.1.4.4.1.6' } # dellNetCpuUtilMemUsage
77 }
78 };
79 my $map_device_type = {
80 1 => 'chassis', 2 => 'stack', 3 => 'rpm', 4 => 'supervisor', 5 => 'linecard', 6 => 'port-extender'
81 };
82
83 sub load_series {
84 my ($self, %options) = @_;
85
86 foreach (keys %{$options{snmp_result}}) {
87 /^$mapping->{ $options{name} }->{mem_used}->{oid}\.(.*)/;
88 my $instance = $1;
89 my $result = $options{snmp}->map_instance(mapping => $mapping->{ $options{name} }, results => $options{snmp_result}, instance => $instance);
90
91 $self->{memory}->{$instance} = {
92 display => $instance,
93 usage => $result->{mem_used}
94 };
95 }
96 }
97
98 sub load_os9 {
99 my ($self, %options) = @_;
100
101 foreach (keys %{$options{snmp_result}}) {
102 /^$mapping->{ $options{name} }->{mem_used}->{oid}\.(\d+)\.(\d+)\.(\d+)/;
103 my $name = $map_device_type->{$1} . ':' . $2 . ':' . $3;
104 my $result = $options{snmp}->map_instance(mapping => $mapping->{ $options{name} }, results => $options{snmp_result}, instance => $1 . '.' . $2 . '.' . $3);
105
106 $self->{memory}->{$name} = {
107 display => $name,
108 usage => $result->{mem_used}
109 };
110 }
111 }
112
113 sub manage_selection {
114 my ($self, %options) = @_;
115
116 my $snmp_result = $options{snmp}->get_multiple_table(
117 oids => [
118 { oid => $mapping->{sseries}->{mem_used}->{oid} },
119 { oid => $mapping->{mseries}->{mem_used}->{oid} },
120 { oid => $mapping->{zseries}->{mem_used}->{oid} },
121 { oid => $mapping->{os9}->{mem_used}->{oid} }
122 ],
123 nothing_quit => 1
124 );
125 my $cb_load = {
126 sseries => $self->can('load_series'),
127 mseries => $self->can('load_series'),
128 zseries => $self->can('load_series'),
129 os9 => $self->can('load_os9')
130 };
131
132 $self->{memory} = {};
133 foreach my $name (keys %$mapping) {
134 $cb_load->{$name}->(
135 $self,
136 name => $name,
137 snmp => $options{snmp},
138 snmp_result => $snmp_result->{ $mapping->{$name}->{mem_used}->{oid} }
139 );
140 }
141
142 if (scalar(keys %{$self->{memory}}) <= 0) {
143 $self->{output}->add_option_msg(short_msg => "No entry found.");
144 $self->{output}->option_exit();
145 }
146 }
147
148 1;
149
150 __END__
151
152 =head1 MODE
153
154 Check memory usages.
155
156 =over 8
157
158 =item B<--warning-usage>
159
160 Warning threshold (in percent).
161
162 =item B<--critical-usage>
163
164 Critical threshold (in percent).
165
166 =back
167
168 =cut