V

2012-12-05
munin plugin for HP USB printers

When I got my printer I wanted to have a possibility to see how much ink was left in the cartridges. After reading the source of the printer driver and googeling I found undocprint.org. A simple perl script for testing showed that these commands also work on my HP CP 1215:

#!/usr/bin/perl -w
#
use strict;
my $out = "";

open DEV, '+<', "/dev/usb/lp0"
  or die "$0: failed to open device: $!\n";

select DEV; $|=1; select STDOUT;

print DEV "\e\%-12345X\@PJL\r\n";
print DEV "\@PJL ",uc join(" ", @ARGV),"\r\n";
print DEV "\e\%-12345X";
sleep 1;

$SIG{'ALRM'} = sub { warn "# sigalrm\n"; print $out; exit; };
alarm 10;

my $char = getc DEV unless eof DEV;
while (defined $char and $char ne "\f") {
    $out .= $char;
    last if eof DEV;
    $char = getc DEV;
}
alarm 0;

close DEV;
$out =~ s/\r\n/\n/msg;
print $out;
# perl ./pjl-cmd.pl info supplies
@PJL INFO SUPPLIES
CARTRIDGE = BLACK
Type = HP
PartNumber = 10752
ReorderPN = CB540A
PercentRemaining = 92
PagesRemaining = 2037
LowReached = 0
SerialNumber = 303369266
PageCount = 163
InstallDate = 0
LastUseDate = 0
Manufacture_Date = 20071122
SuppliesStatus = 1
CartridgeOutOverrideActive = 0
Capacity_Units = 4
Total_Capacity = 2827594000
AvgAreaCvrg = 5
AvgAreaCvrg1 = 90
AvgAreaCvrg2 = 3
AvgAreaCvrg3 = 4
AvgAreaCvrg4 = 2
AvgAreaCvrg5 = 1

CARTRIDGE = CYAN
Type = HP
PartNumber = 10755
ReorderPN = CB541A
PercentRemaining = 25
PagesRemaining = 79
LowReached = 0
SerialNumber = 1091895559
PageCount = 239
InstallDate = 0
LastUseDate = 0
Manufacture_Date = 20080619
SuppliesStatus = 1
CartridgeOutOverrideActive = 0
Capacity_Units = 4
Total_Capacity = 1058999250
AvgAreaCvrg = 16
AvgAreaCvrg1 = 100
AvgAreaCvrg2 = 0
AvgAreaCvrg3 = 0
AvgAreaCvrg4 = 0
AvgAreaCvrg5 = 0

CARTRIDGE = YELLOW
Type = HP
PartNumber = 10753
ReorderPN = CB542A
PercentRemaining = 23
PagesRemaining = 71
LowReached = 0
SerialNumber = 1665728774
PageCount = 240
InstallDate = 0
LastUseDate = 0
Manufacture_Date = 20080619
SuppliesStatus = 1
CartridgeOutOverrideActive = 0
Capacity_Units = 4
Total_Capacity = 943475250
AvgAreaCvrg = 15
AvgAreaCvrg1 = 100
AvgAreaCvrg2 = 0
AvgAreaCvrg3 = 0
AvgAreaCvrg4 = 0
AvgAreaCvrg5 = 0

CARTRIDGE = MAGENTA
Type = HP
PartNumber = 10754
ReorderPN = CB543A
PercentRemaining = 24
PagesRemaining = 75
LowReached = 0
SerialNumber = 1668088071
PageCount = 239
InstallDate = 0
LastUseDate = 0
Manufacture_Date = 20080619
SuppliesStatus = 1
CartridgeOutOverrideActive = 0
Capacity_Units = 4
Total_Capacity = 894006750
AvgAreaCvrg = 14
AvgAreaCvrg1 = 100
AvgAreaCvrg2 = 0
AvgAreaCvrg3 = 0
AvgAreaCvrg4 = 0
AvgAreaCvrg5 = 0

With these infos a plugin for munin was easy: hp_usb_printer_. The resulting graph looks like this:

HP CP 1215 Graph

Permalink | munin, perl.
$HOME
Archives

Tags