Debian Codegraph @

src/network/stonesoft/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::stonesoft::snmp::mode::memory;
22
23 use base qw(centreon::plugins::mode);
24
25 use strict;
26 use warnings;
27
28 sub new {
29 my ($class, %options) = @_;
30 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
31 bless $self, $class;
32
33 $options{options}->add_options(arguments =>
34 {
35 "warning:s" => { name => 'warning' },
36 "critical:s" => { name => 'critical' },
37 "swap" => { name => 'check_swap' },
38 "warning-swap:s" => { name => 'warning_swap' },
39 "critical-swap:s" => { name => 'critical_swap' },
40 "no-swap:s" => { name => 'no_swap' },
41 });
42 $self->{no_swap} = 'critical';
43 return $self;
44 }
45
46 sub check_options {
47 my ($self, %options) = @_;
48 $self->SUPER::init(%options);
49
50 if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) {
51 $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
52 $self->{output}->option_exit();
53 }
54 if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
55 $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
56 $self->{output}->option_exit();
57 }
58 if (defined($self->{option_results}->{check_swap})) {
59 if (($self->{perfdata}->threshold_validate(label => 'warning-swap', value => $self->{option_results}->{warning_swap})) == 0) {
60 $self->{output}->add_option_msg(short_msg => "Wrong warning-swap threshold '" . $self->{option_results}->{warning_swap} . "'.");
61 $self->{output}->option_exit();
62 }
63 if (($self->{perfdata}->threshold_validate(label => 'critical-swap', value => $self->{option_results}->{critical_swap})) == 0) {
64 $self->{output}->add_option_msg(short_msg => "Wrong critical-swap threshold '" . $self->{option_results}->{critical_swap} . "'.");
65 $self->{output}->option_exit();
66 }
67 if (defined($self->{option_results}->{no_swap}) && $self->{option_results}->{no_swap} ne '') {
68 if ($self->{output}->is_litteral_status(status => $self->{option_results}->{no_swap}) == 0) {
69 $self->{output}->add_option_msg(short_msg => "Wrong --no-swap status '" . $self->{option_results}->{no_swap} . "'.");
70 $self->{output}->option_exit();
71 }
72 $self->{no_swap} = $self->{option_results}->{no_swap};
73 }
74 }
75 }
76
77 sub run {
78 my ($self, %options) = @_;
79 $self->{snmp} = $options{snmp};
80
81 my $oid_fwMemBytesTotal = '.1.3.6.1.4.1.1369.5.2.1.11.2.4.0';
82 my $oid_fwMemBytesUsed = '.1.3.6.1.4.1.1369.5.2.1.11.2.5.0';
83 my $oid_fwMemBytesUnused = '.1.3.6.1.4.1.1369.5.2.1.11.2.6.0';
84 my $oid_fwMemBytesBuffers = '.1.3.6.1.4.1.1369.5.2.1.11.2.7.0';
85 my $oid_fwMemBytesCached = '.1.3.6.1.4.1.1369.5.2.1.11.2.8.0';
86 my $oid_fwSwapBytesTotal = '.1.3.6.1.4.1.1369.5.2.1.11.2.1.0';
87 my $oid_fwSwapBytesUsed = '.1.3.6.1.4.1.1369.5.2.1.11.2.2.0';
88 my $oid_fwSwapBytesUnused = '.1.3.6.1.4.1.1369.5.2.1.11.2.3.0';
89
90 my $oids = [$oid_fwMemBytesTotal, $oid_fwMemBytesUsed, $oid_fwMemBytesUnused, $oid_fwMemBytesBuffers, $oid_fwMemBytesCached];
91
92 if (defined($self->{option_results}->{check_swap})) {
93 push @$oids, ($oid_fwSwapBytesTotal, $oid_fwSwapBytesUnused, $oid_fwSwapBytesUsed);
94 }
95
96 my $result = $self->{snmp}->get_leef(oids => $oids,
97 nothing_quit => 1);
98 my $cached_used = $result->{$oid_fwMemBytesCached};
99 my $buffer_used = $result->{$oid_fwMemBytesBuffers};
100 my $physical_used = $result->{$oid_fwMemBytesUsed};
101 my $nobuf_used = $physical_used - $buffer_used - $cached_used;
102 my $total_size = $result->{$oid_fwMemBytesTotal};
103
104 my $prct_used = $nobuf_used * 100 / $total_size;
105 my $exit = $self->{perfdata}->threshold_check(value => $prct_used, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
106
107 my ($nobuf_value, $nobuf_unit) = $self->{perfdata}->change_bytes(value => $nobuf_used);
108 my ($buffer_value, $buffer_unit) = $self->{perfdata}->change_bytes(value => $buffer_used);
109 my ($cached_value, $cached_unit) = $self->{perfdata}->change_bytes(value => $cached_used);
110
111 $self->{output}->output_add(severity => $exit,
112 short_msg => sprintf("Ram used (-buffers/cache) %s (%.2f%%), Buffer: %s, Cached: %s",
113 $nobuf_value . " " . $nobuf_unit, $prct_used,
114 $buffer_value . " " . $buffer_unit,
115 $cached_value . " " . $cached_unit));
116
117 $self->{output}->perfdata_add(label => "cached", unit => 'B',
118 value => $cached_used,
119 min => 0);
120 $self->{output}->perfdata_add(label => "buffer", unit => 'B',
121 value => $buffer_used,
122 min => 0);
123 $self->{output}->perfdata_add(label => "used", unit => 'B',
124 value => $nobuf_used,
125 warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning', total => $total_size, cast_int => 1),
126 critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical', total => $total_size, cast_int => 1),
127 min => 0, max => $total_size);
128
129 if (defined($self->{option_results}->{check_swap})) {
130 if ($result->{$oid_fwSwapBytesTotal} == 0) {
131 $self->{output}->output_add(severity => $self->{no_swap},
132 short_msg => 'No active swap.');
133 $self->{output}->display();
134 $self->{output}->exit();
135 }
136
137 $total_size = $result->{$oid_fwSwapBytesTotal};
138 my $swap_used = $result->{$oid_fwSwapBytesUsed};
139
140 $prct_used = $swap_used * 100 / $total_size;
141 $exit = $self->{perfdata}->threshold_check(value => $prct_used, threshold => [ { label => 'critical-swap', 'exit_litteral' => 'critical' }, { label => 'warning-swap', exit_litteral => 'warning' } ]);
142
143 my ($total_value, $total_unit) = $self->{perfdata}->change_bytes(value => $total_size);
144 my ($swap_used_value, $swap_used_unit) = $self->{perfdata}->change_bytes(value => $swap_used);
145 my ($swap_free_value, $swap_free_unit) = $self->{perfdata}->change_bytes(value => ($total_size - $swap_used));
146
147 $self->{output}->output_add(severity => $exit,
148 short_msg => sprintf("Swap Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)",
149 $total_value . " " . $total_unit,
150 $swap_used_value . " " . $swap_used_unit, $prct_used,
151 $swap_free_value . " " . $swap_free_unit, (100 - $prct_used)));
152
153 $self->{output}->perfdata_add(label => "swap", unit => 'B',
154 value => $swap_used,
155 warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-swap', total => $total_size, cast_int => 1),
156 critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-swap', total => $total_size, cast_int => 1),
157 min => 0, max => $total_size);
158 }
159
160 $self->{output}->display();
161 $self->{output}->exit();
162 }
163
164 1;
165
166 __END__
167
168 =head1 MODE
169
170 Check stonesoftFirewall memory usage (STONESOFT-FIREWALL-MIB).
171
172 =over 8
173
174 =item B<--warning>
175
176 Warning threshold in percent.
177
178 =item B<--critical>
179
180 Critical threshold in percent.
181
182 =item B<-swap>
183
184 Check swap also.
185
186 =item B<--warning-swap>
187
188 Warning threshold in percent.
189
190 =item B<--critical-swap>
191
192 Critical threshold in percent.
193
194 =item B<--no-swap>
195
196 Threshold if no active swap (default: 'critical').
197
198 =back
199
200 =cut