Debian Codegraph @

src/network/kemp/snmp/mode/rsstatus.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::kemp::snmp::mode::rsstatus;
22
23 use base qw(centreon::plugins::templates::counter);
24
25 use strict;
26 use warnings;
27 use Digest::MD5 qw(md5_hex);
28 use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold);
29
30 sub custom_status_output {
31 my ($self, %options) = @_;
32
33 my $msg = 'status : ' . $self->{result_values}->{status};
34 return $msg;
35 }
36
37 sub custom_status_calc {
38 my ($self, %options) = @_;
39
40 $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_status'};
41 $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'};
42 return 0;
43 }
44
45 sub set_counters {
46 my ($self, %options) = @_;
47
48 $self->{maps_counters_type} = [
49 { name => 'rs', type => 1, cb_prefix_output => 'prefix_rs_output', message_multiple => 'All real servers are ok' }
50 ];
51
52 $self->{maps_counters}->{rs} = [
53 { label => 'status', threshold => 0, set => {
54 key_values => [ { name => 'status' }, { name => 'display' } ],
55 closure_custom_calc => $self->can('custom_status_calc'),
56 closure_custom_output => $self->can('custom_status_output'),
57 closure_custom_perfdata => sub { return 0; },
58 closure_custom_threshold_check => \&catalog_status_threshold,
59 }
60 },
61 { label => 'active', set => {
62 key_values => [ { name => 'rSActiveConns' }, { name => 'display' } ],
63 output_template => 'Active connections : %s',
64 perfdatas => [
65 { label => 'active', template => '%s', min => 0, label_extra_instance => 1, instance_use => 'display' },
66 ],
67 }
68 },
69 { label => 'in-traffic', set => {
70 key_values => [ { name => 'rSInBytes', per_second => 1 }, { name => 'display' } ],
71 output_template => 'Traffic In : %s %s/s',
72 output_change_bytes => 2,
73 perfdatas => [
74 { label => 'traffic_in', template => '%.2f', min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' },
75 ],
76 }
77 },
78 { label => 'out-traffic', set => {
79 key_values => [ { name => 'rSOutBytes', per_second => 1 }, { name => 'display' } ],
80 output_template => 'Traffic Out : %s %s/s',
81 output_change_bytes => 2,
82 perfdatas => [
83 { label => 'traffic_out', template => '%.2f', min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' },
84 ],
85 }
86 },
87 ];
88 }
89
90 sub new {
91 my ($class, %options) = @_;
92 my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1);
93 bless $self, $class;
94
95 $options{options}->add_options(arguments => {
96 'filter-name:s' => { name => 'filter_name' },
97 'warning-status:s' => { name => 'warning_status', default => '' },
98 'critical-status:s' => { name => 'critical_status', default => '%{status} !~ /inService|disabled/i' }
99 });
100
101 return $self;
102 }
103
104 sub check_options {
105 my ($self, %options) = @_;
106 $self->SUPER::check_options(%options);
107
108 $self->change_macros(macros => ['warning_status', 'critical_status']);
109 }
110
111 sub prefix_rs_output {
112 my ($self, %options) = @_;
113
114 return "Real server '" . $options{instance_value}->{display} . "' ";
115 }
116
117 my %map_state = (
118 1 => 'inService',
119 2 => 'outOfService',
120 4 => 'disabled',
121 );
122 my $mapping = {
123 rSvsidx => { oid => '.1.3.6.1.4.1.12196.13.2.1.1' },
124 rSip => { oid => '.1.3.6.1.4.1.12196.13.2.1.2' },
125 rSport => { oid => '.1.3.6.1.4.1.12196.13.2.1.3' },
126 rSstate => { oid => '.1.3.6.1.4.1.12196.13.2.1.8', map => \%map_state },
127 rSInBytes => { oid => '.1.3.6.1.4.1.12196.13.2.1.15' },
128 rSOutBytes => { oid => '.1.3.6.1.4.1.12196.13.2.1.16' },
129 rSActiveConns => { oid => '.1.3.6.1.4.1.12196.13.2.1.17' },
130 };
131
132 my $oid_rsEntry = '.1.3.6.1.4.1.12196.13.2.1';
133 my $oid_vSname = '.1.3.6.1.4.1.12196.13.1.1.13';
134
135 sub manage_selection {
136 my ($self, %options) = @_;
137
138 $self->{rs} = {};
139 my $snmp_result = $options{snmp}->get_multiple_table(oids => [ { oid => $oid_rsEntry }, { oid => $oid_vSname } ],
140 nothing_quit => 1);
141
142
143 foreach my $oid (keys %{$snmp_result->{$oid_rsEntry}}) {
144 next if ($oid !~ /^$mapping->{rSstate}->{oid}\.(.*)$/);
145 my $instance = $1;
146 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result->{$oid_rsEntry}, instance => $instance);
147 my $vs_name = $snmp_result->{$oid_vSname}->{$oid_vSname . '.' . $result->{rSvsidx}};
148
149 my $display_name = $vs_name . '/' . $result->{rSip} . ':' . $result->{rSport};
150 if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
151 $display_name !~ /$self->{option_results}->{filter_name}/) {
152 $self->{output}->output_add(long_msg => "skipping '" . $display_name . "': no matching filter.", debug => 1);
153 next;
154 }
155
156 $self->{rs}->{$instance} = { display => $display_name,
157 status => $result->{rSstate},
158 rSInBytes => defined($result->{rSInBytes}) ? $result->{rSInBytes} * 8 : undef,
159 rSOutBytes => defined($result->{rSOutBytes}) ? $result->{rSOutBytes} * 8 : undef,
160 rSActiveConns => $result->{rSActiveConns} };
161 }
162
163 if (scalar(keys %{$self->{rs}}) <= 0) {
164 $self->{output}->add_option_msg(short_msg => "No real server found.");
165 $self->{output}->option_exit();
166 }
167
168 $self->{cache_name} = "kemp_" . $self->{mode} . '_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' .
169 (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all'));
170 }
171
172 1;
173
174 __END__
175
176 =head1 MODE
177
178 Check real server status.
179
180 =over 8
181
182 =item B<--filter-counters>
183
184 Only display some counters (regexp can be used).
185 Example: --filter-counters='^status$'
186
187 =item B<--filter-name>
188
189 Filter real server name (can be a regexp).
190
191 =item B<--warning-status>
192
193 Define the conditions to match for the status to be WARNING.
194 You can use the following variables: %{status}, %{display}
195
196 =item B<--critical-status>
197
198 Define the conditions to match for the status to be CRITICAL (default: '%{status} !~ /inService|disabled/i').
199 You can use the following variables: %{status}, %{display}
200
201 =item B<--warning-*>
202
203 Warning threshold.
204 Can be: 'active', 'in-traffic' (b/s), 'out-traffic' (b/s).
205
206 =item B<--critical-*>
207
208 Critical threshold.
209 Can be: 'active', 'in-traffic' (b/s), 'out-traffic' (b/s).
210
211 =back
212
213 =cut