Debian Codegraph @

src/network/a10/ax/snmp/mode/vserverusage.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::vserverusage;
22
23 use base qw(centreon::plugins::templates::counter);
24
25 use strict;
26 use warnings;
27 use Digest::MD5 qw(md5_hex);
28 use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold);
29
30 sub custom_status_output {
31 my ($self, %options) = @_;
32
33 my $msg = 'status : ' . $self->{result_values}->{status};
34 return $msg;
35 }
36
37 sub custom_status_calc {
38 my ($self, %options) = @_;
39
40 $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_axVirtualServerStatStatus'};
41 $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'};
42 return 0;
43 }
44
45 sub set_counters {
46 my ($self, %options) = @_;
47
48 $self->{maps_counters_type} = [
49 { name => 'vserver', type => 1, cb_prefix_output => 'prefix_vserver_output', message_multiple => 'All virtual servers are ok' }
50 ];
51
52 $self->{maps_counters}->{vserver} = [
53 { label => 'status', threshold => 0, set => {
54 key_values => [ { name => 'axVirtualServerStatStatus' }, { name => 'display' } ],
55 closure_custom_calc => $self->can('custom_status_calc'),
56 closure_custom_output => $self->can('custom_status_output'),
57 closure_custom_perfdata => sub { return 0; },
58 closure_custom_threshold_check => \&catalog_status_threshold,
59 }
60 },
61 { label => 'current-con', nlabel => 'virtualserver.connections.current.count', set => {
62 key_values => [ { name => 'axVirtualServerStatCurConns' }, { name => 'display' } ],
63 output_template => 'Current Connections : %s',
64 perfdatas => [
65 { label => 'current_connections', template => '%s',
66 min => 0, label_extra_instance => 1, instance_use => 'display' },
67 ],
68 }
69 },
70 { label => 'total-con', nlabel => 'virtualserver.connections.total.count', set => {
71 key_values => [ { name => 'axVirtualServerStatTotConns', diff => 1 }, { name => 'display' } ],
72 output_template => 'Total Connections : %s',
73 perfdatas => [
74 { label => 'total_connections', template => '%s',
75 min => 0, label_extra_instance => 1, instance_use => 'display' },
76 ],
77 }
78 },
79 { label => 'traffic-in', nlabel => 'virtualserver.traffic.in.bitspersecond', set => {
80 key_values => [ { name => 'axVirtualServerStatBytesIn', per_second => 1 }, { name => 'display' } ],
81 output_template => 'Traffic In : %s %s/s',
82 output_change_bytes => 2,
83 perfdatas => [
84 { label => 'traffic_in', template => '%.2f',
85 min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' },
86 ],
87 }
88 },
89 { label => 'traffic-out', nlabel => 'virtualserver.traffic.out.bitspersecond', set => {
90 key_values => [ { name => 'axVirtualServerStatBytesOut', per_second => 1 }, { name => 'display' } ],
91 output_template => 'Traffic Out : %s %s/s',
92 output_change_bytes => 2,
93 perfdatas => [
94 { label => 'traffic_out', template => '%.2f',
95 min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' },
96 ],
97 }
98 },
99 ];
100 }
101
102 sub prefix_vserver_output {
103 my ($self, %options) = @_;
104
105 return "Virtual Server '" . $options{instance_value}->{display} . "' ";
106 }
107
108 sub new {
109 my ($class, %options) = @_;
110 my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1);
111 bless $self, $class;
112
113 $options{options}->add_options(arguments => {
114 'filter-name:s' => { name => 'filter_name' },
115 'warning-status:s' => { name => 'warning_status', default => '' },
116 'critical-status:s' => { name => 'critical_status', default => '%{status} =~ /down/i' }
117 });
118
119 return $self;
120 }
121
122 sub check_options {
123 my ($self, %options) = @_;
124 $self->SUPER::check_options(%options);
125
126 $self->change_macros(macros => ['warning_status', 'critical_status']);
127 }
128
129 my %map_status = (
130 1 => 'up', 2 => 'down', 3 => 'disabled',
131 );
132 my $oid_axVirtualServerStatName = '.1.3.6.1.4.1.22610.2.4.3.4.2.1.1.2';
133 my $mapping = {
134 axVirtualServerStatBytesIn => { oid => '.1.3.6.1.4.1.22610.2.4.3.4.2.1.1.4' },
135 axVirtualServerStatBytesOut => { oid => '.1.3.6.1.4.1.22610.2.4.3.4.2.1.1.6' },
136 axVirtualServerStatTotConns => { oid => '.1.3.6.1.4.1.22610.2.4.3.4.2.1.1.8' },
137 axVirtualServerStatCurConns => { oid => '.1.3.6.1.4.1.22610.2.4.3.4.2.1.1.9' },
138 axVirtualServerStatStatus => { oid => '.1.3.6.1.4.1.22610.2.4.3.4.2.1.1.10', map => \%map_status },
139 };
140
141 sub manage_selection {
142 my ($self, %options) = @_;
143
144 if ($options{snmp}->is_snmpv1()) {
145 $self->{output}->add_option_msg(short_msg => "Need to use SNMP v2c or v3.");
146 $self->{output}->option_exit();
147 }
148
149 my $snmp_result = $options{snmp}->get_table(oid => $oid_axVirtualServerStatName, nothing_quit => 1);
150 $self->{vserver} = {};
151 foreach my $oid (keys %{$snmp_result}) {
152 $oid =~ /^$oid_axVirtualServerStatName\.(.*)$/;
153 my $instance = $1;
154 $snmp_result->{$oid} =~ s/\\//g;
155 if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
156 $snmp_result->{$oid} !~ /$self->{option_results}->{filter_name}/) {
157 $self->{output}->output_add(long_msg => "skipping virtual server '" . $snmp_result->{$oid} . "'.", debug => 1);
158 next;
159 }
160
161 $self->{vserver}->{$instance} = { display => $snmp_result->{$oid} };
162 }
163
164 $options{snmp}->load(oids => [$mapping->{axVirtualServerStatBytesIn}->{oid}, $mapping->{axVirtualServerStatBytesOut}->{oid},
165 $mapping->{axVirtualServerStatTotConns}->{oid}, $mapping->{axVirtualServerStatCurConns}->{oid},
166 $mapping->{axVirtualServerStatStatus}->{oid}
167 ],
168 instances => [keys %{$self->{vserver}}], instance_regexp => '^(.*)$');
169 $snmp_result = $options{snmp}->get_leef(nothing_quit => 1);
170
171 foreach (keys %{$self->{vserver}}) {
172 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $_);
173
174 foreach my $name (('axVirtualServerStatBytesIn', 'axVirtualServerStatBytesOut')) {
175 $result->{$name} *= 8;
176 }
177
178 foreach my $name (keys %$mapping) {
179 $self->{vserver}->{$_}->{$name} = $result->{$name};
180 }
181 }
182
183 if (scalar(keys %{$self->{vserver}}) <= 0) {
184 $self->{output}->add_option_msg(short_msg => "No virtual server found.");
185 $self->{output}->option_exit();
186 }
187
188 $self->{cache_name} = "a10_ax_" . $self->{mode} . '_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' .
189 (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' .
190 (defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all'));
191 }
192
193 1;
194
195 __END__
196
197 =head1 MODE
198
199 Check virtual server usage.
200
201 =over 8
202
203 =item B<--warning-status>
204
205 Define the conditions to match for the status to be WARNING.
206 You can use the following variables: %{status}, %{display}
207
208 =item B<--critical-status>
209
210 Define the conditions to match for the status to be CRITICAL (default: '%{status} =~ /down/i').
211 You can use the following variables: %{status}, %{display}
212
213 =item B<--warning-*>
214
215 Warning threshold.
216 Can be: 'current-con', 'total-con', 'traffic-in', 'traffic-out'.
217
218 =item B<--critical-*>
219
220 Critical threshold.
221 Can be: 'current-con', 'total-con', 'traffic-in', 'traffic-out'.
222
223 =item B<--filter-name>
224
225 Filter by virtual server name (can be a regexp).
226
227 =back
228
229 =cut