line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FusionInventory::Agent::Task::Inventory::Solaris::Networks; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
94743251
|
use strict; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
78
|
|
4
|
2
|
|
|
2
|
|
8
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
87
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
#ce5: flags=1000843 mtu 1500 index 3 |
7
|
|
|
|
|
|
|
# inet 55.37.101.171 netmask fffffc00 broadcast 55.37.103.255 |
8
|
|
|
|
|
|
|
# ether 0:3:ba:24:9b:bf |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
#aggr40001:2: flags=201000843 mtu 1500 index 3 |
11
|
|
|
|
|
|
|
# inet 55.37.101.172 netmask ffffff00 broadcast 223.0.146.255 |
12
|
|
|
|
|
|
|
#NDD=/usr/sbin/ndd |
13
|
|
|
|
|
|
|
#KSTAT=/usr/bin/kstat |
14
|
|
|
|
|
|
|
#IFC=/sbin/ifconfig |
15
|
|
|
|
|
|
|
#DLADM=/usr/sbin/dladm |
16
|
|
|
|
|
|
|
|
17
|
2
|
|
|
2
|
|
404
|
use FusionInventory::Agent::Tools; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
246
|
|
18
|
2
|
|
|
2
|
|
799
|
use FusionInventory::Agent::Tools::Solaris; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
99
|
|
19
|
2
|
|
|
2
|
|
747
|
use FusionInventory::Agent::Tools::Network; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
286
|
|
20
|
2
|
|
|
2
|
|
812
|
use FusionInventory::Agent::Tools::Unix; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
2022
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub isEnabled { |
23
|
0
|
|
|
0
|
0
|
0
|
my (%params) = @_; |
24
|
0
|
0
|
|
|
|
0
|
return 0 if $params{no_category}->{network}; |
25
|
0
|
|
|
|
|
0
|
return canRun('ifconfig'); |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub doInventory { |
29
|
0
|
|
|
0
|
0
|
0
|
my (%params) = @_; |
30
|
|
|
|
|
|
|
|
31
|
0
|
|
|
|
|
0
|
my $inventory = $params{inventory}; |
32
|
0
|
|
|
|
|
0
|
my $logger = $params{logger}; |
33
|
|
|
|
|
|
|
|
34
|
0
|
|
|
|
|
0
|
my $routes = getRoutingTable(logger => $logger); |
35
|
0
|
|
|
|
|
0
|
my $default = $routes->{'0.0.0.0'}; |
36
|
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
0
|
my @interfaces = _getInterfaces(logger => $logger); |
38
|
0
|
|
|
|
|
0
|
foreach my $interface (@interfaces) { |
39
|
|
|
|
|
|
|
# if the default gateway address and the interface address belongs to |
40
|
|
|
|
|
|
|
# the same network, that's the gateway for this network |
41
|
|
|
|
|
|
|
$interface->{IPGATEWAY} = $default if isSameNetwork( |
42
|
|
|
|
|
|
|
$default, $interface->{IPADDRESS}, $interface->{IPMASK} |
43
|
0
|
0
|
|
|
|
0
|
); |
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
0
|
$inventory->addEntry( |
46
|
|
|
|
|
|
|
section => 'NETWORKS', |
47
|
|
|
|
|
|
|
entry => $interface |
48
|
|
|
|
|
|
|
); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
$inventory->setHardware({ |
52
|
0
|
|
|
|
|
0
|
DEFAULTGATEWAY => $default |
53
|
|
|
|
|
|
|
}); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub _getInterfaces { |
57
|
0
|
|
|
0
|
|
0
|
my (%params) = @_; |
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
0
|
my @interfaces = _parseIfconfig( |
60
|
|
|
|
|
|
|
command => 'ifconfig -a', |
61
|
|
|
|
|
|
|
@_ |
62
|
|
|
|
|
|
|
); |
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
0
|
foreach my $interface (@interfaces) { |
65
|
|
|
|
|
|
|
$interface->{IPSUBNET} = getSubnetAddress( |
66
|
|
|
|
|
|
|
$interface->{IPADDRESS}, |
67
|
|
|
|
|
|
|
$interface->{IPMASK} |
68
|
0
|
|
|
|
|
0
|
); |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
$interface->{SPEED} = _getInterfaceSpeed( |
71
|
|
|
|
|
|
|
name => $interface->{DESCRIPTION} |
72
|
0
|
|
|
|
|
0
|
); |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
0
|
my $zone = getZone(); |
76
|
0
|
|
|
|
|
0
|
my $OSLevel = getFirstLine(command => 'uname -r'); |
77
|
|
|
|
|
|
|
|
78
|
0
|
0
|
0
|
|
|
0
|
if ($zone && $OSLevel && $OSLevel =~ /5.10/) { |
|
|
|
0
|
|
|
|
|
79
|
|
|
|
|
|
|
push @interfaces, _parseDladm( |
80
|
|
|
|
|
|
|
command => '/usr/sbin/dladm show-aggr', |
81
|
|
|
|
|
|
|
logger => $params{logger} |
82
|
0
|
|
|
|
|
0
|
); |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
push @interfaces, _parsefcinfo( |
85
|
|
|
|
|
|
|
command => '/usr/sbin/fcinfo hba-port', |
86
|
|
|
|
|
|
|
logger => $params{logger} |
87
|
0
|
|
|
|
|
0
|
); |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
0
|
return @interfaces; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub _getInterfaceSpeed { |
94
|
4
|
|
|
4
|
|
1507
|
my (%params) = @_; |
95
|
|
|
|
|
|
|
|
96
|
4
|
|
|
|
|
4
|
my $command; |
97
|
|
|
|
|
|
|
|
98
|
4
|
50
|
|
|
|
11
|
if ($params{name}) { |
99
|
0
|
0
|
|
|
|
0
|
return unless $params{name} =~ /^(\S+)(\d+)/; |
100
|
0
|
|
|
|
|
0
|
my $type = $1; |
101
|
0
|
|
|
|
|
0
|
my $instance = $2; |
102
|
|
|
|
|
|
|
|
103
|
0
|
0
|
|
|
|
0
|
return if $type eq 'aggr'; |
104
|
0
|
0
|
|
|
|
0
|
return if $type eq 'dmfe'; |
105
|
|
|
|
|
|
|
|
106
|
0
|
|
|
|
|
0
|
$command = "/usr/bin/kstat -m $type -i $instance -s link_speed"; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
4
|
|
|
|
|
23
|
my $speed = getFirstMatch( |
110
|
|
|
|
|
|
|
%params, |
111
|
|
|
|
|
|
|
command => $command, |
112
|
|
|
|
|
|
|
pattern => qr/^\s*link_speed+\s*(\d+)/, |
113
|
|
|
|
|
|
|
); |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
# By default, kstat reports speed as Mb/s, no need to normalize |
116
|
4
|
|
|
|
|
18
|
return $speed; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub _parseIfconfig { |
120
|
2
|
|
|
2
|
|
339
|
my $handle = getFileHandle(@_); |
121
|
2
|
50
|
|
|
|
4
|
return unless $handle; |
122
|
|
|
|
|
|
|
|
123
|
2
|
|
|
|
|
3
|
my @interfaces; |
124
|
|
|
|
|
|
|
my $interface; |
125
|
|
|
|
|
|
|
|
126
|
2
|
|
|
|
|
22
|
while (my $line = <$handle>) { |
127
|
32
|
100
|
|
|
|
97
|
if ($line =~ /^(\S+):(\S+):/) { |
|
|
100
|
|
|
|
|
|
128
|
|
|
|
|
|
|
# new interface |
129
|
1
|
50
|
|
|
|
3
|
push @interfaces, $interface if $interface; |
130
|
|
|
|
|
|
|
# quick assertion: nothing else as ethernet interface |
131
|
1
|
|
|
|
|
4
|
$interface = { |
132
|
|
|
|
|
|
|
STATUS => 'Down', |
133
|
|
|
|
|
|
|
DESCRIPTION => $1 . ':' . $2, |
134
|
|
|
|
|
|
|
TYPE => 'ethernet' |
135
|
|
|
|
|
|
|
}; |
136
|
|
|
|
|
|
|
} elsif ($line =~ /^(\S+):/) { |
137
|
|
|
|
|
|
|
# new interface |
138
|
11
|
100
|
|
|
|
15
|
push @interfaces, $interface if $interface; |
139
|
|
|
|
|
|
|
# quick assertion: nothing else as ethernet interface |
140
|
11
|
|
|
|
|
33
|
$interface = { |
141
|
|
|
|
|
|
|
STATUS => 'Down', |
142
|
|
|
|
|
|
|
DESCRIPTION => $1, |
143
|
|
|
|
|
|
|
TYPE => 'ethernet' |
144
|
|
|
|
|
|
|
}; |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
|
147
|
32
|
100
|
|
|
|
118
|
if ($line =~ /inet ($ip_address_pattern)/) { |
148
|
9
|
|
|
|
|
16
|
$interface->{IPADDRESS} = $1; |
149
|
|
|
|
|
|
|
} |
150
|
32
|
100
|
|
|
|
106
|
if ($line =~ /netmask ($hex_ip_address_pattern)/i) { |
151
|
9
|
|
|
|
|
22
|
$interface->{IPMASK} = hex2canonical($1); |
152
|
|
|
|
|
|
|
} |
153
|
32
|
100
|
|
|
|
56
|
if ($line =~ /ether\s+(\S+)/i) { |
154
|
|
|
|
|
|
|
# https://sourceforge.net/tracker/?func=detail&atid=487492&aid=1819948&group_id=58373 |
155
|
|
|
|
|
|
|
$interface->{MACADDR} = |
156
|
8
|
|
|
|
|
48
|
sprintf "%02x:%02x:%02x:%02x:%02x:%02x" , map hex, split /\:/, $1; |
157
|
|
|
|
|
|
|
} |
158
|
32
|
100
|
|
|
|
93
|
if ($line =~ /
|
159
|
12
|
|
|
|
|
37
|
$interface->{STATUS} = "Up"; |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
} |
162
|
2
|
|
|
|
|
13
|
close $handle; |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
# last interface |
165
|
2
|
50
|
|
|
|
6
|
push @interfaces, $interface if $interface; |
166
|
|
|
|
|
|
|
|
167
|
2
|
|
|
|
|
9
|
return @interfaces; |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
sub _parseDladm { |
171
|
0
|
|
|
0
|
|
0
|
my $handle = getFileHandle(@_); |
172
|
0
|
0
|
|
|
|
0
|
return unless $handle; |
173
|
|
|
|
|
|
|
|
174
|
0
|
|
|
|
|
0
|
my @interfaces; |
175
|
0
|
|
|
|
|
0
|
while (my $line = <$handle>) { |
176
|
0
|
0
|
|
|
|
0
|
next if $line =~ /device/; |
177
|
0
|
0
|
|
|
|
0
|
next if $line =~ /key/; |
178
|
0
|
|
|
|
|
0
|
my $interface = { |
179
|
|
|
|
|
|
|
STATUS => 'Down', |
180
|
|
|
|
|
|
|
IPADDRESS => "0.0.0.0", |
181
|
|
|
|
|
|
|
}; |
182
|
|
|
|
|
|
|
next unless |
183
|
0
|
0
|
|
|
|
0
|
$line =~ /(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)/; |
184
|
0
|
|
|
|
|
0
|
$interface->{DESCRIPTION} = $1; |
185
|
0
|
|
|
|
|
0
|
$interface->{MACADDR} = $2; |
186
|
0
|
|
|
|
|
0
|
$interface->{SPEED} = getCanonicalInterfaceSpeed($3 . $4); |
187
|
0
|
0
|
|
|
|
0
|
$interface->{STATUS} = 'Up' if $line =~ /UP/; |
188
|
0
|
|
|
|
|
0
|
push @interfaces, $interface; |
189
|
|
|
|
|
|
|
} |
190
|
0
|
|
|
|
|
0
|
close $handle; |
191
|
|
|
|
|
|
|
|
192
|
0
|
|
|
|
|
0
|
return @interfaces; |
193
|
|
|
|
|
|
|
} |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
sub _parsefcinfo { |
196
|
2
|
|
|
2
|
|
686
|
my $handle = getFileHandle(@_); |
197
|
2
|
50
|
|
|
|
7
|
return unless $handle; |
198
|
|
|
|
|
|
|
|
199
|
2
|
|
|
|
|
3
|
my @interfaces; |
200
|
2
|
|
|
|
|
2
|
my $inc = 1; |
201
|
2
|
|
|
|
|
2
|
my $interface; |
202
|
2
|
|
|
|
|
28
|
while (my $line = <$handle>) { |
203
|
70
|
100
|
|
|
|
105
|
$interface->{DESCRIPTION} = "HBA_Port_WWN_" . $inc |
204
|
|
|
|
|
|
|
if $line =~ /HBA Port WWN:\s+(\S+)/; |
205
|
70
|
100
|
|
|
|
115
|
$interface->{DESCRIPTION} .= " " . $1 |
206
|
|
|
|
|
|
|
if $line =~ /OS Device Name:\s+(\S+)/; |
207
|
70
|
100
|
|
|
|
102
|
$interface->{SPEED} = getCanonicalInterfaceSpeed($1) |
208
|
|
|
|
|
|
|
if $line =~ /Current Speed:\s+(\S+)/; |
209
|
70
|
100
|
|
|
|
106
|
$interface->{WWN} = $1 |
210
|
|
|
|
|
|
|
if $line =~ /Node WWN:\s+(\S+)/; |
211
|
70
|
100
|
|
|
|
110
|
$interface->{DRIVER} = $1 |
212
|
|
|
|
|
|
|
if $line =~ /Driver Name:\s+(\S+)/i; |
213
|
70
|
100
|
|
|
|
96
|
$interface->{MANUFACTURER} = $1 |
214
|
|
|
|
|
|
|
if $line =~ /Manufacturer:\s+(.*)$/; |
215
|
70
|
100
|
|
|
|
123
|
$interface->{MODEL} = $1 |
216
|
|
|
|
|
|
|
if $line =~ /Model:\s+(.*)$/; |
217
|
70
|
100
|
|
|
|
95
|
$interface->{FIRMWARE} = $1 |
218
|
|
|
|
|
|
|
if $line =~ /Firmware Version:\s+(.*)$/; |
219
|
70
|
100
|
|
|
|
98
|
$interface->{STATUS} = 'Up' |
220
|
|
|
|
|
|
|
if $line =~ /online/; |
221
|
|
|
|
|
|
|
|
222
|
70
|
100
|
33
|
|
|
228
|
if ($interface->{DESCRIPTION} && $interface->{WWN}) { |
223
|
5
|
|
|
|
|
6
|
$interface->{TYPE} = 'fibrechannel'; |
224
|
5
|
100
|
|
|
|
10
|
$interface->{STATUS} = 'Down' if !$interface->{STATUS}; |
225
|
|
|
|
|
|
|
|
226
|
5
|
|
|
|
|
4
|
push @interfaces, $interface; |
227
|
5
|
|
|
|
|
6
|
$interface = {}; |
228
|
5
|
|
|
|
|
20
|
$inc++; |
229
|
|
|
|
|
|
|
} |
230
|
|
|
|
|
|
|
} |
231
|
2
|
|
|
|
|
12
|
close $handle; |
232
|
|
|
|
|
|
|
|
233
|
2
|
|
|
|
|
10
|
return @interfaces; |
234
|
|
|
|
|
|
|
} |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
1; |