Compile redis into the icinga2 binary; apply more C++11 code changes

This commit is contained in:
Michael Friedrich 2018-05-15 17:18:04 +02:00
parent 61edfcb68d
commit ddf2aea065
8 changed files with 37 additions and 47 deletions

View File

@ -204,6 +204,9 @@ if(HAVE_SYSTEMD)
list(APPEND base_DEPS systemd)
endif()
if(ICINGA2_WITH_REDIS)
list(APPEND base_OBJS $<TARGET_OBJECTS:hiredis>)
endif()
if(EDITLINE_FOUND)
list(APPEND base_DEPS ${EDITLINE_LIBRARIES})

View File

@ -53,6 +53,10 @@ if(ICINGA2_WITH_PERFDATA)
list(APPEND icinga_app_SOURCES $<TARGET_OBJECTS:perfdata>)
endif()
if(ICINGA2_WITH_REDIS)
list(APPEND icinga_app_SOURCES $<TARGET_OBJECTS:redis>)
endif()
add_executable(icinga-app
$<TARGET_OBJECTS:icingaloader>
${base_OBJS}

View File

@ -1,5 +1,5 @@
# Icinga 2
# Copyright (C) 2012-2017 Icinga Development Team (https://www.icinga.com/)
# Copyright (C) 2012-2018 Icinga Development Team (https://www.icinga.com/)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -15,29 +15,27 @@
# along with this program; if not, write to the Free Software Foundation
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
mkclass_target(rediswriter.ti rediswriter.tcpp rediswriter.thpp)
mkclass_target(rediswriter.ti rediswriter-ti.cpp rediswriter-ti.hpp)
set(redis_SOURCES
rediswriter.cpp rediswriter-status.cpp rediswriter-utility.cpp rediswriter.thpp
rediswriter.cpp rediswriter-status.cpp rediswriter-utility.cpp rediswriter-ti.hpp
)
if(ICINGA2_UNITY_BUILD)
mkunity_target(redis redis redis_SOURCES)
endif()
add_library(redis SHARED ${redis_SOURCES})
target_link_libraries(redis ${Boost_LIBRARIES} base config icinga remote hiredis)
add_library(redis OBJECT ${redis_SOURCES})
include_directories(${icinga2_SOURCE_DIR}/third-party)
add_dependencies(redis base config icinga remote)
link_directories(${icinga2_BINARY_DIR}/third-party/hiredis)
set_target_properties (
redis PROPERTIES
INSTALL_RPATH ${CMAKE_INSTALL_FULL_LIBDIR}/icinga2
DEFINE_SYMBOL I2_REDIS_BUILD
FOLDER Components
VERSION ${SPEC_VERSION}
)
install_if_not_exists(
@ -45,9 +43,4 @@ install_if_not_exists(
${CMAKE_INSTALL_SYSCONFDIR}/icinga2/features-available
)
install(
TARGETS redis
RUNTIME DESTINATION ${CMAKE_INSTALL_SBINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/icinga2
)
set(CPACK_NSIS_EXTRA_INSTALL_COMMANDS "${CPACK_NSIS_EXTRA_INSTALL_COMMANDS}" PARENT_SCOPE)

View File

@ -1,6 +1,6 @@
/******************************************************************************
* Icinga 2 *
* Copyright (C) 2012-2017 Icinga Development Team (https://www.icinga.com/) *
* Copyright (C) 2012-2018 Icinga Development Team (https://www.icinga.com/) *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *

View File

@ -1,6 +1,6 @@
/******************************************************************************
* Icinga 2 *
* Copyright (C) 2012-2017 Icinga Development Team (https://www.icinga.com/) *
* Copyright (C) 2012-2018 Icinga Development Team (https://www.icinga.com/) *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
@ -18,7 +18,7 @@
******************************************************************************/
#include "redis/rediswriter.hpp"
#include "redis/rediswriter.tcpp"
#include "redis/rediswriter-ti.cpp"
#include "remote/eventqueue.hpp"
#include "base/json.hpp"
#include "base/statsfunction.hpp"
@ -147,7 +147,6 @@ void RedisWriter::TryToReconnect()
m_ConfigDumpInProgress = false;
}
/*
void RedisWriter::UpdateSubscriptionsTimerHandler()
{
m_WorkQueue.Enqueue(std::bind(&RedisWriter::UpdateSubscriptions, this));
@ -218,7 +217,6 @@ int RedisWriter::GetSubscriptionTypes(String key, RedisSubscriptionInfo& rsi)
<< "Invalid Redis subscriber info for subscriber '" << key << "': " << DiagnosticInformation(ex);
}
}
*/
void RedisWriter::PublishStatsTimerHandler(void)
{
@ -233,10 +231,18 @@ void RedisWriter::PublishStats()
return;
//TODO: Figure out if more stats can be useful here.
StatsFunction::Ptr func = StatsFunctionRegistry::GetInstance()->GetItem("CIB");
Dictionary::Ptr statsFunctions = ScriptGlobal::Get("StatsFunctions", &Empty);
if (!statsFunctions)
return;
Function::Ptr func = statsFunctions->Get("CIB");
Dictionary::Ptr status = new Dictionary();
Array::Ptr perfdata = new Array();
func->Invoke(status, perfdata);
func->Invoke({ status, perfdata });
String jsonStats = JsonEncode(status);
ExecuteQuery({ "PUBLISH", "icinga:stats", jsonStats });
@ -278,7 +284,6 @@ void RedisWriter::HandleEvents()
EventQueue::UnregisterIfUnused(queueName, queue);
}
/*
void RedisWriter::HandleEvent(const Dictionary::Ptr& event)
{
AssertOnWorkQueue();
@ -313,9 +318,8 @@ void RedisWriter::HandleEvent(const Dictionary::Ptr& event)
ExecuteQuery({ "EXEC" });
}
}
*/
void RedisWriter::HandleEvent(const Dictionary::Ptr& event)
void RedisWriter::SendEvent(const Dictionary::Ptr& event)
{
AssertOnWorkQueue();
@ -412,7 +416,7 @@ std::vector<std::shared_ptr<redisReply> > RedisWriter::ExecuteQueries(const std:
);
}
boost::shared_ptr<redisReply> reply(rawReply, freeReplyObject);
std::shared_ptr<redisReply> reply(rawReply, freeReplyObject);
replies.push_back(reply);
}

View File

@ -1,6 +1,6 @@
/******************************************************************************
* Icinga 2 *
* Copyright (C) 2012-2017 Icinga Development Team (https://www.icinga.com/) *
* Copyright (C) 2012-2018 Icinga Development Team (https://www.icinga.com/) *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
@ -20,7 +20,7 @@
#ifndef REDISWRITER_H
#define REDISWRITER_H
#include "redis/rediswriter.thpp"
#include "redis/rediswriter-ti.hpp"
#include "icinga/customvarobject.hpp"
#include "remote/messageorigin.hpp"
#include "base/timer.hpp"
@ -88,7 +88,7 @@ private:
void ExceptionHandler(boost::exception_ptr exp);
boost::shared_ptr<redisReply> ExecuteQuery(const std::vector<String>& query);
std::shared_ptr<redisReply> ExecuteQuery(const std::vector<String>& query);
std::vector<std::shared_ptr<redisReply> > ExecuteQueries(const std::vector<std::vector<String> >& queries);
Timer::Ptr m_StatsTimer;

View File

@ -1,6 +1,6 @@
/******************************************************************************
* Icinga 2 *
* Copyright (C) 2012-2017 Icinga Development Team (https://www.icinga.com/) *
* Copyright (C) 2012-2018 Icinga Development Team (https://www.icinga.com/) *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
@ -19,7 +19,7 @@
#include "base/configobject.hpp"
library demo;
library redis;
namespace icinga
{

View File

@ -1,5 +1,5 @@
# Icinga 2
# Copyright (C) 2012-2017 Icinga Development Team (https://www.icinga.com/)
# Copyright (C) 2012-2018 Icinga Development Team (https://www.icinga.com/)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -15,7 +15,7 @@
# along with this program; if not, write to the Free Software Foundation
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
add_library(hiredis SHARED net.c net.h hiredis.c hiredis.h sds.c sds.h async.c async.h read.c read.h)
add_library(hiredis OBJECT net.c net.h hiredis.c hiredis.h sds.c sds.h async.c async.h read.c read.h)
if(HAVE_VISIBILITY_HIDDEN)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=default")
@ -25,18 +25,4 @@ endif()
set_target_properties (
hiredis PROPERTIES
FOLDER Lib
VERSION ${SPEC_VERSION}
)
install(
TARGETS hiredis
RUNTIME DESTINATION ${CMAKE_INSTALL_SBINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/icinga2
)
if(APPLE)
install(
TARGETS hiredis
LIBRARY DESTINATION ${CMAKE_INSTALL_BINDIR}/icinga-studio.app/Contents
)
endif()