| 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::denyall::snmp::mode::reverseproxy; |
| 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_status_output { |
| 30 |
my ($self, %options) = @_; |
| 31 |
|
| 32 |
return sprintf( |
| 33 |
'status: %s', |
| 34 |
$self->{result_values}->{status} |
| 35 |
); |
| 36 |
} |
| 37 |
|
| 38 |
sub rp_long_output { |
| 39 |
my ($self, %options) = @_; |
| 40 |
|
| 41 |
return sprintf( |
| 42 |
"checking reverse proxy '%s'", |
| 43 |
$options{instance_value}->{uid} |
| 44 |
); |
| 45 |
} |
| 46 |
|
| 47 |
sub prefix_rp_output { |
| 48 |
my ($self, %options) = @_; |
| 49 |
|
| 50 |
return sprintf( |
| 51 |
"reverse proxy '%s' ", |
| 52 |
$options{instance_value}->{uid} |
| 53 |
); |
| 54 |
} |
| 55 |
|
| 56 |
sub set_counters { |
| 57 |
my ($self, %options) = @_; |
| 58 |
|
| 59 |
$self->{maps_counters_type} = [ |
| 60 |
{ name => 'rps', type => 3, cb_prefix_output => 'prefix_rp_output', cb_long_output => 'rp_long_output', |
| 61 |
indent_long_output => ' ', message_multiple => 'All reverse proxies are ok', |
| 62 |
group => [ |
| 63 |
{ name => 'status', type => 0, skipped_code => { -10 => 1 } }, |
| 64 |
{ name => 'cpu', type => 0, skipped_code => { -10 => 1 } }, |
| 65 |
{ name => 'memory', type => 0, skipped_code => { -10 => 1 } }, |
| 66 |
{ name => 'traffic', type => 0, skipped_code => { -10 => 1 } } |
| 67 |
] |
| 68 |
} |
| 69 |
]; |
| 70 |
|
| 71 |
$self->{maps_counters}->{status} = [ |
| 72 |
{ |
| 73 |
label => 'status', type => 2, critical_default => '%{status} =~ /down/i', |
| 74 |
set => { |
| 75 |
key_values => [ { name => 'status' }, { name => 'uid' } ], |
| 76 |
closure_custom_output => $self->can('custom_status_output'), |
| 77 |
closure_custom_perfdata => sub { return 0; }, |
| 78 |
closure_custom_threshold_check => \&catalog_status_threshold_ng |
| 79 |
} |
| 80 |
} |
| 81 |
]; |
| 82 |
|
| 83 |
$self->{maps_counters}->{cpu} = [ |
| 84 |
{ label => 'cpu-utilization', nlabel => 'reverse_proxy.cpu.utilization.percentage', set => { |
| 85 |
key_values => [ { name => 'cpu_usage' } ], |
| 86 |
output_template => 'cpu usage: %.2f %%', |
| 87 |
perfdatas => [ |
| 88 |
{ template => '%.2f', unit => '%', min => 0, max => 100, label_extra_instance => 1 } |
| 89 |
] |
| 90 |
} |
| 91 |
} |
| 92 |
]; |
| 93 |
|
| 94 |
$self->{maps_counters}->{memory} = [ |
| 95 |
{ label => 'memory-usage', nlabel => 'reverse_proxy.memory.usage.bytes', set => { |
| 96 |
key_values => [ { name => 'memory_used' } ], |
| 97 |
output_template => 'memory used: %s %s', |
| 98 |
output_change_bytes => 1, |
| 99 |
perfdatas => [ |
| 100 |
{ template => '%d', min => 0, unit => 'B', label_extra_instance => 1 } |
| 101 |
] |
| 102 |
} |
| 103 |
} |
| 104 |
]; |
| 105 |
|
| 106 |
$self->{maps_counters}->{traffic} = [ |
| 107 |
{ label => 'requests', nlabel => 'reverse_proxy.requests.persecond', set => { |
| 108 |
key_values => [ { name => 'requests_psec' } ], |
| 109 |
output_template => 'requests: %.2f/s', |
| 110 |
perfdatas => [ |
| 111 |
{ template => '%.2f', min => 0, label_extra_instance => 1 } |
| 112 |
] |
| 113 |
} |
| 114 |
} |
| 115 |
]; |
| 116 |
} |
| 117 |
|
| 118 |
sub new { |
| 119 |
my ($class, %options) = @_; |
| 120 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); |
| 121 |
bless $self, $class; |
| 122 |
|
| 123 |
$options{options}->add_options(arguments => { |
| 124 |
'filter-uid:s' => { name => 'filter_uid' } |
| 125 |
}); |
| 126 |
|
| 127 |
return $self; |
| 128 |
} |
| 129 |
|
| 130 |
my $map_status = { 0 => 'down', 1 => 'ok' }; |
| 131 |
|
| 132 |
my $mapping = { |
| 133 |
status => { oid => '.1.3.6.1.4.1.18433.10.1.1.1.8.2.1.3', map => $map_status }, # rpStatus |
| 134 |
cpu_usage => { oid => '.1.3.6.1.4.1.18433.10.1.1.1.8.2.1.4' }, # rpCpuUsage |
| 135 |
memory_used => { oid => '.1.3.6.1.4.1.18433.10.1.1.1.8.2.1.5' }, # rpMemoryUsage (MB) |
| 136 |
requests_psec => { oid => '.1.3.6.1.4.1.18433.10.1.1.1.8.2.1.11' } # rpRqstsPrSecond |
| 137 |
}; |
| 138 |
|
| 139 |
sub manage_selection { |
| 140 |
my ($self, %options) = @_; |
| 141 |
|
| 142 |
my $oid_uid = '.1.3.6.1.4.1.18433.10.1.1.1.8.2.1.2'; # rpUid |
| 143 |
my $snmp_result = $options{snmp}->get_table( |
| 144 |
oid => $oid_uid, |
| 145 |
nothing_quit => 1 |
| 146 |
); |
| 147 |
|
| 148 |
$self->{rps} = {}; |
| 149 |
foreach (keys %$snmp_result) { |
| 150 |
/\.(\d+)$/; |
| 151 |
my $instance = $1; |
| 152 |
|
| 153 |
if (defined($self->{option_results}->{filter_uid}) && $self->{option_results}->{filter_uid} ne '' && |
| 154 |
$snmp_result->{$_} !~ /$self->{option_results}->{filter_uid}/) { |
| 155 |
$self->{output}->output_add(long_msg => "skipping reverse proxy '" . $snmp_result->{$_} . "'.", debug => 1); |
| 156 |
next; |
| 157 |
} |
| 158 |
|
| 159 |
$self->{rps}->{ $snmp_result->{$_} } = { |
| 160 |
uid => $snmp_result->{$_}, |
| 161 |
instance => $instance |
| 162 |
}; |
| 163 |
} |
| 164 |
|
| 165 |
return if (scalar(keys %{$self->{rps}}) <= 0); |
| 166 |
|
| 167 |
$options{snmp}->load( |
| 168 |
oids => [ map($_->{oid}, values(%$mapping)) ], |
| 169 |
instances => [ map($_->{instance}, values(%{$self->{rps}})) ], |
| 170 |
instance_regexp => '^(.*)$' |
| 171 |
); |
| 172 |
$snmp_result = $options{snmp}->get_leef(); |
| 173 |
foreach (keys %{$self->{rps}}) { |
| 174 |
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $self->{rps}->{$_}->{instance}); |
| 175 |
|
| 176 |
$self->{rps}->{$_}->{memory} = { memory_used => $result->{memory_used} * 1024 * 1024 }; |
| 177 |
$self->{rps}->{$_}->{cpu} = { cpu_usage => $result->{cpu_usage} }; |
| 178 |
$self->{rps}->{$_}->{status} = { status => $result->{status}, uid => $_ }; |
| 179 |
$self->{rps}->{$_}->{traffic} = { requests_psec => $result->{requests_psec} }; |
| 180 |
} |
| 181 |
} |
| 182 |
|
| 183 |
1; |
| 184 |
|
| 185 |
__END__ |
| 186 |
|
| 187 |
=head1 MODE |
| 188 |
|
| 189 |
Check reverse proxies. |
| 190 |
|
| 191 |
=over 8 |
| 192 |
|
| 193 |
=item B<--filter-uid> |
| 194 |
|
| 195 |
Filter reverse proxy by UID (can be a regexp). |
| 196 |
|
| 197 |
=item B<--unknown-status> |
| 198 |
|
| 199 |
Define the conditions to match for the status to be UNKNOWN. |
| 200 |
You can use the following variables: %{status}, %{uid} |
| 201 |
|
| 202 |
=item B<--warning-status> |
| 203 |
|
| 204 |
Define the conditions to match for the status to be WARNING. |
| 205 |
You can use the following variables: %{status}, %{uid} |
| 206 |
|
| 207 |
=item B<--critical-status> |
| 208 |
|
| 209 |
Define the conditions to match for the status to be CRITICAL (default: '%{status} =~ /down/i'). |
| 210 |
You can use the following variables: %{status}, %{uid} |
| 211 |
|
| 212 |
=item B<--warning-*> B<--critical-*> |
| 213 |
|
| 214 |
Thresholds. |
| 215 |
Can be: 'cpu-utilization', 'memory-usage', 'requests'. |
| 216 |
|
| 217 |
=back |
| 218 |
|
| 219 |
=cut |