Debian Codegraph @

src/storage/ibm/fs900/snmp/mode/arraysstatus.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::ibm::fs900::snmp::mode::arraysstatus;
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
29 sub custom_status_output {
30 my ($self, %options) = @_;
31
32 my $msg = sprintf("Status is '%s'", $self->{result_values}->{status});
33 return $msg;
34 }
35
36 sub custom_status_calc {
37 my ($self, %options) = @_;
38
39 $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_arrayStatus'};
40 return 0;
41 }
42
43 sub set_counters {
44 my ($self, %options) = @_;
45
46 $self->{maps_counters_type} = [
47 { name => 'global', type => 1, cb_prefix_output => 'prefix_output', message_multiple => "All arrays metrics are ok", message_separator => ' - ' }
48 ];
49
50 $self->{maps_counters}->{global} = [
51 { label => 'status', threshold => 0, set => {
52 key_values => [ { name => 'arrayStatus' } ],
53 closure_custom_calc => $self->can('custom_status_calc'),
54 closure_custom_output => $self->can('custom_status_output'),
55 closure_custom_perfdata => sub { return 0; },
56 closure_custom_threshold_check => \&catalog_status_threshold,
57 }
58 },
59 { label => 'vdisk-count', set => {
60 key_values => [ { name => 'arrayVDiskCount' }, { name => 'arrayId' } ],
61 output_template => 'VDisk count: %s',
62 perfdatas => [
63 { label => 'vdisk_count', value => 'arrayVDiskCount', template => '%s', label_extra_instance => 1,
64 instance_use => 'arrayId', min => 0 },
65 ],
66 }
67 },
68 ];
69 }
70
71 sub prefix_output {
72 my ($self, %options) = @_;
73
74 return "Array '" . $options{instance_value}->{arrayId} . "' ";
75 }
76
77 sub new {
78 my ($class, %options) = @_;
79 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
80 bless $self, $class;
81
82 $options{options}->add_options(arguments =>
83 {
84 "warning-status:s" => { name => 'warning_status', default => '' },
85 "critical-status:s" => { name => 'critical_status', default => '%{status} =~ /degraded/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']);
96 }
97
98 my $mapping = {
99 arrayId => { oid => '.1.3.6.1.4.1.2.6.255.1.1.1.52.1.2' },
100 arrayStatus => { oid => '.1.3.6.1.4.1.2.6.255.1.1.1.52.1.3' },
101 arrayVDiskCount => { oid => '.1.3.6.1.4.1.2.6.255.1.1.1.52.1.9' },
102 };
103
104 my $oid_arrayIndex = '.1.3.6.1.4.1.2.6.255.1.1.1.52.1';
105
106 sub manage_selection {
107 my ($self, %options) = @_;
108
109 my $snmp_result = $options{snmp}->get_table(oid => $oid_arrayIndex,
110 nothing_quit => 1);
111
112 $self->{global} = {};
113
114 foreach my $oid (keys %{$snmp_result}) {
115 next if ($oid !~ /^$mapping->{arrayId}->{oid}\.(.*)$/);
116 my $instance = $1;
117 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance);
118
119 $self->{global}->{$result->{arrayId}} = $result;
120 }
121 }
122
123 1;
124
125 __END__
126
127 =head1 MODE
128
129 Check arrays status.
130
131 =over 8
132
133 =item B<--warning-status>
134
135 Define the conditions to match for the status to be WARNING.
136 'status' can be: 'online', 'offline', 'excluded', 'degraded'.
137
138 =item B<--critical-status>
139
140 Define the conditions to match for the status to be CRITICAL (default: '%{status} =~ /degraded/i').
141 'status' can be: 'online', 'offline', 'excluded', 'degraded'.
142
143 =item B<--warning-vdisk-count>
144
145 Warning threshold for VDisks count.
146
147 =item B<--critical-vdisk-count>
148
149 Critical threshold for VDisks count.
150
151 =back
152
153 =cut