Debian Codegraph @

src/storage/netapp/ontap/snmp/mode/nvram.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::nvram;
22
23 use base qw(centreon::plugins::mode);
24
25 use strict;
26 use warnings;
27
28 my %mapping_nvram_state = (
29 1 => 'ok',
30 2 => 'partiallyDischarged',
31 3 => 'fullyDischarged',
32 4 => 'notPresent',
33 5 => 'nearEndOfLife',
34 6 => 'atEndOfLife',
35 7 => 'unknown',
36 8 => 'overCharged',
37 9 => 'fullyCharged',
38 );
39
40 my $thresholds = {
41 nvram => [
42 ['ok', 'OK'],
43 ['partiallyDischarged', 'WARNING'],
44 ['fullyDischarged', 'CRITICAL'],
45 ['notPresent', 'CRITICAL'],
46 ['nearEndOfLife', 'WARNING'],
47 ['atEndOfLife', 'CRITICAL'],
48 ['unknown', 'UNKNOWN'],
49 ['overCharged', 'OK'],
50 ['fullyCharged', 'OK'],
51 ],
52 };
53
54 sub new {
55 my ($class, %options) = @_;
56 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
57 bless $self, $class;
58
59 $options{options}->add_options(arguments => {
60 'threshold-overload:s@' => { name => 'threshold_overload' },
61 });
62
63 return $self;
64 }
65
66 sub check_options {
67 my ($self, %options) = @_;
68 $self->SUPER::init(%options);
69
70 $self->{overload_th} = {};
71 foreach my $val (@{$self->{option_results}->{threshold_overload}}) {
72 if ($val !~ /^(.*?),(.*?),(.*)$/) {
73 $self->{output}->add_option_msg(short_msg => "Wrong threshold-overload option '" . $val . "'.");
74 $self->{output}->option_exit();
75 }
76 my ($section, $status, $filter) = ($1, $2, $3);
77 if ($self->{output}->is_litteral_status(status => $status) == 0) {
78 $self->{output}->add_option_msg(short_msg => "Wrong threshold-overload status '" . $val . "'.");
79 $self->{output}->option_exit();
80 }
81 $self->{overload_th}->{$section} = [] if (!defined($self->{overload_th}->{$section}));
82 push @{$self->{overload_th}->{$section}}, {filter => $filter, status => $status};
83 }
84 }
85
86 my $mapping = {
87 nvramBatteryStatus => { oid => '.1.3.6.1.4.1.789.1.2.5.1', map => \%mapping_nvram_state },
88 };
89 my $mapping2 = {
90 nodeNvramBatteryStatus => { oid => '.1.3.6.1.4.1.789.1.25.2.1.17', map => \%mapping_nvram_state },
91 };
92
93 sub run {
94 my ($self, %options) = @_;
95 $self->{snmp} = $options{snmp};
96
97 my $oid_nodeName = '.1.3.6.1.4.1.789.1.25.2.1.1';
98 my $results = $self->{snmp}->get_multiple_table(oids => [
99 { oid => $mapping->{nvramBatteryStatus}->{oid} },
100 { oid => $oid_nodeName },
101 { oid => $mapping2->{nodeNvramBatteryStatus}->{oid} },
102 ], nothing_quit => 1);
103
104 if (defined($results->{$mapping->{nvramBatteryStatus}->{oid}}->{$mapping->{nvramBatteryStatus}->{oid} . '.0'})) {
105 my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $results->{$mapping->{nvramBatteryStatus}->{oid}}, instance => '0');
106 my $exit = $self->get_severity(section => 'nvram', value => $result->{nvramBatteryStatus});
107 $self->{output}->output_add(severity => $exit,
108 short_msg => sprintf("NVRAM Batteries status is '%s'", $result->{nvramBatteryStatus}));
109 } else {
110 $self->{output}->output_add(severity => 'OK',
111 short_msg => 'NVRAM Batteries status are ok on all nodes');
112 foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$results->{$mapping2->{nodeNvramBatteryStatus}->{oid}}})) {
113 $oid =~ /^$mapping2->{nodeNvramBatteryStatus}->{oid}\.(.*)$/;
114 my $instance = $1;
115 my $name = $results->{$oid_nodeName}->{$oid_nodeName . '.' . $instance};
116 my $result = $self->{snmp}->map_instance(mapping => $mapping2, results => $results->{$mapping2->{nodeNvramBatteryStatus}->{oid}}, instance => $instance);
117
118 my $exit = $self->get_severity(section => 'nvram', value => $result->{nodeNvramBatteryStatus});
119 $self->{output}->output_add(long_msg => sprintf("NVRAM Batteries status is '%s' on node '%s'",
120 $result->{nodeNvramBatteryStatus}, $name));
121 if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) {
122 $self->{output}->output_add(severity => $exit,
123 short_msg => sprintf("NVRAM Batteries status is '%s' on node '%s'",
124 $result->{nodeNvramBatteryStatus}, $name));
125 }
126 }
127 }
128
129 $self->{output}->display();
130 $self->{output}->exit();
131 }
132
133 sub get_severity {
134 my ($self, %options) = @_;
135 my $status = 'UNKNOWN'; # default
136
137 if (defined($self->{overload_th}->{$options{section}})) {
138 foreach (@{$self->{overload_th}->{$options{section}}}) {
139 if ($options{value} =~ /$_->{filter}/i) {
140 $status = $_->{status};
141 return $status;
142 }
143 }
144 }
145 foreach (@{$thresholds->{$options{section}}}) {
146 if ($options{value} =~ /$$_[0]/i) {
147 $status = $$_[1];
148 return $status;
149 }
150 }
151
152 return $status;
153 }
154
155 1;
156
157 __END__
158
159 =head1 MODE
160
161 Check current status of the NVRAM batteries.
162
163 =over 8
164
165 =item B<--threshold-overload>
166
167 Use this option to override the status returned by the plugin when the status label matches a regular expression (syntax: section,status,regexp).
168 Example: --threshold-overload='nvram,CRITICAL,^(?!(ok)$)'
169
170 =back
171
172 =cut
173