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