Debian Codegraph @

check_printer_health/check_printer_health-1.1.0.2/plugins-scripts/Classes/PRINTERMIB/Component/PrinterSubsystem.pm

raw
1 package Classes::PRINTERMIB::Component::PrinterSubsystem;
2 our @ISA = qw(Monitoring::GLPlugin::SNMP::Item);
3 use strict;
4
5 sub init {
6 my ($self) = @_;
7 if ($self->mode =~ /device::hardware::health/) {
8 $self->get_snmp_tables('PRINTER-MIB', [
9 ['displays', 'prtConsoleDisplayBufferTable', 'Classes::PRINTERMIB::Component::PrinterSubsystem::Display'],
10 ['covers', 'prtCoverTable', 'Classes::PRINTERMIB::Component::PrinterSubsystem::Cover'],
11 ['channels', 'prtChannelTable', 'Classes::PRINTERMIB::Component::PrinterSubsystem::Channel'],
12 ]);
13 } elsif ($self->mode =~ /device::printer::consumables/) {
14 $self->get_snmp_tables('PRINTER-MIB', [
15 ['inputs', 'prtInputTable', 'Classes::PRINTERMIB::Component::PrinterSubsystem::Input'],
16 ['outputs', 'prtOutputTable', 'Classes::PRINTERMIB::Component::PrinterSubsystem::Output'],
17 ['supplies', 'prtMarkerSuppliesTable', 'Classes::PRINTERMIB::Component::PrinterSubsystem::MarkerSupply'],
18 ['markers', 'prtMarkerTable', 'Classes::PRINTERMIB::Component::PrinterSubsystem::Marker'],
19 ['media', 'prtMediaPathTable', 'Classes::PRINTERMIB::Component::PrinterSubsystem::MediaPath'],
20 ]);
21 }
22 }
23
24 sub check {
25 my ($self) = @_;
26 $self->SUPER::check();
27 if ($self->mode =~ /device::hardware::health/) {
28 $self->reduce_messages("hardware working fine");
29 } elsif ($self->mode =~ /device::printer::consumables/) {
30 $self->reduce_messages("supplies status is fine");
31 } else {
32 $self->reduce_messages("wos is?");
33 }
34 }
35
36 package Classes::PRINTERMIB::Component::PrinterSubsystem::Cover;
37 our @ISA = qw(Monitoring::GLPlugin::SNMP::TableItem);
38 use strict;
39
40 sub check {
41 my ($self) = @_;
42 $self->add_info(sprintf '%s is %s',
43 $self->accentfree($self->{prtCoverDescription}),
44 $self->{prtCoverStatus}
45 );
46 if ($self->{prtCoverStatus} =~ /Open/) {
47 $self->add_warning();
48 }
49 }
50
51 package Classes::PRINTERMIB::Component::PrinterSubsystem::Display;
52 our @ISA = qw(Monitoring::GLPlugin::SNMP::TableItem);
53 use strict;
54
55 sub check {
56 my ($self) = @_;
57 if ($self->{prtConsoleDisplayBufferText}) {
58 $self->add_ok($self->accentfree($self->{prtConsoleDisplayBufferText}));
59 }
60 }
61
62 package Classes::PRINTERMIB::Component::PrinterSubsystem::Input;
63 our @ISA = qw(Monitoring::GLPlugin::SNMP::TableItem);
64 use strict;
65
66 package Classes::PRINTERMIB::Component::PrinterSubsystem::Output;
67 our @ISA = qw(Monitoring::GLPlugin::SNMP::TableItem);
68 use strict;
69
70 package Classes::PRINTERMIB::Component::PrinterSubsystem::Marker;
71 our @ISA = qw(Monitoring::GLPlugin::SNMP::TableItem);
72 use strict;
73
74 package Classes::PRINTERMIB::Component::PrinterSubsystem::MarkerSupply;
75 our @ISA = qw(Monitoring::GLPlugin::SNMP::TableItem);
76 use strict;
77
78 sub finish {
79 my ($self) = @_;
80 if ($self->{prtMarkerSuppliesDescription} =~ /^[^ ]{2} [^ ]{2} [^ ]{2}/) {
81 # wird ueblicherweise gehext, wenn da umlautschlonz drin ist
82 $self->{prtMarkerSuppliesDescription} =
83 $self->unhex_octet_string($self->{prtMarkerSuppliesDescription});
84 } elsif (! $self->{prtMarkerSuppliesDescription}) {
85 # Kyocera ECOSYS P2135dn, prtMarkerSuppliesDescription is empty
86 $self->{prtMarkerSuppliesDescription} = $self->{prtMarkerSuppliesType};
87 }
88 $self->{prtMarkerSuppliesDescription} = $self->accentfree($self->{prtMarkerSuppliesDescription});
89 # Found a JetDirect which added nul here and gearman cut off the perfdata
90 $self->{prtMarkerSuppliesDescription} = unpack("Z*", $self->{prtMarkerSuppliesDescription});
91 }
92
93 sub check {
94 my ($self) = @_;
95 if ($self->{prtMarkerSuppliesMaxCapacity} == 0) {
96 # prtMarkerSuppliesClass: supplyThatIsConsumed
97 # prtMarkerSuppliesDescription: Black Toner
98 # prtMarkerSuppliesLevel: 0
99 # prtMarkerSuppliesMarkerIndex: 1
100 # prtMarkerSuppliesMaxCapacity: 0
101 $self->{usage} = $self->{prtMarkerSuppliesClass} eq 'supplyThatIsConsumed' ?
102 100 : 0;
103 } else {
104 $self->{usage} = 100 * $self->{prtMarkerSuppliesLevel} /
105 $self->{prtMarkerSuppliesMaxCapacity};
106 }
107 $self->add_info(sprintf '%s is at %.2f%%',
108 $self->{prtMarkerSuppliesDescription}, $self->{usage}
109 );
110 my $label = $self->accentfree($self->{prtMarkerSuppliesDescription});
111 $label =~ s/\s+/_/g;
112 $label =~ s/://g;
113 if ($self->{prtMarkerSuppliesClass} eq 'supplyThatIsConsumed') {
114 $label .= '_remaining';
115 $self->set_thresholds(
116 metric => $label, warning => '20:', critical => '5:',
117 );
118 } elsif ($self->{prtMarkerSuppliesClass} eq 'receptacleThatIsFilled') {
119 $label .= '_used';
120 $self->set_thresholds(
121 metric => $label, warning => '90', critical => '95',
122 );
123 }
124 if ($self->{prtMarkerSuppliesLevel} == -1) {
125 # indicates that the sub-unit places no restrictions on this parameter
126 $self->add_ok();
127 } elsif ($self->{prtMarkerSuppliesLevel} == -2) {
128 # The value (-2) means unknown
129 $self->add_unknown(sprintf 'status of %s is unknown',
130 $self->{prtMarkerSuppliesDescription});
131 } elsif ($self->{prtMarkerSuppliesLevel} == -3) {
132 # A value of (-3) means that the
133 # printer knows that there is some supply/remaining space
134 $self->add_info(sprintf '%s is sufficiently large',
135 $self->{prtMarkerSuppliesDescription}
136 );
137 $self->add_ok();
138 } else {
139 if ($self->opts->can("morphmessage") && $self->opts->morphmessage) {
140 foreach my $key (keys %{$self->opts->morphmessage}) {
141 next if $key ne "empty_full" && $key ne "leer_voll";
142 my $empty = (split("_", $key))[0];
143 my $full = (split("_", $key))[1];
144 if ($self->{prtMarkerSuppliesDescription} =~
145 $self->opts->morphmessage->{$key}) {
146 $self->get_last_info();
147 if ($self->check_thresholds(
148 metric => $label, value => $self->{usage})) {
149 if ($self->{prtMarkerSuppliesClass} eq 'supplyThatIsConsumed') {
150 $self->add_info(sprintf '%s %s',
151 $self->{prtMarkerSuppliesDescription}, $empty);
152 } else {
153 $self->add_info(sprintf '%s %s',
154 $self->{prtMarkerSuppliesDescription}, $full);
155 }
156 } else {
157 if ($self->{prtMarkerSuppliesClass} eq 'supplyThatIsConsumed') {
158 $self->add_info(sprintf '%s %s',
159 $self->{prtMarkerSuppliesDescription}, $full);
160 } else {
161 $self->add_info(sprintf '%s %s',
162 $self->{prtMarkerSuppliesDescription}, $empty);
163 }
164 }
165 }
166 }
167 }
168 $self->add_message($self->check_thresholds(
169 metric => $label, value => $self->{usage},
170 ));
171 $self->add_perfdata(
172 label => $label, value => $self->{usage}, uom => '%',
173 );
174 }
175 }
176
177 package Classes::PRINTERMIB::Component::PrinterSubsystem::MediaPath;
178 our @ISA = qw(Monitoring::GLPlugin::SNMP::TableItem);
179 use strict;
180
181 package Classes::PRINTERMIB::Component::PrinterSubsystem::Channel;
182 our @ISA = qw(Monitoring::GLPlugin::SNMP::TableItem);
183 use strict;
184
185 __END__
186
187
188 PRINTER-MIB::prtInputStatus
189 PRINTER-MIB::prtOutputStatus
190