| 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::appacceleration::snmp::mode::serviceclassusage; |
| 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 => 'sc', type => 1, cb_prefix_output => 'prefix_sc_output', message_multiple => 'All Service Class are ok' } |
| 34 |
]; |
| 35 |
|
| 36 |
$self->{maps_counters}->{sc} = [ |
| 37 |
{ label => 'current-acc-con', set => { |
| 38 |
key_values => [ { name => 'wsScsCurrentAcceleratedConnections' }, { name => 'display' } ], |
| 39 |
output_template => 'Current Accelerated Connections : %s', |
| 40 |
perfdatas => [ |
| 41 |
{ label => 'current_accelerated_connections', template => '%s', |
| 42 |
min => 0, label_extra_instance => 1, instance_use => 'display' }, |
| 43 |
], |
| 44 |
} |
| 45 |
}, |
| 46 |
{ label => 'total-acc-con', set => { |
| 47 |
key_values => [ { name => 'wsScsTotalAcceleratedConnections', diff => 1 }, { name => 'display' } ], |
| 48 |
output_template => 'Total Accelerated Connections : %s', |
| 49 |
perfdatas => [ |
| 50 |
{ label => 'total_accelerated_connections', template => '%s', |
| 51 |
min => 0, label_extra_instance => 1, instance_use => 'display' }, |
| 52 |
], |
| 53 |
} |
| 54 |
}, |
| 55 |
{ label => 'total-nonacc-con', set => { |
| 56 |
key_values => [ { name => 'wsScsTotalNonAcceleratedConnections', diff => 1 }, { name => 'display' } ], |
| 57 |
output_template => 'Total Non Accelerated Connections : %s', |
| 58 |
perfdatas => [ |
| 59 |
{ label => 'total_nonaccelerated_connections', template => '%s', |
| 60 |
min => 0, label_extra_instance => 1, instance_use => 'display' }, |
| 61 |
], |
| 62 |
} |
| 63 |
}, |
| 64 |
{ label => 'traffic-in', set => { |
| 65 |
key_values => [ { name => 'wsScsPreCompressReceivedOctets', per_second => 1 }, { name => 'display' } ], |
| 66 |
output_template => 'Traffic In : %s %s/s', |
| 67 |
output_change_bytes => 2, |
| 68 |
perfdatas => [ |
| 69 |
{ label => 'traffic_in', template => '%.2f', |
| 70 |
min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' }, |
| 71 |
], |
| 72 |
} |
| 73 |
}, |
| 74 |
{ label => 'traffic-in-compressed', set => { |
| 75 |
key_values => [ { name => 'wsScsCompressReceivedOctets', per_second => 1 }, { name => 'display' } ], |
| 76 |
output_template => 'Traffic In Compressed : %s %s/s', |
| 77 |
output_change_bytes => 2, |
| 78 |
perfdatas => [ |
| 79 |
{ label => 'traffic_in_compressed', template => '%.2f', |
| 80 |
min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' }, |
| 81 |
], |
| 82 |
} |
| 83 |
}, |
| 84 |
{ label => 'traffic-out', set => { |
| 85 |
key_values => [ { name => 'wsScsPreCompressSentOctets', per_second => 1 }, { name => 'display' } ], |
| 86 |
output_template => 'Traffic Out : %s %s/s', |
| 87 |
output_change_bytes => 2, |
| 88 |
perfdatas => [ |
| 89 |
{ label => 'traffic_out', template => '%.2f', |
| 90 |
min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' }, |
| 91 |
], |
| 92 |
} |
| 93 |
}, |
| 94 |
{ label => 'traffic-out-compressed', set => { |
| 95 |
key_values => [ { name => 'wsScsCompressSentOctets', per_second => 1 }, { name => 'display' } ], |
| 96 |
output_template => 'Traffic Out Compressed : %s %s/s', |
| 97 |
output_change_bytes => 2, |
| 98 |
perfdatas => [ |
| 99 |
{ label => 'traffic_out_compressed', template => '%.2f', |
| 100 |
min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' }, |
| 101 |
], |
| 102 |
} |
| 103 |
}, |
| 104 |
]; |
| 105 |
} |
| 106 |
|
| 107 |
sub prefix_sc_output { |
| 108 |
my ($self, %options) = @_; |
| 109 |
|
| 110 |
return "Service Class '" . $options{instance_value}->{display} . "' "; |
| 111 |
} |
| 112 |
|
| 113 |
sub new { |
| 114 |
my ($class, %options) = @_; |
| 115 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); |
| 116 |
bless $self, $class; |
| 117 |
|
| 118 |
$options{options}->add_options(arguments => { |
| 119 |
'filter-name:s' => { name => 'filter_name' } |
| 120 |
}); |
| 121 |
|
| 122 |
return $self; |
| 123 |
} |
| 124 |
|
| 125 |
my $oid_wsServiceClassName = '.1.3.6.1.4.1.3845.30.4.1.1.2.2.1.2'; |
| 126 |
my $mapping = { |
| 127 |
wsScsCurrentAcceleratedConnections => { oid => '.1.3.6.1.4.1.3845.30.4.1.1.2.2.1.3' }, |
| 128 |
wsScsTotalAcceleratedConnections => { oid => '.1.3.6.1.4.1.3845.30.4.1.1.2.2.1.4' }, |
| 129 |
wsScsTotalNonAcceleratedConnections => { oid => '.1.3.6.1.4.1.3845.30.4.1.1.2.2.1.6' }, |
| 130 |
wsScsCompressSentOctets => { oid => '.1.3.6.1.4.1.3845.30.4.1.1.2.2.1.9' }, |
| 131 |
wsScsCompressReceivedOctets => { oid => '.1.3.6.1.4.1.3845.30.4.1.1.2.2.1.10' }, |
| 132 |
wsScsPreCompressSentOctets => { oid => '.1.3.6.1.4.1.3845.30.4.1.1.2.2.1.11' }, |
| 133 |
wsScsPreCompressReceivedOctets => { oid => '.1.3.6.1.4.1.3845.30.4.1.1.2.2.1.12' }, |
| 134 |
}; |
| 135 |
|
| 136 |
sub manage_selection { |
| 137 |
my ($self, %options) = @_; |
| 138 |
|
| 139 |
if ($options{snmp}->is_snmpv1()) { |
| 140 |
$self->{output}->add_option_msg(short_msg => "Need to use SNMP v2c or v3."); |
| 141 |
$self->{output}->option_exit(); |
| 142 |
} |
| 143 |
|
| 144 |
my $snmp_result = $options{snmp}->get_table(oid => $oid_wsServiceClassName, nothing_quit => 1); |
| 145 |
$self->{sc} = {}; |
| 146 |
foreach my $oid (keys %{$snmp_result}) { |
| 147 |
$oid =~ /\.(\d+)$/; |
| 148 |
my $instance = $1; |
| 149 |
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && |
| 150 |
$snmp_result->{$oid} !~ /$self->{option_results}->{filter_name}/) { |
| 151 |
$self->{output}->output_add(long_msg => "skipping service class '" . $snmp_result->{$oid} . "'.", debug => 1); |
| 152 |
next; |
| 153 |
} |
| 154 |
|
| 155 |
$self->{sc}->{$instance} = { display => $snmp_result->{$oid} }; |
| 156 |
} |
| 157 |
|
| 158 |
$options{snmp}->load(oids => [$mapping->{wsScsCurrentAcceleratedConnections}->{oid}, $mapping->{wsScsTotalAcceleratedConnections}->{oid}, |
| 159 |
$mapping->{wsScsTotalNonAcceleratedConnections}->{oid}, $mapping->{wsScsCompressSentOctets}->{oid}, |
| 160 |
$mapping->{wsScsCompressReceivedOctets}->{oid}, $mapping->{wsScsPreCompressSentOctets}->{oid}, |
| 161 |
$mapping->{wsScsPreCompressReceivedOctets}->{oid} |
| 162 |
], |
| 163 |
instances => [keys %{$self->{sc}}], instance_regexp => '^(.*)$'); |
| 164 |
$snmp_result = $options{snmp}->get_leef(nothing_quit => 1); |
| 165 |
|
| 166 |
foreach (keys %{$self->{sc}}) { |
| 167 |
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $_); |
| 168 |
|
| 169 |
foreach my $name (('wsScsCompressSentOctets', 'wsScsCompressReceivedOctets', 'wsScsPreCompressSentOctets', 'wsScsPreCompressReceivedOctets')) { |
| 170 |
$result->{$name} *= 8; |
| 171 |
} |
| 172 |
|
| 173 |
foreach my $name (keys %$mapping) { |
| 174 |
$self->{sc}->{$_}->{$name} = $result->{$name}; |
| 175 |
} |
| 176 |
} |
| 177 |
|
| 178 |
if (scalar(keys %{$self->{sc}}) <= 0) { |
| 179 |
$self->{output}->add_option_msg(short_msg => "No service class found."); |
| 180 |
$self->{output}->option_exit(); |
| 181 |
} |
| 182 |
|
| 183 |
$self->{cache_name} = "citrix_appacceleration_" . $self->{mode} . '_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . |
| 184 |
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' . |
| 185 |
(defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all')); |
| 186 |
} |
| 187 |
|
| 188 |
1; |
| 189 |
|
| 190 |
__END__ |
| 191 |
|
| 192 |
=head1 MODE |
| 193 |
|
| 194 |
Check service class usage. |
| 195 |
|
| 196 |
=over 8 |
| 197 |
|
| 198 |
=item B<--warning-*> |
| 199 |
|
| 200 |
Warning threshold. |
| 201 |
Can be: 'current-acc-con', 'total-acc-con', 'total-nonacc-con', |
| 202 |
'traffic-in-compressed', 'traffic-out-compressed', |
| 203 |
'traffic-in', 'traffic-out'. |
| 204 |
|
| 205 |
=item B<--critical-*> |
| 206 |
|
| 207 |
Critical threshold. |
| 208 |
Can be: 'current-acc-con', 'total-acc-con', 'total-nonacc-con', |
| 209 |
'traffic-in-compressed', 'traffic-out-compressed', |
| 210 |
'traffic-in', 'traffic-out'. |
| 211 |
|
| 212 |
=item B<--filter-name> |
| 213 |
|
| 214 |
Filter by service class name (can be a regexp). |
| 215 |
|
| 216 |
=back |
| 217 |
|
| 218 |
=cut |