Debian Codegraph @

src/network/f5/bigip/snmp/mode/apm.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::apm;
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 set_counters {
30 my ($self, %options) = @_;
31
32 $self->{maps_counters_type} = [
33 { name => 'global', type => 0, skipped_code => { -10 => 1 } },
34 { name => 'vs', type => 3, cb_prefix_output => 'prefix_vs_output', cb_long_output => 'vs_long_output', indent_long_output => ' ', message_multiple => 'All virtual servers are ok',
35 group => [
36 { name => 'ap', display_long => 1, cb_prefix_output => 'prefix_ap_output', message_multiple => 'All access profiles are ok', type => 1, skipped_code => { -10 => 1 } }
37 ]
38 }
39 ];
40
41 $self->{maps_counters}->{global} = [
42 { label => 'sessions-created', nlabel => 'system.sessions.created.count', set => {
43 key_values => [ { name => 'apmAccessStatTotalSessions', diff => 1 } ],
44 output_template => 'created sessions: %s',
45 perfdatas => [
46 { template => '%s', min => 0 }
47 ]
48 }
49 },
50 { label => 'sessions-active', nlabel => 'system.sessions.active.count', set => {
51 key_values => [ { name => 'apmAccessStatCurrentActiveSessions' } ],
52 output_template => 'active sessions: %s',
53 perfdatas => [
54 { template => '%s', min => 0 }
55 ]
56 }
57 },
58 { label => 'sessions-pending', nlabel => 'system.sessions.pending.count', set => {
59 key_values => [ { name => 'apmAccessStatCurrentPendingSessions' } ],
60 output_template => 'pending sessions: %s',
61 perfdatas => [
62 { template => '%s', min => 0 }
63 ]
64 }
65 }
66 ];
67
68 $self->{maps_counters}->{ap} = [
69 { label => 'ap-sessions-created', nlabel => 'accessprofile.sessions.created.count', set => {
70 key_values => [ { name => 'apmPaStatTotalSessions', diff => 1 } ],
71 output_template => 'created sessions: %s',
72 perfdatas => [
73 { template => '%s', min => 0, label_extra_instance => 1 }
74 ]
75 }
76 },
77 { label => 'ap-sessions-active', nlabel => 'accessprofile.sessions.active.count', set => {
78 key_values => [ { name => 'apmPaStatCurrentActiveSessions' } ],
79 output_template => 'active sessions: %s',
80 perfdatas => [
81 { template => '%s', min => 0, label_extra_instance => 1 }
82 ]
83 }
84 },
85 { label => 'ap-sessions-pending', nlabel => 'accessprofile.sessions.pending.count', set => {
86 key_values => [ { name => 'apmPaStatCurrentPendingSessions' } ],
87 output_template => 'pending sessions: %s',
88 perfdatas => [
89 { template => '%s', min => 0, label_extra_instance => 1 }
90 ]
91 }
92 }
93 ];
94 }
95
96 sub prefix_vs_output {
97 my ($self, %options) = @_;
98
99 return "Virtual server '" . $options{instance_value}->{display} . "' : ";
100 }
101
102 sub vs_long_output {
103 my ($self, %options) = @_;
104
105 return "checking virtual server '" . $options{instance_value}->{display} . "'";
106 }
107
108 sub prefix_ap_output {
109 my ($self, %options) = @_;
110
111 return "access profile '" . $options{instance_value}->{display} . "' ";
112 }
113
114 sub new {
115 my ($class, %options) = @_;
116 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1, statefile => 1);
117 bless $self, $class;
118
119 $options{options}->add_options(arguments => {
120 'filter-vs:s' => { name => 'filter_vs' },
121 'filter-ap:s' => { name => 'filter_ap' }
122 });
123
124 return $self;
125 }
126
127 sub manage_selection {
128 my ($self, %options) = @_;
129
130 my $mapping = {
131 apmPaStatTotalSessions => { oid => '.1.3.6.1.4.1.3375.2.6.1.1.3.1.3' },
132 apmPaStatCurrentActiveSessions => { oid => '.1.3.6.1.4.1.3375.2.6.1.1.3.1.5' },
133 apmPaStatCurrentPendingSessions => { oid => '.1.3.6.1.4.1.3375.2.6.1.1.3.1.6' },
134 };
135 my $mapping2 = {
136 apmAccessStatTotalSessions => { oid => '.1.3.6.1.4.1.3375.2.6.1.4.2' },
137 apmAccessStatCurrentActiveSessions => { oid => '.1.3.6.1.4.1.3375.2.6.1.4.3' },
138 apmAccessStatCurrentPendingSessions => { oid => '.1.3.6.1.4.1.3375.2.6.1.4.4' },
139 };
140
141 my $oid_apmPaStatEntry = '.1.3.6.1.4.1.3375.2.6.1.1.3.1';
142 my $oid_apmAccessStat = '.1.3.6.1.4.1.3375.2.6.1.4';
143 my $snmp_result = $options{snmp}->get_multiple_table(
144 oids => [
145 { oid => $oid_apmPaStatEntry, start => $mapping->{apmPaStatTotalSessions}->{oid}, end => $mapping->{apmPaStatCurrentPendingSessions}->{oid} },
146 { oid => $oid_apmAccessStat },
147 ],
148 nothing_quit => 1,
149 );
150
151 my $result = $options{snmp}->map_instance(mapping => $mapping2, results => $snmp_result->{$oid_apmAccessStat}, instance => '0');
152 $self->{global} = { %$result };
153
154 $self->{vs} = {};
155 foreach my $oid (keys %{$snmp_result->{$oid_apmPaStatEntry}}) {
156 next if ($oid !~ /^$mapping->{apmPaStatTotalSessions}->{oid}\.(.*)$/);
157 my $instance = $1;
158
159 my @indexes = split(/\./, $instance);
160 my $ap_name = $self->{output}->decode(join('', map(chr($_), splice(@indexes, 0, shift(@indexes)) )));
161 my $vs_name = $self->{output}->decode(join('', map(chr($_), splice(@indexes, 0, shift(@indexes)) )));
162
163 $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result->{$oid_apmPaStatEntry}, instance => $instance);
164 if (defined($self->{option_results}->{filter_vs}) && $self->{option_results}->{filter_vs} ne '' &&
165 $vs_name !~ /$self->{option_results}->{filter_vs}/) {
166 $self->{output}->output_add(long_msg => "skipping virtual server '" . $vs_name . "'.", debug => 1);
167 next;
168 }
169 if (defined($self->{option_results}->{filter_ap}) && $self->{option_results}->{filter_ap} ne '' &&
170 $ap_name !~ /$self->{option_results}->{filter_ap}/) {
171 $self->{output}->output_add(long_msg => "skipping access profile '" . $ap_name . "'.", debug => 1);
172 next;
173 }
174
175 if (!defined($self->{vs}->{$vs_name})) {
176 $self->{vs}->{$vs_name} = {
177 display => $vs_name,
178 ap => {},
179 };
180 }
181
182 $self->{vs}->{$vs_name}->{ap}->{$ap_name} = {
183 display => $ap_name,
184 %$result
185 };
186 }
187
188 if (scalar(keys %{$self->{vs}}) <= 0) {
189 $self->{output}->add_option_msg(short_msg => "No virtual server found.");
190 $self->{output}->option_exit();
191 }
192
193 $self->{cache_name} = "f5_bigip_" . $self->{mode} . '_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' .
194 (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' .
195 (defined($self->{option_results}->{filter_vs}) ? md5_hex($self->{option_results}->{filter_vs}) : md5_hex('all')) . '_' .
196 (defined($self->{option_results}->{filter_ap}) ? md5_hex($self->{option_results}->{filter_ap}) : md5_hex('all'));
197 }
198
199 1;
200
201 __END__
202
203 =head1 MODE
204
205 Check access policy manager.
206
207 =over 8
208
209 =item B<--filter-vs>
210
211 Filter virtual server name (can be a regexp).
212
213 =item B<--filter-ap>
214
215 Filter access profile name (can be a regexp).
216
217 =item B<--warning-*> B<--critical-*>
218
219 Thresholds.
220 Can be: 'sessions-created', 'sessions-active', 'sessions-pending',
221 'ap-sessions-created', 'ap-sessions-active', 'ap-sessions-pending'.
222
223 =back
224
225 =cut