def events(logkeys, lognick, loggroup, timefrom, timeto, datefrom, dateto): """Get log events""" if lognick is not None: logkeys = apiutils.get_named_logkey(lognick) elif loggroup is not None: logkeys = apiutils.get_named_logkey_group(loggroup) if all([logkeys, timefrom, timeto]): queryapi.get_events(logkeys, time_from=timefrom, time_to=timeto) elif all([logkeys, datefrom, dateto]): queryapi.get_events(logkeys, date_from=datefrom, date_to=dateto) else: click.echo( "Example usage: lecli events 12345678-aaaa-bbbb-1234-1234cb123456 " "-f 1465370400 -t 1465370500") click.echo( "Example usage: lecli events 12345678-aaaa-bbbb-1234-1234cb123456" "--datefrom '2016-05-18 11:04:00' --dateto '2016-05-18 11:09:59'") click.echo( "Example usage: lecli events --loggroup myloggroup" "--datefrom '2016-05-18 11:04:00' --dateto '2016-05-18 11:09:59'") click.echo( "Example usage: lecli events --lognick mynicknamedlog" "--datefrom '2016-05-18 11:04:00' --dateto '2016-05-18 11:09:59'")
def query(logkeys, lognick, loggroup, leql, querynick, timefrom, timeto, datefrom, dateto, expand): """Query logs using LEQL""" if lognick is not None: logkeys = apiutils.get_named_logkey(lognick) if loggroup is not None: logkeys = apiutils.get_named_logkey_group(loggroup) if all([leql, querynick]): click.echo("Cannot define a LEQL query and query nickname in the same query request") elif querynick is not None: leql = apiutils.get_named_query(querynick) if all([logkeys, leql, timefrom, timeto]): query_api.post_query(logkeys, leql, time_from=timefrom, time_to=timeto, expand=expand) elif all([logkeys, leql, datefrom, dateto]): query_api.post_query(logkeys, leql, date_from=datefrom, date_to=dateto, expand=expand) else: click.echo("Example usage: lecli query 12345678-aaaa-bbbb-1234-1234cb123456 -q " "'where(method=GET) calculate(count)' -f 1465370400 -t 1465370500") click.echo("Example usage: lecli query 12345678-aaaa-bbbb-1234-1234cb123456 -q " "'where(method=GET) calculate(count)' " "--datefrom '2016-05-18 11:04:00' --dateto '2016-05-18 11:09:59'") click.echo("Example usage: lecli query --loggroup myloggroup --leql " "'where(method=GET) calculate(count)' " "--datefrom '2016-05-18 11:04:00' --dateto '2016-05-18 11:09:59'") click.echo("Example usage: lecli query --lognick mynicknamedlog --leql " "'where(method=GET) calculate(count)' " "--datefrom '2016-05-18 11:04:00' --dateto '2016-05-18 11:09:59'")
def query(logkeys, lognick, loggroup, leql, querynick, timefrom, timeto, datefrom, dateto): """Query logs using LEQL""" if lognick is not None: logkeys = apiutils.get_named_logkey(lognick) if loggroup is not None: logkeys = apiutils.get_named_logkey_group(loggroup) if all([leql, querynick]): click.echo("Cannot define a LEQL query and query nickname in the same query request") elif querynick is not None: leql = apiutils.get_query_from_nickname(querynick) if all([logkeys, leql, timefrom, timeto]): queryapi.post_query(logkeys, leql, time_from=timefrom, time_to=timeto) elif all([logkeys, leql, datefrom, dateto]): queryapi.post_query(logkeys, leql, date_from=datefrom, date_to=dateto) else: click.echo("Example usage: lecli query 12345678-aaaa-bbbb-1234-1234cb123456 -q " "'where(method=GET) calculate(count)' -f 1465370400 -t 1465370500") click.echo("Example usage: lecli query 12345678-aaaa-bbbb-1234-1234cb123456 -q " "'where(method=GET) calculate(count)' " "--datefrom '2016-05-18 11:04:00' --dateto '2016-05-18 11:09:59'") click.echo("Example usage: lecli query --loggroup myloggroup --leql " "'where(method=GET) calculate(count)' " "--datefrom '2016-05-18 11:04:00' --dateto '2016-05-18 11:09:59'") click.echo("Example usage: lecli query --lognick mynicknamedlog --leql " "'where(method=GET) calculate(count)' " "--datefrom '2016-05-18 11:04:00' --dateto '2016-05-18 11:09:59'")
def test_get_invalid_named_group_key(capsys): with patch.object(ConfigParser.ConfigParser, 'items', return_value=[('test-log-group-nick', ["test-log-key1", "test-log-key2"])]): nick_to_query = 'test-log-group-nick-invalid' logkeys = apiutils.get_named_logkey_group(nick_to_query) out, err = capsys.readouterr() assert logkeys is None assert 'Error: No group with name ' + '\'' + nick_to_query + '\'\n' == out
def test_get_valid_named_group_key(): with patch.object(ConfigParser.ConfigParser, 'items', return_value=[('test-log-group-nick', misc_ex.TEST_LOG_GROUP)]): logkeys = apiutils.get_named_logkey_group('test-log-group-nick') assert logkeys == filter(None, str(misc_ex.TEST_LOG_GROUP).splitlines())
def test_get_invalid_named_group_key(capsys): with patch.object(ConfigParser.ConfigParser, 'items', return_value=[('test-log-group-nick', ["test-log-key1", "test-log-key2"])]): with pytest.raises(SystemExit): nick_to_query = 'test-log-group-nick-invalid' result = apiutils.get_named_logkey_group(nick_to_query) out, err = capsys.readouterr() assert result is None assert nick_to_query in out assert 'was not found' in out
def recentevents(logkeys, lognick, loggroup, last, expand): """Get recent log events""" if lognick is not None: logkeys = apiutils.get_named_logkey(lognick) elif loggroup is not None: logkeys = apiutils.get_named_logkey_group(loggroup) if all([logkeys, last]): query_api.get_recent_events(logkeys, last, expand=expand) else: click.echo( 'Example usage: lecli recentevents \'12345678-aaaa-bbbb-1234-1234cb123456\' -l 200') click.echo('Example usage: lecli recentevents -n mynicknamedlog -l 200') click.echo('Example usage: lecli recentevents -g myloggroup -l 200')
def recentevents(logkeys, lognick, loggroup, timewindow): """Get recent log events""" if lognick is not None: logkeys = apiutils.get_named_logkey(lognick) elif loggroup is not None: logkeys = apiutils.get_named_logkey_group(loggroup) if all([logkeys, timewindow]): queryapi.get_recent_events(logkeys, timewindow) else: click.echo( 'Example usage: lecli recentevents \'12345678-aaaa-bbbb-1234-1234cb123456\' -t 200') click.echo('Example usage: lecli recentevents -n mynicknamedlog -t 200') click.echo('Example usage: lecli recentevents -g myloggroup -t 200')
def events(logkeys, lognick, loggroup, timefrom, timeto, datefrom, dateto): """Get log events""" if lognick is not None: logkeys = apiutils.get_named_logkey(lognick) elif loggroup is not None: logkeys = apiutils.get_named_logkey_group(loggroup) if all([logkeys, timefrom, timeto]): queryapi.get_events(logkeys, time_from=timefrom, time_to=timeto) elif all([logkeys, datefrom, dateto]): queryapi.get_events(logkeys, date_from=datefrom, date_to=dateto) else: click.echo("Example usage: lecli events 12345678-aaaa-bbbb-1234-1234cb123456 " "-f 1465370400 -t 1465370500") click.echo("Example usage: lecli events 12345678-aaaa-bbbb-1234-1234cb123456" "--datefrom '2016-05-18 11:04:00' --dateto '2016-05-18 11:09:59'") click.echo("Example usage: lecli events --loggroup myloggroup" "--datefrom '2016-05-18 11:04:00' --dateto '2016-05-18 11:09:59'") click.echo("Example usage: lecli events --lognick mynicknamedlog" "--datefrom '2016-05-18 11:04:00' --dateto '2016-05-18 11:09:59'")
def test_case_insensitivity_of_named_groups_key(): with patch.object(ConfigParser.ConfigParser, 'items', return_value=[('test-log-group-nick', misc_ex.TEST_LOG_GROUP)]): logkeys = apiutils.get_named_logkey_group('TEST-log-group-nick') assert logkeys == filter(None, str(misc_ex.TEST_LOG_GROUP).splitlines())