Debian Codegraph @

src/storage/qnap/snmp/mode/upgrade.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::qnap::snmp::mode::upgrade;
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 set_counters {
30 my ($self, %options) = @_;
31
32 $self->{maps_counters_type} = [
33 { name => 'global', type => 0 }
34 ];
35
36 $self->{maps_counters}->{global} = [
37 { label => 'status', type => 2, warning_default => '%{upgrade} eq "available"', set => {
38 key_values => [
39 { name => 'model' }, { name => 'version' }, { name => 'upgrade' }
40 ],
41 closure_custom_output => $self->can('custom_status_output'),
42 closure_custom_perfdata => sub { return 0; },
43 closure_custom_threshold_check => \&catalog_status_threshold_ng
44 }
45 }
46 ];
47 }
48
49 sub custom_status_output {
50 my ($self, %options) = @_;
51
52 return sprintf(
53 "upgrade is %s [model: %s] [version: %s]",
54 $self->{result_values}->{upgrade},
55 $self->{result_values}->{model},
56 $self->{result_values}->{version}
57 );
58 }
59
60 sub new {
61 my ($class, %options) = @_;
62 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
63 bless $self, $class;
64
65 $options{options}->add_options(arguments => {
66 });
67
68 return $self;
69 }
70
71 my $mapping = {
72 model => { oid => '.1.3.6.1.4.1.55062.1.12.3' }, # systemModel
73 version => { oid => '.1.3.6.1.4.1.55062.1.12.6' }, # firmwareVersion
74 upgrade => { oid => '.1.3.6.1.4.1.55062.1.12.7' } # firmwareUpgradeAvailable
75 };
76
77 sub manage_selection {
78 my ($self, %options) = @_;
79
80 my $snmp_result = $options{snmp}->get_leef(
81 oids => [ map($_->{oid} . '.0', values(%$mapping)) ],
82 nothing_quit => 1
83 );
84 $snmp_result->{$mapping->{version}->{oid} . '.0'} =~ s/\r*\n*$//;
85 $self->{global} = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => 0);
86 $self->{global}->{upgrade} = $self->{global}->{upgrade} ? 'available' : 'unavailable';
87 }
88
89 1;
90
91 __END__
92
93 =head1 MODE
94
95 Check upgrade status (only works with QTS OS).
96
97 =over 8
98
99 =item B<--warning-status>
100
101 Define the conditions to match for the status to be WARNING (default : '%{upgrade} eq "available"').
102 You can use the following variables: %{model}, %{version}, %{upgrade}
103
104 =item B<--critical-status>
105
106 Define the conditions to match for the status to be CRITICAL.
107 You can use the following variables: %{model}, %{version}, %{upgrade}
108
109 =back
110
111 =cut