commit 1b2afd771c972c49674889abc283e7e88f5d5b3f Author: Micha vor dem Berge m@mcvdb.de Date: Mon Dec 21 09:52:08 2009 +0000
Added missing files for the new smart module
Signed-off-by: Konstantin Ryabitsev mricon@kernel.org
doc/testcase/smart.testcase | 4 ++ modules/smart_mod.py | 121 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 125 insertions(+), 0 deletions(-) --- diff --git a/doc/testcase/smart.testcase b/doc/testcase/smart.testcase new file mode 100644 index 0000000..152b481 --- /dev/null +++ b/doc/testcase/smart.testcase @@ -0,0 +1,4 @@ +Jul 26 17:48:11 trixi smartd[1502]: Device: /dev/hda, SMART Prefailure Attribute: 1 Raw_Read_Error_Rate changed from 109 to 110 +Jul 26 17:48:11 trixi smartd[1502]: Device: /dev/hda, SMART Usage Attribute: 195 Hardware_ECC_Recovered changed from 54 to 52 +Jul 27 06:46:35 trixi smartd[6412]: Device: /dev/hda, SMART Usage Attribute: 190 Airflow_Temperature_Cel changed from 75 to 76 +Jul 27 06:46:35 trixi smartd[6412]: Device: /dev/hda, SMART Usage Attribute: 194 Temperature_Celsius changed from 25 to 24 diff --git a/modules/smart_mod.py b/modules/smart_mod.py new file mode 100644 index 0000000..bef7196 --- /dev/null +++ b/modules/smart_mod.py @@ -0,0 +1,121 @@ +#!/usr/bin/python -tt +""" +This is an epylog module to monitor the smartd. +Right now, it's only a draft to see how it might look like later on. +""" +## +# Copyright (C) 2009 +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# 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., 59 Temple Place - Suite 330, Boston, MA +# 02111-1307, USA. +# +# $Id: smart_mod.py 272 2004-11-15 14:29:45Z mvdb $ +# +# @Author Micha vor dem Berge m@mcvdb.de +# @version $Date: 2004-11-15 15:29:45 +0100 (Mo, 15. Nov 2004) $ +# + +import sys +import re + +sys.path.insert(0, '../py/') +from epylog import InternalModule + +class smart_mod(InternalModule): + def __init__(self, opts, logger): + InternalModule.__init__(self) + self.logger = logger + + rc = re.compile + + self.prefailure = 2 + self.usage = 1 + + self.regex_map = { + rc('smartd[.*]: Device:.*, SMART Usage Attribute:'): self.usage_attribute, + rc('smartd[.*]: Device:.*, SMART Prefailure Attribute:'): self.prefailure_attribute + } + + self.prefailure_attribute_re = rc('smartd[.*]:\s*Device:\s*(.*),\s*SMART\s*Prefailure\s*Attribute:\s*\d+\s*(\S+)\s*changed\s*from') + self.usage_attribute_re = rc('smartd[.*]:\s*Device:\s*(.*),\s*SMART\s*Usage\s*Attribute:\s*\d+\s*(\S+)\s*changed\s*from') + + self.smart_prefailure_title = '<font color=#FF9900>Prefailure Message</font>' + self.smart_usage_title = '<font color="blue">Usage Message</font>' + self.report_wrap = '<table border="0" width="100%%" rules="cols" cellpadding="2">%s</table>\n' + self.subreport_wrap = '<tr><th colspan="2" align="left"><h3>%s</h3></th></tr>\n' + self.report_line = '<tr><td valign="top">%s</td><td valign="top" width="90%%">%s</td></tr>\n' + + + ## + # Line-matching routines + # + def usage_attribute (self, linemap): + action = self.usage + system, message, mult = self.get_smm(linemap) + mo = self.usage_attribute_re.search(message) + if not mo: + self.logger.put(3, 'Odd usage string: %s' % message) + return None + drive, smart_message = mo.groups() + restuple = (action, system, drive, smart_message) + return {restuple: linemap['multiplier']} + + def prefailure_attribute (self, linemap): + action = self.prefailure + system, message, mult = self.get_smm(linemap) + mo = self.prefailure_attribute_re.search(message) + if not mo: + self.logger.put(3, 'Odd prefailure string: %s' % message) + return None + drive, smart_message = mo.groups() + restuple = (action, system, drive, smart_message) + return {restuple: linemap['multiplier']} + + + ## + # FINALIZE! + # + def finalize(self, resultset): + logger = self.logger + + report = '' + reports = {} + for action in [self.prefailure, self.usage]: + reports[action] = '' + for system in resultset.get_distinct((action,)): + messages = [] + for drive in resultset.get_distinct((action, system)): + mymap = resultset.get_submap((action, system, drive)) + + for message in mymap.keys(): + messages.append('%s (%d)' % (message[0], mymap[message])) + reports[action] += self.report_line % (drive, + '<br>'.join(messages)) + + if reports[self.prefailure]: + report += self.subreport_wrap % self.smart_prefailure_title + report += reports[self.prefailure] + + if reports[self.usage]: + report += self.subreport_wrap % self.smart_usage_title + report += reports[self.usage] + + report = self.report_wrap % report + return report + + +if __name__ == '__main__': + from epylog.helpers import ModuleTest + ModuleTest(smart_mod, sys.argv)