Beispiel #1
0
def test_search_range():
    sr = api.SearchRange("10 minutes ago", arrow.now())
    assert sr.range_in_seconds() == 10 * 60

    sr = api.SearchRange("10 minutes ago", relative=True)
    assert sr.range_in_seconds() == 10 * 60

    sr = api.SearchRange("10 minutes ago")
    with pytest.raises(Exception):
        sr.range_in_seconds()

    sr = api.SearchRange("10 minutes ago", "10 minutes ago")
    assert sr.range_in_seconds() == 1
Beispiel #2
0
def test_graylog_api_search():
    httpretty.register_uri(httpretty.GET,
                           "http://dummyhost:80/search/universal/absolute",
                           body=generate_search_result(),
                           content_type="application/json")

    # More of some dummy tests now
    g = api.GraylogAPI("dummyhost", 80, "dummy", password="******")
    sr = api.SearchRange("10 minutes ago", arrow.now())
    q = api.SearchQuery(sr)
    result = g.search(q)
    assert len(result.messages) == 1
    assert result.query == "*"

    q = api.SearchQuery(sr,
                        fields=["level", "module", "message", "timestamp"],
                        sort="level",
                        ascending=True)
    qq = q.copy_with_range(sr)
    result = g.search(qq)
    assert len(result.messages) == 1
    assert result.query == "*"

    q = api.SearchQuery(sr,
                        fields=["level", "module", "message", "timestamp"],
                        sort="level",
                        ascending=False)
    result = g.search(q)
    assert len(result.messages) == 1
    assert result.query == "*"

    result = g.search(q, fetch_all=True)
    assert len(result.messages) == 1
    assert result.query == "*"
Beispiel #3
0
def test_to_many_results():
    httpretty.register_uri(httpretty.GET, "http://dummyhost:80/search/universal/absolute",
                           body=generate_search_result(1000000),
                           content_type="application/json")

    # More of some dummy tests now
    g = api.GraylogAPI("dummyhost", 80, '/', "dummy", password="******")
    sr = api.SearchRange("10 minutes ago", arrow.now())
    q = api.SearchQuery(sr)

    with pytest.raises(RuntimeError):
        result = g.search(q, fetch_all=True)
Beispiel #4
0
def test_graylog_endpoint_api_search():
    httpretty.register_uri(httpretty.GET, "http://dummyhost:80/api/search/universal/absolute",
                           body=generate_search_result(),
                           content_type="application/json")

    # More of some dummy tests now
    g = api.GraylogAPI("dummyhost", 80, 'api', "dummy", password="******")
    sr = api.SearchRange("10 minutes ago", arrow.now())
    q = api.SearchQuery(sr)
    result = g.search(q)
    assert len(result.messages) == 1
    assert result.query == "*"