Debian Codegraph @

src/network/oracle/otd/snmp/mode/vserverusage.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::oracle::otd::snmp::mode::vserverusage;
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 => 'vs', type => 1, cb_prefix_output => 'prefix_vs_output', message_multiple => 'All Virtual Servers are ok', skipped_code => { -10 => 1 } },
34 ];
35
36 $self->{maps_counters}->{vs} = [
37 { label => 'in', set => {
38 key_values => [ { name => 'vsInOctets', per_second => 1 }, { name => 'display' } ],
39 output_template => 'Traffic In: %s %s/s',
40 output_change_bytes => 2,
41 perfdatas => [
42 { label => 'traffic_in', template => '%.2f', min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' },
43 ],
44 }
45 },
46 { label => 'out', set => {
47 key_values => [ { name => 'vsOutOctets', per_second => 1 }, { name => 'display' } ],
48 output_template => 'Traffic Out: %s %s/s',
49 output_change_bytes => 2,
50 perfdatas => [
51 { label => 'traffic_out', template => '%.2f', min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' },
52 ],
53 }
54 }
55 ];
56 my @map = (
57 'count-request', 'Count Requests : %s', 'vsCountRequests', 'count_request',
58 'count-2xx', 'Count 2xx Responses : %s', 'vsCount2xx', 'count_2xx',
59 'count-3xx', 'Count 3xx Responses : %s', 'vsCount3xx', 'count_3xx',
60 'count-4xx', 'Count 4xx Responses : %s', 'vsCount4xx', 'count_4xx',
61 'count-5xx', 'Count 5xx Responses : %s', 'vsCount5xx', 'count_5xx',
62 );
63 for (my $i = 0; $i < scalar(@map); $i += 4) {
64 push @{$self->{maps_counters}->{vs}}, { label => $map[$i], set => {
65 key_values => [ { name => $map[$i + 2], diff => 1 }, { name => 'display' } ],
66 output_template => $map[$i + 1],
67 perfdatas => [
68 { label => $map[$i + 3], template => '%s', min => 0, label_extra_instance => 1, instance_use => 'display' }
69 ]
70 }
71 };
72 }
73 }
74
75 sub new {
76 my ($class, %options) = @_;
77 my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1);
78 bless $self, $class;
79
80 $options{options}->add_options(arguments => {
81 'filter-name:s' => { name => 'filter_name' }
82 });
83
84 return $self;
85 }
86
87 sub prefix_vs_output {
88 my ($self, %options) = @_;
89
90 return "Virtual Server '" . $options{instance_value}->{display} . "' ";
91 }
92
93 my $mapping = {
94 vsId => { oid => '.1.3.6.1.4.1.111.19.190.1.30.1.2' },
95 vsCountRequests => { oid => '.1.3.6.1.4.1.111.19.190.1.30.1.3' },
96 vsInOctets => { oid => '.1.3.6.1.4.1.111.19.190.1.30.1.4' },
97 vsOutOctets => { oid => '.1.3.6.1.4.1.111.19.190.1.30.1.5' },
98 vsCount2xx => { oid => '.1.3.6.1.4.1.111.19.190.1.30.1.6' },
99 vsCount3xx => { oid => '.1.3.6.1.4.1.111.19.190.1.30.1.7' },
100 vsCount4xx => { oid => '.1.3.6.1.4.1.111.19.190.1.30.1.8' },
101 vsCount5xx => { oid => '.1.3.6.1.4.1.111.19.190.1.30.1.9' },
102 };
103 my $oid_vsEntry = '.1.3.6.1.4.1.111.19.190.1.30.1';
104
105 sub manage_selection {
106 my ($self, %options) = @_;
107
108 if ($options{snmp}->is_snmpv1()) {
109 $self->{output}->add_option_msg(short_msg => "Need to use SNMP v2c or v3.");
110 $self->{output}->option_exit();
111 }
112 my $snmp_result = $options{snmp}->get_table(oid => $oid_vsEntry, end => $mapping->{vsCount5xx}->{oid}, nothing_quit => 1);
113 $self->{vs} = {};
114 foreach my $oid (keys %{$snmp_result}) {
115 next if ($oid !~ /^$mapping->{vsId}->{oid}\.(.*)$/);
116 my $instance = $1;
117 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance);
118
119 if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
120 $result->{vsId} !~ /$self->{option_results}->{filter_name}/) {
121 $self->{output}->output_add(long_msg => "skipping Virtual Server '" . $result->{vsId} . "'.", debug => 1);
122 next;
123 }
124
125 $result->{vsInOctets} *= 8;
126 $result->{vsOutOctets} *= 8;
127 $self->{vs}->{$instance} = {
128 display => $result->{vsId},
129 %$result
130 };
131 }
132
133 if (scalar(keys %{$self->{vs}}) <= 0) {
134 $self->{output}->add_option_msg(short_msg => "No virtual server found.");
135 $self->{output}->option_exit();
136 }
137
138 $self->{cache_name} = "oracle_otd_" . $self->{mode} . '_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' .
139 (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' .
140 (defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all'));
141 }
142
143 1;
144
145 __END__
146
147 =head1 MODE
148
149 Check virtual server usage.
150
151 =over 8
152
153 =item B<--filter-name>
154
155 Filter by vserver name (can be a regexp).
156
157 =item B<--warning-*>
158
159 Warning threshold.
160 Can be: 'in', 'out', 'count-request',
161 'count-2xx', 'count-3xx', 'count-4xx', 'count-5xx'.
162
163 =item B<--critical-*>
164
165 Critical threshold.
166 Can be: 'in', 'out', 'count-request',
167 'count-2xx', 'count-3xx', 'count-4xx', 'count-5xx'.
168
169 =back
170
171 =cut