def collect_journal(from_t, to_t, outf): if not which("journalctl"): log_warning("Command journalctl not found") return if crmutils.is_int(from_t) and from_t == 0: from_time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M") elif crmutils.is_int(from_t): from_time = ts_to_dt(from_t).strftime("%Y-%m-%d %H:%M") if crmutils.is_int(to_t) and to_t == 0: to_time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M") elif crmutils.is_int(to_t): to_time = ts_to_dt(to_t).strftime("%Y-%m-%d %H:%M") if os.path.isfile(outf): log_warning("%s already exists" % outf) log_debug("journalctl from: '%d' until: '%d' from_time: '%s' to_time: '%s' > %s" % \ (from_t, to_t, from_time, to_time, outf)) cmd = 'journalctl -o short-iso --since "%s" --until "%s" --no-pager | tail -n +2' % \ (from_time, to_time) crmutils.str2file(get_command_info(cmd)[1], outf)
def find_files(dirs, from_time, to_time): res = [] if (not crmutils.is_int(from_time)) or (from_time <= 0): logger.warning("sorry, can't find files based on time if you don't supply time") return file_with_stamp = create_tempfile(from_time) findexp = "-newer %s" % file_with_stamp if crmutils.is_int(to_time) and to_time > 0: file_with_stamp = create_tempfile(to_time) findexp += " ! -newer %s" % file_with_stamp cmd = r"find %s -type f %s" % (dirs, findexp) cmd_res = get_command_info(cmd)[1].strip() if cmd_res: res = cmd_res.split('\n') os.remove(file_with_stamp) return res
def random_string(num): tmp = [] if crmutils.is_int(num) and num > 0: s = string.ascii_letters + string.digits tmp = random.sample(s, num) return ''.join(tmp)