Debian Codegraph @

src/network/cisco/firepower/fxos/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::cisco::firepower::fxos::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 => 1, cb_prefix_output => 'prefix_message_output', message_multiple => 'All memory usages are ok' },
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' }, { name => 'display' } ],
51 closure_custom_output => $self->can('custom_usage_output'),
52 perfdatas => [
53 { value => 'used', template => '%d', min => 0, max => 'total',
54 unit => 'B', cast_int => 1, label_extra_instance => 1 }
55 ]
56 }
57 },
58 { label => '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' }, { name => 'display' } ],
60 closure_custom_output => $self->can('custom_usage_output'),
61 perfdatas => [
62 { value => 'free', template => '%d', min => 0, max => 'total',
63 unit => 'B', cast_int => 1, label_extra_instance => 1 }
64 ]
65 }
66 },
67 { label => 'usage-prct', display_ok => 0, nlabel => 'memory.usage.percentage', set => {
68 key_values => [ { name => 'prct_used' }, { name => 'display' } ],
69 output_template => 'Ram Used : %.2f %%',
70 perfdatas => [
71 { value => 'prct_used', template => '%.2f', min => 0, max => 100,
72 unit => '%', label_extra_instance => 1 }
73 ]
74 }
75 }
76 ];
77 }
78
79 sub prefix_message_output {
80 my ($self, %options) = @_;
81
82 return "Security module '" . $options{instance_value}->{display} . "' ";
83 }
84
85 sub new {
86 my ($class, %options) = @_;
87 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
88 bless $self, $class;
89
90 $options{options}->add_options(arguments => {
91 'filter-security-module:s' => { name => 'filter_security_module' }
92 });
93
94 return $self;
95 }
96
97 my $mapping = {
98 display => { oid => '.1.3.6.1.4.1.9.9.826.1.71.20.1.2' }, # cfprSmMonitorDn
99 free => { oid => '.1.3.6.1.4.1.9.9.826.1.71.20.1.9' }, # cfprSmMonitorMemFreeKb
100 total => { oid => '.1.3.6.1.4.1.9.9.826.1.71.20.1.10' } # cfprSmMonitorMemTotalKb
101 };
102 my $oid_cfprSmMonitorEntry = '.1.3.6.1.4.1.9.9.826.1.71.20.1';
103
104 sub manage_selection {
105 my ($self, %options) = @_;
106
107 my $snmp_result = $options{snmp}->get_multiple_table(
108 oids => [
109 { oid => $mapping->{display}->{oid} },
110 { oid => $oid_cfprSmMonitorEntry, start => $mapping->{free}->{oid}, end => $mapping->{total}->{oid} }
111 ],
112 return_type => 1,
113 nothing_quit => 1
114 );
115
116 $self->{memory} = {};
117 foreach my $oid (keys %$snmp_result) {
118 next if ($oid !~ /^$mapping->{display}->{oid}\.(.*)$/);
119 my $instance = $1;
120 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance);
121
122 # remove 'monitor': sec-svc/slot-1/monitor
123 $result->{display} =~ s/\/([^\/]*?)$//;
124 if (defined($self->{option_results}->{filter_security_module}) && $self->{option_results}->{filter_security_module} ne '' &&
125 $result->{display} !~ /$self->{option_results}->{filter_security_module}/) {
126 $self->{output}->output_add(long_msg => "skipping '" . $result->{display} . "': no matching filter.", debug => 1);
127 next;
128 }
129
130 $result->{total} *= 1024;
131 $result->{free} *= 1024;
132 my $prct_used = ($result->{total} - $result->{free}) * 100 / $result->{total};
133 $self->{memory}->{ $result->{display} } = {
134 prct_used => $prct_used,
135 prct_free => 100 - $prct_used,
136 used => $result->{total} - $result->{free},
137 %$result
138 };
139 }
140 }
141
142 1;
143
144 __END__
145
146 =head1 MODE
147
148 Check memory usage.
149
150 =over 8
151
152 =item B<--filter-switch-num>
153
154 Filter switch number.
155
156 =item B<--warning-*> B<--critical-*>
157
158 Thresholds.
159 Can be: 'usage' (B), 'usage-free' (B), 'usage-prct' (%).
160
161 =back
162
163 =cut