From 2699eb3682dd0c88ddfcd98f391c5c4b024dade6 Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Mon, 30 Sep 2013 19:32:32 +0200 Subject: [PATCH] db_ido: Add externalcommands. command_type mapping missing. refs #4768 --- lib/db_ido/servicedbobject.cpp | 28 +++++++++++++++++++++++-- lib/db_ido/servicedbobject.h | 1 + lib/icinga/externalcommandprocessor.cpp | 4 ++++ lib/icinga/externalcommandprocessor.h | 3 +++ 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/lib/db_ido/servicedbobject.cpp b/lib/db_ido/servicedbobject.cpp index 57fb7ca47..491c77933 100644 --- a/lib/db_ido/servicedbobject.cpp +++ b/lib/db_ido/servicedbobject.cpp @@ -28,9 +28,11 @@ #include "icinga/notification.h" #include "icinga/checkcommand.h" #include "icinga/eventcommand.h" +#include "icinga/externalcommandprocessor.h" #include "icinga/compatutility.h" #include #include +#include using namespace icinga; @@ -63,6 +65,8 @@ void ServiceDbObject::StaticInitialize(void) Service::OnFlappingChanged.connect(bind(&ServiceDbObject::AddFlappingHistory, _1, _2)); Service::OnNewCheckResult.connect(bind(&ServiceDbObject::AddServiceCheckHistory, _1, _2)); + + ExternalCommandProcessor::OnNewExternalCommand.connect(bind(&ServiceDbObject::AddExternalCommandHistory, _1, _2, _3)); } ServiceDbObject::ServiceDbObject(const DbType::Ptr& type, const String& name1, const String& name2) @@ -1261,8 +1265,6 @@ void ServiceDbObject::AddServiceCheckHistory(const Service::Ptr& service, const Log(LogDebug, "db_ido", "add service check history for '" + service->GetName() + "'"); - - DbQuery query1; query1.Table = "servicechecks"; query1.Type = DbQueryInsert; @@ -1319,3 +1321,25 @@ void ServiceDbObject::AddServiceCheckHistory(const Service::Ptr& service, const OnQuery(query1); } } + +/* externalcommands */ +void ServiceDbObject::AddExternalCommandHistory(double time, const String& command, const std::vector& arguments) +{ + Log(LogDebug, "db_ido", "add external command history"); + + DbQuery query1; + query1.Table = "externalcommands"; + query1.Type = DbQueryInsert; + + Dictionary::Ptr fields1 = boost::make_shared(); + + fields1->Set("entry_time", DbValue::FromTimestamp(static_cast(time))); + fields1->Set("command_type", Empty); // FIXME + fields1->Set("command_name", command); + fields1->Set("command_args", boost::algorithm::join(arguments, ";")); + + fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */ + + query1.Fields = fields1; + OnQuery(query1); +} \ No newline at end of file diff --git a/lib/db_ido/servicedbobject.h b/lib/db_ido/servicedbobject.h index 30f39beac..8a3228e5d 100644 --- a/lib/db_ido/servicedbobject.h +++ b/lib/db_ido/servicedbobject.h @@ -110,6 +110,7 @@ private: static void AddFlappingHistory(const Service::Ptr& service, FlappingState flapping_state); static void AddServiceCheckHistory(const Service::Ptr& service, const Dictionary::Ptr &cr); + static void AddExternalCommandHistory(double time, const String& command, const std::vector& arguments); }; } diff --git a/lib/icinga/externalcommandprocessor.cpp b/lib/icinga/externalcommandprocessor.cpp index b44c6c416..eb142fdaa 100644 --- a/lib/icinga/externalcommandprocessor.cpp +++ b/lib/icinga/externalcommandprocessor.cpp @@ -41,6 +41,8 @@ boost::once_flag ExternalCommandProcessor::m_InitializeOnce = BOOST_ONCE_INIT; boost::mutex ExternalCommandProcessor::m_Mutex; std::map ExternalCommandProcessor::m_Commands; +boost::signals2::signal&)> ExternalCommandProcessor::OnNewExternalCommand; + void ExternalCommandProcessor::Execute(const String& line) { if (line.IsEmpty()) @@ -90,6 +92,8 @@ void ExternalCommandProcessor::Execute(double time, const String& command, const callback = it->second; } + OnNewExternalCommand(time, command, arguments); + callback(time, arguments); } diff --git a/lib/icinga/externalcommandprocessor.h b/lib/icinga/externalcommandprocessor.h index 49dcd7ae2..2e174c37d 100644 --- a/lib/icinga/externalcommandprocessor.h +++ b/lib/icinga/externalcommandprocessor.h @@ -25,6 +25,7 @@ #include #include #include +#include #include namespace icinga @@ -35,6 +36,8 @@ public: static void Execute(const String& line); static void Execute(double time, const String& command, const std::vector& arguments); + static boost::signals2::signal&)> OnNewExternalCommand; + private: typedef boost::function& arguments)> Callback; -- 2.40.0