Debian Codegraph @

src/apps/proxmox/mg/restapi/mode/version.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 apps::proxmox::mg::restapi::mode::version;
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 custom_version_output {
30 my ($self, %options) = @_;
31
32 return sprintf(
33 'pmg version: %s [release: %s][repoid: %s]',
34 $self->{result_values}->{version},
35 $self->{result_values}->{release},
36 $self->{result_values}->{repoid}
37 );
38 }
39
40 sub set_counters {
41 my ($self, %options) = @_;
42
43 $self->{maps_counters_type} = [
44 { name => 'version', type => 0 }
45 ];
46
47 $self->{maps_counters}->{version} = [
48 { label => 'version', type => 2, set => {
49 key_values => [ { name => 'version' }, { name => 'repoid' }, { name => 'release' } ],
50 closure_custom_output => $self->can('custom_version_output'),
51 closure_custom_perfdata => sub { return 0; },
52 closure_custom_threshold_check => \&catalog_status_threshold_ng
53 }
54 }
55 ];
56 }
57
58 sub new {
59 my ($class, %options) = @_;
60 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
61 bless $self, $class;
62
63 $options{options}->add_options(arguments => {
64 });
65
66 return $self;
67 }
68
69 sub manage_selection {
70 my ($self, %options) = @_;
71
72 my $result = $options{custom}->request(endpoint => '/version');
73 if (defined($result->{version})) {
74 $self->{version} = $result->{version};
75 } elsif (defined($result->{data}) && defined($result->{data}->{version})) {
76 $self->{version} = $result->{data};
77 } else {
78 $self->{version} = {
79 version => 'unknown',
80 repoid => 'unknown',
81 release => 'unknown'
82 };
83 }
84 }
85
86 1;
87
88 __END__
89
90 =head1 MODE
91
92 Check version.
93
94 =over 8
95
96 =item B<--warning-version>
97
98 Set warning threshold for version.
99 You can use the following variables: %{version}, %{repoid}, %{release}
100
101 =item B<--critical-version>
102
103 Set critical threshold for version.
104 You can use the following variables: %{version}, %{repoid}, %{release}
105
106 =back
107
108 =cut