db_ido: Add externalcommands.

command_type mapping missing.

refs #4768
This commit is contained in:
Michael Friedrich 2013-09-30 19:32:32 +02:00
parent 30323f410f
commit 2699eb3682
4 changed files with 34 additions and 2 deletions

View File

@ -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 <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);
}

View 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);
};
}

View 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);
}

View 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;