def clear_old_errors(self): """ Remove do JSON todos os erros que ja passaram do tempo clean_time :return: """ if Utils.file_exists_not_empty(Utils.fullpath('alertlog_errors.json')): error_list = Utils.read_json(Utils.fullpath('alertlog_errors.json')) error_list = [error for error in error_list if not self.error_is_cleared(error['date'])] self.error_list = error_list else: self.error_list = [] self.write_error_json()
def clear_log_position(self): with open(Utils.fullpath('check_alertlog.tmp'), 'w') as f: try: f.write("0") except: print "UNKNOWN - Erro ao escrever check_alertlog.tmp. Verifique as permissoes." exit(3)
def open_gather_json(self): """ Abre o JSON das coletas radicais clean_time :return: """ gather_list = Utils.read_json(Utils.fullpath('dbgrowth_data.json')) self.gather_list = gather_list
def read_partial_file(self): if Utils.file_exists(Utils.fullpath('check_alertlog.tmp')): with open(Utils.fullpath('check_alertlog.tmp'), 'r') as f: try: f.seek(0) file_content = f.readline() self.last_position = int(file_content) except ValueError: print "UNKNOWN - Impossivel ler logfile." exit(3) else: with open(Utils.fullpath('check_alertlog.tmp'), 'a') as f: try: f.write('0') self.last_position = 0 except: print "UNKNOWN - Erro ao escrever check_alertlog.tmp. Verifique as permissoes." exit(3)
def write_gather_json(self): """ Escreve no disco o novo json de erros :return: """ with open(Utils.fullpath('dbgrowth_data.json'), 'w') as f: try: json.dump(self.gather_list, f) except: print "UNKNOWN - Impossivel gravar JSON." exit(3)
def write_error_json(self): """ Escreve no disco o novo json de erros :return: """ with open(Utils.fullpath('alertlog_errors.json'), 'w') as f: try: json.dump(self.error_list, f) except: print "UNKNOWN - Impossivel gravar JSON." exit(3)
def update_log_position(self, lines_read): """ :param lines_read: Numero de linhas lidas """ self.last_position = int(self.last_position) + int(lines_read) with open(Utils.fullpath('check_alertlog.tmp'), 'w') as f: try: f.write(str(self.last_position)) except: print "UNKNOWN - Erro ao escrever check_alertlog.tmp. Verifique as permissoes." exit(3)
def __init__(self, db_name, module): self.read_config(Utils.fullpath("monitoramento.json")) self.config_database(db_name, module)