| 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::devices::barco::cs::restapi::mode::device; |
| 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_device_status_output { |
| 30 |
my ($self, %options) = @_; |
| 31 |
|
| 32 |
return sprintf('status: %s', $self->{result_values}->{status}); |
| 33 |
} |
| 34 |
|
| 35 |
sub custom_process_status_output { |
| 36 |
my ($self, %options) = @_; |
| 37 |
|
| 38 |
return sprintf('status is %s', $self->{result_values}->{status}); |
| 39 |
} |
| 40 |
|
| 41 |
sub custom_cpu_temp_perfdata { |
| 42 |
my ($self, %options) = @_; |
| 43 |
|
| 44 |
$self->{output}->perfdata_add( |
| 45 |
nlabel => $self->{nlabel}, |
| 46 |
unit => 'C', |
| 47 |
instances => 'cpu', |
| 48 |
value => $self->{result_values}->{cpu}, |
| 49 |
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}), |
| 50 |
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}) |
| 51 |
); |
| 52 |
} |
| 53 |
|
| 54 |
sub custom_pcie_temp_perfdata { |
| 55 |
my ($self, %options) = @_; |
| 56 |
|
| 57 |
$self->{output}->perfdata_add( |
| 58 |
nlabel => $self->{nlabel}, |
| 59 |
unit => 'C', |
| 60 |
instances => 'pcie', |
| 61 |
value => $self->{result_values}->{pcie}, |
| 62 |
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}), |
| 63 |
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}) |
| 64 |
); |
| 65 |
} |
| 66 |
|
| 67 |
sub custom_sio_temp_perfdata { |
| 68 |
my ($self, %options) = @_; |
| 69 |
|
| 70 |
$self->{output}->perfdata_add( |
| 71 |
nlabel => $self->{nlabel}, |
| 72 |
unit => 'C', |
| 73 |
instances => 'sio', |
| 74 |
value => $self->{result_values}->{sio}, |
| 75 |
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}), |
| 76 |
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}) |
| 77 |
); |
| 78 |
} |
| 79 |
|
| 80 |
sub custom_cpu_fan_perfdata { |
| 81 |
my ($self, %options) = @_; |
| 82 |
|
| 83 |
$self->{output}->perfdata_add( |
| 84 |
nlabel => $self->{nlabel}, |
| 85 |
unit => 'rpm', |
| 86 |
instances => 'cpu', |
| 87 |
value => $self->{result_values}->{cpu}, |
| 88 |
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}), |
| 89 |
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}) |
| 90 |
); |
| 91 |
} |
| 92 |
|
| 93 |
sub device_long_output { |
| 94 |
my ($self, %options) = @_; |
| 95 |
|
| 96 |
return 'checking device'; |
| 97 |
} |
| 98 |
|
| 99 |
sub prefix_temperature_output { |
| 100 |
my ($self, %options) = @_; |
| 101 |
|
| 102 |
return 'temperature '; |
| 103 |
} |
| 104 |
|
| 105 |
sub prefix_process_output { |
| 106 |
my ($self, %options) = @_; |
| 107 |
|
| 108 |
return "process '" . $options{instance_value}->{name} . "' "; |
| 109 |
} |
| 110 |
|
| 111 |
sub set_counters { |
| 112 |
my ($self, %options) = @_; |
| 113 |
|
| 114 |
$self->{maps_counters_type} = [ |
| 115 |
{ name => 'device', type => 3, cb_long_output => 'device_long_output', indent_long_output => ' ', |
| 116 |
group => [ |
| 117 |
{ name => 'status', type => 0, display_short => 0, skipped_code => { -10 => 1 } }, |
| 118 |
{ name => 'temperature', type => 0, cb_prefix_output => 'prefix_temperature_output', display_short => 0, skipped_code => { -10 => 1 } }, |
| 119 |
{ name => 'fan', type => 0, display_short => 0, skipped_code => { -10 => 1 } }, |
| 120 |
{ name => 'processes', type => 1, display_long => 1, display_short => 0, cb_prefix_output => 'prefix_process_output', skipped_code => { -10 => 1 } } |
| 121 |
] |
| 122 |
} |
| 123 |
]; |
| 124 |
|
| 125 |
$self->{maps_counters}->{status} = [ |
| 126 |
{ |
| 127 |
label => 'device-status', |
| 128 |
type => 2, |
| 129 |
warning_default => '%{status} =~ /warning/', |
| 130 |
critical_default => '%{status} =~ /error/', |
| 131 |
set => { |
| 132 |
key_values => [ { name => 'status' }, ], |
| 133 |
closure_custom_output => $self->can('custom_device_status_output'), |
| 134 |
closure_custom_perfdata => sub { return 0; }, |
| 135 |
closure_custom_threshold_check => \&catalog_status_threshold_ng |
| 136 |
} |
| 137 |
} |
| 138 |
]; |
| 139 |
|
| 140 |
$self->{maps_counters}->{temperature} = [ |
| 141 |
{ label => 'cpu-temperature', nlabel => 'hardware.temperature.celsius', set => { |
| 142 |
key_values => [ { name => 'cpu' } ], |
| 143 |
output_template => 'cpu %s C', |
| 144 |
closure_custom_perfdata => $self->can('custom_cpu_temp_perfdata') |
| 145 |
} |
| 146 |
}, |
| 147 |
{ label => 'pcie-temperature', nlabel => 'hardware.temperature.celsius', set => { |
| 148 |
key_values => [ { name => 'pcie' } ], |
| 149 |
output_template => 'pcie %s C', |
| 150 |
closure_custom_perfdata => $self->can('custom_pcie_temp_perfdata') |
| 151 |
} |
| 152 |
}, |
| 153 |
{ label => 'sio-temperature', nlabel => 'hardware.temperature.celsius', set => { |
| 154 |
key_values => [ { name => 'sio' } ], |
| 155 |
output_template => 'sio %s C', |
| 156 |
closure_custom_perfdata => $self->can('custom_sio_temp_perfdata') |
| 157 |
} |
| 158 |
} |
| 159 |
]; |
| 160 |
|
| 161 |
$self->{maps_counters}->{fan} = [ |
| 162 |
{ label => 'cpu-fanspeed', nlabel => 'hardware.fan.speed.rpm', set => { |
| 163 |
key_values => [ { name => 'cpu' } ], |
| 164 |
output_template => 'cpu fan speed %s rpm', |
| 165 |
closure_custom_perfdata => $self->can('custom_cpu_fan_perfdata') |
| 166 |
} |
| 167 |
} |
| 168 |
]; |
| 169 |
|
| 170 |
$self->{maps_counters}->{processes} = [ |
| 171 |
{ |
| 172 |
label => 'process-status', type => 2, |
| 173 |
set => { |
| 174 |
key_values => [ { name => 'name' }, { name => 'status' } ], |
| 175 |
closure_custom_output => $self->can('custom_process_status_output'), |
| 176 |
closure_custom_perfdata => sub { return 0; }, |
| 177 |
closure_custom_threshold_check => \&catalog_status_threshold_ng |
| 178 |
} |
| 179 |
} |
| 180 |
]; |
| 181 |
} |
| 182 |
|
| 183 |
sub new { |
| 184 |
my ($class, %options) = @_; |
| 185 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); |
| 186 |
bless $self, $class; |
| 187 |
|
| 188 |
$options{options}->add_options(arguments => { |
| 189 |
}); |
| 190 |
|
| 191 |
return $self; |
| 192 |
} |
| 193 |
|
| 194 |
sub manage_selection { |
| 195 |
my ($self, %options) = @_; |
| 196 |
|
| 197 |
my $map_status = { |
| 198 |
0 => 'ok', 1 => 'warning', 2 => 'error' |
| 199 |
}; |
| 200 |
my $versions = $options{custom}->request_api(endpoint => '/SupportedVersions'); |
| 201 |
my $version = 'v1.0'; |
| 202 |
foreach (@{$versions->{data}->{value}}) { |
| 203 |
$version = 'v1.11' if ($_ eq 'v1.11'); |
| 204 |
} |
| 205 |
|
| 206 |
my $device_status = $options{custom}->request_api(endpoint => '/v1.0/DeviceInfo/Status'); |
| 207 |
my $sensors = $options{custom}->request_api(endpoint => '/' . $version . '/DeviceInfo/Sensors'); |
| 208 |
my $processes = $options{custom}->request_api(endpoint => '/v1.0/DeviceInfo/Processes/ProcessTable'); |
| 209 |
|
| 210 |
$self->{output}->output_add(short_msg => 'device is ok'); |
| 211 |
|
| 212 |
$self->{device} = { |
| 213 |
global => { |
| 214 |
status => { status => $map_status->{ $device_status->{data}->{value} } }, |
| 215 |
temperature => { |
| 216 |
cpu => (defined($sensors->{data}->{value}->{CpuTemperature}) && $sensors->{data}->{value}->{CpuTemperature} != 0) ? |
| 217 |
$sensors->{data}->{value}->{CpuTemperature} : undef, |
| 218 |
pcie => (defined($sensors->{data}->{value}->{PcieTemperature}) && $sensors->{data}->{value}->{PcieTemperature} != 0) ? |
| 219 |
$sensors->{data}->{value}->{PcieTemperature} : undef, |
| 220 |
sio => (defined($sensors->{data}->{value}->{SioTemperature}) && $sensors->{data}->{value}->{SioTemperature} != 0) ? |
| 221 |
$sensors->{data}->{value}->{SioTemperature} : undef |
| 222 |
}, |
| 223 |
fan => { |
| 224 |
cpu => (defined($sensors->{data}->{value}->{CpuFanSpeed}) && $sensors->{data}->{value}->{CpuFanSpeed} != 0) ? |
| 225 |
$sensors->{data}->{value}->{CpuFanSpeed} : undef |
| 226 |
}, |
| 227 |
processes => {} |
| 228 |
} |
| 229 |
}; |
| 230 |
|
| 231 |
foreach (values %{$processes->{data}->{value}}) { |
| 232 |
$self->{device}->{global}->{processes}->{ $_->{Name} } = { |
| 233 |
name => $_->{Name}, |
| 234 |
status => $_->{Status} =~ /true|1/i ? 'running' : 'notRunning' |
| 235 |
}; |
| 236 |
} |
| 237 |
} |
| 238 |
|
| 239 |
1; |
| 240 |
|
| 241 |
__END__ |
| 242 |
|
| 243 |
=head1 MODE |
| 244 |
|
| 245 |
Check device. |
| 246 |
|
| 247 |
=over 8 |
| 248 |
|
| 249 |
=item B<--filter-counters> |
| 250 |
|
| 251 |
Only display some counters (regexp can be used). |
| 252 |
Example: --filter-counters='status' |
| 253 |
|
| 254 |
=item B<--warning-device-status> |
| 255 |
|
| 256 |
Set warning threshold (default: '%{status} =~ /warning/'). |
| 257 |
You can use the following variables: %{status} |
| 258 |
|
| 259 |
=item B<--critical-device-status> |
| 260 |
|
| 261 |
Set critical threshold (default: '%{status} =~ /error/'). |
| 262 |
You can use the following variables: %{status} |
| 263 |
|
| 264 |
=item B<--warning-process-status> |
| 265 |
|
| 266 |
Set warning threshold. |
| 267 |
You can use the following variables: %{name}, %{status} |
| 268 |
|
| 269 |
=item B<--critical-process-status> |
| 270 |
|
| 271 |
Set critical threshold. |
| 272 |
You can use the following variables: %{name}, %{status} |
| 273 |
|
| 274 |
=item B<--warning-*> B<--critical-*> |
| 275 |
|
| 276 |
Thresholds. |
| 277 |
Can be: 'cpu-temperature', 'pcie-temperature', 'sio-temperature', |
| 278 |
'cpu-fanspeed'. |
| 279 |
|
| 280 |
=back |
| 281 |
|
| 282 |
=cut |