def main():
    args = get_args()
    cmd  = get_cmd(args.inst, args.db, args.table)

    r = envoy.run(cmd)
    results = {}
    internal_status_code = -1
    if r.status_code != 0:
        print(cmd)
        print(r.std_err)
        print(r.std_out)
    else:
        violations = r.std_out.strip()
        if not isnumeric(violations):
            internal_status_code = 1
            fixed_violations = 1
        else:
            if int(violations) == -1:
                fixed_violations = 1
            else:
                fixed_violations = 0

        results['violation_cnt'] = fixed_violations

    results['rc'] = max(r.status_code, internal_status_code)
    print(hapinsp_formatter.transform_args(results))
def main():
    args = get_args()
    cmd  = get_cmd(args.inst, args.db, args.child_table, args.child_col, args.parent_table, args.parent_col)

    r = envoy.run(cmd)
    results = {}
    if r.status_code != 0:
        print(cmd)
        print(r.std_err)
        print(r.std_out)
    else:
        results['violation_cnt'] = r.std_out.strip()

    results['rc'] = r.status_code
    print(hapinsp_formatter.transform_args(results))
def main():
    args = get_args()
    cmd = get_cmd(args.inst, args.db, args.table, args.timestamp_col)

    r = envoy.run(cmd)
    results = {}
    if r.status_code != 0:
        print(cmd)
        print(r.std_err)
        print(r.std_out)
    else:
        results["violation_cnt"] = r.std_out.strip()

    results["rc"] = r.status_code
    print(hapinsp_formatter.transform_args(results))
def main():
    next_start_dt       = None
    next_stop_dt        = None
    next_period_has_data = False

    args = get_args()
    validate_args(args)

    if args.mode == 'incremental':
        if args.data_start_ts_prior == '':
            first_dt = get_first_dt_by_ymd(args.inst, args.db, args.table, args.ssl)
            if first_dt:
                next_period_has_data = True
                next_start_dt       = tools.dt_override(first_dt, hour=0, minute=0, second=0, ms=0)
                next_stop_dt        = tools.dt_override(first_dt, hour=23, minute=59, second=59, ms=999999)
        else:
            try:
                next_start_dt, next_stop_dt = tools.get_next_dt(tools.iso8601_to_dt(args.data_start_ts_prior),
                                                                tools.iso8601_to_dt(args.data_stop_ts_prior))
            except ValueError:
                print('invalid data_start_ts_prior or data_stop_ts_prior: %s and %s' % (args.data_start_ts_prior, args.data_stop_ts_prior))
            next_period_has_data = does_period_have_data(args.inst, args.db, args.ssl, args.table, next_start_dt, next_stop_dt)
    else:
        next_period_has_data = does_period_have_data(args.inst, args.db, args.ssl, args.table, start_dt=None, stop_dt=None)

    results = {}
    if next_period_has_data:
        results['table_status']       = 'active'
        results['mode']               = args.mode
        if args.mode == 'incremental':
            results['data_start_ts']  = tools.dt_to_iso8601(next_start_dt, precision='second')
            results['data_stop_ts']   = tools.dt_to_iso8601(next_stop_dt, precision='second')
        else:
            results['data_start_ts']  = ''
            results['data_stop_ts']   = ''
    else:
        results['table_status']       = 'inactive'
        results['mode']               = args.mode
        results['data_start_ts']      = args.data_start_ts_prior
        results['data_stop_ts']       = args.data_stop_ts_prior

    results['rc'] = INTERNAL_STATUS_CD
    results['log'] = 'start_ts_prior: %s, stop_ts_prior: %s, next_period_has_data: %s'\
            % (args.data_start_ts_prior, args.data_stop_ts_prior, next_period_has_data)
    for (key, val) in os.environ.items():
        if 'hapinsp' in key:
            results['log'] += ', %s:%s' % (key, val)
    print(hapinsp_formatter.transform_args(results))
def main():
    args = get_args()
    enums = args.enums.split(',')
    cmd  = get_cmd(args.inst, args.db, args.table, args.col, enums)

    r = envoy.run(cmd)
    results = {}
    if r.status_code != 0:
        print(cmd)
        print(r.std_err)
        print(r.std_out)
    else:
        results['violation_cnt'] = r.std_out.strip()

    results['rc'] = r.status_code
    print(hapinsp_formatter.transform_args(results))
def main():
    args = get_args()
    validate_args(args)
    cmd, mode  = get_cmd(args.inst, args.db, args.child_table, args.child_col, args.parent_table, args.parent_col,
                         args.start_ts, args.stop_ts, args.ssl)
    r = envoy.run(cmd)
    results = {}
    if r.status_code != 0:
        print(cmd)
        print(r.std_err)
        print(r.std_out)
    else:
        results['violation_cnt'] = r.std_out.strip()
        results['mode'] = mode

    results['log'] = 'start_ts={}, stop_ts={}'.format(args.start_ts, args.stop_ts)
    results['rc'] = r.status_code
    print(hapinsp_formatter.transform_args(results))
def main():
    args = get_args()
    cmd, mode  = get_cmd(args.inst, args.db, args.table)

    r = envoy.run(cmd)
    violations = get_violations(r.std_out)
    results = {}
    if r.status_code != 0:
        print(cmd)
        print(r.std_err)
        print(r.std_out)
    else:
        results['violation_cnt'] = str(violations)
        results['mode'] = mode

    results['rc'] = r.status_code
    results['hapinsp_table_mode'] = args.table_mode
    results['hapinsp_check_mode'] = args.check_mode
    print(hapinsp_formatter.transform_args(results))
def main():
    results = {}
    results['violation_cnt'] = '4'
    results['rc'] = '0'
    print(hapinsp_formatter.transform_args(results))