forked from ya-mouse/redirector
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathredirector-IDRAC
144 lines (132 loc) · 6.09 KB
/
redirector-IDRAC
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
#!/bin/sh
IDRAC_guess()
{
idrac=
$curl https://$hostip/login.html > $1
if fgrep -q 'iDRAC' $1; then
fgrep -q 'Integrated Dell Remote Access Controller 6 - Enterprise' $1 \
&& idrac=6
[ -n "$idrac" ] && return 0 || idrac=7
return 0
fi
return 1
}
IDRAC_session_open()
{
session=
cookie=
tokenstr=
session="$($curl -v -d "user=${opt_user}&password=${opt_passwd}" "https://$hostip/data/login" 2>&1)"
if [ -n "$session" ]; then
cookie=$(echo "$session" | $sed -n -e 's,.*Set-Cookie\:\ \([^\;]\+\)\;.*,\1,gp')
tokenstr=$(echo "$session" |$sed -n -e 's,.*<forwardUrl>index\.html?\([^\ ><]\+\)<\/.*,\1,gp')
ST2="${tokenstr##*,ST2=}"
ST1="${tokenstr%%,ST2=*}"
ST1=${ST1##ST1=}
[ -n "$ST1" -a -n "$ST2" ] || exit 1
get="$curl -H ST2:$ST2"
fi
}
get_data()
{
$get -b "$cookie; tokenvalue=$ST1" "https://$hostip/data?get=pwState,sysDesc,sysRev,hostName,osName,osVersion,svcTag,expSvcCode,biosVer,fwVersion,LCCfwVersion,iDSDMVersion,v4Enabled,v4IPAddr,v6Enabled,v6LinkLocal,v6Addr,v6SiteLocal,macAddr,dnsDomain,devLocInfo,osVersion,intrusion,powerSupplies,RecentEventLogEntries,GetRecentWorknotes,lcdChassisStatus,hostEventStatus,lcdEventStatus"
}
get_racdata()
{
$get -b "$cookie; tokenvalue=$ST1" "https://$hostip/data?get=racName,productInformation,hwVersion,fwVersion,fwUpdated,datetime,ipmiMaxSessions,ipmiSessionCount,netEnabled,ipmiVersion,macAddr,netMode,v4Enabled,v4DHCPEnabled,v4IPAddr,v4Gateway,v4NetMask,v4DHCPServers,v4DNS1,v4DNS2,v6Enabled,v6DHCPEnabled,v6Addr,v6Gateway,v6DHCPServers,v6DNS1,v6DNS2,v6LinkLocal,v6Prefix,v6SiteLocal,v6SiteLocal3,v6SiteLocal4,v6SiteLocal5,v6SiteLocal6,v6SiteLocal7,v6SiteLocal8,v6SiteLocal9,v6SiteLocal10,v6SiteLocal11,v6SiteLocal12,v6SiteLocal13,v6SiteLocal14,v6SiteLocal15,"
}
get_inv()
{
$get -b "$cookie; tokenvalue=$ST1" -G "https://$hostip/sysmgmt/2012/server/inventory/software"
}
parse_inv_xml()
{
local inv="$1"; shift
$sed -n -e "/<Device\ .*display\=\\\"$inv\\\"/,/<\/Device>/p" | parse_xml
}
IDRAC_mc_reset_cold()
{
ipmitool -U $opt_user -P $opt_passwd -I lanplus -H $hostip_nb mc reset cold
}
IDRAC_mc_info()
{
# get_inventory
local inv=$(get_inv)
local data=$(get_data)
local racdata=
local idracts=
local racname=
local fwver=
local biosver=
if [ -n "$inv" ]; then # IDRAC 7/8
fwver=$(echo "$inv"|parse_inv_xml 'Lifecycle\ Controller' |$sed -n -e 's,.*Application_version\=\"\([^;]\+\)";.*,\1,gp')
biosver=$(echo "$inv"|parse_inv_xml 'BIOS' |$sed -n -e 's,.*Application_version\="\([^;]\+\)";.*,\1,gp')
idracts=$(echo "$inv"|parse_inv_xml 'Lifecycle\ Controller' |$sed -n -e 's,.*Device_TimeStamp\="\([^;]\+\)";.*,\1,gp')
else # IDRAC 6?
# LCCfwVersion is obsoleted and no use
fwver=$(echo "$data"|$sed -n -e '/<\LCCfwVersion>/,$d;s,.*fwVersion>\([^<\/]\+\)<.*,\1,p')
biosver=$(echo "$data"|$sed -n -e 's,.*biosVer>\([^<\/]\+\)<.*,\1,gp')
racdata=$(get_racdata)
racname=$(echo "$racdata"|$sed -n -e 's,.*racName>\([^<\/]\+\)<.*,\1,gp')
idracts=$(echo "$racdata"|$sed -n -e 's,.*fwUpdated>\(.*\),\1,gp')
[ -n "$racname" ] && fwver="$racname $fwver"
fi
cat <<EOF
Power State : $(echo "$data"|$sed -n -e 's,1,Power on,g;s,0,Power off,g;s,.*pwState>\([^<\/]\+\)<.*,\1,gp')
System Description : $(echo "$data"|$sed -n -e 's,.*sysDesc>\([^<\/]\+\)<.*,\1,gp')
System Revision : $(echo "$data"|$sed -n -e 's,.*sysRev>\([^<\/]\+\)<.*,\1,gp')
System Tag : $(echo "$data"|$sed -n -e 's,.*svcTag>\([^<\/]\+\)<.*,\1,gp')
System Hostname : $(echo "$data"|$sed -n -e 's,.*hostName>\([^<\/]\+\)<.*,\1,gp')
iDRAC Hostname : $(echo "$data"|$sed -n -e 's,.*hostname>\([^<\/]\+\)<.*,\1,gp')
iDRAC Firmware Revision : $fwver
iDRAC Updated on : $idracts
BIOS Revision : $biosver
EOF
if [ -n "$racdata" ]; then # IDRAC 6
if [ -n "$(echo "$racdata"|$sed -n -e 's,.*netEnabled>\([^<\/]\+\)<.*,\1,gp')" ]; then
cat <<EOF
== Network information ==
iDRAC MAC address : $(echo "$racdata)"|$sed -n -e 's,.*macAddr>\([^<\/]\+\)<.*,\1,gp')
IPV4
- enabled : $(echo "$racdata)"|$sed -n -e 's,.*v4Enabled>\([^<\/]\+\)<.*,\1,gp')
- address : $(echo "$racdata)"|$sed -n -e 's,.*v4IPAddr>\([^<\/]\+\)<.*,\1,gp')
- DHCP enabled : $(echo "$racdata)"|$sed -n -e 's,.*v4DHCPEnabled>\([^<\/]\+\)<.*,\1,gp')
IPV6
- enabled : $(echo "$racdata)"|$sed -n -e 's,.*v6Enabled>\([^<\/]\+\)<.*,\1,gp')
- address : $(echo "$racdata)"|$sed -n -e 's,.*v6Addr>\([^<\/]\+\)<.*,\1,gp')
- DHCP enabled : $(echo "$racdata)"|$sed -n -e 's,.*v6DHCPEnabled>\([^<\/]\+\)<.*,\1,gp')
EOF
fi
else
cat <<EOF
BIOS Timestamp : $(echo "$inv"|parse_inv_xml 'BIOS' |$sed -n -e 's,.*Device_TimeStamp\="\([^;]\+\)";.*,\1,gp')
Chassis Name : $(echo "$data"|$sed -n -e 's,.*devChassis>\([^<\/]\+\)<.*,\1,gp')
Chassis Tag : $(echo "$data"|$sed -n -e 's,.*devChassisServiceTag>\([^<\/]\+\)<.*,\1,gp')
Chassis Model : $(echo "$data"|$sed -n -e 's,.*devChassisModel>\([^<\/]\+\)<.*,\1,gp')
Blade Slot : $(echo "$data"|$sed -n -e 's,.*devBladeSlot>\([^<\/]\+\)<.*,\1,gp')
EOF
fi
}
IDRAC_kvm()
{
local hostname=
local sysdesc=
# FIXME
local slot=
local data=
# we need the following from get_data:
# hostname
# SysDesc
# BladeSlot
data=$(get_data)
[ -n "$data" ] || error 'Unable to get session data!'
hostname="$(echo "$data"|$sed -n -e 's,.*hostname>\([^<\/]\+\)<.*,\1,gp')"
sysdesc="$(echo "$data"|$sed -n -e 's,\ ,+,g;s,.*sysDesc>\([^<\/]\+\)<.*,\1,gp')"
slot="$(echo "$data"|$sed -n -e 's,.*BladeSlot>\([^<\/]\+\)<.*,\1,gp')"
$curl "https://$hostip/viewer.jnlp($hostip@0@$hostname%2C+$sysdesc%2C++Slot+$slot%2C+User%3A+$opt_user@$(LC_ALL=C date +%s)@ST1=$ST1)" \
-e "https://$hostip/sysSummaryData.html" -b "$cookie; tokenvalue=$ST1" > $1
}
IDRAC_session_close()
{
$curl -b "$cookie" -L -o /dev/null -G https://$hostip/data/logout
}