File Coverage

blib/lib/FusionInventory/Agent/Task/Inventory/Generic/Storages/HP.pm
Criterion Covered Total %
statement 54 74 72.9
branch 12 32 37.5
condition 2 9 22.2
subroutine 8 11 72.7
pod 0 2 0.0
total 76 128 59.3


line stmt bran cond sub pod time code
1             package FusionInventory::Agent::Task::Inventory::Generic::Storages::HP;
2              
3 2     2   129459531 use strict;
  2         6  
  2         63  
4 2     2   7 use warnings;
  2         2  
  2         75  
5              
6 2     2   8 use English qw(-no_match_vars);
  2         34  
  2         22  
7 2     2   824 use UNIVERSAL::require;
  2         2  
  2         34  
8              
9 2     2   447 use FusionInventory::Agent::Tools;
  2         1  
  2         1324  
10             # Tested on 2.6.* kernels
11             #
12             # Cards tested :
13             #
14             # Smart Array E200
15             #
16             # HP Array Configuration Utility CLI 7.85-18.0
17              
18             sub _getHpacuacliFromWinRegistry {
19              
20 0     0   0 my $Registry;
21 0         0 Win32::TieRegistry->require();
22 0         0 Win32::TieRegistry->import(
23             Delimiter => '/',
24             ArrayValues => 0,
25             TiedRef => \$Registry,
26             );
27              
28 0 0       0 my $machKey = $Registry->Open('LMachine', {
29             Access => Win32::TieRegistry::KEY_READ(),
30             }) or die "Can't open HKEY_LOCAL_MACHINE key: $EXTENDED_OS_ERROR";
31              
32             my $uninstallValues =
33 0         0 $machKey->{'SOFTWARE/Microsoft/Windows/CurrentVersion/Uninstall/HP ACUCLI'};
34 0 0       0 return unless $uninstallValues;
35              
36 0         0 my $uninstallString = $uninstallValues->{'/UninstallString'};
37 0 0       0 return unless $uninstallString;
38              
39 0 0       0 return unless $uninstallString =~ /(.*\\)hpuninst\.exe/;
40 0         0 my $hpacuacliPath = $1 . 'bin\\hpacucli.exe';
41 0 0       0 return unless -f $hpacuacliPath;
42              
43 0         0 return $hpacuacliPath;
44             }
45              
46             sub isEnabled {
47             return
48 0   0 0 0 0 canRun('hpacucli') ||
49             ($OSNAME eq 'MSWin32' && _getHpacuacliFromWinRegistry());
50             }
51              
52             sub doInventory {
53 0     0 0 0 my (%params) = @_;
54              
55 0         0 my $inventory = $params{inventory};
56 0         0 my $logger = $params{logger};
57              
58 0 0       0 my $path = canRun('hpacucli') ?
59             "hpacucli":
60             _getHpacuacliFromWinRegistry($logger);
61              
62 0         0 foreach my $slot (_getSlots(path => $path)) {
63 0         0 foreach my $drive (_getDrives(path => $path, slot => $slot)) {
64              
65 0         0 $inventory->addEntry(
66             section => 'STORAGES',
67             entry => _getStorage(
68             path => $path, slot => $slot, drive => $drive
69             )
70             );
71             }
72             }
73             }
74              
75             sub _getSlots {
76 2     2   6199 my %params = @_;
77              
78             my $command = $params{path} ?
79 2 50       5 "$params{path} ctrl all show" : undef;
80 2         6 my $handle = getFileHandle(%params, command => $command);
81 2 50       4 return unless $handle;
82              
83 2         3 my @slots;
84 2         21 while (my $line = <$handle>) {
85 3 50       13 next unless $line =~ /Slot (\d+)/;
86 3         13 push @slots, $1;
87             }
88 2         9 close $handle;
89              
90 2         14 return @slots;
91             }
92              
93             sub _getDrives {
94 2     2   1580 my %params = @_;
95              
96             my $command = $params{path} && defined $params{slot} ?
97 2 50 33     9 "$params{path} ctrl slot=$params{slot} pd all show" : undef;
98 2         7 my $handle = getFileHandle(%params, command => $command);
99 2 50       5 next unless $handle;
100              
101 2         3 my @drives;
102 2         17 while (my $line = <$handle>) {
103 8 100       23 next unless $line =~ /physicaldrive (\S+)/;
104 4         15 push @drives, $1;
105             }
106 2         11 close $handle;
107              
108 2         13 return @drives;
109             }
110              
111             sub _getStorage {
112 2     2   1097 my %params = @_;
113              
114             my $command = $params{path} && defined $params{slot} && defined $params{drive} ?
115 2 50 33     12 "$params{path} ctrl slot=$params{slot} pd $params{drive} show" : undef;
116 2         6 my $handle = getFileHandle(%params, command => $command);
117 2 50       5 next unless $handle;
118              
119 2         2 my %data;
120 2         23 while (my $line = <$handle>) {
121 34 100       90 next unless $line =~ /(\S[^:]+) : \s+ (.+)/x;
122 28         76 $data{$1} = $2;
123             }
124 2         11 close $handle;
125              
126             my $storage = {
127             DESCRIPTION => $data{'Interface Type'},
128             SERIALNUMBER => $data{'Serial Number'},
129 2         30 FIRMWARE => $data{'Firmware Revision'}
130             };
131              
132 2         3 my $model = $data{'Model'};
133 2         7 $model =~ s/^ATA\s+//; # ex: ATA WDC WD740ADFD-00
134 2         5 $model =~ s/\s+/ /;
135 2         4 $storage->{NAME} = $model;
136 2         3 $storage->{MODEL} = $model;
137              
138 2         5 $storage->{MANUFACTURER} = getCanonicalManufacturer($model);
139 2         4 $storage->{DISKSIZE} = getCanonicalSize($data{'Size'});
140              
141             $storage->{TYPE} = $data{'Drive Type'} eq 'Data Drive' ?
142 2 50       6 'disk' : $data{'Drive Type'};
143              
144 2         11 return $storage;
145             }
146              
147             1;