Debian Codegraph @

check_printer_health/src/plugins-scripts/Classes/HOSTRESOURCESMIB/Component/PrinterSubsystem.pm

raw
1 package Classes::HOSTRESOURCESMIB::Component::PrinterSubsystem;
2 our @ISA = qw(Monitoring::GLPlugin::SNMP::Item);
3 use strict;
4
5 sub init {
6 my $self = shift;
7 $self->get_snmp_tables('HOST-RESOURCES-MIB', [
8 ['printers', 'hrPrinterTable', 'Classes::HOSTRESOURCESMIB::Component::PrinterSubsystem::Printer'],
9 ['devices', 'hrDeviceTable', 'Classes::HOSTRESOURCESMIB::Component::DeviceSubsystem::Device'],
10 ]);
11 foreach my $printer (@{$self->{printers}}) {
12 foreach my $device (@{$self->{devices}}) {
13 if ($device->{flat_indices} eq $printer->{flat_indices}) {
14 map {
15 $printer->{$_} = $device->{$_};
16 } grep { $_ =~ /^hrDevice/; } keys %{$device};
17 }
18 }
19 }
20 delete $self->{devices};
21 }
22
23 package Classes::HOSTRESOURCESMIB::Component::PrinterSubsystem::Printer;
24 our @ISA = qw(Monitoring::GLPlugin::SNMP::TableItem);
25 use strict;
26
27 sub finish {
28 my $self = shift;
29 my @errors = split('|', $self->{hrPrinterDetectedErrorState});
30 @errors = grep ! /^(no|low)/, @errors;
31 if (! @errors && $self->{hrDeviceStatus} =~ /(warning|down)/) {
32 $self->{hrDeviceStatus} = 'running';
33 }
34 $self->{hrPrinterDetectedErrorState} = join("|", @errors);
35 }
36
37 sub check {
38 my $self = shift;
39 $self->add_info(sprintf '%s has status %s',
40 $self->{hrDeviceDescr},
41 $self->{hrPrinterDetectedErrorState},
42 );
43 if ($self->{hrDeviceStatus} eq 'warning') {
44 $self->add_warning();
45 } elsif ($self->{hrDeviceStatus} eq 'down') {
46 $self->add_critical();
47 } else {
48 $self->add_ok();
49 }
50 }
51