~ubuntu-branches/ubuntu/trusty/swift/trusty-updates

« back to all changes in this revision

Viewing changes to bin/swift-drive-audit

  • Committer: Package Import Robot
  • Author(s): Chuck Short, James Page, Chuck Short
  • Date: 2013-08-13 10:37:13 UTC
  • mfrom: (1.2.21)
  • Revision ID: package-import@ubuntu.com-20130813103713-1ctbx4zifyljs2aq
Tags: 1.9.1-0ubuntu1
[ James Page ]
* d/control: Update VCS fields for new branch locations.

[ Chuck Short ]
* New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
from swift.common.utils import backward, get_logger
26
26
 
27
27
 
28
 
# To search for more types of errors, add the regex to the list below
29
 
error_re = [
30
 
    re.compile(r'\berror\b.*\b(sd[a-z]{1,2}\d?)\b'),
31
 
    re.compile(r'\b(sd[a-z]{1,2}\d?)\b.*\berror\b'),
32
 
]
33
 
 
34
 
 
35
28
def get_devices(device_dir, logger):
36
29
    devices = []
37
30
    for line in open('/proc/mounts').readlines():
61
54
    return devices
62
55
 
63
56
 
64
 
def get_errors(minutes):
 
57
def get_errors(error_re, log_file_pattern, minutes):
65
58
    # Assuming log rotation is being used, we need to examine
66
59
    # recently rotated files in case the rotation occured
67
60
    # just before the script is being run - the data we are
68
61
    # looking for may have rotated.
69
 
    log_files = [f for f in glob.glob('/var/log/kern.*[!.][!g][!z]')]
 
62
    #
 
63
    # The globbing used before would not work with all out-of-box
 
64
    # distro setup for logrotate and syslog therefore moving this
 
65
    # to the config where one can set it with the desired
 
66
    # globbing pattern.
 
67
    log_files = [f for f in glob.glob(log_file_pattern)]
70
68
    log_files.sort()
71
69
 
72
70
    now_time = datetime.datetime.now()
143
141
    device_dir = conf.get('device_dir', '/srv/node')
144
142
    minutes = int(conf.get('minutes', 60))
145
143
    error_limit = int(conf.get('error_limit', 1))
 
144
    log_file_pattern = conf.get('log_file_pattern',
 
145
                                '/var/log/kern.*[!.][!g][!z]')
 
146
    error_re = []
 
147
    for conf_key in conf:
 
148
        if conf_key.startswith('regex_pattern_'):
 
149
            error_pattern = conf[conf_key]
 
150
            try:
 
151
                r = re.compile(error_pattern)
 
152
            except re.error:
 
153
                sys.exit('Error: unable to compile regex pattern "%s"' %
 
154
                         error_pattern)
 
155
            error_re.append(r)
 
156
    if not error_re:
 
157
        error_re = [
 
158
            re.compile(r'\berror\b.*\b(sd[a-z]{1,2}\d?)\b'),
 
159
            re.compile(r'\b(sd[a-z]{1,2}\d?)\b.*\berror\b'),
 
160
        ]
146
161
    conf['log_name'] = conf.get('log_name', 'drive-audit')
147
162
    logger = get_logger(conf, log_route='drive-audit')
148
163
    devices = get_devices(device_dir, logger)
149
164
    logger.debug("Devices found: %s" % str(devices))
150
165
    if not devices:
151
166
        logger.error("Error: No devices found!")
152
 
    errors = get_errors(minutes)
 
167
    errors = get_errors(error_re, log_file_pattern, minutes)
153
168
    logger.debug("Errors found: %s" % str(errors))
154
169
    unmounts = 0
155
170
    for kernel_device, count in errors.items():