Debian Codegraph @

src/hardware/kvm/avocent/acs/8000/snmp/mode/serialports.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 hardware::kvm::avocent::acs::8000::snmp::mode::serialports;
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 catalog_status_calc);
28 use Digest::MD5 qw(md5_hex);
29
30 sub custom_status_output {
31 my ($self, %options) = @_;
32
33 return sprintf(
34 'status: %s',
35 $self->{result_values}->{status}
36 );
37 }
38
39 sub set_counters {
40 my ($self, %options) = @_;
41
42 $self->{maps_counters_type} = [
43 { name => 'serials', type => 1, cb_prefix_output => 'prefix_serial_output', message_multiple => 'All serial ports are ok' }
44 ];
45
46 $self->{maps_counters}->{serials} = [
47 { label => 'status', threshold => 0, set => {
48 key_values => [ { name => 'status' }, { name => 'display' } ],
49 closure_custom_calc => \&catalog_status_calc,
50 closure_custom_output => $self->can('custom_status_output'),
51 closure_custom_perfdata => sub { return 0; },
52 closure_custom_threshold_check => \&catalog_status_threshold
53 }
54 },
55 { label => 'traffic-in', nlabel => 'serialport.traffic.in.bitspersecond', set => {
56 key_values => [ { name => 'traffic_in', per_second => 1 }, { name => 'display' } ],
57 output_template => 'traffic in: %s%s/s',
58 output_change_bytes => 2,
59 perfdatas => [
60 { template => '%s', min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' }
61 ]
62 }
63 },
64 { label => 'traffic-out', nlabel => 'serialport.traffic.out.bitspersecond', set => {
65 key_values => [ { name => 'traffic_out', per_second => 1 }, { name => 'display' } ],
66 output_template => 'traffic out: %s%s/s',
67 output_change_bytes => 2,
68 perfdatas => [
69 { template => '%s', min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' }
70 ]
71 }
72 }
73 ];
74 }
75
76 sub prefix_serial_output {
77 my ($self, %options) = @_;
78
79 return "Serial port '" . $options{instance_value}->{display} . "' ";
80 }
81
82 sub new {
83 my ($class, %options) = @_;
84 my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1);
85 bless $self, $class;
86
87 $options{options}->add_options(arguments => {
88 'filter-name:s' => { name => 'filter_name' },
89 'unknown-status:s' => { name => 'unknown_status', default => '' },
90 'warning-status:s' => { name => 'warning_status', default => '' },
91 'critical-status:s' => { name => 'critical_status', default => '' }
92 });
93
94 return $self;
95 }
96
97 sub check_options {
98 my ($self, %options) = @_;
99 $self->SUPER::check_options(%options);
100
101 $self->change_macros(
102 macros => [
103 'unknown_status', 'warning_status', 'critical_status'
104 ]
105 );
106 }
107
108 my $map_status = { 1 => 'disabled', 2 => 'idle', 3 => 'inUse' };
109
110 my $mapping = {
111 status => { oid => '.1.3.6.1.4.1.10418.26.2.3.2.1.3', map => $map_status }, # acsSerialPortTableStatus
112 traffic_out => { oid => '.1.3.6.1.4.1.10418.26.2.3.2.1.16' }, # acsSerialPortTableTxBytes
113 traffic_in => { oid => '.1.3.6.1.4.1.10418.26.2.3.2.1.17' } # acsSerialPortTableRxBytes
114 };
115
116 sub manage_selection {
117 my ($self, %options) = @_;
118
119 my $oid_acsSerialPortTableDeviceName = '.1.3.6.1.4.1.10418.26.2.3.2.1.2';
120 my $snmp_result = $options{snmp}->get_table(
121 oid => $oid_acsSerialPortTableDeviceName,
122 nothing_quit => 1
123 );
124
125 $self->{serials} = {};
126 foreach (keys %$snmp_result) {
127 /\.(\d+)$/;
128 my $instance = $1;
129 my $name = $snmp_result->{$_};
130
131 if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
132 $name !~ /$self->{option_results}->{filter_name}/) {
133 $self->{output}->output_add(long_msg => "skipping port '" . $name . "'.", debug => 1);
134 next;
135 }
136
137 $self->{serials}->{$instance} = { display => $name };
138 }
139
140 return if (scalar(keys %{$self->{serials}}) <= 0);
141
142 $options{snmp}->load(
143 oids => [ map($_->{oid}, values(%$mapping)) ],
144 instances => [ keys %{$self->{serials}} ],
145 instance_regexp => '^(.*)$'
146 );
147 $snmp_result = $options{snmp}->get_leef();
148 foreach (keys %{$self->{serials}}) {
149 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $_);
150 $self->{serials}->{$_} = { %{$self->{serials}->{$_}}, %$result };
151 }
152
153 $self->{cache_name} = 'avocent_acs_8000_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode} . '_' .
154 (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' .
155 (defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all'));
156 }
157
158 1;
159
160 __END__
161
162 =head1 MODE
163
164 Check serial ports.
165
166 =over 8
167
168 =item B<--filter-name>
169
170 Filter by serial device name (can be a regexp).
171
172 =item B<--unknown-status>
173
174 Define the conditions to match for the status to be UNKNOWN.
175 You can use the following variables: %{status}, %{display}
176
177 =item B<--warning-status>
178
179 Define the conditions to match for the status to be WARNING.
180 You can use the following variables: %{status}, %{display}
181
182 =item B<--critical-status>
183
184 Define the conditions to match for the status to be CRITICAL.
185 You can use the following variables: %{status}, %{display}
186
187 =item B<--warning-*> B<--critical-*>
188
189 Thresholds.
190 Can be: 'traffic-in', 'traffic-out'.
191
192 =back
193
194 =cut