Debian Codegraph @

src/hardware/devices/cisco/cts/snmp/mode/peripherals.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::devices::cisco::cts::snmp::mode::peripherals;
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_ng);
28
29 sub custom_status_output {
30 my ($self, %options) = @_;
31
32 return sprintf(
33 'status: %s',
34 $self->{result_values}->{status}
35 );
36 }
37
38 sub prefix_peripheral_output {
39 my ($self, %options) = @_;
40
41 return "Peripheral '" . $options{instance_value}->{description} . "' ";
42 }
43
44 sub set_counters {
45 my ($self, %options) = @_;
46
47 $self->{maps_counters_type} = [
48 { name => 'global', type => 0 },
49 { name => 'peripherals', type => 1, cb_prefix_output => 'prefix_peripheral_output', message_multiple => 'All peripherals are ok' }
50 ];
51
52 $self->{maps_counters}->{peripherals} = [
53 { label => 'status', type => 2, critical_default => '%{status} !~ /noError/i', set => {
54 key_values => [ { name => 'status' }, { name => 'description' } ],
55 closure_custom_output => $self->can('custom_status_output'),
56 closure_custom_perfdata => sub { return 0; },
57 closure_custom_threshold_check => \&catalog_status_threshold_ng
58 }
59 }
60 ];
61
62 $self->{maps_counters}->{global} = [
63 { label => 'total', nlabel => 'peripherals.total.count', set => {
64 key_values => [ { name => 'total' } ],
65 output_template => 'Total peripherals: %s',
66 perfdatas => [
67 { template => '%s', min => 0 }
68 ]
69 }
70 }
71 ];
72 }
73
74 sub new {
75 my ($class, %options) = @_;
76 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
77 bless $self, $class;
78
79 $options{options}->add_options(arguments => {
80 'filter-description:s' => { name => 'filter_description' }
81 });
82
83 return $self;
84 }
85
86 my $mapping_status = {
87 0 => 'noError', 1 => 'other', 2 => 'cableError', 3 => 'powerError',
88 4 => 'mgmtSysConfigError', 5 => 'systemError', 6 => 'deviceError',
89 7 => 'linkError', 8 => 'commError', 9 => 'detectionDisabled'
90 };
91
92 my $mapping = {
93 description => { oid => '.1.3.6.1.4.1.9.9.643.1.2.1.1.2' }, # ctpPeripheralDescription
94 status => { oid => '.1.3.6.1.4.1.9.9.643.1.2.1.1.3', map => $mapping_status } # ctpPeripheralStatus
95 };
96 my $oid_ctpPeripheralStatusEntry = '.1.3.6.1.4.1.9.9.643.1.2.1.1';
97
98 sub manage_selection {
99 my ($self, %options) = @_;
100
101 my $snmp_result = $options{snmp}->get_table(
102 oid => $oid_ctpPeripheralStatusEntry,
103 start => $mapping->{description}->{oid},
104 end => $mapping->{status}->{oid},
105 nothing_quit => 1
106 );
107
108 $self->{peripherals} = {};
109 foreach my $oid (keys %$snmp_result) {
110 next if ($oid !~ /^$mapping->{status}->{oid}\.(.*)/);
111 my $instance = $1;
112 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance);
113
114 if (defined($self->{option_results}->{filter_description}) && $self->{option_results}->{filter_description} ne '' &&
115 $result->{description} !~ /$self->{option_results}->{filter_description}/) {
116 $self->{output}->output_add(long_msg => "skipping phone '" . $instance . "': no matching filter.", debug => 1);
117 next;
118 }
119
120 $self->{peripherals}->{$instance} = $result;
121 }
122
123 $self->{global} = { total => scalar(keys %{$self->{peripherals}}) };
124 }
125
126 1;
127
128 __END__
129
130 =head1 MODE
131
132 Check peripherals.
133
134 =over 8
135
136 =item B<--filter-counters>
137
138 Only display some counters (regexp can be used).
139 Example: --filter-counters='status'
140
141 =item B<--filter-description>
142
143 Filter peripheral by description (can be a regexp).
144
145 =item B<--warning-status>
146
147 Define the conditions to match for the status to be WARNING.
148 You can use the following variables: %{status}, %{description}
149
150 =item B<--critical-status>
151
152 Define the conditions to match for the status to be CRITICAL (default: '%{status} !~ /^registered/').
153 You can use the following variables: %{status}, %{description}
154
155 =item B<--warning-*> B<--critical-*>
156
157 Thresholds.
158
159 Can be: 'total'.
160
161 =back
162
163 =cut