-
Notifications
You must be signed in to change notification settings - Fork 0
/
Check_Ilo_health.py
executable file
·165 lines (146 loc) · 4.73 KB
/
Check_Ilo_health.py
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
#!/usr/bin/python3
import ssl
import urllib.request
import urllib.parse
import argparse
import sys
import json
from HTTPMethod import HTTPMethod
class redfish():
def __init__(self, username, password, ip, ilo_version, debug = False):
"""
Init redfish
"""
self.username = username
self.password = password
self.ip = ip
self.http_method = HTTPMethod(self.ip)
self.debug = debug
self.ilo_version = ilo_version
def auth(self):
"""
function to authenticate to the api
"""
data = {
"UserName" : self.username,
"Password" : self.password
}
header, res = self.http_method.post("/SessionService/Sessions/",data)
if self.debug:
print(res,header)
else:
pass
def logout(self):
header, res = self.http_method.delete("/SessionService/Sessions/")
if self.debug:
print(res,header)
else:
pass
def get_FanSpd(self,FanNumber):
"""
Get Speed of the ILO Fan
"""
header, res = self.http_method.get("/Chassis/1/Thermal/")
try:
#print(res)
Fans = json.loads(str(res))['Fans']
if self.ilo_version < 4:
FanName = Fans[FanNumber]['FanName']
spd_fan = Fans[FanNumber]['CurrentReading']
else
FanName = Fans[FanNumber]['Name']
spd_fan = Fans[FanNumber]['ReadingUnits']
if spd_fan <90 and spd_fan !=0:
state = "OK"
print("{} is at {} % state is {}".format(FanName,spd_fan,state))
self.logout()
sys.exit(0)
elif spd_fan >=85:
state = "WARNING"
print("{} is at {} % state is {}".format(FanName,spd_fan,state))
self.logout()
sys.exit(1)
elif spd_fan == 0 or spd_fan >=90:
state = "CRITICAL"
print("{} is at {} % state is {}".format(FanName,spd_fan,state))
self.logout()
sys.exit(2)
else:
state = "UNKNOWN"
print("{} is at {} % state is {}".format(FanName,spd_fan,state))
self.logout()
sys.exit(3)
self.logout()
except IndexError:
print("There is not such Fan {}".format(FanNumber+1))
def get_Temperature(self,TempNumber):
"""
Get Speed of the ILO Fan
"""
header, res = self.http_method.get("/Chassis/1/Thermal/")
try:
#print(res)
Temp = json.loads(str(res))['Temperatures']
TempName = Temp[TempNumber]['Name']
if self.ile_version < 4:
TempDeg = Temp[TempNumber]['ReadingCelsius']
TempNonCrit = Temp[TempNumber]['UpperThresholdNonCritical']
TempCrit = Temp[TempNumber]['UpperThresholdCritical']
else:
TempDeg = Temp[TempNumber]['CurrentReading']
TempNonCrit = Temp[TempNumber]['LowerThresholdNonCritical']
TempCrit = Temp[TempNumber]['LowerThresholdCritical']
if TempCrit == 0:
TempCrit = 90
else:
pass
if TempDeg < TempNonCrit:
state = "OK"
print("{} is at {}C state is {}".format(TempName,TempDeg,state))
self.logout()
sys.exit(0)
elif TempDeg >= TempCrit:
state = "CRITICAL"
print("{} is at {}C state is {}".format(TempName,TempDeg,state))
self.logout()
sys.exit(2)
elif TempDeg >= TempNonCrit:
state = "WARNING"
print("{} is at {}C state is {}".format(TempName,TempDeg,state))
self.logout()
sys.exit(1)
else:
state = "UNKNOWN"
print("{} is at {}C state is {}".format(TempName,TempDeg,state))
self.logout()
sys.exit(3)
self.logout()
except IndexError:
print("There is not such Thing {}".format(FanNumber+1))
if __name__ == "__main__":
#Create argument
parser = argparse.ArgumentParser(description="Check Ilo Health",epilog="usage: check_ilo_health.py --ilo-version 4 -u root -p password -H 192.168.1.1 -chkFan 0")
parser.add_argument('--username','-u',help="username who can access to ILO")
parser.add_argument('--password','-p',help="password of your ILO Account")
parser.add_argument('--host','-H',help="Ip of your server")
parser.add_argument('--checkFan','-chkFan',help="Check speed of the fan number x")
parser.add_argument('--CheckTemperature','-ChkTemp',help="Check Temperature of hardware")
parser.add_argument('--ilo-version','-iv',help="set the ilo version", type="int")
parser.add_argument('--debug','-D',help="Debug mode",dest="debug",action="store_true")
#Check if argument is specified if not print print help
if len(sys.argv)==1:
parser.print_help()
else:
args = parser.parse_args()
#Init redfish
USERNAME = args.username
PASSWORD = args.password
ILO_VERSION = args.ilo_version
HOST = args.host
DEBUG = args.debug
redfish = redfish(USERNAME, PASSWORD, HOST, DEBUG, ILO_VERSION)
redfish.auth()
if args.checkFan:
redfish.get_FanSpd(int(args.checkFan)-1)
if args.CheckTemperature:
redfish.get_Temperature(int(args.CheckTemperature)-1)