]> granicus.if.org Git - icinga2/commitdiff
db_ido: Add externalcommands.
authorMichael Friedrich <michael.friedrich@netways.de>
Mon, 30 Sep 2013 17:32:32 +0000 (19:32 +0200)
committerMichael Friedrich <michael.friedrich@netways.de>
Mon, 30 Sep 2013 17:32:32 +0000 (19:32 +0200)
command_type mapping missing.

refs #4768

lib/db_ido/servicedbobject.cpp
lib/db_ido/servicedbobject.h
lib/icinga/externalcommandprocessor.cpp
lib/icinga/externalcommandprocessor.h

index 57fb7ca472524dc99728881f43b01b3aaec6919f..491c77933ad654db87c39f32ea731c389704ff03 100644 (file)
 #include "icinga/notification.h"
 #include "icinga/checkcommand.h"
 #include "icinga/eventcommand.h"
+#include "icinga/externalcommandprocessor.h"
 #include "icinga/compatutility.h"
 #include <boost/foreach.hpp>
 #include <boost/tuple/tuple.hpp>
+#include <boost/algorithm/string/join.hpp>
 
 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<String>& arguments)
+{
+       Log(LogDebug, "db_ido", "add external command history");
+
+       DbQuery query1;
+       query1.Table = "externalcommands";
+       query1.Type = DbQueryInsert;
+
+       Dictionary::Ptr fields1 = boost::make_shared<Dictionary>();
+
+       fields1->Set("entry_time", DbValue::FromTimestamp(static_cast<long>(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
index 30f39beaca57370dc660d60f0dd6eb630b1d22e7..8a3228e5dceacf87713013b42e28190cafc14129 100644 (file)
@@ -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<String>& arguments);
 };
 
 }
index b44c6c41652b63ef0c9441f5ef6d51738e739584..eb142fdaa3c028a0df9ef1c4a759167efce86ce0 100644 (file)
@@ -41,6 +41,8 @@ boost::once_flag ExternalCommandProcessor::m_InitializeOnce = BOOST_ONCE_INIT;
 boost::mutex ExternalCommandProcessor::m_Mutex;
 std::map<String, ExternalCommandProcessor::Callback> ExternalCommandProcessor::m_Commands;
 
+boost::signals2::signal<void (double, const String&, const std::vector<String>&)> 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);
 }
 
index 49dcd7ae238c714283095059c206f17092a1b482..2e174c37dc5a340bf3e3f2deb1e94795c7901937 100644 (file)
@@ -25,6 +25,7 @@
 #include <boost/thread/mutex.hpp>
 #include <boost/thread/once.hpp>
 #include <boost/function.hpp>
+#include <boost/signals2.hpp>
 #include <vector>
 
 namespace icinga
@@ -35,6 +36,8 @@ public:
        static void Execute(const String& line);
        static void Execute(double time, const String& command, const std::vector<String>& arguments);
 
+        static boost::signals2::signal<void (double, const String&, const std::vector<String>&)> OnNewExternalCommand;
+
 private:
        typedef boost::function<void (double time, const std::vector<String>& arguments)> Callback;