Debian Codegraph @

src/network/bluecoat/snmp/mode/clientrequests.pm

raw
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::bluecoat::snmp::mode::clientrequests;
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 prefix_output {
30 my ($self, %options) = @_;
31
32 return 'Client requests ';
33 }
34
35 sub set_counters {
36 my ($self, %options) = @_;
37
38 $self->{maps_counters_type} = [
39 { name => 'global', type => 0, cb_prefix_output => 'prefix_output' },
40 ];
41 $self->{maps_counters}->{global} = [
42 { label => 'hits', set => {
43 key_values => [ { name => 'client_http_requests', diff => 1 }, { name => 'client_http_hits', diff => 1 } ],
44 closure_custom_calc => $self->can('custom_data_calc'), closure_custom_calc_extra_options => { label_ref => 'hits' },
45 output_template => 'hits: %.2f %%',
46 output_use => 'hits_prct', threshold_use => 'hits_prct',
47 perfdatas => [
48 { label => 'hits', value => 'hits_prct', template => '%.2f', min => 0, max => 100, unit => '%' }
49 ]
50 }
51 },
52 { label => 'partial-hits', set => {
53 key_values => [ { name => 'client_http_requests', diff => 1 }, { name => 'client_http_partial_hits', diff => 1 } ],
54 closure_custom_calc => $self->can('custom_data_calc'), closure_custom_calc_extra_options => { label_ref => 'partial_hits' },
55 output_template => 'partial hits: %.2f %%',
56 output_use => 'partial_hits_prct', threshold_use => 'partial_hits_prct',
57 perfdatas => [
58 { label => 'partial_hits', value => 'partial_hits_prct', template => '%.2f', min => 0, max => 100, unit => '%' }
59 ]
60 }
61 },
62 { label => 'misses', set => {
63 key_values => [ { name => 'client_http_requests', diff => 1 }, { name => 'client_http_misses', diff => 1 } ],
64 closure_custom_calc => $self->can('custom_data_calc'), closure_custom_calc_extra_options => { label_ref => 'misses' },
65 output_template => 'misses: %.2f %%',
66 output_use => 'misses_prct', threshold_use => 'misses_prct',
67 perfdatas => [
68 { label => 'misses', value => 'misses_prct', template => '%.2f', min => 0, max => 100, unit => '%' }
69 ]
70 }
71 },
72 { label => 'errors', set => {
73 key_values => [ { name => 'client_http_requests', diff => 1 }, { name => 'client_http_errors', diff => 1 } ],
74 closure_custom_calc => $self->can('custom_data_calc'), closure_custom_calc_extra_options => { label_ref => 'errors' },
75 output_template => 'errors: %.2f %%',
76 output_use => 'errors_prct', threshold_use => 'errors_prct',
77 perfdatas => [
78 { label => 'errors', value => 'errors_prct', template => '%.2f', min => 0, max => 100, unit => '%' }
79 ]
80 }
81 }
82 ];
83 }
84
85 sub custom_data_calc {
86 my ($self, %options) = @_;
87
88 my $label = $options{extra_options}->{label_ref};
89 my $delta_value = $options{new_datas}->{$self->{instance} . '_client_http_' . $label} - $options{old_datas}->{$self->{instance} . '_client_http_' . $label};
90 my $delta_total = $options{new_datas}->{$self->{instance} . '_client_http_requests'} - $options{old_datas}->{$self->{instance} . '_client_http_requests'};
91
92 $self->{result_values}->{$label . '_prct'} = 0;
93 if ($delta_total > 0) {
94 $self->{result_values}->{$label . '_prct'} = $delta_value * 100 / $delta_total;
95 }
96 return 0;
97 }
98
99 sub new {
100 my ($class, %options) = @_;
101 my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1);
102 bless $self, $class;
103
104 $options{options}->add_options(arguments => {});
105
106 return $self;
107 }
108
109 sub manage_selection {
110 my ($self, %options) = @_;
111
112 if ($options{snmp}->is_snmpv1()) {
113 $self->{output}->add_option_msg(short_msg => "Need to use SNMP v2c or v3.");
114 $self->{output}->option_exit();
115 }
116 my $result = $options{snmp}->get_leef(
117 oids => [
118 '.1.3.6.1.4.1.3417.2.11.3.1.1.1.0',
119 '.1.3.6.1.4.1.3417.2.11.3.1.1.2.0',
120 '.1.3.6.1.4.1.3417.2.11.3.1.1.3.0',
121 '.1.3.6.1.4.1.3417.2.11.3.1.1.4.0',
122 '.1.3.6.1.4.1.3417.2.11.3.1.1.5.0'
123 ],
124 nothing_quit => 1
125 );
126
127 $self->{cache_name} = 'bluecoat_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode} . '_' .
128 (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all'));
129
130 $self->{global} = {
131 client_http_requests => $result->{'.1.3.6.1.4.1.3417.2.11.3.1.1.1.0'},
132 client_http_hits => $result->{'.1.3.6.1.4.1.3417.2.11.3.1.1.2.0'},
133 client_http_partial_hits => $result->{'.1.3.6.1.4.1.3417.2.11.3.1.1.3.0'},
134 client_http_misses => $result->{'.1.3.6.1.4.1.3417.2.11.3.1.1.4.0'},
135 client_http_errors => $result->{'.1.3.6.1.4.1.3417.2.11.3.1.1.5.0'}
136 };
137 }
138
139 1;
140
141 __END__
142
143 =head1 MODE
144
145 Check http client requests (in percent by type: hit, partial, misses, errors)
146
147 =over 8
148
149 =item B<--filter-counters>
150
151 Only display some counters (regexp can be used).
152 Example: --filter-counters='errors'
153
154 =item B<--warning-*>
155
156 Warning threshold.
157 Can be: errors (%), hits (%), partial-hits (%), misses (%).
158
159 =item B<--critical-*>
160
161 Critical threshold.
162 Can be: errors (%), hits (%), partial-hits (%), misses (%).
163
164 =back
165
166 =cut