| 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::sensors::sensormetrix::em01::web::mode::thermistor; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::mode); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
use centreon::plugins::http; |
| 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 |
"hostname:s" => { name => 'hostname' }, |
| 36 |
"port:s" => { name => 'port', }, |
| 37 |
"proto:s" => { name => 'proto' }, |
| 38 |
"urlpath:s" => { name => 'url_path', default => "/index.htm?eR" }, |
| 39 |
"credentials" => { name => 'credentials' }, |
| 40 |
"basic" => { name => 'basic' }, |
| 41 |
"username:s" => { name => 'username' }, |
| 42 |
"password:s" => { name => 'password' }, |
| 43 |
"warning:s" => { name => 'warning' }, |
| 44 |
"critical:s" => { name => 'critical' }, |
| 45 |
"timeout:s" => { name => 'timeout' }, |
| 46 |
}); |
| 47 |
$self->{http} = centreon::plugins::http->new(%options); |
| 48 |
return $self; |
| 49 |
} |
| 50 |
|
| 51 |
sub check_options { |
| 52 |
my ($self, %options) = @_; |
| 53 |
$self->SUPER::init(%options); |
| 54 |
|
| 55 |
if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) { |
| 56 |
$self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'."); |
| 57 |
$self->{output}->option_exit(); |
| 58 |
} |
| 59 |
if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) { |
| 60 |
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); |
| 61 |
$self->{output}->option_exit(); |
| 62 |
} |
| 63 |
$self->{http}->set_options(%{$self->{option_results}}); |
| 64 |
} |
| 65 |
|
| 66 |
sub run { |
| 67 |
my ($self, %options) = @_; |
| 68 |
|
| 69 |
my $webcontent = $self->{http}->request(); |
| 70 |
|
| 71 |
if ($webcontent !~ /<body>(.*)<\/body>/msi || $1 !~ /R([CF])\s*([0-9\.]+)/i) { |
| 72 |
$self->{output}->add_option_msg(short_msg => "Could not find thermistor temperature information."); |
| 73 |
$self->{output}->option_exit(); |
| 74 |
} |
| 75 |
my ($temperature, $unit) = ($2, $1); |
| 76 |
$temperature = '0' . $temperature if ($temperature =~ /^\./); |
| 77 |
|
| 78 |
my $exit = $self->{perfdata}->threshold_check(value => $temperature, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); |
| 79 |
|
| 80 |
$self->{output}->output_add(severity => $exit, |
| 81 |
short_msg => sprintf("Temperature: %.2f %s", $temperature, $unit)); |
| 82 |
$self->{output}->perfdata_add(label => "temperature", unit => $unit, |
| 83 |
value => sprintf("%.2f", $temperature), |
| 84 |
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), |
| 85 |
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), |
| 86 |
); |
| 87 |
|
| 88 |
$self->{output}->display(); |
| 89 |
$self->{output}->exit(); |
| 90 |
|
| 91 |
} |
| 92 |
|
| 93 |
1; |
| 94 |
|
| 95 |
__END__ |
| 96 |
|
| 97 |
=head1 MODE |
| 98 |
|
| 99 |
Check sensor thermistor temperature. |
| 100 |
|
| 101 |
=over 8 |
| 102 |
|
| 103 |
=item B<--hostname> |
| 104 |
|
| 105 |
IP Addr/FQDN of the web server host |
| 106 |
|
| 107 |
=item B<--port> |
| 108 |
|
| 109 |
Port used by Apache |
| 110 |
|
| 111 |
=item B<--proto> |
| 112 |
|
| 113 |
Specify https if needed |
| 114 |
|
| 115 |
=item B<--urlpath> |
| 116 |
|
| 117 |
Set path to get server-status page in auto mode (default: '/index.htm?eR') |
| 118 |
|
| 119 |
=item B<--credentials> |
| 120 |
|
| 121 |
Specify this option if you access server-status page with authentication |
| 122 |
|
| 123 |
=item B<--username> |
| 124 |
|
| 125 |
Specify the username for authentication (mandatory if --credentials is specified) |
| 126 |
|
| 127 |
=item B<--password> |
| 128 |
|
| 129 |
Specify the password for authentication (mandatory if --credentials is specified) |
| 130 |
|
| 131 |
=item B<--basic> |
| 132 |
|
| 133 |
Specify this option if you access server-status page over basic authentication and don't want a '401 UNAUTHORIZED' error to be logged on your web server. |
| 134 |
|
| 135 |
Specify this option if you access server-status page over hidden basic authentication or you'll get a '404 NOT FOUND' error. |
| 136 |
|
| 137 |
(use with --credentials) |
| 138 |
|
| 139 |
=item B<--timeout> |
| 140 |
|
| 141 |
Threshold for HTTP timeout |
| 142 |
|
| 143 |
=item B<--warning> |
| 144 |
|
| 145 |
Warning Threshold for Thermistor Temperature |
| 146 |
|
| 147 |
=item B<--critical> |
| 148 |
|
| 149 |
Critical Threshold for Thermistor Temperature |
| 150 |
|
| 151 |
=back |
| 152 |
|
| 153 |
=cut |