Debian Codegraph @

src/storage/netapp/ontap/snmp/mode/sis.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::netapp::ontap::snmp::mode::sis;
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);
28 use Digest::MD5 qw(md5_hex);
29
30 sub custom_status_output {
31 my ($self, %options) = @_;
32
33 my $msg = sprintf('status : %s [state: %s] [lastOpError: %s]',
34 $self->{result_values}->{status},
35 $self->{result_values}->{state},
36 $self->{result_values}->{lastOpError},
37 );
38 return $msg;
39 }
40
41 sub custom_status_calc {
42 my ($self, %options) = @_;
43
44 $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_sisStatus'};
45 $self->{result_values}->{state} = $options{new_datas}->{$self->{instance} . '_sisState'};
46 $self->{result_values}->{lastOpError} = $options{new_datas}->{$self->{instance} . '_sisLastOpError'};
47 $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'};
48 return 0;
49 }
50
51 sub set_counters {
52 my ($self, %options) = @_;
53
54 $self->{maps_counters_type} = [
55 { name => 'sis', type => 1, cb_prefix_output => 'prefix_sis_output', message_multiple => 'All single instance storages are ok', skipped_code => { -10 => 1, -11 => 1 } }
56 ];
57
58 $self->{maps_counters}->{sis} = [
59 { label => 'status', threshold => 0, set => {
60 key_values => [ { name => 'sisStatus' }, { name => 'sisState' }, { name => 'sisLastOpError' }, { name => 'display' } ],
61 closure_custom_calc => $self->can('custom_status_calc'),
62 closure_custom_output => $self->can('custom_status_output'),
63 closure_custom_perfdata => sub { return 0; },
64 closure_custom_threshold_check => \&catalog_status_threshold,
65 }
66 },
67 ];
68 }
69
70 sub prefix_sis_output {
71 my ($self, %options) = @_;
72
73 return "Single instance storage '" . $options{instance_value}->{display} . "' ";
74 }
75
76 sub new {
77 my ($class, %options) = @_;
78 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
79 bless $self, $class;
80
81 $options{options}->add_options(arguments => {
82 'filter-name:s' => { name => 'filter_name' },
83 'unknown-status:s' => { name => 'unknown_status', default => '' },
84 'warning-status:s' => { name => 'warning_status', default => '' },
85 'critical-status:s' => { name => 'critical_status', default => '%{state} eq "enabled" and %{lastOpError} !~ /-|Success/i' },
86 });
87
88 return $self;
89 }
90
91 sub check_options {
92 my ($self, %options) = @_;
93 $self->SUPER::check_options(%options);
94
95 $self->change_macros(macros => ['warning_status', 'critical_status', 'unknown_status']);
96 }
97
98 my $map_status = {
99 1 => 'idle', 2 => 'active', 3 => 'undoing',
100 4 => 'pending', 5 => 'initializing',
101 6 => 'downgrading', 7 => 'disabled',
102 };
103
104 my $map_state = { 1 => 'disabled', 2 => 'enabled' };
105
106 my $mapping = {
107 sisState => { oid => '.1.3.6.1.4.1.789.1.23.2.1.3', map => $map_state },
108 sisStatus => { oid => '.1.3.6.1.4.1.789.1.23.2.1.4', map => $map_status },
109 sisLastOpError => { oid => '.1.3.6.1.4.1.789.1.23.2.1.12' },
110 };
111
112 sub manage_selection {
113 my ($self, %options) = @_;
114
115 my $oid_sisIsLicensed = '.1.3.6.1.4.1.789.1.23.1.0';
116 my $snmp_result = $options{snmp}->get_leef(oids => [$oid_sisIsLicensed]);
117 if (!defined($snmp_result->{$oid_sisIsLicensed}) || $snmp_result->{$oid_sisIsLicensed} != 2) {
118 $self->{output}->add_option_msg(short_msg => 'single instance storage is not licensed');
119 $self->{output}->option_exit();
120 }
121
122 my $oid_sisPath = '.1.3.6.1.4.1.789.1.23.2.1.2';
123 my $oid_sisVserver = '.1.3.6.1.4.1.789.1.23.2.1.16';
124
125 $self->{snapvault} = {};
126 $snmp_result = $options{snmp}->get_multiple_table(oids => [ { oid => $oid_sisPath }, { oid => $oid_sisVserver }], return_type => 1, nothing_quit => 1);
127 foreach my $oid (keys %{$snmp_result}) {
128 next if ($oid !~ /^$oid_sisPath\.(.*)$/);
129 my $instance = $1;
130 my $name = defined($snmp_result->{$oid_sisVserver . '.' . $instance}) && $snmp_result->{$oid_sisVserver . '.' . $instance} ne '' ?
131 $snmp_result->{$oid_sisVserver . '.' . $instance} . ':' . $snmp_result->{$oid} :
132 $snmp_result->{$oid};
133
134 if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
135 $name !~ /$self->{option_results}->{filter_name}/) {
136 $self->{output}->output_add(long_msg => "skipping sis '" . $name . "'.", debug => 1);
137 next;
138 }
139
140 $self->{sis}->{$instance} = { display => $name };
141 }
142
143 if (scalar(keys %{$self->{sis}}) <= 0) {
144 $self->{output}->add_option_msg(short_msg => "No entry found.");
145 $self->{output}->option_exit();
146 }
147
148 $options{snmp}->load(oids => [
149 map($_->{oid}, values(%$mapping))
150 ],
151 instances => [keys %{$self->{sis}}], instance_regexp => '^(.*)$');
152 $snmp_result = $options{snmp}->get_leef(nothing_quit => 1);
153
154 foreach (keys %{$self->{sis}}) {
155 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $_);
156
157 $self->{sis}->{$_} = { %{$self->{sis}->{$_}}, %$result };
158 }
159 }
160
161 1;
162
163 __END__
164
165 =head1 MODE
166
167 Check single instance storage.
168
169 =over 8
170
171 =item B<--filter-name>
172
173 Filter name (can be a regexp).
174
175 =item B<--unknown-status>
176
177 Define the conditions to match for the status to be UNKNOWN (default: '').
178 You can use the following variables: %{state}, %{status}, %{lastOpError}, %{display}
179
180 =item B<--warning-status>
181
182 Define the conditions to match for the status to be WARNING (default: '').
183 You can use the following variables: %{state}, %{status}, %{lastOpError}, %{display}
184
185 =item B<--critical-status>
186
187 Define the conditions to match for the status to be CRITICAL (default: '%{state} eq "enabled" and %{lastOpError} !~ /-|Success/i').
188 You can use the following variables: %{state}, %{status}, %{lastOpError}, %{display}
189
190 =back
191
192 =cut