This commit is contained in:
garnier-quentin 2019-06-13 12:55:37 +02:00
parent 236763d4f8
commit 4340022c1b
6 changed files with 499 additions and 0 deletions

View File

@ -0,0 +1,82 @@
#
# Copyright 2019 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package hardware::pdu::schleifenbauer::gateway::snmp::mode::components::contact;
use strict;
use warnings;
use hardware::pdu::schleifenbauer::gateway::snmp::mode::components::resources qw($oid_pdumeasuresEntry $oid_deviceName $mapping);
sub load {}
sub check_contact {
my ($self, %options) = @_;
my $description = $options{device_name};
$description .= '.' . ((defined($options{sensor_name}) && $options{sensor_name} ne '') ? $options{sensor_name} : $options{num});
next if ($self->check_filter(section => 'contact', instance => $options{instance}, name => $description));
$self->{components}->{contact}->{total}++;
$self->{output}->output_add(long_msg => sprintf("contact '%s' is %s [instance = %s]",
$description, $options{value}, $options{instance}));
my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'contact', instance => $options{instance}, name => $description, value => $options{value});
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("Contact '%s' is %s %%", $description, $options{value}));
}
$self->{output}->perfdata_add(
label => 'contact',
nlabel => 'hardware.sensor.contact.count',
instances => [$options{device_name}, (defined($options{sensor_name}) && $options{sensor_name} ne '') ? $options{sensor_name} : $options{num}],
value => $options{value},
warning => $warn,
critical => $crit,
min => 0, max => 100
);
}
sub check {
my ($self) = @_;
$self->{output}->output_add(long_msg => "Checking contact");
$self->{components}->{contact} = { name => 'contact', total => 0, skip => 0 };
return if ($self->check_filter(section => 'contact'));
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_deviceName}})) {
$oid =~ /^$oid_deviceName.(.*)$/;
my $instance = $1;
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_pdumeasuresEntry}, instance => $instance);
for (my $i = 1; $i <= 16; $i++) {
next if (!defined($result->{'sensor' . $i . 'Type'}) || $result->{'sensor' . $i . 'Type'} !~ /I/);
check_contact($self,
instance => $instance,
device_name => $self->{results}->{$oid_deviceName}->{$oid},
num => $i,
value => $result->{'sensor' . $i . 'Value'},
sensor_name => $result->{'sensor' . $i . 'Name'},
);
}
}
}
1;

View File

@ -0,0 +1,82 @@
#
# Copyright 2019 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package hardware::pdu::schleifenbauer::gateway::snmp::mode::components::humidity;
use strict;
use warnings;
use hardware::pdu::schleifenbauer::gateway::snmp::mode::components::resources qw($oid_pdumeasuresEntry $oid_deviceName $mapping);
sub load {}
sub check_humidity {
my ($self, %options) = @_;
my $description = $options{device_name};
$description .= '.' . ((defined($options{sensor_name}) && $options{sensor_name} ne '') ? $options{sensor_name} : $options{num});
next if ($self->check_filter(section => 'humidity', instance => $options{instance}, name => $description));
$self->{components}->{humidity}->{total}++;
$self->{output}->output_add(long_msg => sprintf("humidity '%s' is %s %% [instance = %s]",
$description, $options{value}, $options{instance}));
my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'humidity', instance => $options{instance}, name => $description, value => $options{value});
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("Humdity '%s' is %s %%", $description, $options{value}));
}
$self->{output}->perfdata_add(
label => 'humidity', unit => '%',
nlabel => 'hardware.sensor.humidity.percentage',
instances => [$options{device_name}, (defined($options{sensor_name}) && $options{sensor_name} ne '') ? $options{sensor_name} : $options{num}],
value => $options{value},
warning => $warn,
critical => $crit,
min => 0, max => 100
);
}
sub check {
my ($self) = @_;
$self->{output}->output_add(long_msg => "Checking humidity");
$self->{components}->{humidity} = { name => 'humidity', total => 0, skip => 0 };
return if ($self->check_filter(section => 'humidity'));
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_deviceName}})) {
$oid =~ /^$oid_deviceName.(.*)$/;
my $instance = $1;
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_pdumeasuresEntry}, instance => $instance);
for (my $i = 1; $i <= 16; $i++) {
next if (!defined($result->{'sensor' . $i . 'Type'}) || $result->{'sensor' . $i . 'Type'} !~ /H/);
check_humidity($self,
instance => $instance,
device_name => $self->{results}->{$oid_deviceName}->{$oid},
num => $i,
value => $result->{'sensor' . $i . 'Value'},
sensor_name => $result->{'sensor' . $i . 'Name'},
);
}
}
}
1;

View File

@ -0,0 +1,90 @@
#
# Copyright 2019 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package hardware::pdu::schleifenbauer::gateway::snmp::mode::components::resources;
use strict;
use warnings;
use Exporter;
our $oid_pdumeasuresEntry;
our $oid_deviceName;
our $mapping;
our @ISA = qw(Exporter);
our @EXPORT_OK = qw($oid_pdumeasuresEntry $oid_deviceName $mapping);
$oid_pdumeasuresEntry = '.1.3.6.1.4.1.31034.1.1.8.1';
$oid_deviceName = '.1.3.6.1.4.1.31034.1.1.4.1.3';
$mapping = {
pduIntTemperature => { oid => '.1.3.6.1.4.1.31034.1.1.8.1.3' },
pduExtTemperature => { oid => '.1.3.6.1.4.1.31034.1.1.8.1.4' },
sensor1Type => { oid => '.1.3.6.1.4.1.31034.1.1.8.1.7' },
sensor1Value => { oid => '.1.3.6.1.4.1.31034.1.1.8.1.8' },
sensor1Name => { oid => '.1.3.6.1.4.1.31034.1.1.8.1.9' },
sensor2Type => { oid => '.1.3.6.1.4.1.31034.1.1.8.1.10' },
sensor2Value => { oid => '.1.3.6.1.4.1.31034.1.1.8.1.11' },
sensor2Name => { oid => '.1.3.6.1.4.1.31034.1.1.8.1.12' },
sensor3Type => { oid => '.1.3.6.1.4.1.31034.1.1.8.1.13' },
sensor3Value => { oid => '.1.3.6.1.4.1.31034.1.1.8.1.14' },
sensor3Name => { oid => '.1.3.6.1.4.1.31034.1.1.8.1.15' },
sensor4Type => { oid => '.1.3.6.1.4.1.31034.1.1.8.1.16' },
sensor4Value => { oid => '.1.3.6.1.4.1.31034.1.1.8.1.17' },
sensor4Name => { oid => '.1.3.6.1.4.1.31034.1.1.8.1.18' },
sensor5Type => { oid => '.1.3.6.1.4.1.31034.1.1.8.1.19' },
sensor5Value => { oid => '.1.3.6.1.4.1.31034.1.1.8.1.20' },
sensor5Name => { oid => '.1.3.6.1.4.1.31034.1.1.8.1.21' },
sensor6Type => { oid => '.1.3.6.1.4.1.31034.1.1.8.1.22' },
sensor6Value => { oid => '.1.3.6.1.4.1.31034.1.1.8.1.23' },
sensor6Name => { oid => '.1.3.6.1.4.1.31034.1.1.8.1.24' },
sensor7Type => { oid => '.1.3.6.1.4.1.31034.1.1.8.1.25' },
sensor7Value => { oid => '.1.3.6.1.4.1.31034.1.1.8.1.26' },
sensor7Name => { oid => '.1.3.6.1.4.1.31034.1.1.8.1.27' },
sensor8Type => { oid => '.1.3.6.1.4.1.31034.1.1.8.1.28' },
sensor8Value => { oid => '.1.3.6.1.4.1.31034.1.1.8.1.29' },
sensor8Name => { oid => '.1.3.6.1.4.1.31034.1.1.8.1.30' },
sensor9Type => { oid => '.1.3.6.1.4.1.31034.1.1.8.1.31' },
sensor9Value => { oid => '.1.3.6.1.4.1.31034.1.1.8.1.32' },
sensor9Name => { oid => '.1.3.6.1.4.1.31034.1.1.8.1.33' },
sensor10Type => { oid => '.1.3.6.1.4.1.31034.1.1.8.1.34' },
sensor10Value => { oid => '.1.3.6.1.4.1.31034.1.1.8.1.35' },
sensor10Name => { oid => '.1.3.6.1.4.1.31034.1.1.8.1.36' },
sensor11Type => { oid => '.1.3.6.1.4.1.31034.1.1.8.1.37' },
sensor11Value => { oid => '.1.3.6.1.4.1.31034.1.1.8.1.38' },
sensor11Name => { oid => '.1.3.6.1.4.1.31034.1.1.8.1.39' },
sensor12Type => { oid => '.1.3.6.1.4.1.31034.1.1.8.1.40' },
sensor12Value => { oid => '.1.3.6.1.4.1.31034.1.1.8.1.41' },
sensor12Name => { oid => '.1.3.6.1.4.1.31034.1.1.8.1.42' },
sensor13Type => { oid => '.1.3.6.1.4.1.31034.1.1.8.1.43' },
sensor13Value => { oid => '.1.3.6.1.4.1.31034.1.1.8.1.44' },
sensor13Name => { oid => '.1.3.6.1.4.1.31034.1.1.8.1.45' },
sensor14Type => { oid => '.1.3.6.1.4.1.31034.1.1.8.1.46' },
sensor14Value => { oid => '.1.3.6.1.4.1.31034.1.1.8.1.47' },
sensor14Name => { oid => '.1.3.6.1.4.1.31034.1.1.8.1.48' },
sensor15Type => { oid => '.1.3.6.1.4.1.31034.1.1.8.1.49' },
sensor15Value => { oid => '.1.3.6.1.4.1.31034.1.1.8.1.50' },
sensor15Name => { oid => '.1.3.6.1.4.1.31034.1.1.8.1.51' },
sensor16Type => { oid => '.1.3.6.1.4.1.31034.1.1.8.1.52' },
sensor16Value => { oid => '.1.3.6.1.4.1.31034.1.1.8.1.53' },
sensor16Name => { oid => '.1.3.6.1.4.1.31034.1.1.8.1.54' },
};
1;

View File

@ -0,0 +1,96 @@
#
# Copyright 2019 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package hardware::pdu::schleifenbauer::gateway::snmp::mode::components::temperature;
use strict;
use warnings;
use hardware::pdu::schleifenbauer::gateway::snmp::mode::components::resources qw($oid_pdumeasuresEntry $oid_deviceName $mapping);
sub load {}
sub check_temperature {
my ($self, %options) = @_;
my $description = $options{device_name};
$description .= '.' . ((defined($options{sensor_name}) && $options{sensor_name} ne '') ? $options{sensor_name} : $options{num});
next if ($self->check_filter(section => 'temperature', instance => $options{instance}, name => $description));
$self->{components}->{temperature}->{total}++;
$self->{output}->output_add(long_msg => sprintf("temperature '%s' is %s C [instance = %s]",
$description, $options{value}, $options{instance}));
my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $options{instance}, name => $description, value => $options{value});
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("Temperature '%s' is %s C", $description, $options{value}));
}
$self->{output}->perfdata_add(
label => 'temperature', unit => 'C',
nlabel => 'hardware.sensor.temperature.celsius',
instances => [$options{device_name}, (defined($options{sensor_name}) && $options{sensor_name} ne '') ? $options{sensor_name} : $options{num}],
value => $options{value},
warning => $warn,
critical => $crit,
);
}
sub check {
my ($self) = @_;
$self->{output}->output_add(long_msg => "Checking temperature");
$self->{components}->{temperature} = { name => 'temperature', total => 0, skip => 0 };
return if ($self->check_filter(section => 'temperature'));
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_deviceName}})) {
$oid =~ /^$oid_deviceName.(.*)$/;
my $instance = $1;
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_pdumeasuresEntry}, instance => $instance);
for (my $i = 1; $i <= 16; $i++) {
next if (!defined($result->{'sensor' . $i . 'Type'}) || $result->{'sensor' . $i . 'Type'} !~ /T/);
check_temperature($self,
instance => $instance,
device_name => $self->{results}->{$oid_deviceName}->{$oid},
num => $i,
value => $result->{'sensor' . $i . 'Value'},
sensor_name => $result->{'sensor' . $i . 'Name'},
);
}
check_temperature($self,
instance => $instance,
device_name => $self->{results}->{$oid_deviceName}->{$oid},
num => 0,
value => $result->{pduIntTemperature},
sensor_name => 'Internal',
) if ($result->{pduIntTemperature} != 0);
check_temperature($self,
instance => $instance,
device_name => $self->{results}->{$oid_deviceName}->{$oid},
num => 0,
value => $result->{pduExtTemperature},
sensor_name => 'External',
) if ($result->{pduExtTemperature} != 0);
}
}
1;

View File

@ -0,0 +1,101 @@
#
# Copyright 2019 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package hardware::pdu::schleifenbauer::gateway::snmp::mode::sensors;
use base qw(centreon::plugins::templates::hardware);
use strict;
use warnings;
use hardware::pdu::schleifenbauer::gateway::snmp::mode::components::resources qw($oid_pdumeasuresEntry $oid_deviceName);
sub set_system {
my ($self, %options) = @_;
$self->{regexp_threshold_overload_check_section_option} = '^(temperature|humidity|contact)$';
$self->{regexp_threshold_numeric_check_section_option} = '^(temperature|humidity|contact)$';
$self->{cb_hook2} = 'snmp_execute';
$self->{components_path} = 'hardware::pdu::schleifenbauer::gateway::snmp::mode::components';
$self->{components_module} = ['humidity', 'temperature', 'contact'];
}
sub snmp_execute {
my ($self, %options) = @_;
$self->{snmp} = $options{snmp};
$self->{results} = $self->{snmp}->get_multiple_table(oids => [
{ oid => $oid_deviceName },
{ oid => $oid_pdumeasuresEntry },
]);
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1, force_new_perfdata => 1);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments => {
});
return $self;
}
1;
__END__
=head1 MODE
Check sensors.
=over 8
=item B<--component>
Which component to check (Default: '.*').
Can be: 'temperature', 'humidity', 'contact'.
=item B<--filter>
Exclude some parts (comma seperated list) (Example: --filter=temperature --filter=contact)
Can also exclude specific instance: --filter=temperature,1
=item B<--no-component>
Return an error if no compenents are checked.
If total (with skipped) is 0. (Default: 'critical' returns).
=item B<--warning>
Set warning threshold for 'temperature', 'humidity', 'contact' (syntax: type,regexp,threshold)
Example: --warning='temperature,.*,30'
=item B<--critical>
Set critical threshold for 'temperature', 'humidity', 'contact' (syntax: type,regexp,threshold)
Example: --warning='temperature,.*,50'
=back
=cut

View File

@ -0,0 +1,48 @@
#
# Copyright 2019 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package hardware::pdu::schleifenbauer::gateway::snmp::plugin;
use strict;
use warnings;
use base qw(centreon::plugins::script_snmp);
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '1.0';
%{$self->{modes}} = (
'sensors' => 'hardware::pdu::schleifenbauer::gateway::snmp::mode::sensors',
);
return $self;
}
1;
__END__
=head1 PLUGIN DESCRIPTION
Check Schleifenbauwer gateway in SNMP.
=cut