Debian Codegraph @

src/network/a10/ax/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::a10::ax::snmp::mode::memory;
22
23 use base qw(centreon::plugins::templates::counter);
24
25 use strict;
26 use warnings;
27
28 sub custom_usage_perfdata {
29 my ($self, %options) = @_;
30
31 $self->{output}->perfdata_add(label => 'used', unit => 'B',
32 nlabel => $self->{nlabel},
33 value => $self->{result_values}->{used},
34 warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}, total => $self->{result_values}->{total}, cast_int => 1),
35 critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}, total => $self->{result_values}->{total}, cast_int => 1),
36 min => 0, max => $self->{result_values}->{total});
37 }
38
39 sub custom_usage_threshold {
40 my ($self, %options) = @_;
41
42 my $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{prct_used}, threshold => [ { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{thlabel}, exit_litteral => 'warning' } ]);
43 return $exit;
44 }
45
46 sub custom_usage_output {
47 my ($self, %options) = @_;
48
49 my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total});
50 my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used});
51 my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free});
52
53 my $msg = sprintf("Memory Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)",
54 $total_size_value . " " . $total_size_unit,
55 $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used},
56 $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free});
57 return $msg;
58 }
59
60 sub custom_usage_calc {
61 my ($self, %options) = @_;
62
63 $self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_total'};
64 $self->{result_values}->{used} = $options{new_datas}->{$self->{instance} . '_used'};
65 $self->{result_values}->{prct_used} = $self->{result_values}->{used} * 100 / $self->{result_values}->{total};
66 $self->{result_values}->{prct_free} = 100 - $self->{result_values}->{prct_used};
67 $self->{result_values}->{free} = $self->{result_values}->{total} - $self->{result_values}->{used};
68
69 return 0;
70 }
71
72 sub set_counters {
73 my ($self, %options) = @_;
74
75 $self->{maps_counters_type} = [
76 { name => 'memory', type => 0 }
77 ];
78
79 $self->{maps_counters}->{memory} = [
80 { label => 'usage', nlabel => 'memory.usage.bytes', set => {
81 key_values => [ { name => 'used' }, { name => 'total' } ],
82 closure_custom_calc => $self->can('custom_usage_calc'),
83 closure_custom_output => $self->can('custom_usage_output'),
84 closure_custom_perfdata => $self->can('custom_usage_perfdata'),
85 closure_custom_threshold_check => $self->can('custom_usage_threshold'),
86 }
87 },
88 ];
89 }
90
91 sub new {
92 my ($class, %options) = @_;
93 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
94 bless $self, $class;
95
96 $options{options}->add_options(arguments =>
97 {
98 });
99
100 return $self;
101 }
102
103 sub manage_selection {
104 my ($self, %options) = @_;
105
106 my $oid_axSysMemoryUsage = '.1.3.6.1.4.1.22610.2.4.1.2.2.0'; # in KB
107 my $oid_axSysMemoryTotal = '.1.3.6.1.4.1.22610.2.4.1.2.1.0'; # in KB
108 my $snmp_result = $options{snmp}->get_leef(oids => [$oid_axSysMemoryUsage, $oid_axSysMemoryTotal],
109 nothing_quit => 1);
110
111 $self->{memory} = { used => $snmp_result->{$oid_axSysMemoryUsage} * 1024, total => $snmp_result->{$oid_axSysMemoryTotal} * 1024 };
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<--warning-usage>
126
127 Warning threshold (in percent).
128
129 =item B<--critical-usage>
130
131 Critical threshold (in percent).
132
133 =back
134
135 =cut