ipfixcol2 icon indicating copy to clipboard operation
ipfixcol2 copied to clipboard

using hiredis in output plugin

Open kama1 opened this issue 2 years ago • 1 comments

Hi, I want to change Printer.cpp in json output plugins to use redis, in order to use hiredis -lhiredis flag should be added to compiler options, Unfortunately I'am a newbie in c/c++, so I don't know how to include this flag so the compiler recognize hiredis library.

My changes to Printer.cpp so far: #include <hiredis/hiredis.h> redisContext *c; redisReply *reply; c = redisConnect("127.0.0.1", 6379); reply = (redisReply *)redisCommand(c, "PING"); printf("REDIS PING: %s\n", reply->str); freeReplyObject(reply);

Thanks.

kama1 avatar Apr 30 '22 09:04 kama1

Hi,

the easiest (and also the most naïve) way is to modify target_link_libraries command in CMakeLists.txt file of the JSON plugin:

target_link_libraries(json-output
    ${ZLIB_LIBRARIES}
    ${LIBRDKAFKA_LIBRARIES}
    hiredis                 # <<< new parameter
)

Slightly better way is to use add following lines at the beginning of the file:

find_package(PkgConfig REQUIRED)
pkg_check_modules(HIREDIS REQUIRED hiredis)

and modify commands:

include_directories(
    ${ZLIB_INCLUDE_DIRS}         # zlib
    ${LIBRDKAFKA_INCLUDE_DIRS}   # librdkafka
    ${HIREDIS_INCLUDE_DIRS}               # <<< new parameter
)
target_link_libraries(json-output
    ${ZLIB_LIBRARIES}
    ${LIBRDKAFKA_LIBRARIES}
    ${HIREDIS_LIBRARIES}                  # <<< new parameter
)

Lukas

Lukas955 avatar May 02 '22 08:05 Lukas955