| 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::contact; |
| 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?eL" }, |
| 39 |
"credentials" => { name => 'credentials' }, |
| 40 |
"basic" => { name => 'basic' }, |
| 41 |
"username:s" => { name => 'username' }, |
| 42 |
"password:s" => { name => 'password' }, |
| 43 |
"warning" => { name => 'warning' }, |
| 44 |
"critical" => { name => 'critical' }, |
| 45 |
"closed" => { name => 'closed' }, |
| 46 |
"timeout:s" => { name => 'timeout' }, |
| 47 |
}); |
| 48 |
$self->{status} = { closed => 'ok', opened => 'ok' }; |
| 49 |
$self->{http} = centreon::plugins::http->new(%options); |
| 50 |
return $self; |
| 51 |
} |
| 52 |
|
| 53 |
sub check_options { |
| 54 |
my ($self, %options) = @_; |
| 55 |
$self->SUPER::init(%options); |
| 56 |
|
| 57 |
my $label = 'opened'; |
| 58 |
$label = 'closed' if (defined($self->{option_results}->{closed})); |
| 59 |
if (defined($self->{option_results}->{critical})) { |
| 60 |
$self->{status}->{$label} = 'critical'; |
| 61 |
} elsif (defined($self->{option_results}->{warning})) { |
| 62 |
$self->{status}->{$label} = 'warning'; |
| 63 |
} |
| 64 |
|
| 65 |
$self->{http}->set_options(%{$self->{option_results}}); |
| 66 |
} |
| 67 |
|
| 68 |
sub run { |
| 69 |
my ($self, %options) = @_; |
| 70 |
|
| 71 |
my $webcontent = $self->{http}->request(); |
| 72 |
my $contact; |
| 73 |
|
| 74 |
if ($webcontent !~ /<body>(.*)<\/body>/msi || $1 !~ /([NW]).*?:/) { |
| 75 |
$self->{output}->add_option_msg(short_msg => "Could not find door contact information."); |
| 76 |
$self->{output}->option_exit(); |
| 77 |
} |
| 78 |
$contact = $1; |
| 79 |
|
| 80 |
if ($contact eq 'N') { |
| 81 |
$self->{output}->output_add(severity => $self->{status}->{opened}, |
| 82 |
short_msg => sprintf("Door is opened.")); |
| 83 |
} else { |
| 84 |
$self->{output}->output_add(severity => $self->{status}->{closed}, |
| 85 |
short_msg => sprintf("Door is closed.")); |
| 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 contact. |
| 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?eL') |
| 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 if door is opened (can set --close for closed door) |
| 146 |
|
| 147 |
=item B<--critical> |
| 148 |
|
| 149 |
Critical if door is opened (can set --close for closed door) |
| 150 |
|
| 151 |
=item B<--closed> |
| 152 |
|
| 153 |
Threshold is on closed door (default: opened) |
| 154 |
|
| 155 |
=back |
| 156 |
|
| 157 |
=cut |