centreon-plugins/snmp_standard/mode/printererror.pm

105 lines
3.1 KiB
Perl
Raw Normal View History

2014-03-13 16:53:39 +01:00
#
2019-01-09 09:57:11 +01:00
# Copyright 2019 Centreon (http://www.centreon.com/)
2015-07-21 11:51:02 +02:00
#
# 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.
#
2014-03-13 16:53:39 +01:00
package snmp_standard::mode::printererror;
use base qw(centreon::plugins::mode);
use strict;
use warnings;
my %errors_printer = (
0 => ["Printer is low paper", 'WARNING'],
1 => ["Printer has no paper", 'WARNING'],
2 => ["Printer is low toner", 'WARNING'],
3 => ["Printer has no toner", 'WARNING'],
4 => ["Printer has a door open", 'WARNING'],
5 => ["Printer is jammed", 'WARNING'],
6 => ["Printer is offline", 'WARNING'],
7 => ["Printer needs service requested", 'WARNING'],
8 => ["Printer has input tray missing", 'WARNING'],
9 => ["Printer has output tray missing", 'WARNING'],
10 => ["Printer has maker supply missing", 'WARNING'],
11 => ["Printer output is near full", 'WARNING'],
12 => ["Printer output is full", 'WARNING'],
13 => ["Printer has input tray empty", 'WARNING'],
14 => ["Printer is 'overdue prevent maint'", 'WARNING'],
);
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
}
sub run {
my ($self, %options) = @_;
$self->{snmp} = $options{snmp};
$self->{output}->output_add(severity => 'OK',
short_msg => "Printer is ok.");
2014-03-14 14:30:52 +01:00
my $oid_hrPrinterDetectedErrorState = '.1.3.6.1.2.1.25.3.5.1.2';
my $result = $self->{snmp}->get_table(oid => $oid_hrPrinterDetectedErrorState, nothing_quit => 1);
2014-03-13 16:53:39 +01:00
2014-03-14 14:30:52 +01:00
foreach (keys %$result) {
2017-11-22 14:14:08 +01:00
# 16 bits value
my $value = unpack('S', $result->{$_});
2014-03-14 14:30:52 +01:00
2017-11-22 14:14:08 +01:00
foreach my $key (keys %errors_printer) {
if (($value & (1 << $key)) &&
2014-03-14 14:30:52 +01:00
(!$self->{output}->is_status(value => ${$errors_printer{$key}}[1], compare => 'ok', litteral => 1))) {
$self->{output}->output_add(severity => ${$errors_printer{$key}}[1],
short_msg => sprintf(${$errors_printer{$key}}[0]));
}
2014-03-13 16:53:39 +01:00
}
}
$self->{output}->display();
$self->{output}->exit();
}
1;
__END__
=head1 MODE
Check printer errors (HOST-RESOURCES-MIB).
=over 8
=back
=cut