| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package FusionInventory::Agent::Task::Inventory::Generic::Printers; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
127240995
|
use strict; |
|
|
1
|
|
|
|
|
4
|
|
|
|
1
|
|
|
|
|
71
|
|
|
4
|
1
|
|
|
1
|
|
19
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
93
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
6
|
use English qw(-no_match_vars); |
|
|
1
|
|
|
|
|
100
|
|
|
|
1
|
|
|
|
|
25
|
|
|
7
|
1
|
|
|
1
|
|
984
|
use UNIVERSAL::require; |
|
|
1
|
|
|
|
|
7
|
|
|
|
1
|
|
|
|
|
18
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
700
|
use FusionInventory::Agent::Tools; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
564
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub isEnabled { |
|
12
|
0
|
|
|
0
|
0
|
|
my (%params) = @_; |
|
13
|
|
|
|
|
|
|
|
|
14
|
0
|
0
|
|
|
|
|
return 0 if $params{no_category}->{printer}; |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# we use system profiler on MacOS |
|
17
|
0
|
0
|
|
|
|
|
return 0 if $OSNAME eq 'darwin'; |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# we use WMI on Windows |
|
20
|
0
|
0
|
|
|
|
|
return 0 if $OSNAME eq 'MSWin32'; |
|
21
|
|
|
|
|
|
|
|
|
22
|
0
|
|
|
|
|
|
Net::CUPS->require(); |
|
23
|
0
|
0
|
|
|
|
|
if ($EVAL_ERROR) { |
|
24
|
|
|
|
|
|
|
$params{logger}->debug( |
|
25
|
0
|
|
|
|
|
|
"Net::CUPS Perl module not available, unable to retrieve printers" |
|
26
|
|
|
|
|
|
|
); |
|
27
|
0
|
|
|
|
|
|
return 0; |
|
28
|
|
|
|
|
|
|
} |
|
29
|
|
|
|
|
|
|
|
|
30
|
0
|
0
|
|
|
|
|
if ($Net::CUPS::VERSION < 0.60) { |
|
31
|
|
|
|
|
|
|
$params{logger}->debug( |
|
32
|
0
|
|
|
|
|
|
"Net::CUPS Perl module too old " . |
|
33
|
|
|
|
|
|
|
"(available: $Net::CUPS::VERSION, required: 0.60), ". |
|
34
|
|
|
|
|
|
|
"unable to retrieve printers" |
|
35
|
|
|
|
|
|
|
); |
|
36
|
0
|
|
|
|
|
|
return 0; |
|
37
|
|
|
|
|
|
|
} |
|
38
|
|
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
|
return 1; |
|
40
|
|
|
|
|
|
|
} |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub doInventory { |
|
43
|
0
|
|
|
0
|
0
|
|
my (%params) = @_; |
|
44
|
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
my $inventory = $params{inventory}; |
|
46
|
|
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
my $cups = Net::CUPS->new(); |
|
48
|
0
|
|
|
|
|
|
my @printers = $cups->getDestinations(); |
|
49
|
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
foreach my $printer (@printers) { |
|
51
|
0
|
|
|
|
|
|
my $uri = $printer->getUri(); |
|
52
|
0
|
|
|
|
|
|
my $name = $uri; |
|
53
|
0
|
|
|
|
|
|
$name =~ s/^.*\/\/([^\.]*).*$/$1/eg ; |
|
|
0
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
|
$name =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg; |
|
|
0
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
$inventory->addEntry( |
|
56
|
|
|
|
|
|
|
section => 'PRINTERS', |
|
57
|
|
|
|
|
|
|
entry => { |
|
58
|
|
|
|
|
|
|
NAME => $name, |
|
59
|
|
|
|
|
|
|
PORT => $uri, |
|
60
|
|
|
|
|
|
|
DESCRIPTION => $printer->getDescription(), |
|
61
|
|
|
|
|
|
|
DRIVER => $printer->getOptionValue( |
|
62
|
|
|
|
|
|
|
"printer-make-and-model" |
|
63
|
|
|
|
|
|
|
), |
|
64
|
|
|
|
|
|
|
} |
|
65
|
|
|
|
|
|
|
); |
|
66
|
|
|
|
|
|
|
} |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
} |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
1; |