| 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::radware::alteon::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 |
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); |
| 29 |
|
| 30 |
sub custom_status_output { |
| 31 |
my ($self, %options) = @_; |
| 32 |
|
| 33 |
my $msg = 'state : ' . $self->{result_values}->{state}; |
| 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} . '_state'}; |
| 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 => 'vservers', type => 1, cb_prefix_output => 'prefix_vservers_output', message_multiple => 'All Virtual Servers are ok' } |
| 50 |
]; |
| 51 |
|
| 52 |
$self->{maps_counters}->{vservers} = [ |
| 53 |
{ label => 'status', threshold => 0, set => { |
| 54 |
key_values => [ { name => 'state' }, { 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 => 'traffic', set => { |
| 62 |
key_values => [ { name => 'traffic', per_second => 1 }, { name => 'display' } ], |
| 63 |
output_template => 'Traffic : %s %s/s', |
| 64 |
output_change_bytes => 2, |
| 65 |
perfdatas => [ |
| 66 |
{ label => 'traffic', template => '%.2f', min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' }, |
| 67 |
], |
| 68 |
} |
| 69 |
}, |
| 70 |
{ label => 'current-sessions', set => { |
| 71 |
key_values => [ { name => 'current_sessions' }, { name => 'display' } ], |
| 72 |
output_template => 'Current Sessions : %s', |
| 73 |
perfdatas => [ |
| 74 |
{ label => 'current_sessions', template => '%s', min => 0, label_extra_instance => 1, instance_use => 'display' }, |
| 75 |
], |
| 76 |
} |
| 77 |
}, |
| 78 |
{ label => 'total-sessions', set => { |
| 79 |
key_values => [ { name => 'total_sessions', diff => 1 }, { name => 'display' } ], |
| 80 |
output_template => 'Total Sessions : %s', |
| 81 |
perfdatas => [ |
| 82 |
{ label => 'total_sessions', template => '%s', min => 0, label_extra_instance => 1, instance_use => 'display' } |
| 83 |
] |
| 84 |
} |
| 85 |
} |
| 86 |
]; |
| 87 |
} |
| 88 |
|
| 89 |
sub prefix_vservers_output { |
| 90 |
my ($self, %options) = @_; |
| 91 |
|
| 92 |
return "Virtual Server '" . $options{instance_value}->{display} . "' "; |
| 93 |
} |
| 94 |
|
| 95 |
sub new { |
| 96 |
my ($class, %options) = @_; |
| 97 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); |
| 98 |
bless $self, $class; |
| 99 |
|
| 100 |
$options{options}->add_options(arguments => { |
| 101 |
'filter-name:s' => { name => 'filter_name' }, |
| 102 |
'warning-status:s' => { name => 'warning_status', default => '' }, |
| 103 |
'critical-status:s' => { name => 'critical_status', default => '' } |
| 104 |
}); |
| 105 |
|
| 106 |
return $self; |
| 107 |
} |
| 108 |
|
| 109 |
sub check_options { |
| 110 |
my ($self, %options) = @_; |
| 111 |
$self->SUPER::check_options(%options); |
| 112 |
|
| 113 |
$self->change_macros(macros => ['warning_status', 'critical_status']); |
| 114 |
} |
| 115 |
|
| 116 |
my %map_state = ( |
| 117 |
2 => 'enabled', |
| 118 |
3 => 'disabled', |
| 119 |
); |
| 120 |
|
| 121 |
my $mapping = { |
| 122 |
slbCurCfgVirtServerState => { oid => '.1.3.6.1.4.1.1872.2.5.4.1.1.4.2.1.4', map => \%map_state }, |
| 123 |
slbCurCfgVirtServerVname => { oid => '.1.3.6.1.4.1.1872.2.5.4.1.1.4.2.1.10' }, |
| 124 |
slbCurCfgVirtServerAvail => { oid => '.1.3.6.1.4.1.1872.2.5.4.1.1.4.2.1.8' }, # can't get mapping for that. If someones has it, i'm interested :) |
| 125 |
}; |
| 126 |
my $mapping2 = { |
| 127 |
slbStatVServerCurrSessions => { oid => '.1.3.6.1.4.1.1872.2.5.4.2.4.1.2' }, |
| 128 |
slbStatVServerTotalSessions => { oid => '.1.3.6.1.4.1.1872.2.5.4.2.4.1.3' }, |
| 129 |
slbStatVServerHCOctetsLow32 => { oid => '.1.3.6.1.4.1.1872.2.5.4.2.4.1.5' }, |
| 130 |
slbStatVServerHCOctetsHigh32 => { oid => '.1.3.6.1.4.1.1872.2.5.4.2.4.1.6' }, |
| 131 |
slbStatVServerHCOctets => { oid => '.1.3.6.1.4.1.1872.2.5.4.2.4.1.13' }, |
| 132 |
}; |
| 133 |
|
| 134 |
sub manage_selection { |
| 135 |
my ($self, %options) = @_; |
| 136 |
|
| 137 |
my $snmp_result = $options{snmp}->get_multiple_table(oids => [ |
| 138 |
{ oid => $mapping->{slbCurCfgVirtServerState}->{oid} }, |
| 139 |
{ oid => $mapping->{slbCurCfgVirtServerVname}->{oid} }, |
| 140 |
], return_type => 1, nothing_quit => 1); |
| 141 |
$self->{vservers} = {}; |
| 142 |
foreach my $oid (keys %{$snmp_result}) { |
| 143 |
next if ($oid !~ /^$mapping->{slbCurCfgVirtServerVname}->{oid}\.(.*)$/); |
| 144 |
my $instance = $1; |
| 145 |
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); |
| 146 |
|
| 147 |
if (!defined($result->{slbCurCfgVirtServerVname}) || $result->{slbCurCfgVirtServerVname} eq '') { |
| 148 |
$self->{output}->output_add(long_msg => "skipping Virtual Server '$instance': cannot get a name. please set it.", debug => 1); |
| 149 |
next; |
| 150 |
} |
| 151 |
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && |
| 152 |
$result->{slbCurCfgVirtServerVname} !~ /$self->{option_results}->{filter_name}/) { |
| 153 |
$self->{output}->output_add(long_msg => "skipping Virtual Server '" . $result->{slbCurCfgVirtServerVname} . "'.", debug => 1); |
| 154 |
next; |
| 155 |
} |
| 156 |
|
| 157 |
$self->{vservers}->{$instance} = { display => $result->{slbCurCfgVirtServerVname}, state => $result->{slbCurCfgVirtServerState} }; |
| 158 |
} |
| 159 |
|
| 160 |
$options{snmp}->load(oids => [$mapping2->{slbStatVServerCurrSessions}->{oid}, $mapping2->{slbStatVServerTotalSessions}->{oid}, |
| 161 |
$mapping2->{slbStatVServerHCOctetsLow32}->{oid}, $mapping2->{slbStatVServerHCOctetsHigh32}->{oid}, |
| 162 |
$mapping2->{slbStatVServerHCOctets}->{oid} |
| 163 |
], |
| 164 |
instances => [keys %{$self->{vservers}}], instance_regexp => '^(.*)$'); |
| 165 |
$snmp_result = $options{snmp}->get_leef(nothing_quit => 1); |
| 166 |
|
| 167 |
foreach (keys %{$self->{vservers}}) { |
| 168 |
my $result = $options{snmp}->map_instance(mapping => $mapping2, results => $snmp_result, instance => $_); |
| 169 |
|
| 170 |
$self->{vservers}->{$_}->{traffic} = (defined($result->{slbStatVServerHCOctets}) ? $result->{slbStatVServerHCOctets} * 8 : |
| 171 |
(($result->{slbStatVServerHCOctetsHigh32} << 32) + $result->{slbStatVServerHCOctetsLow32})) * 8; |
| 172 |
$self->{vservers}->{$_}->{current_sessions} = $result->{slbStatVServerCurrSessions}; |
| 173 |
$self->{vservers}->{$_}->{total_sessions} = $result->{slbStatVServerTotalSessions}; |
| 174 |
} |
| 175 |
|
| 176 |
if (scalar(keys %{$self->{vservers}}) <= 0) { |
| 177 |
$self->{output}->add_option_msg(short_msg => "No virtual server found."); |
| 178 |
$self->{output}->option_exit(); |
| 179 |
} |
| 180 |
|
| 181 |
$self->{cache_name} = "alteon_" . $self->{mode} . '_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . |
| 182 |
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' . |
| 183 |
(defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all')); |
| 184 |
} |
| 185 |
|
| 186 |
1; |
| 187 |
|
| 188 |
__END__ |
| 189 |
|
| 190 |
=head1 MODE |
| 191 |
|
| 192 |
Check vservers status. |
| 193 |
|
| 194 |
=over 8 |
| 195 |
|
| 196 |
=item B<--warning-*> |
| 197 |
|
| 198 |
Warning threshold. |
| 199 |
Can be: 'traffic', 'total-sessions', 'current-sessions'. |
| 200 |
|
| 201 |
=item B<--critical-*> |
| 202 |
|
| 203 |
Critical threshold. |
| 204 |
Can be: 'traffic', 'total-sessions', 'current-sessions'. |
| 205 |
|
| 206 |
=item B<--warning-status> |
| 207 |
|
| 208 |
Define the conditions to match for the status to be WARNING. |
| 209 |
You can use the following variables: %{state}, %{display} |
| 210 |
|
| 211 |
=item B<--critical-status> |
| 212 |
|
| 213 |
Define the conditions to match for the status to be CRITICAL. |
| 214 |
You can use the following variables: %{state}, %{display} |
| 215 |
|
| 216 |
=item B<--filter-name> |
| 217 |
|
| 218 |
Filter by virtual server name (can be a regexp). |
| 219 |
|
| 220 |
=back |
| 221 |
|
| 222 |
=cut |