-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsmartctl_util.py
37 lines (26 loc) · 1.21 KB
/
smartctl_util.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
import logging
logger = logging.getLogger(__name__)
# smartctl のエラーメッセージのリストを返します。
# エラーメッセージがない場合は空のリストを返します。
# @return [{"string": "this is message", "severity": "error"}]
def get_smartctl_messages_from_result(smartctl_result):
if ("smartctl" not in smartctl_result):
return []
if ("messages" not in smartctl_result["smartctl"]):
return []
return smartctl_result["smartctl"]["messages"]
# エラーメッセージにパラメタの単語が含まれたものが一つでもあるか否かを返します。
def _message_contains(smartctl_result, checkString):
msgs = get_smartctl_messages_from_result(smartctl_result)
if msgs == None:
return False
for msg in msgs:
if (checkString in msg["string"]):
return True
return False
def is_usb_device(smartctl_result):
return _message_contains(smartctl_result, "Unknown USB bridge")
def is_megaraid_device(smartctl_result):
return _message_contains(smartctl_result, "DELL or MegaRaid controller")
def is_unknown_device(smartctl_result):
return _message_contains(smartctl_result, "Unable to detect device type")