line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FusionInventory::Agent::Task::Inventory::AIX::Networks; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
74781563
|
use strict; |
|
1
|
|
|
|
|
10
|
|
|
1
|
|
|
|
|
74
|
|
4
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
68
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
447
|
use FusionInventory::Agent::Tools; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
141
|
|
7
|
1
|
|
|
1
|
|
539
|
use FusionInventory::Agent::Tools::Unix; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
73
|
|
8
|
1
|
|
|
1
|
|
7
|
use FusionInventory::Agent::Tools::Network; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
622
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub isEnabled { |
11
|
0
|
|
|
0
|
0
|
|
my (%params) = @_; |
12
|
0
|
0
|
|
|
|
|
return 0 if $params{no_category}->{network}; |
13
|
0
|
|
|
|
|
|
return canRun('lscfg'); |
14
|
|
|
|
|
|
|
} |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub doInventory { |
17
|
0
|
|
|
0
|
0
|
|
my (%params) = @_; |
18
|
|
|
|
|
|
|
|
19
|
0
|
|
|
|
|
|
my $inventory = $params{inventory}; |
20
|
0
|
|
|
|
|
|
my $logger = $params{logger}; |
21
|
|
|
|
|
|
|
|
22
|
0
|
|
|
|
|
|
my $routes = getRoutingTable(command => 'netstat -nr', logger => $logger); |
23
|
0
|
|
|
|
|
|
my $default = $routes->{'0.0.0.0'}; |
24
|
|
|
|
|
|
|
|
25
|
0
|
|
|
|
|
|
my @interfaces = _getInterfaces(logger => $logger); |
26
|
0
|
|
|
|
|
|
foreach my $interface (@interfaces) { |
27
|
|
|
|
|
|
|
# if the default gateway address and the interface address belongs to |
28
|
|
|
|
|
|
|
# the same network, that's the gateway for this network |
29
|
0
|
0
|
|
|
|
|
$interface->{IPGATEWAY} = $default if isSameNetwork( |
30
|
|
|
|
|
|
|
$default, $interface->{IPADDRESS}, $interface->{IPMASK} |
31
|
|
|
|
|
|
|
); |
32
|
|
|
|
|
|
|
|
33
|
0
|
|
|
|
|
|
$inventory->addEntry( |
34
|
|
|
|
|
|
|
section => 'NETWORKS', |
35
|
|
|
|
|
|
|
entry => $interface |
36
|
|
|
|
|
|
|
); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
$inventory->setHardware({ |
40
|
0
|
|
|
|
|
|
DEFAULTGATEWAY => $default |
41
|
|
|
|
|
|
|
}); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub _getInterfaces { |
45
|
0
|
|
|
0
|
|
|
my (%params) = @_; |
46
|
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
my $logger = $params{logger}; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# get a list of interfaces from ifconfig |
50
|
0
|
|
|
|
|
|
my @interfaces = |
51
|
0
|
|
|
|
|
|
map { { DESCRIPTION => $_ } } |
52
|
|
|
|
|
|
|
split(/ /, getFirstLine(command => 'ifconfig -l')); |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# complete with hardware addresses, extracted from lscfg |
55
|
0
|
|
|
|
|
|
my %addresses = _parseLscfg( |
56
|
|
|
|
|
|
|
command => 'lscfg -v -l ent*', |
57
|
|
|
|
|
|
|
logger => $logger |
58
|
|
|
|
|
|
|
); |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
foreach my $interface (@interfaces) { |
61
|
0
|
0
|
|
|
|
|
next unless $addresses{$interface->{DESCRIPTION}}; |
62
|
0
|
|
|
|
|
|
$interface->{TYPE} = 'ethernet'; |
63
|
0
|
|
|
|
|
|
$interface->{MACADDR} = $addresses{$interface->{DESCRIPTION}}; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
# complete with network information, extracted from lsattr |
67
|
0
|
|
|
|
|
|
foreach my $interface (@interfaces) { |
68
|
0
|
|
|
|
|
|
my $handle = getFileHandle( |
69
|
|
|
|
|
|
|
command => "lsattr -E -l $interface->{DESCRIPTION}", |
70
|
|
|
|
|
|
|
logger => $logger |
71
|
|
|
|
|
|
|
); |
72
|
0
|
0
|
|
|
|
|
next unless $handle; |
73
|
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
|
while (my $line = <$handle>) { |
75
|
0
|
0
|
|
|
|
|
$interface->{IPADDRESS} = $1 |
76
|
|
|
|
|
|
|
if $line =~ /^netaddr \s+ ($ip_address_pattern)/x; |
77
|
0
|
0
|
|
|
|
|
$interface->{IPMASK} = $1 |
78
|
|
|
|
|
|
|
if $line =~ /^netmask \s+ ($ip_address_pattern)/x; |
79
|
0
|
0
|
|
|
|
|
$interface->{STATUS} = $1 |
80
|
|
|
|
|
|
|
if $line =~ /^state \s+ (\w+)/x; |
81
|
|
|
|
|
|
|
} |
82
|
0
|
|
|
|
|
|
close $handle; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
|
foreach my $interface (@interfaces) { |
86
|
0
|
|
|
|
|
|
$interface->{IPSUBNET} = getSubnetAddress( |
87
|
|
|
|
|
|
|
$interface->{IPADDRESS}, |
88
|
|
|
|
|
|
|
$interface->{IPMASK}, |
89
|
|
|
|
|
|
|
); |
90
|
|
|
|
|
|
|
|
91
|
0
|
0
|
|
|
|
|
$interface->{STATUS} = "Down" unless $interface->{IPADDRESS}; |
92
|
0
|
|
|
|
|
|
$interface->{IPDHCP} = "No"; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
|
return @interfaces; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub _parseLscfg { |
100
|
0
|
|
|
0
|
|
|
my $handle = getFileHandle(@_); |
101
|
0
|
0
|
|
|
|
|
return unless $handle; |
102
|
|
|
|
|
|
|
|
103
|
0
|
|
|
|
|
|
my %addresses; |
104
|
|
|
|
|
|
|
my $current_interface; |
105
|
0
|
|
|
|
|
|
while (my $line = <$handle>) { |
106
|
0
|
0
|
|
|
|
|
if ($line =~ /^\s+ ent(\d+) \s+ \S+ \s+/x) { |
107
|
0
|
|
|
|
|
|
$current_interface = "en$1"; |
108
|
|
|
|
|
|
|
} |
109
|
0
|
0
|
|
|
|
|
if ($line =~ /Network Address\.+($alt_mac_address_pattern)/) { |
110
|
0
|
|
|
|
|
|
$addresses{$current_interface} = alt2canonical($1); |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
} |
113
|
0
|
|
|
|
|
|
close $handle; |
114
|
|
|
|
|
|
|
|
115
|
0
|
|
|
|
|
|
return %addresses; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
1; |