File tree Expand file tree Collapse file tree 7 files changed +89
-2
lines changed Expand file tree Collapse file tree 7 files changed +89
-2
lines changed Original file line number Diff line number Diff line change 1+ version : ' 2'
2+ services :
3+ rabbitmq :
4+ image : " rabbitmq:3.8-management-alpine"
5+ volumes :
6+ - ./setup_rabbitmq.sh:/usr/local/bin/setup_rabbitmq.sh
7+ ports :
8+ - " 5672:5672"
9+ - " 15672:15672"
Original file line number Diff line number Diff line change @@ -28,4 +28,4 @@ services:
2828 - " 12201:12201/tcp"
2929 - " 12202:12202/udp"
3030 - " 12203:12203"
31- - " 12204:12204/tcp"
31+ - " 12204:12204/tcp"
Original file line number Diff line number Diff line change 3939 },
4040 "type" : " org.graylog2.inputs.gelf.tcp.GELFTCPInput" ,
4141 "global" : true
42+ },
43+ {
44+ "title" :" rmq" ,
45+ "configuration" : {
46+ "heartbeat" :60 ,
47+ "prefetch" :100 ,
48+ "exchange_bind" :true ,
49+ "broker_vhost" :" /" ,
50+ "broker_username" :" graylog" ,
51+ "decompress_size_limit" :8388608 ,
52+ "broker_port" :5672 ,
53+ "parallel_queues" :1 ,
54+ "broker_password" :" graylog" ,
55+ "throttling_allowed" :false ,
56+ "exchange" :" log-messages" ,
57+ "tls" :false ,
58+ "override_source" :null ,
59+ "routing_key" :" #" ,
60+ "requeue_invalid_messages" :true ,
61+ "broker_hostname" :" rabbitmq" ,
62+ "queue" :" log-messages"
63+ },
64+ "static_fields" :{},
65+ "type" :" org.graylog2.inputs.gelf.amqp.GELFAMQPInput" ,
66+ "global" :true ,
67+ "extractors" :[]
4268 }
4369 ],
4470 "streams" : [],
Original file line number Diff line number Diff line change 1+ rabbitmqctl add_user graylog graylog
2+ rabbitmqctl set_user_tags graylog administrator
3+ rabbitmqctl set_permissions -p / graylog " .*" " .*" " .*"
4+
5+ rabbitmqadmin declare exchange name=log-messages type=direct -u graylog -p graylog
Original file line number Diff line number Diff line change 66DIR=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " > /dev/null 2>&1 && pwd ) "
77cd ${DIR}
88
9+ # remove a potential previous setup
10+ docker-compose -f docker-compose-rmq.yml down
11+ docker-compose -f docker-compose.yml down
12+
13+ # first setup RabbitMQ, as it requires extra setup before Graylog can connect to it.
14+ docker-compose -f docker-compose-rmq.yml up -d
15+
16+ # wait for RabbitMQ to start
17+ sleep 30
18+
19+ # Configure a user and exchange for graylog to use
20+ RMQ_CONTAINER_ID=" $( docker ps -qf " name=rabbit" ) "
21+ docker exec -ti ${RMQ_CONTAINER_ID} sh /usr/local/bin/setup_rabbitmq.sh
22+
923# create ssl certs for enabling the graylog server to use a
1024# TLS connection for GELF input
1125bash create_ssl_certs.sh -h localhost -i 127.0.0.1
1226
1327# start the graylog server docker container
14- docker-compose -f docker-compose.yml down
1528docker-compose -f docker-compose.yml up -d
1629
1730# wait for the graylog server docker container to start
Original file line number Diff line number Diff line change 66DIR=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " > /dev/null 2>&1 && pwd ) "
77cd ${DIR}
88
9+ docker-compose -f docker-compose-rmq.yml down
910docker-compose -f docker-compose.yml down
Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python
2+ # -*- coding: utf-8 -*-
3+
4+ """pytests sending logs to Graylog through RabbitMQ"""
5+
6+ import logging
7+
8+ import pytest
9+
10+ from graypy .rabbitmq import GELFRabbitHandler
11+ from graypy .handler import SYSLOG_LEVELS
12+
13+ from tests .integration import LOCAL_GRAYLOG_UP
14+ from tests .integration .helper import get_unique_message , get_graylog_response
15+
16+
17+ @pytest .mark .skipif (not LOCAL_GRAYLOG_UP ,
18+ reason = "local Graylog instance not up" )
19+ def test_rmq_logging ():
20+ """Test that verifies the log message was received by Graylog"""
21+ logger = logging .getLogger ("test_rmq_logging" )
22+ handler = GELFRabbitHandler (
url = "amqp://graylog:[email protected] " ,
23+ exchange = "log-messages" ,
24+ exchange_type = "direct" ,
25+ routing_key = "#" )
26+ logger .addHandler (handler )
27+ message = get_unique_message ()
28+ logger .error (message )
29+ graylog_response = get_graylog_response (message )
30+ assert message == graylog_response ["message" ]
31+ assert "long_message" not in graylog_response
32+ assert "timestamp" in graylog_response
33+ assert SYSLOG_LEVELS [logging .ERROR ] == graylog_response ["level" ]
You can’t perform that action at this time.
0 commit comments