Home | History | Annotate | Download | only in platform_CheckErrorsInLog
      1 #!/usr/bin/python
      2 #
      3 # Copyright (c) 2010 The Chromium Authors. All rights reserved.
      4 # Use of this source code is governed by a BSD-style license that can be
      5 # found in the LICENSE file.
      6 
      7 __author__ = 'kdlucas (at] chromium.org (Kelly Lucas)'
      8 
      9 import logging, os
     10 
     11 from autotest_lib.client.bin import test, utils
     12 from autotest_lib.client.common_lib import error
     13 
     14 
     15 class platform_CheckErrorsInLog(test.test):
     16     """
     17     Check system logs for errors.
     18     """
     19     version = 1
     20 
     21     def search_log(self, logfile):
     22         """
     23         Try to ping the remote host and report the status.
     24         Args:
     25             logfile: string, pathname of logfile to search.
     26         Returns:
     27             integer: number of errors found.
     28         """
     29         errors = 0
     30         kerrors = ['fatal', 'oops', 'panic', 'segfault']
     31         f = open(logfile, 'r')
     32         log = f.readlines()
     33         for line in log:
     34             for key in kerrors:
     35                 if key in line:
     36                     errors += 1
     37                     logging.error('%s found in %s' ,line, logfile)
     38         f.close()
     39 
     40         return errors
     41 
     42 
     43     def run_once(self):
     44         errors = 0
     45         logs = ['kern.log', 'syslog', 'dmesg']
     46 
     47         for log in logs:
     48             logfile = os.path.join('/var/log', log)
     49             if os.path.isfile(logfile):
     50                 errors += self.search_log(logfile)
     51             else:
     52                 logging.warning('%s does not exist' % logfile)
     53 
     54         if errors:
     55             raise error.TestFail('%d failures found in logs' % errors)
     56