-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding an integration test for the GELFRabbitHandler
- Loading branch information
Showing
7 changed files
with
89 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
version: '2' | ||
services: | ||
rabbitmq: | ||
image: "rabbitmq:3.8-management-alpine" | ||
volumes: | ||
- ./setup_rabbitmq.sh:/usr/local/bin/setup_rabbitmq.sh | ||
ports: | ||
- "5672:5672" | ||
- "15672:15672" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,4 +28,4 @@ services: | |
- "12201:12201/tcp" | ||
- "12202:12202/udp" | ||
- "12203:12203" | ||
- "12204:12204/tcp" | ||
- "12204:12204/tcp" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
rabbitmqctl add_user graylog graylog | ||
rabbitmqctl set_user_tags graylog administrator | ||
rabbitmqctl set_permissions -p / graylog ".*" ".*" ".*" | ||
|
||
rabbitmqadmin declare exchange name=log-messages type=direct -u graylog -p graylog |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
"""pytests sending logs to Graylog through RabbitMQ""" | ||
|
||
import logging | ||
|
||
import pytest | ||
|
||
from graypy.rabbitmq import GELFRabbitHandler | ||
from graypy.handler import SYSLOG_LEVELS | ||
|
||
from tests.integration import LOCAL_GRAYLOG_UP | ||
from tests.integration.helper import get_unique_message, get_graylog_response | ||
|
||
|
||
@pytest.mark.skipif(not LOCAL_GRAYLOG_UP, | ||
reason="local Graylog instance not up") | ||
def test_rmq_logging(): | ||
"""Test that verifies the log message was received by Graylog""" | ||
logger = logging.getLogger("test_rmq_logging") | ||
handler = GELFRabbitHandler(url="amqp://graylog:[email protected]", | ||
exchange="log-messages", | ||
exchange_type="direct", | ||
routing_key="#") | ||
logger.addHandler(handler) | ||
message = get_unique_message() | ||
logger.error(message) | ||
graylog_response = get_graylog_response(message) | ||
assert message == graylog_response["message"] | ||
assert "long_message" not in graylog_response | ||
assert "timestamp" in graylog_response | ||
assert SYSLOG_LEVELS[logging.ERROR] == graylog_response["level"] |