| 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::citrix::netscaler::snmp::mode::vserverstatus; |
| 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 => 'vservers', type => 1, cb_prefix_output => 'prefix_vservers_output', message_multiple => 'All virtual servers are ok', skipped_code => { -10 => 1 } } |
| 34 |
]; |
| 35 |
|
| 36 |
$self->{maps_counters}->{vservers} = [ |
| 37 |
{ label => 'status', threshold => 0, set => { |
| 38 |
key_values => [ { name => 'state' } ], |
| 39 |
closure_custom_output => $self->can('custom_status_output'), |
| 40 |
closure_custom_perfdata => sub { return 0; }, |
| 41 |
closure_custom_threshold_check => $self->can('custom_threshold_output') |
| 42 |
} |
| 43 |
}, |
| 44 |
{ label => 'health', nlabel => 'vserver.health.percentage', set => { |
| 45 |
key_values => [ { name => 'health' }, { name => 'display' } ], |
| 46 |
output_template => 'health: %.2f %%', |
| 47 |
perfdatas => [ |
| 48 |
{ label => 'health', template => '%.2f', |
| 49 |
unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' } |
| 50 |
] |
| 51 |
} |
| 52 |
}, |
| 53 |
{ label => 'in-traffic', nlabel => 'vserver.traffic.in.bitspersecond', set => { |
| 54 |
key_values => [ { name => 'in', per_second => 1 }, { name => 'display' } ], |
| 55 |
output_template => 'traffic in: %s %s/s', |
| 56 |
output_change_bytes => 2, |
| 57 |
perfdatas => [ |
| 58 |
{ label => 'traffic_in', template => '%.2f', |
| 59 |
min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' } |
| 60 |
] |
| 61 |
} |
| 62 |
}, |
| 63 |
{ label => 'out-traffic', nlabel => 'vserver.traffic.out.bitspersecond', set => { |
| 64 |
key_values => [ { name => 'out', per_second => 1 }, { name => 'display' } ], |
| 65 |
output_template => 'traffic out: %s %s/s', |
| 66 |
output_change_bytes => 2, |
| 67 |
perfdatas => [ |
| 68 |
{ label => 'traffic_out', template => '%.2f', |
| 69 |
min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' } |
| 70 |
] |
| 71 |
} |
| 72 |
}, |
| 73 |
{ label => 'clients', nlabel => 'vserver.connections.client.count', set => { |
| 74 |
key_values => [ { name => 'clients', diff => 1 }, { name => 'display' } ], |
| 75 |
output_template => 'total client connections: %s', |
| 76 |
perfdatas => [ |
| 77 |
{ label => 'clients', template => '%s', |
| 78 |
min => 0, label_extra_instance => 1, instance_use => 'display' } |
| 79 |
] |
| 80 |
} |
| 81 |
}, |
| 82 |
{ label => 'servers', nlabel => 'vserver.connections.server.count', set => { |
| 83 |
key_values => [ { name => 'servers', diff => 1 }, { name => 'display' } ], |
| 84 |
output_template => 'total server connections: %s', |
| 85 |
perfdatas => [ |
| 86 |
{ label => 'servers', template => '%s', |
| 87 |
min => 0, label_extra_instance => 1, instance_use => 'display' } |
| 88 |
] |
| 89 |
} |
| 90 |
} |
| 91 |
]; |
| 92 |
} |
| 93 |
|
| 94 |
sub prefix_vservers_output { |
| 95 |
my ($self, %options) = @_; |
| 96 |
|
| 97 |
return "Virtual server '" . $options{instance_value}->{display} . "' "; |
| 98 |
} |
| 99 |
|
| 100 |
my $overload_th = {}; |
| 101 |
|
| 102 |
my $thresholds = { |
| 103 |
vs => [ |
| 104 |
['unknown', 'UNKNOWN'], |
| 105 |
['down|outOfService|transitionToOutOfService|transitionToOutOfServiceDown', 'CRITICAL'], |
| 106 |
['up', 'OK'] |
| 107 |
] |
| 108 |
}; |
| 109 |
|
| 110 |
sub get_severity { |
| 111 |
my (%options) = @_; |
| 112 |
my $status = 'UNKNOWN'; # default |
| 113 |
|
| 114 |
if (defined($overload_th->{$options{section}})) { |
| 115 |
foreach (@{$overload_th->{$options{section}}}) { |
| 116 |
if ($options{value} =~ /$_->{filter}/i) { |
| 117 |
$status = $_->{status}; |
| 118 |
return $status; |
| 119 |
} |
| 120 |
} |
| 121 |
} |
| 122 |
foreach (@{$thresholds->{$options{section}}}) { |
| 123 |
if ($options{value} =~ /$$_[0]/i) { |
| 124 |
$status = $$_[1]; |
| 125 |
return $status; |
| 126 |
} |
| 127 |
} |
| 128 |
|
| 129 |
return $status; |
| 130 |
} |
| 131 |
|
| 132 |
sub custom_threshold_output { |
| 133 |
my ($self, %options) = @_; |
| 134 |
|
| 135 |
return get_severity(section => 'vs', value => $self->{result_values}->{state}); |
| 136 |
} |
| 137 |
|
| 138 |
sub custom_status_output { |
| 139 |
my ($self, %options) = @_; |
| 140 |
|
| 141 |
return 'state: ' . $self->{result_values}->{state}; |
| 142 |
} |
| 143 |
|
| 144 |
sub new { |
| 145 |
my ($class, %options) = @_; |
| 146 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); |
| 147 |
bless $self, $class; |
| 148 |
|
| 149 |
$options{options}->add_options(arguments => { |
| 150 |
'filter-name:s' => { name => 'filter_name' }, |
| 151 |
'filter-type:s' => { name => 'filter_type' }, |
| 152 |
'force-counters64' => { name => 'force_counters64' }, |
| 153 |
'threshold-overload:s@' => { name => 'threshold_overload' } |
| 154 |
}); |
| 155 |
|
| 156 |
return $self; |
| 157 |
} |
| 158 |
|
| 159 |
sub check_options { |
| 160 |
my ($self, %options) = @_; |
| 161 |
$self->SUPER::check_options(%options); |
| 162 |
|
| 163 |
foreach my $val (@{$self->{option_results}->{threshold_overload}}) { |
| 164 |
if ($val !~ /^(.*?),(.*)$/) { |
| 165 |
$self->{output}->add_option_msg(short_msg => "Wrong threshold-overload option '" . $val . "'."); |
| 166 |
$self->{output}->option_exit(); |
| 167 |
} |
| 168 |
my ($section, $status, $filter) = ('vs', $1, $2); |
| 169 |
if ($self->{output}->is_litteral_status(status => $status) == 0) { |
| 170 |
$self->{output}->add_option_msg(short_msg => "Wrong threshold-overload status '" . $val . "'."); |
| 171 |
$self->{output}->option_exit(); |
| 172 |
} |
| 173 |
$overload_th->{$section} = [] if (!defined($overload_th->{$section})); |
| 174 |
push @{$overload_th->{$section}}, {filter => $filter, status => $status}; |
| 175 |
} |
| 176 |
} |
| 177 |
|
| 178 |
my %map_vs_type = ( |
| 179 |
0 => 'unknown', |
| 180 |
1 => 'loadbalancing', |
| 181 |
2 => 'loadbalancinggroup', |
| 182 |
3 => 'sslvpn', |
| 183 |
4 => 'contentswitching', |
| 184 |
5 => 'cacheredirection', |
| 185 |
); |
| 186 |
|
| 187 |
my %map_vs_status = ( |
| 188 |
1 => 'down', |
| 189 |
2 => 'unknown', |
| 190 |
3 => 'busy', |
| 191 |
4 => 'outOfService', |
| 192 |
5 => 'transitionToOutOfService', |
| 193 |
7 => 'up', |
| 194 |
8 => 'transitionToOutOfServiceDown' |
| 195 |
); |
| 196 |
|
| 197 |
my $mapping = { |
| 198 |
vsvrState => { oid => '.1.3.6.1.4.1.5951.4.1.3.1.1.5', map => \%map_vs_status }, |
| 199 |
vsvrFullName => { oid => '.1.3.6.1.4.1.5951.4.1.3.1.1.59' }, |
| 200 |
vsvrEntityType => { oid => '.1.3.6.1.4.1.5951.4.1.3.1.1.64', map => \%map_vs_type } |
| 201 |
}; |
| 202 |
my $mapping2 = { |
| 203 |
vsvrTotalRequestBytesLow => { oid => '.1.3.6.1.4.1.5951.4.1.3.1.1.13' }, |
| 204 |
vsvrTotalRequestBytesHigh => { oid => '.1.3.6.1.4.1.5951.4.1.3.1.1.14' }, |
| 205 |
vsvrTotalResponseBytesLow => { oid => '.1.3.6.1.4.1.5951.4.1.3.1.1.17' }, |
| 206 |
vsvrTotalResponseBytesHigh => { oid => '.1.3.6.1.4.1.5951.4.1.3.1.1.18' }, |
| 207 |
vsvrTotalRequestBytes => { oid => '.1.3.6.1.4.1.5951.4.1.3.1.1.31' }, |
| 208 |
vsvrTotalResponseBytes => { oid => '.1.3.6.1.4.1.5951.4.1.3.1.1.33' }, |
| 209 |
vsvrTotalClients => { oid => '.1.3.6.1.4.1.5951.4.1.3.1.1.56' }, |
| 210 |
vsvrHealth => { oid => '.1.3.6.1.4.1.5951.4.1.3.1.1.62' }, |
| 211 |
vsvrTotalServers => { oid => '.1.3.6.1.4.1.5951.4.1.3.1.1.65' } |
| 212 |
}; |
| 213 |
|
| 214 |
sub manage_selection { |
| 215 |
my ($self, %options) = @_; |
| 216 |
|
| 217 |
my $snmp_result = $options{snmp}->get_multiple_table( |
| 218 |
oids => [ |
| 219 |
{ oid => $mapping->{vsvrFullName}->{oid} }, |
| 220 |
{ oid => $mapping->{vsvrState}->{oid} }, |
| 221 |
{ oid => $mapping->{vsvrEntityType}->{oid} } |
| 222 |
], |
| 223 |
return_type => 1, |
| 224 |
nothing_quit => 1 |
| 225 |
); |
| 226 |
|
| 227 |
$self->{vservers} = {}; |
| 228 |
foreach my $oid (keys %{$snmp_result}) { |
| 229 |
next if ($oid !~ /^$mapping->{vsvrFullName}->{oid}\.(.*)$/); |
| 230 |
my $instance = $1; |
| 231 |
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); |
| 232 |
|
| 233 |
if (defined($self->{option_results}->{filter_type}) && $self->{option_results}->{filter_type} ne '' && |
| 234 |
$result->{vsvrEntityType} !~ /$self->{option_results}->{filter_type}/) { |
| 235 |
$self->{output}->output_add(long_msg => "skipping Virtual Server '" . $result->{vsvrFullName} . "'.", debug => 1); |
| 236 |
next; |
| 237 |
} |
| 238 |
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && |
| 239 |
$result->{vsvrFullName} !~ /$self->{option_results}->{filter_name}/) { |
| 240 |
$self->{output}->output_add(long_msg => "skipping Virtual Server '" . $result->{vsvrFullName} . "'.", debug => 1); |
| 241 |
next; |
| 242 |
} |
| 243 |
|
| 244 |
$self->{vservers}->{$instance} = { |
| 245 |
display => $result->{vsvrFullName}, |
| 246 |
type => $result->{vsvrEntityType}, |
| 247 |
state => $result->{vsvrState} |
| 248 |
}; |
| 249 |
} |
| 250 |
|
| 251 |
if (scalar(keys %{$self->{vservers}}) <= 0) { |
| 252 |
$self->{output}->add_option_msg(short_msg => "No virtual server found."); |
| 253 |
$self->{output}->option_exit(); |
| 254 |
} |
| 255 |
|
| 256 |
$options{snmp}->load( |
| 257 |
oids => defined($self->{option_results}->{force_counters64}) ? [ |
| 258 |
$mapping2->{vsvrTotalRequestBytes}->{oid}, $mapping2->{vsvrTotalResponseBytes}->{oid}, |
| 259 |
$mapping2->{vsvrTotalClients}->{oid}, $mapping2->{vsvrHealth}->{oid}, $mapping2->{vsvrTotalServers}->{oid} |
| 260 |
] : [ |
| 261 |
$mapping2->{vsvrTotalRequestBytesLow}->{oid}, $mapping2->{vsvrTotalRequestBytesHigh}->{oid}, |
| 262 |
$mapping2->{vsvrTotalResponseBytesLow}->{oid}, $mapping2->{vsvrTotalResponseBytesHigh}->{oid}, |
| 263 |
$mapping2->{vsvrTotalRequestBytes}->{oid}, $mapping2->{vsvrTotalResponseBytes}->{oid}, |
| 264 |
$mapping2->{vsvrTotalClients}->{oid}, $mapping2->{vsvrHealth}->{oid}, $mapping2->{vsvrTotalServers}->{oid} |
| 265 |
], |
| 266 |
instances => [keys %{$self->{vservers}}], instance_regexp => '^(.*)$' |
| 267 |
); |
| 268 |
$snmp_result = $options{snmp}->get_leef(nothing_quit => 1); |
| 269 |
|
| 270 |
foreach (keys %{$self->{vservers}}) { |
| 271 |
my $result = $options{snmp}->map_instance(mapping => $mapping2, results => $snmp_result, instance => $_); |
| 272 |
|
| 273 |
$self->{vservers}->{$_}->{out} = defined($result->{vsvrTotalResponseBytes}) ? $result->{vsvrTotalResponseBytes} * 8 : |
| 274 |
(($result->{vsvrTotalResponseBytesHigh} << 32) + $result->{vsvrTotalResponseBytesLow}) * 8; |
| 275 |
$self->{vservers}->{$_}->{in} = defined($result->{vsvrTotalRequestBytes}) ? $result->{vsvrTotalRequestBytes} * 8 : |
| 276 |
(($result->{vsvrTotalRequestBytesHigh} << 32) + $result->{vsvrTotalRequestBytesLow}) * 8; |
| 277 |
if ($self->{vservers}->{$_}->{type} ne 'sslvpn') { |
| 278 |
$self->{vservers}->{$_}->{health} = $result->{vsvrHealth}; |
| 279 |
} |
| 280 |
$self->{vservers}->{$_}->{clients} = $result->{vsvrTotalClients}; |
| 281 |
$self->{vservers}->{$_}->{servers} = $result->{vsvrTotalServers}; |
| 282 |
} |
| 283 |
|
| 284 |
$self->{cache_name} = "citrix_netscaler_" . $self->{mode} . '_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . |
| 285 |
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' . |
| 286 |
(defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all')) . '_' . |
| 287 |
(defined($self->{option_results}->{filter_type}) ? md5_hex($self->{option_results}->{filter_type}) : md5_hex('all')); |
| 288 |
} |
| 289 |
|
| 290 |
1; |
| 291 |
|
| 292 |
__END__ |
| 293 |
|
| 294 |
=head1 MODE |
| 295 |
|
| 296 |
Check vservers status and health. |
| 297 |
|
| 298 |
=over 8 |
| 299 |
|
| 300 |
=item B<--warning-*> |
| 301 |
|
| 302 |
Warning threshold. |
| 303 |
Can be: 'in-traffic', 'out-traffic', 'health' (%), |
| 304 |
'clients', 'servers'. |
| 305 |
|
| 306 |
=item B<--critical-*> |
| 307 |
|
| 308 |
Critical threshold. |
| 309 |
Can be: 'in-traffic', 'out-traffic', 'health' (%), |
| 310 |
'clients', 'servers'. |
| 311 |
|
| 312 |
=item B<--filter-name> |
| 313 |
|
| 314 |
Filter by virtual server name (can be a regexp). |
| 315 |
|
| 316 |
=item B<--filter-type> |
| 317 |
|
| 318 |
Filter which type of vserver (can be a regexp). |
| 319 |
|
| 320 |
=item B<--force-counters64> |
| 321 |
|
| 322 |
Force to use 64 bits counters only. Can be used to improve performance, |
| 323 |
or to solve a missing counters bug. |
| 324 |
|
| 325 |
=item B<--threshold-overload> |
| 326 |
|
| 327 |
Use this option to override the status returned by the plugin when the status label matches a regular expression (syntax: status,regexp). |
| 328 |
Example: --threshold-overload='CRITICAL,^(?!(green)$)' |
| 329 |
|
| 330 |
=back |
| 331 |
|
| 332 |
=cut |