Skip to content

Commit

Permalink
fix: Fix and refacto Canon page counters support
Browse files Browse the repository at this point in the history
Closes #574
  • Loading branch information
g-bougard committed Jan 5, 2024
1 parent 11525a5 commit a9666de
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 27 deletions.
3 changes: 3 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ netdiscovery/netinventory:
which will be reported during netinventory. This will fix duplication issues
while using "(by mac)" import & update rules in GLPI.
* fix #574: Updated page counters support for Ricoh printers
Also updated with refacto in dedicated MibSupport module page counters support
for Canon printers
* Added page counters support for Canon LPB7660 models

1.7.1 Fri, 22 Dec 2023

Expand Down
61 changes: 61 additions & 0 deletions lib/GLPI/Agent/SNMP/MibSupport/Canon.pm
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ use constant canServInfoSerialNumberDeviceNumber => canServInfoSerialNumberTa
use constant ppmPrinter => ppmMIB . '.1.2';
use constant ppmPrinterName => ppmPrinter . '.1.1.2.1';

use constant countersC55XX => canon . '.1.11.1.3.1.4';
use constant countersLPB76XX => canon . '.1.11.2.1.1.3';

our $mibSupport = [
{
name => "canon",
Expand Down Expand Up @@ -54,6 +57,64 @@ sub getModel {
return getCanonicalString($self->get(canPdInfoProductName) || $self->get(ppmPrinterName));
}

sub run {
my ($self) = @_;

my $device = $self->device
or return;

my $counters;
if ($counters = $self->walk(countersC55XX)) {

my %mapping = (
101 => 'COPYTOTAL',
112 => 'COPYBLACK',
113 => 'COPYBLACK',
122 => 'COPYCOLOR',
123 => 'COPYCOLOR',
301 => 'PRINTTOTAL',
501 => 'SCANNED',
);

my %add_mapping = map { $_ => 1 } (112, 113, 122, 123);

foreach my $index (sort keys(%{$counters})) {
my $counter = $mapping{$index}
or next;
my $count = $counters->{$index}
or next;
if ($add_mapping{$index} && $device->{PAGECOUNTERS}->{$counter}) {
$device->{PAGECOUNTERS}->{$counter} += $count;
} else {
$device->{PAGECOUNTERS}->{$counter} = $count;
}
}
} elsif ($counters = $self->walk(countersLPB76XX)) {

my %mapping = (
1 => 'TOTAL',
2 => 'PRINTBLACK',
3 => 'PRINTBLACK',
4 => 'PRINTCOLOR',
5 => 'PRINTCOLOR',
);

my %add_mapping = map { $_ => 1 } (2, 3, 4, 5);

foreach my $index (sort keys(%{$counters})) {
my $counter = $mapping{$index}
or next;
my $count = $counters->{$index}
or next;
if ($add_mapping{$index} && $device->{PAGECOUNTERS}->{$counter}) {
$device->{PAGECOUNTERS}->{$counter} += $count;
} else {
$device->{PAGECOUNTERS}->{$counter} = $count;
}
}
}
}

1;

__END__
Expand Down
33 changes: 6 additions & 27 deletions lib/GLPI/Agent/Tools/Hardware.pm
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ my %printer_pagecounters_variables = (
# value and use it to flag a call out of service techs.
# Hint: Increasing rate = bad paper pickup roller types.
'.1.3.6.1.2.1.43.10.2.1.4.1.1' #Default Value
]
]
},
BLACK => {
oid => '.1.3.6.1.4.1.1347.42.2.2.1.1.3.1.1' #Kyocera specific non-MFP counter
Expand All @@ -212,16 +212,10 @@ my %printer_pagecounters_variables = (
},
RECTOVERSO => { },
SCANNED => {
oid => [
'.1.3.6.1.4.1.1347.46.10.1.1.5.3', #Kyocera MFP specific counter ( total scan counter)
'.1.3.6.1.4.1.1602.1.11.1.3.1.4.501' #Canon specific counter
]
oid => '.1.3.6.1.4.1.1347.46.10.1.1.5.3' #Kyocera MFP specific counter ( total scan counter)
},
PRINTTOTAL => {
oid => [
'.1.3.6.1.4.1.1347.42.3.1.1.1.1.1', #Kyocera MFP specific counter
'.1.3.6.1.4.1.1602.1.11.1.3.1.4.301' #Canon specific counter
]
oid => '.1.3.6.1.4.1.1347.42.3.1.1.1.1.1' #Kyocera MFP specific counter
},
PRINTBLACK => {
oid => '.1.3.6.1.4.1.1347.42.3.1.2.1.1.1.1' #Kyocera MFP specific counter
Expand All @@ -230,28 +224,13 @@ my %printer_pagecounters_variables = (
oid => '.1.3.6.1.4.1.1347.42.3.1.2.1.1.1.3' #Kyocera MFP specific counter
},
COPYTOTAL => {
oid => [
'.1.3.6.1.4.1.1347.42.3.1.1.1.1.2', #Kyocera MFP specific counter
'.1.3.6.1.4.1.1602.1.11.1.3.1.4.101' #Canon specific counter
]
oid => '.1.3.6.1.4.1.1347.42.3.1.1.1.1.2' #Kyocera MFP specific counter
},
COPYBLACK => {
oid => [
'.1.3.6.1.4.1.1347.42.3.1.2.1.1.2.1', #Kyocera MFP specific counter
'.1.3.6.1.4.1.1602.1.11.1.3.1.4.113' #Canon specific counter
]
},
COPYBLACK_A3 => {
oid => '.1.3.6.1.4.1.1602.1.11.1.3.1.4.112' #Canon specific counter
oid => '.1.3.6.1.4.1.1347.42.3.1.2.1.1.2.1' #Kyocera MFP specific counter
},
COPYCOLOR => {
oid => [
'.1.3.6.1.4.1.1347.42.3.1.2.1.1.2.3', #Kyocera MFP specific counter
'.1.3.6.1.4.1.1602.1.11.1.3.1.4.123' #Canon specific counter
]
},
COPYCOLOR_A3 => {
oid => '.1.3.6.1.4.1.1602.1.11.1.3.1.4.122' #Canon specific counter
oid => '.1.3.6.1.4.1.1347.42.3.1.2.1.1.2.3' #Kyocera MFP specific counter
},
FAXTOTAL => {
oid => '.1.3.6.1.4.1.1347.42.3.1.1.1.1.4' #Kyocera MFP specific counter
Expand Down

0 comments on commit a9666de

Please sign in to comment.