This file is indexed.

/usr/share/fusioninventory/lib/FusionInventory/Agent/Task/Inventory/Generic/Storages/3ware.pm is in fusioninventory-agent 1:2.3.10.1-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
package FusionInventory::Agent::Task::Inventory::Generic::Storages::3ware;

use strict;
use warnings;

use FusionInventory::Agent::Tools;
use FusionInventory::Agent::Tools::Linux;

use English qw(-no_match_vars);

# Tested on 2.6.* kernels
#
# Cards tested :
#
# 8006-2LP
# 9500S-4LP
# 9550SXU-4LP
# 9550SXU-8LP
# 9650SE-2LP
# 9650SE-4LPML
# 9650SE-8LPML
#
# AMCC/3ware CLI (version 2.00.0X.XXX)

sub isEnabled {
    return canRun('tw_cli');
}

sub doInventory {
    my (%params) = @_;

    my $inventory = $params{inventory};
    my $logger    = $params{logger};

    my @devices;

    foreach my $card (_getCards()) {
        foreach my $unit (_getUnits($card)) {

            # Try do get unit's serial in order to compare it to what was found
            # in udev db.
            # Works only on newer cards.
            # Allow us to associate a node to a drive : sda -> WD-WMANS1648590
            my $sn = getFirstMatch(
                logger => $logger,
                command => "tw_cli info $card->{id} $unit->{id} serial",
                pattern => qr/serial number\s=\s(\w+)/
            );

            foreach my $port (_getPorts($card, $unit)) {
                # Finally, getting drives' values.
                my $storage = _getStorage($card, $port);

                if ($OSNAME eq 'Linux') {

                    @devices = getDevicesFromUdev(logger => $logger) unless @devices;

                    foreach my $device (@devices) {
# How does this work with multiple older cards
# where serial for units is not implemented ?
# Need to be tested on a system with multiple
# 3ware cards.
                        if (
                                $device->{SERIALNUMBER} eq 'AMCC_' . $sn ||
                                $device->{MODEL} eq 'Logical_Disk_' . $unit->{index}
                           ) {
                            $storage->{NAME} = $device->{NAME};
                        }
                    }
                }

                $inventory->addEntry(section => 'STORAGES', entry => $storage);
            }
        }
    }
}


sub _getCards {
    my ($file) = @_;

    my $handle = getFileHandle(
        file => $file,
        command => "tw_cli info"
    );
    return unless $handle;

    my @cards;
    while (my $line = <$handle>) {
        next unless $line =~ /^(c\d+)\s+([\w-]+)/;
        push @cards, { id => $1, model => $2 };
    }
    close $handle;

    return @cards;
}

sub _getUnits {
    my ($card, $file) = @_;

    my $handle = getFileHandle(
        file => $file,
        command => "tw_cli info $card->{id}"
    );
    return unless $handle;

    my @units;
    while (my $line = <$handle>) {
        next unless $line =~ /^(u(\d+))/;
        push @units, { id => $1, index => $2 };
    }
    close $handle;

    return @units;
}

sub _getPorts {
    my ($card, $unit, $file) = @_;

    my $handle = getFileHandle(
        file => $file,
        command => "tw_cli info $card->{id} $unit->{id}"
    );
    return unless $handle;

    my @ports;
    while (my $line = <$handle>) {
        next unless $line =~ /(p\d+)/;
        push @ports, { id => $1 };
    }
    close $handle;

    return @ports;
}

sub _getStorage {
    my ($card, $port, $file) = @_;

    my $handle = getFileHandle(
        file => $file,
        command =>
            "tw_cli info $card->{id} $port->{id} model serial capacity firmware"
    );
    return unless $handle;

    my $storage;
    while (my $line = <$handle>) {
        if ($line =~ /Model\s=\s(.*)/) {
            $storage->{MODEL} = $1;
        } elsif ($line =~ /Serial\s=\s(.*)/) {
            $storage->{SERIALNUMBER} = $1;
        } elsif ($line =~ /Capacity\s=\s(\S+)\sGB.*/) {
            $storage->{DISKSIZE} = 1024 * $1;
        } elsif ($line =~ /Firmware Version\s=\s(.*)/) {
            $storage->{FIRMWARE} = $1
        }
    }
    close $handle;

    $storage->{MANUFACTURER} = getCanonicalManufacturer(
        $storage->{MODEL}
    );
    $storage->{TYPE} = 'disk';

    # Getting description from card model, very basic
    # and unreliable
    # Assuming only IDE drives can be plugged in
    # 5xxx/6xxx cards and
    # SATA drives only to 7xxx/8xxx/9xxxx cards
    $storage->{DESCRIPTION} =
        $card->{model} =~ /^[56]/  ? 'IDE'  :
        $card->{model} =~ /^[789]/ ? 'SATA' :
        undef;

    return $storage;
}

1;