| 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::fortinet::fortiadc::snmp::mode::virtualservers; |
| 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_throughput_perfdata { |
| 30 |
my ($self, %options) = @_; |
| 31 |
|
| 32 |
$self->{output}->perfdata_add( |
| 33 |
nlabel => $self->{nlabel}, |
| 34 |
unit => 'b/s', |
| 35 |
instances => [$self->{result_values}->{vdom}, $self->{result_values}->{name}], |
| 36 |
value => $self->{result_values}->{throughput}, |
| 37 |
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}), |
| 38 |
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}), |
| 39 |
min => 0 |
| 40 |
); |
| 41 |
} |
| 42 |
|
| 43 |
sub custom_connections_perfdata { |
| 44 |
my ($self, %options) = @_; |
| 45 |
|
| 46 |
$self->{output}->perfdata_add( |
| 47 |
nlabel => $self->{nlabel}, |
| 48 |
instances => [$self->{result_values}->{vdom}, $self->{result_values}->{name}], |
| 49 |
value => $self->{result_values}->{connections}, |
| 50 |
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}), |
| 51 |
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}), |
| 52 |
min => 0 |
| 53 |
); |
| 54 |
} |
| 55 |
|
| 56 |
sub custom_status_output { |
| 57 |
my ($self, %options) = @_; |
| 58 |
|
| 59 |
return sprintf( |
| 60 |
"status: %s [%s]", |
| 61 |
$self->{result_values}->{status}, |
| 62 |
$self->{result_values}->{state} |
| 63 |
); |
| 64 |
} |
| 65 |
|
| 66 |
sub vs_long_output { |
| 67 |
my ($self, %options) = @_; |
| 68 |
|
| 69 |
return sprintf( |
| 70 |
"checking virtual server '%s' [vdom: %s]", |
| 71 |
$options{instance_value}->{name}, |
| 72 |
$options{instance_value}->{vdom} |
| 73 |
); |
| 74 |
} |
| 75 |
|
| 76 |
sub prefix_vs_output { |
| 77 |
my ($self, %options) = @_; |
| 78 |
|
| 79 |
return sprintf( |
| 80 |
"virtual server '%s' [vdom: %s] ", |
| 81 |
$options{instance_value}->{name}, |
| 82 |
$options{instance_value}->{vdom} |
| 83 |
); |
| 84 |
} |
| 85 |
|
| 86 |
sub prefix_global_output { |
| 87 |
my ($self, %options) = @_; |
| 88 |
|
| 89 |
return 'Virtual servers '; |
| 90 |
} |
| 91 |
|
| 92 |
sub set_counters { |
| 93 |
my ($self, %options) = @_; |
| 94 |
|
| 95 |
$self->{maps_counters_type} = [ |
| 96 |
{ name => 'global', type => 0, cb_prefix_output => 'prefix_global_output', }, |
| 97 |
{ name => 'vs', type => 3, cb_prefix_output => 'prefix_vs_output', cb_long_output => 'vs_long_output', |
| 98 |
indent_long_output => ' ', message_multiple => 'All virtual servers are ok', |
| 99 |
group => [ |
| 100 |
{ name => 'status', type => 0, skipped_code => { -10 => 1 } }, |
| 101 |
{ name => 'stats', type => 0, skipped_code => { -10 => 1 } } |
| 102 |
] |
| 103 |
} |
| 104 |
]; |
| 105 |
|
| 106 |
$self->{maps_counters}->{global} = [ |
| 107 |
{ label => 'virtualservers-detected', display_ok => 0, nlabel => 'virtual_servers.detected.count', set => { |
| 108 |
key_values => [ { name => 'detected' } ], |
| 109 |
output_template => 'detected: %s', |
| 110 |
perfdatas => [ |
| 111 |
{ template => '%s', min => 0 } |
| 112 |
] |
| 113 |
} |
| 114 |
}, |
| 115 |
{ label => 'virtualservers-healthy', display_ok => 0, nlabel => 'virtual_servers.healthy.count', set => { |
| 116 |
key_values => [ { name => 'healthy' } ], |
| 117 |
output_template => 'healthy: %s', |
| 118 |
perfdatas => [ |
| 119 |
{ template => '%s', min => 0 } |
| 120 |
] |
| 121 |
} |
| 122 |
} |
| 123 |
]; |
| 124 |
|
| 125 |
$self->{maps_counters}->{status} = [ |
| 126 |
{ |
| 127 |
label => 'status', |
| 128 |
type => 2, |
| 129 |
critical_default => '%{status} eq "unhealthy"', |
| 130 |
set => { |
| 131 |
key_values => [ |
| 132 |
{ name => 'state' }, { name => 'status' }, |
| 133 |
{ name => 'name' }, { name => 'vdom' } |
| 134 |
], |
| 135 |
closure_custom_output => $self->can('custom_status_output'), |
| 136 |
closure_custom_perfdata => sub { return 0; }, |
| 137 |
closure_custom_threshold_check => \&catalog_status_threshold_ng |
| 138 |
} |
| 139 |
} |
| 140 |
]; |
| 141 |
|
| 142 |
$self->{maps_counters}->{stats} = [ |
| 143 |
{ label => 'virtualserver-connections', nlabel => 'virtual_server.connections.count', set => { |
| 144 |
key_values => [ { name => 'connections' }, { name => 'name' }, { name => 'vdom' } ], |
| 145 |
output_template => 'connections: %s', |
| 146 |
closure_custom_perfdata => $self->can('custom_connections_perfdata') |
| 147 |
} |
| 148 |
}, |
| 149 |
{ label => 'virtualserver-throughput', nlabel => 'virtual_server.throughput.bitspersecond', set => { |
| 150 |
key_values => [ { name => 'throughput' }, { name => 'name' }, { name => 'vdom' } ], |
| 151 |
output_template => 'throughput: %.2f %s/s', |
| 152 |
output_change_bytes => 2, |
| 153 |
closure_custom_perfdata => $self->can('custom_throughput_perfdata') |
| 154 |
} |
| 155 |
} |
| 156 |
]; |
| 157 |
} |
| 158 |
|
| 159 |
sub new { |
| 160 |
my ($class, %options) = @_; |
| 161 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); |
| 162 |
bless $self, $class; |
| 163 |
|
| 164 |
$options{options}->add_options(arguments => { |
| 165 |
'filter-name:s' => { name => 'filter_name' }, |
| 166 |
'filter-vdom:s' => { name => 'filter_vdom' } |
| 167 |
}); |
| 168 |
|
| 169 |
return $self; |
| 170 |
} |
| 171 |
|
| 172 |
my $map_plex_status = { |
| 173 |
1 => 'offline', 2 => 'resyncing', 3 => 'online' |
| 174 |
}; |
| 175 |
|
| 176 |
my $mapping = { |
| 177 |
state => { oid => '.1.3.6.1.4.1.12356.112.3.2.1.3' }, # fadcVSStatus |
| 178 |
status => { oid => '.1.3.6.1.4.1.12356.112.3.2.1.4' }, # fadcVSHealth |
| 179 |
connections => { oid => '.1.3.6.1.4.1.12356.112.3.2.1.6' }, # fadcVSConcurrent |
| 180 |
throughput => { oid => '.1.3.6.1.4.1.12356.112.3.2.1.7' }, # fadcVSThroughputKbps |
| 181 |
vdom => { oid => '.1.3.6.1.4.1.12356.112.3.2.1.8' } # fadcVSVdom |
| 182 |
}; |
| 183 |
|
| 184 |
sub manage_selection { |
| 185 |
my ($self, %options) = @_; |
| 186 |
|
| 187 |
my $oid_vsName = '.1.3.6.1.4.1.12356.112.3.2.1.2'; # fadcVSName |
| 188 |
my $snmp_result = $options{snmp}->get_table(oid => $oid_vsName, nothing_quit => 1); |
| 189 |
|
| 190 |
$self->{global} = { detected => 0, healthy => 0, unhealthy => 0 }; |
| 191 |
$self->{vs} = {}; |
| 192 |
foreach my $oid (keys %$snmp_result) { |
| 193 |
$oid =~ /^$oid_vsName\.(.*)$/; |
| 194 |
my $instance = $1; |
| 195 |
my $name = $snmp_result->{$oid}; |
| 196 |
|
| 197 |
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && |
| 198 |
$name !~ /$self->{option_results}->{filter_name}/) { |
| 199 |
$self->{output}->output_add(long_msg => "skipping virtual server '" . $name . "'.", debug => 1); |
| 200 |
next; |
| 201 |
} |
| 202 |
|
| 203 |
$self->{vs}->{$instance} = { name => $name }; |
| 204 |
} |
| 205 |
|
| 206 |
return if (scalar(keys %{$self->{vs}}) <= 0); |
| 207 |
|
| 208 |
$options{snmp}->load( |
| 209 |
oids => [ |
| 210 |
map($_->{oid}, values(%$mapping)) |
| 211 |
], |
| 212 |
instances => [ map($_, keys %{$self->{vs}}) ], |
| 213 |
instance_regexp => '^(.*)$' |
| 214 |
); |
| 215 |
$snmp_result = $options{snmp}->get_leef(); |
| 216 |
|
| 217 |
foreach (keys %{$self->{vs}}) { |
| 218 |
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $_); |
| 219 |
if (defined($self->{option_results}->{filter_vdom}) && $self->{option_results}->{filter_vdom} ne '' && |
| 220 |
$result->{vdom} !~ /$self->{option_results}->{filter_vdom}/) { |
| 221 |
$self->{output}->output_add(long_msg => "skipping vdom '" . $result->{vdom} . "'.", debug => 1); |
| 222 |
next; |
| 223 |
} |
| 224 |
|
| 225 |
$self->{vs}->{$_}->{vdom} = $result->{vdom}; |
| 226 |
$self->{vs}->{$_}->{status} = { |
| 227 |
name => $self->{vs}->{$_}->{name}, |
| 228 |
state => lc($result->{state}), |
| 229 |
status => lc($result->{status}), |
| 230 |
vdom => $result->{vdom} |
| 231 |
}; |
| 232 |
$self->{vs}->{$_}->{stats} = { |
| 233 |
name => $self->{vs}->{$_}->{name}, |
| 234 |
vdom => $result->{vdom}, |
| 235 |
connections => $result->{connections}, |
| 236 |
throughput => $result->{throughput} * 1000 |
| 237 |
}; |
| 238 |
|
| 239 |
$self->{global}->{detected}++; |
| 240 |
$self->{global}->{ lc($result->{status}) }++; |
| 241 |
} |
| 242 |
} |
| 243 |
|
| 244 |
1; |
| 245 |
|
| 246 |
__END__ |
| 247 |
|
| 248 |
=head1 MODE |
| 249 |
|
| 250 |
Check virtual servers. |
| 251 |
|
| 252 |
=over 8 |
| 253 |
|
| 254 |
=item B<--filter-name> |
| 255 |
|
| 256 |
Filter virtual servers by name. |
| 257 |
|
| 258 |
=item B<--filter-vdom> |
| 259 |
|
| 260 |
Filter virtual servers by vdom name. |
| 261 |
|
| 262 |
=item B<--unknown-status> |
| 263 |
|
| 264 |
Define the conditions to match for the status to be UNKNOWN. |
| 265 |
You can use the following variables: %{status}, %{state}, %{name}, %{vdom} |
| 266 |
|
| 267 |
=item B<--warning-status> |
| 268 |
|
| 269 |
Define the conditions to match for the status to be WARNING. |
| 270 |
You can use the following variables: %{status}, %{state}, %{name}, %{vdom} |
| 271 |
|
| 272 |
=item B<--critical-status> |
| 273 |
|
| 274 |
Define the conditions to match for the status to be CRITICAL (default: '%{status} eq "unhealthy"'). |
| 275 |
You can use the following variables: %{status}, %{state}, %{name}, %{vdom} |
| 276 |
|
| 277 |
=item B<--warning-*> B<--critical-*> |
| 278 |
|
| 279 |
Thresholds. |
| 280 |
Can be: 'virtualservers-detected', 'virtualservers-healthy', |
| 281 |
'virtualserver-connections', 'virtualserver-throughput'. |
| 282 |
|
| 283 |
=back |
| 284 |
|
| 285 |
=cut |