Adds Error Handling to swift-drive-audit for missing or unreadable /var/log/kern.log
Fixes Bug 1049081 Change-Id: If977080350cc5cdb6bc633b6af7d3c490ed23d46
This commit is contained in:
parent
3482eb26f9
commit
463da7e170
1
AUTHORS
1
AUTHORS
@ -52,6 +52,7 @@ Dragos Manolescu (dragosm@hp.com)
|
|||||||
Juan J. Martinez (juan@memset.com)
|
Juan J. Martinez (juan@memset.com)
|
||||||
Marcelo Martins (btorch@gmail.com)
|
Marcelo Martins (btorch@gmail.com)
|
||||||
Donagh McCabe (donagh.mccabe@hp.com)
|
Donagh McCabe (donagh.mccabe@hp.com)
|
||||||
|
Andy McCrae (andy.mccrae@gmail.com)
|
||||||
Paul McMillan (paul.mcmillan@nebula.com)
|
Paul McMillan (paul.mcmillan@nebula.com)
|
||||||
Ewan Mellor (ewan.mellor@citrix.com)
|
Ewan Mellor (ewan.mellor@citrix.com)
|
||||||
Samuel Merritt (sam@swiftstack.com)
|
Samuel Merritt (sam@swiftstack.com)
|
||||||
|
@ -63,20 +63,25 @@ def get_devices(device_dir, logger):
|
|||||||
def get_errors(minutes):
|
def get_errors(minutes):
|
||||||
errors = {}
|
errors = {}
|
||||||
start_time = datetime.datetime.now() - datetime.timedelta(minutes=minutes)
|
start_time = datetime.datetime.now() - datetime.timedelta(minutes=minutes)
|
||||||
for line in open('/var/log/kern.log'):
|
try:
|
||||||
if '[ 0.000000]' in line:
|
for line in open('/var/log/kern.log'):
|
||||||
# Ignore anything before the last boot
|
if '[ 0.000000]' in line:
|
||||||
errors = {}
|
# Ignore anything before the last boot
|
||||||
continue
|
errors = {}
|
||||||
log_time_string = '%s %s' % (start_time.year,
|
continue
|
||||||
' '.join(line.split()[:3]))
|
log_time_string = '%s %s' % (start_time.year,
|
||||||
log_time = datetime.datetime.strptime(
|
' '.join(line.split()[:3]))
|
||||||
log_time_string, '%Y %b %d %H:%M:%S')
|
log_time = datetime.datetime.strptime(
|
||||||
if log_time > start_time:
|
log_time_string, '%Y %b %d %H:%M:%S')
|
||||||
for err in error_re:
|
if log_time > start_time:
|
||||||
for device in err.findall(line):
|
for err in error_re:
|
||||||
errors[device] = errors.get(device, 0) + 1
|
for device in err.findall(line):
|
||||||
return errors
|
errors[device] = errors.get(device, 0) + 1
|
||||||
|
return errors
|
||||||
|
except IOError:
|
||||||
|
logger.error("Error: Unable to open /var/log/kern.log")
|
||||||
|
print("Unable to open /var/log/kern.log")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
def comment_fstab(mount_point):
|
def comment_fstab(mount_point):
|
||||||
|
Loading…
Reference in New Issue
Block a user