Debian Codegraph @

src/hardware/sensors/sensormetrix/em01/web/mode/humidity.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::sensors::sensormetrix::em01::web::mode::humidity;
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?em" },
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 my $humidity;
71
72 if ($webcontent !~ /<body>(.*)<\/body>/msi || $1 !~ /HU:\s*([0-9\.]+)/i) {
73 $self->{output}->add_option_msg(short_msg => "Could not find humidity information.");
74 $self->{output}->option_exit();
75 }
76 $humidity = $1;
77 $humidity = '0' . $humidity if ($humidity =~ /^\./);
78
79 my $exit = $self->{perfdata}->threshold_check(value => $humidity, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
80
81 $self->{output}->output_add(severity => $exit,
82 short_msg => sprintf("Humidity: %.2f %%", $humidity));
83 $self->{output}->perfdata_add(label => "humidity", unit => '%',
84 value => sprintf("%.2f", $humidity),
85 warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
86 critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
87 );
88
89 $self->{output}->display();
90 $self->{output}->exit();
91
92 }
93
94 1;
95
96 __END__
97
98 =head1 MODE
99
100 Check sensor Humidity.
101
102 =over 8
103
104 =item B<--hostname>
105
106 IP Addr/FQDN of the web server host
107
108 =item B<--port>
109
110 Port used by Apache
111
112 =item B<--proto>
113
114 Specify https if needed
115
116 =item B<--urlpath>
117
118 Set path to get server-status page in auto mode (default: '/index.htm?em')
119
120 =item B<--credentials>
121
122 Specify this option if you access server-status page with authentication
123
124 =item B<--username>
125
126 Specify the username for authentication (mandatory if --credentials is specified)
127
128 =item B<--password>
129
130 Specify the password for authentication (mandatory if --credentials is specified)
131
132 =item B<--basic>
133
134 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.
135
136 Specify this option if you access server-status page over hidden basic authentication or you'll get a '404 NOT FOUND' error.
137
138 (use with --credentials)
139
140 =item B<--timeout>
141
142 Threshold for HTTP timeout
143
144 =item B<--warning>
145
146 Warning Threshold for Humidity
147
148 =item B<--critical>
149
150 Critical Threshold for Humidity
151
152 =back
153
154 =cut