Debian Codegraph @

src/storage/emc/datadomain/snmp/mode/listreplications.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 storage::emc::datadomain::snmp::mode::listreplications;
22
23 use base qw(centreon::plugins::mode);
24
25 use strict;
26 use warnings;
27 use storage::emc::datadomain::snmp::lib::functions;
28
29 sub new {
30 my ($class, %options) = @_;
31 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
32 bless $self, $class;
33
34 $options{options}->add_options(arguments => {
35 });
36
37 return $self;
38 }
39
40 sub check_options {
41 my ($self, %options) = @_;
42 $self->SUPER::init(%options);
43 }
44
45 my $oid_fileSystemSpaceEntry = '.1.3.6.1.4.1.19746.1.3.2.1.1';
46 my $oid_sysDescr = '.1.3.6.1.2.1.1.1.0'; # 'Data Domain OS 5.4.1.1-411752'
47 my ($oid_fileSystemResourceName, $oid_fileSystemSpaceUsed, $oid_fileSystemSpaceAvail);
48
49 my @mapping = ('index', 'type', 'source', 'destination', 'state', 'status', 'initiator');
50
51 sub manage_selection {
52 my ($self, %options) = @_;
53
54 my $oid_sysName = '.1.3.6.1.2.1.1.5.0';
55 my $oid_sysDescr = '.1.3.6.1.2.1.1.1.0'; # 'Data Domain OS 5.4.1.1-411752'
56 my $oid_replicationInfoEntry = '.1.3.6.1.4.1.19746.1.8.1.1.1';
57
58 my $snmp_result = $options{snmp}->get_leef(
59 oids => [ $oid_sysDescr, $oid_sysName ],
60 nothing_quit => 1
61 );
62
63 if (!($self->{os_version} = storage::emc::datadomain::snmp::lib::functions::get_version(value => $snmp_result->{$oid_sysDescr}))) {
64 $self->{output}->output_add(
65 severity => 'UNKNOWN',
66 short_msg => 'Cannot get DataDomain OS version.'
67 );
68 $self->{output}->display();
69 $self->{output}->exit();
70 }
71
72 my $sysname = $snmp_result->{$oid_sysName};
73
74 $snmp_result = $options{snmp}->get_table(
75 oid => $oid_replicationInfoEntry,
76 nothing_quit => 1
77 );
78
79 my ($oid_replSource, $oid_replDestination, $oid_replState, $oid_replStatus);
80 my %map_state = (
81 1 => 'enabled', 2 => 'disabled', 3 => 'disabledNeedsResync',
82 );
83 my %map_status = (
84 1 => 'connected', 2 => 'disconnected', 3 => 'migrating',
85 4 => 'suspended', 5 => 'neverConnected', 6 => 'idle'
86 );
87 if (centreon::plugins::misc::minimal_version($self->{os_version}, '5.4')) {
88 %map_state = (
89 1 => 'initializing', 2 => 'normal', 3 => 'recovering', 4 => 'uninitialized',
90 );
91 $oid_replSource = '.1.3.6.1.4.1.19746.1.8.1.1.1.7';
92 $oid_replDestination = '.1.3.6.1.4.1.19746.1.8.1.1.1.8';
93 $oid_replStatus = '.1.3.6.1.4.1.19746.1.8.1.1.1.4';
94 $oid_replState = '.1.3.6.1.4.1.19746.1.8.1.1.1.3';
95 } elsif (centreon::plugins::misc::minimal_version($self->{os_version}, '5.0')) {
96 $oid_replSource = '.1.3.6.1.4.1.19746.1.8.1.1.1.7';
97 $oid_replDestination = '.1.3.6.1.4.1.19746.1.8.1.1.1.8';
98 $oid_replStatus = '.1.3.6.1.4.1.19746.1.8.1.1.1.4';
99 $oid_replState = '.1.3.6.1.4.1.19746.1.8.1.1.1.3';
100 } else {
101 $oid_replSource = '.1.3.6.1.4.1.19746.1.8.1.1.1.6';
102 $oid_replDestination = '.1.3.6.1.4.1.19746.1.8.1.1.1.7';
103 $oid_replStatus = '.1.3.6.1.4.1.19746.1.8.1.1.1.3';
104 $oid_replState = '.1.3.6.1.4.1.19746.1.8.1.1.1.2';
105 }
106
107 my $mapping = {
108 replState => { oid => $oid_replState, map => \%map_state },
109 replStatus => { oid => $oid_replStatus, map => \%map_status },
110 replSource => { oid => $oid_replSource },
111 replDestination => { oid => $oid_replDestination }
112 };
113
114 my $results = {};
115 foreach my $oid (keys %$snmp_result) {
116 next if ($oid !~ /^$mapping->{replState}->{oid}\.(.*)$/);
117 my $instance = $1;
118 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance);
119
120 $result->{replSource} =~ /^(.*?):\/\//;
121 my $type = $1;
122
123 $result->{replSource} =~ s/^(.*?):\/\///;
124 $result->{replDestination} =~ s/^(.*?):\/\///;
125
126 # /data/col1/ is always present (useless information)
127 $result->{replSource} =~ s/\/data\/col1//;
128 $result->{replDestination} =~ s/\/data\/col1//;
129
130 my $initiator = 0;
131 $initiator = 1 if ($result->{replSource} =~ /^$sysname/);
132
133 $results->{$instance} = {
134 index => $instance,
135 type => $type,
136 source => $result->{replSource},
137 destination => $result->{replDestination},
138 state => $result->{replState},
139 status => $result->{replStatus},
140 initiator => $initiator
141 };
142 }
143
144 return $results;
145 }
146
147 sub run {
148 my ($self, %options) = @_;
149
150 my $results = $self->manage_selection(snmp => $options{snmp});
151 foreach my $name (sort keys %$results) {
152 $self->{output}->output_add(long_msg =>
153 join('', map("[$_ = " . $results->{$name}->{$_} . ']', @mapping))
154 );
155 }
156
157 $self->{output}->output_add(
158 severity => 'OK',
159 short_msg => 'List replications:'
160 );
161 $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
162 $self->{output}->exit();
163 }
164
165 sub disco_format {
166 my ($self, %options) = @_;
167
168 $self->{output}->add_disco_format(elements => [@mapping]);
169 }
170
171 sub disco_show {
172 my ($self, %options) = @_;
173
174 my $results = $self->manage_selection(snmp => $options{snmp});
175 foreach (sort keys %$results) {
176 $self->{output}->add_disco_entry(
177 %{$results->{$_}}
178 );
179 }
180 }
181
182 1;
183
184 __END__
185
186 =head1 MODE
187
188 List replications.
189
190 =over 8
191
192 =back
193
194 =cut