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