25
25
from swift.common.utils import backward, get_logger
28
# To search for more types of errors, add the regex to the list below
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'),
35
28
def get_devices(device_dir, logger):
37
30
for line in open('/proc/mounts').readlines():
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]')]
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
67
log_files = [f for f in glob.glob(log_file_pattern)]
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]')
147
for conf_key in conf:
148
if conf_key.startswith('regex_pattern_'):
149
error_pattern = conf[conf_key]
151
r = re.compile(error_pattern)
153
sys.exit('Error: unable to compile regex pattern "%s"' %
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'),
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))
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))
155
170
for kernel_device, count in errors.items():