Debian Codegraph @

src/storage/synology/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::synology::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} ne "unavailable"', 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 "'%s': version is '%s', upgrade is '%s'",
54 $self->{result_values}->{model},
55 $self->{result_values}->{version},
56 $self->{result_values}->{upgrade}
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 $map_states = {
72 1 => 'available', 2 => 'unavailable',
73 3 => 'connecting', 4 => 'disconnected',
74 5 => 'others'
75 };
76
77 my $mapping = {
78 model => { oid => '.1.3.6.1.4.1.6574.1.5.1' }, # modelName
79 version => { oid => '.1.3.6.1.4.1.6574.1.5.3' }, # version
80 upgrade => { oid => '.1.3.6.1.4.1.6574.1.5.4', map => $map_states } # upgradeAvailable
81 };
82
83 sub manage_selection {
84 my ($self, %options) = @_;
85
86 my $snmp_result = $options{snmp}->get_leef(
87 oids => [ map($_->{oid} . '.0', values(%$mapping)) ],
88 nothing_quit => 1
89 );
90 $self->{global} = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => 0);
91
92 }
93
94 1;
95
96 __END__
97
98 =head1 MODE
99
100 Check upgrade status
101
102 =over 8
103
104 =item B<--warning-status>
105
106 Define the conditions to match for the status to be WARNING (default : '%{upgrade} ne "unavailable"').
107 You can use the following variables: %{model}, %{version}, %{upgrade}
108
109 =item B<--critical-status>
110
111 Define the conditions to match for the status to be CRITICAL.
112 You can use the following variables: %{model}, %{version}, %{upgrade}
113
114 =back
115
116 =cut