IPMI 实用小代码,对基于IPMI的刀片服务器的LED进行控制

通过这个小脚本,我们可以用来实现对基于IPMI的刀片服务器的LED进行控制。

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
#!/bin/bash
###########################################################
#
# function getFRULEDProperties
#
###########################################################

function getFRULEDProperties
{
local LEDName=$1

#Get FRU LED Properties command
AvailableLEDs=`ipmitool raw 0x2c 0x05 0x00 0x00 | awk '{print $2}'`

case ${LEDs} in
bule ) $(( 0x$AvailableLEDs & 0x01 ) == 1 ? return "available" : return "unavailable" ;;
oos ) $(( 0x$AvailableLEDs & 0x01 ) == 2 ? return "available" : return "unavailable" ;;
is ) $(( 0x$AvailableLEDs & 0x01 ) == 4 ? return "available" : return "unavailable" ;;
atn ) $(( 0x$AvailableLEDs & 0x01 ) == 8 ? return "available" : return "unavailable" ;;
esac

}

###########################################################
#
# function getLEDColor
#
###########################################################

function getLEDColor
{
local LEDName=$1
local LEDNumber

case $LEDName in
bule ) LEDNumber=0x00 ;;
oos ) LEDNumber=0x01 ;;
is ) LEDNumber=0x02 ;;
atn ) LEDNumber=0x03 ;;

esac

#Get LED Color Capabilities command
LEDColor=`ipmitool raw 0x2c 0x06 0x00 0x00 $LEDNumber | awk '{print $2}'`

#defaule value for supported colors
BULE=""
RED=""
GREEN=""
AMBER=""
ORANGE=""
WHITE=""
supportedColor=($(( 0x$LEDColor & 0x40 )) $(( 0x$LEDColor & 0x20 )) $(( 0x$LEDColor & 0x10 )) $(( 0x$LEDColor & 0x8 )) $(( 0x$LEDColor & 0x4 )) $(( 0x$LEDColor & 0x2 )) )

for colors in ${supportedColor[@]}
do
#printf "%x" $colors
case ${colors} in
2 ) BULE="BULE" ;;
4 ) RED="RED" ;;
8 ) GREEN="GREEN" ;;
16 ) AMBER="AMBER" ;;
32 ) ORANGE="ORANGE" ;;
64 ) WHITE="WHITE" ;;
esac
done

printf "%s supports Color : %s %s %s %s %s %s\n" `echo $LEDName|tr "[:lower:]" "[:upper:]"` $BULE $RED $GREEN $AMBER $ORANGE $WHITE
}

################################
# Main function
################################
getFRULEDProperties bule
getFRULEDProperties oos
getFRULEDProperties is
getFRULEDProperties atn

printf "LED %s" $(getFRULEDProperties bule)

getLEDColor bule
getLEDColor oos
getLEDColor is
getLEDColor atn