/usr/share/fusioninventory/lib/FusionInventory/Agent/Task/Inventory/HPUX/Networks.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 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 | package FusionInventory::Agent::Task::Inventory::HPUX::Networks;
use strict;
use warnings;
use FusionInventory::Agent::Tools;
use FusionInventory::Agent::Tools::Unix;
use FusionInventory::Agent::Tools::Network;
#TODO Get pcislot virtualdev
sub isEnabled {
return canRun('lanscan');
}
sub doInventory {
my (%params) = @_;
my $inventory = $params{inventory};
my $logger = $params{logger};
# set list of network interfaces
my $routes = getRoutingTable(command => 'netstat -nr', logger => $logger);
my @interfaces = _getInterfaces(logger => $logger);
foreach my $interface (@interfaces) {
$interface->{IPGATEWAY} = $params{routes}->{$interface->{IPSUBNET}}
if $interface->{IPSUBNET};
$inventory->addEntry(
section => 'NETWORKS',
entry => $interface
);
}
$inventory->setHardware({
DEFAULTGATEWAY => $routes->{'0.0.0.0'}
});
}
sub _getInterfaces {
my (%params) = @_;
my @prototypes = _parseLanscan(
command => 'lanscan -iap',
logger => $params{logger}
);
my %ifStatNrv = _parseNetstatNrv();
my @interfaces;
foreach my $prototype (@prototypes) {
my $lanadminInfo = _getLanadminInfo(
command => "lanadmin -g $prototype->{lan_id}",
logger => $params{logger}
);
$prototype->{TYPE} = $lanadminInfo->{'Type (value)'};
$prototype->{SPEED} = $lanadminInfo->{Speed} > 1000000 ?
$lanadminInfo->{Speed} / 1000000 : $lanadminInfo->{Speed};
if ($ifStatNrv{$prototype->{DESCRIPTION}}) {
# if this interface name has been found in netstat output, let's
# use the list of interfaces found there, using the prototype
# to provide additional informations
foreach my $interface (@{$ifStatNrv{$prototype->{DESCRIPTION}}}) {
foreach my $key (qw/MACADDR STATUS TYPE SPEED/) {
next unless $prototype->{$key};
$interface->{$key} = $prototype->{$key};
}
push @interfaces, $interface;
}
} else {
# otherwise, we promote this prototype to an interface, using
# ifconfig to provide additional informations
my $ifconfigInfo = _getIfconfigInfo(
command => "ifconfig $prototype->{DESCRIPTION}",
logger => $params{logger}
);
$prototype->{STATUS} = $ifconfigInfo->{status};
$prototype->{IPADDRESS} = $ifconfigInfo->{address};
$prototype->{IPMASK} = $ifconfigInfo->{netmask};
delete $prototype->{lan_id};
push @interfaces, $prototype;
}
}
foreach my $interface (@interfaces) {
if ($interface->{IPADDRESS} && $interface->{IPADDRESS} eq '0.0.0.0') {
$interface->{IPADDRESS} = undef;
$interface->{IPMASK} = undef;
} else {
$interface->{IPSUBNET} = getSubnetAddress(
$interface->{IPADDRESS},
$interface->{IPMASK}
);
}
}
return @interfaces;
}
sub _parseLanscan {
my (%params) = @_;
my $handle = getFileHandle(%params);
return unless $handle;
my @interfaces;
while (my $line = <$handle>) {
next unless $line =~ /^
0x($alt_mac_address_pattern)
\s
(\S+)
\s
\S+
\s+
(\S+)
/x;
# quick assertion: nothing else as ethernet interface
my $interface = {
MACADDR => alt2canonical($1),
STATUS => 'Down',
DESCRIPTION => $2,
TYPE => 'ethernet',
lan_id => $3,
};
push @interfaces, $interface;
}
close $handle;
return @interfaces;
}
sub _getLanadminInfo {
my $handle = getFileHandle(@_);
return unless $handle;
my $info;
while (my $line = <$handle>) {
next unless $line =~ /^(\S.+\S) \s+ = \s (.+)$/x;
$info->{$1} = $2;
}
close $handle;
return $info;
}
sub _getIfconfigInfo {
my $handle = getFileHandle(@_);
return unless $handle;
my $info;
while (my $line = <$handle>) {
if ($line =~ /<UP/) {
$info->{status} = 'Up';
}
if ($line =~ /inet ($ip_address_pattern)/) {
$info->{address} = $1;
}
if ($line =~ /netmask ($hex_ip_address_pattern)/) {
$info->{netmask} = hex2canonical($1);
}
}
close $handle;
return $info;
}
# will be need to get the bonding configuration
sub _getNwmgrInfo {
my $handle = getFileHandle(@_);
return unless $handle;
my $info;
while (my $line = <$handle>) {
next unless $line =~ /^
(\w+)
\s+
(\w+)
\s+
0x($alt_mac_address_pattern)
\s+
(\w+)
\s+
(\w*)
/x;
my $interface = $1;
$info->{$interface} = {
status => $2,
mac => alt2canonical($3),
driver => $4,
media => $5,
related_if => undef
}
}
close $handle;
return $info;
}
sub _parseNetstatNrv {
my (%params) = (
command => 'netstat -nrv',
@_
);
my $handle = getFileHandle(%params);
return unless $handle;
my %interfaces;
while (my $line = <$handle>) {
next unless $line =~ /^
($ip_address_pattern) # address
\/
($ip_address_pattern) # mask
\s+
($ip_address_pattern) # gateway
\s+
[A-Z]* H [A-Z]* # host flag
\s+
\d
\s+
(\w+) (?: :\d+)? # interface name, with optional alias
\s+
(\d+) # MTU
$/x;
my $address = $1;
my $mask = $2;
my $gateway = ($3 ne $1) ? $3 : undef;
my $interface = $4;
my $mtu = $5;
# quick assertion: nothing else as ethernet interface
push @{$interfaces{$interface}}, {
IPADDRESS => $address,
IPMASK => $mask,
IPGATEWAY => $gateway,
DESCRIPTION => $interface,
TYPE => 'ethernet',
MTU => $mtu
}
}
close $handle;
return %interfaces;
}
1;
|