コード例 #1
0
ファイル: utillib.py プロジェクト: renzhengeek/crmsh
def get_ts(line):
    ts = None
    with stdchannel_redirected(sys.stderr, os.devnull):
        if not constants.GET_STAMP_FUNC:
            func = find_getstampproc_raw(line)
        else:
            func = constants.GET_STAMP_FUNC
        if func:
            if func == "rfc5424":
                ts = crmutils.parse_to_timestamp(line.split()[0])
            if func == "syslog":
                ts = crmutils.parse_to_timestamp(' '.join(line.split()[0:3]))
            if func == "legacy":
                ts = crmutils.parse_to_timestamp(line.split()[1])
    return ts
コード例 #2
0
ファイル: test_time.py プロジェクト: yuusuke/crmsh
def test_time_convert2():
    loctz = dateutil.tz.tzlocal()
    tm = time.localtime(
        utils.datetime_to_timestamp(
            utils.make_datetime_naive(datetime.datetime(2015, 6, 1, 10, 0, 0).replace(tzinfo=loctz))
        )
    )
    ts = time.localtime(utils.parse_to_timestamp("Jun 01, 2015 10:00:00"))
    eq_(time.strftime("%Y-%m-%d %H:%M:%S", ts), time.strftime("%Y-%m-%d %H:%M:%S", tm))
コード例 #3
0
ファイル: test_time.py プロジェクト: zmyer/crmsh
def test_time_convert2():
    loctz = dateutil.tz.tzlocal()
    tm = time.localtime(
        utils.datetime_to_timestamp(
            utils.make_datetime_naive(
                datetime.datetime(2015, 6, 1, 10, 0,
                                  0).replace(tzinfo=loctz))))
    ts = time.localtime(utils.parse_to_timestamp('Jun 01, 2015 10:00:00'))
    eq_(time.strftime('%Y-%m-%d %H:%M:%S', ts),
        time.strftime('%Y-%m-%d %H:%M:%S', tm))
コード例 #4
0
ファイル: utillib.py プロジェクト: wenshizhang/hb_report
def setvarsanddefaults():
    '''
	do some environment variable initial 
	'''
    now = datetime.datetime.now()
    now_string = now.strftime("%Y-%m-%d %H:%M:%S.%f")
    now_t = utils.parse_to_timestamp(now_string)
    envir.UNIQUE_MSG = "Mark:HB_REPORT:" + str(int(now_t))
    NOW = now

    envir.TO_TIME = utils.parse_to_timestamp(now_string)
    date = datetime.datetime.date(now).strftime("%a-%d-%m-%Y")
    envir.DEST = "hb_report-" + date
    envir.SANITIZE.append("passw.*")
    envir.SSH_OPTS = [
        '-o StrictHostKeyChecking=no', '-o EscapeChar=none',
        '-o ConnectTimeout=15'
    ]
    envir.LOG_PATTERNS.append("CRIT:")
    envir.LOG_PATTERNS.append("ERROR:")
コード例 #5
0
ファイル: node.py プロジェクト: wenshizhang/hb_report
    def change_to_timestamp(self, times):
        if not len(envir.DATE):
            if len(times.split()) > 1:
                date_string = times.split()[0]
                date = ''.join(re.findall(r'\d+', date_string))
            else:
                date = time.strftime("%Y%m%d")

            envir.DATE = date

        try:
            ds = utils.parse_to_timestamp(times)
            return ds
        except:
            return 0
コード例 #6
0
def parse_argument(argv):
    try:
        opt, arg = getopt.getopt(argv[1:], constants.ARGOPTS_VALUE)
    except getopt.GetoptError:
        usage("short")

    if len(arg) == 0:
        constants.DESTDIR = "."
        constants.DEST = "crm_report-%s" % datetime.datetime.now().strftime(
            '%a-%d-%b-%Y')
    elif len(arg) == 1:
        constants.TMP = arg[0]
    else:
        usage("short")

    for args, option in opt:
        if args == '-h':
            usage()
        if args == "-V":
            version()
        if args == '-f':
            constants.FROM_TIME = crmutils.parse_to_timestamp(option)
            utillib.check_time(constants.FROM_TIME, option)
        if args == '-t':
            constants.TO_TIME = crmutils.parse_to_timestamp(option)
            utillib.check_time(constants.TO_TIME, option)
        if args == "-n":
            constants.USER_NODES += " %s" % option
        if args == "-u":
            constants.SSH_USER = option
        if args == "-X":
            constants.SSH_OPTS += " %s" % option
        if args == "-l":
            constants.HA_LOG = option
        if args == "-e":
            constants.EDITOR = option
        if args == "-p":
            constants.SANITIZE_RULE += " %s" % option
        if args == "-s":
            constants.DO_SANITIZE = True
        if args == "-Q":
            constants.SKIP_LVL = True
        if args == "-L":
            constants.LOG_PATTERNS += " %s" % option
        if args == "-S":
            constants.NO_SSH = True
        if args == "-D":
            constants.NO_DESCRIPTION = 1
        if args == "-Z":
            constants.FORCE_REMOVE_DEST = True
        if args == "-M":
            constants.EXTRA_LOGS = ""
        if args == "-E":
            constants.EXTRA_LOGS += " %s" % option
        if args == "-v":
            constants.VERBOSITY += 1
            config.report.verbosity = constants.VERBOSITY
        if args == '-d':
            constants.COMPRESS = False

    if config.report.sanitize_rule:
        constants.DO_SANITIZE = True
        temp_pattern_set = set()
        temp_pattern_set |= set(
            re.split('\s*\|\s*|\s+', config.report.sanitize_rule.strip('|')))
        constants.SANITIZE_RULE += " {}".format(' '.join(temp_pattern_set))
    utillib.parse_sanitize_rule(constants.SANITIZE_RULE)

    if not constants.FROM_TIME:
        from_time = config.report.from_time
        if re.search("^-[1-9][0-9]*[YmdHM]$", from_time):
            number = int(re.findall("[1-9][0-9]*", from_time)[0])
            if re.search("^-[1-9][0-9]*Y$", from_time):
                timedelta = datetime.timedelta(days=number * 365)
            if re.search("^-[1-9][0-9]*m$", from_time):
                timedelta = datetime.timedelta(days=number * 30)
            if re.search("^-[1-9][0-9]*d$", from_time):
                timedelta = datetime.timedelta(days=number)
            if re.search("^-[1-9][0-9]*H$", from_time):
                timedelta = datetime.timedelta(hours=number)
            if re.search("^-[1-9][0-9]*M$", from_time):
                timedelta = datetime.timedelta(minutes=number)
            from_time = (datetime.datetime.now() -
                         timedelta).strftime("%Y-%m-%d %H:%M")
            constants.FROM_TIME = crmutils.parse_to_timestamp(from_time)
            utillib.check_time(constants.FROM_TIME, from_time)
        else:
            utillib.log_fatal(
                "Wrong format for from_time in /etc/crm/crm.conf; (-[1-9][0-9]*[YmdHM])"
            )