2014-03-13 16:53:39 +01:00
#
2021-02-08 09:55:50 +01:00
# Copyright 2021 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 ;
2019-02-28 09:32:43 +01:00
use base qw( centreon::plugins::templates::counter ) ;
2014-03-13 16:53:39 +01:00
use strict ;
use warnings ;
2019-02-28 09:32:43 +01:00
use centreon::plugins::templates::catalog_functions qw( catalog_status_threshold ) ;
2014-03-13 16:53:39 +01:00
2021-05-11 16:17:40 +02:00
sub prefix_printer_output {
2019-02-28 09:32:43 +01:00
my ( $ self , % options ) = @ _ ;
2021-05-11 16:17:40 +02:00
return "Printer '" . $ options { instance_value } - > { display } . "' " ;
}
sub printer_long_output {
my ( $ self , % options ) = @ _ ;
return "checking printer '" . $ options { instance_value } - > { display } . "'" ;
2019-02-28 09:32:43 +01:00
}
sub set_counters {
my ( $ self , % options ) = @ _ ;
$ self - > { maps_counters_type } = [
{ name = > 'printer' , type = > 3 , cb_prefix_output = > 'prefix_printer_output' , cb_long_output = > 'printer_long_output' , indent_long_output = > ' ' , message_multiple = > 'All printers are ok' ,
group = > [
2021-05-11 16:17:40 +02:00
{ name = > 'errors' , message_multiple = > 'Printer is ok' , type = > 1 , skipped_code = > { - 10 = > 1 } }
2019-02-28 09:32:43 +01:00
]
}
] ;
$ self - > { maps_counters } - > { errors } = [
{ label = > 'status' , threshold = > 0 , set = > {
key_values = > [ { name = > 'status' } ] ,
output_template = > "status is '%s'" ,
closure_custom_perfdata = > sub { return 0 ; } ,
2021-05-11 16:17:40 +02:00
closure_custom_threshold_check = > \ & catalog_status_threshold
2019-02-28 09:32:43 +01:00
}
2021-05-11 16:17:40 +02:00
}
2019-02-28 09:32:43 +01:00
] ;
}
2014-03-13 16:53:39 +01:00
sub new {
my ( $ class , % options ) = @ _ ;
my $ self = $ class - > SUPER:: new ( package = > __PACKAGE__ , % options ) ;
bless $ self , $ class ;
2021-05-11 16:17:40 +02:00
$ options { options } - > add_options ( arguments = > {
'big-endian' = > { name = > 'big_endian' } ,
2019-08-01 16:35:36 +02:00
'ok-status:s' = > { name = > 'ok_status' , default = > '%{status} =~ /ok/' } ,
'unknown-status:s' = > { name = > 'unknown_status' , default = > '' } ,
'warning-status:s' = > { name = > 'warning_status' , default = > '%{status} =~ /.*/' } ,
2021-05-11 16:17:40 +02:00
'critical-status:s' = > { name = > 'critical_status' , default = > '' }
2019-02-28 09:32:43 +01:00
} ) ;
2014-03-13 16:53:39 +01:00
return $ self ;
}
sub check_options {
my ( $ self , % options ) = @ _ ;
2019-02-28 09:32:43 +01:00
$ self - > SUPER:: check_options ( % options ) ;
$ self - > change_macros ( macros = > [ 'ok_status' , 'unknown_status' , 'warning_status' , 'critical_status' ] ) ;
2014-03-13 16:53:39 +01:00
}
2021-05-11 16:17:40 +02:00
my $ errors_printer = {
normal = > {
0 = > 'low paper' ,
1 = > 'no paper' ,
2 = > 'low toner' ,
3 = > 'no toner' ,
4 = > 'door open' ,
5 = > 'jammed' ,
6 = > 'offline' ,
7 = > 'service requested' ,
8 = > 'input tray missing' ,
9 = > 'output tray missing' ,
10 = > 'maker supply missing' ,
11 = > 'output near full' ,
12 = > 'output full' ,
13 = > 'input tray empty' ,
14 = > 'overdue prevent maint'
} ,
bigendian = > {
7 = > 'low paper' ,
6 = > 'no paper' ,
5 = > 'low toner' ,
4 = > 'no toner' ,
3 = > 'door open' ,
2 = > 'jammed' ,
1 = > 'offline' ,
0 = > 'service requested' ,
14 = > 'input tray missing' ,
13 = > 'output tray missing' ,
12 = > 'maker supply missing' ,
11 = > 'output near full' ,
10 = > 'output full' ,
9 = > 'input tray empty' ,
8 = > 'overdue prevent maint'
}
} ;
2019-02-28 09:32:43 +01:00
sub manage_selection {
2014-03-13 16:53:39 +01:00
my ( $ self , % options ) = @ _ ;
2014-03-14 14:30:52 +01:00
my $ oid_hrPrinterDetectedErrorState = '.1.3.6.1.2.1.25.3.5.1.2' ;
2019-02-28 09:32:43 +01:00
my $ result = $ options { snmp } - > get_table ( oid = > $ oid_hrPrinterDetectedErrorState , nothing_quit = > 1 ) ;
2021-05-11 16:17:40 +02:00
my $ label_errors = 'normal' ;
$ label_errors = 'bigendian' if ( defined ( $ self - > { option_results } - > { big_endian } ) ) ;
2019-02-28 09:32:43 +01:00
$ self - > { printer } = { } ;
2014-03-14 14:30:52 +01:00
foreach ( keys %$ result ) {
2019-02-28 09:32:43 +01:00
/\.(\d+)$/ ;
my $ instance = $ 1 ;
2017-11-22 14:14:08 +01:00
# 16 bits value
my $ value = unpack ( 'S' , $ result - > { $ _ } ) ;
2019-08-01 16:35:36 +02:00
if ( ! defined ( $ value ) ) {
$ value = ord ( $ result - > { $ _ } ) ;
}
2019-02-28 09:32:43 +01:00
$ self - > { printer } - > { $ instance } = { display = > $ instance , errors = > { } } ;
my $ i = 0 ;
2021-05-11 16:17:40 +02:00
foreach my $ key ( keys % { $ errors_printer - > { $ label_errors } } ) {
2019-02-28 09:32:43 +01:00
if ( ( $ value & ( 1 << $ key ) ) ) {
2021-05-11 16:17:40 +02:00
$ self - > { printer } - > { $ instance } - > { errors } - > { $ i } = { status = > $ errors_printer - > { $ label_errors } - > { $ key } } ;
2019-02-28 09:32:43 +01:00
$ i + + ;
2014-03-14 14:30:52 +01:00
}
2014-03-13 16:53:39 +01:00
}
2021-05-11 16:17:40 +02:00
2019-02-28 10:48:20 +01:00
if ( $ i == 0 ) {
$ self - > { printer } - > { $ instance } - > { errors } - > { 0 } = { status = > 'ok' } ;
next ;
}
2014-03-13 16:53:39 +01:00
}
}
1 ;
__END__
= head1 MODE
Check printer errors ( HOST - RESOURCES - MIB ) .
= over 8
2021-05-11 16:17:40 +02:00
= item B <--big-endian>
Use that option if your printer provides big - endian bits ordering .
2019-02-28 09:32:43 +01:00
= item B <--ok-status>
Set warning threshold for status ( Default: '%{status} =~ /ok/' ) .
Can used special variables like: % { status }
= item B <--unknown-status>
2021-05-11 16:17:40 +02:00
Set unknown threshold for status .
2019-02-28 09:32:43 +01:00
Can used special variables like: % { status }
= item B <--warning-status>
Set warning threshold for status ( Default: '%{status} =~ /.*/' ) .
Can used special variables like: % { status }
= item B <--critical-status>
2021-05-11 16:17:40 +02:00
Set critical threshold for status .
2019-02-28 09:32:43 +01:00
Can used special variables like: % { status }
2014-03-13 16:53:39 +01:00
= back
= cut