Debian Codegraph @

src/hardware/server/ibm/hmc/ssh/mode/hardwareerrors.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 hardware::server::ibm::hmc::ssh::mode::hardwareerrors;
22
23 use base qw(centreon::plugins::mode);
24
25 use strict;
26 use warnings;
27 use centreon::plugins::misc;
28
29 sub new {
30 my ($class, %options) = @_;
31 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
32 bless $self, $class;
33
34 $options{options}->add_options(arguments => {
35 'hmc-command:s' => { name => 'hmc_command', default => 'lssvcevents' },
36 'retention:s' => { name => 'retention' },
37 'minutes' => { name => 'minutes' },
38 'filter-status:s' => { name => 'filter_status', default => 'open' },
39 'filter-problem-nums:s' => { name => 'filter_problem_nums' },
40 'filter-system:s' => { name => 'filter_system' }
41 });
42
43 return $self;
44 }
45
46 sub check_options {
47 my ($self, %options) = @_;
48 $self->SUPER::init(%options);
49
50 if (defined($self->{option_results}->{retention}) && $self->{option_results}->{retention} !~ /^\d+$/) {
51 $self->{output}->add_option_msg(short_msg => 'Need to specify an integer as retention.');
52 $self->{output}->option_exit();
53 }
54 }
55
56 sub build_command {
57 my ($self, %options) = @_;
58
59 $self->{hmc_command} = $self->{option_results}->{hmc_command} . ' -t hardware -F first_time~sys_name~text ';
60 if (defined($self->{option_results}->{retention}) && $self->{option_results}->{retention} ne '') {
61 if (defined($self->{option_results}->{minutes})) {
62 $self->{hmc_command} .= ' -i ' . $self->{option_results}->{retention};
63 } else {
64 $self->{hmc_command} .= ' -d ' . $self->{option_results}->{retention};
65 }
66 }
67
68 if ($self->{option_results}->{filter_status} ne '' && (!defined($self->{option_results}->{filter_problem_nums}) || ($self->{option_results}->{filter_problem_nums} eq ''))) {
69 $self->{hmc_command} .= ' --filter "status=' . $self->{option_results}->{filter_status} . '" ';
70 } elsif ($self->{option_results}->{filter_status} ne '' && defined($self->{option_results}->{filter_problem_nums}) && $self->{option_results}->{filter_problem_nums} ne '') {
71 $self->{hmc_command} .= ' --filter "status=' . $self->{option_results}->{filter_status} . ',problem_nums=' . $self->{option_results}->{filter_problem_nums} . '"';
72 } elsif (defined($self->{option_results}->{filter_problem_nums}) && $self->{option_results}->{filter_problem_nums} ne '') {
73 $self->{hmc_command} .= ' --filter "status=' . $self->{option_results}->{filter_problem_nums} . '"';
74 }
75
76 if (defined($self->{option_results}->{filter_system}) && $self->{option_results}->{filter_system} ne '') {
77 $self->{hmc_command} .= ' -m ' . $self->{option_results}->{filter_system} . ' ';
78 }
79 }
80
81 sub run {
82 my ($self, %options) = @_;
83
84 $self->build_command();
85 my ($stdout) = $options{custom}->execute_command(
86 command => $self->{hmc_command}
87 );
88
89 ######
90 # Command treatment
91 ######
92 my @long_msg = split("\n", $stdout);
93 if (defined($self->{option_results}->{retention}) and defined($self->{option_results}->{minutes})) {
94 $self->{output}->output_add(
95 severity => 'OK',
96 short_msg => "No problems on system since " . $self->{option_results}->{retention} . " minutes."
97 );
98 } elsif (defined($self->{option_results}->{retention})) {
99 $self->{output}->output_add(
100 severity => 'OK',
101 short_msg => "No Problems on system since " . $self->{option_results}->{retention} . " days."
102 );
103 } else {
104 $self->{output}->output_add(
105 severity => 'OK',
106 short_msg => "No problems on system."
107 );
108 }
109
110 foreach my $line (@long_msg){
111 if ($line =~ /^(.*)~(.*)~(.*)$/) {
112 $self->{output}->output_add(
113 severity => 'CRITICAL',
114 short_msg => "[$1][$2] $3"
115 );
116 }
117 }
118
119 $self->{output}->display();
120 $self->{output}->exit();
121 }
122
123 1;
124
125 __END__
126
127 =head1 MODE
128
129 Check Hardware for system managed by HMC.
130
131 =over 8
132
133 =item B<--command-hmc>
134
135 Hmc command to list events (default: lssvcevents).
136
137 =item B<--timeout>
138
139 Timeout in seconds for the command (default: 30).
140
141 =item B<--retention>
142
143 Retention of errors. If option --minutes is not specified, retention is in days.
144
145 =item B<--minutes>
146
147 Retention in minutes. Use with option --retention.
148
149 =item B<--filter-status>
150
151 Filter by status ("open" or "closed") (default : open).
152
153 =item B<--filter-problem-nums>
154
155 Filter by problem number (several number can be specified, separated by coma).
156
157 =item B<--filter-system>
158
159 Filter by system. The name may either be the user-defined name for the managed system, or be in the form tttt-mmm*ssssssss, where tttt is the machine type, mmm is the model, and ssssssss is the serial number of the managed system
160
161 =back
162
163 =cut