line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FusionInventory::Agent::Task::Inventory::HPUX::Networks; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
80666974
|
use strict; |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
61
|
|
4
|
2
|
|
|
2
|
|
7
|
use warnings; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
65
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
373
|
use FusionInventory::Agent::Tools; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
240
|
|
7
|
2
|
|
|
2
|
|
751
|
use FusionInventory::Agent::Tools::Unix; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
125
|
|
8
|
2
|
|
|
2
|
|
10
|
use FusionInventory::Agent::Tools::Network; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
1801
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
#TODO Get pcislot virtualdev |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub isEnabled { |
13
|
0
|
|
|
0
|
0
|
0
|
my (%params) = @_; |
14
|
0
|
0
|
|
|
|
0
|
return 0 if $params{no_category}->{network}; |
15
|
0
|
|
|
|
|
0
|
return canRun('lanscan'); |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub doInventory { |
19
|
0
|
|
|
0
|
0
|
0
|
my (%params) = @_; |
20
|
|
|
|
|
|
|
|
21
|
0
|
|
|
|
|
0
|
my $inventory = $params{inventory}; |
22
|
0
|
|
|
|
|
0
|
my $logger = $params{logger}; |
23
|
|
|
|
|
|
|
|
24
|
0
|
|
|
|
|
0
|
my $routes = getRoutingTable(command => 'netstat -nr', logger => $logger); |
25
|
0
|
|
|
|
|
0
|
my $default = $routes->{'0.0.0.0'}; |
26
|
|
|
|
|
|
|
|
27
|
0
|
|
|
|
|
0
|
my @interfaces = _getInterfaces(logger => $logger); |
28
|
0
|
|
|
|
|
0
|
foreach my $interface (@interfaces) { |
29
|
|
|
|
|
|
|
# if the default gateway address and the interface address belongs to |
30
|
|
|
|
|
|
|
# the same network, that's the gateway for this network |
31
|
|
|
|
|
|
|
$interface->{IPGATEWAY} = $default if isSameNetwork( |
32
|
|
|
|
|
|
|
$default, $interface->{IPADDRESS}, $interface->{IPMASK} |
33
|
0
|
0
|
|
|
|
0
|
); |
34
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
0
|
$inventory->addEntry( |
36
|
|
|
|
|
|
|
section => 'NETWORKS', |
37
|
|
|
|
|
|
|
entry => $interface |
38
|
|
|
|
|
|
|
); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
$inventory->setHardware({ |
42
|
0
|
|
|
|
|
0
|
DEFAULTGATEWAY => $default |
43
|
|
|
|
|
|
|
}); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub _getInterfaces { |
47
|
0
|
|
|
0
|
|
0
|
my (%params) = @_; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
my @prototypes = _parseLanscan( |
50
|
|
|
|
|
|
|
command => 'lanscan -iap', |
51
|
|
|
|
|
|
|
logger => $params{logger} |
52
|
0
|
|
|
|
|
0
|
); |
53
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
0
|
my %ifStatNrv = _parseNetstatNrv(); |
55
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
0
|
my @interfaces; |
57
|
0
|
|
|
|
|
0
|
foreach my $prototype (@prototypes) { |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
my $lanadminInfo = _getLanadminInfo( |
60
|
|
|
|
|
|
|
command => "lanadmin -g $prototype->{lan_id}", |
61
|
|
|
|
|
|
|
logger => $params{logger} |
62
|
0
|
|
|
|
|
0
|
); |
63
|
0
|
|
|
|
|
0
|
$prototype->{TYPE} = $lanadminInfo->{'Type (value)'}; |
64
|
|
|
|
|
|
|
$prototype->{SPEED} = $lanadminInfo->{Speed} > 1000000 ? |
65
|
0
|
0
|
|
|
|
0
|
$lanadminInfo->{Speed} / 1000000 : $lanadminInfo->{Speed}; |
66
|
|
|
|
|
|
|
|
67
|
0
|
0
|
|
|
|
0
|
if ($ifStatNrv{$prototype->{DESCRIPTION}}) { |
68
|
|
|
|
|
|
|
# if this interface name has been found in netstat output, let's |
69
|
|
|
|
|
|
|
# use the list of interfaces found there, using the prototype |
70
|
|
|
|
|
|
|
# to provide additional informations |
71
|
0
|
|
|
|
|
0
|
foreach my $interface (@{$ifStatNrv{$prototype->{DESCRIPTION}}}) { |
|
0
|
|
|
|
|
0
|
|
72
|
0
|
|
|
|
|
0
|
foreach my $key (qw/MACADDR STATUS TYPE SPEED/) { |
73
|
0
|
0
|
|
|
|
0
|
next unless $prototype->{$key}; |
74
|
0
|
|
|
|
|
0
|
$interface->{$key} = $prototype->{$key}; |
75
|
|
|
|
|
|
|
} |
76
|
0
|
|
|
|
|
0
|
push @interfaces, $interface; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
} else { |
79
|
|
|
|
|
|
|
# otherwise, we promote this prototype to an interface, using |
80
|
|
|
|
|
|
|
# ifconfig to provide additional informations |
81
|
|
|
|
|
|
|
my $ifconfigInfo = _getIfconfigInfo( |
82
|
|
|
|
|
|
|
command => "ifconfig $prototype->{DESCRIPTION}", |
83
|
|
|
|
|
|
|
logger => $params{logger} |
84
|
0
|
|
|
|
|
0
|
); |
85
|
0
|
|
|
|
|
0
|
$prototype->{STATUS} = $ifconfigInfo->{status}; |
86
|
0
|
|
|
|
|
0
|
$prototype->{IPADDRESS} = $ifconfigInfo->{address}; |
87
|
0
|
|
|
|
|
0
|
$prototype->{IPMASK} = $ifconfigInfo->{netmask}; |
88
|
0
|
|
|
|
|
0
|
delete $prototype->{lan_id}; |
89
|
0
|
|
|
|
|
0
|
push @interfaces, $prototype; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
0
|
|
|
|
|
0
|
foreach my $interface (@interfaces) { |
94
|
0
|
0
|
0
|
|
|
0
|
if ($interface->{IPADDRESS} && $interface->{IPADDRESS} eq '0.0.0.0') { |
95
|
0
|
|
|
|
|
0
|
$interface->{IPADDRESS} = undef; |
96
|
0
|
|
|
|
|
0
|
$interface->{IPMASK} = undef; |
97
|
|
|
|
|
|
|
} else { |
98
|
|
|
|
|
|
|
$interface->{IPSUBNET} = getSubnetAddress( |
99
|
|
|
|
|
|
|
$interface->{IPADDRESS}, |
100
|
|
|
|
|
|
|
$interface->{IPMASK} |
101
|
0
|
|
|
|
|
0
|
); |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
0
|
|
|
|
|
0
|
return @interfaces; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub _parseLanscan { |
109
|
3
|
|
|
3
|
|
3448
|
my (%params) = @_; |
110
|
|
|
|
|
|
|
|
111
|
3
|
|
|
|
|
11
|
my $handle = getFileHandle(%params); |
112
|
3
|
50
|
|
|
|
9
|
return unless $handle; |
113
|
|
|
|
|
|
|
|
114
|
3
|
|
|
|
|
3
|
my @interfaces; |
115
|
3
|
|
|
|
|
37
|
while (my $line = <$handle>) { |
116
|
51
|
50
|
|
|
|
232
|
next unless $line =~ /^ |
117
|
|
|
|
|
|
|
0x($alt_mac_address_pattern) |
118
|
|
|
|
|
|
|
\s |
119
|
|
|
|
|
|
|
(\S+) |
120
|
|
|
|
|
|
|
\s |
121
|
|
|
|
|
|
|
\S+ |
122
|
|
|
|
|
|
|
\s+ |
123
|
|
|
|
|
|
|
(\S+) |
124
|
|
|
|
|
|
|
/x; |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
# quick assertion: nothing else as ethernet interface |
127
|
51
|
|
|
|
|
85
|
my $interface = { |
128
|
|
|
|
|
|
|
MACADDR => alt2canonical($1), |
129
|
|
|
|
|
|
|
STATUS => 'Down', |
130
|
|
|
|
|
|
|
DESCRIPTION => $2, |
131
|
|
|
|
|
|
|
TYPE => 'ethernet', |
132
|
|
|
|
|
|
|
lan_id => $3, |
133
|
|
|
|
|
|
|
}; |
134
|
|
|
|
|
|
|
|
135
|
51
|
|
|
|
|
130
|
push @interfaces, $interface; |
136
|
|
|
|
|
|
|
} |
137
|
3
|
|
|
|
|
18
|
close $handle; |
138
|
|
|
|
|
|
|
|
139
|
3
|
|
|
|
|
17
|
return @interfaces; |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
sub _getLanadminInfo { |
143
|
4
|
|
|
4
|
|
10364
|
my $handle = getFileHandle(@_); |
144
|
4
|
50
|
|
|
|
7
|
return unless $handle; |
145
|
|
|
|
|
|
|
|
146
|
4
|
|
|
|
|
4
|
my $info; |
147
|
4
|
|
|
|
|
46
|
while (my $line = <$handle>) { |
148
|
164
|
100
|
|
|
|
412
|
next unless $line =~ /^(\S.+\S) \s+ = \s (.+)$/x; |
149
|
136
|
|
|
|
|
345
|
$info->{$1} = $2; |
150
|
|
|
|
|
|
|
} |
151
|
4
|
|
|
|
|
21
|
close $handle; |
152
|
|
|
|
|
|
|
|
153
|
4
|
|
|
|
|
13
|
return $info; |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
sub _getIfconfigInfo { |
157
|
2
|
|
|
2
|
|
1995
|
my $handle = getFileHandle(@_); |
158
|
2
|
50
|
|
|
|
6
|
return unless $handle; |
159
|
|
|
|
|
|
|
|
160
|
2
|
|
|
|
|
1
|
my $info; |
161
|
2
|
|
|
|
|
19
|
while (my $line = <$handle>) { |
162
|
4
|
100
|
|
|
|
10
|
if ($line =~ /
|
163
|
2
|
|
|
|
|
4
|
$info->{status} = 'Up'; |
164
|
|
|
|
|
|
|
} |
165
|
4
|
100
|
|
|
|
37
|
if ($line =~ /inet ($ip_address_pattern)/) { |
166
|
2
|
|
|
|
|
5
|
$info->{address} = $1; |
167
|
|
|
|
|
|
|
} |
168
|
4
|
100
|
|
|
|
38
|
if ($line =~ /netmask ($hex_ip_address_pattern)/) { |
169
|
2
|
|
|
|
|
7
|
$info->{netmask} = hex2canonical($1); |
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
} |
172
|
2
|
|
|
|
|
12
|
close $handle; |
173
|
|
|
|
|
|
|
|
174
|
2
|
|
|
|
|
5
|
return $info; |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
# will be need to get the bonding configuration |
178
|
|
|
|
|
|
|
sub _getNwmgrInfo { |
179
|
2
|
|
|
2
|
|
13533
|
my $handle = getFileHandle(@_); |
180
|
2
|
50
|
|
|
|
6
|
return unless $handle; |
181
|
|
|
|
|
|
|
|
182
|
2
|
|
|
|
|
3
|
my $info; |
183
|
2
|
|
|
|
|
42
|
while (my $line = <$handle>) { |
184
|
54
|
100
|
|
|
|
262
|
next unless $line =~ /^ |
185
|
|
|
|
|
|
|
(\w+) |
186
|
|
|
|
|
|
|
\s+ |
187
|
|
|
|
|
|
|
(\w+) |
188
|
|
|
|
|
|
|
\s+ |
189
|
|
|
|
|
|
|
0x($alt_mac_address_pattern) |
190
|
|
|
|
|
|
|
\s+ |
191
|
|
|
|
|
|
|
(\w+) |
192
|
|
|
|
|
|
|
\s+ |
193
|
|
|
|
|
|
|
(\w*) |
194
|
|
|
|
|
|
|
/x; |
195
|
46
|
|
|
|
|
46
|
my $interface = $1; |
196
|
|
|
|
|
|
|
|
197
|
46
|
|
|
|
|
68
|
$info->{$interface} = { |
198
|
|
|
|
|
|
|
status => $2, |
199
|
|
|
|
|
|
|
mac => alt2canonical($3), |
200
|
|
|
|
|
|
|
driver => $4, |
201
|
|
|
|
|
|
|
media => $5, |
202
|
|
|
|
|
|
|
related_if => undef |
203
|
|
|
|
|
|
|
} |
204
|
|
|
|
|
|
|
} |
205
|
2
|
|
|
|
|
12
|
close $handle; |
206
|
|
|
|
|
|
|
|
207
|
2
|
|
|
|
|
7
|
return $info; |
208
|
|
|
|
|
|
|
} |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
sub _parseNetstatNrv { |
211
|
4
|
|
|
4
|
|
25135
|
my (%params) = ( |
212
|
|
|
|
|
|
|
command => 'netstat -nrv', |
213
|
|
|
|
|
|
|
@_ |
214
|
|
|
|
|
|
|
); |
215
|
|
|
|
|
|
|
|
216
|
4
|
|
|
|
|
13
|
my $handle = getFileHandle(%params); |
217
|
4
|
50
|
|
|
|
11
|
return unless $handle; |
218
|
|
|
|
|
|
|
|
219
|
4
|
|
|
|
|
5
|
my %interfaces; |
220
|
4
|
|
|
|
|
66
|
while (my $line = <$handle>) { |
221
|
34
|
100
|
|
|
|
276
|
next unless $line =~ /^ |
222
|
|
|
|
|
|
|
($ip_address_pattern) # address |
223
|
|
|
|
|
|
|
\/ |
224
|
|
|
|
|
|
|
($ip_address_pattern) # mask |
225
|
|
|
|
|
|
|
\s+ |
226
|
|
|
|
|
|
|
($ip_address_pattern) # gateway |
227
|
|
|
|
|
|
|
\s+ |
228
|
|
|
|
|
|
|
[A-Z]* H [A-Z]* # host flag |
229
|
|
|
|
|
|
|
\s+ |
230
|
|
|
|
|
|
|
\d |
231
|
|
|
|
|
|
|
\s+ |
232
|
|
|
|
|
|
|
(\w+) (?: :\d+)? # interface name, with optional alias |
233
|
|
|
|
|
|
|
\s+ |
234
|
|
|
|
|
|
|
(\d+) # MTU |
235
|
|
|
|
|
|
|
$/x; |
236
|
|
|
|
|
|
|
|
237
|
11
|
|
|
|
|
17
|
my $address = $1; |
238
|
11
|
|
|
|
|
12
|
my $mask = $2; |
239
|
11
|
50
|
|
|
|
20
|
my $gateway = ($3 ne $1) ? $3 : undef; |
240
|
11
|
|
|
|
|
10
|
my $interface = $4; |
241
|
11
|
|
|
|
|
9
|
my $mtu = $5; |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
# quick assertion: nothing else as ethernet interface |
244
|
11
|
|
|
|
|
9
|
push @{$interfaces{$interface}}, { |
|
11
|
|
|
|
|
60
|
|
245
|
|
|
|
|
|
|
IPADDRESS => $address, |
246
|
|
|
|
|
|
|
IPMASK => $mask, |
247
|
|
|
|
|
|
|
IPGATEWAY => $gateway, |
248
|
|
|
|
|
|
|
DESCRIPTION => $interface, |
249
|
|
|
|
|
|
|
TYPE => 'ethernet', |
250
|
|
|
|
|
|
|
MTU => $mtu |
251
|
|
|
|
|
|
|
} |
252
|
|
|
|
|
|
|
} |
253
|
4
|
|
|
|
|
21
|
close $handle; |
254
|
|
|
|
|
|
|
|
255
|
4
|
|
|
|
|
22
|
return %interfaces; |
256
|
|
|
|
|
|
|
} |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
1; |