Debian Codegraph @

src/apps/antivirus/mcafee/webgateway/snmp/mode/httpstatistics.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 apps::antivirus::mcafee::webgateway::snmp::mode::httpstatistics;
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 => 'global', type => 0 },
34 { name => 'traffics', type => 0, cb_prefix_output => 'prefix_traffic_output' }
35 ];
36
37 $self->{maps_counters}->{global} = [
38 { label => 'requests', nlabel => 'http.requests.persecond', set => {
39 key_values => [ { name => 'stHttpRequests', per_second => 1 } ],
40 output_template => 'HTTP Requests (per sec): %d',
41 perfdatas => [
42 { label => 'http_requests', template => '%d', min => 0, unit => 'requests/s' }
43 ]
44 }
45 }
46 ];
47
48 $self->{maps_counters}->{traffics} = [
49 { label => 'client-to-proxy', nlabel => 'http.traffic.client2proxy.bitspersecond', set => {
50 key_values => [ { name => 'stHttpBytesFromClient', per_second => 1 } ],
51 output_template => 'from client to proxy: %s %s/s',
52 output_change_bytes => 2,
53 perfdatas => [
54 { label => 'http_traffic_client_to_proxy', template => '%d', min => 0, unit => 'b/s' }
55 ]
56 }
57 },
58 { label => 'server-to-proxy', nlabel => 'http.traffic.server2proxy.bitspersecond', set => {
59 key_values => [ { name => 'stHttpBytesFromServer', per_second => 1 } ],
60 output_template => 'from server to proxy: %s %s/s',
61 output_change_bytes => 2,
62 perfdatas => [
63 { label => 'http_traffic_server_to_proxy', template => '%d', min => 0, unit => 'b/s' }
64 ]
65 }
66 },
67 { label => 'proxy-to-client', nlabel => 'http.traffic.proxy2client.bitspersecond', set => {
68 key_values => [ { name => 'stHttpBytesToClient', per_second => 1 } ],
69 output_template => 'from proxy to client: %s %s/s',
70 output_change_bytes => 2,
71 perfdatas => [
72 { label => 'http_traffic_proxy_to_client', template => '%d', min => 0, unit => 'b/s' }
73 ]
74 }
75 },
76 { label => 'proxy-to-server', nlabel => 'http.traffic.proxy2server.bitspersecond', set => {
77 key_values => [ { name => 'stHttpBytesToServer', per_second => 1 } ],
78 output_template => 'from proxy to server: %s %s/s',
79 output_change_bytes => 2,
80 perfdatas => [
81 { label => 'http_traffic_proxy_to_server', template => '%d', min => 0, unit => 'b/s' }
82 ]
83 }
84 }
85 ];
86 }
87
88 sub prefix_traffic_output {
89 my ($self, %options) = @_;
90
91 return "HTTP Traffic ";
92 }
93
94 sub new {
95 my ($class, %options) = @_;
96 my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1);
97 bless $self, $class;
98
99 $options{options}->add_options(arguments => {
100 });
101
102 return $self;
103 }
104
105 my $oid_stHttpRequests = '.1.3.6.1.4.1.1230.2.7.2.2.1.0';
106 my $oid_stHttpBytesFromClient = '.1.3.6.1.4.1.1230.2.7.2.2.3.0';
107 my $oid_stHttpBytesFromServer = '.1.3.6.1.4.1.1230.2.7.2.2.4.0';
108 my $oid_stHttpBytesToClient = '.1.3.6.1.4.1.1230.2.7.2.2.5.0';
109 my $oid_stHttpBytesToServer = '.1.3.6.1.4.1.1230.2.7.2.2.6.0';
110
111 sub manage_selection {
112 my ($self, %options) = @_;
113
114 $self->{cache_name} = 'mcafee_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode} . '_' .
115 (defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all')) . '_' .
116 (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all'));
117
118 my $results = $options{snmp}->get_leef(
119 oids => [
120 $oid_stHttpRequests, $oid_stHttpBytesFromClient,
121 $oid_stHttpBytesFromServer, $oid_stHttpBytesToClient,
122 $oid_stHttpBytesToServer
123 ],
124 nothing_quit => 1
125 );
126
127 $self->{global} = {
128 stHttpRequests => $results->{$oid_stHttpRequests}
129 };
130 $self->{traffics} = {
131 stHttpBytesFromClient => $results->{$oid_stHttpBytesFromClient} * 8,
132 stHttpBytesFromServer => $results->{$oid_stHttpBytesFromServer} * 8,
133 stHttpBytesToClient => $results->{$oid_stHttpBytesToClient} * 8,
134 stHttpBytesToServer => $results->{$oid_stHttpBytesToServer} * 8
135 };
136 }
137
138 1;
139
140 __END__
141
142 =head1 MODE
143
144 Check HTTP statistics.
145
146 =over 8
147
148 =item B<--filter-counters>
149
150 Only display some counters (regexp can be used).
151 (example: --filter-counters='^proxy')
152
153 =item B<--warning-*>
154
155 Warning threshold.
156 Can be: 'request', 'client-to-proxy', 'server-to-proxy',
157 'proxy-to-client', 'proxy-to-server'.
158
159 =item B<--critical-*>
160
161 Critical threshold.
162 Can be: 'request', 'client-to-proxy', 'server-to-proxy',
163 'proxy-to-client', 'proxy-to-server'.
164
165 =back
166
167 =cut