├── .gitignore ├── .travis.yml ├── LICENSE ├── Makefile ├── README.md ├── configs_example ├── n2kafka_config.json ├── n2kafka_config.json.default ├── n2kafka_config_debug.json ├── n2kafka_config_meraki.json ├── n2kafka_config_mse.json ├── n2kafka_config_rbhttp.json ├── n2kafka_config_response.json ├── n2kafka_tests_http.json └── n2kafka_tests_tcp.json ├── configure ├── configure.n2kafka ├── mklove ├── Makefile.base └── modules │ ├── configure.atomics │ ├── configure.base │ ├── configure.builtin │ ├── configure.cc │ ├── configure.gitversion │ ├── configure.good_cflags │ ├── configure.host │ └── configure.socket ├── n2kafka.service ├── packaging └── rpm │ ├── Makefile │ └── n2kafka.spec ├── src ├── Makefile.mk ├── decoder │ ├── Makefile.mk │ ├── meraki │ │ ├── Makefile.mk │ │ ├── rb_meraki.c │ │ └── rb_meraki.h │ ├── mse │ │ ├── Makefile.mk │ │ ├── rb_mse.c │ │ └── rb_mse.h │ └── rb_http2k │ │ ├── Makefile.mk │ │ ├── rb_database.c │ │ ├── rb_database.h │ │ ├── rb_http2k_curl_handler.c │ │ ├── rb_http2k_curl_handler.h │ │ ├── rb_http2k_decoder.c │ │ ├── rb_http2k_decoder.h │ │ ├── rb_http2k_organizations_database.c │ │ ├── rb_http2k_organizations_database.h │ │ ├── rb_http2k_parser.c │ │ ├── rb_http2k_parser.h │ │ ├── rb_http2k_sensors_database.c │ │ ├── rb_http2k_sensors_database.h │ │ ├── rb_http2k_sync_common.h │ │ ├── rb_http2k_sync_thread.c │ │ ├── rb_http2k_sync_thread.h │ │ ├── tommyds │ │ ├── LICENSE │ │ ├── tommychain.h │ │ ├── tommyhash.c │ │ ├── tommyhash.h │ │ ├── tommyhashdyn.c │ │ ├── tommyhashdyn.h │ │ ├── tommylist.c │ │ ├── tommylist.h │ │ └── tommytypes.h │ │ ├── uuid_database.c │ │ └── uuid_database.h ├── engine │ ├── Makefile.mk │ ├── engine.c │ ├── engine.h │ ├── global_config.c │ ├── global_config.h │ ├── n2kafka.c │ ├── parse.h │ ├── rb_addr.c │ └── rb_addr.h ├── listener │ ├── Makefile.mk │ ├── http.c │ ├── http.h │ ├── socket.c │ └── socket.h └── util │ ├── Makefile.mk │ ├── in_addr_list.c │ ├── in_addr_list.h │ ├── kafka.c │ ├── kafka.h │ ├── kafka_message_list.c │ ├── kafka_message_list.h │ ├── pair.c │ ├── pair.h │ ├── rb_json.c │ ├── rb_json.h │ ├── rb_mac.c │ ├── rb_mac.h │ ├── rb_time.h │ ├── rb_timer.c │ ├── rb_timer.h │ ├── topic_database.c │ ├── topic_database.h │ └── util.h ├── tests ├── 0000-MSE8.c ├── 0000-MSE8.objdeps ├── 0001-MSE10.c ├── 0001-MSE10.objdeps ├── 0002-meraki.c ├── 0002-meraki.objdeps ├── 0003-MSE8_listener_enrich.c ├── 0003-MSE8_listener_enrich.objdeps ├── 0004-MSE10_listener_enrich.c ├── 0004-MSE10_listener_enrich.objdeps ├── 0005-rb_decoder.c ├── 0005-rb_decoder.objdeps ├── 0006-meraki-null-fields.c ├── 0006-meraki-null-fields.objdeps ├── 0007-mac-partitioner.c ├── 0007-mac-partitioner.objdeps ├── 0008-http2k-malformed-messages.c ├── 0008-http2k-malformed-messages.objdeps ├── 0009-http2k-url.c ├── 0009-http2k-url.objdeps ├── 0010-http2k-organization_enrichment.c ├── 0010-http2k-organization_enrichment.objdeps ├── 0011-rb_http2k-limits.c ├── 0011-rb_http2k-limits.objdeps ├── 0012-http2k-reload.c ├── 0012-http2k-reload.objdeps ├── 0013-http2k-clients-reports.c ├── 0013-http2k-clients-reports.objdeps ├── 0014-http-posts.c ├── 0014-http-posts.objdeps ├── 0015-kafka-producer.c ├── 0015-kafka-producer.objdeps ├── Makefile.tests ├── assertion_handler.c ├── assertion_handler.h ├── display_coverage.sh ├── rb_http2k_tests.c ├── rb_json_tests.c ├── rb_meraki_tests.h ├── rb_mse_tests.h ├── run_tests.sh └── valgrind.suppressions └── version.h /.gitignore: -------------------------------------------------------------------------------- 1 | # Object files 2 | *.o 3 | *.ko 4 | *.obj 5 | *.elf 6 | 7 | # Libraries 8 | *.lib 9 | *.a 10 | 11 | # Shared objects (inc. Windows DLLs) 12 | *.dll 13 | *.so 14 | *.so.* 15 | *.dylib 16 | 17 | # Executables 18 | *.exe 19 | *.out 20 | *.app 21 | *.i*86 22 | *.x86_64 23 | *.hex 24 | 25 | # Dependendes 26 | *.d 27 | 28 | # Coverage 29 | *.gcda 30 | *.gcno 31 | 32 | # mklove 33 | Makefile.config 34 | config.cache 35 | config.h 36 | config.log 37 | config.log.old 38 | version.c 39 | 40 | # Tests 41 | /tests/*.test 42 | /tests/*.xml 43 | /tests/coverage.info 44 | /tests/out 45 | 46 | # Binary 47 | n2kafka 48 | 49 | #build 50 | /packaging/rpm/SOURCES/ 51 | /packaging/rpm/pkgs 52 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: required 2 | 3 | language: c 4 | 5 | notifications: 6 | email: false 7 | 8 | branches: 9 | only: 10 | - master 11 | - develop 12 | - /^[0-9]+\.[0-9]+\.[0-9]+/ 13 | 14 | services: 15 | - docker 16 | 17 | install: 18 | - sudo apt-get install -y docker-engine 19 | - pip install --user cpp-coveralls 20 | 21 | script: 22 | - docker network create --subnet=172.26.0.0/24 test 23 | - docker run -d --net test --ip 172.26.0.2 --name zookeeper wurstmeister/zookeeper 24 | - docker run -d --net test --ip 172.26.0.3 --name kafka -e KAFKA_ADVERTISED_HOST_NAME="172.26.0.3" -e KAFKA_ADVERTISED_PORT="9092" -e KAFKA_ZOOKEEPER_CONNECT="172.26.0.2:2181" -v /var/run/docker.sock:/var/run/docker.sock wurstmeister/kafka 25 | - docker run -v $(pwd):/app redborder/build-dockerfiles:n2kafka ./configure 26 | - docker run -v $(pwd):/app redborder/build-dockerfiles:n2kafka make 27 | - docker run -v $(pwd):/app -e CFLAGS=-w --link kafka --net test redborder/build-dockerfiles:n2kafka make tests 28 | 29 | after_success: 30 | - docker run -v $(pwd):/app redborder/build-dockerfiles:n2kafka make clean 31 | - docker run -v $(pwd):/app redborder/build-dockerfiles:n2kafka ./configure --enable-coverage 32 | - docker run -v $(pwd):/app -e CFLAGS=-w --link kafka --net test redborder/build-dockerfiles:n2kafka make coverage 33 | - docker run -v $(pwd):/app redborder/build-dockerfiles:n2kafka lcov --remove tests/coverage.info 'tests/*' '/usr/*' --output-file tests/coverage.info 34 | - docker run -v $(pwd):/app redborder/build-dockerfiles:n2kafka lcov --list tests/coverage.info 35 | - coveralls --exclude /usr/lib --exclude tests --gcov-options '\-lp' 36 | 37 | before_deploy: 38 | - tar -cvzf n2kafka-${TRAVIS_TAG}.tar.gz n2kafka 39 | 40 | deploy: 41 | provider: releases 42 | api_key: 43 | secure: dTyNSU5oSYX9mc5u25b3Hxzui0nNp88z1IVaxAK7A1qROld3S9GT4PbM5jzM/kYrHrpbzGeV7NUzh/WyAorgtYa2W5waJyTA1WhTx2Vn2NUOcm5TZ1KiOHxK05zeIsTMVjzEIRXGj1xsoQ1f9dwzlBh1cMx5jSDk4E3+B/YKFgQ= 44 | file: n2kafka-${TRAVIS_TAG}.tar.gz 45 | on: 46 | tags: true 47 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | BIN= n2kafka 2 | 3 | SRCS= version.c 4 | OBJS = $(SRCS:.c=.o) 5 | TESTS_C = $(sort $(wildcard tests/0*.c)) 6 | 7 | TESTS = $(TESTS_C:.c=.test) 8 | TESTS_OBJS = $(TESTS:.test=.o) 9 | TESTS_CHECKS_XML = $(TESTS_C:.c=.xml) 10 | TESTS_MEM_XML = $(TESTS_C:.c=.mem.xml) 11 | TESTS_HELGRIND_XML = $(TESTS_C:.c=.helgrind.xml) 12 | TESTS_DRD_XML = $(TESTS_C:.c=.drd.xml) 13 | TESTS_VALGRIND_XML = $(TESTS_MEM_XML) $(TESTS_HELGRIND_XML) $(TESTS_DRD_XML) 14 | TESTS_XML = $(TESTS_CHECKS_XML) $(TESTS_VALGRIND_XML) 15 | 16 | all: $(BIN) 17 | 18 | CURRENT_N2KAFKA_DIR = $(dir $(lastword $(MAKEFILE_LIST))) 19 | 20 | include src/Makefile.mk 21 | include mklove/Makefile.base 22 | 23 | .PHONY: version.c tests coverage 24 | 25 | version.c: 26 | @rm -f $@ 27 | @echo "const char *n2kafka_revision=\"`git describe --abbrev=6 --dirty --tags --always`\";" >> $@ 28 | @echo 'const char *n2kafka_version="1.0.0";' >> $@ 29 | 30 | install: bin-install 31 | 32 | clean: bin-clean 33 | rm -f $(TESTS) $(TESTS_OBJS) $(TESTS_XML) $(COV_FILES) 34 | 35 | COV_FILES = $(foreach ext,gcda gcno, $(SRCS:.c=.$(ext)) $(TESTS_C:.c=.$(ext))) 36 | 37 | VALGRIND ?= valgrind 38 | SUPPRESSIONS_FILE ?= tests/valgrind.suppressions 39 | ifneq ($(wildcard $(SUPPRESSIONS_FILE)),) 40 | SUPPRESSIONS_VALGRIND_ARG = --suppressions=$(SUPPRESSIONS_FILE) 41 | endif 42 | 43 | .PHONY: tests checks memchecks drdchecks helchecks coverage check_coverage 44 | 45 | run_tests = tests/run_tests.sh $(1) $(TESTS_C:.c=) 46 | run_valgrind = $(VALGRIND) --tool=$(1) $(SUPPRESSIONS_VALGRIND_ARG) --xml=yes \ 47 | --xml-file=$(2) $(3) >/dev/null 2>&1 48 | 49 | tests: $(TESTS_XML) 50 | @$(call run_tests, -cvdh) 51 | 52 | checks: $(TESTS_CHECKS_XML) 53 | @$(call run_tests,-c) 54 | 55 | memchecks: $(TESTS_VALGRIND_XML) 56 | @$(call run_tests,-v) 57 | 58 | drdchecks: $(TESTS_DRD_XML) 59 | @$(call run_tests,-d) 60 | 61 | helchecks: $(TESTS_HELGRIND_XML) 62 | @$(call run_tests,-h) 63 | 64 | tests/%.mem.xml: tests/%.test 65 | @echo -e '\033[0;33m Checking memory:\033[0m $<' 66 | -@$(call run_valgrind,memcheck,"$@","./$<") 67 | 68 | tests/%.helgrind.xml: tests/%.test 69 | @echo -e '\033[0;33m Testing concurrency [HELGRIND]:\033[0m $<' 70 | -@$(call run_valgrind,helgrind,"$@","./$<") 71 | 72 | tests/%.drd.xml: tests/%.test 73 | @echo -e '\033[0;33m Testing concurrency [DRD]:\033[0m $<' 74 | -@$(call run_valgrind,drd,"$@","./$<") 75 | 76 | tests/%.xml: tests/%.test 77 | @echo -e '\033[0;33m Testing:\033[0m $<' 78 | @CMOCKA_XML_FILE="$@" CMOCKA_MESSAGE_OUTPUT=XML "./$<" >/dev/null 2>&1 79 | 80 | tests/%.test: CPPFLAGS := -I. $(CPPFLAGS) 81 | tests/%.test: tests/%.o $(filter-out src/engine/n2kafka.o,$(OBJS)) 82 | @echo -e '\033[0;33m Building: $@ \033[0m' 83 | @$(CC) $(CPPFLAGS) $(LDFLAGS) $< $(shell cat $(@:.test=.objdeps)) -o $@ $(LIBS) -lcmocka 84 | 85 | check_coverage: 86 | @( if [[ "x$(WITH_COVERAGE)" == "xn" ]]; then \ 87 | echo -e "$(MKL_RED) You need to configure using --enable-coverage"; \ 88 | echo -n "$(MKL_CLR_RESET)"; \ 89 | false; \ 90 | fi) 91 | 92 | COVERAGE_INFO ?= coverage.info 93 | COVERAGE_OUTPUT_DIRECTORY ?= coverage.out.html 94 | COV_VALGRIND ?= valgrind 95 | COV_GCOV ?= gcov 96 | COV_LCOV ?= lcov 97 | 98 | coverage: check_coverage $(TESTS) 99 | ( for test in $(TESTS); do ./$$test; done ) 100 | $(COV_LCOV) --gcov-tool=$(COV_GCOV) -q \ 101 | --rc lcov_branch_coverage=1 --capture \ 102 | --directory ./ --output-file ${COVERAGE_INFO} 103 | genhtml --branch-coverage ${COVERAGE_INFO} --output-directory \ 104 | ${COVERAGE_OUTPUT_DIRECTORY} > coverage.out 105 | # ./display_coverage.sh 106 | 107 | -include $(DEPS) 108 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # n2kafka 2 | 3 | [![Build Status](https://travis-ci.org/redBorder/n2kafka.svg?branch=develop)](https://travis-ci.org/redBorder/n2kafka) 4 | [![Coverage Status](https://coveralls.io/repos/github/redBorder/n2kafka/badge.svg?branch=develop)](https://coveralls.io/github/redBorder/n2kafka?branch=develop) 5 | 6 | Network to kafka translator. It (currently) support conversion from tcp/udp raw 7 | sockets and HTTP POST to kafka messages, doing message-processing if you need 8 | to. 9 | 10 | # Setup 11 | To use it, you only need to do a typical `./configure && make && make install` 12 | 13 | # Usage 14 | ## Basic usage 15 | 16 | In order to send raw tcp messages from port `2056`, to `mymessages` topic, using 17 | `40` threads, you need to use this config file: 18 | ```json 19 | { 20 | "listeners":[ 21 | {"proto":"tcp","port":2056,"num_threads":40} 22 | ], 23 | "brokers":"localhost", 24 | "topic":"mymessages" 25 | } 26 | ``` 27 | 28 | And launch `n2kafka` using `./n2kafka `. You can also use `udp` and 29 | `http` as proto values. If you want to listen in different ports, you can add as 30 | many listeners as you want. 31 | 32 | ## Recommended config parameters 33 | You can also use this parameters in config json root to improve n2kafka 34 | behavior: 35 | - `"blacklist":["192.168.101.3"]`, that will ignore requests of this directions 36 | (useful for load balancers) 37 | - All 38 | [librdkafka](https://github.com/edenhill/librdkafka/blob/master/CONFIGURATION.md). 39 | options. If a config option starts with `rdkafka.