add hanwha camera snmp plugin

This commit is contained in:
garnier-quentin 2019-08-06 15:01:15 +02:00
parent 52acd75655
commit 16127cc919
4 changed files with 286 additions and 0 deletions

View File

@ -0,0 +1,57 @@
#
# 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::devices::camera::hanwha::snmp::mode::components::sdcard;
use strict;
use warnings;
my $oid_nwCam = '.1.3.6.1.4.1.36849.1.2';
sub load {}
sub check {
my ($self) = @_;
$self->{output}->output_add(long_msg => "Checking sdcard");
$self->{components}->{sdcard} = { name => 'sdcard', total => 0, skip => 0 };
return if ($self->check_filter(section => 'sdcard'));
my $branch_sdcard_status = '4.3.0';
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_nwCam}})) {
next if ($oid !~ /^$oid_nwCam\.(\d+)\.$branch_sdcard_status$/);
my $instance = '0';
my $sdcard_status = $self->{results}->{$oid_nwCam}->{$oid};
next if ($self->check_filter(section => 'sdcard', instance => $instance));
$self->{components}->{sdcard}->{total}++;
$self->{output}->output_add(long_msg => sprintf("sdcard '%s' status is '%s' [instance = %s]",
$instance, $sdcard_status, $instance));
my $exit = $self->get_severity(section => 'sdcard', instance => $instance, value => $sdcard_status);
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("sdcard '%s' status is '%s'", $instance, $sdcard_status));
}
}
}
1;

View File

@ -0,0 +1,81 @@
#
# 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::devices::camera::hanwha::snmp::mode::components::service;
use strict;
use warnings;
my $services = {
'3.1.1.1' => 'alarmInput1',
'3.1.2.1' => 'alarmInput2',
'3.1.3.1' => 'alarmInput3',
'3.1.4.1' => 'alarmInput4',
'3.2.1.1' => 'relayOutput1',
'3.2.2.1' => 'relayOutput2',
'3.2.3.1' => 'relayOutput3',
'3.2.4.1' => 'relayOutput4',
'3.3.1' => 'motionDetection',
'3.4.1' => 'videoAnalytics',
'3.5.1' => 'faceDetection',
'3.6.1' => 'networkDisconnection',
'3.7.1' => 'tampering',
'3.8.1' => 'audioDetection',
'3.10.1' => 'defocus',
'3.11.1' => 'fogDetection',
'3.12.1' => 'soundClassification',
'3.13.1' => 'shockDetection',
'3.14.1' => 'temperatureDetection',
};
my $oid_nwCam = '.1.3.6.1.4.1.36849.1.2';
sub load {}
sub check {
my ($self) = @_;
$self->{output}->output_add(long_msg => "Checking services");
$self->{components}->{service} = { name => 'services', total => 0, skip => 0 };
return if ($self->check_filter(section => 'service'));
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_nwCam}})) {
next if ($oid !~ /^$oid_nwCam\.(\d+)\.(.*?)\.0$/);
my ($product_id, $service) = ($1, $2);
next if (!defined($services->{$service}));
my $instance = $services->{$service};
my $service_status = $self->{results}->{$oid_nwCam}->{$oid};
my $service_date = defined($self->{results}->{$oid_nwCam}->{$oid_nwCam . '.' . $product_id . '.' . $service . '.1'}) ?
$self->{results}->{$oid_nwCam}->{$oid_nwCam . '.' . $product_id . '.' . $service . '.1'} : '-';
next if ($self->check_filter(section => 'service', instance => $instance));
$self->{components}->{service}->{total}++;
$self->{output}->output_add(long_msg => sprintf("service '%s' status is '%s' [instance = %s] [date = %s]",
$instance, $service_status, $instance, $service_date));
my $exit = $self->get_severity(section => 'service', instance => $instance, value => $service_status);
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("service '%s' status is '%s'", $instance, $service_status));
}
}
}
1;

View File

@ -0,0 +1,100 @@
#
# 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::devices::camera::hanwha::snmp::mode::hardware;
use base qw(centreon::plugins::templates::hardware);
use strict;
use warnings;
sub set_system {
my ($self, %options) = @_;
$self->{regexp_threshold_overload_check_section_option} = '^service|sdcard$';
$self->{cb_hook2} = 'snmp_execute';
$self->{thresholds} = {
service => [
['low', 'OK'],
['high', 'CRITICAL'],
],
sdcard => [
['normal', 'OK'],
['fail', 'CRITICAL'],
],
};
$self->{components_path} = 'hardware::devices::camera::hanwha::snmp::mode::components';
$self->{components_module} = ['service', 'sdcard'];
}
sub snmp_execute {
my ($self, %options) = @_;
$self->{snmp} = $options{snmp};
my $oid_nwCam = '.1.3.6.1.4.1.36849.1.2';
$self->{results} = $self->{snmp}->get_multiple_table(oids => [ { oid => $oid_nwCam } ]);
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1, no_performance => 1, no_absent => 1);
bless $self, $class;
$options{options}->add_options(arguments => {});
return $self;
}
1;
__END__
=head1 MODE
Check hardware.
=over 8
=item B<--component>
Which component to check (Default: '.*').
Can be: 'service', 'sdcard'.
=item B<--filter>
Exclude some parts (comma seperated list)
Can also exclude specific instance: --filter=instance,relayOutput1
=item B<--no-component>
Return an error if no compenents are checked.
If total (with skipped) is 0. (Default: 'critical' returns).
=item B<--threshold-overload>
Set to overload default threshold values (syntax: section,[instance,]status,regexp)
It used before default thresholds (order stays).
Example: --threshold-overload='service,relayOutpu1,OK,high'
=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::devices::camera::hanwha::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}} = (
'hardware' => 'hardware::devices::camera::hanwha::snmp::mode::hardware',
);
return $self;
}
1;
__END__
=head1 PLUGIN DESCRIPTION
Check Hanwha camera in SNMP.
=cut