-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathsmartctl.py
More file actions
executable file
·35 lines (27 loc) · 965 Bytes
/
smartctl.py
File metadata and controls
executable file
·35 lines (27 loc) · 965 Bytes
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
#!/usr/bin/env python
import subprocess
import sys
"""
NOTE:
The smartctl command needs to be run as root.
Paste this into the bottom of /etc/sudoers:
dataloop ALL=(ALL) NOPASSWD: /sbin/smartctl
"""
status = "OK"
disks = []
try:
cmd = "sudo smartctl --scan-open"
cmd_output = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True, universal_newlines=True)
for line in cmd_output.splitlines():
(dev, _, dtype) = line.split(' ')[0:3]
disks.append((dev, dtype))
for (dev, dtype) in disks:
cmd = "sudo smartctl --device=%s --health %s" % (dtype, dev)
cmd_output = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True, universal_newlines=True)
for line in cmd_output.splitlines():
if "test result" in line and "PASSED" not in line:
status = "CRITICAL"
break
except subprocess.CalledProcessError:
status = "WARNING"
print status