Created
January 18, 2013 00:05
-
-
Save cesarkawakami/4561097 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- encoding: utf-8 -*- | |
import re | |
import datetime | |
import subprocess | |
import sys | |
query_date = datetime.datetime.today() - datetime.timedelta(days=3) | |
query_date = query_date.strftime("%d-%b") | |
error_regexes = [ | |
r"FD.*termination.*error", | |
r"SD.*termination.*Waiting", | |
r"SD.*termination.*Error", | |
r"Termination:.*Error", | |
r"Non-fatal.*1", | |
r"Canceled", | |
query_date + r".*Unable to connect", | |
query_date + r".*Open.*Device", | |
query_date + r".*Could not open", | |
] | |
error_regexes = [re.compile(x, re.IGNORECASE) for x in error_regexes] | |
with open("bacula_teste") as log_file: | |
# consume lines until the specified date | |
for line in log_file: | |
if query_date in line: | |
break | |
else: | |
# we didn't find anything | |
subprocess.call(['/root/Scripts/bacula-nao_rodou.sh']) | |
sys.exit(0) | |
# the following now loops through the remaining lines in the file | |
for line in log_file: | |
if any(x.search(line) for x in error_regexes): | |
# found errors | |
subprocess.call(['/root/Scripts/bacula-err_execucao.sh']) | |
break | |
else: | |
# didn't find errors | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment