Debian Codegraph @

src/network/f5/bigip/snmp/mode/tmmusage.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::f5::bigip::snmp::mode::tmmusage;
22
23 use base qw(centreon::plugins::templates::counter);
24
25 use strict;
26 use warnings;
27 use Digest::MD5 qw(md5_hex);
28
29 sub custom_usage_perfdata {
30 my ($self, %options) = @_;
31
32 $self->{output}->perfdata_add(
33 label => 'memory_used', unit => 'B',
34 instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{display} : undef,
35 value => $self->{result_values}->{used},
36 warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}, total => $self->{result_values}->{total}, cast_int => 1),
37 critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}, total => $self->{result_values}->{total}, cast_int => 1),
38 min => 0, max => $self->{result_values}->{total}
39 );
40 }
41
42 sub custom_usage_threshold {
43 my ($self, %options) = @_;
44
45 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' } ]);
46 return $exit;
47 }
48
49 sub custom_usage_output {
50 my ($self, %options) = @_;
51
52 my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total});
53 my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used});
54 my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free});
55
56 my $msg = sprintf("Memory Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)",
57 $total_size_value . " " . $total_size_unit,
58 $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used},
59 $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free});
60 return $msg;
61 }
62
63 sub custom_usage_calc {
64 my ($self, %options) = @_;
65
66 return - 10 if ($options{new_datas}->{$self->{instance} . '_sysTmmStatMemoryTotal'} == 0);
67 $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'};
68 $self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_sysTmmStatMemoryTotal'};
69 $self->{result_values}->{used} = $options{new_datas}->{$self->{instance} . '_sysTmmStatMemoryUsed'};
70 $self->{result_values}->{free} = $self->{result_values}->{total} - $self->{result_values}->{used};
71 $self->{result_values}->{prct_free} = $self->{result_values}->{free} * 100 / $self->{result_values}->{total};
72 $self->{result_values}->{prct_used} = $self->{result_values}->{used} * 100 / $self->{result_values}->{total};
73 return 0;
74 }
75
76 sub set_counters {
77 my ($self, %options) = @_;
78
79 $self->{maps_counters_type} = [
80 { name => 'tmm', type => 1, cb_prefix_output => 'prefix_tmm_output', message_multiple => 'All TMM are ok', skipped_code => { -10 => 1 } },
81 ];
82
83 $self->{maps_counters}->{tmm} = [
84 { label => 'memory-usage', set => {
85 key_values => [ { name => 'display' }, { name => 'sysTmmStatMemoryTotal' }, { name => 'sysTmmStatMemoryUsed' } ],
86 closure_custom_calc => $self->can('custom_usage_calc'),
87 closure_custom_output => $self->can('custom_usage_output'),
88 closure_custom_perfdata => $self->can('custom_usage_perfdata'),
89 closure_custom_threshold_check => $self->can('custom_usage_threshold'),
90 }
91 },
92 { label => 'cpu-1m', set => {
93 key_values => [ { name => 'sysTmmStatTmUsageRatio1m' }, { name => 'display' } ],
94 output_template => 'CPU Usage 1min : %s %%', output_error_template => "CPU Usage 1min : %s",
95 perfdatas => [
96 { label => 'cpu_1m', value => 'sysTmmStatTmUsageRatio1m', template => '%s',
97 unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' },
98 ],
99 }
100 },
101 { label => 'cpu-5m', set => {
102 key_values => [ { name => 'sysTmmStatTmUsageRatio5m' }, { name => 'display' } ],
103 output_template => 'CPU Usage 5min : %s %%', output_error_template => "CPU Usage 5min : %s",
104 perfdatas => [
105 { label => 'cpu_5m', value => 'sysTmmStatTmUsageRatio5m', template => '%s',
106 unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' },
107 ],
108 }
109 },
110 { label => 'current-client-connections', set => {
111 key_values => [ { name => 'sysTmmStatClientCurConns' }, { name => 'display' } ],
112 output_template => 'Current Client Connections : %s', output_error_template => "Current Client Connections : %s",
113 perfdatas => [
114 { label => 'current_client_connections', value => 'sysTmmStatClientCurConns', template => '%s',
115 min => 0, label_extra_instance => 1, instance_use => 'display' },
116 ],
117 }
118 },
119 { label => 'total-client-connections', set => {
120 key_values => [ { name => 'sysTmmStatClientTotConns', diff => 1 }, { name => 'display' } ],
121 output_template => 'Total Client Connections : %s', output_error_template => "Total Client Connections : %s",
122 perfdatas => [
123 { label => 'total_client_connections', value => 'sysTmmStatClientTotConns', template => '%s',
124 min => 0, label_extra_instance => 1, instance_use => 'display' },
125 ],
126 }
127 },
128 { label => 'current-server-connections', set => {
129 key_values => [ { name => 'sysTmmStatServerCurConns' }, { name => 'display' } ],
130 output_template => 'Current Server Connections : %s', output_error_template => "Current Server Connections : %s",
131 perfdatas => [
132 { label => 'current_server_connections', value => 'sysTmmStatServerCurConns', template => '%s',
133 min => 0, label_extra_instance => 1, instance_use => 'display' },
134 ],
135 }
136 },
137 { label => 'total-server-connections', set => {
138 key_values => [ { name => 'sysTmmStatServerTotConns', diff => 1 }, { name => 'display' } ],
139 output_template => 'Total Server Connections : %s', output_error_template => "Total Server Connections : %s",
140 perfdatas => [
141 { label => 'total_server_connections', value => 'sysTmmStatServerTotConns', template => '%s',
142 min => 0, label_extra_instance => 1, instance_use => 'display' },
143 ],
144 }
145 },
146 ];
147 }
148
149 sub prefix_tmm_output {
150 my ($self, %options) = @_;
151
152 return "TMM '" . $options{instance_value}->{display} . "' ";
153 }
154
155 sub new {
156 my ($class, %options) = @_;
157 my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1);
158 bless $self, $class;
159
160 $options{options}->add_options(arguments => {
161 'filter-name:s' => { name => 'filter_name' },
162 });
163
164 return $self;
165 }
166
167 my $mapping = {
168 sysTmmStatTmmId => { oid => '.1.3.6.1.4.1.3375.2.1.8.2.3.1.1' },
169 sysTmmStatClientTotConns => { oid => '.1.3.6.1.4.1.3375.2.1.8.2.3.1.11' },
170 sysTmmStatClientCurConns => { oid => '.1.3.6.1.4.1.3375.2.1.8.2.3.1.12' },
171 sysTmmStatServerTotConns => { oid => '.1.3.6.1.4.1.3375.2.1.8.2.3.1.18' },
172 sysTmmStatServerCurConns => { oid => '.1.3.6.1.4.1.3375.2.1.8.2.3.1.19' },
173 sysTmmStatMemoryTotal => { oid => '.1.3.6.1.4.1.3375.2.1.8.2.3.1.31' }, # B
174 sysTmmStatMemoryUsed => { oid => '.1.3.6.1.4.1.3375.2.1.8.2.3.1.32' }, # B
175 sysTmmStatTmUsageRatio1m => { oid => '.1.3.6.1.4.1.3375.2.1.8.2.3.1.38' },
176 sysTmmStatTmUsageRatio5m => { oid => '.1.3.6.1.4.1.3375.2.1.8.2.3.1.39' },
177 };
178 my $oid_sysTmmStatEntry = '.1.3.6.1.4.1.3375.2.1.8.2.3.1';
179
180 sub manage_selection {
181 my ($self, %options) = @_;
182
183 if ($options{snmp}->is_snmpv1()) {
184 $self->{output}->add_option_msg(short_msg => "Need to use SNMP v2c or v3.");
185 $self->{output}->option_exit();
186 }
187
188 my $results = $options{snmp}->get_table(
189 oid => $oid_sysTmmStatEntry,
190 nothing_quit => 1
191 );
192
193 $self->{tmm} = {};
194 foreach my $oid (keys %$results) {
195 next if ($oid !~ /^$mapping->{sysTmmStatTmmId}->{oid}\.(.*)$/);
196 my $instance = $1;
197 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $results, instance => $instance);
198
199 if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
200 $result->{sysTmmStatTmmId} !~ /$self->{option_results}->{filter_name}/) {
201 $self->{output}->output_add(long_msg => "skipping '" . $result->{sysTmmStatTmmId} . "': no matching filter name.", debug => 1);
202 next;
203 }
204
205 $self->{tmm}->{$result->{sysTmmStatTmmId}} = {
206 display => $result->{sysTmmStatTmmId},
207 %$result
208 };
209 }
210
211 if (scalar(keys %{$self->{tmm}}) <= 0) {
212 $self->{output}->add_option_msg(short_msg => "No TMM found.");
213 $self->{output}->option_exit();
214 }
215
216 $self->{cache_name} = "f5_bipgip_" . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode} . '_' .
217 (defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all')) . '_' .
218 (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all'));
219 }
220
221 1;
222
223 __END__
224
225 =head1 MODE
226
227 Check TMM usages.
228
229 =over 8
230
231 =item B<--filter-counters>
232
233 Only display some counters (regexp can be used).
234 Example : --filter-counters='^memory-usage$'
235
236 =item B<--filter-name>
237
238 Filter by TMM name (regexp can be used).
239
240 =item B<--warning-*>
241
242 Warning threshold.
243 Can be: 'cpu-1m', 'cpu-5m', 'memory-usage' (%), 'total-client-connections', 'current-client-connections',
244 'total-server-connections', 'current-server-connections'.
245
246 =item B<--critical-*>
247
248 Critical threshold.
249 Can be: 'cpu-1m', 'cpu-5m', 'memory-usage' (%), 'total-client-connections', 'current-client-connections',
250 'total-server-connections', 'current-server-connections'.
251
252 =back
253
254 =cut