Debian Codegraph @

src/network/cambium/cnpilot/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 package network::cambium::cnpilot::snmp::mode::memory;
21
22 use base qw(centreon::plugins::templates::counter);
23
24 use strict;
25 use warnings;
26
27 sub prefix_memory_output {
28 my ($self, %options) = @_;
29
30 return "Memory '" . $options{instance_value}->{name} . "' ";
31 }
32
33 sub custom_usage_output {
34 my ($self, %options) = @_;
35
36 return sprintf(
37 'used: %.2f %%',
38 $self->{result_values}->{used}
39 );
40 }
41
42 sub set_counters {
43 my ($self, %options) = @_;
44
45 $self->{maps_counters_type} = [
46 { name => 'memory', type => 1, cb_prefix_output => 'prefix_memory_output', message_multiple => 'All memories are ok' }
47 ];
48
49 $self->{maps_counters}->{memory} = [
50 { label => 'memory-usage-prct', nlabel => 'memory.usage.percentage', set => {
51 key_values => [ { name => 'used' }, { name => 'free' }, { name => 'name' } ],
52 closure_custom_output => $self->can('custom_usage_output'),
53 perfdatas => [
54 { template => '%s', min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'name'}
55 ]
56 }
57 }
58 ];
59 }
60
61 sub new {
62 my ($class, %options) = @_;
63 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
64 bless $self, $class;
65
66 $options{options}->add_options(arguments => {
67 'filter-ap:s' => { name => 'filter_ap' }
68 });
69
70 return $self;
71 }
72
73 sub manage_selection {
74 my ($self, %options) = @_;
75
76 # Select relevant oids for Memory monitoring
77 my $mapping = {
78 cambiumAPName => { oid => '.1.3.6.1.4.1.17713.22.1.1.1.2' },
79 cambiumAPMemoryFree => { oid => '.1.3.6.1.4.1.17713.22.1.1.1.7' }
80 };
81
82 # Point at the begining of the table
83 my $oid_cambiumAccessPointEntry = '.1.3.6.1.4.1.17713.22.1.1.1';
84
85 my $memory_result = $options{snmp}->get_table(
86 oid => $oid_cambiumAccessPointEntry,
87 nothing_quit => 1
88 );
89
90 foreach my $oid (keys %{$memory_result}) {
91 next if ($oid !~ /^$mapping->{cambiumAPName}->{oid}\.(.*)$/);
92 # Catch instance in table
93 my $instance = $1;
94 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $memory_result, instance => $instance);
95
96 if (defined($self->{option_results}->{filter_ap}) && $self->{option_results}->{filter_ap} ne '' &&
97 $result->{cambiumAPName} !~ /$self->{option_results}->{filter_ap}/) {
98 $self->{output}->output_add(long_msg => "skipping '" . $result->{cambiumAPName} . "': no matching filter.", debug => 1);
99 next;
100 }
101
102 $self->{memory}->{$instance} = {
103 name => $result->{cambiumAPName},
104 free => $result->{cambiumAPMemoryFree},
105 used => 100 - $result->{cambiumAPMemoryFree}
106 };
107 }
108
109 if (scalar(keys %{$self->{memory}}) <= 0) {
110 $self->{output}->add_option_msg(short_msg => "No AP matching with filter found.");
111 $self->{output}->option_exit();
112 }
113 }
114
115 1;
116
117 __END__
118
119 =head1 MODE
120
121 Check memory usage.
122
123 =over 8
124
125 =item B<--filter-ap>
126
127 Filter on one or several AP.
128
129 =item B<--warning>
130
131 Warning threshold for Memory.
132
133 =item B<--critical>
134
135 Critical threshold for Memory.
136
137 =back
138
139 =cut