From 84207483cc8a8d00d047ab3c15e2f15cb194884c Mon Sep 17 00:00:00 2001 From: Michael DeHaan Date: Mon, 24 Sep 2007 12:01:38 -0400 Subject: Add basic module for checking smart status of drives. --- modules/smart.py | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100755 modules/smart.py (limited to 'modules/smart.py') diff --git a/modules/smart.py b/modules/smart.py new file mode 100755 index 0000000..fc4c329 --- /dev/null +++ b/modules/smart.py @@ -0,0 +1,58 @@ +#!/usr/bin/python + +## +## Grabs status from SMART to see if your hard drives are ok +## Returns in the format of (return code, [line1, line2, line3,...]) +## +## Copyright 2007, Red Hat, Inc +## Michael DeHaan +## +## This software may be freely redistributed under the terms of the GNU +## general public license. +## +## You should have received a copy of the GNU General Public License +## along with this program; if not, write to the Free Software +## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +## + +# other modules +import subprocess + +# our modules +from codes import * +from modules import func_module + +# ================================= + +class SmartModule(func_module.FuncModule): + def __init__(self): + self.methods = { + "info" : self.info, + } + func_module.FuncModule.__init__(self) + + def info(self,flags="-q onecheck"): + """ + Returns a struct of hardware information. By default, this pulls down + all of the devices. If you don't care about them, set with_devices to + False. + """ + + flags.replace(";","") # prevent stupidity + + cmd = subprocess.Popen("/usr/sbin/smartd %s" % flags,stdout=subprocess.PIPE,shell=True) + data = cmd.communicate()[0] + + results = [] + + for x in data.split("\n"): + tokens = x.split() + results.append(tokens) + + return (cmd.returncode, results) + +methods = SmartModule() +register_rpc = methods.register_rpc + + + -- cgit From 9fa149f6e2a5a0d3233644298a5d50db3f8b6748 Mon Sep 17 00:00:00 2001 From: Michael DeHaan Date: Mon, 24 Sep 2007 14:30:53 -0400 Subject: Basic plugin for checking SMART status on drives. --- modules/smart.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'modules/smart.py') diff --git a/modules/smart.py b/modules/smart.py index fc4c329..410e353 100755 --- a/modules/smart.py +++ b/modules/smart.py @@ -46,8 +46,7 @@ class SmartModule(func_module.FuncModule): results = [] for x in data.split("\n"): - tokens = x.split() - results.append(tokens) + results.append(x) return (cmd.returncode, results) -- cgit From 412671ee48804867fc6707fa12409ae9365f5ea3 Mon Sep 17 00:00:00 2001 From: Michael DeHaan Date: Mon, 24 Sep 2007 14:52:43 -0400 Subject: Package the subprocess module so that we can use it on EL4. --- modules/smart.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'modules/smart.py') diff --git a/modules/smart.py b/modules/smart.py index 410e353..4ed8335 100755 --- a/modules/smart.py +++ b/modules/smart.py @@ -16,7 +16,7 @@ ## # other modules -import subprocess +import sub_process # our modules from codes import * @@ -40,7 +40,7 @@ class SmartModule(func_module.FuncModule): flags.replace(";","") # prevent stupidity - cmd = subprocess.Popen("/usr/sbin/smartd %s" % flags,stdout=subprocess.PIPE,shell=True) + cmd = sub_process.Popen("/usr/sbin/smartd %s" % flags,stdout=sub_process.PIPE,shell=True) data = cmd.communicate()[0] results = [] -- cgit