| 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::virtualserverstatus; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::templates::counter); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); |
| 28 |
|
| 29 |
sub custom_status_output { |
| 30 |
my ($self, %options) = @_; |
| 31 |
|
| 32 |
return sprintf( |
| 33 |
'status: %s [state: %s] [reason: %s]', |
| 34 |
$self->{result_values}->{status}, |
| 35 |
$self->{result_values}->{state}, |
| 36 |
$self->{result_values}->{reason} |
| 37 |
); |
| 38 |
} |
| 39 |
|
| 40 |
sub set_counters { |
| 41 |
my ($self, %options) = @_; |
| 42 |
|
| 43 |
$self->{maps_counters_type} = [ |
| 44 |
{ name => 'vs', type => 1, cb_prefix_output => 'prefix_vs_output', message_multiple => 'All virtual servers are ok' } |
| 45 |
]; |
| 46 |
|
| 47 |
$self->{maps_counters}->{vs} = [ |
| 48 |
{ |
| 49 |
label => 'status', |
| 50 |
type => 2, |
| 51 |
warning_default => '%{state} eq "enabled" and %{status} eq "yellow"', |
| 52 |
critical_default => '%{state} eq "enabled" and %{status} eq "red"', |
| 53 |
set => { |
| 54 |
key_values => [ { name => 'state' }, { name => 'status' }, { name => 'reason' }, { name => 'display' } ], |
| 55 |
closure_custom_output => $self->can('custom_status_output'), |
| 56 |
closure_custom_perfdata => sub { return 0; }, |
| 57 |
closure_custom_threshold_check => \&catalog_status_threshold_ng |
| 58 |
} |
| 59 |
}, |
| 60 |
{ label => 'current-client-connections', nlabel => 'virtualserver.connections.client.current.count', set => { |
| 61 |
key_values => [ { name => 'client_current_connections' }, { name => 'display' } ], |
| 62 |
output_template => 'current client connections: %s', |
| 63 |
perfdatas => [ |
| 64 |
{ template => '%s', min => 0, label_extra_instance => 1, instance_use => 'display' } |
| 65 |
] |
| 66 |
} |
| 67 |
} |
| 68 |
]; |
| 69 |
} |
| 70 |
|
| 71 |
sub prefix_vs_output { |
| 72 |
my ($self, %options) = @_; |
| 73 |
|
| 74 |
return "Virtual server '" . $options{instance_value}->{display} . "' "; |
| 75 |
} |
| 76 |
|
| 77 |
sub new { |
| 78 |
my ($class, %options) = @_; |
| 79 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); |
| 80 |
bless $self, $class; |
| 81 |
|
| 82 |
$options{options}->add_options(arguments => { |
| 83 |
'filter-name:s' => { name => 'filter_name' } |
| 84 |
}); |
| 85 |
|
| 86 |
return $self; |
| 87 |
} |
| 88 |
|
| 89 |
my $map_vs_status = { |
| 90 |
0 => 'none', 1 => 'green', |
| 91 |
2 => 'yellow', 3 => 'red', |
| 92 |
4 => 'blue', 5 => 'gray' |
| 93 |
}; |
| 94 |
my $map_vs_enabled = { |
| 95 |
0 => 'none', 1 => 'enabled', |
| 96 |
2 => 'disabled', 3 => 'disabledbyparent' |
| 97 |
}; |
| 98 |
|
| 99 |
my $mapping = { |
| 100 |
new => { |
| 101 |
state => { oid => '.1.3.6.1.4.1.3375.2.2.10.13.2.1.3', map => $map_vs_enabled }, # EnabledState |
| 102 |
reason => { oid => '.1.3.6.1.4.1.3375.2.2.10.13.2.1.5' }, # StatusReason |
| 103 |
client_current_connections => { oid => '.1.3.6.1.4.1.3375.2.2.10.2.3.1.12' } # ltmVirtualServStatClientCurConns |
| 104 |
}, |
| 105 |
old => { |
| 106 |
state => { oid => '.1.3.6.1.4.1.3375.2.2.10.1.2.1.23', map => $map_vs_enabled }, # EnabledState |
| 107 |
reason => { oid => '.1.3.6.1.4.1.3375.2.2.10.1.2.1.25' }, # StatusReason |
| 108 |
client_current_connections => { oid => '.1.3.6.1.4.1.3375.2.2.10.2.3.1.12' } # ltmVirtualServStatClientCurConns |
| 109 |
} |
| 110 |
}; |
| 111 |
# AvailState |
| 112 |
my $oid_status = { |
| 113 |
new => '.1.3.6.1.4.1.3375.2.2.10.13.2.1.2', |
| 114 |
old => '.1.3.6.1.4.1.3375.2.2.10.1.2.1.22' |
| 115 |
}; |
| 116 |
|
| 117 |
sub manage_selection { |
| 118 |
my ($self, %options) = @_; |
| 119 |
|
| 120 |
my $snmp_result = $options{snmp}->get_multiple_table( |
| 121 |
oids => [ |
| 122 |
{ oid => $oid_status->{new} }, |
| 123 |
{ oid => $oid_status->{old} } |
| 124 |
], |
| 125 |
nothing_quit => 1 |
| 126 |
); |
| 127 |
|
| 128 |
my $map = 'new'; |
| 129 |
if (!defined($snmp_result->{ $oid_status->{new} }) || scalar(keys %{$snmp_result->{ $oid_status->{new} }}) == 0) { |
| 130 |
$map = 'old'; |
| 131 |
} |
| 132 |
|
| 133 |
$self->{vs} = {}; |
| 134 |
foreach my $oid (keys %{$snmp_result->{ $oid_status->{$map} }}) { |
| 135 |
$oid =~ /^$oid_status->{$map}\.(.*?)\.(.*)$/; |
| 136 |
my ($num, $index) = ($1, $2); |
| 137 |
|
| 138 |
my $name = $self->{output}->decode(join('', map(chr($_), split(/\./, $index)))); |
| 139 |
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && |
| 140 |
$name !~ /$self->{option_results}->{filter_name}/) { |
| 141 |
$self->{output}->output_add(long_msg => "skipping '" . $name . "': no matching filter name.", debug => 1); |
| 142 |
next; |
| 143 |
} |
| 144 |
|
| 145 |
|
| 146 |
$self->{vs}->{$num . '.' . $index} = { |
| 147 |
display => $name, |
| 148 |
status => $map_vs_status->{ $snmp_result->{ $oid_status->{$map} }->{$oid} } |
| 149 |
}; |
| 150 |
} |
| 151 |
|
| 152 |
if (scalar(keys %{$self->{vs}}) <= 0) { |
| 153 |
$self->{output}->add_option_msg(short_msg => 'No entry found.'); |
| 154 |
$self->{output}->option_exit(); |
| 155 |
} |
| 156 |
|
| 157 |
$options{snmp}->load( |
| 158 |
oids => [ map($_->{oid}, values(%{$mapping->{$map}})) ], |
| 159 |
instances => [ keys %{$self->{vs}} ], |
| 160 |
instance_regexp => '^(.*)$' |
| 161 |
); |
| 162 |
$snmp_result = $options{snmp}->get_leef(); |
| 163 |
foreach (keys %{$self->{vs}}) { |
| 164 |
my $result = $options{snmp}->map_instance(mapping => $mapping->{$map}, results => $snmp_result, instance => $_); |
| 165 |
|
| 166 |
$result->{StatusReason} = '-' if (!defined($result->{StatusReason}) || $result->{StatusReason} eq ''); |
| 167 |
$self->{vs}->{$_} = { %{$self->{vs}->{$_}}, %$result }; |
| 168 |
} |
| 169 |
} |
| 170 |
|
| 171 |
1; |
| 172 |
|
| 173 |
__END__ |
| 174 |
|
| 175 |
=head1 MODE |
| 176 |
|
| 177 |
Check virtual servers. |
| 178 |
|
| 179 |
=over 8 |
| 180 |
|
| 181 |
=item B<--filter-name> |
| 182 |
|
| 183 |
Filter by name (regexp can be used). |
| 184 |
|
| 185 |
=item B<--unknown-status> |
| 186 |
|
| 187 |
Define the conditions to match for the status to be UNKNOWN (default: ''). |
| 188 |
You can use the following variables: %{state}, %{status}, %{display} |
| 189 |
|
| 190 |
=item B<--warning-status> |
| 191 |
|
| 192 |
Define the conditions to match for the status to be WARNING (default: '%{state} eq "enabled" and %{status} eq "yellow"'). |
| 193 |
You can use the following variables: %{state}, %{status}, %{display} |
| 194 |
|
| 195 |
=item B<--critical-status> |
| 196 |
|
| 197 |
Define the conditions to match for the status to be CRITICAL (default: '%{state} eq "enabled" and %{status} eq "red"'). |
| 198 |
You can use the following variables: %{state}, %{status}, %{display} |
| 199 |
|
| 200 |
=item B<--warning-*> B<--critical-*> |
| 201 |
|
| 202 |
Thresholds. |
| 203 |
Can be: 'current-client-connections'. |
| 204 |
|
| 205 |
=back |
| 206 |
|
| 207 |
=cut |