1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
package Ocsinventory::Agent::Backend::OS::Generic::Printers::Cups;
use strict;
sub check {
my $params = shift;
my $common = $params->{common};
# If we are on a MAC, Mac::SysProfile will do the job
return if -r '/usr/sbin/system_profiler';
return unless $common->can_load("Net::CUPS") && $Net::CUPS::VERSION >= 0.60;
return 1;
}
sub run {
my $params = shift;
my $common = $params->{common};
my $cups = Net::CUPS->new();
my @destinations = $cups->getDestinations();
my $printer;
my $description;
my $port;
my $driver;
foreach (@destinations) {
$printer = $_->getName() unless $printer;
$description = $_->getDescription() unless $description;
$port = $_->getUri() unless $port;
$driver = $_->getOptionValue("printer-make-and-model") unless $driver;
# Just grab the default printer, if I use getDestinations, CUPS
# returns all the printer of the local subnet (if it can)
# TODO There is room for improvement here
$common->addPrinter({
NAME => $printer,
DESCRIPTION => $description,
PORT => $port,
DRIVER => $driver
});
$printer = $description = $port = $driver = undef;
}
}
1;
|