-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinvinfo
executable file
·304 lines (254 loc) · 8.51 KB
/
invinfo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
#!/bin/bash
# invinfo - Get inventory information
# Configuration
PROG=`basename $0`
HOST=`hostname`
CFG=/usr/local/sysadm/etc/invinfo.conf
TMPFILE="/tmp/$PROG.$$"
# VMware ESX trigger
PROCVMMEMCTL=/proc/vmmemctl
DMIDECODE=/usr/sbin/dmidecode
LSPCI=/usr/bin/lspci
if [ -x /sbin/lspci ]; then LSPCI=/sbin/lspci; fi
IP=/sbin/ip
# CPUSPEED (MHz)
# CPUVENDOR
# NUMCPU
GetCPUInfo() {
CPUMODEL=`sed -ne '/model name/s/.*: \(.*\)$/\1/p' /proc/cpuinfo | head -1`
CPUSPEED=`sed -ne '/cpu MHz/s/.*: \(.*\)$/\1/p' /proc/cpuinfo | head -1`
CPUVENDOR=`sed -ne '/vendor_id/s/.*: \(.*\)$/\1/p' /proc/cpuinfo | head -1`
NUMCPU=`sed -ne '/processor/s/.*: \(.*\)$/\1/p' /proc/cpuinfo | wc -l | awk '{ print $1 }' `
echo "cpu_model=$CPUMODEL" >$1.cpu
echo "cpu_speed=$CPUSPEED" >>$1.cpu
echo "cpu_vendor=$CPUVENDOR" >>$1.cpu
echo "cpu_num=$NUMCPU" >>$1.cpu
}
# DISKTOTAL (Gb)
GetDiskInfo() {
DISKTOT=`df | grep '^/dev/' | awk 'BEGIN {$tot = 0 }; { $tot = $tot + $2 };END { print $tot/1024 }'`
}
GetDMIInfo() {
if [ -x $DMIDECODE -a $EUID = 0 ]; then
echo >$1.dmi
DMI=`$DMIDECODE -s 2>&1 | grep '^ '`
for i in $DMI; do
echo dmi_$i=\'`$DMIDECODE -s $i`\' | sed 's/[-]/_/g' >>$1.dmi
done
fi
}
# MEMTOTAL (Mb)
GetMemoryInfo() {
MEMTOTAL=`sed -ne '/MemTotal:/s/.*: *\(.*\) kB$/\1/p' /proc/meminfo`
}
GetNetInfo() {
if [ -x $IP ]; then
$IP addr show | awk '
BEGIN { ifc = ""; ipv4 = ""; mac = ""; state = "DOWN" }
/^[0-9]+:/ {
if (mac != "")
print "net_" ifc "=" ipv4 "," mac "," state ;
split($2,d,":"); ifc = d[1]; flags = $3; ipv4 = ""; state = "DOWN"; mac = "";
}
/link\// { mac = $2 }
/inet / { ipv4 = $2; }
$3 ~ /LOWER_UP/ { state = "UP" }
END {
if (mac != "")
print "net_" ifc "=" ipv4 "," mac "," state "\n";
}
' >$1.net
fi
}
# DEFAULTGW
# PRIMARYIF
# Assume IP of interface wih default route is the primary
GetRouteInfo() {
awk '
function decodeHex(str) {
hexdigs = "123456789abcdef"
code1 = substr(str, 1, 1) # first hex digit
code2 = substr(str, 2, 1) # second hex digit
code1 = tolower(code1)
code2 = tolower(code2)
val = index(hexdigs, code1) * 16 \
+ index(hexdigs, code2)
return val
}
BEGIN { defif = ""; gw = "" }
/Iface/ { }
/./ {
if ($2 == "00000000") {
defif = $1;
a4 = decodeHex(substr($3,1,2));
a3 = decodeHex(substr($3,3,2));
a2 = decodeHex(substr($3,5,2));
a1 = decodeHex(substr($3,7,2));
}
}
END {
printf "net_defaultgw=%d.%d.%d.%d\n", a1, a2, a3, a4;
print "net_primaryif=" defif;
}
' /proc/net/route >$1.route
}
GetOSInfo() {
# Figure out which vedor we are
if [ -r /etc/lsb-release ]; then
. /etc/lsb-release
VENDORNAME=$DISTRIB_ID
RELEASE=$DISTRIB_RELEASE
else
for r in RedHat CentOS Fedora; do
VENDORPKG="`echo $r | tr [:upper:] [:lower:]`-release"
VENDORNAME=$r
RELEASE=`rpm -q --queryformat '%{VERSION}' $VENDORPKG`
if [ $? = 0 ]; then
break
fi
VENDORNAME=""
done
# Get update level
if [ -n "`grep Update /etc/redhat-release`" ]; then
# Get update
UPDATE=`cat /etc/redhat-release | sed s/.*Update\ // | sed s/\)$//`
else
# Assume update 0
UPDATE=0
fi
fi
echo "os_vendor=$VENDORNAME" >$1.os
echo "os_release=$RELEASE" >>$1.os
if [ -n "$UPDATE" ]; then
echo "os_version=$UPDATE" >>$1.os
fi
}
GetPCIInfo() {
# CPUVENDOR=`sed -ne '/vendor_id/s/.*: \(.*\)$/\1/p' /proc/cpuinfo | uniq`
if [ ! -d /proc/bus/pci ]; then
# Xen doesn't pretend to have a PCI bus
return 1
fi
$LSPCI | sed -ne '
/Dell PowerEdge Expandable RAID/s/^.*ller \(.*\) (.*)$/pci_raid_perc=\1/p;t;
/Dell PowerEdge Expandable RAID/s/^.*ller \(.*\)$/pci_raid_perc=\1/p;
/Smart Array/s/^.*Smart Array \(.*\) (.*)/pci_raid_cciss=\1/p;
/Symbios Logic MegaRAID SAS/s/^.*SAS \(.*\) (.*)$/pci_raid_megaraid=sas_\1/p;t;
/Dell Embedded Remote Access or ERA/s/^.*ss or /pci_rcon_era=/p;
/Dell Remote Access Card III/s/^.*$/pci_rcon_drac=3\nrcon=DRAC3/p;
/Dell Embedded Remote Access: BMC/s/^.*Access: \(.*\) device/pci_rcon_bmc=\1/p;
/Integrated Lights Out Controller/s/^.*$/pci_rcon_ilo=1\nrcon=iLO/p;
/Advanced System Management/s/^.*$/pci_rcon_riloe=asm/p;
/NetXtreme BCM/s/^.*NetXtreme \(.*\) Gigabit.*$/pci_net_tg3=\1/p;
/NetXtreme II BCM/s/^.*NetXtreme II \(.*\) Gigabit.*$/pci_net_bnx2=\1/p;
/Advanced Micro Devices .*PCnet32/s/^.*AMD\] \(.*\) \[PC.*$/pci_net_pcnet32=\1/p;
/PRO\/Wireless/s/^.*Wireless \(.*\) Network.*$/pci_net_ipw=\1/p;
/Ethernet Pro/s/^.*tion \(.*\) \[Ether.*$/pci_net_epro=\1/p;
/Ethernet controller: Intel Corporation .* Gigabit/s/^.*ration \(.*\) Gigabit .*$/pci_net_epro=\1/p;
/NetXen Incorporated .* Multi/s/^.*rated \(.*\) Multi.*$/pci_net_netxen=\1/p;
/Ethernet controller: Intel Corporation .* 10-Gigabit/s/^.*ration \(.*\) 10-Gigabit .*$/pci_net_epro=\1/p;
/Symbios Logic/s/^.*Symbios Logic \(.*\) PCI-X.*(.*)$/pci_scsi_lsi=\1/p;t;
/Symbios Logic/s/^.*Symbios Logic \(.*\) (.*)$/pci_scsi_lsi=\1/p;
' >$1.pci
# pci.raid
# 04:08.1 RAID bus controller: Dell PowerEdge Expandable RAID Controller 3/Di (rev 01)
# 02:0e.0 RAID bus controller: Dell PowerEdge Expandable RAID controller 5i
# 01:03.0 RAID bus controller: Compaq Computer Corporation Smart Array 5i/532 (rev 01)
# 02:02.0 RAID bus controller: Compaq Computer Corporation Smart Array 64xx (rev 01)
# 03:00.0 RAID bus controller: LSI Logic / Symbios Logic MegaRAID SAS 1078 (rev 04)
# pci.rcon
# 00:04.0 Class ff00: Dell Embedded Remote Access or ERA/O
# 00:04.1 Class ff00: Dell Remote Access Card III
# 00:04.2 Class ff00: Dell Embedded Remote Access: BMC/SMIC device
# 00:04.0 System peripheral: Compaq Computer Corporation Integrated Lights Out Controller (rev 01)
# 00:04.0 System peripheral: Compaq Computer Corporation Advanced System Management Controller
# pci.net
# 02:01.0 Ethernet controller: Broadcom Corporation NetXtreme BCM5703X Gigabit Ethernet (rev 02)
# 02:01.0 Ethernet controller: Broadcom Corporation NetXtreme BCM5703 Gigabit Ethernet (rev 10)
# 05:00.0 Ethernet controller: Broadcom Corporation NetXtreme II BCM5708 Gigabit Ethernet (rev 12)
# 00:12.0 Ethernet controller: Advanced Micro Devices [AMD] 79c970 [PCnet32 LANCE] (rev 10)
# 04:02.0 Network controller: Intel Corporation PRO/Wireless 2200BG Network Connection (rev 05)
# 00:02.0 Ethernet controller: Intel Corporation 82557/8/9 [Ethernet Pro 100] (rev 08)
# 04:00.0 Ethernet controller: NetXen Incorporated NX3031 Multifunction 1/10 Gigabit Server Adapter (rev 42)
# 05:00.0 Ethernet controller: Intel Corporation 82576 Gigabit Network Connection (rev 01)
# 04:00.0 Ethernet controller: Intel Corporation 82599EB 10-Gigabit Network Connection (rev 01)
# pci.scsi
# 00:01.0 RAID bus controller: LSI Logic / Symbios Logic 53C1510 (rev 02)
# 00:10.0 SCSI storage controller: LSI Logic / Symbios Logic 53c1030 PCI-X Fusion-MPT Dual Ultra320 SCSI (rev 01)
}
# MFG
# SN
# ASSET
GetVMInfo() {
MFG="VMware"
SN="virtual"
ASSET="virtual"
}
GetXenInfo() {
MFG="Xen"
SN="virtual"
ASSET="virtual"
}
# Collect info
if [ -f $CFG ]; then
# source the config file to set some defaults
. $CFG
fi
GetOSInfo $TMPFILE
GetCPUInfo $TMPFILE
GetDiskInfo
GetMemoryInfo
if [ -e $PROCVMMEMCTL ]; then
GetVMInfo
fi
if [ -d /sys/bus/xen/drivers/vif ]; then
# Xen DomU
GetXenInfo
fi
# We have real hardware to discover
GetDMIInfo $TMPFILE
. $TMPFILE.dmi
MFG=${MFG:-$dmi_system_manufacturer}
MFG=${MFG:-$dmi_baseboard_manufacturer}
# Normalize MFG
MFG=`echo $MFG | sed -ne '
/Dell/s/^.*$/Dell/;
/HP/s/^.*$/HP/;
/Hewlett Packard/s/^.*$/HP/;
p;
'`
SN=${SN:-$dmi_system_serial_number}
GetPCIInfo $TMPFILE
. $TMPFILE.pci
# Hack to check for 2950/DRAC5
if [ "$dmi_system_product_name" = "PowerEdge 2950" ]; then
rcon=DRAC5
echo "rcon=$rcon"
fi
echo "hostname=`hostname`"
echo "memtotal=$MEMTOTAL"
echo "disktot=$DISKTOT"
# Show the hard-coded defaults if they have been set
if [ -n "$MFG" ]; then
echo "mfg=\"$MFG\""
fi
if [ -n "$PART" ]; then
echo "part=$PART"
fi
if [ -n "$SN" ]; then
echo "sn=$SN"
fi
if [ -n "$ASSET" ]; then
echo "asset=$ASSET"
fi
if [ -n "$UUID" ]; then
echo "uuid=$UUID"
fi
GetNetInfo $TMPFILE
GetRouteInfo $TMPFILE
# Show cached output
for i in os cpu dmi pci net route; do
[ -r $TMPFILE.$i ] && cat $TMPFILE.$i
done
# Clean up after ourselves
rm $TMPFILE.*