#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;
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)
Log(LogDebug, "db_ido", "add service check history for '" + service->GetName() + "'");
-
-
DbQuery query1;
query1.Table = "servicechecks";
query1.Type = DbQueryInsert;
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
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())
callback = it->second;
}
+ OnNewExternalCommand(time, command, arguments);
+
callback(time, arguments);
}
#include <boost/thread/mutex.hpp>
#include <boost/thread/once.hpp>
#include <boost/function.hpp>
+#include <boost/signals2.hpp>
#include <vector>
namespace icinga
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;