| 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::kemp::snmp::mode::vsstatus; |
| 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} . '_status'}; |
| 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 => 'vs', type => 1, cb_prefix_output => 'prefix_vs_output', message_multiple => 'All virtual servers are ok' } |
| 50 |
]; |
| 51 |
|
| 52 |
$self->{maps_counters}->{vs} = [ |
| 53 |
{ label => 'status', threshold => 0, set => { |
| 54 |
key_values => [ { name => 'status' }, { 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 => 'active', set => { |
| 62 |
key_values => [ { name => 'vSActivConns' }, { name => 'display' } ], |
| 63 |
output_template => 'Active connections : %s', |
| 64 |
perfdatas => [ |
| 65 |
{ label => 'active', template => '%s', min => 0, label_extra_instance => 1, instance_use => 'display' }, |
| 66 |
], |
| 67 |
} |
| 68 |
}, |
| 69 |
{ label => 'in-traffic', set => { |
| 70 |
key_values => [ { name => 'vSInBytes', per_second => 1 }, { name => 'display' } ], |
| 71 |
output_template => 'Traffic In : %s %s/s', |
| 72 |
output_change_bytes => 2, |
| 73 |
perfdatas => [ |
| 74 |
{ label => 'traffic_in', template => '%.2f', min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' }, |
| 75 |
], |
| 76 |
} |
| 77 |
}, |
| 78 |
{ label => 'out-traffic', set => { |
| 79 |
key_values => [ { name => 'vSOutBytes', per_second => 1 }, { name => 'display' } ], |
| 80 |
output_template => 'Traffic Out : %s %s/s', |
| 81 |
output_change_bytes => 2, |
| 82 |
perfdatas => [ |
| 83 |
{ label => 'traffic_out', template => '%.2f', min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' }, |
| 84 |
] |
| 85 |
} |
| 86 |
} |
| 87 |
]; |
| 88 |
} |
| 89 |
|
| 90 |
sub new { |
| 91 |
my ($class, %options) = @_; |
| 92 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); |
| 93 |
bless $self, $class; |
| 94 |
|
| 95 |
$options{options}->add_options(arguments => { |
| 96 |
'filter-name:s' => { name => 'filter_name' }, |
| 97 |
'warning-status:s' => { name => 'warning_status', default => '' }, |
| 98 |
'critical-status:s' => { name => 'critical_status', default => '%{status} !~ /inService|disabled|redirect/i' } |
| 99 |
}); |
| 100 |
|
| 101 |
return $self; |
| 102 |
} |
| 103 |
|
| 104 |
sub check_options { |
| 105 |
my ($self, %options) = @_; |
| 106 |
$self->SUPER::check_options(%options); |
| 107 |
|
| 108 |
$self->change_macros(macros => ['warning_status', 'critical_status']); |
| 109 |
} |
| 110 |
|
| 111 |
sub prefix_vs_output { |
| 112 |
my ($self, %options) = @_; |
| 113 |
|
| 114 |
return "Virtual server '" . $options{instance_value}->{display} . "' "; |
| 115 |
} |
| 116 |
|
| 117 |
my %map_state = ( |
| 118 |
1 => 'inService', |
| 119 |
2 => 'outOfService', |
| 120 |
4 => 'disabled', |
| 121 |
5 => 'sorry', |
| 122 |
6 => 'redirect', |
| 123 |
7 => 'errormsg', |
| 124 |
); |
| 125 |
my $mapping = { |
| 126 |
vSname => { oid => '.1.3.6.1.4.1.12196.13.1.1.13' }, |
| 127 |
vSstate => { oid => '.1.3.6.1.4.1.12196.13.1.1.14', map => \%map_state }, |
| 128 |
vSInBytes => { oid => '.1.3.6.1.4.1.12196.13.1.1.19' }, |
| 129 |
vSOutBytes => { oid => '.1.3.6.1.4.1.12196.13.1.1.20' }, |
| 130 |
vSActivConns => { oid => '.1.3.6.1.4.1.12196.13.1.1.21' }, |
| 131 |
}; |
| 132 |
|
| 133 |
my $oid_vsEntry = '.1.3.6.1.4.1.12196.13.1.1'; |
| 134 |
|
| 135 |
sub manage_selection { |
| 136 |
my ($self, %options) = @_; |
| 137 |
|
| 138 |
$self->{vs} = {}; |
| 139 |
my $snmp_result = $options{snmp}->get_table(oid => $oid_vsEntry, |
| 140 |
nothing_quit => 1); |
| 141 |
|
| 142 |
|
| 143 |
foreach my $oid (keys %{$snmp_result}) { |
| 144 |
next if ($oid !~ /^$mapping->{vSstate}->{oid}\.(.*)$/); |
| 145 |
my $instance = $1; |
| 146 |
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); |
| 147 |
|
| 148 |
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && |
| 149 |
$result->{vSname} !~ /$self->{option_results}->{filter_name}/) { |
| 150 |
$self->{output}->output_add(long_msg => "skipping '" . $result->{vSname} . "': no matching filter.", debug => 1); |
| 151 |
next; |
| 152 |
} |
| 153 |
|
| 154 |
$self->{vs}->{$instance} = { display => $result->{vSname}, |
| 155 |
status => $result->{vSstate}, |
| 156 |
vSInBytes => defined($result->{vSInBytes}) ? $result->{vSInBytes} * 8 : undef, |
| 157 |
vSOutBytes => defined($result->{vSOutBytes}) ? $result->{vSOutBytes} * 8 : undef, |
| 158 |
vSActivConns => $result->{vSActivConns} }; |
| 159 |
} |
| 160 |
|
| 161 |
if (scalar(keys %{$self->{vs}}) <= 0) { |
| 162 |
$self->{output}->add_option_msg(short_msg => "No virtual server found."); |
| 163 |
$self->{output}->option_exit(); |
| 164 |
} |
| 165 |
|
| 166 |
$self->{cache_name} = "kemp_" . $self->{mode} . '_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . |
| 167 |
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')); |
| 168 |
} |
| 169 |
|
| 170 |
1; |
| 171 |
|
| 172 |
__END__ |
| 173 |
|
| 174 |
=head1 MODE |
| 175 |
|
| 176 |
Check virtual server status. |
| 177 |
|
| 178 |
=over 8 |
| 179 |
|
| 180 |
=item B<--filter-counters> |
| 181 |
|
| 182 |
Only display some counters (regexp can be used). |
| 183 |
Example: --filter-counters='^status$' |
| 184 |
|
| 185 |
=item B<--filter-name> |
| 186 |
|
| 187 |
Filter virtual server name (can be a regexp). |
| 188 |
|
| 189 |
=item B<--warning-status> |
| 190 |
|
| 191 |
Define the conditions to match for the status to be WARNING. |
| 192 |
You can use the following variables: %{status}, %{display} |
| 193 |
|
| 194 |
=item B<--critical-status> |
| 195 |
|
| 196 |
Define the conditions to match for the status to be CRITICAL (default: '%{status} !~ /inService|disabled|redirect/i'). |
| 197 |
You can use the following variables: %{status}, %{display} |
| 198 |
|
| 199 |
=item B<--warning-*> |
| 200 |
|
| 201 |
Warning threshold. |
| 202 |
Can be: 'active', 'in-traffic' (b/s), 'out-traffic' (b/s). |
| 203 |
|
| 204 |
=item B<--critical-*> |
| 205 |
|
| 206 |
Critical threshold. |
| 207 |
Can be: 'active', 'in-traffic' (b/s), 'out-traffic' (b/s). |
| 208 |
|
| 209 |
=back |
| 210 |
|
| 211 |
=cut |