Debian Codegraph @

src/storage/emc/xtremio/restapi/mode/xenvscpu.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::emc::xtremio::restapi::mode::xenvscpu;
22
23 use base qw(centreon::plugins::mode);
24
25 use strict;
26 use warnings;
27
28 sub new {
29 my ($class, %options) = @_;
30 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
31 bless $self, $class;
32
33 $options{options}->add_options(arguments =>
34 {
35 "filter:s@" => { name => 'filter' },
36 "warning:s" => { name => 'warning' },
37 "critical:s" => { name => 'critical' },
38 });
39
40 return $self;
41 }
42
43 sub check_options {
44 my ($self, %options) = @_;
45 $self->SUPER::init(%options);
46
47 $self->{filter} = [];
48 foreach my $val (@{$self->{option_results}->{filter}}) {
49 next if (!defined($val) || $val eq '');
50 my @values = split (/,/, $val);
51 push @{$self->{filter}}, { filter => $values[0], instance => $values[1] };
52 }
53
54 if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) {
55 $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
56 $self->{output}->option_exit();
57 }
58 if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
59 $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
60 $self->{output}->option_exit();
61 }
62 }
63
64 sub run {
65 my ($self, %options) = @_;
66 my $xtremio = $options{custom};
67
68 my $urlbase = '/api/json/types/';
69 my @items = $xtremio->get_items(url => $urlbase,
70 obj => 'xenvs');
71
72 $self->{output}->output_add(severity => 'OK',
73 short_msg => 'All Xenvs CPU Usage are OK');
74
75 foreach my $item (@items) {
76 next if ($self->check_filter(section => 'cpu', instance => $item));
77 my $details = $xtremio->get_details(url => $urlbase,
78 obj => 'xenvs',
79 name => $item);
80
81 $self->{output}->output_add(long_msg => sprintf("Xenvs '%s' CPU Usage is %i%%",
82 $item,
83 $details->{'cpu-usage'}));
84
85
86 my $exit = $self->{perfdata}->threshold_check(value => $details->{'cpu-usage'}, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
87 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
88 $self->{output}->output_add(severity => $exit,
89 short_msg => sprintf("Xenvs '%s' cpu-Usage is %i%%",
90 $item,
91 $details->{'cpu-usage'}));
92 }
93 $self->{output}->perfdata_add(label => 'cpu_' . $item, unit => '%',
94 value => $details->{'cpu-usage'},
95 warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
96 critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
97 min => 0, max => 100);
98 }
99
100 $self->{output}->display();
101 $self->{output}->exit();
102
103 }
104
105 sub check_filter {
106 my ($self, %options) = @_;
107
108 foreach (@{$self->{filter}}) {
109 if ($options{section} =~ /$_->{filter}/) {
110 if (!defined($options{instance}) && !defined($_->{instance})) {
111 $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section."));
112 return 1;
113 } elsif (defined($options{instance}) && $options{instance} =~ /$_->{instance}/) {
114 $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section $options{instance} instance."));
115 return 1;
116 }
117 }
118 }
119
120 return 0;
121 }
122
123 1;
124
125 __END__
126
127 =head1 MODE
128
129 Check Xenvs CPU usage
130
131 =over 8
132
133 =item B<--filter>
134
135 Filter some parts (comma separated list)
136 You can also exclude items from specific instances: --filter=cpu,XENVS-NAME-NUMBER
137
138 =item B<--warning>
139
140 Value to trigger a warning alarm on CPU usage
141
142 =item B<--critical>
143
144 Value to trigger a critical alarm on CPU usage
145
146 =back
147
148 =cut